You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I stumbled on this, as you know it's marked as not implemented, but I figured I can circumvent it with lodepng that supports indexed palettes.
Workaround
Add
lodepng = { version = "3.10.0" }
Use lodePNG to decode the PNG file to RGBA u8 vector:
let decoded_png = lodepng::decode32(pngbytes.as_slice())?;let bytevector:Vec<u8> = decoded_png.buffer.iter().flat_map(|pixel| [pixel.r, pixel.g, pixel.b, pixel.a]).collect();let icondata = ico::IconImage::from_rgba_data(
decoded_png.widthasu32,
decoded_png.heightasu32,
bytevector,);// Then write to file normally with letmut icon_dir = ico::IconDir::new(ico::ResourceType::Icon);
icon_dir.add_entry(ico::IconDirEntry::encode(&icondata)?);
icon_dir.write(std::fs::File::create(&icon_file)?)?;
Other thoughts
I would probably remove all support for reading PNG from this library and instead use just RGBA u8 vectors, this way you could have functions that take Vec<u8> (RGBA) and produce ICO files. If the user wants to have a paletted ICO file, then this library would take all distinct colors in Vec u8 and produce palettes, etc.
It would simplify the library and move the responsibility of loading PNG files to other libraries. I know, this has probably been just a little project which you are not actively maintaining, these are just my thoughts, no need to respond.
Overall I like the library nonetheless!
The text was updated successfully, but these errors were encountered:
Ciantic
changed the title
Indexed palettes are not supported
Indexed PNG palettes are not supported
May 9, 2024
Ciantic
changed the title
Indexed PNG palettes are not supported
Indexed PNG palettes are not supported (workaround)
May 9, 2024
I stumbled on this, as you know it's marked as not implemented, but I figured I can circumvent it with lodepng that supports indexed palettes.
Workaround
Other thoughts
I would probably remove all support for reading PNG from this library and instead use just RGBA u8 vectors, this way you could have functions that take
Vec<u8>
(RGBA) and produce ICO files. If the user wants to have a paletted ICO file, then this library would take all distinct colors in Vec u8 and produce palettes, etc.It would simplify the library and move the responsibility of loading PNG files to other libraries. I know, this has probably been just a little project which you are not actively maintaining, these are just my thoughts, no need to respond.
Overall I like the library nonetheless!
The text was updated successfully, but these errors were encountered: