Skip to content

Commit 7f5fc45

Browse files
committed
Fix image dictionary for new libpng-based PNG image support (Issue #90)
1 parent 7c527cc commit 7f5fc45

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

pdfio-content.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2057,6 +2057,8 @@ pdfioFileCreateImageObjFromFile(
20572057
_pdfio_image_func_t copy_func = NULL; // Image copy function
20582058

20592059

2060+
PDFIO_DEBUG("pdfioFileCreateImageObjFromFile(pdf=%p, filename=\"%s\", interpolate=%s)\n", (void *)pdf, filename, interpolate ? "true" : "false");
2061+
20602062
// Range check input...
20612063
if (!pdf || !filename)
20622064
return (NULL);
@@ -2078,6 +2080,8 @@ pdfioFileCreateImageObjFromFile(
20782080

20792081
lseek(fd, 0, SEEK_SET);
20802082

2083+
PDFIO_DEBUG("pdfioFileCreateImageObjFromFile: buffer=<%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X>\n", buffer[0], buffer[1], buffer[2], buffer[3], buffer[4], buffer[5], buffer[6], buffer[7], buffer[8], buffer[9], buffer[10], buffer[11], buffer[12], buffer[13], buffer[14], buffer[15], buffer[16], buffer[17], buffer[18], buffer[19], buffer[20], buffer[21], buffer[22], buffer[23], buffer[24], buffer[25], buffer[26], buffer[27], buffer[28], buffer[29], buffer[30], buffer[31]);
2084+
20812085
if (!memcmp(buffer, "\211PNG\015\012\032\012\000\000\000\015IHDR", 16))
20822086
{
20832087
// PNG image...
@@ -2494,6 +2498,8 @@ copy_png(pdfio_dict_t *dict, // I - Dictionary
24942498
bool alpha; // Alpha transparency?
24952499

24962500

2501+
PDFIO_DEBUG("copy_png(dict=%p, fd=%d)\n", (void *)dict, fd);
2502+
24972503
// Allocate memory for PNG reader structures...
24982504
if ((pp = png_create_read_struct(PNG_LIBPNG_VER_STRING, (png_voidp)dict->pdf, png_error_func, png_error_func)) == NULL)
24992505
{
@@ -2507,10 +2513,13 @@ copy_png(pdfio_dict_t *dict, // I - Dictionary
25072513
goto finish_png;
25082514
}
25092515

2516+
PDFIO_DEBUG("copy_png: pp=%p, info=%p\n", (void *)pp, (void *)info);
2517+
25102518
if (setjmp(png_jmpbuf(pp)))
25112519
{
25122520
// If we get here, PNG loading failed and any errors/warnings were logged
25132521
// via the corresponding callback functions...
2522+
fputs("copy_png: setjmp error handler called.\n", stderr);
25142523
goto finish_png;
25152524
}
25162525

@@ -2537,6 +2546,8 @@ copy_png(pdfio_dict_t *dict, // I - Dictionary
25372546
else
25382547
num_colors = 1;
25392548

2549+
PDFIO_DEBUG("copy_png: width=%u, height=%u, color_type=%u, num_colors=%d\n", width, height, color_type, num_colors);
2550+
25402551
// Set decoding options...
25412552
if (png_get_valid(pp, info, PNG_INFO_tRNS))
25422553
{
@@ -2591,6 +2602,11 @@ copy_png(pdfio_dict_t *dict, // I - Dictionary
25912602
for (i = png_set_interlace_handling(pp); i > 0; i --)
25922603
png_read_rows(pp, rows, NULL, (png_uint_32)height);
25932604

2605+
// Add image dictionary information...
2606+
pdfioDictSetNumber(dict, "Width", width);
2607+
pdfioDictSetNumber(dict, "Height", height);
2608+
pdfioDictSetNumber(dict, "BitsPerComponent", 8);
2609+
25942610
// Grab any color space/palette information...
25952611
pdfioDictSetArray(dict, "ColorSpace", pdfioArrayCreateColorFromStandard(dict->pdf, num_colors, PDFIO_CS_SRGB));
25962612

@@ -3475,6 +3491,8 @@ png_read_func(png_structp pp, // I - PNG pointer
34753491
ssize_t bytes; // Bytes read
34763492

34773493

3494+
PDFIO_DEBUG("png_read_func(pp=%p, data=%p, length=%lu)\n", (void *)pp, (void *)data, (unsigned long)length);
3495+
34783496
if ((bytes = read(*fd, data, length)) < (ssize_t)length)
34793497
png_error(pp, "Unable to read from PNG file.");
34803498
}

0 commit comments

Comments
 (0)