Another bugfix for WB.

This commit is contained in:
Emil Martinec
2010-09-28 06:59:17 -05:00
parent 751ebdf0eb
commit 595b124a23
2 changed files with 10 additions and 11 deletions

View File

@@ -661,29 +661,29 @@
+ double d = tpp->defGain * image[i* ::width+j][1];
+ if (d>64000)
+ continue;
+ avg_g += d*d*d*d*d*d;
+ avg_g += d;
+ gn++;
+ }
+ if (FISRED(filter,i,j)) {
+ double d = tpp->defGain * image[i* ::width+j][0];
+ if (d>64000)
+ continue;
+ avg_r += d*d*d*d*d*d;
+ avg_r += d;
+ rn++;
+ }
+ if (FISBLUE(filter,i,j)) {
+ double d = tpp->defGain * image[i* ::width+j][2];
+ if (d>64000)
+ continue;
+ avg_b += d*d*d*d*d*d;
+ avg_b += d;
+ bn++;
+ }
+ }
+ }
+
+ double reds = pow (avg_r/rn, 1.0/6.0) * tpp->camwbRed;
+ double greens = pow (avg_g/gn, 1.0/6.0) * tpp->camwbGreen;
+ double blues = pow (avg_b/bn, 1.0/6.0) * tpp->camwbBlue;
+ double reds = avg_r/rn * tpp->camwbRed;
+ double greens = avg_g/gn * tpp->camwbGreen;
+ double blues = avg_b/bn * tpp->camwbBlue;
+
+ double rm = rgb_cam[0][0]*reds + rgb_cam[0][1]*greens + rgb_cam[0][2]*blues;
+ double gm = rgb_cam[1][0]*reds + rgb_cam[1][1]*greens + rgb_cam[1][2]*blues;

View File

@@ -116,18 +116,17 @@ Thumbnail* Thumbnail::loadFromImage (const Glib::ustring& fname, int &w, int &h,
double avg_g = 0;
double avg_b = 0;
int n = 0;
int p = 6;
for (int i=1; i<img->height-1; i++)
for (int j=1; j<img->width-1; j++) {
int ofs = 3*(i*img->width + j);
if (img->data[ofs]>250 || img->data[ofs+1]>250 || img->data[ofs+2]>250)
continue;
avg_r += StdImageSource::intpow((double)img->data[ofs]*256, p);
avg_g += StdImageSource::intpow((double)img->data[ofs+1]*256, p);
avg_b += StdImageSource::intpow((double)img->data[ofs+2]*256, p);
avg_r += img->data[ofs];
avg_g += img->data[ofs+1];
avg_b += img->data[ofs+2];
n++;
}
ColorTemp::mul2temp (pow(avg_r/n, 1.0/p), pow(avg_g/n, 1.0/p), pow(avg_b/n, 1.0/p), tpp->autowbTemp, tpp->autowbGreen);
ColorTemp::mul2temp (avg_r/n, avg_g/n, avg_b/n, tpp->autowbTemp, tpp->autowbGreen);
delete img;
tpp->init ();