Hi,

I've been away from the VFX world for a while but still use OIIO and iv as my image viewer.

One thing i note is that iv seems to get the gamma wrong for images I am browsing off the internet (mostly JPGs) far more often than not, which means I am frequently hammering the ')' key to turn up the gamma.

I modified iv and added a preference to set the default gamma to 2.2 unless specified otherwise in the file.

I am not sure if this has been discussed before, and it may very well be that this is not something you would take a pull request for, as the way OIIO does it in intentional.

However, I attach this patch (If you would like a github pull request instead i can do that I think) in case it is something people would like a toggle for.

Thanks,

-Pete


diff --git src/iv/imageviewer.cpp src/iv/imageviewer.cpp
index 91c898e..e834667 100644
--- src/iv/imageviewer.cpp
+++ src/iv/imageviewer.cpp
@@ -405,6 +405,8 @@ ImageViewer::createActions()
     darkPaletteBox->setChecked (true);
     autoMipmap = new QCheckBox (tr("Generate mipmaps (requires restart)"));
     autoMipmap->setChecked (false);
+    defaultGamma = new QCheckBox (tr("Default gamma 2.2"));
+    autoMipmap->setChecked (false);
 
     maxMemoryICLabel = new QLabel (tr("Image Cache max memory (requires 
restart)"));
     maxMemoryIC = new QSpinBox ();
@@ -595,6 +597,7 @@ ImageViewer::readSettings (bool ui_is_set_up)
     pixelviewFollowsMouseBox->setChecked (settings.value 
("pixelviewFollowsMouse").toBool());
     linearInterpolationBox->setChecked (settings.value 
("linearInterpolation").toBool());
     darkPaletteBox->setChecked (settings.value ("darkPalette").toBool());
+    defaultGamma->setChecked(settings.value ("defaultGamma_2_2").toBool());
     QStringList recent = settings.value ("RecentFiles").toStringList();
     for (auto&& s : recent)
         addRecentFile (s.toStdString());
@@ -624,6 +627,7 @@ ImageViewer::writeSettings()
                        linearInterpolationBox->isChecked());
     settings.setValue ("darkPalette", darkPaletteBox->isChecked());
     settings.setValue ("autoMipmap", autoMipmap->isChecked());
+    settings.setValue ("defaultGamma_2_2", defaultGamma->isChecked());
     settings.setValue ("maxMemoryIC", maxMemoryIC->value());
     settings.setValue ("slideShowDuration", slideShowDuration->value());
     QStringList recent;
@@ -766,6 +770,10 @@ ImageViewer::add_image (const std::string &filename)
     IvImage *newimage = new IvImage(filename);
     ASSERT (newimage);
     newimage->gamma (m_default_gamma);
+    if (defaultGamma->isChecked())
+    {
+        newimage->set_default_gamma(2.2);
+    }
     m_images.push_back (newimage);
     addRecentFile (filename);
     updateRecentFilesMenu ();
diff --git src/iv/imageviewer.h src/iv/imageviewer.h
index eb2ff50..93b4c2b 100644
--- src/iv/imageviewer.h
+++ src/iv/imageviewer.h
@@ -97,6 +97,8 @@ public:
                   void *progress_callback_data=NULL, bool 
secondary_buffer=false);
     bool init_spec_iv (const std::string &filename,
                        int subimage, int miplevel);
+    
+    void set_default_gamma(float g);
 
     float gamma (void) const { return m_gamma; }
     void gamma (float e) { m_gamma = e; }
@@ -376,6 +378,7 @@ private:
     QCheckBox *linearInterpolationBox;
     QCheckBox *darkPaletteBox;
     QCheckBox *autoMipmap;
+    QCheckBox *defaultGamma;
     QLabel   *maxMemoryICLabel;
     QSpinBox *maxMemoryIC;
     QLabel   *slideShowDurationLabel;
diff --git src/iv/ivimage.cpp src/iv/ivimage.cpp
index 390c81a..362d6bc 100644
--- src/iv/ivimage.cpp
+++ src/iv/ivimage.cpp
@@ -108,7 +108,16 @@ IvImage::read_iv (int subimage, int miplevel, bool force, 
TypeDesc format,
     return m_image_valid;
 }
 
+void IvImage::set_default_gamma(float g)
+{
+    string_view colorspace = spec().get_string_attribute ("oiio:ColorSpace");
+    if ( ! Strutil::istarts_with (colorspace, "GammaCorrected")) {
+        if (g > 1.0 && g <= 3.0 /*sanity check*/) {
+            gamma(g); 
+        }
 
+    }
+}
 
 std::string
 IvImage::shortinfo () const
diff --git src/iv/ivpref.cpp src/iv/ivpref.cpp
index ba73d02..d0696d1 100644
--- src/iv/ivpref.cpp
+++ src/iv/ivpref.cpp
@@ -55,6 +55,7 @@ IvPreferenceWindow::IvPreferenceWindow (ImageViewer &viewer)
     layout->addWidget (viewer.linearInterpolationBox);
     layout->addWidget (viewer.darkPaletteBox);
     layout->addWidget (viewer.autoMipmap);
+    layout->addWidget (viewer.defaultGamma);
     
     QLayout *inner_layout = new QHBoxLayout;
     inner_layout->addWidget (viewer.maxMemoryICLabel);
_______________________________________________
Oiio-dev mailing list
[email protected]
http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org

Reply via email to