Distingish alphatransparent pixels in PNGs
| From: | double | Date: | Tue, 20 Jul 2010 16:18:05 +0000 |
| Subject: | Distingish alphatransparent pixels in PNGs | ||
| Groups: | php.gd.devel | ||
| Request: | Send a blank email to php-gd-devel+get-671@lists.php.net to get a copy of this message | ||
Hello,
Is there a chance to distinguish alphatransparent pixels from simple
transparent pixels in PNGs? More precisely, is there a chance to check,
wheater a PNG uses alphatransparent pixels or not?
The down below testcase reports alphatransparent pixels, even if the
source file has only 1bit transparency.
Thanks a lot
Marcus
#include <stdio.h>
#include <stdlib.h>
#include <gd.h>
int main( int argc, char *argv[] )
{
system( "wget -O /tmp/test.png http://doppelbauer.name/test.png" );
FILE *fp = fopen( "/tmp/test.png", "r" );
gdImagePtr image = gdImageCreateFromPng( fp );
fclose( fp );
int x, y;
for( x=0; x < gdImageSX(image); ++x )
{
for( y=0; y < gdImageSY(image); ++y )
{
int color = gdImageGetPixel(image, x, y);
int alpha = gdImageAlpha(image,color);
if( alpha == 0 || alpha == gdTransparent )
continue;
printf( "PNG with 1bit alpha channel contains alphatransparent pixel\n" );
return 0;
}
}
return 0;
}