Beep6581 / RawTherapee

A powerful cross-platform raw photo processing program
https://rawtherapee.com
GNU General Public License v3.0
2.91k stars 325 forks source link

Auto Levels completely wrong for monochrome raw files, sigma raw files and canon mraw/sraw files #3863

Closed heckflosse closed 7 years ago

heckflosse commented 7 years ago

While testing #3858, I detected that for some Sensors Auto-Level is completely wrong. Especially for foveon Sensors and Leica Monochrome sensors. Should be also wrong for Canon mraw/sraw, but for these I don't have test files atm.

Suggested Fix:

diff --git a/rtengine/rawimagesource.cc b/rtengine/rawimagesource.cc
index e178906..11bdeb6 100644
--- a/rtengine/rawimagesource.cc
+++ b/rtengine/rawimagesource.cc
@@ -4613,13 +4613,13 @@ void RawImageSource::getAutoExpHistogram (LUTu & histogram, int& histcompr)
                 }
             } else if (ri->get_colors() == 1) {
                 for (int j = start; j < end; j++) {
-                    tmphistogram[(int)(refwb_red *  rawData[i][j])]++;
+                    tmphistogram[(int)(refwb[0] *  rawData[i][j])]++;
                 }
             } else {
                 for (int j = start; j < end; j++) {
-                    tmphistogram[CLIP((int)(refwb_red *  rawData[i][3 * j + 0]))]++;
-                    tmphistogram[CLIP((int)(refwb_green * rawData[i][3 * j + 1]))] += 2;
-                    tmphistogram[CLIP((int)(refwb_blue * rawData[i][3 * j + 2]))]++;
+                    tmphistogram[CLIP((int)(refwb[0] * rawData[i][3 * j + 0]))]++;
+                    tmphistogram[CLIP((int)(refwb[1] * rawData[i][3 * j + 1]))]++;
+                    tmphistogram[CLIP((int)(refwb[2] * rawData[i][3 * j + 2]))]++;
                 }
             }
         }
heckflosse commented 7 years ago

I found some mraw files. Just searched for mraw here. As expected before patch auto-levels for mraw files was wrong too. After patch it's much better.

heckflosse commented 7 years ago

Any objections to push this for 5.1?

agriggio commented 7 years ago

for me :+1: