rawTherapee/rtengine/previewimage.cc
Desmis 69c1caafa1
Whitebalance - Removed GUI Itcwb from whitebalance and preferences (#6710)
* Change Preferences for observer whitebalance

* Change label white balance preferences

* Added Preferences 2 parameters Whitebalance auto correlation

* Add Preference Temperature correlation - sort and tooltip

* Change to rtengine cmakelist

* Apply patch from Lawrence37

* Small comment code

* Change defaut order prefrences wba

* Added force extra algoritm to Preferences

* Harmonize itcwb sorted

* Add fields to Preferences Itcwb

* Change settings precision Itcwb in Preferences

* Change tooltip Itcwb preferences

* First stage Itwcwb settings in main with pp3 and selction in preferences

* Second stage Itwcwb settings in main with pp3 and selction in preferences

* Third stage Itwcwb settings in main with pp3 and selction in preferences

* Add itcwb_fgreen student - green optimize

* Add Itcwb green range

* Itcwb history msg - first tooltips

* Remove force-extra because always used

* reused force-extra to use entire CIExy for sampling datas

* Removed inwanted text in console

* Set sensitive for Itcwbframe

* Various change - comment ..

* Small code review - chnage tooltips

* Remove settings itcwb_delta in Rawimagesource.cc to simplify

* Remove Itcwb Observer - put a single observer for everything - general - itcwb

* Fixed conflicts in colortemp.cc

* Various change - fixed bug - simplify

* Fixed limits for settings pp3 - chnage tooltip

* Clean unused code

* Put itcwb_findgreen in GUI

* Added checkbox 'Low sampling' to find the settings of 5.9

* Set Observer to Observer 10° - preferences default

* Missing setting Low sampling

* Show white balance multipliers

* Change default settings - Itcwb_sorted

* Move observer from preferences to WB

* Make observer selectable for camera WB

* Ensure observer checkbox is in sync with PP3

* Set default ITCWB low sampling for PP3s from <=5.9

Ensure temperature correlation white balance algorithm 1 is used when
opening edits from versions 5.9 and earlier.

* Removed unused White-balance frame in Preferences

* Comment some GUI sliders checkbox

* Removed all GUI itcwb in preferences and whitebalance

* Removed forgotten code in preferences

* Remove labels tooltips history Itcwb

---------

Co-authored-by: Lawrence Lee <45837045+Lawrence37@users.noreply.github.com>
2023-03-19 07:47:58 +01:00

180 lines
6.2 KiB
C++

/*
* This file is part of RawTherapee.
*
* Copyright (c) 2004-2010 Gabor Horvath <hgabor@rawtherapee.com>
*
* RawTherapee is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* RawTherapee is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with RawTherapee. If not, see <https://www.gnu.org/licenses/>.
*/
#include "previewimage.h"
#include "color.h"
#include "iimage.h"
#include "iimage.h"
#include "procparams.h"
#include "rawimagesource.h"
#include "rtthumbnail.h"
#include "utils.h"
using namespace rtengine;
using namespace procparams;
PreviewImage::PreviewImage (const Glib::ustring &fname, const Glib::ustring &ext, const PreviewImageMode mode)
{
rtengine::Thumbnail* tpp = nullptr;
if (mode == PIM_EmbeddedPreviewOnly || mode == PIM_EmbeddedOrRaw) {
const unsigned char *data = nullptr;
int width = -1, height = -1;
if (ext.lowercase() == "jpg" || ext.lowercase() == "jpeg") {
// int deg = infoFromImage (fname);
tpp = rtengine::Thumbnail::loadFromImage (fname, width, height, 1, 1., ColorTemp::DEFAULT_OBSERVER, true);
if (tpp) {
data = tpp->getImage8Data();
}
} else if (ext.lowercase() == "png") {
tpp = rtengine::Thumbnail::loadFromImage (fname, width, height, 1, 1., ColorTemp::DEFAULT_OBSERVER, true);
if (tpp) {
data = tpp->getImage8Data();
}
} else if (ext.lowercase() == "tif" || ext.lowercase() == "tiff") {
// int deg = infoFromImage (fname);
tpp = rtengine::Thumbnail::loadFromImage (fname, width, height, 1, 1., ColorTemp::DEFAULT_OBSERVER, true);
if (tpp) {
data = tpp->getImage8Data();
}
} else {
rtengine::RawMetaDataLocation ri;
eSensorType sensorType = rtengine::ST_NONE;
tpp = rtengine::Thumbnail::loadQuickFromRaw (fname, ri, sensorType, width, height, 1, true, true);
if (tpp) {
data = tpp->getImage8Data();
}
}
if (tpp) {
if (data) {
int w, h;
double scale = 1.;
tpp->getDimensions(w, h, scale);
previewImage = Cairo::ImageSurface::create(Cairo::FORMAT_RGB24, w, h);
previewImage->flush();
#ifdef _OPENMP
#pragma omp parallel for
#endif
for (unsigned int i = 0; i < (unsigned int)(h); ++i) {
const unsigned char *src = data + i * w * 3;
unsigned char *dst = previewImage->get_data() + i * w * 4;
for (unsigned int j = 0; j < (unsigned int)(w); ++j) {
unsigned char r = *(src++);
unsigned char g = *(src++);
unsigned char b = *(src++);
poke255_uc(dst, r, g, b);
}
}
previewImage->mark_dirty();
}
}
}
if ((mode == PIM_EmbeddedOrRaw && !tpp) || mode == PIM_ForceRaw) {
RawImageSource rawImage;
int error = rawImage.load(fname);
if (!error) {
const unsigned char *data = nullptr;
int fw, fh;
procparams::ProcParams params;
ColorTemp wb = rawImage.getWB ();
rawImage.getFullSize (fw, fh, TR_NONE);
PreviewProps pp (0, 0, fw, fh, 1);
params.icm.inputProfile = Glib::ustring("(embedded)");
params.raw.bayersensor.method = RAWParams::BayerSensor::getMethodString(RAWParams::BayerSensor::Method::FAST);
params.raw.deadPixelFilter = false;
params.raw.ca_autocorrect = false;
params.raw.xtranssensor.method = RAWParams::XTransSensor::getMethodString(RAWParams::XTransSensor::Method::FAST);
rawImage.preprocess(params.raw, params.lensProf, params.coarse);
double contrastThresholdDummy = 0.0;
rawImage.demosaic(params.raw, false, contrastThresholdDummy);
Imagefloat image(fw, fh);
rawImage.getImage (wb, TR_NONE, &image, pp, params.toneCurve, params.raw, 0);
rtengine::Image8 output(fw, fh);
rawImage.convertColorSpace(&image, params.icm, wb);
#ifdef _OPENMP
#pragma omp parallel for schedule(dynamic, 10)
#endif
for (int i = 0; i < fh; ++i)
for (int j = 0; j < fw; ++j) {
image.r(i, j) = Color::gamma2curve[image.r(i, j)];
image.g(i, j) = Color::gamma2curve[image.g(i, j)];
image.b(i, j) = Color::gamma2curve[image.b(i, j)];
}
image.resizeImgTo<Image8>(fw, fh, TI_Nearest, &output);
data = output.getData();
if (data) {
int w, h;
w = output.getWidth();
h = output.getHeight();
previewImage = Cairo::ImageSurface::create(Cairo::FORMAT_RGB24, w, h);
previewImage->flush();
#ifdef _OPENMP
#pragma omp parallel for
#endif
for (unsigned int i = 0; i < (unsigned int)(h); i++) {
const unsigned char *src = data + i * w * 3;
unsigned char *dst = previewImage->get_data() + i * w * 4;
for (unsigned int j = 0; j < (unsigned int)(w); j++) {
unsigned char r = *(src++);
unsigned char g = *(src++);
unsigned char b = *(src++);
poke255_uc(dst, r, g, b);
}
}
previewImage->mark_dirty();
}
}
}
if (tpp) {
delete tpp;
}
}
Cairo::RefPtr<Cairo::ImageSurface> PreviewImage::getImage()
{
return previewImage;
}