2012-02-06 15:38:55 +00:00
|
|
|
$NetBSD: patch-as,v 1.5 2011/03/25 15:28:26 wiz Exp $
|
|
|
|
|
|
|
|
--- src/kernel/qpngio.cpp.orig 2007-02-02 10:01:15.000000000 -0400
|
|
|
|
+++ src/kernel/qpngio.cpp
|
|
|
|
@@ -43,6 +43,7 @@
|
|
|
|
#include "qiodevice.h"
|
2012-02-08 15:33:01 +00:00
|
|
|
|
2012-02-06 15:38:55 +00:00
|
|
|
#include <png.h>
|
|
|
|
+#include <zlib.h>
|
2012-02-08 15:33:01 +00:00
|
|
|
|
|
|
|
|
2012-02-06 15:38:55 +00:00
|
|
|
#ifdef Q_OS_TEMP
|
|
|
|
@@ -123,9 +124,24 @@ void setup_qt( QImage& image, png_struct
|
|
|
|
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
|
2012-02-08 15:33:01 +00:00
|
|
|
0, 0, 0);
|
|
|
|
|
2012-02-06 15:38:55 +00:00
|
|
|
+ png_colorp info_ptr_palette = NULL;
|
|
|
|
+ int info_ptr_num_palette = 0;
|
|
|
|
+ if (png_get_valid(png_ptr, info_ptr, PNG_INFO_PLTE)) {
|
|
|
|
+ png_get_PLTE(png_ptr, info_ptr, &info_ptr_palette, &info_ptr_num_palette);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ png_bytep info_ptr_trans_alpha = NULL;
|
|
|
|
+ int info_ptr_num_trans = 0;
|
|
|
|
+ png_color_16p info_ptr_trans_color = NULL;
|
|
|
|
+
|
|
|
|
+ if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
|
|
|
|
+ png_get_tRNS(png_ptr, info_ptr, &info_ptr_trans_alpha, &info_ptr_num_trans, &info_ptr_trans_color);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
if ( color_type == PNG_COLOR_TYPE_GRAY ) {
|
2012-02-08 15:33:01 +00:00
|
|
|
// Black & White or 8-bit grayscale
|
2012-02-06 15:38:55 +00:00
|
|
|
- if ( bit_depth == 1 && info_ptr->channels == 1 ) {
|
|
|
|
+ if ( bit_depth == 1 && png_get_channels(png_ptr, info_ptr) == 1 ) {
|
2012-02-08 15:33:01 +00:00
|
|
|
png_set_invert_mono( png_ptr );
|
|
|
|
png_read_update_info( png_ptr, info_ptr );
|
|
|
|
if (!image.create( width, height, 1, 2, QImage::BigEndian ))
|
2012-02-06 15:38:55 +00:00
|
|
|
@@ -159,7 +175,7 @@ void setup_qt( QImage& image, png_struct
|
2012-02-08 15:33:01 +00:00
|
|
|
image.setColor( i, qRgba(c,c,c,0xff) );
|
|
|
|
}
|
|
|
|
if ( png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS) ) {
|
2012-02-06 15:38:55 +00:00
|
|
|
- const int g = info_ptr->trans_values.gray;
|
|
|
|
+ const int g = info_ptr_trans_color->gray;
|
2012-02-08 15:33:01 +00:00
|
|
|
if (g < ncols) {
|
|
|
|
image.setAlphaBuffer(TRUE);
|
|
|
|
image.setColor(g, image.color(g) & RGB_MASK);
|
2012-02-06 15:38:55 +00:00
|
|
|
@@ -168,7 +184,7 @@ void setup_qt( QImage& image, png_struct
|
2012-02-08 15:33:01 +00:00
|
|
|
}
|
2012-02-06 15:38:55 +00:00
|
|
|
} else if ( color_type == PNG_COLOR_TYPE_PALETTE
|
|
|
|
&& png_get_valid(png_ptr, info_ptr, PNG_INFO_PLTE)
|
|
|
|
- && info_ptr->num_palette <= 256 )
|
|
|
|
+ && info_ptr_num_palette <= 256 )
|
|
|
|
{
|
2012-02-08 15:33:01 +00:00
|
|
|
// 1-bit and 8-bit color
|
|
|
|
if ( bit_depth != 1 )
|
2012-02-06 15:38:55 +00:00
|
|
|
@@ -176,28 +192,28 @@ void setup_qt( QImage& image, png_struct
|
2012-02-08 15:33:01 +00:00
|
|
|
png_read_update_info( png_ptr, info_ptr );
|
|
|
|
png_get_IHDR(png_ptr, info_ptr,
|
|
|
|
&width, &height, &bit_depth, &color_type, 0, 0, 0);
|
2012-02-06 15:38:55 +00:00
|
|
|
- if (!image.create(width, height, bit_depth, info_ptr->num_palette,
|
|
|
|
+ if (!image.create(width, height, bit_depth, info_ptr_num_palette,
|
2012-02-08 15:33:01 +00:00
|
|
|
QImage::BigEndian))
|
|
|
|
return;
|
|
|
|
int i = 0;
|
|
|
|
if ( png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS) ) {
|
|
|
|
image.setAlphaBuffer( TRUE );
|
2012-02-06 15:38:55 +00:00
|
|
|
- while ( i < info_ptr->num_trans ) {
|
|
|
|
+ while ( i < info_ptr_num_trans ) {
|
2012-02-08 15:33:01 +00:00
|
|
|
image.setColor(i, qRgba(
|
2012-02-06 15:38:55 +00:00
|
|
|
- info_ptr->palette[i].red,
|
|
|
|
- info_ptr->palette[i].green,
|
|
|
|
- info_ptr->palette[i].blue,
|
|
|
|
- info_ptr->trans[i]
|
|
|
|
+ info_ptr_palette[i].red,
|
|
|
|
+ info_ptr_palette[i].green,
|
|
|
|
+ info_ptr_palette[i].blue,
|
|
|
|
+ info_ptr_trans_alpha[i]
|
2012-02-08 15:33:01 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
2012-02-06 15:38:55 +00:00
|
|
|
- while ( i < info_ptr->num_palette ) {
|
|
|
|
+ while ( i < info_ptr_num_palette ) {
|
2012-02-08 15:33:01 +00:00
|
|
|
image.setColor(i, qRgba(
|
2012-02-06 15:38:55 +00:00
|
|
|
- info_ptr->palette[i].red,
|
|
|
|
- info_ptr->palette[i].green,
|
|
|
|
- info_ptr->palette[i].blue,
|
|
|
|
+ info_ptr_palette[i].red,
|
|
|
|
+ info_ptr_palette[i].green,
|
|
|
|
+ info_ptr_palette[i].blue,
|
2012-02-08 15:33:01 +00:00
|
|
|
0xff
|
|
|
|
)
|
|
|
|
);
|
2012-02-06 15:38:55 +00:00
|
|
|
@@ -284,7 +300,7 @@ void read_png_image(QImageIO* iio)
|
2012-02-08 15:33:01 +00:00
|
|
|
return;
|
2012-02-06 15:38:55 +00:00
|
|
|
}
|
2012-02-08 15:33:01 +00:00
|
|
|
|
2012-02-06 15:38:55 +00:00
|
|
|
- if (setjmp(png_ptr->jmpbuf)) {
|
|
|
|
+ if (setjmp(png_jmpbuf(png_ptr))) {
|
2012-02-08 15:33:01 +00:00
|
|
|
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
|
|
|
|
iio->setStatus(-4);
|
|
|
|
return;
|
2012-02-06 15:38:55 +00:00
|
|
|
@@ -469,7 +485,7 @@ bool QPNGImageWriter::writeImage(const Q
|
2012-02-08 15:33:01 +00:00
|
|
|
return FALSE;
|
2012-02-06 15:38:55 +00:00
|
|
|
}
|
2012-02-08 15:33:01 +00:00
|
|
|
|
2012-02-06 15:38:55 +00:00
|
|
|
- if (setjmp(png_ptr->jmpbuf)) {
|
|
|
|
+ if (setjmp(png_jmpbuf(png_ptr))) {
|
2012-02-08 15:33:01 +00:00
|
|
|
png_destroy_write_struct(&png_ptr, &info_ptr);
|
|
|
|
return FALSE;
|
2012-02-06 15:38:55 +00:00
|
|
|
}
|
|
|
|
@@ -491,10 +507,16 @@ bool QPNGImageWriter::writeImage(const Q
|
2012-02-08 15:33:01 +00:00
|
|
|
|
2012-02-06 15:38:55 +00:00
|
|
|
png_set_write_fn(png_ptr, (void*)this, qpiw_write_fn, qpiw_flush_fn);
|
2012-02-08 15:33:01 +00:00
|
|
|
|
2012-02-06 15:38:55 +00:00
|
|
|
+#warning XXXtnn not too sure about this
|
2012-02-08 15:33:01 +00:00
|
|
|
+/*
|
2012-02-06 15:38:55 +00:00
|
|
|
+according to png.h, channels is only used on read, not writes, so we
|
|
|
|
+should be able to comment this out.
|
|
|
|
+
|
|
|
|
info_ptr->channels =
|
2012-02-08 15:33:01 +00:00
|
|
|
(image.depth() == 32)
|
|
|
|
? (image.hasAlphaBuffer() ? 4 : 3)
|
|
|
|
: 1;
|
2012-02-06 15:38:55 +00:00
|
|
|
+*/
|
2012-02-08 15:33:01 +00:00
|
|
|
|
2012-02-06 15:38:55 +00:00
|
|
|
png_set_IHDR(png_ptr, info_ptr, image.width(), image.height(),
|
2012-02-08 15:33:01 +00:00
|
|
|
image.depth() == 1 ? 1 : 8 /* per channel */,
|
2012-02-06 15:38:55 +00:00
|
|
|
@@ -504,11 +526,12 @@ bool QPNGImageWriter::writeImage(const Q
|
2012-02-08 15:33:01 +00:00
|
|
|
: PNG_COLOR_TYPE_RGB
|
|
|
|
: PNG_COLOR_TYPE_PALETTE, 0, 0, 0);
|
|
|
|
|
2012-02-06 15:38:55 +00:00
|
|
|
+ png_color_8 sig_bit;
|
|
|
|
+ sig_bit.red = 8;
|
|
|
|
+ sig_bit.green = 8;
|
|
|
|
+ sig_bit.blue = 8;
|
|
|
|
+ png_set_sBIT(png_ptr, info_ptr, &sig_bit);
|
2012-02-08 15:33:01 +00:00
|
|
|
|
2012-02-06 15:38:55 +00:00
|
|
|
- //png_set_sBIT(png_ptr, info_ptr, 8);
|
|
|
|
- info_ptr->sig_bit.red = 8;
|
|
|
|
- info_ptr->sig_bit.green = 8;
|
|
|
|
- info_ptr->sig_bit.blue = 8;
|
2012-02-08 15:33:01 +00:00
|
|
|
|
2012-02-06 15:38:55 +00:00
|
|
|
if (image.depth() == 1 && image.bitOrder() == QImage::LittleEndian)
|
|
|
|
png_set_packswap(png_ptr);
|
|
|
|
@@ -522,11 +545,14 @@ bool QPNGImageWriter::writeImage(const Q
|
2012-02-08 15:33:01 +00:00
|
|
|
png_set_PLTE(png_ptr, info_ptr, palette, num_palette);
|
|
|
|
int* trans = new int[num_palette];
|
|
|
|
int num_trans = 0;
|
2012-02-06 15:38:55 +00:00
|
|
|
+ png_colorp info_ptr_palette = NULL;
|
|
|
|
+ int tmp;
|
|
|
|
+ png_get_PLTE(png_ptr, info_ptr, &info_ptr_palette, &tmp);
|
2012-02-08 15:33:01 +00:00
|
|
|
for (int i=0; i<num_palette; i++) {
|
|
|
|
QRgb rgb=image.color(i);
|
2012-02-06 15:38:55 +00:00
|
|
|
- info_ptr->palette[i].red = qRed(rgb);
|
|
|
|
- info_ptr->palette[i].green = qGreen(rgb);
|
|
|
|
- info_ptr->palette[i].blue = qBlue(rgb);
|
|
|
|
+ info_ptr_palette[i].red = qRed(rgb);
|
|
|
|
+ info_ptr_palette[i].green = qGreen(rgb);
|
|
|
|
+ info_ptr_palette[i].blue = qBlue(rgb);
|
2012-02-08 15:33:01 +00:00
|
|
|
if (image.hasAlphaBuffer()) {
|
|
|
|
trans[i] = rgb >> 24;
|
|
|
|
if (trans[i] < 255) {
|
2012-02-06 15:38:55 +00:00
|
|
|
@@ -534,6 +560,7 @@ bool QPNGImageWriter::writeImage(const Q
|
2012-02-08 15:33:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-02-06 15:38:55 +00:00
|
|
|
+ png_set_PLTE(png_ptr, info_ptr, info_ptr_palette, num_palette);
|
2012-02-08 15:33:01 +00:00
|
|
|
if (num_trans) {
|
|
|
|
copy_trans = new png_byte[num_trans];
|
|
|
|
for (int i=0; i<num_trans; i++)
|
2012-02-06 15:38:55 +00:00
|
|
|
@@ -544,7 +571,10 @@ bool QPNGImageWriter::writeImage(const Q
|
|
|
|
}
|
2012-02-08 15:33:01 +00:00
|
|
|
|
2012-02-06 15:38:55 +00:00
|
|
|
if ( image.hasAlphaBuffer() ) {
|
|
|
|
- info_ptr->sig_bit.alpha = 8;
|
|
|
|
+ png_color_8p sig_bit;
|
|
|
|
+ png_get_sBIT(png_ptr, info_ptr, &sig_bit);
|
|
|
|
+ sig_bit->alpha = 8;
|
|
|
|
+ png_set_sBIT(png_ptr, info_ptr, sig_bit);
|
|
|
|
}
|
2012-02-08 15:33:01 +00:00
|
|
|
|
2012-02-06 15:38:55 +00:00
|
|
|
// Swap ARGB to RGBA (normal PNG format) before saving on
|
|
|
|
@@ -1030,7 +1060,7 @@ int QPNGFormat::decode(QImage& img, QIma
|
2012-02-08 15:33:01 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-02-06 15:38:55 +00:00
|
|
|
- if (setjmp((png_ptr)->jmpbuf)) {
|
|
|
|
+ if (setjmp(png_jmpbuf(png_ptr))) {
|
2012-02-08 15:33:01 +00:00
|
|
|
png_destroy_read_struct(&png_ptr, &info_ptr, 0);
|
|
|
|
image = 0;
|
|
|
|
return -1;
|
2012-02-06 15:38:55 +00:00
|
|
|
@@ -1057,7 +1087,7 @@ int QPNGFormat::decode(QImage& img, QIma
|
2012-02-08 15:33:01 +00:00
|
|
|
|
2012-02-06 15:38:55 +00:00
|
|
|
if ( !png_ptr ) return 0;
|
2012-02-08 15:33:01 +00:00
|
|
|
|
2012-02-06 15:38:55 +00:00
|
|
|
- if (setjmp(png_ptr->jmpbuf)) {
|
|
|
|
+ if (setjmp(png_jmpbuf(png_ptr))) {
|
2012-02-08 15:33:01 +00:00
|
|
|
png_destroy_read_struct(&png_ptr, &info_ptr, 0);
|
|
|
|
image = 0;
|
|
|
|
state = MovieStart;
|
2012-02-06 15:38:55 +00:00
|
|
|
@@ -1117,7 +1147,7 @@ void QPNGFormat::end(png_structp png, pn
|
|
|
|
consumer->frameDone(QPoint(offx,offy),r);
|
|
|
|
consumer->end();
|
|
|
|
state = FrameStart;
|
|
|
|
- unused_data = (int)png->buffer_size; // Since libpng doesn't tell us
|
|
|
|
+ unused_data = png_process_data_pause(png, 0);
|
|
|
|
}
|
2012-02-08 15:33:01 +00:00
|
|
|
|
2012-02-06 15:38:55 +00:00
|
|
|
#ifdef PNG_USER_CHUNKS_SUPPORTED
|