Sorry, but I don't think I want to try to make a pull request for this. Even just figuring out the minimal changes to fix the bug would take some time.
As for refactoring the whole thing to use CF_DIB, one issue is that ideally I'd want clipboard.c and bmp.c to share a lot of code, and I don't even know how to do that, and be compliant with your coding standards.
I suggest essentially the following steps for pasting an image from the clipboard:
Code: Select all
OpenClipboard(NULL)
[Optional: EnumClipboardFormats(), see below]
cliphandle = GetClipboardData(CF_DIB)
clipmem_size = GlobalSize(cliphandle)
clipmem = GlobalLock(cliphandle)
[Make a copy of the bytes in clipmem.]
GlobalUnlock(cliphandle)
CloseClipboard();
You now have a copy of clipmem, in DIB format (a BMP file, but without the 14-byte FILEHEADER).
If you want to try to support transparency, the best I can figure out is that you can use EnumClipboardFormats to get a list of available formats. If CF_DIBV5 appears in the list before CF_DIB or CF_BITMAP, then request the data in CF_DIBV5 format instead of CF_DIB format.
Copying an image
to the clipboard would be something like this (this is not too different from the current code):
Code: Select all
cliphandle = GlobalAlloc(GMEM_MOVEABLE, clipmem_size)
clipmem = GlobalLock(cliphandle)
[Encode or copy the image in DIB format to clipmem.]
GlobalUnlock(cliphandle)
OpenClipboard(NULL)
EmptyClipboard()
SetClipboardData(CF_DIB [or CIF_DIBV5], cliphandle)
CloseClipboard()