-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support to decode JPEG, GIF and BMP formats, and more pixel formats #74
Conversation
@martincapello although I like this PR, it feels like something is missing. The idea of the clip library is to include code that is used inside the clip library (it's not a general purpose library like laf, the clip library has just one goal that is copying/pasting data from/to the clipboard). I think we can add these functions if we use them here, so I'd suggest:
|
I think this is not gonna be possible. Tried in Chrome and Edge and when an image is copied to the clipboard (whatever format had the source file) it creates the "PNG" data on the clipboard. But this is not the case when a drag & drop operation takes place. In this case the IDataObject that contains the dragged data from Chrome in Windows has the following formats:
Reference about clipboard formats on Windows: https://www.codeproject.com/Reference/1091137/Windows-Clipboard-Formats Hence, there is no "JPG", "GIF", nor "BMP" data reported on the IDataObject either. The format is inferred from the filename in FileGroupDescriptorW (by using the file extension) and then try to decode the FileContents with the appropriate decoder.
As I just said, I didn't find a case where the additional formats are used because they are not clipboard formats actually nor used by Chrome or Edge. I just need to use the decoders because I need to decode the file contents. So, it was (is) actually pretty convenient to have the code in clip because it has a decoder already and then I was able to avoid duplicating several code. So, let me know what do you prefer to do with these changes. Should I move the code to laf and then copy the parts I need? |
I think we have several options:
|
Oh right! Forgot about those, despite I couldn't find an actual use case it seems that they are actually a thing that might be used, then I believe we should add support (I will start adding this).
I like the idea of making the decode_with_wic public, but I would also like to keep the current read methods. Let me know if this makes sense to you, otherwise I think I prefer to keep it private and have only the read methods for now.
This is a good idea, been able to customize which decoder laf should use for each case makes a lot of sense. I will see how to do it. |
There is something we have to figure it out about decoding GIFs...currently all the read methods proposed here return just an image. If we want that the decoding of a GIF returns the full set of frames, I guess that the read method should return a clip::image sequence along with timing data, right? This would imply that from Laf, the DragDataProvider interface must have some method to get the animation, because currently it supports getPaths, getImage and getUrl. |
"JPG", "JPEG", "image/jpeg", "image/png", "BMP", "image/bmp", "GIF", and "image/gif"
We could leave the GIF support in clip library to load just one frame (or drop it completely) there is no difference here for me. What I was thinking: 1) minimal clip support for these clipboard support (read just one image), 2) same minimal support in laf library to load these types in case of drag-and-drop, 3) full support to load GIF files in Aseprite (using the path or the file content and the Aseprite GIF decoder). |
Perfect, this is what this PR is all about right now.
Good, this is what I'm currently doing in laf.
About this...the only way to achieve it with the current DragDataProvider interface is by using getUrl() and download the gif from there. If we would want to use the file contents, then we would need to add a new method to DragDataProvider to get the file contents in some way. But I believe we can discuss this later. |
…ette when converting 8bpp images This avoids crashing the program when converting a decoded malformed BMP (i.e. references palette indexes that don't exist).
This reduces 30KB the resulting .exe binary code in release mode.
It looks good so far although I've made some changes:
This last change is the most important one as it reduces the final binary size by 30KB (creating a global std::vector and doing all the ctors calls + push_back adds a lot of code in the initialization). Here the comparison: As in this PR:
With fa93604:
Please check the dacap/improve-decoders-support branch with your laf changes and if it works I can merge this to main. |
I've pushed your commits since it works as well |
Just merged 👍 |
Add support to decode data in JPEG, GIF, or BMP formats. When decoding animated GIFs only the first frame is taken into account.
Also this PR adds support to decoded images in more pixel formats: 24bpp, 32bpp without alpha, and 8bpp indexed with or without alpha.
This changes will be needed for a future commit (which I'm currently working on) in laf to make the drag&drop of images from Chrome on Windows behave in a similar fashion as Chrome on macOS. Because figured out that the dragged data from Chrome contains a CFSTR_FILEDESCRIPTOR and a CFSTR_FILECONTENTS, which means that we can get the content of the file where the image is temporarily stored.