Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

png: enable loading of RGBA images

  • Loading branch information...
commit 031740c39fd11b7d3ac4ebd51efb31e2d2ff0b6b 1 parent f03c8c5
Sébastien Bourdeauducq sbourdeauducq authored
28 src/pixbuf/dither.c
View
@@ -82,7 +82,7 @@ static void floyd_steinberg(int *pic, int width, int height)
}
}
-int pixbuf_dither(unsigned short *ret, unsigned char **row_pointers, int width, int height)
+int pixbuf_dither(unsigned short *ret, unsigned char **row_pointers, int width, int height, int has_alpha)
{
int x, y;
unsigned char *row;
@@ -92,13 +92,25 @@ int pixbuf_dither(unsigned short *ret, unsigned char **row_pointers, int width,
pic = malloc(width*height*3*sizeof(int));
if(pic == NULL) return 0;
- for(y=0;y<height;y++) {
- row = row_pointers[y];
- for(x=0;x<width;x++) {
- offset = 3*(width*y+x);
- pic[offset] = ((unsigned int)row[3*x]) << 16;
- pic[offset+1] = ((unsigned int)row[3*x+1]) << 16;
- pic[offset+2] = ((unsigned int)row[3*x+2]) << 16;
+ if(has_alpha) {
+ for(y=0;y<height;y++) {
+ row = row_pointers[y];
+ for(x=0;x<width;x++) {
+ offset = 3*(width*y+x);
+ pic[offset] = ((unsigned int)row[4*x]) << 16;
+ pic[offset+1] = ((unsigned int)row[4*x+1]) << 16;
+ pic[offset+2] = ((unsigned int)row[4*x+2]) << 16;
+ }
+ }
+ } else {
+ for(y=0;y<height;y++) {
+ row = row_pointers[y];
+ for(x=0;x<width;x++) {
+ offset = 3*(width*y+x);
+ pic[offset] = ((unsigned int)row[3*x]) << 16;
+ pic[offset+1] = ((unsigned int)row[3*x+1]) << 16;
+ pic[offset+2] = ((unsigned int)row[3*x+2]) << 16;
+ }
}
}
2  src/pixbuf/dither.h
View
@@ -18,6 +18,6 @@
#ifndef __PIXBUF_DITHER_H
#define __PIXBUF_DITHER_H
-int pixbuf_dither(unsigned short *ret, unsigned char **row_pointers, int width, int height);
+int pixbuf_dither(unsigned short *ret, unsigned char **row_pointers, int width, int height, int has_alpha);
#endif /* __PIXBUF_DITHER_H */
2  src/pixbuf/loaderjpeg.c
View
@@ -75,7 +75,7 @@ struct pixbuf *pixbuf_load_jpeg(char *filename)
ret = pixbuf_new(cinfo.image_width, cinfo.image_height);
if(ret == NULL) goto free5;
- if(!pixbuf_dither(ret->pixels, row_pointers, cinfo.image_width, cinfo.image_height)) {
+ if(!pixbuf_dither(ret->pixels, row_pointers, cinfo.image_width, cinfo.image_height, 0)) {
pixbuf_dec_ref(ret);
ret = NULL;
goto free5;
4 src/pixbuf/loaderpng.c
View
@@ -64,7 +64,7 @@ struct pixbuf *pixbuf_load_png(char *filename)
color_type = png_get_color_type(png_ptr, info_ptr);
bit_depth = png_get_bit_depth(png_ptr, info_ptr);
- if(color_type != PNG_COLOR_TYPE_RGB) goto free3;
+ if((color_type != PNG_COLOR_TYPE_RGB) && (color_type != PNG_COLOR_TYPE_RGBA)) goto free3;
if(bit_depth != 8) goto free3;
row_pointers = calloc(sizeof(png_bytep), height);
@@ -82,7 +82,7 @@ struct pixbuf *pixbuf_load_png(char *filename)
ret = pixbuf_new(width, height);
if(ret == NULL) goto free4;
ret->filename = strdup(filename);
- if(!pixbuf_dither(ret->pixels, row_pointers, width, height)) {
+ if(!pixbuf_dither(ret->pixels, row_pointers, width, height, color_type == PNG_COLOR_TYPE_RGBA)) {
pixbuf_dec_ref(ret);
ret = NULL;
goto free4;
Please sign in to comment.
Something went wrong with that request. Please try again.