7
7
* Description : A digital camera RAW files loader for DImg
8
8
* framework using an external dcraw instance.
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>
10
* Copyright (C) 2005-2010 by Gilles Caulier <caulier dot gilles at gmail dot com>
11
* Copyright (C) 2005-2010 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
130
129
m_observer->progressInfo(m_image, value);
133
#if KDCRAW_VERSION < 0x000400
134
bool RAWLoader::checkToCancelReceivingData()
136
return (m_observer ? m_observer->isShuttingDown() : false);
139
void RAWLoader::setReceivingDataProgress(double value)
142
m_observer->progressInfo(m_image, value);
146
132
bool RAWLoader::loadedFromDcraw(QByteArray data, int width, int height, int rgbmax,
147
DImgLoaderObserver *observer)
133
DImgLoaderObserver* observer)
149
135
int checkpoint = 0;
179
165
if (QSysInfo::ByteOrder == QSysInfo::LittleEndian) // Intel
181
#if KDCRAW_VERSION < 0x000400
182
dst[0] = (unsigned short)((src[4]*256 + src[5]) * fac); // Blue
183
dst[1] = (unsigned short)((src[2]*256 + src[3]) * fac); // Green
184
dst[2] = (unsigned short)((src[0]*256 + src[1]) * fac); // Red
186
167
dst[0] = (unsigned short)((src[5]*256 + src[4]) * fac); // Blue
187
168
dst[1] = (unsigned short)((src[3]*256 + src[2]) * fac); // Green
188
169
dst[2] = (unsigned short)((src[1]*256 + src[0]) * fac); // Red
204
#if KDCRAW_VERSION < 0x000400
205
// ----------------------------------------------------------
207
// Special case: if Color Management is not used here, output color space is in sRGB* color space
208
// RAW decoded image is a linear-histogram image with 16 bits color depth.
209
// No auto white balance and no gamma adjustments are performed. Image is a black hole.
210
// We need to reproduce all dcraw 8 bits color depth adjustments here.
212
if (m_rawDecodingSettings.outputColorSpace != DRawDecoding::RAWCOLOR)
214
ImageHistogram histogram(image, width, height, true);
215
histogram.calculate();
217
int perc, val, total;
218
float white=0.0, r, gamma=2.222222;
219
unsigned short lut[65536];
221
// Search 99th percentile white level.
223
perc = (int)(width * height * 0.01);
224
kDebug() << "White Level: " << perc;
225
for (int c = 1 ; c < 4 ; ++c)
228
for (val = 65535 ; val > 256 ; --val)
229
if ((total += (int)histogram.getValue(c, val)) > perc)
232
if (white < val) white = (float)val;
235
white *= 1.0 / m_rawDecodingSettings.brightness;
237
kDebug() << "White Point: " << white;
239
// Compute the Gamma lut accordingly.
241
for (int i=0; i < 65536; ++i)
244
val = (int)(65536.0 * (r <= 0.018 ? r*4.5 : pow(r, 1.0/gamma) * 1.099-0.099));
245
if (val > 65535) val = 65535;
249
// Apply Gamma lut to the whole image.
251
unsigned short *im = (unsigned short *)image;
252
for (int i = 0; i < width*height; ++i)
254
im[0] = lut[im[0]]; // Blue
255
im[1] = lut[im[1]]; // Green
256
im[2] = lut[im[2]]; // Red
261
184
// ----------------------------------------------------------
263
186
imageData() = (uchar *)image;
379
302
if (m_customRawSettings.exposureComp != 0.0 || m_customRawSettings.saturation != 1.0)
381
WhiteBalance wb(m_rawDecodingSettings.sixteenBitsImage);
382
wb.whiteBalance(imageData(), imageWidth(), imageHeight(), m_rawDecodingSettings.sixteenBitsImage,
384
m_customRawSettings.exposureComp, // exposure
385
6500.0, // temperature (neutral)
389
m_customRawSettings.saturation); // saturation
304
WBContainer settings;
305
settings.temperature = 6500.0;
307
settings.black = 0.0;
308
settings.exposition = m_customRawSettings.exposureComp;
309
settings.gamma = 1.0;
310
settings.saturation = m_customRawSettings.saturation;
311
settings.green = 1.0;
312
WBFilter wb(m_image, 0L, settings);
313
wb.startFilterDirectly();
314
m_image->putImageData(wb.getTargetImage().bits());
391
317
if (observer) observer->progressInfo(m_image, 0.92F);
393
319
if (m_customRawSettings.lightness != 0.0 ||
394
320
m_customRawSettings.contrast != 1.0 ||
395
321
m_customRawSettings.gamma != 1.0)
398
bcg.setBrightness(m_customRawSettings.lightness);
399
bcg.setContrast(m_customRawSettings.contrast);
400
bcg.setGamma(m_customRawSettings.gamma);
401
bcg.applyBCG(imageData(), imageWidth(), imageHeight(), m_rawDecodingSettings.sixteenBitsImage);
323
BCGContainer settings;
324
settings.brightness = m_customRawSettings.lightness;
325
settings.contrast = m_customRawSettings.contrast;
326
settings.gamma = m_customRawSettings.gamma;
327
BCGFilter bcg(m_image, 0L, settings);
328
bcg.startFilterDirectly();
329
m_image->putImageData(bcg.getTargetImage().bits());
403
332
if (observer) observer->progressInfo(m_image, 0.94F);
405
334
if (!m_customRawSettings.curveAdjust.isEmpty())
407
DImg tmp(imageWidth(), imageHeight(), m_rawDecodingSettings.sixteenBitsImage);
408
ImageCurves curves(m_rawDecodingSettings.sixteenBitsImage);
409
curves.setCurvePoints(LuminosityChannel, m_customRawSettings.curveAdjust);
410
curves.curvesCalculateCurve(LuminosityChannel);
411
curves.curvesLutSetup(AlphaChannel);
412
curves.curvesLutProcess(imageData(), tmp.bits(), imageWidth(), imageHeight());
413
memcpy(imageData(), tmp.bits(), tmp.numBytes());
336
CurvesContainer settings;
337
settings.curvesType = ImageCurves::CURVE_SMOOTH;
338
settings.lumCurveVals = m_customRawSettings.curveAdjust;
339
CurvesFilter curves(m_image, 0L, settings);
340
curves.startFilterDirectly();
341
m_image->putImageData(curves.getTargetImage().bits());
415
344
if (observer) observer->progressInfo(m_image, 0.96F);
417
346
if (!m_customRawSettings.levelsAdjust.isEmpty())