summaryrefslogtreecommitdiffstats
path: root/digikam/build/digikam_libkdcraw_ftbfs_fix.patch
blob: 86e5a7ba8e1cfb3b811860cb4a4d00b2ec1f9182 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
Digikam 0.9.3 will not compile against libkdcraw-0.1.4 unless the patch below
is applied.
Found at http://patches.ubuntu.com/by-release/extracted/ubuntu/d/digikam/2:0.9.3-2/20_fix_ftbfs_with_libkdcraw3.diff

Eric Hameleers, 08-may-2008

--- a/digikam/imageplugins/whitebalance/imageeffect_whitebalance.cpp
+++ b/digikam/imageplugins/whitebalance/imageeffect_whitebalance.cpp
@@ -7,7 +7,8 @@
  * Description : a digiKam image editor plugin to correct 
  *               image white balance 
  * 
- * Copyright (C) 2005-2007 by Gilles Caulier <caulier dot gilles at gmail dot com>
+ * Copyright (C) 2005-2008 by Gilles Caulier <caulier dot gilles at gmail dot com>
+ * Copyright (C) 2008 by Guillaume Castagnino <casta at xwing dot info>
  * 
  * This program is free software; you can redistribute it
  * and/or modify it under the terms of the GNU General
@@ -191,7 +192,7 @@
     m_adjTemperatureLabel = new QLabel(i18n("Adjustment:"), gboxSettings);
     m_temperatureInput    = new KDoubleNumInput(gboxSettings);
     m_temperatureInput->setPrecision(1);
-    m_temperatureInput->setRange(2200.0, 7000.0, 10.0, true);
+    m_temperatureInput->setRange(2000.0, 12000.0, 10.0, true);
     QWhatsThis::add( m_temperatureInput, i18n("<p>Set here the white balance color temperature in Kelvin."));
     
     m_temperaturePresetLabel = new QLabel(i18n("Preset:"), gboxSettings);
@@ -268,7 +269,7 @@
     m_greenLabel = new QLabel(i18n("Green:"), gboxSettings);
     m_greenInput = new KDoubleNumInput(gboxSettings);
     m_greenInput->setPrecision(2);
-    m_greenInput->setRange(1.0, 2.5, 0.01, true);
+    m_greenInput->setRange(0.2, 2.5, 0.01, true);
     QWhatsThis::add(m_greenInput, i18n("<p>Set here the green component to set magenta color "
                                        "cast removal level."));
 
@@ -633,7 +634,7 @@
 
     m_destinationPreviewData = new uchar[w*h*(sb ? 8 : 4)];
 
-    double temperature  = m_temperatureInput->value()/1000.0;
+    double temperature  = m_temperatureInput->value();
     double dark         = m_darkInput->value();
     double black        = m_blackInput->value();
     double mainExposure = m_mainExposureInput->value();
@@ -666,7 +667,7 @@
     int h                      = iface->originalHeight();
     bool sb                    = iface->originalSixteenBit();
 
-    double temperature  = m_temperatureInput->value()/1000.0;
+    double temperature  = m_temperatureInput->value();
     double dark         = m_darkInput->value();
     double black        = m_blackInput->value();
     double mainExposure = m_mainExposureInput->value();
@@ -698,16 +699,16 @@
     m_greenInput->blockSignals(true);
     m_temperaturePresetCB->blockSignals(true);
     
-    // Neutral color temperature settings.
+    // Neutral color temperature settings is D65
     m_darkInput->setValue(0.5);
     m_blackInput->setValue(0.0);
     m_mainExposureInput->setValue(0.0);
     m_fineExposureInput->setValue(0.0);
     m_gammaInput->setValue(1.0);  
     m_saturationInput->setValue(1.0);  
-    m_greenInput->setValue(1.2);  
-    m_temperaturePresetCB->setCurrentItem(Neutral);
-    slotTemperaturePresetChanged(Neutral);
+    m_greenInput->setValue(1.0);
+    m_temperaturePresetCB->setCurrentItem(DaylightD65);
+    slotTemperaturePresetChanged(DaylightD65);
     
     m_previewWidget->resetSpotPosition();    
     m_channelCB->setCurrentItem(LuminosityChannel);
