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

Open
wants to merge 17 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 13 additions & 10 deletions rtengine/improccoordinator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,14 @@ 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),
histChroma(65536),

histToneCurve(256),
histToneCurveBW(256),
histLCurve(256),
Expand All @@ -125,7 +129,6 @@ ImProcCoordinator::ImProcCoordinator() :
histCCAM(256),
histClad(256),
bcabhist(256),
histChroma(256),

histLRETI(256),

Expand Down Expand Up @@ -1759,7 +1762,7 @@ void 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])) * 1.3653333333f)]++; // = 65536/48000
}
}
#ifdef _OPENMP
Expand All @@ -1771,7 +1774,7 @@ void ImProcCoordinator::updateLRGBHistograms()
for (int i = y1; i < y2; i++)
for (int j = x1; j < x2; j++)
{
histLuma[(int)(nprevl->L[i][j] / 128.f)]++;
histLuma[2 * (int)(nprevl->L[i][j])]++; // L = [0..32768] map to [0..65535]
}
}
#ifdef _OPENMP
Expand All @@ -1787,9 +1790,9 @@ void ImProcCoordinator::updateLRGBHistograms()
int ofs = (i * pW + x1) * 3;

for (int j = x1; j < x2; j++) {
int r = workimg->data[ofs++];
int g = workimg->data[ofs++];
int b = workimg->data[ofs++];
int r = workimg->data[ofs++] * 256; // scale up, because workimg is 8 bit
int g = workimg->data[ofs++] * 256;
int b = workimg->data[ofs++] * 256;

histRed[r]++;
histGreen[g]++;
Expand Down
5 changes: 3 additions & 2 deletions rtengine/improccoordinator.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,9 @@ class ImProcCoordinator final : public StagedImageProcessor
LUTu histRed, histRedRaw;
LUTu histGreen, histGreenRaw;
LUTu histBlue, histBlueRaw;
LUTu histLuma, histToneCurve, histToneCurveBW, histLCurve, histCCurve;
LUTu histLLCurve, histLCAM, histCCAM, histClad, bcabhist, histChroma, histLRETI;
LUTu histLuma, histChroma;
LUTu histToneCurve, histToneCurveBW, histLCurve, histCCurve;
LUTu histLLCurve, histLCAM, histCCAM, histClad, bcabhist, histLRETI;

LUTf CAMBrightCurveJ, CAMBrightCurveQ;

Expand Down
10 changes: 5 additions & 5 deletions rtengine/rawimagesource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3729,7 +3729,7 @@ void RawImageSource::getRAWHistogram (LUTu & histRedRaw, LUTu & histGreenRaw, LU

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 multScale = maxWhite <= 1.f ? 1.f / 65535.f : 65535.f;
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 @@ -3838,12 +3838,12 @@ void RawImageSource::getRAWHistogram (LUTu & histRedRaw, LUTu & histGreenRaw, LU
}
} // end of critical region
} // end of parallel region

const auto getidx =
[&](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), 65535)) : 0;
};

