Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 355091 | Differences between
and this patch

Collapse All | Expand All

(-)trunk/source/texk/web2c/luatexdir/image/writepng.w (-77 / +83 lines)
Lines 76-87 Link Here
76
        png_set_tRNS_to_alpha(png_p);
76
        png_set_tRNS_to_alpha(png_p);
77
    }
77
    }
78
    /* alpha channel support  */
78
    /* alpha channel support  */
79
    if (pdf->minor_version < 4 && png_p->color_type | PNG_COLOR_MASK_ALPHA)
79
    if (pdf->minor_version < 4 && png_get_color_type (png_p, info_p) | PNG_COLOR_MASK_ALPHA)
80
        png_set_strip_alpha(png_p);
80
        png_set_strip_alpha(png_p);
81
    /* 16bit depth support */
81
    /* 16bit depth support */
82
    if (pdf->minor_version < 5)
82
    if (pdf->minor_version < 5)
83
        pdf->image_hicolor = 0;
83
        pdf->image_hicolor = 0;
84
    if ((info_p->bit_depth == 16) && (pdf->image_hicolor == 0))
84
    if ((png_get_bit_depth (png_p, info_p) == 16) && (pdf->image_hicolor == 0))
85
        png_set_strip_16(png_p);
85
        png_set_strip_16(png_p);
86
    /* gamma support */
86
    /* gamma support */
