summaryrefslogtreecommitdiff
path: root/gdk-pixbuf/io-png.c
diff options
context:
space:
mode:
authorMark Crichton <crichton@src.gnome.org>1999-06-29 02:54:16 +0000
committerMark Crichton <crichton@src.gnome.org>1999-06-29 02:54:16 +0000
commita83f00d89e734894e5b3958f4b055edc4aec6266 (patch)
tree31ca9f7149eacd70d893e418870fbb1bef008c5d /gdk-pixbuf/io-png.c
parent8854db3c4fc7784aef2b886bd5e5b8f893a88c2f (diff)
downloadgtk+-a83f00d89e734894e5b3958f4b055edc4aec6266.tar.gz
Ok, now it determines if it has an alpha channel. If it does, load it, if
Ok, now it determines if it has an alpha channel. If it does, load it, if not, don't make one.
Diffstat (limited to 'gdk-pixbuf/io-png.c')
-rw-r--r--gdk-pixbuf/io-png.c35
1 files changed, 20 insertions, 15 deletions
diff --git a/gdk-pixbuf/io-png.c b/gdk-pixbuf/io-png.c
index a1fef8dfbf..70d2df645f 100644
--- a/gdk-pixbuf/io-png.c
+++ b/gdk-pixbuf/io-png.c
@@ -17,7 +17,7 @@ GdkPixBuf *image_load(FILE * f)
{
png_structp png_ptr;
png_infop info_ptr, end_info;
- gint i, depth, ctype, inttype, passes;
+ gint i, depth, ctype, inttype, passes, bpp; /* bpp = BYTES/pixel */
png_uint_32 w, h, x, y;
png_bytepp rows;
art_u8 *pixels, *temp, *rowdata;
@@ -74,11 +74,6 @@ GdkPixBuf *image_load(FILE * f)
if (depth < 8)
png_set_packing(png_ptr);
- /* Add filler bits to non-alpha PNGs */
- /* make it 255, full opaque */
- if (depth == 8 && ctype == PNG_COLOR_TYPE_RGB)
- png_set_filler(png_ptr, 0xFF, PNG_FILLER_AFTER);
-
/* Lastly, if the PNG is greyscale, convert to RGB */
if (ctype == PNG_COLOR_TYPE_GRAY || ctype == PNG_COLOR_TYPE_GRAY_ALPHA)
png_set_gray_to_rgb(png_ptr);
@@ -91,7 +86,12 @@ GdkPixBuf *image_load(FILE * f)
/* Allocate some memory and set up row array */
/* This "inhales vigirously"... */
- pixels = g_malloc(w*h*4);
+ if (ctype & PNG_COLOR_MASK_ALPHA)
+ bpp = 4;
+ else
+ bpp = 3;
+
+ pixels = g_malloc(w*h*bpp);
rows = g_malloc(h*sizeof(png_bytep));
if ((!pixels) || (!rows)) {
@@ -101,7 +101,7 @@ GdkPixBuf *image_load(FILE * f)
/* Icky code, but it has to be done... */
for (i = 0; i < h; i++) {
- if ((rows[i] = g_malloc(w*sizeof(art_u8)*4)) == NULL) {
+ if ((rows[i] = g_malloc(w*sizeof(art_u8)*bpp)) == NULL) {
int n;
for (n = 0; n < i; n++)
g_free(rows[i]);
@@ -116,16 +116,18 @@ GdkPixBuf *image_load(FILE * f)
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
/* Now stuff the bytes into pixels & free rows[y] */
- /* RGBA order */
+
temp = pixels;
+
for (y = 0; y < h; y++) {
(png_bytep)rowdata = rows[y];
for (x = 0; x < w; x++) {
- temp[0] = rowdata[(x*4)];
- temp[1] = rowdata[(x*4)+1];
- temp[2] = rowdata[(x*4)+2];
- temp[3] = rowdata[(x*4)+3];
- temp += 4;
+ temp[0] = rowdata[(x*bpp)];
+ temp[1] = rowdata[(x*bpp)+1];
+ temp[2] = rowdata[(x*bpp)+2];
+ if (bpp == 4)
+ temp[3] = rowdata[(x*4)+3];
+ temp += bpp;
}
g_free(rows[y]);
}
@@ -134,7 +136,10 @@ GdkPixBuf *image_load(FILE * f)
/* Return the GdkPixBuf */
pixbuf = g_new(GdkPixBuf, 1);
- pixbuf->art_pixbuf = art_pixbuf_new_rgba (pixels, w, h, (w*4));
+ if (ctype & PNG_COLOR_MASK_ALPHA)
+ pixbuf->art_pixbuf = art_pixbuf_new_rgba (pixels, w, h, (w*4));
+ else
+ pixbuf->art_pixbuf = art_pixbuf_new_rgb (pixels, w, h, (w*3));
/* Ok, I'm anal...shoot me */
if (!(pixbuf->art_pixbuf))