fix black level computation for applying flat-field correction, taken from ART, thanks @agriggio

This commit is contained in:
Ingo Weyrich 2020-06-19 17:07:49 +02:00
parent 09fab8de0e
commit e89a3041fa
3 changed files with 32 additions and 4 deletions

View File

@ -84,6 +84,29 @@ eSensorType RawImage::getSensorType() const
*/
void RawImage::get_colorsCoeff(float *pre_mul_, float *scale_mul_, float *cblack_, bool forceAutoWB)
{
if (!pre_mul_ && !scale_mul_ && !forceAutoWB) {
// only black levels
if (isXtrans()) {
// for xtrans files dcraw stores black levels in cblack[6] .. cblack[41], but all are equal, so we just use cblack[6]
for (int c = 0; c < 4; c++) {
cblack_[c] = (float) this->get_cblack(6);
}
} else if ((this->get_cblack(4) + 1) / 2 == 1 && (this->get_cblack(5) + 1) / 2 == 1) {
for (int c = 0; c < 4; c++) {
cblack_[c] = this->get_cblack(c);
}
for (int c = 0; c < 4; c++) {
cblack_[FC(c / 2, c % 2)] = this->get_cblack(6 + c / 2 % this->get_cblack(4) * this->get_cblack(5) + c % 2 % this->get_cblack(5));
}
} else {
for (int c = 0; c < 4; c++) {
cblack_[c] = (float) this->get_cblack(c);
}
}
return;
}
unsigned sum[8], c;
unsigned W = this->get_width();
unsigned H = this->get_height();

View File

@ -259,6 +259,10 @@ public:
{
return float_raw_image;
}
void set_filters(unsigned f)
{
filters = f;
}
public:
// dcraw functions

View File

@ -2400,10 +2400,11 @@ void RawImageSource::HLRecovery_Global(const ToneCurveParams &hrp)
*/
void RawImageSource::copyOriginalPixels(const RAWParams &raw, RawImage *src, RawImage *riDark, RawImage *riFlatFile, array2D<float> &rawData)
{
const float black[4] = {
static_cast<float>(ri->get_cblack(0)), static_cast<float>(ri->get_cblack(1)),
static_cast<float>(ri->get_cblack(2)), static_cast<float>(ri->get_cblack(3))
};
const auto tmpfilters = ri->get_filters();
ri->set_filters(ri->prefilters); // we need 4 blacks for bayer processing
float black[4];
ri->get_colorsCoeff(nullptr, nullptr, black, false);
ri->set_filters(tmpfilters);
if (ri->getSensorType() == ST_BAYER || ri->getSensorType() == ST_FUJI_XTRANS) {
if (!rawData) {