7
7
* Description : A digital camera RAW files loader for DImg
8
8
* framework using an external dcraw instance.
10
* Copyright (C) 2005-2007 by Gilles Caulier <caulier dot gilles at gmail dot com>
11
* Copyright (C) 2005-2007 by Marcel Wiesweg <marcel.wiesweg@gmx.de>
10
* Copyright (C) 2005-2008 by Gilles Caulier <caulier dot gilles at gmail dot com>
11
* Copyright (C) 2005-2008 by Marcel Wiesweg <marcel.wiesweg@gmx.de>
13
13
* This program is free software; you can redistribute it
14
14
* and/or modify it under the terms of the GNU General
57
66
// I hope when porting to Qt4, all the event loop stuff (and this problem) can be removed.
58
67
if (imageGetAttribute("noeventloop").isValid())
61
70
readMetadata(filePath, DImg::RAW);
63
72
// NOTE: Here, we don't check a possible embedded work-space color profile using
64
73
// the method checkExifWorkingColorSpace() like with JPEG, PNG, and TIFF loaders,
65
74
// because RAW file are always in linear mode.
67
76
int width, height, rgbmax;
69
78
if (!KDcrawIface::KDcraw::decodeRAWImage(filePath, m_rawDecodingSettings,
145
// ----------------------------------------------------------
147
// Special case : if Color Management is not used here, output color space is in sRGB* color space
148
// RAW decoded image is a linear-histogram image with 16 bits color depth.
149
// No auto white balance and no gamma adjustemnts are performed. Image is a black hole.
150
// We need to reproduce all dcraw 8 bits color depth adjustements here.
152
if (m_rawDecodingSettings.outputColorSpace != KDcrawIface::RawDecodingSettings::RAWCOLOR)
154
ImageHistogram histogram(image, width, height, true);
156
int perc, val, total;
158
unsigned short lut[65536];
160
// Search 99th percentile white level.
162
perc = (int)(width * height * 0.01);
163
DDebug() << "White Level: " << perc << endl;
164
for (int c = 1 ; c < 4 ; c++)
167
for (val = 65535 ; val > 256 ; --val)
168
if ((total += (int)histogram.getValue(c, val)) > perc)
171
if (white < val) white = (float)val;
173
DDebug() << "White Point: " << white << endl;
175
// Compute the Gamma lut accordingly.
177
for (int i=0; i < 65536; i++)
180
val = (int)(65536.0 * (r <= 0.018 ? r*4.5 : pow(r,0.45)*1.099-0.099));
181
if (val > 65535) val = 65535;
185
// Apply Gamma lut to the whole image.
187
unsigned short *im = (unsigned short *)image;
188
for (int i = 0; i < width*height; i++)
190
im[0] = lut[im[0]]; // Blue
191
im[1] = lut[im[1]]; // Green
192
im[2] = lut[im[2]]; // Red
197
// ----------------------------------------------------------
136
199
imageData() = (uchar *)image;
138
201
else // 8 bits image
236
// NOTE: if Color Management is not used here, output color space is in sRGB* color space.
237
// Gamma and White balance are previously adjusted by dcraw in 8 bits color depth.
173
239
imageData() = image;
176
242
//----------------------------------------------------------
243
// Assign the right color-space profile.
245
KGlobal::dirs()->addResourceType("profiles", KGlobal::dirs()->kde_default("data") + "digikam/profiles");
246
switch(m_rawDecodingSettings.outputColorSpace)
248
case KDcrawIface::RawDecodingSettings::SRGB:
250
QString directory = KGlobal::dirs()->findResourceDir("profiles", "srgb.icm");
251
m_image->getICCProfilFromFile(directory + "srgb.icm");
254
case KDcrawIface::RawDecodingSettings::ADOBERGB:
256
QString directory = KGlobal::dirs()->findResourceDir("profiles", "adobergb.icm");
257
m_image->getICCProfilFromFile(directory + "adobergb.icm");
260
case KDcrawIface::RawDecodingSettings::WIDEGAMMUT:
262
QString directory = KGlobal::dirs()->findResourceDir("profiles", "widegamut.icm");
263
m_image->getICCProfilFromFile(directory + "widegamut.icm");
266
case KDcrawIface::RawDecodingSettings::PROPHOTO:
268
QString directory = KGlobal::dirs()->findResourceDir("profiles", "prophoto.icm");
269
m_image->getICCProfilFromFile(directory + "prophoto.icm");
273
// No icc color-space profile to assign in RAW color mode.
277
//----------------------------------------------------------
178
279
imageWidth() = width;
179
280
imageHeight() = height;