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

(-)texk/web2c/luatexdir/image/writepng.w.orig (-92 / +103 lines)
Lines 67-73 void read_png_info(PDF pdf, image_dict * Link Here
67
    if ((info_p = png_create_info_struct(png_p)) == NULL)
67
    if ((info_p = png_create_info_struct(png_p)) == NULL)
68
        pdftex_fail("libpng: png_create_info_struct() failed");
68
        pdftex_fail("libpng: png_create_info_struct() failed");
69
    img_png_info_ptr(idict) = info_p;
69
    img_png_info_ptr(idict) = info_p;
70
    if (setjmp(png_p->jmpbuf))
70
    if (setjmp(png_jmpbuf(png_p)))
71
        pdftex_fail("libpng: internal error");
71
        pdftex_fail("libpng: internal error");
72
    png_init_io(png_p, img_file(idict));
72
    png_init_io(png_p, img_file(idict));
73
    png_read_info(png_p, info_p);
73
    png_read_info(png_p, info_p);
Lines 76-87 void read_png_info(PDF pdf, image_dict * 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 void read_png_info(PDF pdf, image_dict * 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 (png_get_valid(png_p, info_p, 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 void read_png_info(PDF pdf, image_dict * 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 void read_png_info(PDF pdf, image_dict * 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 void read_png_info(PDF pdf, image_dict * 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 179-203 static void write_png_palette(PDF pdf, i Link Here
179
    png_infop info_p = img_png_info_ptr(idict);
179
    png_infop info_p = img_png_info_ptr(idict);
180
    png_bytep row, r, *rows;
180
    png_bytep row, r, *rows;
181
    int palette_objnum = 0;
181
    int palette_objnum = 0;
182
    png_colorp palette;
183
    int num_palette;
184
185
    png_get_PLTE(png_p, info_p, &palette, &num_palette);
186
182
    if (img_colorspace(idict) != 0) {
187
    if (img_colorspace(idict) != 0) {
183
        pdf_printf(pdf, "%i 0 R\n", (int) img_colorspace(idict));
188
        pdf_printf(pdf, "%i 0 R\n", (int) img_colorspace(idict));
184
    } else {
189
    } else {
185
        palette_objnum = pdf_create_obj(pdf, obj_type_others, 0);
190
        palette_objnum = pdf_create_obj(pdf, obj_type_others, 0);
186
        pdf_printf(pdf, "[/Indexed /DeviceRGB %i %i 0 R]\n",
191
        pdf_printf(pdf, "[/Indexed /DeviceRGB %i %i 0 R]\n",
187
                   (int) (info_p->num_palette - 1), (int) palette_objnum);
192
                   num_palette - 1, (int) palette_objnum);
188
    }
193
    }
189
    pdf_begin_stream(pdf);
194
    pdf_begin_stream(pdf);
190
    if (info_p->interlace_type == PNG_INTERLACE_NONE) {
195
    if (png_get_interlace_type (png_p, info_p) == PNG_INTERLACE_NONE) {
191
        row = xtalloc(info_p->rowbytes, png_byte);
196
        row = xtalloc(png_get_rowbytes (png_p, info_p), png_byte);
192
        write_noninterlaced(write_simple_pixel(r));
197
        write_noninterlaced(write_simple_pixel(r));
193
        xfree(row);
198
        xfree(row);
194
    } else {
199
    } else {
195
        if (info_p->height * info_p->rowbytes >= 10240000L)
200
        if (png_get_image_height (png_p, info_p) * png_get_rowbytes (png_p, info_p) >= 10240000L)
196
            pdftex_warn
201
            pdftex_warn
197
                ("large interlaced PNG might cause out of memory (use non-interlaced PNG to fix this)");
202
                ("large interlaced PNG might cause out of memory (use non-interlaced PNG to fix this)");
198
        rows = xtalloc(info_p->height, png_bytep);
203
        rows = xtalloc(png_get_image_height (png_p, info_p), png_bytep);
199
        for (i = 0; (unsigned) i < info_p->height; i++)
204
        for (i = 0; (unsigned) i < png_get_image_height (png_p, info_p); i++)
200
            rows[i] = xtalloc(info_p->rowbytes, png_byte);
205
            rows[i] = xtalloc(png_get_rowbytes (png_p, info_p), png_byte);
201
        png_read_image(png_p, rows);
206
        png_read_image(png_p, rows);
202
        write_interlaced(write_simple_pixel(row));
207
        write_interlaced(write_simple_pixel(row));
203
        xfree(rows);
208
        xfree(rows);
Lines 206-216 static void write_png_palette(PDF pdf, i Link Here
206
    if (palette_objnum > 0) {
211
    if (palette_objnum > 0) {
207
        pdf_begin_dict(pdf, palette_objnum, 0);
212
        pdf_begin_dict(pdf, palette_objnum, 0);
208
        pdf_begin_stream(pdf);
213
        pdf_begin_stream(pdf);
209
        for (i = 0; (unsigned) i < info_p->num_palette; i++) {
214
        for (i = 0; (unsigned) i < num_palette; i++) {
210
            pdf_room(pdf, 3);
215
            pdf_room(pdf, 3);
211
            pdf_quick_out(pdf, info_p->palette[i].red);
216
            pdf_quick_out(pdf, palette[i].red);
212
            pdf_quick_out(pdf, info_p->palette[i].green);
217
            pdf_quick_out(pdf, palette[i].green);
213
            pdf_quick_out(pdf, info_p->palette[i].blue);
218
            pdf_quick_out(pdf, palette[i].blue);
214
        }
219
        }
215
        pdf_end_stream(pdf);
220
        pdf_end_stream(pdf);
216
    }
221
    }
Lines 229-245 static void write_png_gray(PDF pdf, imag Link Here
229
        pdf_puts(pdf, "/DeviceGray\n");
234
        pdf_puts(pdf, "/DeviceGray\n");
230
    }
235
    }
231
    pdf_begin_stream(pdf);
236
    pdf_begin_stream(pdf);
232
    if (info_p->interlace_type == PNG_INTERLACE_NONE) {
237
    if (png_get_interlace_type (png_p, info_p) == PNG_INTERLACE_NONE) {
233
        row = xtalloc(info_p->rowbytes, png_byte);
238
        row = xtalloc(png_get_rowbytes (png_p, info_p), png_byte);
234
        write_noninterlaced(write_simple_pixel(r));
239
        write_noninterlaced(write_simple_pixel(r));
235
        xfree(row);
240
        xfree(row);
236
    } else {
241
    } else {
237
        if (info_p->height * info_p->rowbytes >= 10240000L)
242
        if (png_get_image_height (png_p, info_p) * png_get_rowbytes (png_p, info_p) >= 10240000L)
238
            pdftex_warn
243
            pdftex_warn
239
                ("large interlaced PNG might cause out of memory (use non-interlaced PNG to fix this)");
244
                ("large interlaced PNG might cause out of memory (use non-interlaced PNG to fix this)");
240
        rows = xtalloc(info_p->height, png_bytep);
245
        rows = xtalloc(png_get_image_height (png_p, info_p), png_bytep);
241
        for (i = 0; (unsigned) i < info_p->height; i++)
246
        for (i = 0; (unsigned) i < png_get_image_height (png_p, info_p); i++)
242
            rows[i] = xtalloc(info_p->rowbytes, png_byte);
247
            rows[i] = xtalloc(png_get_rowbytes (png_p, info_p), png_byte);
243
        png_read_image(png_p, rows);
248
        png_read_image(png_p, rows);
244
        write_interlaced(write_simple_pixel(row));
249
        write_interlaced(write_simple_pixel(row));
245
        xfree(rows);
250
        xfree(rows);
Lines 258-264 static void write_png_gray_alpha(PDF pdf Link Here
258
    png_bytep smask;
263
    png_bytep smask;
259
    int smask_ptr = 0;
264
    int smask_ptr = 0;
260
    int smask_size = 0;
265
    int smask_size = 0;
261
    int bitdepth;
266
    png_byte bitdepth;
262
    if (img_colorspace(idict) != 0) {
267
    if (img_colorspace(idict) != 0) {
263
        pdf_printf(pdf, "%i 0 R\n", (int) img_colorspace(idict));
268
        pdf_printf(pdf, "%i 0 R\n", (int) img_colorspace(idict));
264
    } else {
269
    } else {
Lines 266-291 static void write_png_gray_alpha(PDF pdf Link Here
266
    }
271
    }
267
    smask_objnum = pdf_create_obj(pdf, obj_type_others, 0);
272
    smask_objnum = pdf_create_obj(pdf, obj_type_others, 0);
268
    pdf_printf(pdf, "/SMask %i 0 R\n", (int) smask_objnum);
273
    pdf_printf(pdf, "/SMask %i 0 R\n", (int) smask_objnum);
269
    smask_size = (int) ((info_p->rowbytes / 2) * info_p->height);
274
    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);
275
    smask = xtalloc((unsigned) smask_size, png_byte);
271
    pdf_begin_stream(pdf);
276
    pdf_begin_stream(pdf);
272
    if (info_p->interlace_type == PNG_INTERLACE_NONE) {
277
    if (png_get_interlace_type (png_p, info_p) == PNG_INTERLACE_NONE) {
273
        row = xtalloc(info_p->rowbytes, png_byte);
278
        row = xtalloc(png_get_rowbytes (png_p, info_p), png_byte);
274
        if ((info_p->bit_depth == 16) && (pdf->image_hicolor != 0)) {
279
        if ((png_get_bit_depth (png_p, info_p) == 16) && (pdf->image_hicolor != 0)) {
275
            write_noninterlaced(write_gray_pixel_16(r));
280
            write_noninterlaced(write_gray_pixel_16(r));
276
        } else {
281
        } else {
277
            write_noninterlaced(write_gray_pixel_8(r));
282
            write_noninterlaced(write_gray_pixel_8(r));
278
        }
283
        }
279
        xfree(row);
284
        xfree(row);
280
    } else {
285
    } else {
281
        if (info_p->height * info_p->rowbytes >= 10240000L)
286
        if (png_get_image_height (png_p, info_p) * png_get_rowbytes (png_p, info_p) >= 10240000L)
282
            pdftex_warn
287
            pdftex_warn
283
                ("large interlaced PNG might cause out of memory (use non-interlaced PNG to fix this)");
288
                ("large interlaced PNG might cause out of memory (use non-interlaced PNG to fix this)");
284
        rows = xtalloc(info_p->height, png_bytep);
289
        rows = xtalloc(png_get_image_height (png_p, info_p), png_bytep);
285
        for (i = 0; (unsigned) i < info_p->height; i++)
290
        for (i = 0; (unsigned) i < png_get_image_height (png_p, info_p); i++)
286
            rows[i] = xtalloc(info_p->rowbytes, png_byte);
291
            rows[i] = xtalloc(png_get_rowbytes (png_p, info_p), png_byte);
287
        png_read_image(png_p, rows);
292
        png_read_image(png_p, rows);
288
        if ((info_p->bit_depth == 16) && (pdf->image_hicolor != 0)) {
293
        if ((png_get_bit_depth (png_p, info_p) == 16) && (pdf->image_hicolor != 0)) {
289
            write_interlaced(write_gray_pixel_16(row));
294
            write_interlaced(write_gray_pixel_16(row));
290
        } else {
295
        } else {
291
            write_interlaced(write_gray_pixel_8(row));
296
            write_interlaced(write_gray_pixel_8(row));
Lines 295-308 static void write_png_gray_alpha(PDF pdf Link Here
295
    pdf_end_stream(pdf);
300
    pdf_end_stream(pdf);
296
    pdf_flush(pdf);
301
    pdf_flush(pdf);
297
    /* now write the Smask object */
302
    /* now write the Smask object */
298
    bitdepth = (int) info_p->bit_depth;
303
    bitdepth = png_get_bit_depth (png_p, info_p);
299
    pdf_begin_dict(pdf, smask_objnum, 0);
304
    pdf_begin_dict(pdf, smask_objnum, 0);
300
    pdf_puts(pdf, "/Type /XObject\n/Subtype /Image\n");
305
    pdf_puts(pdf, "/Type /XObject\n/Subtype /Image\n");
301
    if (img_attr(idict) != NULL && strlen(img_attr(idict)) > 0)
306
    if (img_attr(idict) != NULL && strlen(img_attr(idict)) > 0)
302
        pdf_printf(pdf, "%s\n", img_attr(idict));
307
        pdf_printf(pdf, "%s\n", img_attr(idict));
303
    pdf_printf(pdf, "/Width %i\n/Height %i\n/BitsPerComponent %i\n",
308
    pdf_printf(pdf, "/Width %u\n/Height %i\n/BitsPerComponent %u\n",
304
               (int) info_p->width,
309
               png_get_image_width (png_p, info_p),
305
               (int) info_p->height, (bitdepth == 16 ? 8 : bitdepth));
310
               png_get_image_height (png_p, info_p), 
311
               (bitdepth == 16 ? 8 : bitdepth));
306
    pdf_puts(pdf, "/ColorSpace /DeviceGray\n");
312
    pdf_puts(pdf, "/ColorSpace /DeviceGray\n");
307
    pdf_begin_stream(pdf);
313
    pdf_begin_stream(pdf);
308
    for (i = 0; i < smask_size; i++) {
314
    for (i = 0; i < smask_size; i++) {
Lines 329-345 static void write_png_rgb(PDF pdf, image Link Here
329
        pdf_puts(pdf, "/DeviceRGB\n");
335
        pdf_puts(pdf, "/DeviceRGB\n");
330
    }
336
    }
331
    pdf_begin_stream(pdf);
337
    pdf_begin_stream(pdf);
332
    if (info_p->interlace_type == PNG_INTERLACE_NONE) {
338
    if (png_get_interlace_type (png_p, info_p) == PNG_INTERLACE_NONE) {
333
        row = xtalloc(info_p->rowbytes, png_byte);
339
        row = xtalloc(png_get_rowbytes (png_p, info_p), png_byte);
334
        write_noninterlaced(write_simple_pixel(r));
340
        write_noninterlaced(write_simple_pixel(r));
335
        xfree(row);
341
        xfree(row);
336
    } else {
342
    } else {
337
        if (info_p->height * info_p->rowbytes >= 10240000L)
343
        if (png_get_image_height (png_p, info_p) * png_get_rowbytes (png_p, info_p) >= 10240000L)
338
            pdftex_warn
344
            pdftex_warn
339
                ("large interlaced PNG might cause out of memory (use non-interlaced PNG to fix this)");
345
                ("large interlaced PNG might cause out of memory (use non-interlaced PNG to fix this)");
340
        rows = xtalloc(info_p->height, png_bytep);
346
        rows = xtalloc(png_get_image_height (png_p, info_p), png_bytep);
341
        for (i = 0; (unsigned) i < info_p->height; i++)
347
        for (i = 0; (unsigned) i < png_get_image_height (png_p, info_p); i++)
342
            rows[i] = xtalloc(info_p->rowbytes, png_byte);
348
            rows[i] = xtalloc(png_get_rowbytes (png_p, info_p), png_byte);
343
        png_read_image(png_p, rows);
349
        png_read_image(png_p, rows);
344
        write_interlaced(write_simple_pixel(row));
350
        write_interlaced(write_simple_pixel(row));
345
        xfree(rows);
351
        xfree(rows);
Lines 358-364 static void write_png_rgb_alpha(PDF pdf, Link Here
358
    png_bytep smask;
364
    png_bytep smask;
359
    int smask_ptr = 0;
365
    int smask_ptr = 0;
360
    int smask_size = 0;
366
    int smask_size = 0;
361
    int bitdepth;
367
    png_byte bitdepth;
362
    if (img_colorspace(idict) != 0) {
368
    if (img_colorspace(idict) != 0) {
363
        pdf_printf(pdf, "%i 0 R\n", (int) img_colorspace(idict));
369
        pdf_printf(pdf, "%i 0 R\n", (int) img_colorspace(idict));
364
    } else {
370
    } else {
Lines 366-391 static void write_png_rgb_alpha(PDF pdf, Link Here
366
    }
372
    }
367
    smask_objnum = pdf_create_obj(pdf, obj_type_others, 0);
373
    smask_objnum = pdf_create_obj(pdf, obj_type_others, 0);
368
    pdf_printf(pdf, "/SMask %i 0 R\n", (int) smask_objnum);
374
    pdf_printf(pdf, "/SMask %i 0 R\n", (int) smask_objnum);
369
    smask_size = (int) ((info_p->rowbytes / 4) * info_p->height);
375
    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);
376
    smask = xtalloc((unsigned) smask_size, png_byte);
371
    pdf_begin_stream(pdf);
377
    pdf_begin_stream(pdf);
372
    if (info_p->interlace_type == PNG_INTERLACE_NONE) {
378
    if (png_get_interlace_type (png_p, info_p) == PNG_INTERLACE_NONE) {
373
        row = xtalloc(info_p->rowbytes, png_byte);
379
        row = xtalloc(png_get_rowbytes (png_p, info_p), png_byte);
374
        if ((info_p->bit_depth == 16) && (pdf->image_hicolor != 0)) {
380
        if ((png_get_bit_depth (png_p, info_p) == 16) && (pdf->image_hicolor != 0)) {
375
            write_noninterlaced(write_rgb_pixel_16(r));
381
            write_noninterlaced(write_rgb_pixel_16(r));
376
        } else {
382
        } else {
377
            write_noninterlaced(write_rgb_pixel_8(r));
383
            write_noninterlaced(write_rgb_pixel_8(r));
378
        }
384
        }
379
        xfree(row);
385
        xfree(row);
380
    } else {
386
    } else {
381
        if (info_p->height * info_p->rowbytes >= 10240000L)
387
        if (png_get_image_height (png_p, info_p) * png_get_rowbytes (png_p, info_p) >= 10240000L)
382
            pdftex_warn
388
            pdftex_warn
383
                ("large interlaced PNG might cause out of memory (use non-interlaced PNG to fix this)");
389
                ("large interlaced PNG might cause out of memory (use non-interlaced PNG to fix this)");
384
        rows = xtalloc(info_p->height, png_bytep);
390
        rows = xtalloc(png_get_image_height (png_p, info_p), png_bytep);
385
        for (i = 0; (unsigned) i < info_p->height; i++)
391
        for (i = 0; (unsigned) i < png_get_image_height (png_p, info_p); i++)
386
            rows[i] = xtalloc(info_p->rowbytes, png_byte);
392
            rows[i] = xtalloc(png_get_rowbytes (png_p, info_p), png_byte);
387
        png_read_image(png_p, rows);
393
        png_read_image(png_p, rows);
388
        if ((info_p->bit_depth == 16) && (pdf->image_hicolor != 0)) {
394
        if ((png_get_bit_depth (png_p, info_p) == 16) && (pdf->image_hicolor != 0)) {
389
            write_interlaced(write_rgb_pixel_16(row));
395
            write_interlaced(write_rgb_pixel_16(row));
390
        } else {
396
        } else {
391
            write_interlaced(write_rgb_pixel_8(row));
397
            write_interlaced(write_rgb_pixel_8(row));
Lines 396-409 static void write_png_rgb_alpha(PDF pdf, Link Here
396
    pdf_flush(pdf);
402
    pdf_flush(pdf);
397
    /* now write the Smask object */
403
    /* now write the Smask object */
398
    if (smask_objnum > 0) {
404
    if (smask_objnum > 0) {
399
        bitdepth = (int) info_p->bit_depth;
405
        bitdepth = png_get_bit_depth (png_p, info_p);
400
        pdf_begin_dict(pdf, smask_objnum, 0);
406
        pdf_begin_dict(pdf, smask_objnum, 0);
401
        pdf_puts(pdf, "/Type /XObject\n/Subtype /Image\n");
407
        pdf_puts(pdf, "/Type /XObject\n/Subtype /Image\n");
402
        if (img_attr(idict) != NULL && strlen(img_attr(idict)) > 0)
408
        if (img_attr(idict) != NULL && strlen(img_attr(idict)) > 0)
403
            pdf_printf(pdf, "%s\n", img_attr(idict));
409
            pdf_printf(pdf, "%s\n", img_attr(idict));
404
        pdf_printf(pdf, "/Width %i\n/Height %i\n/BitsPerComponent %i\n",
410
        pdf_printf(pdf, "/Width %u\n/Height %u\n/BitsPerComponent %i\n",
405
                   (int) info_p->width,
411
                   png_get_image_width (png_p, info_p),
406
                   (int) info_p->height, (bitdepth == 16 ? 8 : bitdepth));
412
                   png_get_image_height (png_p, info_p), 
413
                   (bitdepth == 16 ? 8 : bitdepth));
407
        pdf_puts(pdf, "/ColorSpace /DeviceGray\n");
414
        pdf_puts(pdf, "/ColorSpace /DeviceGray\n");
408
        pdf_begin_stream(pdf);
415
        pdf_begin_stream(pdf);
409
        for (i = 0; i < smask_size; i++) {
416
        for (i = 0; i < smask_size; i++) {
Lines 451-457 static void copy_png(PDF pdf, image_dict Link Here
451
    assert(idict != NULL);
458
    assert(idict != NULL);
452
    png_p = img_png_png_ptr(idict);
459
    png_p = img_png_png_ptr(idict);
453
    info_p = img_png_info_ptr(idict);
460
    info_p = img_png_info_ptr(idict);
454
    fp = (FILE *) png_p->io_ptr;
461
    fp = (FILE *) png_get_io_ptr (png_p);
455
    /* 1st pass to find overall stream /Length */
462
    /* 1st pass to find overall stream /Length */
456
    if (fseek(fp, 8, SEEK_SET) != 0)
463
    if (fseek(fp, 8, SEEK_SET) != 0)
457
        pdftex_fail("writepng: fseek in PNG file failed");
464
        pdftex_fail("writepng: fseek in PNG file failed");
Lines 473-483 static void copy_png(PDF pdf, image_dict Link Here
473
               "/Filter/FlateDecode\n"
480
               "/Filter/FlateDecode\n"
474
               "/DecodeParms<<"
481
               "/DecodeParms<<"
475
               "/Colors %d"
482
               "/Colors %d"
476
               "/Columns %d"
483
               "/Columns %u"
477
               "/BitsPerComponent %i"
484
               "/BitsPerComponent %i"
478
               "/Predictor 10>>\n>>\nstream\n", streamlength,
485
               "/Predictor 10>>\n>>\nstream\n", streamlength,
479
               info_p->color_type == 2 ? 3 : 1,
486
               png_get_color_type (png_p, info_p) == 2 ? 3 : 1,
480
               (int) info_p->width, info_p->bit_depth);
487
               png_get_image_width (png_p, info_p), 
488
               png_get_bit_depth (png_p, info_p));
481
    /* 2nd pass to copy data */
489
    /* 2nd pass to copy data */
482
    endflag = false;
490
    endflag = false;
483
    if (fseek(fp, 8, SEEK_SET) != 0)
491
    if (fseek(fp, 8, SEEK_SET) != 0)
Lines 549-557 void write_png(PDF pdf, image_dict * idi Link Here
549
    pdf_puts(pdf, "/Type /XObject\n/Subtype /Image\n");
557
    pdf_puts(pdf, "/Type /XObject\n/Subtype /Image\n");
550
    if (img_attr(idict) != NULL && strlen(img_attr(idict)) > 0)
558
    if (img_attr(idict) != NULL && strlen(img_attr(idict)) > 0)
551
        pdf_printf(pdf, "%s\n", img_attr(idict));
559
        pdf_printf(pdf, "%s\n", img_attr(idict));
552
    pdf_printf(pdf, "/Width %i\n/Height %i\n/BitsPerComponent %i\n",
560
    pdf_printf(pdf, "/Width %u\n/Height %u\n/BitsPerComponent %u\n",
553
               (int) info_p->width,
561
               png_get_image_width (png_p, info_p),
554
               (int) info_p->height, (int) info_p->bit_depth);
562
               png_get_image_height (png_p, info_p), 
563
               png_get_bit_depth (png_p, info_p));
555
    pdf_puts(pdf, "/ColorSpace ");
564
    pdf_puts(pdf, "/ColorSpace ");
556
    checked_gamma = 1.0;
565
    checked_gamma = 1.0;
557
    if (pdf->image_apply_gamma) {
566
    if (pdf->image_apply_gamma) {
Lines 563-583 void write_png(PDF pdf, image_dict * idi Link Here
563
    }
572
    }
564
    /* the switching between |info_p| and |png_p| queries has been trial and error.
573
    /* the switching between |info_p| and |png_p| queries has been trial and error.
565
     */
574
     */
566
    if (pdf->minor_version > 1 && info_p->interlace_type == PNG_INTERLACE_NONE && (png_p->transformations == 0 || png_p->transformations == 0x2000)     /* gamma */
575
    if (pdf->minor_version > 1 
567
        &&!(png_p->color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
576
           && png_get_interlace_type (png_p, info_p) == PNG_INTERLACE_NONE 
568
            png_p->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
577
        &&!(png_get_color_type (png_p, info_p) == PNG_COLOR_TYPE_GRAY_ALPHA ||
569
        && ((pdf->image_hicolor != 0) || (png_p->bit_depth <= 8))
578
            png_get_color_type (png_p, info_p) == PNG_COLOR_TYPE_RGB_ALPHA)
579
        && ((pdf->image_hicolor != 0) || (png_get_bit_depth (png_p, info_p) <= 8))
570
        && (checked_gamma <= 1.01 && checked_gamma > 0.99)
580
        && (checked_gamma <= 1.01 && checked_gamma > 0.99)
571
        ) {
581
        ) {
582
        png_colorp palette;
583
        int num_palette;
584
585
        png_get_PLTE(png_p, info_p, &palette, &num_palette);
572
        if (img_colorspace(idict) != 0) {
586
        if (img_colorspace(idict) != 0) {
573
            pdf_printf(pdf, "%i 0 R\n", (int) img_colorspace(idict));
587
            pdf_printf(pdf, "%i 0 R\n", (int) img_colorspace(idict));
574
        } else {
588
        } else {
575
            switch (info_p->color_type) {
589
            switch (png_get_color_type (png_p, info_p)) {
576
            case PNG_COLOR_TYPE_PALETTE:
590
            case PNG_COLOR_TYPE_PALETTE:
577
                palette_objnum = pdf_create_obj(pdf, obj_type_others, 0);
591
                palette_objnum = pdf_create_obj(pdf, obj_type_others, 0);
578
                pdf_printf(pdf, "[/Indexed /DeviceRGB %i %i 0 R]\n",
592
                pdf_printf(pdf, "[/Indexed /DeviceRGB %i %i 0 R]\n",
579
                           (int) (info_p->num_palette - 1),
593
                           num_palette - 1, (int) palette_objnum);
580
                           (int) palette_objnum);
581
                break;
594
                break;
582
            case PNG_COLOR_TYPE_GRAY:
595
            case PNG_COLOR_TYPE_GRAY:
583
                pdf_puts(pdf, "/DeviceGray\n");
596
                pdf_puts(pdf, "/DeviceGray\n");
Lines 592-602 void write_png(PDF pdf, image_dict * idi Link Here
592
        if (palette_objnum > 0) {
605
        if (palette_objnum > 0) {
593
            pdf_begin_dict(pdf, palette_objnum, 0);
606
            pdf_begin_dict(pdf, palette_objnum, 0);
594
            pdf_begin_stream(pdf);
607
            pdf_begin_stream(pdf);
595
            for (i = 0; (unsigned) i < info_p->num_palette; i++) {
608
            for (i = 0; (unsigned) i < num_palette; i++) {
596
                pdf_room(pdf, 3);
609
                pdf_room(pdf, 3);
597
                pdf_quick_out(pdf, info_p->palette[i].red);
610
                pdf_quick_out(pdf, palette[i].red);
598
                pdf_quick_out(pdf, info_p->palette[i].green);
611
                pdf_quick_out(pdf, palette[i].green);
599
                pdf_quick_out(pdf, info_p->palette[i].blue);
612
                pdf_quick_out(pdf, palette[i].blue);
600
            }
613
            }
601
            pdf_end_stream(pdf);
614
            pdf_end_stream(pdf);
602
        }
615
        }
Lines 606-627 void write_png(PDF pdf, image_dict * idi Link Here
606
            if ((pdf->image_apply_gamma != 0) &&
619
            if ((pdf->image_apply_gamma != 0) &&
607
                (checked_gamma > 1.01 || checked_gamma < 0.99))
620
                (checked_gamma > 1.01 || checked_gamma < 0.99))
608
                tex_printf("gamma delta=%lf ", checked_gamma);
621
                tex_printf("gamma delta=%lf ", checked_gamma);
609
            if (png_p->transformations != PNG_TRANSFORM_IDENTITY)
622
            if ((png_get_color_type (png_p, info_p) != PNG_COLOR_TYPE_GRAY)
610
                tex_printf("transform=%lu", (long) png_p->transformations);
623
                && (png_get_color_type (png_p, info_p) != PNG_COLOR_TYPE_RGB)
611
            if ((info_p->color_type != PNG_COLOR_TYPE_GRAY)
624
                && (png_get_color_type (png_p, info_p) != PNG_COLOR_TYPE_PALETTE))
612
                && (info_p->color_type != PNG_COLOR_TYPE_RGB)
613
                && (info_p->color_type != PNG_COLOR_TYPE_PALETTE))
614
                tex_printf("colortype ");
625
                tex_printf("colortype ");
615
            if (pdf->minor_version <= 1)
626
            if (pdf->minor_version <= 1)
616
                tex_printf("version=%d ", pdf->minor_version);
627
                tex_printf("version=%d ", pdf->minor_version);
617
            if (info_p->interlace_type != PNG_INTERLACE_NONE)
628
            if (png_get_interlace_type (png_p, info_p) != PNG_INTERLACE_NONE)
618
                tex_printf("interlaced ");
629
                tex_printf("interlaced ");
619
            if (info_p->bit_depth > 8)
630
            if (png_get_bit_depth (png_p, info_p) > 8)
620
                tex_printf("bitdepth=%d ", info_p->bit_depth);
631
                tex_printf("bitdepth=%d ", png_get_bit_depth (png_p, info_p));
621
            if (png_get_valid(png_p, info_p, PNG_INFO_tRNS))
632
            if (png_get_valid(png_p, info_p, PNG_INFO_tRNS))
622
                tex_printf("simple transparancy ");
633
                tex_printf("simple transparancy ");
623
        }
634
        }
624
        switch (info_p->color_type) {
635
        switch (png_get_color_type (png_p, info_p)) {
625
        case PNG_COLOR_TYPE_PALETTE:
636
        case PNG_COLOR_TYPE_PALETTE:
626
            write_png_palette(pdf, idict);
637
            write_png_palette(pdf, idict);
627
            break;
638
            break;
Lines 647-653 void write_png(PDF pdf, image_dict * idi Link Here
647
            break;
658
            break;
648
        default:
659
        default:
649
            pdftex_fail("unsupported type of color_type <%i>",
660
            pdftex_fail("unsupported type of color_type <%i>",
650
                        info_p->color_type);
661
                        png_get_color_type (png_p, info_p));
651
        }
662
        }
652
    }
663
    }
653
    pdf_flush(pdf);
664
    pdf_flush(pdf);

Return to bug 355091