pouët.net

Go to bottom

Loading png files with libpng

category: code [glöplog]
 
Hello guys!

Would someone help me with this issue?

http://stackoverflow.com/questions/14951423/how-to-load-photoshop-png-with-libpng

I need to convert this internal format to rgba8/rgb8, but I have no idea how.
added on the 2013-02-20 00:39:02 by Danguafer Danguafer
You could try picopng.
added on the 2013-02-20 11:18:22 by revival revival
or use stb_image; I've been using it for years and I love it.
added on the 2013-02-20 11:22:40 by ferris ferris
stb_image <3
added on the 2013-02-20 15:31:27 by fragment fragment
The image has not only cHRM, but also iCCP which overrides cHRM if you can process it.

Basic: just convert the colors. Calll png_get_cHRM to get data from cHRM: it's the color of red, green, blue and white in the xyY color space. Then convert the image into the standard sRGB color space: multiply each pixel's RGB by a 3×3 matrix. See http://onlinelibrary.wiley.com/doi/10.1002/9780470994375.app8/pdf on how to compute the matrix.

Overkill: colorimetry. Call png_get_iCCP to get data from iCCP. The current specification is at http://www.color.org/ICC1V42.pdf: it is a zlib-compressed 128-byte header and a bunch of extra tags. It can specify the color space, rendering intent, chromatic adaptation, reference viewing envionment, whatever.

The simplest thing to do is to convert it in Photoshop into the standard sRGB space, resave it, and ignore the tags.
added on the 2013-02-20 16:10:14 by rrrola rrrola
Seems like stb_image is pure love. Gotta try it. If it, somehow, doesn't fit my needs, I will follow your guidance, rrrola. Thanks everyone for helping.
added on the 2013-02-20 18:49:31 by Danguafer Danguafer
Well, the question is, do you want to be able to load any kind of PNG files, or can you just stick to some generic subset (supported by stb_load)? If your application is not supposed to deal with images supplied by the user, you can pretty much rule out the former.
Yeah, I just realized that. Got to go back to libpng :P
added on the 2013-02-20 19:30:57 by Danguafer Danguafer
Uh, he has problems with a particular file using the canonical PNG library. And you guys suggest to switch library?! Yeah, as if that's going to lead to *less* problems :P
added on the 2013-02-20 23:52:37 by kusma kusma
Since nobody else was offering up solutions, I think it was fair to suggest other directions to look in. :) libpng is tediously lowlevel, other libs might handle that case automagically.

I'd buy pouet gold for rrrola if I could though.
added on the 2013-02-21 00:43:10 by revival revival
How do I detect if the chunk is present or not? :<
added on the 2013-03-01 01:39:15 by Danguafer Danguafer
png_get_valid
added on the 2013-03-01 15:59:47 by rrrola rrrola
Also, if you're under Windows, try GdiPlus' Bitmap class. Bitmap::FromStream or Bitmap::FromFile and then Bitmap::GetHBITMAP -> GetObject() works wonders.
added on the 2013-03-01 16:15:37 by kb_ kb_
D3DXLoadTexture or sth. like that... ;)
added on the 2013-03-02 15:33:00 by T$ T$
Except that my post was actually serious. GdiPlus::Bitmap easily loads everything that stb_image fails at, and also has color space conversions (which Danguafer needs to have).
added on the 2013-03-02 16:16:15 by kb_ kb_

login

Go to top