-
Notifications
You must be signed in to change notification settings - Fork 123
.ICO and .CUR format support #241
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
base: master
Are you sure you want to change the base?
Conversation
Blockage 1ICO is not the only image format with support for sub-images of different width and heights see #16 for instance. I think we would need to add another format-independant type alongside Blockage 2Yup BMP support is not complete so if you find an ICO or CUR that needs bitmap with version earlier than v4 or v5 please implement support for it :) |
|
What constitutes the 'largest image' in the set? The largest area, most bytes, greatest width, greatest height, etc? |
Biggest width and height |
|
How do you want to handle converting between different pixel formats? My personal use case is to convert to ICO images, but they only really support BGRA32. Should converting (e.g., PNG -> ICO) be done automatically when writing to the format? |
See the reply I put here: #231 (comment) |
|
I think this is all that makes sense for me to do. I thought it would take longer, but the ICO format is simple enough and both PNG and BMP have a foundational implementation. There's still some stuff missing, but a lot of it depends on BMP and PNG support, as well as supporting multiple entries as we talked about. This is enough for my use case (at least for now), and I don't want this PR to get out of scope. I'll likely be back another time with some more PRs as this library is fundamental to my project. |
src/formats/ico.zig
Outdated
| return result; | ||
| } | ||
|
|
||
| pub fn largestEntryIdx(self: ICO) ?usize { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
largestEntryIndex
|
Looking good so far, the only thing missing are tests, you can submit test images to this repo: https://github.com/zigimg/test-suite |
|
I'll finally add some tests this week, been busy. Not really sure where to get some good test images from, though. |
This is still early days, but I thought a PR would help to track this, and since I may need some help.
For now, I'm just using the Wikipedia page for .ICO as a reference: https://en.wikipedia.org/wiki/ICO_(file_format)#Icon_file_structure.
Blockage 1
The main blockage is that .ICO and .CUR files have entries with different sizes. Normally multiple images would be fine (see .gif files), however currently there's no support in zigimg for entries of various sizes. To get around this temporarily, I've just made any files without exactly 1 entry unsupported.
I am not sure whether different entry sizes is something maintainers of zigimg want or not, but it may be the case that .ICO and .CUR files are "out of scope" and should instead store multiple ImageUnmanaged.
Blockage 2
The second blockage is that the .BMP file format support has no support for the windows bitmap header:
zigimg/src/formats/bmp.zig
Line 58 in b0a046b
zigimg/src/formats/bmp.zig
Line 129 in b0a046b
zigimg/src/formats/bmp.zig
Line 319 in b0a046b
Presumably .ICO and .CUR files support other header formats for BMP, but since they're windows formats I still consider this to be a blockage.
This is a lot easier to fix than blockage 1, and I will probably just add it to this PR.
Notes
I've updated to Zig 0.14.0 because the Mach Nominated Zig version
2024.11.0-machis no longer registered forzigupto download. I don't suppose this PR will be finished before the next nominated version, so I don't think this is a problem. (I'll continue to work on 0.14.0)