UI: Allow Clipboard Copy/Paste Images #105833

Merged
Harley Acheson merged 2 commits from Harley/blender:ClipboardImage into main 2023-04-14 03:48:28 +02:00
2 changed files with 17 additions and 3 deletions
Showing only changes of commit a8db9ec742 - Show all commits

View File

@ -2332,8 +2332,9 @@ static uint *getClipboardImageDibV5(int *r_width, int *r_height)
int offset = bitmapV5Header->bV5Size + bitmapV5Header->bV5ClrUsed * sizeof(RGBQUAD);
if (bitmapV5Header->bV5Compression == BI_BITFIELDS)
if (bitmapV5Header->bV5Compression == BI_BITFIELDS) {
Harley marked this conversation as resolved Outdated

picky use braces with all statements.

*picky* use braces with all statements.
offset += 12;
}
BYTE *buffer = (BYTE *)bitmapV5Header + offset;
int bitcount = bitmapV5Header->bV5BitCount;
int width = bitmapV5Header->bV5Width;

View File

@ -2087,8 +2087,21 @@ ImBuf *WM_clipboard_image_get(void)
bool WM_clipboard_image_set(ImBuf *ibuf)
{
IMB_rect_from_float(ibuf);
return (bool)GHOST_putClipboardImage(ibuf->rect, ibuf->x, ibuf->y);
bool free_byte_buffer = false;
Harley marked this conversation as resolved Outdated

Since this function doesn't know anything else about the ibuf, I think it would be best not to keep the byte-buffer (if it's created).

This can call imb_freerectImBuf(..); in the case there was previously no byte-buffer.

Since this function doesn't know anything else about the `ibuf`, I think it would be best not to keep the byte-buffer (if it's created). This can call `imb_freerectImBuf(..);` in the case there was previously no byte-buffer.
if (ibuf->rect == NULL) {
/* Add a byte buffer if it does not have one. */
IMB_rect_from_float(ibuf);
free_byte_buffer = true;
}
bool success = (bool)GHOST_putClipboardImage(ibuf->rect, ibuf->x, ibuf->y);
if (free_byte_buffer) {
/* Remove the byte buffer if we added it. */
imb_freerectImBuf(ibuf);
}
return success;
}
/** \} */