87
    if (pdf->image_apply_gamma) {
87
    if (pdf->image_apply_gamma) {
Lines 94-108 Link Here
94
    /* reset structure */
94
    /* reset structure */
95
    png_read_update_info(png_p, info_p);
95
    png_read_update_info(png_p, info_p);
96
    /* resolution support */
96
    /* resolution support */
97
    img_xsize(idict) = (int) info_p->width;
97
    img_xsize(idict) = (int) png_get_image_width (png_p, info_p);
98
    img_ysize(idict) = (int) info_p->height;
98
    img_ysize(idict) = (int) png_get_image_height (png_p, info_p);
99
    if (info_p->valid & PNG_INFO_pHYs) {
99
    if (info_p->valid & PNG_INFO_pHYs) {
100
        img_xres(idict) =
100
        img_xres(idict) =
101
            round(0.0254 * (double) png_get_x_pixels_per_meter(png_p, info_p));
101
            round(0.0254 * (double) png_get_x_pixels_per_meter(png_p, info_p));
102
        img_yres(idict) =
102
        img_yres(idict) =
103
            round(0.0254 * (double) png_get_y_pixels_per_meter(png_p, info_p));
103
            round(0.0254 * (double) png_get_y_pixels_per_meter(png_p, info_p));
104
    }
104
    }
105
    switch (info_p->color_type) {
105
    switch (png_get_color_type (png_p, info_p)) {
106
    case PNG_COLOR_TYPE_PALETTE:
106
    case PNG_COLOR_TYPE_PALETTE:
107
        img_procset(idict) |= PROCSET_IMAGE_C | PROCSET_IMAGE_I;
107
        img_procset(idict) |= PROCSET_IMAGE_C | PROCSET_IMAGE_I;
108
        break;
108
        break;
Lines 115-123 Link Here
115
        img_procset(idict) |= PROCSET_IMAGE_C;
115
        img_procset(idict) |= PROCSET_IMAGE_C;
116
        break;
116
        break;
117
    default:
117
    default:
118
        pdftex_fail("unsupported type of color_type <%i>", info_p->color_type);
118
        pdftex_fail("unsupported type of color_type <%i>", (int)png_get_color_type (png_p, info_p));
119
    }
119
    }
120
    img_colordepth(idict) = info_p->bit_depth;
120
    img_colordepth(idict) = png_get_bit_depth (png_p, info_p);
121
    if (readtype == IMG_CLOSEINBETWEEN)
121
    if (readtype == IMG_CLOSEINBETWEEN)
122
        close_and_cleanup_png(idict);
122
        close_and_cleanup_png(idict);
123
}
123
}
Lines 142-151 Link Here
142
#define write_simple_pixel(r)    pdf_quick_out(pdf,*r++)
142
#define write_simple_pixel(r)    pdf_quick_out(pdf,*r++)
143
143
144
#define write_noninterlaced(outmac)                      \
144
#define write_noninterlaced(outmac)                      \
145
    for (i = 0; i < (int)info_p->height; i++) {          \
145
    for (i = 0; i < (int)png_get_image_height (png_p, info_p); i++) {          \
146
    png_read_row(png_p, row, NULL);                      \
146
    png_read_row(png_p, row, NULL);                      \
147
    r = row;                                             \
147
    r = row;                                             \
148
    k = (int)info_p->rowbytes;				 \
148
    k = (int)png_get_rowbytes (png_p, info_p);				 \
149
    while(k > 0) {                                       \
149
    while(k > 0) {                                       \
150
        l = (k > pdf->buf_size)? pdf->buf_size : k;      \
150
        l = (k > pdf->buf_size)? pdf->buf_size : k;      \
151
                pdf_room(pdf,l);                         \
151
                pdf_room(pdf,l);                         \
Lines 157-165 Link Here
157
        }
157
        }
158
158
159
#define write_interlaced(outmac)                         \
159
#define write_interlaced(outmac)                         \
160
    for (i = 0; i < (int)info_p->height; i++) {          \
160
    for (i = 0; i < (int)png_get_image_height (png_p, info_p); i++) {          \
161
            row = rows[i];                               \
161
            row = rows[i];                               \
162
            k = (int)info_p->rowbytes;			 \
162
            k = (int)png_get_rowbytes (png_p, info_p);			 \
163
            while(k > 0) {                               \
163
            while(k > 0) {                               \
164
                l = (k > pdf->buf_size)?pdf->buf_size: k;\
164
                l = (k > pdf->buf_size)?pdf->buf_size: k;\
165
                pdf_room(pdf,l);                         \
165
                pdf_room(pdf,l);                         \
Lines 187-203 Link Here
187
                   (int) (info_p->num_palette - 1), (int) palette_objnum);
187
                   (int) (info_p->num_palette - 1), (int) palette_objnum);
188
    }
188
    }
189
    pdf_begin_stream(pdf);
189
    pdf_begin_stream(pdf);
190
    if (info_p->interlace_type == PNG_INTERLACE_NONE) {
190
    if (png_get_interlace_type (png_p, info_p) == PNG_INTERLACE_NONE) {
191
        row = xtalloc(info_p->rowbytes, png_byte);
191
        row = xtalloc(png_get_rowbytes (png_p, info_p), png_byte);
192
        write_noninterlaced(write_simple_pixel(r));
192
        write_noninterlaced(write_simple_pixel(r));
193
        xfree(row);
193
        xfree(row);
194
    } else {
194
    } else {
195
        if (info_p->height * info_p->rowbytes >= 10240000L)
195
        if (png_get_image_height (png_p, info_p) * png_get_rowbytes (png_p, info_p) >= 10240000L)
196
            pdftex_warn
196
            pdftex_warn
197
                ("large interlaced PNG might cause out of memory (use non-interlaced PNG to fix this)");
197
                ("large interlaced PNG might cause out of memory (use non-interlaced PNG to fix this)");
198
        rows = xtalloc(info_p->height, png_bytep);
198
        rows = xtalloc(png_get_image_height (png_p, info_p), png_bytep);
199
        for (i = 0; (unsigned) i < info_p->height; i++)
199
        for (i = 0; (unsigned) i < png_get_image_height (png_p, info_p); i++)
200
            rows[i] = xtalloc(info_p->rowbytes, png_byte);
200
            rows[i] = xtalloc(png_get_rowbytes (png_p, info_p), png_byte);
201
        png_read_image(png_p, rows);
201
        png_read_image(png_p, rows);
202
        write_interlaced(write_simple_pixel(row));
202
        write_interlaced(write_simple_pixel(row));
203
        xfree(rows);
203
        xfree(rows);
Lines 229-245 Link Here
229
        pdf_puts(pdf, "/DeviceGray\n");
229
        pdf_puts(pdf, "/DeviceGray\n");
230
    }
230
    }
231
    pdf_begin_stream(pdf);
231
    pdf_begin_stream(pdf);
232
    if (info_p->interlace_type == PNG_INTERLACE_NONE) {
232
    if (png_get_interlace_type (png_p, info_p) == PNG_INTERLACE_NONE) {
233
        row = xtalloc(info_p->rowbytes, png_byte);
233
        row = xtalloc(png_get_rowbytes (png_p, info_p), png_byte);
234
        write_noninterlaced(write_simple_pixel(r));
234
        write_noninterlaced(write_simple_pixel(r));
235
        xfree(row);
235
        xfree(row);
236
    } else {
236
    } else {
237
        if (info_p->height * info_p->rowbytes >= 10240000L)
237
        if (png_get_image_height (png_p, info_p) * png_get_rowbytes (png_p, info_p) >= 10240000L)
238
            pdftex_warn
238
            pdftex_warn
239
                ("large interlaced PNG might cause out of memory (use non-interlaced PNG to fix this)");
239
                ("large interlaced PNG might cause out of memory (use non-interlaced PNG to fix this)");
240
        rows = xtalloc(info_p->height, png_bytep);
240
        rows = xtalloc(png_get_image_height (png_p, info_p), png_bytep);
241
        for (i = 0; (unsigned) i < info_p->height; i++)
241
        for (i = 0; (unsigned) i < png_get_image_height (png_p, info_p); i++)
242
            rows[i] = xtalloc(info_p->rowbytes, png_byte);
242
            rows[i] = xtalloc(png_get_rowbytes (png_p, info_p), png_byte);
243
        png_read_image(png_p, rows);
243
        png_read_image(png_p, rows);
244
        write_interlaced(write_simple_pixel(row));
244
        write_interlaced(write_simple_pixel(row));
245
        xfree(rows);
245
        xfree(rows);
Lines 258-264 Link Here
258
    png_bytep smask;
258
    png_bytep smask;
259
    int smask_ptr = 0;
259
    int smask_ptr = 0;
260
    int smask_size = 0;
260
    int smask_size = 0;
261
    int bitdepth;
261
    png_byte bitdepth;
262
    if (img_colorspace(idict) != 0) {
262
    if (img_colorspace(idict) != 0) {
263
        pdf_printf(pdf, "%i 0 R\n", (int) img_colorspace(idict));
263
        pdf_printf(pdf, "%i 0 R\n", (int) img_colorspace(idict));
264
    } else {
264
    } else {
Lines 266-291 Link Here
266
    }
266
    }
267
    smask_objnum = pdf_create_obj(pdf, obj_type_others, 0);
267
    smask_objnum = pdf_create_obj(pdf, obj_type_others, 0);
268
    pdf_printf(pdf, "/SMask %i 0 R\n", (int) smask_objnum);
268
    pdf_printf(pdf, "/SMask %i 0 R\n", (int) smask_objnum);
269
    smask_size = (int) ((info_p->rowbytes / 2) * info_p->height);
269
    smask_size = (int) ((png_get_rowbytes (png_p, info_p) / 2) * png_get_image_height (png_p, info_p));
270
    smask = xtalloc((unsigned) smask_size, png_byte);
270
    smask = xtalloc((unsigned) smask_size, png_byte);
271
    pdf_begin_stream(pdf);
271
    pdf_begin_stream(pdf);
272
    if (info_p->interlace_type == PNG_INTERLACE_NONE) {
272
    if (png_get_interlace_type (png_p, info_p) == PNG_INTERLACE_NONE) {
273
        row = xtalloc(info_p->rowbytes, png_byte);
273
        row = xtalloc(png_get_rowbytes (png_p, info_p), png_byte);
274
        if ((info_p->bit_depth == 16) && (pdf->image_hicolor != 0)) {
274
        if ((png_get_bit_depth (png_p, info_p) == 16) && (pdf->image_hicolor != 0)) {
275
            write_noninterlaced(write_gray_pixel_16(r));
275
            write_noninterlaced(write_gray_pixel_16(r));
276
        } else {
276
        } else {
277
            write_noninterlaced(write_gray_pixel_8(r));
277
            write_noninterlaced(write_gray_pixel_8(r));
278
        }
278
        }
279
        xfree(row);
279
        xfree(row);
280
    } else {
280
    } else {
281
        if (info_p->height * info_p->rowbytes >= 10240000L)
281
        if (png_get_image_height (png_p, info_p) * png_get_rowbytes (png_p, info_p) >= 10240000L)
282
            pdftex_warn
282
            pdftex_warn
283
                ("large interlaced PNG might cause out of memory (use non-interlaced PNG to fix this)");
283
                ("large interlaced PNG might cause out of memory (use non-interlaced PNG to fix this)");
284
        rows = xtalloc(info_p->height, png_bytep);
284
        rows = xtalloc(png_get_image_height (png_p, info_p), png_bytep);
285
        for (i = 0; (unsigned) i < info_p->height; i++)
285
        for (i = 0; (unsigned) i < png_get_image_height (png_p, info_p); i++)
286
            rows[i] = xtalloc(info_p->rowbytes, png_byte);
286
            rows[i] = xtalloc(png_get_rowbytes (png_p, info_p), png_byte);
287
        png_read_image(png_p, rows);
287
        png_read_image(png_p, rows);
288
        if ((info_p->bit_depth == 16) && (pdf->image_hicolor != 0)) {
288
        if ((png_get_bit_depth (png_p, info_p) == 16) && (pdf->image_hicolor != 0)) {
289
            write_interlaced(write_gray_pixel_16(row));
289
            write_interlaced(write_gray_pixel_16(row));
290
        } else {
290
        } else {
291
            write_interlaced(write_gray_pixel_8(row));
291
            write_interlaced(write_gray_pixel_8(row));
Lines 295-308 Link Here
295
    pdf_end_stream(pdf);
295
    pdf_end_stream(pdf);
296
    pdf_flush(pdf);
296
    pdf_flush(pdf);
297
    /* now write the Smask object */
297
    /* now write the Smask object */
298
    bitdepth = (int) info_p->bit_depth;
298
    bitdepth = png_get_bit_depth (png_p, info_p);
299
    pdf_begin_dict(pdf, smask_objnum, 0);
299
    pdf_begin_dict(pdf, smask_objnum, 0);
300
    pdf_puts(pdf, "/Type /XObject\n/Subtype /Image\n");
300
    pdf_puts(pdf, "/Type /XObject\n/Subtype /Image\n");
301
    if (img_attr(idict) != NULL && strlen(img_attr(idict)) > 0)
301
    if (img_attr(idict) != NULL && strlen(img_attr(idict)) > 0)
302
        pdf_printf(pdf, "%s\n", img_attr(idict));
302
        pdf_printf(pdf, "%s\n", img_attr(idict));
303
    pdf_printf(pdf, "/Width %i\n/Height %i\n/BitsPerComponent %i\n",
303
    pdf_printf(pdf, "/Width %u\n/Height %i\n/BitsPerComponent %u\n",
304
               (int) info_p->width,
304
               png_get_image_width (png_p, info_p),
305
               (int) info_p->height, (bitdepth == 16 ? 8 : bitdepth));
305
               png_get_image_height (png_p, info_p), 
306
               (bitdepth == 16 ? 8 : bitdepth));
306
    pdf_puts(pdf, "/ColorSpace /DeviceGray\n");
307
    pdf_puts(pdf, "/ColorSpace /DeviceGray\n");
307
    pdf_begin_stream(pdf);
308
    pdf_begin_stream(pdf);
308
    for (i = 0; i < smask_size; i++) {
309
    for (i = 0; i < smask_size; i++) {
Lines 329-345 Link Here
329
        pdf_puts(pdf, "/DeviceRGB\n");
330
        pdf_puts(pdf, "/DeviceRGB\n");
330
    }
331
    }
331
    pdf_begin_stream(pdf);
332
    pdf_begin_stream(pdf);
332
    if (info_p->interlace_type == PNG_INTERLACE_NONE) {
333
    if (png_get_interlace_type (png_p, info_p) == PNG_INTERLACE_NONE) {
333
        row = xtalloc(info_p->rowbytes, png_byte);
334
        row = xtalloc(png_get_rowbytes (png_p, info_p), png_byte);
334
        write_noninterlaced(write_simple_pixel(r));
335
        write_noninterlaced(write_simple_pixel(r));
335
        xfree(row);
336
        xfree(row);
336
    } else {
337
    } else {
337
        if (info_p->height * info_p->rowbytes >= 10240000L)
338
        if (png_get_image_height (png_p, info_p) * png_get_rowbytes (png_p, info_p) >= 10240000L)
338
            pdftex_warn
339
            pdftex_warn
339
                ("large interlaced PNG might cause out of memory (use non-interlaced PNG to fix this)");
340
                ("large interlaced PNG might cause out of memory (use non-interlaced PNG to fix this)");
340
        rows = xtalloc(info_p->height, png_bytep);
341
        rows = xtalloc(png_get_image_height (png_p, info_p), png_bytep);
341
        for (i = 0; (unsigned) i < info_p->height; i++)
342
        for (i = 0; (unsigned) i < png_get_image_height (png_p, info_p); i++)
342
            rows[i] = xtalloc(info_p->rowbytes, png_byte);
343
            rows[i] = xtalloc(png_get_rowbytes (png_p, info_p), png_byte);
343
        png_read_image(png_p, rows);
344
        png_read_image(png_p, rows);
344
        write_interlaced(write_simple_pixel(row));
345
        write_interlaced(write_simple_pixel(row));
345
        xfree(rows);
346
        xfree(rows);
Lines 358-364 Link Here
358
    png_bytep smask;
359
    png_bytep smask;
359
    int smask_ptr = 0;
360
    int smask_ptr = 0;
360
    int smask_size = 0;
361
    int smask_size = 0;
361
    int bitdepth;
362
    png_byte bitdepth;
362
    if (img_colorspace(idict) != 0) {
363
    if (img_colorspace(idict) != 0) {
363
        pdf_printf(pdf, "%i 0 R\n", (int) img_colorspace(idict));
364
        pdf_printf(pdf, "%i 0 R\n", (int) img_colorspace(idict));
364
    } else {
365
    } else {
Lines 366-391 Link Here
366
    }
367
    }
367
    smask_objnum = pdf_create_obj(pdf, obj_type_others, 0);
368
    smask_objnum = pdf_create_obj(pdf, obj_type_others, 0);
368
    pdf_printf(pdf, "/SMask %i 0 R\n", (int) smask_objnum);
369
    pdf_printf(pdf, "/SMask %i 0 R\n", (int) smask_objnum);
369
    smask_size = (int) ((info_p->rowbytes / 4) * info_p->height);
370
    smask_size = (int) ((png_get_rowbytes (png_p, info_p) / 4) * png_get_image_height (png_p, info_p));
370
    smask = xtalloc((unsigned) smask_size, png_byte);
371
    smask = xtalloc((unsigned) smask_size, png_byte);
371
    pdf_begin_stream(pdf);
372
    pdf_begin_stream(pdf);
372
    if (info_p->interlace_type == PNG_INTERLACE_NONE) {
373
    if (png_get_interlace_type (png_p, info_p) == PNG_INTERLACE_NONE) {
373
        row = xtalloc(info_p->rowbytes, png_byte);
374
        row = xtalloc(png_get_rowbytes (png_p, info_p), png_byte);
374
        if ((info_p->bit_depth == 16) && (pdf->image_hicolor != 0)) {
375
        if ((png_get_bit_depth (png_p, info_p) == 16) && (pdf->image_hicolor != 0)) {
375
            write_noninterlaced(write_rgb_pixel_16(r));
376
            write_noninterlaced(write_rgb_pixel_16(r));
376
        } else {
377
        } else {
377
            write_noninterlaced(write_rgb_pixel_8(r));
378
            write_noninterlaced(write_rgb_pixel_8(r));
378
        }
379
        }
379
        xfree(row);
380
        xfree(row);
380
    } else {
381
    } else {
381
        if (info_p->height * info_p->rowbytes >= 10240000L)
382
        if (png_get_image_height (png_p, info_p) * png_get_rowbytes (png_p, info_p) >= 10240000L)
382
            pdftex_warn
383
            pdftex_warn
383
                ("large interlaced PNG might cause out of memory (use non-interlaced PNG to fix this)");
384
                ("large interlaced PNG might cause out of memory (use non-interlaced PNG to fix this)");
384
        rows = xtalloc(info_p->height, png_bytep);
385
        rows = xtalloc(png_get_image_height (png_p, info_p), png_bytep);
385
        for (i = 0; (unsigned) i < info_p->height; i++)
386
        for (i = 0; (unsigned) i < png_get_image_height (png_p, info_p); i++)
386
            rows[i] = xtalloc(info_p->rowbytes, png_byte);
387
            rows[i] = xtalloc(png_get_rowbytes (png_p, info_p), png_byte);
387
        png_read_image(png_p, rows);
388
        png_read_image(png_p, rows);
388
        if ((info_p->bit_depth == 16) && (pdf->image_hicolor != 0)) {
389
        if ((png_get_bit_depth (png_p, info_p) == 16) && (pdf->image_hicolor != 0)) {
389
            write_interlaced(write_rgb_pixel_16(row));
390
            write_interlaced(write_rgb_pixel_16(row));
390
        } else {
391
        } else {
391
            write_interlaced(write_rgb_pixel_8(row));
392
            write_interlaced(write_rgb_pixel_8(row));
Lines 396-409 Link Here
396
    pdf_flush(pdf);
397
    pdf_flush(pdf);
397
    /* now write the Smask object */
398
    /* now write the Smask object */
398
    if (smask_objnum > 0) {
399
    if (smask_objnum > 0) {
399
        bitdepth = (int) info_p->bit_depth;
400
        bitdepth = png_get_bit_depth (png_p, info_p);
400
        pdf_begin_dict(pdf, smask_objnum, 0);
401
        pdf_begin_dict(pdf, smask_objnum, 0);
401
        pdf_puts(pdf, "/Type /XObject\n/Subtype /Image\n");
402
        pdf_puts(pdf, "/Type /XObject\n/Subtype /Image\n");
402
        if (img_attr(idict) != NULL && strlen(img_attr(idict)) > 0)
403
        if (img_attr(idict) != NULL && strlen(img_attr(idict)) > 0)
403
            pdf_printf(pdf, "%s\n", img_attr(idict));
404
            pdf_printf(pdf, "%s\n", img_attr(idict));
404
        pdf_printf(pdf, "/Width %i\n/Height %i\n/BitsPerComponent %i\n",
405
        pdf_printf(pdf, "/Width %u\n/Height %u\n/BitsPerComponent %i\n",
405
                   (int) info_p->width,
406
                   png_get_image_width (png_p, info_p),
406
                   (int) info_p->height, (bitdepth == 16 ? 8 : bitdepth));
407
                   png_get_image_height (png_p, info_p), 
408
                   (bitdepth == 16 ? 8 : bitdepth));
407
        pdf_puts(pdf, "/ColorSpace /DeviceGray\n");
409
        pdf_puts(pdf, "/ColorSpace /DeviceGray\n");
408
        pdf_begin_stream(pdf);
410
        pdf_begin_stream(pdf);
409
        for (i = 0; i < smask_size; i++) {
411
        for (i = 0; i < smask_size; i++) {
Lines 451-457 Link Here
451
    assert(idict != NULL);
453
    assert(idict != NULL);
452
    png_p = img_png_png_ptr(idict);
454
    png_p = img_png_png_ptr(idict);
453
    info_p = img_png_info_ptr(idict);
455
    info_p = img_png_info_ptr(idict);
454
    fp = (FILE *) png_p->io_ptr;
456
    fp = (FILE *) png_get_io_ptr (png_p);
455
    /* 1st pass to find overall stream /Length */
457
    /* 1st pass to find overall stream /Length */
456
    if (fseek(fp, 8, SEEK_SET) != 0)
458
    if (fseek(fp, 8, SEEK_SET) != 0)
457
        pdftex_fail("writepng: fseek in PNG file failed");
459
        pdftex_fail("writepng: fseek in PNG file failed");
Lines 473-483 Link Here
473
               "/Filter/FlateDecode\n"
475
               "/Filter/FlateDecode\n"
474
               "/DecodeParms<<"
476
               "/DecodeParms<<"
475
               "/Colors %d"
477
               "/Colors %d"
476
               "/Columns %d"
478
               "/Columns %u"
477
               "/BitsPerComponent %i"
479
               "/BitsPerComponent %i"
478
               "/Predictor 10>>\n>>\nstream\n", streamlength,
480
               "/Predictor 10>>\n>>\nstream\n", streamlength,
479
               info_p->color_type == 2 ? 3 : 1,
481
               png_get_color_type (png_p, info_p) == 2 ? 3 : 1,
480
               (int) info_p->width, info_p->bit_depth);
482
               png_get_image_width (png_p, info_p), 
483
               png_get_bit_depth (png_p, info_p));
481
    /* 2nd pass to copy data */
484
    /* 2nd pass to copy data */
482
    endflag = false;
485
    endflag = false;
483
    if (fseek(fp, 8, SEEK_SET) != 0)
486
    if (fseek(fp, 8, SEEK_SET) != 0)
Lines 549-557 Link Here
549
    pdf_puts(pdf, "/Type /XObject\n/Subtype /Image\n");
552
    pdf_puts(pdf, "/Type /XObject\n/Subtype /Image\n");
550
    if (img_attr(idict) != NULL && strlen(img_attr(idict)) > 0)
553
    if (img_attr(idict) != NULL && strlen(img_attr(idict)) > 0)
551
        pdf_printf(pdf, "%s\n", img_attr(idict));
554
        pdf_printf(pdf, "%s\n", img_attr(idict));
552
    pdf_printf(pdf, "/Width %i\n/Height %i\n/BitsPerComponent %i\n",
555
    pdf_printf(pdf, "/Width %u\n/Height %u\n/BitsPerComponent %u\n",
553
               (int) info_p->width,
556
               png_get_image_width (png_p, info_p),
554
               (int) info_p->height, (int) info_p->bit_depth);
557
               png_get_image_height (png_p, info_p), 
558
               png_get_bit_depth (png_p, info_p));
555
    pdf_puts(pdf, "/ColorSpace ");
559
    pdf_puts(pdf, "/ColorSpace ");
556
    checked_gamma = 1.0;
560
    checked_gamma = 1.0;
557
    if (pdf->image_apply_gamma) {
561
    if (pdf->image_apply_gamma) {
Lines 563-578 Link Here
563
    }
567
    }
564
    /* the switching between |info_p| and |png_p| queries has been trial and error.
568
    /* the switching between |info_p| and |png_p| queries has been trial and error.
565
     */
569
     */
566
    if (pdf->minor_version > 1 && info_p->interlace_type == PNG_INTERLACE_NONE && (png_p->transformations == 0 || png_p->transformations == 0x2000)     /* gamma */
570
    if (pdf->minor_version > 1 
567
        &&!(png_p->color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
571
           && png_get_interlace_type (png_p, info_p) == PNG_INTERLACE_NONE 
568
            png_p->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
572
           && (png_p->transformations == 0 || png_p->transformations == 0x2000)     /* gamma */
569
        && ((pdf->image_hicolor != 0) || (png_p->bit_depth <= 8))
573
        &&!(png_get_color_type (png_p, info_p) == PNG_COLOR_TYPE_GRAY_ALPHA ||
574
            png_get_color_type (png_p, info_p) == PNG_COLOR_TYPE_RGB_ALPHA)
575
        && ((pdf->image_hicolor != 0) || (png_get_bit_depth (png_p, info_p) <= 8))
570
        && (checked_gamma <= 1.01 && checked_gamma > 0.99)
576
        && (checked_gamma <= 1.01 && checked_gamma > 0.99)
571
        ) {
577
        ) {
572
        if (img_colorspace(idict) != 0) {
578
        if (img_colorspace(idict) != 0) {
573
            pdf_printf(pdf, "%i 0 R\n", (int) img_colorspace(idict));
579
            pdf_printf(pdf, "%i 0 R\n", (int) img_colorspace(idict));
574
        } else {
580
        } else {
575
            switch (info_p->color_type) {
581
            switch (png_get_color_type (png_p, info_p)) {
576
            case PNG_COLOR_TYPE_PALETTE:
582
            case PNG_COLOR_TYPE_PALETTE:
577
                palette_objnum = pdf_create_obj(pdf, obj_type_others, 0);
583
                palette_objnum = pdf_create_obj(pdf, obj_type_others, 0);
578
                pdf_printf(pdf, "[/Indexed /DeviceRGB %i %i 0 R]\n",
584
                pdf_printf(pdf, "[/Indexed /DeviceRGB %i %i 0 R]\n",
Lines 608-627 Link Here
608
                tex_printf("gamma delta=%lf ", checked_gamma);
614
                tex_printf("gamma delta=%lf ", checked_gamma);
609
            if (png_p->transformations != PNG_TRANSFORM_IDENTITY)
615
            if (png_p->transformations != PNG_TRANSFORM_IDENTITY)
610
                tex_printf("transform=%lu", (long) png_p->transformations);
616
                tex_printf("transform=%lu", (long) png_p->transformations);
611
            if ((info_p->color_type != PNG_COLOR_TYPE_GRAY)
617
            if ((png_get_color_type (png_p, info_p) != PNG_COLOR_TYPE_GRAY)
612
                && (info_p->color_type != PNG_COLOR_TYPE_RGB)
618
                && (png_get_color_type (png_p, info_p) != PNG_COLOR_TYPE_RGB)
613
                && (info_p->color_type != PNG_COLOR_TYPE_PALETTE))
619
                && (png_get_color_type (png_p, info_p) != PNG_COLOR_TYPE_PALETTE))
614
                tex_printf("colortype ");
620
                tex_printf("colortype ");
615
            if (pdf->minor_version <= 1)
621
            if (pdf->minor_version <= 1)
616
                tex_printf("version=%d ", pdf->minor_version);
622
                tex_printf("version=%d ", pdf->minor_version);
617
            if (info_p->interlace_type != PNG_INTERLACE_NONE)
623
            if (png_get_interlace_type (png_p, info_p) != PNG_INTERLACE_NONE)
618
                tex_printf("interlaced ");
624
                tex_printf("interlaced ");
619
            if (info_p->bit_depth > 8)
625
            if (png_get_bit_depth (png_p, info_p) > 8)
620
                tex_printf("bitdepth=%d ", info_p->bit_depth);
626
                tex_printf("bitdepth=%d ", png_get_bit_depth (png_p, info_p));
621
            if (png_get_valid(png_p, info_p, PNG_INFO_tRNS))
627
            if (png_get_valid(png_p, info_p, PNG_INFO_tRNS))
622
                tex_printf("simple transparancy ");
628
                tex_printf("simple transparancy ");
623
        }
629
        }
624
        switch (info_p->color_type) {
630
        switch (png_get_color_type (png_p, info_p)) {
625
        case PNG_COLOR_TYPE_PALETTE:
631
        case PNG_COLOR_TYPE_PALETTE:
626
            write_png_palette(pdf, idict);
632
            write_png_palette(pdf, idict);
627
            break;
633
            break;
Lines 647-653 Link Here
647
            break;
653
            break;
648
        default:
654
        default:
649
            pdftex_fail("unsupported type of color_type <%i>",
655
            pdftex_fail("unsupported type of color_type <%i>",
650
                        info_p->color_type);
656
                        png_get_color_type (png_p, info_p));
651
        }
657
        }
652
    }
658
    }
653
    pdf_flush(pdf);
659
    pdf_flush(pdf);

Return to bug 355091