Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@edqx
Copy link
Contributor

@edqx edqx commented Mar 16, 2025

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:

pub const BitmapInfoHeaderWindows31 = extern struct {

windows31: BitmapInfoHeaderWindows31,

else => return ImageUnmanaged.Error.Unsupported,

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-mach is no longer registered for zigup to 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)

PS D:\Projects\zigimg> zigup 0.14.0-dev.2577+271452d22
install directory 'C:\Users\aquila\.zigup\zigup-v2025_01_02\zig'
mkdir "C:\Users\aquila\.zigup\zigup-v2025_01_02\zig"
rd /s /q "C:\Users\aquila\.zigup\zigup-v2025_01_02\zig\0.14.0-dev.2577+271452d22.installing"
mkdir "C:\Users\aquila\.zigup\zigup-v2025_01_02\zig\0.14.0-dev.2577+271452d22.installing"
downloading 'https://ziglang.org/builds/zig-windows-x86_64-0.14.0-dev.2577+271452d22.zip' to 'C:\Users\aquila\.zigup\zigup-v2025_01_02\zig\0.14.0-dev.2577+271452d22.installing\zig-windows-x86_64-0.14.0-dev.2577+271452d22.zip'
error: download 'https://ziglang.org/builds/zig-windows-x86_64-0.14.0-dev.2577+271452d22.zip' failed: HTTP server replied with unsuccessful response '404 Not Found'
rd /s /q "C:\Users\aquila\.zigup\zigup-v2025_01_02\zig\0.14.0-dev.2577+271452d22.installing"

@edqx edqx marked this pull request as draft March 16, 2025 15:45
@mlarouche
Copy link
Collaborator

Blockage 1

ICO 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 Image/ImageUnmanaged to support these multi-size images with their own read/write interface. For now just read/write the largest image format unless you want to provide that format-independant type. Even if we add a new format-independant type, Image/ImageUnmanaged should still support ICO and return the largest image.

Blockage 2

Yup 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 :)

@edqx
Copy link
Contributor Author

edqx commented Mar 16, 2025

What constitutes the 'largest image' in the set? The largest area, most bytes, greatest width, greatest height, etc?

@mlarouche
Copy link
Collaborator

mlarouche commented Mar 16, 2025

What constitutes the 'largest image' in the set? The largest area, most bytes, greatest width, greatest height, etc?

Biggest width and height

@edqx
Copy link
Contributor Author

edqx commented Mar 17, 2025

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?

@mlarouche
Copy link
Collaborator

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)

@edqx
Copy link
Contributor Author

edqx commented Mar 18, 2025

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.

@edqx edqx marked this pull request as ready for review March 18, 2025 20:35
return result;
}

pub fn largestEntryIdx(self: ICO) ?usize {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

largestEntryIndex

@mlarouche
Copy link
Collaborator

Looking good so far, the only thing missing are tests, you can submit test images to this repo: https://github.com/zigimg/test-suite

@edqx
Copy link
Contributor Author

edqx commented Mar 30, 2025

I'll finally add some tests this week, been busy. Not really sure where to get some good test images from, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants