pkgsrc/graphics/xart/patches/patch-ag
2011-02-07 21:28:56 +00:00

213 lines
7.4 KiB
Text

$NetBSD: patch-ag,v 1.2 2011/02/07 21:28:56 wiz Exp $
Fix build with png-1.5.
--- rw/writePNG.c.orig 1996-08-29 05:24:57.000000000 +0000
+++ rw/writePNG.c
@@ -31,6 +31,9 @@ WritePNG(char *file, Image *image, int i
png_structp png_ptr;
png_infop info_ptr;
png_textp software;
+ int bit_depth;
+ int color_type;
+ png_timep mod_time;
Trace((stderr, "\nGRR WritePNG: %d x %d, scale = %d\n",
@@ -38,47 +41,41 @@ WritePNG(char *file, Image *image, int i
if (!fp)
return 1;
- png_ptr = (png_structp)malloc(sizeof (png_struct));
+ png_ptr = (png_structp)png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL,
+ NULL, NULL);
if (!png_ptr)
return 1;
- info_ptr = (png_infop)malloc(sizeof (png_info));
+ info_ptr = (png_infop)png_create_info_struct(png_ptr);
if (!info_ptr) {
- free(png_ptr);
+ png_destroy_write_struct(&png_ptr, NULL);
return 1;
}
- if (setjmp(png_ptr->jmpbuf)) {
- png_write_destroy(png_ptr);
- free(info_ptr);
- free(png_ptr);
+ if (setjmp(png_jmpbuf(png_ptr))) {
+ png_destroy_write_struct(&png_ptr, &info_ptr);
fclose(fp);
return 1;
}
- png_info_init(info_ptr);
- png_write_init(png_ptr);
png_init_io(png_ptr, fp);
- info_ptr->width = image->width;
- info_ptr->height = image->height;
-
if (image->isBW) {
if (image->maskData) {
- info_ptr->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
- info_ptr->bit_depth = 8; /* promote to full grayscale */
+ color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
+ bit_depth = 8; /* promote to full grayscale */
} else {
- info_ptr->color_type = PNG_COLOR_TYPE_GRAY;
- info_ptr->bit_depth = 1;
+ color_type = PNG_COLOR_TYPE_GRAY;
+ bit_depth = 1;
}
Trace((stderr, "GRR WritePNG: B/W, bit_depth = %d\n",
- info_ptr->bit_depth));
+ bit_depth));
} else if (image->isGrey) {
- info_ptr->color_type = image->maskData? PNG_COLOR_TYPE_GRAY_ALPHA :
+ color_type = image->maskData? PNG_COLOR_TYPE_GRAY_ALPHA :
PNG_COLOR_TYPE_GRAY;
if (image->cmapPacked)
- info_ptr->bit_depth = 8;
+ bit_depth = 8;
else {
Trace((stderr,
"GRR WritePNG: isGrey: cmapSize = %d (before compressing), ",
@@ -86,15 +83,15 @@ WritePNG(char *file, Image *image, int i
compressColormap(image);
Trace((stderr, "%d (after)\n", image->cmapSize));
if (image->cmapSize > 16)
- info_ptr->bit_depth = 8;
+ bit_depth = 8;
else if (image->cmapSize > 4)
- info_ptr->bit_depth = 4;
+ bit_depth = 4;
else if (image->cmapSize > 2)
- info_ptr->bit_depth = 2;
+ bit_depth = 2;
else
- info_ptr->bit_depth = 1;
+ bit_depth = 1;
Trace((stderr, "GRR WritePNG: isGrey: picked bit_depth = %d\n",
- info_ptr->bit_depth));
+ bit_depth));
}
} else if (image->scale == 3) {
@@ -107,9 +104,9 @@ WritePNG(char *file, Image *image, int i
if (cmapImage) {
image = cmapImage; /* original was deleted in ImageCompress() */
} else {
- info_ptr->color_type = image->maskData? PNG_COLOR_TYPE_RGB_ALPHA :
+ color_type = image->maskData? PNG_COLOR_TYPE_RGB_ALPHA :
PNG_COLOR_TYPE_RGB;
- info_ptr->bit_depth = 8;
+ bit_depth = 8;
Trace((stderr, "GRR WritePNG: RGB, bit_depth = 8\n"));
}
}
@@ -129,7 +126,7 @@ WritePNG(char *file, Image *image, int i
* ImageCompress() worked
*/
if (image->scale == 1) {
- info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;
+ color_type = PNG_COLOR_TYPE_PALETTE;
if (image->maskData) {
fprintf(stderr,
"WritePNG: can't use alpha mask with colormapped image\n");
@@ -139,18 +136,17 @@ WritePNG(char *file, Image *image, int i
if (!image->cmapPacked)
compressColormap(image);
if (image->cmapSize > 16)
- info_ptr->bit_depth = 8;
+ bit_depth = 8;
else if (image->cmapSize > 4)
- info_ptr->bit_depth = 4;
+ bit_depth = 4;
else if (image->cmapSize > 2)
- info_ptr->bit_depth = 2;
+ bit_depth = 2;
else
- info_ptr->bit_depth = 1;
- info_ptr->valid |= PNG_INFO_PLTE;
- info_ptr->num_palette = image->cmapSize;
- info_ptr->palette = (png_colorp)image->cmapData; /* seems to work... */
- Trace((stderr, "%d, num_palette = %d\n", info_ptr->bit_depth,
- info_ptr->num_palette));
+ bit_depth = 1;
+ png_set_PLTE(png_ptr, info_ptr, (png_colorp)image->cmapData,
+ image->cmapSize); /* seems to work... */
+ Trace((stderr, "%d, num_palette = %d\n", bit_depth,
+ image->cmapSize));
#if 0
for (i = 0; i < image->cmapSize; ++i) {
info_ptr->palette[i].red =
@@ -160,14 +156,15 @@ WritePNG(char *file, Image *image, int i
#endif
}
- info_ptr->interlace_type = interlace_type;
+ png_set_IHDR(png_ptr, info_ptr, image->width, image->height,
+ bit_depth, color_type, interlace_type, PNG_COMPRESSION_TYPE_BASE,
+ PNG_FILTER_TYPE_BASE);
/* set the file gamma */
- info_ptr->valid |= PNG_INFO_gAMA;
#ifdef DISPLAY_GAMMA
- info_ptr->gamma = 1.0 / DISPLAY_GAMMA;
+ png_set_gAMA(png_ptr, info_ptr, 1.0 / DISPLAY_GAMMA);
#else
- info_ptr->gamma = 0.45; /* default: assume PC-like system */
+ png_set_gAMA(png_ptr, info_ptr, 0.45); /* default: assume PC-like system */
#endif
/* info_ptr->valid |= PNG_INFO_tEXt; DOES NOT EXIST */
@@ -180,16 +177,14 @@ WritePNG(char *file, Image *image, int i
software->key = "Software";
software->text = software_text;
software->text_length = strlen(software->text);
- info_ptr->num_text = 1;
- info_ptr->text = software;
+ png_set_text(png_ptr, info_ptr, software, 1);
} else {
/* couldn't malloc: oh well */
- info_ptr->num_text = 0;
- info_ptr->text = NULL;
+ png_set_text(png_ptr, info_ptr, NULL, 0);
}
- info_ptr->valid |= PNG_INFO_tIME;
- png_convert_from_time_t(&info_ptr->mod_time, time(NULL));
+ png_convert_from_time_t(mod_time, time(NULL));
+ png_set_tIME(png_ptr, info_ptr, mod_time);
png_write_flush(png_ptr);
png_write_info(png_ptr, info_ptr);
@@ -200,9 +195,7 @@ WritePNG(char *file, Image *image, int i
/* alpha channel version */
fprintf(stderr, "WritePNG: sorry, can't write alpha images yet\n");
fflush(stderr);
- png_write_destroy(png_ptr);
- free(info_ptr);
- free(png_ptr);
+ png_destroy_write_struct(&png_ptr, &info_ptr);
fclose(fp);
return 1;
} else {
@@ -222,13 +215,11 @@ WritePNG(char *file, Image *image, int i
}
png_write_end(png_ptr, NULL);
- png_write_destroy(png_ptr);
+ png_destroy_write_struct(&png_ptr, &info_ptr);
if (software)
free(software); /* we LOVE free software!! */
- free(info_ptr);
- free(png_ptr); /* necessary?? */
fclose(fp);
return 0;