@@ -739,8 +740,8 @@
     m_fineExposureInput->setValue(config->readDoubleNumEntry("FineExposure", 0.0));
     m_gammaInput->setValue(config->readDoubleNumEntry("Gamma", 1.0));  
     m_saturationInput->setValue(config->readDoubleNumEntry("Saturation", 1.0));  
-    m_greenInput->setValue(config->readDoubleNumEntry("Green", 1.2));  
-    m_temperatureInput->setValue(config->readDoubleNumEntry("Temperature", 4750.0));
+    m_greenInput->setValue(config->readDoubleNumEntry("Green", 1.0));  
+    m_temperatureInput->setValue(config->readDoubleNumEntry("Temperature", 6500.0));
     slotTemperatureChanged(m_temperatureInput->value());
     slotChannelChanged(m_channelCB->currentItem());
     slotScaleChanged(m_scaleBG->selectedId());
--- a/digikam/imageplugins/whitebalance/imageeffect_whitebalance.h
+++ b/digikam/imageplugins/whitebalance/imageeffect_whitebalance.h
@@ -7,7 +7,8 @@
  * Description : a digiKam image editor plugin to correct 
  *               image white balance 
  * 
- * Copyright (C) 2005-2007 by Gilles Caulier <caulier dot gilles at gmail dot com>
+ * Copyright (C) 2005-2008 by Gilles Caulier <caulier dot gilles at gmail dot com>
+ * Copyright (C) 2008 by Guillaume Castagnino <casta at xwing dot info>
  * 
  * This program is free software; you can redistribute it
  * and/or modify it under the terms of the GNU General
@@ -22,7 +23,6 @@
  * 
  * ============================================================ */
 
-
 #ifndef IMAGEEFFECT_WHITEBALANCE_H
 #define IMAGEEFFECT_WHITEBALANCE_H
 
--- a/digikam/libs/whitebalance/whitebalance.cpp
+++ b/digikam/libs/whitebalance/whitebalance.cpp
@@ -6,7 +6,8 @@
  * Date        : 2007-16-01
  * Description : white balance color correction.
  * 
- * Copyright (C) 2007 by Gilles Caulier <caulier dot gilles at gmail dot com>
+ * Copyright (C) 2007-2008 by Gilles Caulier <caulier dot gilles at gmail dot com>
+ * Copyright (C) 2008 by Guillaume Castagnino <casta at xwing dot info>
  *
  * Some parts are inspired from RawPhoto implementation copyrighted 
  * 2004-2005 by Pawel T. Jochym <jochym at ifj edu pl>
@@ -39,7 +40,6 @@
 
 #include "ddebug.h"
 #include "imagehistogram.h"
-#include "blackbody.h"
 #include "whitebalance.h"
 
 namespace Digikam
@@ -69,8 +69,8 @@
         exposition  = 0.0;
         gamma       = 1.0;  
         saturation  = 1.0;  
-        green       = 1.2;  
-        temperature = 4.750;
+        green       = 1.0;
+        temperature = 6500.0;
     }
 
     bool   clipSat;
@@ -127,7 +127,7 @@
     if (d->clipSat) d->mg = 1.0; 
     setLUTv();
     setRGBmult();
-       
+
     // Apply White balance adjustments.
     adjustWhiteBalance(data, width, height, sixteenBit);
 }
