Fix build with png-1.5.diff -r1.52 -r1.53 pkgsrc/graphics/xart/Makefile
(wiz)
@@ -1,26 +1,29 @@ | @@ -1,26 +1,29 @@ | |||
1 | # $NetBSD: Makefile,v 1.52 2011/01/13 13:38:23 wiz Exp $ | 1 | # $NetBSD: Makefile,v 1.53 2011/02/07 21:28:56 wiz Exp $ | |
2 | # | 2 | # | |
3 | 3 | |||
4 | DISTNAME= xart19980415 | 4 | DISTNAME= xart19980415 | |
5 | PKGNAME= xart-19980415 | 5 | PKGNAME= xart-19980415 | |
6 | PKGREVISION= 15 | 6 | PKGREVISION= 15 | |
7 | CATEGORIES= graphics x11 | 7 | CATEGORIES= graphics x11 | |
8 | MASTER_SITES= http://linux01.gwdg.de/~rhohen/linux/ | 8 | MASTER_SITES= http://linux01.gwdg.de/~rhohen/linux/ | |
9 | EXTRACT_SUFX= .tgz | 9 | EXTRACT_SUFX= .tgz | |
10 | 10 | |||
11 | MAINTAINER= pkgsrc-users@NetBSD.org | 11 | MAINTAINER= pkgsrc-users@NetBSD.org | |
12 | HOMEPAGE= http://linux01.gwdg.de/~rhohen/linux.html | 12 | HOMEPAGE= http://linux01.gwdg.de/~rhohen/linux.html | |
13 | COMMENT= Paint program (enhanced xpaint) | 13 | COMMENT= Paint program (enhanced xpaint) | |
14 | # quite like isc, but copyright needs to mention in documentation as well | |||
15 | # see the bottom of the included "Help.txt" file | |||
16 | #LICENSE= isc | |||
14 | 17 | |||
15 | PKG_DESTDIR_SUPPORT= user-destdir | 18 | PKG_DESTDIR_SUPPORT= user-destdir | |
16 | 19 | |||
17 | WRKSRC= ${WRKDIR}/19980415 | 20 | WRKSRC= ${WRKDIR}/19980415 | |
18 | USE_IMAKE= YES | 21 | USE_IMAKE= YES | |
19 | 22 | |||
20 | post-extract: | 23 | post-extract: | |
21 | cd ${WRKDIR} && find * -type d -exec chmod 755 "{}" ";" | 24 | cd ${WRKDIR} && find * -type d -exec chmod 755 "{}" ";" | |
22 | cd ${WRKDIR} && find * -type f -print | xargs chmod 644 | 25 | cd ${WRKDIR} && find * -type f -print | xargs chmod 644 | |
23 | 26 | |||
24 | .include "../../mk/jpeg.buildlink3.mk" | 27 | .include "../../mk/jpeg.buildlink3.mk" | |
25 | .include "../../graphics/tiff/buildlink3.mk" | 28 | .include "../../graphics/tiff/buildlink3.mk" | |
26 | .include "../../graphics/png/buildlink3.mk" | 29 | .include "../../graphics/png/buildlink3.mk" |
@@ -1,16 +1,16 @@ | @@ -1,16 +1,16 @@ | |||
1 | $NetBSD: distinfo,v 1.13 2010/06/13 22:44:46 wiz Exp $ | 1 | $NetBSD: distinfo,v 1.14 2011/02/07 21:28:56 wiz Exp $ | |
2 | 2 | |||
3 | SHA1 (xart19980415.tgz) = d4445392e33a5dcf5ae951babac82394e7cdd65c | 3 | SHA1 (xart19980415.tgz) = d4445392e33a5dcf5ae951babac82394e7cdd65c | |
4 | RMD160 (xart19980415.tgz) = 99077c23a798d8c0026bd53450052b1a8cf6ff6f | 4 | RMD160 (xart19980415.tgz) = 99077c23a798d8c0026bd53450052b1a8cf6ff6f | |
5 | Size (xart19980415.tgz) = 343909 bytes | 5 | Size (xart19980415.tgz) = 343909 bytes | |
6 | SHA1 (patch-aa) = 7d8ae61d9a624cc537396f406b496f28376cf7b5 | 6 | SHA1 (patch-aa) = 7d8ae61d9a624cc537396f406b496f28376cf7b5 | |
7 | SHA1 (patch-ab) = b0f00e29560ce786e37a8ba62fef82dae80c4ee9 | 7 | SHA1 (patch-ab) = b0f00e29560ce786e37a8ba62fef82dae80c4ee9 | |
8 | SHA1 (patch-ac) = 618003b6d192e85a1aa5f64b0f8eccfec991012e | 8 | SHA1 (patch-ac) = 618003b6d192e85a1aa5f64b0f8eccfec991012e | |
9 | SHA1 (patch-ad) = 08059ca068d156be0e31283180c5deaebb99f7bd | 9 | SHA1 (patch-ad) = 08059ca068d156be0e31283180c5deaebb99f7bd | |
10 | SHA1 (patch-ae) = d0d87fe957cbec5979e635270d2ad05b294f7530 | 10 | SHA1 (patch-ae) = d0d87fe957cbec5979e635270d2ad05b294f7530 | |
11 | SHA1 (patch-af) = 2ee00a7b02d14a5962ac0f561ede6423c4d45801 | 11 | SHA1 (patch-af) = 7253489721eead898cd3a67878584d86b7719e3f | |
12 | SHA1 (patch-ag) = c764ddf68af02eda1475778e6c1774d751e68a92 | 12 | SHA1 (patch-ag) = 58bf357debce54707378b6598ca813af6a632e3b | |
13 | SHA1 (patch-ah) = f888c5167cd8a6111e2064d586ff50984320b210 | 13 | SHA1 (patch-ah) = f888c5167cd8a6111e2064d586ff50984320b210 | |
14 | SHA1 (patch-ai) = 349170a16199734f35dc56de12e77dd289db412b | 14 | SHA1 (patch-ai) = 349170a16199734f35dc56de12e77dd289db412b | |
15 | SHA1 (patch-aj) = 7139b114301de5becf1449bd2b346223b205a908 | 15 | SHA1 (patch-aj) = 7139b114301de5becf1449bd2b346223b205a908 | |
16 | SHA1 (patch-ak) = a7778776ec8251a51477f3548f28ed30a1ef9770 | 16 | SHA1 (patch-ak) = a7778776ec8251a51477f3548f28ed30a1ef9770 |
@@ -1,80 +1,202 @@ | @@ -1,80 +1,202 @@ | |||
1 | $NetBSD: patch-af,v 1.2 2006/04/19 17:04:31 wiz Exp $ | 1 | $NetBSD: patch-af,v 1.3 2011/02/07 21:28:56 wiz Exp $ | |
2 | 2 | |||
3 | --- rw/readPNG.c.orig 1996-08-29 07:24:48.000000000 +0200 | 3 | Fix build with png-1.5. | |
4 | ||||
5 | --- rw/readPNG.c.orig 1996-08-29 05:24:48.000000000 +0000 | |||
4 | +++ rw/readPNG.c | 6 | +++ rw/readPNG.c | |
5 | @@ -46,8 +46,8 @@ Image * | 7 | @@ -28,7 +28,7 @@ | |
8 | int | |||
9 | TestPNG(char *file) /* gets called a LOT on the first image: brushes? */ | |||
10 | { | |||
11 | - char header[8]; | |||
12 | + unsigned char header[8]; | |||
13 | FILE *fp = fopen(file, "rb"); /* libpng requires ANSI; so do we */ | |||
14 | ||||
15 | if (!fp) | |||
16 | @@ -46,11 +46,13 @@ Image * | |||
6 | ReadPNG(char *file) | 17 | ReadPNG(char *file) | |
7 | { | 18 | { | |
8 | FILE *fp; | 19 | FILE *fp; | |
9 | - png_structp png_ptr; | 20 | - png_structp png_ptr; | |
10 | - png_infop info_ptr; | 21 | - png_infop info_ptr; | |
11 | + png_structp png_ptr = NULL; | 22 | + png_structp png_ptr = NULL; | |
12 | + png_infop info_ptr = NULL; | 23 | + png_infop info_ptr = NULL; | |
13 | int i, hasAlpha=FALSE; | 24 | int i, hasAlpha=FALSE; | |
14 | int width, height, level, bit_depth, npasses; | 25 | int width, height, level, bit_depth, npasses; | |
15 | Image *image = NULL; | 26 | Image *image = NULL; | |
16 | @@ -59,14 +59,15 @@ ReadPNG(char *file) | 27 | + png_colorp palette; | |
28 | + int num_palette; | |||
29 | ||||
30 | ||||
31 | Trace((stderr, "\nGRR ReadPNG: reading file %s\n", file)); | |||
32 | @@ -59,14 +61,15 @@ ReadPNG(char *file) | |||
17 | return NULL; | 33 | return NULL; | |
18 | } | 34 | } | |
19 | 35 | |||
20 | - png_ptr = (png_structp)malloc(sizeof(png_struct)); | 36 | - png_ptr = (png_structp)malloc(sizeof(png_struct)); | |
21 | + png_ptr = (png_structp)png_create_read_struct(PNG_LIBPNG_VER_STRING, | 37 | + png_ptr = (png_structp)png_create_read_struct(PNG_LIBPNG_VER_STRING, | |
22 | + NULL, NULL, NULL); | 38 | + NULL, NULL, NULL); | |
23 | if (!png_ptr) { | 39 | if (!png_ptr) { | |
24 | RWSetMsg("Error allocating PNG png_ptr memory"); | 40 | RWSetMsg("Error allocating PNG png_ptr memory"); | |
25 | fclose(fp); | 41 | fclose(fp); | |
26 | return NULL; | 42 | return NULL; | |
27 | } | 43 | } | |
28 | 44 | |||
29 | - info_ptr = (png_infop)malloc(sizeof(png_info)); | 45 | - info_ptr = (png_infop)malloc(sizeof(png_info)); | |
30 | + info_ptr = (png_infop)png_create_info_struct(png_ptr); | 46 | + info_ptr = (png_infop)png_create_info_struct(png_ptr); | |
31 | if (!info_ptr) { | 47 | if (!info_ptr) { | |
32 | RWSetMsg("Error allocating PNG info_ptr memory"); | 48 | RWSetMsg("Error allocating PNG info_ptr memory"); | |
33 | free(png_ptr); | 49 | free(png_ptr); | |
34 | @@ -74,17 +75,13 @@ ReadPNG(char *file) | 50 | @@ -74,38 +77,36 @@ ReadPNG(char *file) | |
35 | return NULL; | 51 | return NULL; | |
36 | } | 52 | } | |
37 | 53 | |||
38 | - if (setjmp(png_ptr->jmpbuf)) { | 54 | - if (setjmp(png_ptr->jmpbuf)) { | |
39 | + if (setjmp(png_jmpbuf(png_ptr))) { | 55 | + if (setjmp(png_jmpbuf(png_ptr))) { | |
40 | RWSetMsg("Error setting longjmp error handler"); | 56 | RWSetMsg("Error setting longjmp error handler"); | |
41 | - png_read_destroy(png_ptr, info_ptr, (png_info *)0); | 57 | - png_read_destroy(png_ptr, info_ptr, (png_info *)0); | |
42 | - free(png_ptr); | 58 | - free(png_ptr); | |
43 | - free(info_ptr); | 59 | - free(info_ptr); | |
44 | + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); | 60 | + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); | |
45 | fclose(fp); | 61 | fclose(fp); | |
46 | return NULL; | 62 | return NULL; | |
47 | } | 63 | } | |
48 | 64 | |||
49 | - png_info_init(info_ptr); | 65 | - png_info_init(info_ptr); | |
50 | - png_read_init(png_ptr); | 66 | - png_read_init(png_ptr); | |
51 | png_init_io(png_ptr, fp); | 67 | png_init_io(png_ptr, fp); | |
52 | png_read_info(png_ptr, info_ptr); | 68 | png_read_info(png_ptr, info_ptr); | |
53 | 69 | |||
54 | @@ -183,7 +180,7 @@ ReadPNG(char *file) | 70 | - width = info_ptr->width; | |
55 | info_ptr->color_type); | 71 | - height = info_ptr->height; | |
72 | + width = png_get_image_width(png_ptr, info_ptr); | |||
73 | + height = png_get_image_height(png_ptr, info_ptr); | |||
74 | ||||
75 | Trace((stderr, "GRR ReadPNG: width = %d, height = %d\n", width, height)); | |||
76 | - switch (info_ptr->color_type) { | |||
77 | + | |||
78 | + png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette); | |||
79 | + switch (png_get_color_type(png_ptr, info_ptr)) { | |||
80 | ||||
81 | case PNG_COLOR_TYPE_PALETTE: | |||
82 | Trace((stderr, "GRR ReadPNG: PNG_COLOR_TYPE_PALETTE\n")); | |||
83 | - image = ImageNewCmap(width, height, info_ptr->num_palette); | |||
84 | - for (i = 0; i < info_ptr->num_palette; ++i) | |||
85 | - ImageSetCmap(image, i, info_ptr->palette[i].red, | |||
86 | - info_ptr->palette[i].green, info_ptr->palette[i].blue); | |||
87 | + image = ImageNewCmap(width, height, num_palette); | |||
88 | + for (i = 0; i < num_palette; ++i) | |||
89 | + ImageSetCmap(image, i, palette[i].red, | |||
90 | + palette[i].green, palette[i].blue); | |||
91 | /* GRR: still need to get image data into `image' */ | |||
92 | break; | |||
93 | ||||
94 | case PNG_COLOR_TYPE_RGB: | |||
95 | Trace((stderr, "GRR ReadPNG: PNG_COLOR_TYPE_RGB\n")); | |||
96 | - if (info_ptr->bit_depth == 16) { | |||
97 | + if (png_get_bit_depth(png_ptr, info_ptr) == 16) { | |||
98 | RWSetMsg("Stripping 48-bit RGB image to 24 bits"); | |||
99 | fprintf(stderr, | |||
100 | "ReadPNG: stripping 48-bit RGB image to 24 bits\n"); | |||
101 | @@ -117,8 +118,8 @@ ReadPNG(char *file) | |||
102 | ||||
103 | case PNG_COLOR_TYPE_GRAY: /* treat grayscale as special colormap */ | |||
104 | Trace((stderr, "GRR ReadPNG: PNG_COLOR_TYPE_GRAY\n")); | |||
105 | - bit_depth = info_ptr->bit_depth; | |||
106 | - if (info_ptr->bit_depth == 16) { | |||
107 | + bit_depth = png_get_bit_depth(png_ptr, info_ptr); | |||
108 | + if (bit_depth == 16) { | |||
109 | RWSetMsg("Stripping 16-bit grayscale image to 8 bits"); | |||
110 | fprintf(stderr, | |||
111 | "ReadPNG: stripping 16-bit grayscale image to 8 bits\n"); | |||
112 | @@ -157,7 +158,7 @@ ReadPNG(char *file) | |||
113 | ||||
114 | case PNG_COLOR_TYPE_RGB_ALPHA: | |||
115 | Trace((stderr, "GRR ReadPNG: PNG_COLOR_TYPE_RGB_ALPHA\n")); | |||
116 | - if (info_ptr->bit_depth == 16) { | |||
117 | + if (png_get_bit_depth(png_ptr, info_ptr) == 16) { | |||
118 | RWSetMsg("Stripping 64-bit RGBA image to 32 bits"); | |||
119 | png_set_strip_16(png_ptr); | |||
120 | } | |||
121 | @@ -169,7 +170,7 @@ ReadPNG(char *file) | |||
122 | ||||
123 | case PNG_COLOR_TYPE_GRAY_ALPHA: | |||
124 | Trace((stderr, "GRR ReadPNG: PNG_COLOR_TYPE_GRAY_ALPHA\n")); | |||
125 | - if (info_ptr->bit_depth == 16) { | |||
126 | + if (png_get_bit_depth(png_ptr, info_ptr) == 16) { | |||
127 | RWSetMsg("Stripping 32-bit gray+alpha image to 16 bits"); | |||
128 | png_set_strip_16(png_ptr); | |||
129 | } | |||
130 | @@ -180,20 +181,20 @@ ReadPNG(char *file) | |||
131 | ||||
132 | default: | |||
133 | fprintf(stderr, "ReadPNG: unknown image type (%d)\n", | |||
134 | - info_ptr->color_type); | |||
135 | + png_get_color_type(png_ptr, info_ptr)); | |||
56 | fflush(stderr); | 136 | fflush(stderr); | |
57 | RWSetMsg("Unknown PNG image type"); | 137 | RWSetMsg("Unknown PNG image type"); | |
58 | - png_read_destroy(png_ptr, info_ptr, (png_infop)NULL); | 138 | - png_read_destroy(png_ptr, info_ptr, (png_infop)NULL); | |
59 | + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); | 139 | + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); | |
60 | free(png_ptr); | 140 | free(png_ptr); | |
61 | free(info_ptr); | 141 | free(info_ptr); | |
62 | fclose(fp); | 142 | fclose(fp); | |
63 | @@ -217,7 +214,7 @@ ReadPNG(char *file) | 143 | return image; /* NULL */ | |
144 | } | |||
145 | ||||
146 | - if (info_ptr->bit_depth < 8) | |||
147 | + if (png_get_bit_depth(png_ptr, info_ptr) < 8) | |||
148 | png_set_packing(png_ptr); | |||
149 | ||||
150 | - if (info_ptr->interlace_type) | |||
151 | + if (png_get_interlace_type(png_ptr, info_ptr)) | |||
152 | npasses = png_set_interlace_handling(png_ptr); | |||
153 | ||||
154 | png_read_update_info(png_ptr, info_ptr); | |||
155 | @@ -211,13 +212,13 @@ ReadPNG(char *file) | |||
156 | * no easy way around it: libpng returns the image and alpha channel | |||
157 | * interspersed, and interlaced alpha images just make matters worse | |||
158 | */ | |||
159 | - png_data = (png_bytep)malloc(height*info_ptr->rowbytes); | |||
160 | + png_data = (png_bytep)malloc(height*png_get_rowbytes(png_ptr, info_ptr)); | |||
161 | if (!png_data) { | |||
162 | RWSetMsg("Unable to allocate temporary storage for alpha image"); | |||
64 | fprintf(stderr, "ReadPNG error: unable to malloc png_data\n"); | 163 | fprintf(stderr, "ReadPNG error: unable to malloc png_data\n"); | |
65 | fflush(stderr); | 164 | fflush(stderr); | |
66 | ImageDelete(image); | 165 | ImageDelete(image); | |
67 | - png_read_destroy(png_ptr, info_ptr, (png_infop)NULL); | 166 | - png_read_destroy(png_ptr, info_ptr, (png_infop)NULL); | |
68 | + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); | 167 | + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); | |
69 | free(png_ptr); | 168 | free(png_ptr); | |
70 | free(info_ptr); | 169 | free(info_ptr); | |
71 | fclose(fp); | 170 | fclose(fp); | |
72 | @@ -271,7 +268,7 @@ ReadPNG(char *file) | 171 | @@ -226,11 +227,11 @@ ReadPNG(char *file) | |
172 | ||||
173 | /* only bit depths of 8 and 16 support alpha channels */ | |||
174 | for (i = 0; i < height; ++i) | |||
175 | - row_pointers[i] = (png_bytep)png_data + i*info_ptr->rowbytes; | |||
176 | + row_pointers[i] = (png_bytep)png_data + i*png_get_rowbytes(png_ptr, info_ptr); | |||
177 | ||||
178 | png_read_image(png_ptr, row_pointers); | |||
179 | ||||
180 | - if (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA) { | |||
181 | + if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_RGB_ALPHA) { | |||
182 | png_bytep png=png_data, rgb=image->data, alpha=image->maskData; | |||
183 | ||||
184 | for (i = 0; i < height*width; ++i) { | |||
185 | @@ -258,7 +259,7 @@ ReadPNG(char *file) | |||
186 | return NULL; | |||
187 | } | |||
188 | for (i = 0; i < height; ++i) | |||
189 | - row_pointers[i] = (png_bytep)image->data + i*info_ptr->rowbytes; | |||
190 | + row_pointers[i] = (png_bytep)image->data + i*png_get_rowbytes(png_ptr, info_ptr); | |||
191 | ||||
192 | png_read_image(png_ptr, row_pointers); | |||
193 | ||||
194 | @@ -271,7 +272,7 @@ ReadPNG(char *file) | |||
73 | */ | 195 | */ | |
74 | 196 | |||
75 | png_read_end(png_ptr, info_ptr); | 197 | png_read_end(png_ptr, info_ptr); | |
76 | - png_read_destroy(png_ptr, info_ptr, (png_infop)NULL); | 198 | - png_read_destroy(png_ptr, info_ptr, (png_infop)NULL); | |
77 | + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); | 199 | + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); | |
78 | free(png_ptr); | 200 | free(png_ptr); | |
79 | free(info_ptr); | 201 | free(info_ptr); | |
80 | fclose(fp); | 202 | fclose(fp); |
@@ -1,18 +1,30 @@ | @@ -1,18 +1,30 @@ | |||
1 | $NetBSD: patch-ag,v 1.1 2001/08/03 09:43:18 wiz Exp $ | 1 | $NetBSD: patch-ag,v 1.2 2011/02/07 21:28:56 wiz Exp $ | |
2 | 2 | |||
3 | --- rw/writePNG.c.orig Thu Aug 29 07:24:57 1996 | 3 | Fix build with png-1.5. | |
4 | ||||
5 | --- rw/writePNG.c.orig 1996-08-29 05:24:57.000000000 +0000 | |||
4 | +++ rw/writePNG.c | 6 | +++ rw/writePNG.c | |
5 | @@ -38,26 +38,23 @@ | 7 | @@ -31,6 +31,9 @@ WritePNG(char *file, Image *image, int i | |
8 | png_structp png_ptr; | |||
9 | png_infop info_ptr; | |||
10 | png_textp software; | |||
11 | + int bit_depth; | |||
12 | + int color_type; | |||
13 | + png_timep mod_time; | |||
14 | ||||
15 | ||||
16 | Trace((stderr, "\nGRR WritePNG: %d x %d, scale = %d\n", | |||
17 | @@ -38,47 +41,41 @@ WritePNG(char *file, Image *image, int i | |||
6 | if (!fp) | 18 | if (!fp) | |
7 | return 1; | 19 | return 1; | |
8 | 20 | |||
9 | - png_ptr = (png_structp)malloc(sizeof (png_struct)); | 21 | - png_ptr = (png_structp)malloc(sizeof (png_struct)); | |
10 | + png_ptr = (png_structp)png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, | 22 | + png_ptr = (png_structp)png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, | |
11 | + NULL, NULL); | 23 | + NULL, NULL); | |
12 | if (!png_ptr) | 24 | if (!png_ptr) | |
13 | return 1; | 25 | return 1; | |
14 | 26 | |||
15 | - info_ptr = (png_infop)malloc(sizeof (png_info)); | 27 | - info_ptr = (png_infop)malloc(sizeof (png_info)); | |
16 | + info_ptr = (png_infop)png_create_info_struct(png_ptr); | 28 | + info_ptr = (png_infop)png_create_info_struct(png_ptr); | |
17 | if (!info_ptr) { | 29 | if (!info_ptr) { | |
18 | - free(png_ptr); | 30 | - free(png_ptr); | |
@@ -24,39 +36,177 @@ $NetBSD: patch-ag,v 1.1 2001/08/03 09:43 | @@ -24,39 +36,177 @@ $NetBSD: patch-ag,v 1.1 2001/08/03 09:43 | |||
24 | - png_write_destroy(png_ptr); | 36 | - png_write_destroy(png_ptr); | |
25 | - free(info_ptr); | 37 | - free(info_ptr); | |
26 | - free(png_ptr); | 38 | - free(png_ptr); | |
27 | + if (setjmp(png_jmpbuf(png_ptr))) { | 39 | + if (setjmp(png_jmpbuf(png_ptr))) { | |
28 | + png_destroy_write_struct(&png_ptr, &info_ptr); | 40 | + png_destroy_write_struct(&png_ptr, &info_ptr); | |
29 | fclose(fp); | 41 | fclose(fp); | |
30 | return 1; | 42 | return 1; | |
31 | } | 43 | } | |
32 | 44 | |||
33 | - png_info_init(info_ptr); | 45 | - png_info_init(info_ptr); | |
34 | - png_write_init(png_ptr); | 46 | - png_write_init(png_ptr); | |
35 | png_init_io(png_ptr, fp); | 47 | png_init_io(png_ptr, fp); | |
36 | 48 | |||
37 | info_ptr->width = image->width; | 49 | - info_ptr->width = image->width; | |
38 | @@ -200,9 +197,7 @@ | 50 | - info_ptr->height = image->height; | |
51 | - | |||
52 | if (image->isBW) { | |||
53 | if (image->maskData) { | |||
54 | - info_ptr->color_type = PNG_COLOR_TYPE_GRAY_ALPHA; | |||
55 | - info_ptr->bit_depth = 8; /* promote to full grayscale */ | |||
56 | + color_type = PNG_COLOR_TYPE_GRAY_ALPHA; | |||
57 | + bit_depth = 8; /* promote to full grayscale */ | |||
58 | } else { | |||
59 | - info_ptr->color_type = PNG_COLOR_TYPE_GRAY; | |||
60 | - info_ptr->bit_depth = 1; | |||
61 | + color_type = PNG_COLOR_TYPE_GRAY; | |||
62 | + bit_depth = 1; | |||
63 | } | |||
64 | Trace((stderr, "GRR WritePNG: B/W, bit_depth = %d\n", | |||
65 | - info_ptr->bit_depth)); | |||
66 | + bit_depth)); | |||
67 | ||||
68 | } else if (image->isGrey) { | |||
69 | - info_ptr->color_type = image->maskData? PNG_COLOR_TYPE_GRAY_ALPHA : | |||
70 | + color_type = image->maskData? PNG_COLOR_TYPE_GRAY_ALPHA : | |||
71 | PNG_COLOR_TYPE_GRAY; | |||
72 | if (image->cmapPacked) | |||
73 | - info_ptr->bit_depth = 8; | |||
74 | + bit_depth = 8; | |||
75 | else { | |||
76 | Trace((stderr, | |||
77 | "GRR WritePNG: isGrey: cmapSize = %d (before compressing), ", | |||
78 | @@ -86,15 +83,15 @@ WritePNG(char *file, Image *image, int i | |||
79 | compressColormap(image); | |||
80 | Trace((stderr, "%d (after)\n", image->cmapSize)); | |||
81 | if (image->cmapSize > 16) | |||
82 | - info_ptr->bit_depth = 8; | |||
83 | + bit_depth = 8; | |||
84 | else if (image->cmapSize > 4) | |||
85 | - info_ptr->bit_depth = 4; | |||
86 | + bit_depth = 4; | |||
87 | else if (image->cmapSize > 2) | |||
88 | - info_ptr->bit_depth = 2; | |||
89 | + bit_depth = 2; | |||
90 | else | |||
91 | - info_ptr->bit_depth = 1; | |||
92 | + bit_depth = 1; | |||
93 | Trace((stderr, "GRR WritePNG: isGrey: picked bit_depth = %d\n", | |||
94 | - info_ptr->bit_depth)); | |||
95 | + bit_depth)); | |||
96 | } | |||
97 | ||||
98 | } else if (image->scale == 3) { | |||
99 | @@ -107,9 +104,9 @@ WritePNG(char *file, Image *image, int i | |||
100 | if (cmapImage) { | |||
101 | image = cmapImage; /* original was deleted in ImageCompress() */ | |||
102 | } else { | |||
103 | - info_ptr->color_type = image->maskData? PNG_COLOR_TYPE_RGB_ALPHA : | |||
104 | + color_type = image->maskData? PNG_COLOR_TYPE_RGB_ALPHA : | |||
105 | PNG_COLOR_TYPE_RGB; | |||
106 | - info_ptr->bit_depth = 8; | |||
107 | + bit_depth = 8; | |||
108 | Trace((stderr, "GRR WritePNG: RGB, bit_depth = 8\n")); | |||
109 | } | |||
110 | } | |||
111 | @@ -129,7 +126,7 @@ WritePNG(char *file, Image *image, int i | |||
112 | * ImageCompress() worked | |||
113 | */ | |||
114 | if (image->scale == 1) { | |||
115 | - info_ptr->color_type = PNG_COLOR_TYPE_PALETTE; | |||
116 | + color_type = PNG_COLOR_TYPE_PALETTE; | |||
117 | if (image->maskData) { | |||
118 | fprintf(stderr, | |||
119 | "WritePNG: can't use alpha mask with colormapped image\n"); | |||
120 | @@ -139,18 +136,17 @@ WritePNG(char *file, Image *image, int i | |||
121 | if (!image->cmapPacked) | |||
122 | compressColormap(image); | |||
123 | if (image->cmapSize > 16) | |||
124 | - info_ptr->bit_depth = 8; | |||
125 | + bit_depth = 8; | |||
126 | else if (image->cmapSize > 4) | |||
127 | - info_ptr->bit_depth = 4; | |||
128 | + bit_depth = 4; | |||
129 | else if (image->cmapSize > 2) | |||
130 | - info_ptr->bit_depth = 2; | |||
131 | + bit_depth = 2; | |||
132 | else | |||
133 | - info_ptr->bit_depth = 1; | |||
134 | - info_ptr->valid |= PNG_INFO_PLTE; | |||
135 | - info_ptr->num_palette = image->cmapSize; | |||
136 | - info_ptr->palette = (png_colorp)image->cmapData; /* seems to work... */ | |||
137 | - Trace((stderr, "%d, num_palette = %d\n", info_ptr->bit_depth, | |||
138 | - info_ptr->num_palette)); | |||
139 | + bit_depth = 1; | |||
140 | + png_set_PLTE(png_ptr, info_ptr, (png_colorp)image->cmapData, | |||
141 | + image->cmapSize); /* seems to work... */ | |||
142 | + Trace((stderr, "%d, num_palette = %d\n", bit_depth, | |||
143 | + image->cmapSize)); | |||
144 | #if 0 | |||
145 | for (i = 0; i < image->cmapSize; ++i) { | |||
146 | info_ptr->palette[i].red = | |||
147 | @@ -160,14 +156,15 @@ WritePNG(char *file, Image *image, int i | |||
148 | #endif | |||
149 | } | |||
150 | ||||
151 | - info_ptr->interlace_type = interlace_type; | |||
152 | + png_set_IHDR(png_ptr, info_ptr, image->width, image->height, | |||
153 | + bit_depth, color_type, interlace_type, PNG_COMPRESSION_TYPE_BASE, | |||
154 | + PNG_FILTER_TYPE_BASE); | |||
155 | ||||
156 | /* set the file gamma */ | |||
157 | - info_ptr->valid |= PNG_INFO_gAMA; | |||
158 | #ifdef DISPLAY_GAMMA | |||
159 | - info_ptr->gamma = 1.0 / DISPLAY_GAMMA; | |||
160 | + png_set_gAMA(png_ptr, info_ptr, 1.0 / DISPLAY_GAMMA); | |||
161 | #else | |||
162 | - info_ptr->gamma = 0.45; /* default: assume PC-like system */ | |||
163 | + png_set_gAMA(png_ptr, info_ptr, 0.45); /* default: assume PC-like system */ | |||
164 | #endif | |||
165 | ||||
166 | /* info_ptr->valid |= PNG_INFO_tEXt; DOES NOT EXIST */ | |||
167 | @@ -180,16 +177,14 @@ WritePNG(char *file, Image *image, int i | |||
168 | software->key = "Software"; | |||
169 | software->text = software_text; | |||
170 | software->text_length = strlen(software->text); | |||
171 | - info_ptr->num_text = 1; | |||
172 | - info_ptr->text = software; | |||
173 | + png_set_text(png_ptr, info_ptr, software, 1); | |||
174 | } else { | |||
175 | /* couldn't malloc: oh well */ | |||
176 | - info_ptr->num_text = 0; | |||
177 | - info_ptr->text = NULL; | |||
178 | + png_set_text(png_ptr, info_ptr, NULL, 0); | |||
179 | } | |||
180 | ||||
181 | - info_ptr->valid |= PNG_INFO_tIME; | |||
182 | - png_convert_from_time_t(&info_ptr->mod_time, time(NULL)); | |||
183 | + png_convert_from_time_t(mod_time, time(NULL)); | |||
184 | + png_set_tIME(png_ptr, info_ptr, mod_time); | |||
185 | ||||
186 | png_write_flush(png_ptr); | |||
187 | png_write_info(png_ptr, info_ptr); | |||
188 | @@ -200,9 +195,7 @@ WritePNG(char *file, Image *image, int i | |||
39 | /* alpha channel version */ | 189 | /* alpha channel version */ | |
40 | fprintf(stderr, "WritePNG: sorry, can't write alpha images yet\n"); | 190 | fprintf(stderr, "WritePNG: sorry, can't write alpha images yet\n"); | |
41 | fflush(stderr); | 191 | fflush(stderr); | |
42 | - png_write_destroy(png_ptr); | 192 | - png_write_destroy(png_ptr); | |
43 | - free(info_ptr); | 193 | - free(info_ptr); | |
44 | - free(png_ptr); | 194 | - free(png_ptr); | |
45 | + png_destroy_write_struct(&png_ptr, &info_ptr); | 195 | + png_destroy_write_struct(&png_ptr, &info_ptr); | |
46 | fclose(fp); | 196 | fclose(fp); | |
47 | return 1; | 197 | return 1; | |
48 | } else { | 198 | } else { | |
49 | @@ -222,13 +217,11 @@ | 199 | @@ -222,13 +215,11 @@ WritePNG(char *file, Image *image, int i | |
50 | } | 200 | } | |
51 | 201 | |||
52 | png_write_end(png_ptr, NULL); | 202 | png_write_end(png_ptr, NULL); | |
53 | - png_write_destroy(png_ptr); | 203 | - png_write_destroy(png_ptr); | |
54 | + png_destroy_write_struct(&png_ptr, &info_ptr); | 204 | + png_destroy_write_struct(&png_ptr, &info_ptr); | |
55 | 205 | |||
56 | if (software) | 206 | if (software) | |
57 | free(software); /* we LOVE free software!! */ | 207 | free(software); /* we LOVE free software!! */ | |
58 | 208 | |||
59 | - free(info_ptr); | 209 | - free(info_ptr); | |
60 | - free(png_ptr); /* necessary?? */ | 210 | - free(png_ptr); /* necessary?? */ | |
61 | fclose(fp); | 211 | fclose(fp); | |
62 | 212 |