[cairo-commit] cairo-demo/png write_png.c,1.1,1.2
Carl Worth
commit at pdx.freedesktop.org
Wed Dec 10 13:32:12 PST 2003
Committed by: cworth
Update of /cvs/cairo/cairo-demo/png
In directory pdx:/tmp/cvs-serv6891
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/png/write_png.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** write_png.c 18 Aug 2003 18:11:38 -0000 1.1
--- write_png.c 10 Dec 2003 21:32:10 -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