@@ -136,41 +136,33 @@
 {       
     // Calculate Temperature and Green component from color picked.
             
-    register int l, r, m;
-    double sR, sG, sB, mRB, t;
+    double tmin, tmax, mBR;
+    float mr, mg, mb;
 
-    t   = QMAX( QMAX(tc.red(), tc.green()), tc.blue());
-    sR  = tc.red()   / t;
-    sG  = tc.green() / t;
-    sB  = tc.blue()  / t;
-    mRB = sR / sB;
-
-    DDebug() << "Sums:  R:" << sR << " G:" << sG  << " B:" << sB << endl;
-
-    l = 0;
-    r = sizeof(blackBodyWhiteBalance)/(sizeof(float)*3);
-    m = (r + l) / 2;
+    DDebug() << "Sums:  R:" << tc.red() << " G:" << tc.green() << " B:" << tc.blue() << endl;
 
-    for (l = 0, r = sizeof(blackBodyWhiteBalance)/(sizeof(float)*3), m = (l+r)/2 ; r-l > 1 ; m = (l+r)/2) 
+    /* This is a dichotomic search based on Blue and Red layers ratio
+       to find the matching temperature
+       Adapted from ufraw (0.12.1) RGB_to_Temperature
+    */
+    tmin = 2000.0;
+    tmax = 12000.0;
+    mBR = (double)tc.blue() / (double)tc.red();
+    green = 1.0;
+    for (temperature = (tmin+tmax)/2; tmax-tmin > 10; temperature = (tmin+tmax)/2)
     {
-        if (blackBodyWhiteBalance[m][0]/blackBodyWhiteBalance[m][2] > mRB) 
-            l = m;
+        DDebug() << "Intermediate Temperature (K):" << temperature << endl;
+        setRGBmult(temperature, green, mr, mg, mb);
+        if (mr/mb > mBR)
+            tmax = temperature;
         else
-            r = m;
-
-        DDebug() << "L,M,R:  " << l << " " << m << " " << r 
-                 << " blackBodyWhiteBalance[m]=:" << blackBodyWhiteBalance[m][0]/blackBodyWhiteBalance[m][2]
-                 << endl;
+            tmin = temperature;
     }
-    
-    DDebug() << "Temperature (K):" << m*10.0+2000.0 << endl;
-
-    t = (blackBodyWhiteBalance[m][1]/blackBodyWhiteBalance[m][0]) / (sG/sR);
+    // Calculate the green level to neutralize picture
+    green = (mr / mg) / ((double)tc.green() / (double)tc.red());
 
-    DDebug() << "Green component:" << t << endl;
-
-    temperature = m*10.0+2000.0;
-    green       = t;
+    DDebug() << "Temperature (K):" << temperature << endl;
+    DDebug() << "Green component:" << green << endl;
 }
 
 void WhiteBalance::autoExposureAdjustement(uchar* data, int width, int height, bool sb,
@@ -207,25 +199,73 @@
     delete histogram;
 }
 
-void WhiteBalance::setRGBmult()
+void WhiteBalance::setRGBmult(double &temperature, double &green, float &mr, float &mg, float &mb)
 {
-    int   t;
     float mi;
+    double xD, yD, X, Y, Z;
 
-    if ( d->temperature > 7.0 ) d->temperature = 7.0;
+    if ( temperature > 12000 ) temperature = 12000.0;
     
-    t     = (int)(d->temperature * 100.0 - 200.0);
-    d->mr  = 1.0 / blackBodyWhiteBalance[t][0];
-    d->mg  = 1.0 / blackBodyWhiteBalance[t][1];
-    d->mb  = 1.0 / blackBodyWhiteBalance[t][2];
-    d->mg *= d->green;
+    /* Here starts the code picked from ufraw (0.12.1)
+       to convert Temperature + green multiplier to RGB multipliers
+    */
+    /* Convert between Temperature and RGB.
+     * Base on information from http://www.brucelindbloom.com/
+     * The fit for D-illuminant between 4000K and 12000K are from CIE
+     * The generalization to 2000K < T < 4000K and the blackbody fits
+     * are my own and should be taken with a grain of salt.
+     */
+    const double XYZ_to_RGB[3][3] = {
+        { 3.24071,  -0.969258,  0.0556352 },
+        {-1.53726,  1.87599,    -0.203996 },
+        {-0.498571, 0.0415557,  1.05707 } };
+    // Fit for CIE Daylight illuminant
+    if (temperature <= 4000)
+    {
+        xD = 0.27475e9/(temperature*temperature*temperature)
+             - 0.98598e6/(temperature*temperature) 
+             + 1.17444e3/temperature + 0.145986;
+    }
+    else if (temperature <= 7000)
+    {
+        xD = -4.6070e9/(temperature*temperature*temperature)
+             + 2.9678e6/(temperature*temperature)
+             + 0.09911e3/temperature + 0.244063;
+    }
+    else
+    {
+        xD = -2.0064e9/(temperature*temperature*temperature)
+             + 1.9018e6/(temperature*temperature)
+             + 0.24748e3/temperature + 0.237040;
+    }
+    yD = -3*xD*xD + 2.87*xD - 0.275;
+
+    X = xD/yD;
+    Y = 1;
+    Z = (1-xD-yD)/yD;
+    mr = X*XYZ_to_RGB[0][0] + Y*XYZ_to_RGB[1][0] + Z*XYZ_to_RGB[2][0];
+    mg = X*XYZ_to_RGB[0][1] + Y*XYZ_to_RGB[1][1] + Z*XYZ_to_RGB[2][1];
+    mb = X*XYZ_to_RGB[0][2] + Y*XYZ_to_RGB[1][2] + Z*XYZ_to_RGB[2][2];
+    /* End of the code picked to ufraw
+    */
+
+    // Apply green multiplier
+    mg = mg / green;
+
+    mr  = 1.0 / mr;
+    mg  = 1.0 / mg;
+    mb  = 1.0 / mb;
     
     // Normalize to at least 1.0, so we are not dimming colors only bumping.
-    mi    = QMIN(d->mr, d->mg);
-    mi    = QMIN(mi, d->mb);
-    d->mr /= mi;
-    d->mg /= mi;
-    d->mb /= mi;
+    mi  = QMIN(mr, QMIN(mg, mb));
+    mr /= mi;
+    mg /= mi;
+    mb /= mi;
+}
+
+void WhiteBalance::setRGBmult()
+{
+    setRGBmult(d->temperature, d->green, d->mr, d->mg, d->mb);
 }
 
 void WhiteBalance::setLUTv()
