|
|
|
@ -46,7 +46,7 @@
|
|
|
|
|
#include "qiodevice.h"
|
|
|
|
|
|
|
|
|
|
#include <png.h>
|
|
|
|
|
#if PNG_LIBPNG_VER_MAJOR>1 || ( PNG_LIBPNG_VER_MAJOR==1 && PNG_LIBPNG_VER_MINOR>=5 )
|
|
|
|
|
#if PNG_LIBPNG_VER>=10500
|
|
|
|
|
#include <zlib.h>
|
|
|
|
|
#endif /* LIBPNG 1.5 */
|
|
|
|
|
|
|
|
|
@ -129,7 +129,7 @@ void setup_qt( QImage& image, png_structp png_ptr, png_infop info_ptr, float scr
|
|
|
|
|
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
|
|
|
|
|
0, 0, 0);
|
|
|
|
|
|
|
|
|
|
#if PNG_LIBPNG_VER_MAJOR>1 || ( PNG_LIBPNG_VER_MAJOR==1 && PNG_LIBPNG_VER_MINOR>=5 )
|
|
|
|
|
#if PNG_LIBPNG_VER>=10500
|
|
|
|
|
png_colorp info_ptr_palette = NULL;
|
|
|
|
|
int info_ptr_num_palette = 0;
|
|
|
|
|
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_PLTE)) {
|
|
|
|
@ -147,7 +147,7 @@ void setup_qt( QImage& image, png_structp png_ptr, png_infop info_ptr, float scr
|
|
|
|
|
|
|
|
|
|
if ( color_type == PNG_COLOR_TYPE_GRAY ) {
|
|
|
|
|
// Black & White or 8-bit grayscale
|
|
|
|
|
#if PNG_LIBPNG_VER_MAJOR>1 || ( PNG_LIBPNG_VER_MAJOR==1 && PNG_LIBPNG_VER_MINOR>=5 )
|
|
|
|
|
#if PNG_LIBPNG_VER>=10500
|
|
|
|
|
if ( bit_depth == 1 && png_get_channels(png_ptr, info_ptr) == 1 ) {
|
|
|
|
|
#else /* LIBPNG 1.5 */
|
|
|
|
|
if ( bit_depth == 1 && info_ptr->channels == 1 ) {
|
|
|
|
@ -185,9 +185,9 @@ void setup_qt( QImage& image, png_structp png_ptr, png_infop info_ptr, float scr
|
|
|
|
|
image.setColor( i, qRgba(c,c,c,0xff) );
|
|
|
|
|
}
|
|
|
|
|
if ( png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS) ) {
|
|
|
|
|
#if PNG_LIBPNG_VER_MAJOR>1 || ( PNG_LIBPNG_VER_MAJOR==1 && PNG_LIBPNG_VER_MINOR>=5 )
|
|
|
|
|
#if PNG_LIBPNG_VER>=10500
|
|
|
|
|
const int g = info_ptr_trans_color->gray;
|
|
|
|
|
#elif ( PNG_LIBPNG_VER_MAJOR==1 && PNG_LIBPNG_VER_MINOR>=4 )
|
|
|
|
|
#elif PNG_LIBPNG_VER>=10400
|
|
|
|
|
const int g = info_ptr->trans_color.gray;
|
|
|
|
|
#else
|
|
|
|
|
const int g = info_ptr->trans_values.gray;
|
|
|
|
@ -200,7 +200,7 @@ void setup_qt( QImage& image, png_structp png_ptr, png_infop info_ptr, float scr
|
|
|
|
|
}
|
|
|
|
|
} else if ( color_type == PNG_COLOR_TYPE_PALETTE
|
|
|
|
|
&& png_get_valid(png_ptr, info_ptr, PNG_INFO_PLTE)
|
|
|
|
|
#if PNG_LIBPNG_VER_MAJOR>1 || ( PNG_LIBPNG_VER_MAJOR==1 && PNG_LIBPNG_VER_MINOR>=5 )
|
|
|
|
|
#if PNG_LIBPNG_VER>=10500
|
|
|
|
|
&& info_ptr_num_palette <= 256 )
|
|
|
|
|
#else /* LIBPNG 1.5 */
|
|
|
|
|
&& info_ptr->num_palette <= 256 )
|
|
|
|
@ -212,7 +212,7 @@ void setup_qt( QImage& image, png_structp png_ptr, png_infop info_ptr, float scr
|
|
|
|
|
png_read_update_info( png_ptr, info_ptr );
|
|
|
|
|
png_get_IHDR(png_ptr, info_ptr,
|
|
|
|
|
&width, &height, &bit_depth, &color_type, 0, 0, 0);
|
|
|
|
|
#if PNG_LIBPNG_VER_MAJOR>1 || ( PNG_LIBPNG_VER_MAJOR==1 && PNG_LIBPNG_VER_MINOR>=5 )
|
|
|
|
|
#if PNG_LIBPNG_VER>=10500
|
|
|
|
|
if (!image.create(width, height, bit_depth, info_ptr_num_palette,
|
|
|
|
|
#else /* LIBPNG 1.5 */
|
|
|
|
|
if (!image.create(width, height, bit_depth, info_ptr->num_palette,
|
|
|
|
@ -223,7 +223,7 @@ void setup_qt( QImage& image, png_structp png_ptr, png_infop info_ptr, float scr
|
|
|
|
|
if ( png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS) ) {
|
|
|
|
|
image.setAlphaBuffer( TRUE );
|
|
|
|
|
|
|
|
|
|
#if PNG_LIBPNG_VER_MAJOR>1 || ( PNG_LIBPNG_VER_MAJOR==1 && PNG_LIBPNG_VER_MINOR>=5 )
|
|
|
|
|
#if PNG_LIBPNG_VER>=10500
|
|
|
|
|
while ( i < info_ptr_num_trans ) {
|
|
|
|
|
image.setColor(i, qRgba(
|
|
|
|
|
info_ptr_palette[i].red,
|
|
|
|
@ -236,9 +236,9 @@ void setup_qt( QImage& image, png_structp png_ptr, png_infop info_ptr, float scr
|
|
|
|
|
info_ptr->palette[i].green,
|
|
|
|
|
info_ptr->palette[i].blue,
|
|
|
|
|
#endif /* LIBPNG 1.5 */
|
|
|
|
|
#if PNG_LIBPNG_VER_MAJOR>1 || ( PNG_LIBPNG_VER_MAJOR==1 && PNG_LIBPNG_VER_MINOR>=5 )
|
|
|
|
|
#if PNG_LIBPNG_VER>=10500
|
|
|
|
|
info_ptr_trans_alpha[i]
|
|
|
|
|
#elif ( PNG_LIBPNG_VER_MAJOR==1 && PNG_LIBPNG_VER_MINOR>=4 )
|
|
|
|
|
#elif PNG_LIBPNG_VER>=10400
|
|
|
|
|
info_ptr->trans_alpha[i]
|
|
|
|
|
#else
|
|
|
|
|
info_ptr->trans[i]
|
|
|
|
@ -248,7 +248,7 @@ void setup_qt( QImage& image, png_structp png_ptr, png_infop info_ptr, float scr
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#if PNG_LIBPNG_VER_MAJOR>1 || ( PNG_LIBPNG_VER_MAJOR==1 && PNG_LIBPNG_VER_MINOR>=5 )
|
|
|
|
|
#if PNG_LIBPNG_VER>=10500
|
|
|
|
|
while ( i < info_ptr_num_palette ) {
|
|
|
|
|
image.setColor(i, qRgba(
|
|
|
|
|
info_ptr_palette[i].red,
|
|
|
|
@ -347,7 +347,7 @@ void read_png_image(QImageIO* iio)
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if PNG_LIBPNG_VER_MAJOR>1 || ( PNG_LIBPNG_VER_MAJOR==1 && PNG_LIBPNG_VER_MINOR>=5 )
|
|
|
|
|
#if PNG_LIBPNG_VER>=10500
|
|
|
|
|
if (setjmp(png_jmpbuf(png_ptr))) {
|
|
|
|
|
#else /* LIBPNG 1.5 */
|
|
|
|
|
if (setjmp(png_ptr->jmpbuf)) {
|
|
|
|
@ -388,7 +388,7 @@ void read_png_image(QImageIO* iio)
|
|
|
|
|
png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)
|
|
|
|
|
if (image.depth()==32 && png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
|
|
|
|
|
QRgb trans = 0xFF000000 | qRgb(
|
|
|
|
|
#if PNG_LIBPNG_VER_MAJOR>1 || ( PNG_LIBPNG_VER_MAJOR==1 && PNG_LIBPNG_VER_MINOR>=4 )
|
|
|
|
|
#if PNG_LIBPNG_VER>=10400
|
|
|
|
|
(info_ptr->trans_color.red << 8 >> bit_depth)&0xff,
|
|
|
|
|
(info_ptr->trans_color.green << 8 >> bit_depth)&0xff,
|
|
|
|
|
(info_ptr->trans_color.blue << 8 >> bit_depth)&0xff);
|
|
|
|
@ -542,7 +542,7 @@ bool QPNGImageWriter::writeImage(const QImage& image, int quality_in, int off_x_
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if PNG_LIBPNG_VER_MAJOR>1 || ( PNG_LIBPNG_VER_MAJOR==1 && PNG_LIBPNG_VER_MINOR>=5 )
|
|
|
|
|
#if PNG_LIBPNG_VER>=10500
|
|
|
|
|
if (setjmp(png_jmpbuf(png_ptr))) {
|
|
|
|
|
#else /* LIBPNG 1.5 */
|
|
|
|
|
if (setjmp(png_ptr->jmpbuf)) {
|
|
|
|
@ -568,7 +568,7 @@ bool QPNGImageWriter::writeImage(const QImage& image, int quality_in, int off_x_
|
|
|
|
|
|
|
|
|
|
png_set_write_fn(png_ptr, (void*)this, qpiw_write_fn, qpiw_flush_fn);
|
|
|
|
|
|
|
|
|
|
#if PNG_LIBPNG_VER_MAJOR>1 || ( PNG_LIBPNG_VER_MAJOR==1 && PNG_LIBPNG_VER_MINOR>=5 )
|
|
|
|
|
#if PNG_LIBPNG_VER>=10500
|
|
|
|
|
#warning XXXtnn not too sure about this
|
|
|
|
|
/*
|
|
|
|
|
according to png.h, channels is only used on read, not writes, so we
|
|
|
|
@ -589,7 +589,7 @@ should be able to comment this out.
|
|
|
|
|
: PNG_COLOR_TYPE_RGB
|
|
|
|
|
: PNG_COLOR_TYPE_PALETTE, 0, 0, 0);
|
|
|
|
|
|
|
|
|
|
#if PNG_LIBPNG_VER_MAJOR>1 || ( PNG_LIBPNG_VER_MAJOR==1 && PNG_LIBPNG_VER_MINOR>=5 )
|
|
|
|
|
#if PNG_LIBPNG_VER>=10500
|
|
|
|
|
png_color_8 sig_bit;
|
|
|
|
|
sig_bit.red = 8;
|
|
|
|
|
sig_bit.green = 8;
|
|
|
|
@ -614,14 +614,14 @@ should be able to comment this out.
|
|
|
|
|
png_set_PLTE(png_ptr, info_ptr, palette, num_palette);
|
|
|
|
|
int* trans = new int[num_palette];
|
|
|
|
|
int num_trans = 0;
|
|
|
|
|
#if PNG_LIBPNG_VER_MAJOR>1 || ( PNG_LIBPNG_VER_MAJOR==1 && PNG_LIBPNG_VER_MINOR>=5 )
|
|
|
|
|
#if PNG_LIBPNG_VER>=10500
|
|
|
|
|
png_colorp info_ptr_palette = NULL;
|
|
|
|
|
int tmp;
|
|
|
|
|
png_get_PLTE(png_ptr, info_ptr, &info_ptr_palette, &tmp);
|
|
|
|
|
#endif /* LIBPNG 1.5 */
|
|
|
|
|
for (int i=0; i<num_palette; i++) {
|
|
|
|
|
QRgb rgb=image.color(i);
|
|
|
|
|
#if PNG_LIBPNG_VER_MAJOR>1 || ( PNG_LIBPNG_VER_MAJOR==1 && PNG_LIBPNG_VER_MINOR>=5 )
|
|
|
|
|
#if PNG_LIBPNG_VER>=10500
|
|
|
|
|
info_ptr_palette[i].red = qRed(rgb);
|
|
|
|
|
info_ptr_palette[i].green = qGreen(rgb);
|
|
|
|
|
info_ptr_palette[i].blue = qBlue(rgb);
|
|
|
|
@ -637,7 +637,7 @@ should be able to comment this out.
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#if PNG_LIBPNG_VER_MAJOR>1 || ( PNG_LIBPNG_VER_MAJOR==1 && PNG_LIBPNG_VER_MINOR>=5 )
|
|
|
|
|
#if PNG_LIBPNG_VER>=10500
|
|
|
|
|
png_set_PLTE(png_ptr, info_ptr, info_ptr_palette, num_palette);
|
|
|
|
|
#endif /* LIBPNG 1.5 */
|
|
|
|
|
if (num_trans) {
|
|
|
|
@ -650,7 +650,7 @@ should be able to comment this out.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( image.hasAlphaBuffer() ) {
|
|
|
|
|
#if PNG_LIBPNG_VER_MAJOR>1 || ( PNG_LIBPNG_VER_MAJOR==1 && PNG_LIBPNG_VER_MINOR>=5 )
|
|
|
|
|
#if PNG_LIBPNG_VER>=10500
|
|
|
|
|
png_color_8p sig_bit;
|
|
|
|
|
png_get_sBIT(png_ptr, info_ptr, &sig_bit);
|
|
|
|
|
sig_bit->alpha = 8;
|
|
|
|
@ -1143,7 +1143,7 @@ int QPNGFormat::decode(QImage& img, QImageConsumer* cons,
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if PNG_LIBPNG_VER_MAJOR>1 || ( PNG_LIBPNG_VER_MAJOR==1 && PNG_LIBPNG_VER_MINOR>=5 )
|
|
|
|
|
#if PNG_LIBPNG_VER>=10500
|
|
|
|
|
if (setjmp(png_jmpbuf(png_ptr))) {
|
|
|
|
|
#else /* LIBPNG 1.5 */
|
|
|
|
|
if (setjmp((png_ptr)->jmpbuf)) {
|
|
|
|
@ -1174,7 +1174,7 @@ int QPNGFormat::decode(QImage& img, QImageConsumer* cons,
|
|
|
|
|
|
|
|
|
|
if ( !png_ptr ) return 0;
|
|
|
|
|
|
|
|
|
|
#if PNG_LIBPNG_VER_MAJOR>1 || ( PNG_LIBPNG_VER_MAJOR==1 && PNG_LIBPNG_VER_MINOR>=5 )
|
|
|
|
|
#if PNG_LIBPNG_VER>=10500
|
|
|
|
|
if (setjmp(png_jmpbuf(png_ptr))) {
|
|
|
|
|
#else /* LIBPNG 1.5 */
|
|
|
|
|
if (setjmp(png_ptr->jmpbuf)) {
|
|
|
|
@ -1238,7 +1238,7 @@ void QPNGFormat::end(png_structp png, png_infop info)
|
|
|
|
|
consumer->frameDone(QPoint(offx,offy),r);
|
|
|
|
|
consumer->end();
|
|
|
|
|
state = FrameStart;
|
|
|
|
|
#if PNG_LIBPNG_VER_MAJOR>1 || ( PNG_LIBPNG_VER_MAJOR==1 && PNG_LIBPNG_VER_MINOR>=5 )
|
|
|
|
|
#if PNG_LIBPNG_VER>=10500
|
|
|
|
|
unused_data = png_process_data_pause(png, 0);
|
|
|
|
|
#else /* LIBPNG 1.5 */
|
|
|
|
|
unused_data = (int)png->buffer_size; // Since libpng doesn't tell us
|
|
|
|
|