[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#333542: [Issue N89425] QImageIO::setGamma doesn't work on PNG



Christopher Martin wrote, on Friday 2005 October 21 1:42 pm:
> On October 12, 2005 13:44, Christopher Martin wrote:
> > Anyway, could you confirm that 28_qtc_png-gamma-fix.dpatch is the source
> > of your problem? If so, then we'll probably just drop it from the
> > package.
>
> If you need a hand in rebuilding the package without
> 28_qtc_png-gamma-fix.dpatch, or can provide a hint on how to test the
> effects of this patch (since I'd like to verify or have you verify that it
> is causing the gamma correction issues you report before removing it from
> the package), let us know.


I can confirm that 28_qtc_png-gamma-fix.dpatch causes the bug I reported.

I can also confirm that Qt is just broken as there's no way to set it to 
reasonable values.  I should also note to TrollTech that I sent them a patch 
which does this all /correctly/ a several years ago, before 
QImageIO::setGamma even existed.

The following patches actually fix the problem, so that Konqueror has correct 
gamma images according to http://www.w3.org/Graphics/PNG/all_seven.html, and 
that setGamma(0.0) will actually work.

-Charles
--- ../moo/qt-x11-free-3.3.5/src/kernel/qimage.cpp	2005-09-02 13:43:01.000000000 +0100
+++ src/kernel/qimage.cpp	2005-10-21 14:36:27.000000000 +0100
@@ -3783,7 +3783,7 @@
     d = new QImageIOData();
     d->parameters = 0;
     d->quality = -1; // default quality of the current format
-    d->gamma=0.0f;
+    d->gamma=-1.0f;
     iostat = 0;
     iodev  = 0;
 }
@@ -4187,7 +4187,9 @@
     modify the image. Setting to 0.0 will disable gamma correction
     (i.e. any specification in the file will be ignored).
 
-    The default value is 0.0.
+    Setting to a negative number will use reasonable defaults
+
+    The default value is -1.0.
 
     \sa gamma()
 */
--- ../moo/qt-x11-free-3.3.5/src/kernel/qpngio.cpp	2005-09-02 13:43:05.000000000 +0100
+++ src/kernel/qpngio.cpp	2005-10-21 14:44:28.000000000 +0100
@@ -110,6 +110,20 @@
 static
 void setup_qt( QImage& image, png_structp png_ptr, png_infop info_ptr, float screen_gamma=0.0 )
 {
+    if ( screen_gamma  < 0.0 )
+	// PNG docs say this is a good guess for a PC monitor
+        // in a dark room
+	screen_gamma = 2.2;
+    if ( png_get_valid(png_ptr, info_ptr, PNG_INFO_gAMA) ) {
+	// the file has a gAMA attribute
+ 	double file_gamma;
+	if ( png_get_gAMA(png_ptr, info_ptr, &file_gamma))
+	    png_set_gamma( png_ptr, screen_gamma, file_gamma );
+    } else {
+	// no file gamma, use a reasonable default
+	png_set_gamma( png_ptr, screen_gamma, 0.0 ); 
+     }
+    
     if ( screen_gamma != 0.0 && png_get_valid(png_ptr, info_ptr, PNG_INFO_gAMA) ) {
 	double file_gamma;
 	png_get_gAMA(png_ptr, info_ptr, &file_gamma);

Reply to: