- #88, MFB: Bug loading png images in grayscale + alpha

- add test
master
pajoye 2007-11-18 14:46:45 +00:00
parent d5e41b333c
commit 191ef86832
7 changed files with 52 additions and 2 deletions

View File

@ -195,7 +195,8 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromPngCtx (gdIOCtx * infile)
png_read_info (png_ptr, info_ptr); /* read all PNG info up to image data */
png_get_IHDR (png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, NULL, NULL);
if ((color_type == PNG_COLOR_TYPE_RGB) || (color_type == PNG_COLOR_TYPE_RGB_ALPHA)) {
if ((color_type == PNG_COLOR_TYPE_RGB) || (color_type == PNG_COLOR_TYPE_RGB_ALPHA)
|| color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {
im = gdImageCreateTrueColor ((int) width, (int) height);
} else {
im = gdImageCreate ((int) width, (int) height);
@ -258,7 +259,6 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromPngCtx (gdIOCtx * infile)
break;
case PNG_COLOR_TYPE_GRAY:
case PNG_COLOR_TYPE_GRAY_ALPHA:
/* create a fake palette and check for single-shade transparency */
if ((palette = (png_colorp) gdMalloc (256 * sizeof (png_color))) == NULL) {
fprintf (stderr, "gd-png error: cannot allocate gray palette\n");
@ -298,6 +298,9 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromPngCtx (gdIOCtx * infile)
}
break;
case PNG_COLOR_TYPE_GRAY_ALPHA:
png_set_gray_to_rgb(png_ptr);
case PNG_COLOR_TYPE_RGB:
case PNG_COLOR_TYPE_RGB_ALPHA:
/* gd 2.0: we now support truecolor. See the comment above
@ -396,6 +399,8 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromPngCtx (gdIOCtx * infile)
}
}
break;
case PNG_COLOR_TYPE_GRAY_ALPHA:
case PNG_COLOR_TYPE_RGB_ALPHA:
for (h = 0; h < height; h++) {
int boffset = 0;

View File

@ -3,6 +3,7 @@ SET(TESTS_FILES
bug00011
bug00033
bug00086
bug00088
)
FOREACH(test_name ${TESTS_FILES})

44
tests/png/bug00088.c Normal file
View File

@ -0,0 +1,44 @@
/* $Id$ */
#include "gd.h"
#include <stdio.h>
#include <stdlib.h>
#include "gdtest.h"
int main()
{
int error;
gdImagePtr im;
FILE *fp;
char path[1024];
const char * files[2] = {"bug00088_1.png", "bug00088_2.png"};
const char * files_exp[2] = {"bug00088_1_exp.png", "bug00088_2_exp.png"};
int i, cnt = 2;
error = 0;
for (i = 0; i < cnt; i++) {
sprintf(path, "%s/png/%s", GDTEST_TOP_DIR, files[i]);
fp = fopen(path, "rb");
if (!fp) {
printf("failed, cannot open file <%s>\n", path);
return 1;
}
im = gdImageCreateFromPng(fp);
fclose(fp);
if (!im) {
error |= 1;
continue;
}
sprintf(path, "%s/png/%s", GDTEST_TOP_DIR, files_exp[i]);
if (!gdAssertImageEqualsToFile(path, im)) {
error |= 1;
}
gdImageDestroy(im);
}
return error;
}

BIN
tests/png/bug00088_1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

BIN
tests/png/bug00088_2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 238 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 284 B