|
Lines 46-51
Link Here
|
| 46 |
#include "qiodevice.h" |
46 |
#include "qiodevice.h" |
| 47 |
|
47 |
|
| 48 |
#include <png.h> |
48 |
#include <png.h> |
|
|
49 |
#if PNG_LIBPNG_VER_MAJOR>1 || ( PNG_LIBPNG_VER_MAJOR==1 && PNG_LIBPNG_VER_MINOR>=5 ) |
| 50 |
#include <zlib.h> |
| 51 |
#endif /* LIBPNG 1.5 */ |
| 49 |
|
52 |
|
| 50 |
|
53 |
|
| 51 |
#ifdef Q_OS_TEMP |
54 |
#ifdef Q_OS_TEMP |
|
Lines 126-134
Link Here
|
| 126 |
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, |
129 |
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, |
| 127 |
0, 0, 0); |
130 |
0, 0, 0); |
| 128 |
|
131 |
|
|
|
132 |
#if PNG_LIBPNG_VER_MAJOR>1 || ( PNG_LIBPNG_VER_MAJOR==1 && PNG_LIBPNG_VER_MINOR>=5 ) |
| 133 |
png_colorp info_ptr_palette = NULL; |
| 134 |
int info_ptr_num_palette = 0; |
| 135 |
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_PLTE)) { |
| 136 |
png_get_PLTE(png_ptr, info_ptr, &info_ptr_palette, &info_ptr_num_palette); |
| 137 |
} |
| 138 |
|
| 139 |
png_bytep info_ptr_trans_alpha = NULL; |
| 140 |
int info_ptr_num_trans = 0; |
| 141 |
png_color_16p info_ptr_trans_color = NULL; |
| 142 |
|
| 143 |
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) { |
| 144 |
png_get_tRNS(png_ptr, info_ptr, &info_ptr_trans_alpha, &info_ptr_num_trans, &info_ptr_trans_color); |
| 145 |
} |
| 146 |
#endif /* LIBPNG 1.5 */ |
| 147 |
|
| 129 |
if ( color_type == PNG_COLOR_TYPE_GRAY ) { |
148 |
if ( color_type == PNG_COLOR_TYPE_GRAY ) { |
| 130 |
// Black & White or 8-bit grayscale |
149 |
// Black & White or 8-bit grayscale |
|
|
150 |
#if PNG_LIBPNG_VER_MAJOR>1 || ( PNG_LIBPNG_VER_MAJOR==1 && PNG_LIBPNG_VER_MINOR>=5 ) |
| 151 |
if ( bit_depth == 1 && png_get_channels(png_ptr, info_ptr) == 1 ) { |
| 152 |
#else /* LIBPNG 1.5 */ |
| 131 |
if ( bit_depth == 1 && info_ptr->channels == 1 ) { |
153 |
if ( bit_depth == 1 && info_ptr->channels == 1 ) { |
|
|
154 |
#endif /* LIBPNG 1.5 */ |
| 132 |
png_set_invert_mono( png_ptr ); |
155 |
png_set_invert_mono( png_ptr ); |
| 133 |
png_read_update_info( png_ptr, info_ptr ); |
156 |
png_read_update_info( png_ptr, info_ptr ); |
| 134 |
if (!image.create( width, height, 1, 2, TQImage::BigEndian )) |
157 |
if (!image.create( width, height, 1, 2, TQImage::BigEndian )) |
|
Lines 162-168
Link Here
|
| 162 |
image.setColor( i, qRgba(c,c,c,0xff) ); |
185 |
image.setColor( i, qRgba(c,c,c,0xff) ); |
| 163 |
} |
186 |
} |
| 164 |
if ( png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS) ) { |
187 |
if ( png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS) ) { |
| 165 |
#if PNG_LIBPNG_VER_MAJOR>1 || ( PNG_LIBPNG_VER_MAJOR==1 && PNG_LIBPNG_VER_MINOR>=4 ) |
188 |
#if PNG_LIBPNG_VER_MAJOR>1 || ( PNG_LIBPNG_VER_MAJOR==1 && PNG_LIBPNG_VER_MINOR>=5 ) |
|
|
189 |
const int g = info_ptr_trans_color->gray; |
| 190 |
#elif ( PNG_LIBPNG_VER_MAJOR==1 && PNG_LIBPNG_VER_MINOR>=4 ) |
| 166 |
const int g = info_ptr->trans_color.gray; |
191 |
const int g = info_ptr->trans_color.gray; |
| 167 |
#else |
192 |
#else |
| 168 |
const int g = info_ptr->trans_values.gray; |
193 |
const int g = info_ptr->trans_values.gray; |
|
Lines 175-181
Link Here
|
| 175 |
} |
200 |
} |
| 176 |
} else if ( color_type == PNG_COLOR_TYPE_PALETTE |
201 |
} else if ( color_type == PNG_COLOR_TYPE_PALETTE |
| 177 |
&& png_get_valid(png_ptr, info_ptr, PNG_INFO_PLTE) |
202 |
&& png_get_valid(png_ptr, info_ptr, PNG_INFO_PLTE) |
|
|
203 |
#if PNG_LIBPNG_VER_MAJOR>1 || ( PNG_LIBPNG_VER_MAJOR==1 && PNG_LIBPNG_VER_MINOR>=5 ) |
| 204 |
&& info_ptr_num_palette <= 256 ) |
| 205 |
#else /* LIBPNG 1.5 */ |
| 178 |
&& info_ptr->num_palette <= 256 ) |
206 |
&& info_ptr->num_palette <= 256 ) |
|
|
207 |
#endif /* LIBPNG 1.5 */ |
| 179 |
{ |
208 |
{ |
| 180 |
// 1-bit and 8-bit color |
209 |
// 1-bit and 8-bit color |
| 181 |
if ( bit_depth != 1 ) |
210 |
if ( bit_depth != 1 ) |
|
Lines 183-200
Link Here
|
| 183 |
png_read_update_info( png_ptr, info_ptr ); |
212 |
png_read_update_info( png_ptr, info_ptr ); |
| 184 |
png_get_IHDR(png_ptr, info_ptr, |
213 |
png_get_IHDR(png_ptr, info_ptr, |
| 185 |
&width, &height, &bit_depth, &color_type, 0, 0, 0); |
214 |
&width, &height, &bit_depth, &color_type, 0, 0, 0); |
|
|
215 |
#if PNG_LIBPNG_VER_MAJOR>1 || ( PNG_LIBPNG_VER_MAJOR==1 && PNG_LIBPNG_VER_MINOR>=5 ) |
| 216 |
if (!image.create(width, height, bit_depth, info_ptr_num_palette, |
| 217 |
#else /* LIBPNG 1.5 */ |
| 186 |
if (!image.create(width, height, bit_depth, info_ptr->num_palette, |
218 |
if (!image.create(width, height, bit_depth, info_ptr->num_palette, |
|
|
219 |
#endif /* LIBPNG 1.5 */ |
| 187 |
TQImage::BigEndian)) |
220 |
TQImage::BigEndian)) |
| 188 |
return; |
221 |
return; |
| 189 |
int i = 0; |
222 |
int i = 0; |
| 190 |
if ( png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS) ) { |
223 |
if ( png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS) ) { |
| 191 |
image.setAlphaBuffer( TRUE ); |
224 |
image.setAlphaBuffer( TRUE ); |
|
|
225 |
#if PNG_LIBPNG_VER_MAJOR>1 || ( PNG_LIBPNG_VER_MAJOR==1 && PNG_LIBPNG_VER_MINOR>=5 ) |
| 226 |
while ( i < info_ptr_num_trans ) { |
| 227 |
image.setColor(i, qRgba( |
| 228 |
info_ptr_palette[i].red, |
| 229 |
info_ptr_palette[i].green, |
| 230 |
info_ptr_palette[i].blue, |
| 231 |
#else /* LIBPNG 1.5 */ |
| 192 |
while ( i < info_ptr->num_trans ) { |
232 |
while ( i < info_ptr->num_trans ) { |
| 193 |
image.setColor(i, qRgba( |
233 |
image.setColor(i, qRgba( |
| 194 |
info_ptr->palette[i].red, |
234 |
info_ptr->palette[i].red, |
| 195 |
info_ptr->palette[i].green, |
235 |
info_ptr->palette[i].green, |
| 196 |
info_ptr->palette[i].blue, |
236 |
info_ptr->palette[i].blue, |
| 197 |
#if PNG_LIBPNG_VER_MAJOR>1 || ( PNG_LIBPNG_VER_MAJOR==1 && PNG_LIBPNG_VER_MINOR>=4 ) |
237 |
#endif /* LIBPNG 1.5 */ |
|
|
238 |
#if PNG_LIBPNG_VER_MAJOR>1 || ( PNG_LIBPNG_VER_MAJOR==1 && PNG_LIBPNG_VER_MINOR>=5 ) |
| 239 |
info_ptr_trans_alpha[i] |
| 240 |
#elif ( PNG_LIBPNG_VER_MAJOR==1 && PNG_LIBPNG_VER_MINOR>=4 ) |
| 198 |
info_ptr->trans_alpha[i] |
241 |
info_ptr->trans_alpha[i] |
| 199 |
#else |
242 |
#else |
| 200 |
info_ptr->trans[i] |
243 |
info_ptr->trans[i] |
|
Lines 204-214
Link Here
|
| 204 |
i++; |
247 |
i++; |
| 205 |
} |
248 |
} |
| 206 |
} |
249 |
} |
|
|
250 |
#if PNG_LIBPNG_VER_MAJOR>1 || ( PNG_LIBPNG_VER_MAJOR==1 && PNG_LIBPNG_VER_MINOR>=5 ) |
| 251 |
while ( i < info_ptr_num_palette ) { |
| 252 |
image.setColor(i, qRgba( |
| 253 |
info_ptr_palette[i].red, |
| 254 |
info_ptr_palette[i].green, |
| 255 |
info_ptr_palette[i].blue, |
| 256 |
#else /* LIBPNG 1.5 */ |
| 207 |
while ( i < info_ptr->num_palette ) { |
257 |
while ( i < info_ptr->num_palette ) { |
| 208 |
image.setColor(i, qRgba( |
258 |
image.setColor(i, qRgba( |
| 209 |
info_ptr->palette[i].red, |
259 |
info_ptr->palette[i].red, |
| 210 |
info_ptr->palette[i].green, |
260 |
info_ptr->palette[i].green, |
| 211 |
info_ptr->palette[i].blue, |
261 |
info_ptr->palette[i].blue, |
|
|
262 |
#endif /* LIBPNG 1.5 */ |
| 212 |
0xff |
263 |
0xff |
| 213 |
) |
264 |
) |
| 214 |
); |
265 |
); |
|
Lines 295-301
Link Here
|
| 295 |
return; |
346 |
return; |
| 296 |
} |
347 |
} |
| 297 |
|
348 |
|
|
|
349 |
#if PNG_LIBPNG_VER_MAJOR>1 || ( PNG_LIBPNG_VER_MAJOR==1 && PNG_LIBPNG_VER_MINOR>=5 ) |
| 350 |
if (setjmp(png_jmpbuf(png_ptr))) { |
| 351 |
#else /* LIBPNG 1.5 */ |
| 298 |
if (setjmp(png_ptr->jmpbuf)) { |
352 |
if (setjmp(png_ptr->jmpbuf)) { |
|
|
353 |
#endif /* LIBPNG 1.5 */ |
| 299 |
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info); |
354 |
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info); |
| 300 |
iio->setStatus(-4); |
355 |
iio->setStatus(-4); |
| 301 |
return; |
356 |
return; |
|
Lines 486-492
Link Here
|
| 486 |
return FALSE; |
541 |
return FALSE; |
| 487 |
} |
542 |
} |
| 488 |
|
543 |
|
|
|
544 |
#if PNG_LIBPNG_VER_MAJOR>1 || ( PNG_LIBPNG_VER_MAJOR==1 && PNG_LIBPNG_VER_MINOR>=5 ) |
| 545 |
if (setjmp(png_jmpbuf(png_ptr))) { |
| 546 |
#else /* LIBPNG 1.5 */ |
| 489 |
if (setjmp(png_ptr->jmpbuf)) { |
547 |
if (setjmp(png_ptr->jmpbuf)) { |
|
|
548 |
#endif /* LIBPNG 1.5 */ |
| 490 |
png_destroy_write_struct(&png_ptr, &info_ptr); |
549 |
png_destroy_write_struct(&png_ptr, &info_ptr); |
| 491 |
return FALSE; |
550 |
return FALSE; |
| 492 |
} |
551 |
} |
|
Lines 508-517
Link Here
|
| 508 |
|
567 |
|
| 509 |
png_set_write_fn(png_ptr, (void*)this, qpiw_write_fn, qpiw_flush_fn); |
568 |
png_set_write_fn(png_ptr, (void*)this, qpiw_write_fn, qpiw_flush_fn); |
| 510 |
|
569 |
|
|
|
570 |
#if PNG_LIBPNG_VER_MAJOR>1 || ( PNG_LIBPNG_VER_MAJOR==1 && PNG_LIBPNG_VER_MINOR>=5 ) |
| 571 |
#warning XXXtnn not too sure about this |
| 572 |
/* |
| 573 |
according to png.h, channels is only used on read, not writes, so we |
| 574 |
should be able to comment this out. |
| 575 |
*/ |
| 576 |
#else /* LIBPNG 1.5 */ |
| 511 |
info_ptr->channels = |
577 |
info_ptr->channels = |
| 512 |
(image.depth() == 32) |
578 |
(image.depth() == 32) |
| 513 |
? (image.hasAlphaBuffer() ? 4 : 3) |
579 |
? (image.hasAlphaBuffer() ? 4 : 3) |
| 514 |
: 1; |
580 |
: 1; |
|
|
581 |
#endif /* LIBPNG 1.5 */ |
| 515 |
|
582 |
|
| 516 |
png_set_IHDR(png_ptr, info_ptr, image.width(), image.height(), |
583 |
png_set_IHDR(png_ptr, info_ptr, image.width(), image.height(), |
| 517 |
image.depth() == 1 ? 1 : 8 /* per channel */, |
584 |
image.depth() == 1 ? 1 : 8 /* per channel */, |
|
Lines 521-531
Link Here
|
| 521 |
: PNG_COLOR_TYPE_RGB |
588 |
: PNG_COLOR_TYPE_RGB |
| 522 |
: PNG_COLOR_TYPE_PALETTE, 0, 0, 0); |
589 |
: PNG_COLOR_TYPE_PALETTE, 0, 0, 0); |
| 523 |
|
590 |
|
| 524 |
|
591 |
#if PNG_LIBPNG_VER_MAJOR>1 || ( PNG_LIBPNG_VER_MAJOR==1 && PNG_LIBPNG_VER_MINOR>=5 ) |
|
|
592 |
png_color_8 sig_bit; |
| 593 |
sig_bit.red = 8; |
| 594 |
sig_bit.green = 8; |
| 595 |
sig_bit.blue = 8; |
| 596 |
png_set_sBIT(png_ptr, info_ptr, &sig_bit); |
| 597 |
#else /* LIBPNG 1.5 */ |
| 525 |
//png_set_sBIT(png_ptr, info_ptr, 8); |
598 |
//png_set_sBIT(png_ptr, info_ptr, 8); |
| 526 |
info_ptr->sig_bit.red = 8; |
599 |
info_ptr->sig_bit.red = 8; |
| 527 |
info_ptr->sig_bit.green = 8; |
600 |
info_ptr->sig_bit.green = 8; |
| 528 |
info_ptr->sig_bit.blue = 8; |
601 |
info_ptr->sig_bit.blue = 8; |
|
|
602 |
#endif /* LIBPNG 1.5 */ |
| 529 |
|
603 |
|
| 530 |
if (image.depth() == 1 && image.bitOrder() == TQImage::LittleEndian) |
604 |
if (image.depth() == 1 && image.bitOrder() == TQImage::LittleEndian) |
| 531 |
png_set_packswap(png_ptr); |
605 |
png_set_packswap(png_ptr); |
|
Lines 539-549
Link Here
|
| 539 |
png_set_PLTE(png_ptr, info_ptr, palette, num_palette); |
613 |
png_set_PLTE(png_ptr, info_ptr, palette, num_palette); |
| 540 |
int* trans = new int[num_palette]; |
614 |
int* trans = new int[num_palette]; |
| 541 |
int num_trans = 0; |
615 |
int num_trans = 0; |
|
|
616 |
#if PNG_LIBPNG_VER_MAJOR>1 || ( PNG_LIBPNG_VER_MAJOR==1 && PNG_LIBPNG_VER_MINOR>=5 ) |
| 617 |
png_colorp info_ptr_palette = NULL; |
| 618 |
int tmp; |
| 619 |
png_get_PLTE(png_ptr, info_ptr, &info_ptr_palette, &tmp); |
| 620 |
#endif /* LIBPNG 1.5 */ |
| 542 |
for (int i=0; i<num_palette; i++) { |
621 |
for (int i=0; i<num_palette; i++) { |
| 543 |
TQRgb rgb=image.color(i); |
622 |
TQRgb rgb=image.color(i); |
|
|
623 |
#if PNG_LIBPNG_VER_MAJOR>1 || ( PNG_LIBPNG_VER_MAJOR==1 && PNG_LIBPNG_VER_MINOR>=5 ) |
| 624 |
info_ptr_palette[i].red = qRed(rgb); |
| 625 |
info_ptr_palette[i].green = qGreen(rgb); |
| 626 |
info_ptr_palette[i].blue = qBlue(rgb); |
| 627 |
#else /* LIBPNG 1.5 */ |
| 544 |
info_ptr->palette[i].red = qRed(rgb); |
628 |
info_ptr->palette[i].red = qRed(rgb); |
| 545 |
info_ptr->palette[i].green = qGreen(rgb); |
629 |
info_ptr->palette[i].green = qGreen(rgb); |
| 546 |
info_ptr->palette[i].blue = qBlue(rgb); |
630 |
info_ptr->palette[i].blue = qBlue(rgb); |
|
|
631 |
#endif /* LIBPNG 1.5 */ |
| 547 |
if (image.hasAlphaBuffer()) { |
632 |
if (image.hasAlphaBuffer()) { |
| 548 |
trans[i] = rgb >> 24; |
633 |
trans[i] = rgb >> 24; |
| 549 |
if (trans[i] < 255) { |
634 |
if (trans[i] < 255) { |
|
Lines 551-556
Link Here
|
| 551 |
} |
636 |
} |
| 552 |
} |
637 |
} |
| 553 |
} |
638 |
} |
|
|
639 |
#if PNG_LIBPNG_VER_MAJOR>1 || ( PNG_LIBPNG_VER_MAJOR==1 && PNG_LIBPNG_VER_MINOR>=5 ) |
| 640 |
png_set_PLTE(png_ptr, info_ptr, info_ptr_palette, num_palette); |
| 641 |
#endif /* LIBPNG 1.5 */ |
| 554 |
if (num_trans) { |
642 |
if (num_trans) { |
| 555 |
copy_trans = new png_byte[num_trans]; |
643 |
copy_trans = new png_byte[num_trans]; |
| 556 |
for (int i=0; i<num_trans; i++) |
644 |
for (int i=0; i<num_trans; i++) |
|
Lines 561-567
Link Here
|
| 561 |
} |
649 |
} |
| 562 |
|
650 |
|
| 563 |
if ( image.hasAlphaBuffer() ) { |
651 |
if ( image.hasAlphaBuffer() ) { |
|
|
652 |
#if PNG_LIBPNG_VER_MAJOR>1 || ( PNG_LIBPNG_VER_MAJOR==1 && PNG_LIBPNG_VER_MINOR>=5 ) |
| 653 |
png_color_8p sig_bit; |
| 654 |
png_get_sBIT(png_ptr, info_ptr, &sig_bit); |
| 655 |
sig_bit->alpha = 8; |
| 656 |
png_set_sBIT(png_ptr, info_ptr, sig_bit); |
| 657 |
#else /* LIBPNG 1.5 */ |
| 564 |
info_ptr->sig_bit.alpha = 8; |
658 |
info_ptr->sig_bit.alpha = 8; |
|
|
659 |
#endif /* LIBPNG 1.5 */ |
| 565 |
} |
660 |
} |
| 566 |
|
661 |
|
| 567 |
// Swap ARGB to RGBA (normal PNG format) before saving on |
662 |
// Swap ARGB to RGBA (normal PNG format) before saving on |
|
Lines 1047-1053
Link Here
|
| 1047 |
return -1; |
1142 |
return -1; |
| 1048 |
} |
1143 |
} |
| 1049 |
|
1144 |
|
|
|
1145 |
#if PNG_LIBPNG_VER_MAJOR>1 || ( PNG_LIBPNG_VER_MAJOR==1 && PNG_LIBPNG_VER_MINOR>=5 ) |
| 1146 |
if (setjmp(png_jmpbuf(png_ptr))) { |
| 1147 |
#else /* LIBPNG 1.5 */ |
| 1050 |
if (setjmp((png_ptr)->jmpbuf)) { |
1148 |
if (setjmp((png_ptr)->jmpbuf)) { |
|
|
1149 |
#endif /* LIBPNG 1.5 */ |
| 1051 |
png_destroy_read_struct(&png_ptr, &info_ptr, 0); |
1150 |
png_destroy_read_struct(&png_ptr, &info_ptr, 0); |
| 1052 |
image = 0; |
1151 |
image = 0; |
| 1053 |
return -1; |
1152 |
return -1; |
|
Lines 1074-1080
Link Here
|
| 1074 |
|
1173 |
|
| 1075 |
if ( !png_ptr ) return 0; |
1174 |
if ( !png_ptr ) return 0; |
| 1076 |
|
1175 |
|
|
|
1176 |
#if PNG_LIBPNG_VER_MAJOR>1 || ( PNG_LIBPNG_VER_MAJOR==1 && PNG_LIBPNG_VER_MINOR>=5 ) |
| 1177 |
if (setjmp(png_jmpbuf(png_ptr))) { |
| 1178 |
#else /* LIBPNG 1.5 */ |
| 1077 |
if (setjmp(png_ptr->jmpbuf)) { |
1179 |
if (setjmp(png_ptr->jmpbuf)) { |
|
|
1180 |
#endif /* LIBPNG 1.5 */ |
| 1078 |
png_destroy_read_struct(&png_ptr, &info_ptr, 0); |
1181 |
png_destroy_read_struct(&png_ptr, &info_ptr, 0); |
| 1079 |
image = 0; |
1182 |
image = 0; |
| 1080 |
state = MovieStart; |
1183 |
state = MovieStart; |
|
Lines 1134-1140
Link Here
|
| 1134 |
consumer->frameDone(TQPoint(offx,offy),r); |
1237 |
consumer->frameDone(TQPoint(offx,offy),r); |
| 1135 |
consumer->end(); |
1238 |
consumer->end(); |
| 1136 |
state = FrameStart; |
1239 |
state = FrameStart; |
|
|
1240 |
#if PNG_LIBPNG_VER_MAJOR>1 || ( PNG_LIBPNG_VER_MAJOR==1 && PNG_LIBPNG_VER_MINOR>=5 ) |
| 1241 |
unused_data = png_process_data_pause(png, 0); |
| 1242 |
#else /* LIBPNG 1.5 */ |
| 1137 |
unused_data = (int)png->buffer_size; // Since libpng doesn't tell us |
1243 |
unused_data = (int)png->buffer_size; // Since libpng doesn't tell us |
|
|
1244 |
#endif /* LIBPNG 1.5 */ |
| 1138 |
} |
1245 |
} |
| 1139 |
|
1246 |
|
| 1140 |
#ifdef PNG_USER_CHUNKS_SUPPORTED |
1247 |
#ifdef PNG_USER_CHUNKS_SUPPORTED |