Merge pull request #4670 from Beep6581/float_dng_range_0_1
Floating point dng files in [0;1] range have black thumbnail
This commit is contained in:
commit
d9cab1f553
@ -10043,29 +10043,6 @@ static void expandFloats(Bytef * dst, int tileWidth, int bytesps) {
|
||||
}
|
||||
}
|
||||
|
||||
static void copyFloatDataToInt(float * src, ushort * dst, size_t size, float max) {
|
||||
bool negative = false, nan = false;
|
||||
|
||||
#ifdef _OPENMP
|
||||
#pragma omp parallel for
|
||||
#endif
|
||||
for (size_t i = 0; i < size; ++i) {
|
||||
if (src[i] < 0.0f) {
|
||||
negative = true;
|
||||
src[i] = 0.0f;
|
||||
} else if (std::isnan(src[i])) {
|
||||
nan = true;
|
||||
src[i] = max;
|
||||
}
|
||||
// Copy the data to the integer buffer to build the thumbnail
|
||||
dst[i] = (ushort)src[i];
|
||||
}
|
||||
if (negative)
|
||||
fprintf(stderr, "DNG Float: Negative data found in input file\n");
|
||||
if (nan)
|
||||
fprintf(stderr, "DNG Float: NaN data found in input file\n");
|
||||
}
|
||||
|
||||
static int decompress(size_t srcLen, size_t dstLen, unsigned char *in, unsigned char *out) {
|
||||
// At least in zlib 1.2.11 the uncompress function is not thread save while it is thread save in zlib 1.2.8
|
||||
// This simple replacement is thread save. Used example code from https://zlib.net/zlib_how.html
|
||||
@ -10207,9 +10184,6 @@ void CLASS deflate_dng_load_raw() {
|
||||
}
|
||||
}
|
||||
|
||||
if (ifd->sample_format == 3) { // Floating point data
|
||||
copyFloatDataToInt(float_raw_image, raw_image, raw_width*raw_height, maximum);
|
||||
}
|
||||
}
|
||||
|
||||
/* RT: removed unused functions */
|
||||
|
@ -167,10 +167,22 @@ public:
|
||||
{
|
||||
return top_margin;
|
||||
}
|
||||
|
||||
int get_rawwidth() const
|
||||
{
|
||||
return raw_width;
|
||||
}
|
||||
|
||||
int get_FujiWidth() const
|
||||
{
|
||||
return fuji_width;
|
||||
}
|
||||
|
||||
float const * get_FloatRawImage() const
|
||||
{
|
||||
return float_raw_image;
|
||||
}
|
||||
|
||||
eSensorType getSensorType();
|
||||
|
||||
void getRgbCam (float rgbcam[3][4]);
|
||||
@ -312,6 +324,11 @@ public:
|
||||
return filters == 9;
|
||||
}
|
||||
|
||||
bool isFloat() const
|
||||
{
|
||||
return float_raw_image;
|
||||
}
|
||||
|
||||
public:
|
||||
// dcraw functions
|
||||
void pre_interpolate()
|
||||
|
@ -66,7 +66,11 @@ void scale_colors (rtengine::RawImage *ri, float scale_mul[4], float cblack[4],
|
||||
if (ri->isBayer()) {
|
||||
const int height = ri->get_iheight();
|
||||
const int width = ri->get_iwidth();
|
||||
|
||||
const bool isFloat = ri->isFloat();
|
||||
const int top_margin = ri->get_topmargin();
|
||||
const int left_margin = ri->get_leftmargin();
|
||||
const int raw_width = ri->get_rawwidth();
|
||||
const float * const float_raw_image = ri->get_FloatRawImage();
|
||||
#ifdef _OPENMP
|
||||
#pragma omp parallel for if(multiThread)
|
||||
#endif
|
||||
@ -76,8 +80,15 @@ void scale_colors (rtengine::RawImage *ri, float scale_mul[4], float cblack[4],
|
||||
int col = 0;
|
||||
|
||||
for (; col < width - 1; col += 2) {
|
||||
float val0 = image[row * width + col][c0];
|
||||
float val1 = image[row * width + col + 1][c1];
|
||||
float val0;
|
||||
float val1;
|
||||
if (isFloat) {
|
||||
val0 = float_raw_image[(row + top_margin) * raw_width + col + left_margin];
|
||||
val1 = float_raw_image[(row + top_margin) * raw_width + col + left_margin + 1];
|
||||
} else {
|
||||
val0 = image[row * width + col][c0];
|
||||
val1 = image[row * width + col + 1][c1];
|
||||
}
|
||||
val0 -= cblack[c0];
|
||||
val1 -= cblack[c1];
|
||||
val0 *= scale_mul[c0];
|
||||
@ -87,7 +98,12 @@ void scale_colors (rtengine::RawImage *ri, float scale_mul[4], float cblack[4],
|
||||
}
|
||||
|
||||
if (col < width) { // in case width is odd
|
||||
float val0 = image[row * width + col][c0];
|
||||
float val0;
|
||||
if (isFloat) {
|
||||
val0 = float_raw_image[(row + top_margin) * raw_width + col + left_margin];
|
||||
} else {
|
||||
val0 = image[row * width + col][c0];
|
||||
}
|
||||
val0 -= cblack[c0];
|
||||
val0 *= scale_mul[c0];
|
||||
image[row * width + col][c0] = rtengine::CLIP (val0);
|
||||
@ -96,6 +112,11 @@ void scale_colors (rtengine::RawImage *ri, float scale_mul[4], float cblack[4],
|
||||
} else if (ri->isXtrans()) {
|
||||
const int height = ri->get_iheight();
|
||||
const int width = ri->get_iwidth();
|
||||
const bool isFloat = ri->isFloat();
|
||||
const int top_margin = ri->get_topmargin();
|
||||
const int left_margin = ri->get_leftmargin();
|
||||
const int raw_width = ri->get_rawwidth();
|
||||
const float * const float_raw_image = ri->get_FloatRawImage();
|
||||
|
||||
#ifdef _OPENMP
|
||||
#pragma omp parallel for if(multiThread)
|
||||
@ -111,7 +132,12 @@ void scale_colors (rtengine::RawImage *ri, float scale_mul[4], float cblack[4],
|
||||
for (; col < width - 5; col += 6) {
|
||||
for (int i = 0; i < 6; ++i) {
|
||||
const unsigned ccol = c[i];
|
||||
float val = image[row * width + col + i][ccol];
|
||||
float val;
|
||||
if (isFloat) {
|
||||
val = float_raw_image[(row + top_margin) * raw_width + col + i + left_margin];
|
||||
} else {
|
||||
val = image[row * width + col + i][ccol];
|
||||
}
|
||||
val -= cblack[ccol];
|
||||
val *= scale_mul[ccol];
|
||||
image[row * width + col + i][ccol] = rtengine::CLIP (val);
|
||||
@ -120,7 +146,12 @@ void scale_colors (rtengine::RawImage *ri, float scale_mul[4], float cblack[4],
|
||||
|
||||
for (; col < width; ++col) { // remaining columns
|
||||
const unsigned ccol = ri->XTRANSFC (row, col);
|
||||
float val = image[row * width + col][ccol];
|
||||
float val;
|
||||
if (isFloat) {
|
||||
val = float_raw_image[(row + top_margin) * raw_width + col + left_margin];
|
||||
} else {
|
||||
val = image[row * width + col][ccol];
|
||||
}
|
||||
val -= cblack[ccol];
|
||||
val *= scale_mul[ccol];
|
||||
image[row * width + col][ccol] = rtengine::CLIP (val);
|
||||
|
Loading…
x
Reference in New Issue
Block a user