mirror of
https://github.com/deater/dos33fsprogs.git
synced 2024-06-28 14:29:42 +00:00
gr-utils: loadpng: make it handle indexed PNGs
This commit is contained in:
parent
4841c64ca7
commit
12edf9ea02
|
@ -54,7 +54,7 @@ int loadpng(char *filename, unsigned char **image_ptr, int *xsize, int *ysize) {
|
|||
png_structp png_ptr;
|
||||
png_infop info_ptr;
|
||||
png_bytep *row_pointers;
|
||||
// png_byte color_type;
|
||||
png_byte color_type;
|
||||
// int number_of_passes;
|
||||
|
||||
unsigned char header[8];
|
||||
|
@ -96,11 +96,16 @@ int loadpng(char *filename, unsigned char **image_ptr, int *xsize, int *ysize) {
|
|||
*xsize=width/2;
|
||||
*ysize=height;
|
||||
|
||||
// color_type = png_get_color_type(png_ptr, info_ptr);
|
||||
color_type = png_get_color_type(png_ptr, info_ptr);
|
||||
bit_depth = png_get_bit_depth(png_ptr, info_ptr);
|
||||
|
||||
|
||||
|
||||
if (debug) {
|
||||
printf("PNG: width=%d height=%d depth=%d\n",width,height,bit_depth);
|
||||
if (color_type==PNG_COLOR_TYPE_RGB) printf("Type RGB\n");
|
||||
else if (color_type==PNG_COLOR_TYPE_RGB_ALPHA) printf("Type RGBA\n");
|
||||
else if (color_type==PNG_COLOR_TYPE_PALETTE) printf("Type palette\n");
|
||||
}
|
||||
|
||||
// number_of_passes = png_set_interlace_handling(png_ptr);
|
||||
|
@ -122,6 +127,7 @@ int loadpng(char *filename, unsigned char **image_ptr, int *xsize, int *ysize) {
|
|||
}
|
||||
out_ptr=image;
|
||||
|
||||
if (color_type==PNG_COLOR_TYPE_RGB_ALPHA) {
|
||||
for(y=0;y<height;y+=2) {
|
||||
for(x=0;x<width/2;x++) {
|
||||
|
||||
|
@ -150,6 +156,32 @@ int loadpng(char *filename, unsigned char **image_ptr, int *xsize, int *ysize) {
|
|||
}
|
||||
if (debug) printf("\n");
|
||||
}
|
||||
}
|
||||
else if (color_type==PNG_COLOR_TYPE_PALETTE) {
|
||||
for(y=0;y<height;y+=2) {
|
||||
for(x=0;x<width/2;x++) {
|
||||
|
||||
/* top color */
|
||||
a2_color=row_pointers[y][x*2];
|
||||
|
||||
/* bottom color */
|
||||
color=row_pointers[y+1][x*2];
|
||||
|
||||
a2_color|=(color<<4);
|
||||
|
||||
if (debug) {
|
||||
printf("%x ",a2_color);
|
||||
}
|
||||
|
||||
*out_ptr=a2_color;
|
||||
out_ptr++;
|
||||
}
|
||||
if (debug) printf("\n");
|
||||
}
|
||||
}
|
||||
else {
|
||||
printf("Unknown color type\n");
|
||||
}
|
||||
|
||||
/* Stripe test image */
|
||||
// for(x=0;x<40;x++) for(y=0;y<40;y++) image[(y*width)+x]=y%16;
|
||||
|
|
Loading…
Reference in New Issue
Block a user