for (int i = 0; i < histoSize; i++) {
Expand All @@ -3865,11 +3865,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
104 changes: 36 additions & 68 deletions rtgui/histogrampanel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -670,9 +670,9 @@ HistogramArea::HistogramArea (DrawModeListener *fml) :
isPressed(false), movingPosition(0.0)
{

rhist(256);
ghist(256);
bhist(256);
rhist(65536);
ghist(65536);
bhist(65536);
lhist(256);
chist(256);

Expand Down Expand Up @@ -869,105 +869,72 @@ void HistogramArea::updateBackBuffer ()
LUTu& gh = rawMode ? ghistRaw : ghist;
LUTu& bh = rawMode ? bhistRaw : bhist;

// make double copies of LUT, one for faster access, another one to scale down the raw histos
Thanatomanic marked this conversation as resolved.
Show resolved Hide resolved
LUTu rhchanged(256), ghchanged(256), bhchanged(256);
unsigned int lhisttemp[256] ALIGNED16 {0}, chisttemp[256] ALIGNED16 {0}, rhtemp[256] ALIGNED16 {0}, ghtemp[256] ALIGNED16 {0}, bhtemp[256] ALIGNED16 {0};
const int scale = (rawMode ? 8 : 1);

for(int i = 0; i < 256; i++) {
if(needLuma) {
lhisttemp[i] = lhist[i];
}

if(needChroma) {
chisttemp[i] = chist[i];
}

if(needRed) {
rhchanged[i] = rhtemp[i] = rh[i] / scale;
}

if(needGreen) {
ghchanged[i] = ghtemp[i] = gh[i] / scale;
}

if(needBlue) {
bhchanged[i] = bhtemp[i] = bh[i] / scale;
}
}

// Compute the highest point of the histogram for scaling
// Values at far left and right end (0 and 255) are handled differently

unsigned int histheight = 0;
unsigned int rgbmax = 0;
unsigned int lumamax = 0;
unsigned int chromamax = 0;

for (int i = 1; i < 255; i++) {
if (needLuma && lhisttemp[i] > histheight) {
histheight = lhisttemp[i];
for (int i = 1; i < 65535; i++) { // Values at far left and right end are handled differently
Thanatomanic marked this conversation as resolved.
Show resolved Hide resolved
if (needLuma && lhist[i] > lumamax) {
lumamax = lhist[i];
}

if (needChroma && chisttemp[i] > histheight) {
histheight = chisttemp[i];
if (needChroma && chist[i] > chromamax) {
chromamax = chist[i];
}

if (needRed && rhtemp[i] > histheight) {
histheight = rhtemp[i];
if (needRed && rh[i] > rgbmax) {
rgbmax = rh[i];
}

if (needGreen && ghtemp[i] > histheight) {
histheight = ghtemp[i];
if (needGreen && gh[i] > rgbmax) {
rgbmax = gh[i];
}

if (needBlue && bhtemp[i] > histheight) {
histheight = bhtemp[i];
if (needBlue && bh[i] > rgbmax) {
rgbmax = bh[i];
}
}

int realhistheight = histheight;

if (realhistheight < winh - 2) {
realhistheight = winh - 2;
}

cr->set_antialias (Cairo::ANTIALIAS_SUBPIXEL);
cr->set_line_width (1.0 * s);
cr->set_operator (Cairo::OPERATOR_OVER);

int ui = 0, oi = 0;

if (needLuma && !rawMode) {
drawCurve(cr, lhist, realhistheight, w, h);
cr->set_source_rgba (0.65, 0.65, 0.65, 0.65);
cr->fill ();
drawMarks(cr, lhist, realhistheight, w, ui, oi);
drawCurve(cr, lhist, lumamax, w, h);
cr->set_source_rgb (0.7, 0.7, 0.7);
cr->stroke ();
drawMarks(cr, lhist, lumamax, w, ui, oi);
}

if (needChroma && !rawMode) {
drawCurve(cr, chist, realhistheight, w, h);
drawCurve(cr, chist, chromamax, w, h);
cr->set_source_rgb (0.9, 0.9, 0.);
cr->stroke ();
drawMarks(cr, chist, realhistheight, w, ui, oi);
drawMarks(cr, chist, chromamax, w, ui, oi);
}

if (needRed) {
drawCurve(cr, rhchanged, realhistheight, w, h);
drawCurve(cr, rh, rgbmax, w, h);
cr->set_source_rgb (1.0, 0.0, 0.0);
cr->stroke ();
drawMarks(cr, rhchanged, realhistheight, w, ui, oi);
drawMarks(cr, rh, rgbmax, w, ui, oi);
}

if (needGreen) {
drawCurve(cr, ghchanged, realhistheight, w, h);
drawCurve(cr, gh, rgbmax, w, h);
cr->set_source_rgb (0.0, 1.0, 0.0);
cr->stroke ();
drawMarks(cr, ghchanged, realhistheight, w, ui, oi);
drawMarks(cr, gh, rgbmax, w, ui, oi);
}

if (needBlue) {
drawCurve(cr, bhchanged, realhistheight, w, h);
drawCurve(cr, bh, rgbmax, w, h);
cr->set_source_rgb (0.0, 0.4, 1.0);
cr->stroke ();
drawMarks(cr, bhchanged, realhistheight, w, ui, oi);
drawMarks(cr, bh, rgbmax, w, ui, oi);
}

}
Expand All @@ -994,10 +961,10 @@ void HistogramArea::drawCurve(Cairo::RefPtr<Cairo::Context> &cr,
double s = RTScalable::getScale();

cr->set_line_width(s);
cr->move_to (padding, vsize - 1);
//cr->move_to (padding, vsize - 1);
scale = scale <= 0.0 ? 0.001 : scale; // avoid division by zero and negative values

for (int i = 0; i < 256; i++) {
for (int i = 0; i < 65536; i++) {
Thanatomanic marked this conversation as resolved.
Show resolved Hide resolved
double val = data[i] * (double)vsize / scale;

if (drawMode > 0) { // scale y for single and double log-scale
Expand All @@ -1006,16 +973,17 @@ void HistogramArea::drawCurve(Cairo::RefPtr<Cairo::Context> &cr,

double iscaled = i;
if (drawMode == 2) { // scale x for double log-scale
iscaled = HistogramScaling::log (255.0, (double)i);
iscaled = HistogramScaling::log (65535.0, (double)i);
}

double posX = padding + iscaled * (hsize - padding * 2.0) / 255.0;
double posX = padding + iscaled * (hsize - padding * 2.0) / 65535.0;
double posY = vsize - 2 + val * (4 - vsize) / vsize;

cr->move_to (posX, vsize - 2);
cr->line_to (posX, posY);
}

cr->line_to (hsize - padding, vsize - 1);
//cr->line_to (hsize - padding, vsize - 1);
}

void HistogramArea::drawMarks(Cairo::RefPtr<Cairo::Context> &cr,
Expand All @@ -1027,7 +995,7 @@ void HistogramArea::drawMarks(Cairo::RefPtr<Cairo::Context> &cr,
cr->rectangle(padding, (ui++)*s, s, s);
}

if(data[255] > scale) {
if(data[65535] > scale) {
cr->rectangle(hsize - s - padding, (oi++)*s, s, s);
}

Expand Down