Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to load Photoshop png with LIBPNG?
    primarykey
    data
    text
    <p>I am facing some problems to load some specific png images. Here are some helpful images.</p> <ol> <li>Image #1 www.silexars.com/image.png (Doesn't load properly)</li> <li>Image #2 www.silexars.com/image2.png (Loads fine)</li> <li>Screenshot of Image #1 rendered with OpenGL <a href="http://www.silexars.com/screenshot.jpg" rel="nofollow">http://www.silexars.com/screenshot.jpg</a></li> <li>Screenshot of PNG Analyzer with both images open: <a href="http://www.silexars.com/screenshot.png" rel="nofollow">http://www.silexars.com/screenshot.png</a> Image #1 @ Left, Image #2 @ Right</li> </ol> <p>I've noticed that the left image has a chunk called cHRM and I believe I have to convert it somehow. Would someone help me with this issue?</p> <p>The code that I am using for loading the png file is:</p> <pre><code>uint8 Graphics::Image::loadPNG(FILE *fp) { uint8 header[8]; fread(header,sizeof(header),1,fp); if (png_sig_cmp(header,0,sizeof(header))) return INVALID_FILE; png_structp png; png_infop info; png = png_create_read_struct(PNG_LIBPNG_VER_STRING,0,0,0); if (!png) return FAILURE; info = png_create_info_struct(png); if (!info) { png_destroy_read_struct(&amp;png,0,0); return FAILURE; } png_init_io(png,fp);\ png_set_sig_bytes(png,sizeof(header)); png_read_info(png,info); delete[] data; data = 0; int32 bitdepth,colortype; png_get_IHDR(png,info,&amp;width,&amp;height,&amp;bitdepth,&amp;colortype,0,0,0); if (colortype == PNG_COLOR_TYPE_PALETTE) { png_set_palette_to_rgb(png); } if (colortype == PNG_COLOR_TYPE_GRAY &amp;&amp; bitdepth &lt; 8) { png_set_expand_gray_1_2_4_to_8(png); } if (colortype == PNG_COLOR_TYPE_GRAY || colortype == PNG_COLOR_TYPE_GRAY_ALPHA) { png_set_gray_to_rgb(png); } if (png_get_valid(png, info, PNG_INFO_tRNS)) { png_set_tRNS_to_alpha(png); } if (colortype == PNG_COLOR_TYPE_RGB) { png_set_filler(png, 0xff, PNG_FILLER_AFTER); } if (bitdepth == 16) { png_set_strip_16(png); } if (bitdepth &lt; 8) png_set_packing(png); png_read_update_info(png,info); png_get_IHDR(png,info,&amp;width,&amp;height,0,0,0,0,0); int32 rowbytes = png_get_rowbytes(png,info); std::cout &lt;&lt; rowbytes/bpp &lt;&lt; std::endl; data = new uint8[rowbytes*height]; png_bytep *row_pointers = new png_bytep[height*sizeof(png_bytep)]; for (int i = 0; i &lt; height; i++) row_pointers[height-1-i] = data + i * rowbytes; png_read_image(png, row_pointers); png_read_end(png,0); delete[] row_pointers; png_destroy_read_struct(&amp;png,&amp;info,0); return OK; } </code></pre> <p>Hope the info is enough. But if you need any extra data, just ask me.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload