Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements to change main histogram to 65535 bins #5904

Draft
wants to merge 17 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion rtdata/themes/RawTherapee-GTK3-20_.css
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,8 @@ flowboxchild:selected {

#HistogramArea,
#HistogramRGBArea {
border-width: 0.083333333333333333em;
border: none;
/*border-width: 0.083333333333333333em;*/
}

#histButton {
Expand Down
5 changes: 5 additions & 0 deletions rtengine/imagesource.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ class ImageSource : public InitialImage
virtual void WBauto(double &tempref, double &greenref, array2D<float> &redloc, array2D<float> &greenloc, array2D<float> &blueloc, int bfw, int bfh, double &avg_rm, double &avg_gm, double &avg_bm, double &tempitc, double &greenitc, float &studgood, bool &twotimes, const procparams::WBParams & wbpar, int begx, int begy, int yEn, int xEn, int cx, int cy, const procparams::ColorManagementParams &cmp, const procparams::RAWParams &raw) = 0;
virtual void getrgbloc(int begx, int begy, int yEn, int xEn, int cx, int cy, int bf_h, int bf_w) = 0;

virtual unsigned int getBitDepth() const
{
return 0;
}

virtual double getDefGain () const
{
return 1.0;
Expand Down
26 changes: 19 additions & 7 deletions rtengine/improccoordinator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,13 @@ ImProcCoordinator::ImProcCoordinator() :
lhist16CCAM(65536),
lhist16RETI(),
lhist16LClad(65536),
histRed(256), histRedRaw(256),
histGreen(256), histGreenRaw(256),
histBlue(256), histBlueRaw(256),
histLuma(256),

// Main histogram
histRed(65536), histRedRaw(65536),
histGreen(65536), histGreenRaw(65536),
histBlue(65536), histBlueRaw(65536),
histLuma(65536),

histToneCurve(256),
histToneCurveBW(256),
histLCurve(256),
Expand All @@ -113,7 +116,7 @@ ImProcCoordinator::ImProcCoordinator() :
histCCAM(256),
histClad(256),
bcabhist(256),
histChroma(256),
histChroma(65536),

histLRETI(256),

Expand Down Expand Up @@ -310,6 +313,14 @@ void ImProcCoordinator::updatePreviewImage(int todo, bool panningRelatedChange)
}
}

// Forward bit depth of image to the histogram
if (hListener) {
hListener->setBitDepth(imgsrc->getBitDepth());
if (settings->verbose) {
printf("Image has a bit depth of %u bits\n",imgsrc->getBitDepth());
}
}

if (((todo & ALL) == ALL) || (todo & M_MONITOR) || panningRelatedChange || (highDetailNeeded && options.prevdemo != PD_Sidecar)) {
bwAutoR = bwAutoG = bwAutoB = -9000.f;

Expand Down Expand Up @@ -1827,7 +1838,7 @@ bool ImProcCoordinator::updateLRGBHistograms()
for (int i = y1; i < y2; i++)
for (int j = x1; j < x2; j++)
{
histChroma[(int)(sqrtf(SQR(nprevl->a[i][j]) + SQR(nprevl->b[i][j])) / 188.f)]++; //188 = 48000/256
histChroma[(int)(sqrtf(SQR(nprevl->a[i][j]) + SQR(nprevl->b[i][j])) * 255.0/48000.0)]++;
}
}
#ifdef _OPENMP
Expand All @@ -1836,10 +1847,11 @@ bool ImProcCoordinator::updateLRGBHistograms()
{
histLuma.clear();

double s = 0.0078125; // map L = [0..32768] to [0..255]
for (int i = y1; i < y2; i++)
for (int j = x1; j < x2; j++)
{
histLuma[(int)(nprevl->L[i][j] / 128.f)]++;
histLuma[(int)(nprevl->L[i][j] * s)]++;
}
}
#ifdef _OPENMP
Expand Down
5 changes: 5 additions & 0 deletions rtengine/rawimage.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ class RawImage: public DCraw
{
return fuji_width;
}

unsigned int get_bitdepth() const
{
return tiff_bps;
}

float const * get_FloatRawImage() const
{
Expand Down
18 changes: 12 additions & 6 deletions rtengine/rawimagesource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,11 @@ int RawImageSource::getRotateDegree() const
return ri->get_rotateDegree();
}

unsigned int RawImageSource::getBitDepth() const
{
return ri->get_bitdepth();
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void RawImageSource::transformRect (const PreviewProps &pp, int tran, int &ssx1, int &ssy1, int &width, int &height, int &fw)
Expand Down Expand Up @@ -3769,17 +3774,18 @@ void RawImageSource::getAutoExpHistogram (LUTu & histogram, int& histcompr)
}
}

// Histogram MUST be 256 in size; gamma is applied, blackpoint and gain also
// For histogram data gamma is applied, blackpoint and gain also
void RawImageSource::getRAWHistogram (LUTu & histRedRaw, LUTu & histGreenRaw, LUTu & histBlueRaw)
{
// BENCHFUN
histRedRaw.clear();
histGreenRaw.clear();
histBlueRaw.clear();

const float maxrawvalue = static_cast<float>(1 << getBitDepth()) - 1.f;
const float maxWhite = rtengine::max(c_white[0], c_white[1], c_white[2], c_white[3]);
const float scale = maxWhite <= 1.f ? 65535.f : 1.f; // special case for float raw images in [0.0;1.0] range
const float multScale = maxWhite <= 1.f ? 1.f / 255.f : 255.f;
const float scale = maxWhite <= 1.f ? maxrawvalue : 1.f; // special case for float raw images in [0.0;1.0] range
const float multScale = maxWhite <= 1.f ? 1.f / maxrawvalue : maxrawvalue;
const float mult[4] = { multScale / (c_white[0] - cblacksom[0]),
multScale / (c_white[1] - cblacksom[1]),
multScale / (c_white[2] - cblacksom[2]),
Expand Down Expand Up @@ -3893,7 +3899,7 @@ void RawImageSource::getRAWHistogram (LUTu & histRedRaw, LUTu & histGreenRaw, LU
[&](int c, int i) -> int
{
float f = mult[c] * std::max(0.f, i - cblacksom[c]);
return f > 0.f ? (f < 1.f ? 1 : std::min(int(f), 255)) : 0;
return f > 0.f ? (f < 1.f ? 1 : std::min(int(f), int(maxrawvalue))) : 0;
};

for (int i = 0; i < histoSize; i++) {
Expand All @@ -3915,11 +3921,11 @@ void RawImageSource::getRAWHistogram (LUTu & histRedRaw, LUTu & histGreenRaw, LU
}

if (ri->getSensorType() == ST_BAYER) // since there are twice as many greens, correct for it
for (int i = 0; i < 256; i++) {
for (int i = 0; i < 65536; i++) {
histGreenRaw[i] >>= 1;
}
else if (ri->getSensorType() == ST_FUJI_XTRANS) // since Xtrans has 2.5 as many greens, correct for it
for (int i = 0; i < 256; i++) {
for (int i = 0; i < 65536; i++) {
histGreenRaw[i] = (histGreenRaw[i] * 2) / 5;
}
else if (ri->get_colors() == 1) { // monochrome sensor => set all histograms equal
Expand Down
2 changes: 2 additions & 0 deletions rtengine/rawimagesource.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ class RawImageSource final : public ImageSource
void getSize (const PreviewProps &pp, int& w, int& h) override;
int getRotateDegree() const override;

unsigned int getBitDepth() const override;

ImageMatrices* getImageMatrices () override
{
return &imatrices;
Expand Down
2 changes: 2 additions & 0 deletions rtengine/rtengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,8 @@ class HistogramListener
virtual bool updateVectorscopeHS(void) const = 0;
/** Returns if the listener wants the waveform to be updated. */
virtual bool updateWaveform(void) const = 0;
/** Set the bit depth of the image for the histogram binning */
virtual void setBitDepth(unsigned int bitdepth) = 0;
};

class HistogramObservable
Expand Down
5 changes: 5 additions & 0 deletions rtengine/stdimagesource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,11 @@ void StdImageSource::getSize (const PreviewProps &pp, int& w, int& h)
h = pp.getHeight() / pp.getSkip() + (pp.getHeight() % pp.getSkip() > 0);
}

unsigned int StdImageSource::getBitDepth() const
{
return img->getBPS();
}

void StdImageSource::getAutoExpHistogram (LUTu & histogram, int& histcompr)
{
if (img->getType() == sImage8) {
Expand Down
2 changes: 2 additions & 0 deletions rtengine/stdimagesource.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ class StdImageSource : public ImageSource
void getFullSize (int& w, int& h, int tr = TR_NONE) override;
void getSize (const PreviewProps &pp, int& w, int& h) override;

unsigned int getBitDepth() const override;

ImageIO* getImageIO ()
{
return img;
Expand Down
7 changes: 7 additions & 0 deletions rtgui/editorpanel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2305,6 +2305,13 @@ bool EditorPanel::updateWaveform(void) const
|| histogram_scope_type == ScopeType::NONE;
}

void EditorPanel::setBitDepth(unsigned int bitdepth)
{
if (histogramPanel) {
histogramPanel->setBitDepth(bitdepth);
}
}

void EditorPanel::scopeTypeChanged(ScopeType new_type)
{
histogram_scope_type = new_type;
Expand Down
1 change: 1 addition & 0 deletions rtgui/editorpanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ class EditorPanel final :
bool updateVectorscopeHC(void) const override;
bool updateVectorscopeHS(void) const override;
bool updateWaveform(void) const override;
void setBitDepth(unsigned int bitdepth) override;

// HistogramPanelListener
void scopeTypeChanged(Options::ScopeType new_type) override;
Expand Down
Loading