Refactor: Improve image buffer save/load functions in GHOST
This commit is contained in:
@@ -8035,7 +8035,7 @@ GHOST_TSuccess GHOST_SystemWayland::hasClipboardImage() const
|
||||
if (!uris.empty()) {
|
||||
const std::string_view &uri = uris.front();
|
||||
char *filepath = GHOST_URL_decode_alloc(uri.data(), uri.size());
|
||||
if (IMB_ispic(filepath)) {
|
||||
if (IMB_test_image(filepath)) {
|
||||
result = GHOST_kSuccess;
|
||||
}
|
||||
free(filepath);
|
||||
@@ -8076,8 +8076,8 @@ uint *GHOST_SystemWayland::getClipboardImage(int *r_width, int *r_height) const
|
||||
|
||||
if (data) {
|
||||
/* Generate the image buffer with the received data. */
|
||||
ibuf = IMB_ibImageFromMemory(
|
||||
(const uint8_t *)data, data_len, IB_byte_data, nullptr, "<clipboard>");
|
||||
ibuf = IMB_load_image_from_memory(
|
||||
(const uint8_t *)data, data_len, IB_byte_data, "<clipboard>");
|
||||
free(data);
|
||||
}
|
||||
}
|
||||
@@ -8092,7 +8092,7 @@ uint *GHOST_SystemWayland::getClipboardImage(int *r_width, int *r_height) const
|
||||
if (!uris.empty()) {
|
||||
const std::string_view &uri = uris.front();
|
||||
char *filepath = GHOST_URL_decode_alloc(uri.data(), uri.size());
|
||||
ibuf = IMB_loadiffname(filepath, IB_byte_data, nullptr);
|
||||
ibuf = IMB_load_image_from_filepath(filepath, IB_byte_data);
|
||||
free(filepath);
|
||||
}
|
||||
free(data);
|
||||
@@ -8131,7 +8131,7 @@ GHOST_TSuccess GHOST_SystemWayland::putClipboardImage(uint *rgba, int width, int
|
||||
ImBuf *ibuf = IMB_allocFromBuffer(reinterpret_cast<uint8_t *>(rgba), nullptr, width, height, 32);
|
||||
ibuf->ftype = IMB_FTYPE_PNG;
|
||||
ibuf->foptions.quality = 15;
|
||||
if (!IMB_saveiff(ibuf, "<memory>", IB_byte_data | IB_mem)) {
|
||||
if (!IMB_save_image(ibuf, "<memory>", IB_byte_data | IB_mem)) {
|
||||
IMB_freeImBuf(ibuf);
|
||||
return GHOST_kFailure;
|
||||
}
|
||||
|
||||
@@ -2429,7 +2429,8 @@ GHOST_TSuccess GHOST_SystemWin32::hasClipboardImage(void) const
|
||||
WCHAR lpszFile[MAX_PATH] = {0};
|
||||
DragQueryFileW(hDrop, 0, lpszFile, MAX_PATH);
|
||||
char *filepath = alloc_utf_8_from_16(lpszFile, 0);
|
||||
ImBuf *ibuf = IMB_testiffname(filepath, IB_byte_data | IB_multilayer);
|
||||
ImBuf *ibuf = IMB_load_image_from_filepath(filepath,
|
||||
IB_byte_data | IB_multilayer | IB_test);
|
||||
free(filepath);
|
||||
if (ibuf) {
|
||||
IMB_freeImBuf(ibuf);
|
||||
@@ -2465,7 +2466,7 @@ static uint *getClipboardImageFilepath(int *r_width, int *r_height)
|
||||
}
|
||||
|
||||
if (filepath) {
|
||||
ImBuf *ibuf = IMB_loadiffname(filepath, IB_byte_data | IB_multilayer, nullptr);
|
||||
ImBuf *ibuf = IMB_load_image_from_filepath(filepath, IB_byte_data | IB_multilayer);
|
||||
free(filepath);
|
||||
if (ibuf) {
|
||||
*r_width = ibuf->x;
|
||||
@@ -2583,8 +2584,8 @@ static uint *getClipboardImageImBuf(int *r_width, int *r_height, UINT format)
|
||||
|
||||
uint *rgba = nullptr;
|
||||
|
||||
ImBuf *ibuf = IMB_ibImageFromMemory(
|
||||
(uchar *)pMem, GlobalSize(hGlobal), IB_byte_data, nullptr, "<clipboard>");
|
||||
ImBuf *ibuf = IMB_load_image_from_memory(
|
||||
(uchar *)pMem, GlobalSize(hGlobal), IB_byte_data, "<clipboard>");
|
||||
|
||||
if (ibuf) {
|
||||
*r_width = ibuf->x;
|
||||
@@ -2695,7 +2696,7 @@ static bool putClipboardImagePNG(uint *rgba, int width, int height)
|
||||
ImBuf *ibuf = IMB_allocFromBuffer(reinterpret_cast<uint8_t *>(rgba), nullptr, width, height, 32);
|
||||
ibuf->ftype = IMB_FTYPE_PNG;
|
||||
ibuf->foptions.quality = 15;
|
||||
if (!IMB_saveiff(ibuf, "<memory>", IB_byte_data | IB_mem)) {
|
||||
if (!IMB_save_image(ibuf, "<memory>", IB_byte_data | IB_mem)) {
|
||||
IMB_freeImBuf(ibuf);
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user