3 * fixes build with libpng
>=1.5.
5 --- src
/images
/Fl_Png
.cpp
.orig
2003-07-13 15:07:26.000000000 +0000
6 +++ src
/images
/Fl_Png
.cpp
7 @@
-18,17 +18,17 @@
bool setup_png_transformations(png_struc
8 static void my_png_warning(png_structp png_ptr
, png_const_charp message
)
10 const char *name
= "PNG: Unknown (WARNING!)";
11 - if (png_ptr
!= NULL
&& png_ptr
->error_ptr
!= NULL
)
12 - name
= (const char *)png_ptr
->error_ptr
;
13 + if (png_ptr
!= NULL
&& png_get_error_ptr(png_ptr
) != NULL
)
14 + name
= (const char *)png_get_error_ptr(png_ptr
);
15 Fl::warning("%s: libpng warning: %s", name
, message
);
18 static void my_png_error(png_structp png_ptr
, png_const_charp message
)
20 png_last_error
= (volatile char*)"PNG: Unknown (ERROR!)";
21 - if (png_ptr
!= NULL
&& png_ptr
->error_ptr
!= NULL
)
22 + if (png_ptr
!= NULL
&& png_get_error_ptr(png_ptr
) != NULL
)
23 png_last_error
= (volatile char*)message
;
24 - longjmp(png_ptr
->jmpbuf
, 0);
25 + png_longjmp(png_ptr
, 0);
28 static bool png_is_valid_file(const char *filename
)
29 @@
-56,7 +56,7 @@
static bool png_is_valid_mem(const uint8
32 static void read_data_fn(png_structp png_ptr
, png_bytep d
, png_size_t length
) {
33 - ((Fl_IO
*)png_ptr
->io_ptr
)->read(d
, length
);
34 + ((Fl_IO
*)png_get_io_ptr(png_ptr
))->read(d
, length
);
37 #define return_error() \
38 @@ -81,7 +81,7 @@ static bool png_create(Fl_IO &png_io, ui
39 if(!end_info_ptr
) { return_error(); }
42 - if(setjmp(png_ptr
->jmpbuf
)) {
43 + if(setjmp(png_jmpbuf(png_ptr
))) {
45 if(png_ptr
) png_destroy_read_struct (&png_ptr
, &info_ptr
, &end_info_ptr
);
46 fputs((const char *)png_last_error
, stderr
);
47 @@
-94,6 +94,8 @@
static bool png_create(Fl_IO
&png_io
, ui
49 uint32 Rmask
=0, Gmask
=0, Bmask
=0, Amask
=0;
50 png_color_16
*transv
=0;
51 + png_colorp png_palette
;
52 + int png_num_palette
;
53 Fl_Colormap
*palette
=0;
55 png_set_error_fn(png_ptr
, (png_voidp
)0, my_png_error
, my_png_warning
);
56 @@
-108,15 +110,15 @@
static bool png_create(Fl_IO
&png_io
, ui
60 - Amask
= (info_ptr
->channels
== 4) ? 0xFF000000 : 0;
61 + Amask
= (png_get_channels(png_ptr
, info_ptr
) == 4) ? 0xFF000000 : 0;
63 - int s
= (info_ptr
->channels
== 4) ? 0 : 8;
64 + int s
= (png_get_channels(png_ptr
, info_ptr
) == 4) ? 0 : 8;
65 Rmask
= 0xFF000000 >> s
;
66 Gmask
= 0x00FF0000 >> s
;
67 Bmask
= 0x0000FF00 >> s
;
68 Amask
= 0x000000FF >> s
;
70 - if(info_ptr
->channels
== 4)
71 + if(png_get_channels(png_ptr
, info_ptr
) == 4)
72 fmt
.masktype
= FL_MASK_ALPHA
;
75 @@
-144,13 +146,13 @@
static bool png_create(Fl_IO
&png_io
, ui
76 palette
->colors
[i
].g
= i
;
77 palette
->colors
[i
].b
= i
;
79 - } else if(info_ptr
->num_palette
> 0 )
80 + } else if(png_get_PLTE(png_ptr
, info_ptr
, &png_palette
, &png_num_palette
) != 0 )
82 - palette
->ncolors
= info_ptr
->num_palette
;
83 - for( i
=0; i
<info_ptr
->num_palette
; ++i
) {
84 - palette
->colors
[i
].b
= info_ptr
->palette
[i
].blue
;
85 - palette
->colors
[i
].g
= info_ptr
->palette
[i
].green
;
86 - palette
->colors
[i
].r
= info_ptr
->palette
[i
].red
;
87 + palette
->ncolors
= png_num_palette
;
88 + for( i
=0; i
<png_num_palette
; ++i
) {
89 + palette
->colors
[i
].b
= png_palette
[i
].blue
;
90 + palette
->colors
[i
].g
= png_palette
[i
].green
;
91 + palette
->colors
[i
].r
= png_palette
[i
].red
;
95 @@
-178,10 +180,11 @@
bool setup_png_transformations(png_struc
97 int bit_depth
, interlace_type
, compression_type
, filter_type
;
101 /* Get the image info */
102 png_get_IHDR(png_ptr
, info_ptr
,
103 - (ulong
*)&width
, (ulong
*)&height
,
108 @@
-191,10 +194,10 @@
bool setup_png_transformations(png_struc
109 /* Extract multiple pixels with bit depths of 1, 2, and 4 from a single
110 * byte into separate bytes (useful for paletted and grayscale images).
112 - if (info_ptr
->bit_depth
< 8)
113 + if (png_get_bit_depth(png_ptr
, info_ptr
) < 8)
114 png_set_packing(png_ptr
);
115 /* tell libpng to strip 16 bit/color files down to 8 bits/color */
116 - else if (info_ptr
->bit_depth
== 16)
117 + else if (png_get_bit_depth(png_ptr
, info_ptr
) == 16)
118 png_set_strip_16(png_ptr
) ;
120 /* scale greyscale values to the range 0..255 */
121 @@
-234,7 +237,7 @@
bool setup_png_transformations(png_struc
122 /* Update the info the reflect our transformations */
123 png_read_update_info(png_ptr
, info_ptr
);
124 png_get_IHDR(png_ptr
, info_ptr
,
125 - (ulong
*)&width
, (ulong
*)&height
,
130 @@
-242,6 +245,8 @@
bool setup_png_transformations(png_struc
132 channels
= png_get_channels(png_ptr
, info_ptr
);
133 bitspp
= bit_depth
*channels
;
137 if(channels
< 1 || channels
> 4) {
139 @@
-254,7 +259,7 @@
bool setup_png_transformations(png_struc
140 // PNG WRITE METHODS:
142 static void write_data_fn(png_structp png_ptr
, png_bytep d
, png_size_t length
) {
143 - ((Fl_IO
*)png_ptr
->io_ptr
)->write(d
, length
);
144 + ((Fl_IO
*)png_get_io_ptr(png_ptr
))->write(d
, length
);
145 //png_io.write(d, length);
148 @@
-318,7 +323,7 @@
static bool png_write(Fl_IO
&png_io
, con
150 bool allocated
= false;
151 uint8
*wr_data
= (uint8
*)data
;
152 - if(setjmp(png_ptr
->jmpbuf
)) {
153 + if(setjmp(png_jmpbuf(png_ptr
))) {
154 if(png_ptr
) png_destroy_write_struct(&png_ptr
, &info_ptr
);
155 if(allocated
&& wr_data
) free(wr_data
);
157 @@
-373,7 +378,6 @@
static bool png_write(Fl_IO
&png_io
, con
158 * PNG_INTERLACE_ADAM7
, and the compression_type
and filter_type MUST
159 * currently be PNG_COMPRESSION_TYPE_BASE
and PNG_FILTER_TYPE_BASE
. REQUIRED
161 - info_ptr
->channels
= wr_fmt
->bytespp
;
162 png_set_IHDR(png_ptr
, info_ptr
, w
, h
,
163 (wr_fmt
->bitspp
==1) == 1 ? 1 : 8 /* per channel */,
165 @@
-385,9 +389,14 @@
static bool png_write(Fl_IO
&png_io
, con
169 - info_ptr
->sig_bit
.red
= 8;
170 - info_ptr
->sig_bit
.green
= 8;
171 - info_ptr
->sig_bit
.blue
= 8;
172 + png_color_8 sig_bit
;
176 + if(wr_fmt
->Amask
) {
179 + png_set_sBIT(png_ptr
, info_ptr
, &sig_bit
);
181 if(wr_fmt
->bitspp
==1) png_set_packswap(png_ptr
);
183 @@
-418,10 +427,6 @@
static bool png_write(Fl_IO
&png_io
, con
184 png_set_PLTE(png_ptr
, info_ptr
, palette
, wr_fmt
->palette
->ncolors
);
187 - if(wr_fmt
->Amask
) {
188 - info_ptr
->sig_bit
.alpha
= 8;
191 /* Write the file header information. REQUIRED */
192 png_write_info(png_ptr
, info_ptr
);