/* * This file is part of RawTherapee. * * Copyright (c) 2004-2010 Gabor Horvath * * 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 . */ namespace rtengine { template T** allocArray (int W, int H) { T** t = new T*[H]; for (int i=0; i maxr) maxr = red[j]; if (green[i][j] > maxg) maxg = green[i][j]; if (blue[j] > maxb) maxb = blue[j]; } } delete [] red; delete [] blue; maxr = maxr * 19 / 20; maxg = maxg * 19 / 20; maxb = maxb * 19 / 20; int max[3]; max[0] = maxr; max[1] = maxg; max[2] = maxb; if( options.rtSettings.verbose ) printf ("HLRecoveryMap Maximum: R: %d, G: %d, B: %d\n", maxr, maxg, maxb); // downscale image int dw = W/SCALE; int dh = H/SCALE; Image16* ds = new Image16 (dw, dh); // overburnt areas int** rec[3]; for (int i=0; i<3; i++) rec[i] = allocArray (dw, dh); unsigned short* reds[SCALE]; unsigned short* blues[SCALE]; for (int i=0; ir(i,j) = sumr / SCALE/SCALE; ds->g(i,j) = sumg / SCALE/SCALE; ds->b(i,j) = sumb / SCALE/SCALE; } } for (int i=0; i200) phase2 = true; for (int i=1; i=0) { for (int x=-1; x<=1; x++) for (int y=-1; y<=1; y++) // average m/c color ratios in the surrounding pixels if (rec[m][i+x][j+y]>=0 && rec[m][i+x][j+y]!=INT_MAX && rec[c][i+x][j+y]>0 && rec[c][i+x][j+y]!=INT_MAX) { double ww = 1.0; if (!phase2 && (/*(double)(rec[m][i+x][j+y] - rec[m][i][j])/max[m]*(rec[m][i+x][j+y] - rec[m][i][j])/max[m] > 1.0/2 || */rec[c][i+x][j+y]200) phase2 = true; for (int i=1; i0 && rec[0][i+x][j+y]!=INT_MAX && rec[1][i+x][j+y]>0 && rec[1][i+x][j+y]!=INT_MAX && rec[2][i+x][j+y]>0 && rec[2][i+x][j+y]!=INT_MAX) { // convert to yiq double Y = 0.299 * rec[0][i+x][j+y] + 0.587 * rec[1][i+x][j+y] + 0.114 * rec[2][i+x][j+y]; double I = 0.596 * rec[0][i+x][j+y] - 0.275 * rec[1][i+x][j+y] - 0.321 * rec[2][i+x][j+y]; double Q = 0.212 * rec[0][i+x][j+y] - 0.523 * rec[1][i+x][j+y] + 0.311 * rec[2][i+x][j+y]; if (Y > maxY*7/10) { double w = 1.0;// / (I*I+Q*Q); yavg += Y*w; iavg += I*w; qavg += Q*w; weight += w; count++; } } if ((!phase2 && count>5) || (phase2 && count>3)) { double Y = yavg / weight; double I = iavg / weight; double Q = qavg / weight; rec[0][i][j] = - (Y + 0.956*I + 0.621*Q); rec[1][i][j] = - (Y - 0.272*I - 0.647*Q); rec[2][i][j] = - (Y - 1.105*I + 1.702*Q); } } } bool change = false; for (int i=0; imaxval) maxval = rec[c][i][j]; for (int i=0; i (hrmap[0], dh); freeArray (hrmap[1], dh); freeArray (hrmap[2], dh); } hrmap[0] = allocArray (dw, dh); hrmap[1] = allocArray (dw, dh); hrmap[2] = allocArray (dw, dh); this->full = full; for (int i=0; ir(i,j); hrmap[1][i][j] = (double)rec[1][i][j] / ds->g(i,j); hrmap[2][i][j] = (double)rec[2][i][j] / ds->b(i,j); } /* for (int i=0; ir(i,j) = CLIP (rec[0][i][j]); ds->g(i,j) = CLIP (rec[1][i][j]); ds->b(i,j) = CLIP (rec[2][i][j]); } ds->save ("test.png"); */ delete ds; freeArray (rec[0], dh); freeArray (rec[1], dh); freeArray (rec[2], dh); printf ("HLMap vege\n"); } void RawImageSource::hlRecovery (unsigned short* red, unsigned short* green, unsigned short* blue, int i, int sx1, int sx2, int skip) { int blr = (i+SCALE/2) / SCALE - 1; if (blr<0 || blr>=H/SCALE-1) return; double mr1 = 1.0 - ((double)((i+SCALE/2) % SCALE) / SCALE + 0.5 / SCALE); int jx = 0; int maxcol = W/SCALE; for (int j=sx1, jx=0; j=maxcol-1) continue; double mc1 = 1.0 - ((double)((j+SCALE/2) % SCALE) / SCALE + 0.5 / SCALE); double mulr = mr1*mc1 * hrmap[0][blr][blc] + mr1*(1.0-mc1) * hrmap[0][blr][blc+1] + (1.0-mr1)*mc1 * hrmap[0][blr+1][blc] + (1.0-mr1)*(1.0-mc1) * hrmap[0][blr+1][blc+1]; double mulg = mr1*mc1 * hrmap[1][blr][blc] + mr1*(1.0-mc1) * hrmap[1][blr][blc+1] + (1.0-mr1)*mc1 * hrmap[1][blr+1][blc] + (1.0-mr1)*(1.0-mc1) * hrmap[1][blr+1][blc+1]; double mulb = mr1*mc1 * hrmap[2][blr][blc] + mr1*(1.0-mc1) * hrmap[2][blr][blc+1] + (1.0-mr1)*mc1 * hrmap[2][blr+1][blc] + (1.0-mr1)*(1.0-mc1) * hrmap[2][blr+1][blc+1]; red[jx] = CLIP(red[jx] * mulr); green[jx] = CLIP(green[jx] * mulg); blue[jx] = CLIP(blue[jx] * mulb); } } }