--- a/digikam/libs/whitebalance/whitebalance.h
+++ b/digikam/libs/whitebalance/whitebalance.h
@@ -6,7 +6,8 @@
  * Date        : 2007-16-01
  * Description : white balance color correction.
  * 
- * Copyright (C) 2007 by Gilles Caulier <caulier dot gilles at gmail dot com>
+ * Copyright (C) 2007-2008 by Gilles Caulier <caulier dot gilles at gmail dot com>
+ * Copyright (C) 2008 by Guillaume Castagnino <casta at xwing dot info>
  *
  * This program is free software; you can redistribute it
  * and/or modify it under the terms of the GNU General
@@ -45,7 +46,7 @@
 
     void whiteBalance(uchar *data, int width, int height, bool sixteenBit, 
                       double black=0.0, double exposition=0.0,
-                      double temperature=4.750, double green=1.2, double dark=0.5, 
+                      double temperature=6500.0, double green=1.0, double dark=0.5, 
                       double gamma=1.0, double saturation=1.0);
 
     static void autoExposureAdjustement(uchar* data, int width, int height, bool sb,
@@ -56,6 +57,7 @@
 private:
 
     void setRGBmult();
+    static void setRGBmult(double &temperature, double &green, float &mr, float &mg, float &mb);
     void setLUTv();
     void adjustWhiteBalance(uchar *data, int width, int height, bool sixteenBit);
     inline unsigned short pixelColor(int colorMult, int index, int value);
--- a/digikam/utilities/setup/setupdcraw.cpp
+++ b/digikam/utilities/setup/setupdcraw.cpp
@@ -6,7 +6,7 @@
  * Date        : 2007-02-06
  * Description : setup RAW decoding settings.
  * 
- * Copyright (C) 2007 by Gilles Caulier <caulier dot gilles at gmail dot com>
+ * Copyright (C) 2007-2008 by Gilles Caulier <caulier dot gilles at gmail dot com>
  *
  * This program is free software; you can redistribute it
  * and/or modify it under the terms of the GNU General
@@ -89,8 +89,9 @@
     KConfig* config = kapp->config();
     config->setGroup("ImageViewer Settings");
     config->writeEntry("SixteenBitsImage", d->dcrawSettings->sixteenBits());
-    config->writeEntry("CameraColorBalance", d->dcrawSettings->useCameraWB());
-    config->writeEntry("AutomaticColorBalance", d->dcrawSettings->useAutoColorBalance());
+    config->writeEntry("WhiteBalance", d->dcrawSettings->whiteBalance());
+    config->writeEntry("CustomWhiteBalance", d->dcrawSettings->customWhiteBalance());
+    config->writeEntry("CustomWhiteBalanceGreen", d->dcrawSettings->customWhiteBalanceGreen());
     config->writeEntry("RGBInterpolate4Colors", d->dcrawSettings->useFourColor());
     config->writeEntry("DontStretchPixels", d->dcrawSettings->useDontStretchPixels());
     config->writeEntry("EnableNoiseReduction", d->dcrawSettings->useNoiseReduction());
@@ -116,8 +117,11 @@
     d->dcrawSettings->setcaBlueMultiplier(config->readDoubleNumEntry("caBlueMultiplier", 1.0));
     d->dcrawSettings->setDontStretchPixels(config->readBoolEntry("DontStretchPixels", false));
     d->dcrawSettings->setUnclipColor(config->readNumEntry("UnclipColors", 0));
-    d->dcrawSettings->setCameraWB(config->readBoolEntry("CameraColorBalance", true));
-    d->dcrawSettings->setAutoColorBalance(config->readBoolEntry("AutomaticColorBalance", true));
+    d->dcrawSettings->setWhiteBalance((KDcrawIface::RawDecodingSettings::WhiteBalance)
+                                      config->readNumEntry("WhiteBalance",
+                                      KDcrawIface::RawDecodingSettings::CAMERA));
+    d->dcrawSettings->setCustomWhiteBalance(config->readNumEntry("CustomWhiteBalance", 6500));
+    d->dcrawSettings->setCustomWhiteBalanceGreen(config->readDoubleNumEntry("CustomWhiteBalanceGreen", 1.0));
     d->dcrawSettings->setFourColor(config->readBoolEntry("RGBInterpolate4Colors", false));
     d->dcrawSettings->setQuality((KDcrawIface::RawDecodingSettings::DecodingQuality)
                                   config->readNumEntry("RAWQuality",
--- a/digikam/utilities/setup/setupdcraw.h
+++ b/digikam/utilities/setup/setupdcraw.h
@@ -6,7 +6,7 @@
  * Date        : 2007-02-06
  * Description : setup RAW decoding settings.
  * 
- * Copyright (C) 2007 by Gilles Caulier <caulier dot gilles at gmail dot com>
+ * Copyright (C) 2007-2008 by Gilles Caulier <caulier dot gilles at gmail dot com>
  *
  * This program is free software; you can redistribute it
  * and/or modify it under the terms of the GNU General
--- a/digikam/utilities/imageeditor/editor/editorwindow.cpp
+++ b/digikam/utilities/imageeditor/editor/editorwindow.cpp
@@ -885,10 +885,12 @@
         m_IOFileSettings->rawDecodingSettings.outputColorSpace = KDcrawIface::RawDecodingSettings::SRGB;
 
     m_IOFileSettings->rawDecodingSettings.sixteenBitsImage        = config->readBoolEntry("SixteenBitsImage", false);
-    m_IOFileSettings->rawDecodingSettings.automaticColorBalance   = config->readBoolEntry("AutomaticColorBalance", true);
-    m_IOFileSettings->rawDecodingSettings.cameraColorBalance      = config->readBoolEntry("CameraColorBalance", true);
+    m_IOFileSettings->rawDecodingSettings.whiteBalance            = (KDcrawIface::RawDecodingSettings::WhiteBalance)config->readNumEntry("WhiteBalance",
+                                                                    KDcrawIface::RawDecodingSettings::CAMERA);
+    m_IOFileSettings->rawDecodingSettings.customWhiteBalance      = config->readNumEntry("CustomWhiteBalance", 6500);
+    m_IOFileSettings->rawDecodingSettings.customWhiteBalanceGreen = config->readDoubleNumEntry("CustomWhiteBalanceGreen", 1.0);
     m_IOFileSettings->rawDecodingSettings.RGBInterpolate4Colors   = config->readBoolEntry("RGBInterpolate4Colors", false);
-    m_IOFileSettings->rawDecodingSettings.DontStretchPixels = config->readBoolEntry("DontStretchPixels", false);
+    m_IOFileSettings->rawDecodingSettings.DontStretchPixels       = config->readBoolEntry("DontStretchPixels", false);
     m_IOFileSettings->rawDecodingSettings.enableNoiseReduction    = config->readBoolEntry("EnableNoiseReduction", false);
     m_IOFileSettings->rawDecodingSettings.unclipColors            = config->readNumEntry("UnclipColors", 0);
     m_IOFileSettings->rawDecodingSettings.RAWQuality              = (KDcrawIface::RawDecodingSettings::DecodingQuality)config->readNumEntry("RAWQuality",