I’m writing a texture loader, attempting to use libpng with it. I am currently stumped on one tiny part, which makes no sense. I’m trying to get the image width and height, and am finding that the returned values are not saving.
unsigned int width;
unsigned int height;
...
width = png_get_image_width(png_ptr, info_ptr);
height = png_get_image_height(png_ptr, info_ptr);
printf("Width: %d\nHeight: %d\n\n", width, height);
printf("Width: %d\nHeight: %d\n\n", png_get_image_width(png_ptr, info_ptr), png_get_image_height(png_ptr, info_ptr));
This returns the following:
Width: 0
Height: 0
Width: 1024
Height: 2048
So what’s the deal? This should work, but it is very clearly not.
Pastbin of all relevent code: http://pastebin.com/9RP1iqqU
It looks like you’re using the wrong type.
widthandheightshould bepng_uint_32notunsigned intUPDATE:
After seeing your pastebin, it looks like you’re passing in
widthandheightto the function asunsigned charwhich are effectively hiding the class memberswidthandheightand is probably not what you want, specifically sinceunsigned charcan only hold values up to 255 and the width and height are 1024 and 2048.Just rename the function parameters.