[cairo-commit] cairo-demo/PS write_png.c,1.1,1.2
Carl Worth
commit at pdx.freedesktop.org
Wed Dec 10 13:33:36 PST 2003
Committed by: cworth
Update of /cvs/cairo/cairo-demo/PS
In directory pdx:/tmp/cvs-serv6992
Modified Files:
write_png.c
Log Message:
* write_png.c (unpremultiply_data): Fix to keep libpng happy on
big-endian machines.
Index: write_png.c
===================================================================
RCS file: /cvs/cairo/cairo-demo/PS/write_png.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** write_png.c 1 Nov 2003 05:59:13 -0000 1.1
--- write_png.c 10 Dec 2003 21:33:34 -0000 1.2
***************
*** 39,54 ****
for (i = 0; i < row_info->rowbytes; i += 4) {
unsigned char *b = &data[i];
! unsigned char alpha = b[3];
! unsigned long pixel;
! unsigned long *p;
! if (alpha == 0)
! pixel = 0;
! else
! pixel = ((((b[0] * 255) / alpha) << 0) |
! (((b[1] * 255) / alpha) << 8) |
! (((b[2] * 255) / alpha) << 16) |
! (alpha << 24));
! p = (unsigned long *) b;
! *p = pixel;
}
}
--- 39,53 ----
for (i = 0; i < row_info->rowbytes; i += 4) {
unsigned char *b = &data[i];
! unsigned long *p = (unsigned long *) &data[i];
! unsigned long pixel = *p;
! unsigned char alpha = (pixel & 0xff000000) >> 24;
! if (alpha == 0) {
! *p = 0;
! } else {
! b[0] = (((pixel & 0x0000ff) >> 0) * 255) / alpha;
! b[1] = (((pixel & 0x00ff00) >> 8) * 255) / alpha;
! b[2] = (((pixel & 0xff0000) >> 16) * 255) / alpha;
! b[3] = alpha;
! }
}
}
More information about the cairo-commit
mailing list