Note that there are some explanatory texts on larger screens.

plurals
  1. POPNG Image with BGRA CgBI premultiplied alpha
    primarykey
    data
    text
    <p>I have PNGs in Apple's iOS optimized BGRA PNG format (what I get using <a href="https://github.com/basuke/OptimizedPNG" rel="nofollow">OptimizedPNG</a>) and want to draw them in a way that tells CoreGraphics NOT to ignore the alpha component of the image. I'm drawing to a <code>CGContextRef</code> in <code>drawRect:</code></p> <p>Edit: the rendered image shows black where it should be fully transparent (sometimes other random artifacts). The opaque areas are rendered normally. <code>CGImageAlphaInfo</code> I get from the image is <code>kCGImageAlphaNoneSkipLast</code>, which <em>seems</em> to indicate there is a problem in the way the image is saved by OptimizedPNG. I think this should be <code>kCGImageAlphaPremultipliedLast</code>.</p> <p>Perhaps the PNG chunks are wrong, but I don't see anything wrong with IHDR, and there is very little I can find about the CgBI chunk. </p> <p>This is how OptimizedPNG saves the color data:</p> <pre><code>// IDAT int size = width*height*4; unsigned char *buffer = malloc(size); CGContextRef context = CGBitmapContextCreate(buffer, width, height, 8, width*4, CGImageGetColorSpace(originalImage.CGImage), kCGImageAlphaPremultipliedLast); CGRect rect = CGRectMake(0.0, 0.0, (CGFloat)width, (CGFloat)height); CGContextDrawImage(context, rect, originalImage.CGImage); CGContextRelease(context); int size_line = 1 + width*4; int size_in = height*size_line; unsigned char *buffer_in = malloc(size_in); for(int y = 0; y &lt; height; ++y){ unsigned char *src = &amp;buffer[y*width*4]; unsigned char *dst = &amp;buffer_in[y*size_line]; *dst++ = 1; unsigned char r = 0, g = 0, b = 0, a = 0; for(int x = 0; x &lt; width; ++x){ dst[0] = src[2] - b; dst[1] = src[1] - g; dst[2] = src[0] - r; dst[3] = src[3] - a; r = src[0], g = src[1], b = src[2], a = src[3]; src += 4; dst += 4; } } </code></pre>
    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