Skip to content
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

png codec doesn't support non indexed grayscale #163

Closed
igor-elovikov opened this issue Apr 6, 2022 · 9 comments
Closed

png codec doesn't support non indexed grayscale #163

igor-elovikov opened this issue Apr 6, 2022 · 9 comments

Comments

@igor-elovikov
Copy link

basically if I just check formats with sail::codec_info::from_extension("png").write_features().output_pixel_formats() it just gives me this list: 13,14,15,16,31,32,33,34,47,48,49,50,55,56,57,58

I've tried to write png image from grayscale buffer but didn't actually find an obvious way to do that (apart from converting it to rgb which I'd like to avoid)

is that intended? or it's something with my build (I just installed it from vcpkg)

@HappySeaFox
Copy link
Owner

Hi! SAIL always tries to write pixels as closer to the source pixels as possible. With png, it always writes source pixels. If you want to save a grayscale image as a 24bit rgb, the only way is to convert the image to 24bit beforehand. There are two conversion methods: 1. Modifying: Overwrite the original image 2. Const: Return a converted image

Hope this helps

@igor-elovikov
Copy link
Author

Hi! thanks for your reply.

Not sure though if I've explained my issue clearly. I have a procedurally generated image in memory coming from external tool. It's a grayscale image and it can have a different precision.

So I wanted to save it as a grayscale png.

This is what I did:

auto image = sail::image(texture.buffer, SAIL_PIXEL_FORMAT_BPP8_GRAYSCALE, texture.level0Width, texture.level0Height);

image.save("myfile.png"); // this won't work (sail says it's not supported pixel format)
image.convert(SAIL_PIXEL_FORMAT_BPP8_INDEXED); // this one also not supported

// the only workaround I've found is this and it's not ideal:
image.convert(SAIL_PIXEL_FORMAT_BPP24_RGB);
image.save("myfile.png"); 

The same goes with 16 bit grayscale. Am I missing something here?

Thanks!

@HappySeaFox
Copy link
Owner

Oh, I see. Let me check and get back to you.

@HappySeaFox
Copy link
Owner

HappySeaFox commented Apr 6, 2022

Yeah, the png implementation doesn't support grayscale images. See https://github.com/HappySeaFox/sail/blob/master/src/sail-codecs/png/png.codec.info.in (there is no grayscale in the list) . I don't really remember the actual reason behind that. Let me investigate more.

@HappySeaFox
Copy link
Owner

It looks like an artifact of the old-era SAIL. Technically, now we have no reasons for not supporting grayscale image.

@HappySeaFox
Copy link
Owner

HappySeaFox commented Apr 6, 2022

Please wait for the next available release in vcpkg.

Or, if you feel comfortable, you can try patching SAIL locally in your current copy of vcpkg just to test if everything works find. This can be done in ports/sail/portfile.cmake in the vcpkg_from_github() call. However, this may require manual cache removal as vcpkg may try to re-use the previously built buggy version.

@igor-elovikov
Copy link
Author

yep, all good so far, thanks for quick fix!
also just a quick question. currently sail spamming logs (also it's all red at least in clion output which makes it a bit noisy)
do I have to explicitly set level via sail_set_log_barrier or is there a setting to completely turn it off
logs

@HappySeaFox
Copy link
Owner

Great!😃

Yes, sail_set_log_barrier is the way to silence logs below the specified level.

@HappySeaFox
Copy link
Owner

microsoft/vcpkg#24005

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

No branches or pull requests

2 participants