Lines 36-47
Link Here
|
36 |
#include "gdevpccm.h" |
36 |
#include "gdevpccm.h" |
37 |
#include "gscdefs.h" |
37 |
#include "gscdefs.h" |
38 |
|
38 |
|
39 |
#define PNG_INTERNAL |
|
|
40 |
/* |
39 |
/* |
41 |
* libpng versions 1.0.3 and later allow disabling access to the stdxxx |
40 |
* libpng versions 1.0.3 and later allow disabling access to the stdxxx |
42 |
* files while retaining support for FILE * I/O. |
41 |
* files while retaining support for FILE * I/O. |
|
|
42 |
* |
43 |
* This is a misunderstanding - this is a build time option for libpng, |
44 |
* it has no effect on a user of libpng. |
43 |
*/ |
45 |
*/ |
44 |
#define PNG_NO_CONSOLE_IO |
46 |
/*#define PNG_NO_CONSOLE_IO*/ |
45 |
/* |
47 |
/* |
46 |
* Earlier libpng versions require disabling FILE * I/O altogether. |
48 |
* Earlier libpng versions require disabling FILE * I/O altogether. |
47 |
* This produces a compiler warning about no prototype for png_init_io. |
49 |
* This produces a compiler warning about no prototype for png_init_io. |
Lines 280-286
png_print_page(gx_device_printer * pdev,
Link Here
|
280 |
goto done; |
282 |
goto done; |
281 |
} |
283 |
} |
282 |
/* set error handling */ |
284 |
/* set error handling */ |
283 |
if (setjmp(png_ptr->jmpbuf)) { |
285 |
if (setjmp(png_jmpbuf(png_ptr))) { |
284 |
/* If we get here, we had a problem reading the file */ |
286 |
/* If we get here, we had a problem reading the file */ |
285 |
code = gs_note_error(gs_error_VMerror); |
287 |
code = gs_note_error(gs_error_VMerror); |
286 |
goto done; |
288 |
goto done; |
Lines 290-308
png_print_page(gx_device_printer * pdev,
Link Here
|
290 |
png_init_io(png_ptr, file); |
292 |
png_init_io(png_ptr, file); |
291 |
|
293 |
|
292 |
/* set the file information here */ |
294 |
/* set the file information here */ |
293 |
info_ptr->width = pdev->width; |
|
|
294 |
info_ptr->height = pdev->height; |
295 |
/* resolution is in pixels per meter vs. dpi */ |
296 |
info_ptr->x_pixels_per_unit = |
297 |
(png_uint_32) (pdev->HWResolution[0] * (100.0 / 2.54)); |
298 |
info_ptr->y_pixels_per_unit = |
299 |
(png_uint_32) (pdev->HWResolution[1] * (100.0 / 2.54)); |
300 |
info_ptr->phys_unit_type = PNG_RESOLUTION_METER; |
301 |
info_ptr->valid |= PNG_INFO_pHYs; |
302 |
switch (depth) { |
295 |
switch (depth) { |
303 |
case 32: |
296 |
case 32: |
304 |
info_ptr->bit_depth = 8; |
297 |
png_set_IHDR(png_ptr, info_ptr, pdev->width, pdev->height, |
305 |
info_ptr->color_type = PNG_COLOR_TYPE_RGB_ALPHA; |
298 |
8, PNG_COLOR_TYPE_RGB_ALPHA, |
|
|
299 |
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, |
300 |
PNG_FILTER_TYPE_DEFAULT); |
306 |
png_set_invert_alpha(png_ptr); |
301 |
png_set_invert_alpha(png_ptr); |
307 |
{ gx_device_pngalpha *ppdev = (gx_device_pngalpha *)pdev; |
302 |
{ gx_device_pngalpha *ppdev = (gx_device_pngalpha *)pdev; |
308 |
png_color_16 background; |
303 |
png_color_16 background; |
Lines 315-371
png_print_page(gx_device_printer * pdev,
Link Here
|
315 |
} |
310 |
} |
316 |
break; |
311 |
break; |
317 |
case 48: |
312 |
case 48: |
318 |
info_ptr->bit_depth = 16; |
313 |
png_set_IHDR(png_ptr, info_ptr, pdev->width, pdev->height, |
319 |
info_ptr->color_type = PNG_COLOR_TYPE_RGB; |
314 |
16, PNG_COLOR_TYPE_RGB, |
|
|
315 |
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, |
316 |
PNG_FILTER_TYPE_DEFAULT); |
320 |
#if defined(ARCH_IS_BIG_ENDIAN) && (!ARCH_IS_BIG_ENDIAN) |
317 |
#if defined(ARCH_IS_BIG_ENDIAN) && (!ARCH_IS_BIG_ENDIAN) |
321 |
png_set_swap(png_ptr); |
318 |
png_set_swap(png_ptr); |
322 |
#endif |
319 |
#endif |
323 |
break; |
320 |
break; |
324 |
case 24: |
321 |
case 24: |
325 |
info_ptr->bit_depth = 8; |
322 |
png_set_IHDR(png_ptr, info_ptr, pdev->width, pdev->height, |
326 |
info_ptr->color_type = PNG_COLOR_TYPE_RGB; |
323 |
8, PNG_COLOR_TYPE_RGB, |
|
|
324 |
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, |
325 |
PNG_FILTER_TYPE_DEFAULT); |
327 |
break; |
326 |
break; |
328 |
case 8: |
327 |
case 8: |
329 |
info_ptr->bit_depth = 8; |
328 |
png_set_IHDR(png_ptr, info_ptr, pdev->width, pdev->height, |
330 |
if (gx_device_has_color(pdev)) |
329 |
8, gx_device_has_color(pdev) ? |
331 |
info_ptr->color_type = PNG_COLOR_TYPE_PALETTE; |
330 |
PNG_COLOR_TYPE_PALETTE : PNG_COLOR_TYPE_GRAY, |
332 |
else |
331 |
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, |
333 |
info_ptr->color_type = PNG_COLOR_TYPE_GRAY; |
332 |
PNG_FILTER_TYPE_DEFAULT); |
334 |
break; |
333 |
break; |
335 |
case 4: |
334 |
case 4: |
336 |
info_ptr->bit_depth = 4; |
335 |
png_set_IHDR(png_ptr, info_ptr, pdev->width, pdev->height, |
337 |
info_ptr->color_type = PNG_COLOR_TYPE_PALETTE; |
336 |
4, PNG_COLOR_TYPE_PALETTE, |
|
|
337 |
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, |
338 |
PNG_FILTER_TYPE_DEFAULT); |
338 |
break; |
339 |
break; |
339 |
case 1: |
340 |
case 1: |
340 |
info_ptr->bit_depth = 1; |
341 |
png_set_IHDR(png_ptr, info_ptr, pdev->width, pdev->height, |
341 |
info_ptr->color_type = PNG_COLOR_TYPE_GRAY; |
342 |
1, PNG_COLOR_TYPE_GRAY, |
|
|
343 |
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, |
344 |
PNG_FILTER_TYPE_DEFAULT); |
342 |
/* invert monocrome pixels */ |
345 |
/* invert monocrome pixels */ |
343 |
png_set_invert_mono(png_ptr); |
346 |
png_set_invert_mono(png_ptr); |
344 |
break; |
347 |
break; |
|
|
348 |
default: |
349 |
png_error(png_ptr, "invalid bit depth"); |
345 |
} |
350 |
} |
346 |
|
351 |
|
|
|
352 |
/* resolution is in pixels per meter vs. dpi */ |
353 |
png_set_pHYs(png_ptr, info_ptr, |
354 |
(png_uint_32) (pdev->HWResolution[0] * (100.0 / 2.54)), |
355 |
(png_uint_32) (pdev->HWResolution[1] * (100.0 / 2.54)), |
356 |
PNG_RESOLUTION_METER); |
357 |
|
347 |
/* set the palette if there is one */ |
358 |
/* set the palette if there is one */ |
348 |
if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) { |
359 |
if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_PALETTE) { |
349 |
int i; |
360 |
int i; |
350 |
int num_colors = 1 << depth; |
361 |
int num_colors = 1 << depth; |
351 |
gx_color_value rgb[3]; |
362 |
gx_color_value rgb[3]; |
|
|
363 |
png_color palette[256]; |
364 |
|
365 |
if (num_colors > 256) |
366 |
num_colors = 256; |
352 |
|
367 |
|
353 |
info_ptr->palette = |
|
|
354 |
(void *)gs_alloc_bytes(mem, 256 * sizeof(png_color), |
355 |
"png palette"); |
356 |
if (info_ptr->palette == 0) { |
357 |
code = gs_note_error(gs_error_VMerror); |
358 |
goto done; |
359 |
} |
360 |
info_ptr->num_palette = num_colors; |
361 |
info_ptr->valid |= PNG_INFO_PLTE; |
362 |
for (i = 0; i < num_colors; i++) { |
368 |
for (i = 0; i < num_colors; i++) { |
363 |
(*dev_proc(pdev, map_color_rgb)) ((gx_device *) pdev, |
369 |
(*dev_proc(pdev, map_color_rgb)) ((gx_device *) pdev, |
364 |
(gx_color_index) i, rgb); |
370 |
(gx_color_index) i, rgb); |
365 |
info_ptr->palette[i].red = gx_color_value_to_byte(rgb[0]); |
371 |
palette[i].red = gx_color_value_to_byte(rgb[0]); |
366 |
info_ptr->palette[i].green = gx_color_value_to_byte(rgb[1]); |
372 |
palette[i].green = gx_color_value_to_byte(rgb[1]); |
367 |
info_ptr->palette[i].blue = gx_color_value_to_byte(rgb[2]); |
373 |
palette[i].blue = gx_color_value_to_byte(rgb[2]); |
368 |
} |
374 |
} |
|
|
375 |
png_set_PLTE(png_ptr, info_ptr, palette, num_colors); |
369 |
} |
376 |
} |
370 |
/* add comment */ |
377 |
/* add comment */ |
371 |
strncpy(software_key, "Software", sizeof(software_key)); |
378 |
strncpy(software_key, "Software", sizeof(software_key)); |
Lines 375-389
png_print_page(gx_device_printer * pdev,
Link Here
|
375 |
text_png.key = software_key; |
382 |
text_png.key = software_key; |
376 |
text_png.text = software_text; |
383 |
text_png.text = software_text; |
377 |
text_png.text_length = strlen(software_text); |
384 |
text_png.text_length = strlen(software_text); |
378 |
info_ptr->text = &text_png; |
385 |
png_set_text(png_ptr, info_ptr, &text_png, 1); |
379 |
info_ptr->num_text = 1; |
|
|
380 |
|
386 |
|
381 |
/* write the file information */ |
387 |
/* write the file information */ |
382 |
png_write_info(png_ptr, info_ptr); |
388 |
png_write_info(png_ptr, info_ptr); |
383 |
|
389 |
|
384 |
/* don't write the comments twice */ |
390 |
/* don't write the comments twice */ |
385 |
info_ptr->num_text = 0; |
391 |
/*info_ptr->num_text = 0;*/ |
386 |
info_ptr->text = NULL; |
392 |
/*info_ptr->text = NULL;*/ |
387 |
|
393 |
|
388 |
/* Write the contents of the image. */ |
394 |
/* Write the contents of the image. */ |
389 |
for (y = 0; y < height; y++) { |
395 |
for (y = 0; y < height; y++) { |
Lines 395-401
png_print_page(gx_device_printer * pdev,
Link Here
|
395 |
png_write_end(png_ptr, info_ptr); |
401 |
png_write_end(png_ptr, info_ptr); |
396 |
|
402 |
|
397 |
/* if you alloced the palette, free it here */ |
403 |
/* if you alloced the palette, free it here */ |
398 |
gs_free_object(mem, info_ptr->palette, "png palette"); |
404 |
/*gs_free_object(mem, info_ptr->palette, "png palette");*/ |
399 |
|
405 |
|
400 |
done: |
406 |
done: |
401 |
/* free the structures */ |
407 |
/* free the structures */ |
Lines 405-410
png_print_page(gx_device_printer * pdev,
Link Here
|
405 |
return code; |
411 |
return code; |
406 |
} |
412 |
} |
407 |
|
413 |
|
|
|
414 |
#if 0 /* not required in 1.5 */ |
408 |
/* |
415 |
/* |
409 |
* Patch around a static reference to a never-used procedure. |
416 |
* Patch around a static reference to a never-used procedure. |
410 |
* This could be avoided if we were willing to edit pngconf.h to |
417 |
* This could be avoided if we were willing to edit pngconf.h to |
Lines 422-427
png_push_fill_buffer(png_structp png_ptr
Link Here
|
422 |
{ |
429 |
{ |
423 |
} |
430 |
} |
424 |
#endif |
431 |
#endif |
|
|
432 |
#endif |
425 |
|
433 |
|
426 |
static int |
434 |
static int |
427 |
pngalpha_open(gx_device * pdev) |
435 |
pngalpha_open(gx_device * pdev) |