Floating point dng files in [0;1] range have black thumbnail, fixes #4669

This commit is contained in:
heckflosse
2018-07-07 16:09:37 +02:00
parent 523fe40662
commit 9224d6e18c
3 changed files with 37 additions and 30 deletions

View File

@@ -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) { 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 // 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 // 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 */ /* RT: removed unused functions */

View File

@@ -167,10 +167,22 @@ public:
{ {
return top_margin; return top_margin;
} }
int get_rawwidth() const
{
return raw_width;
}
int get_FujiWidth() const int get_FujiWidth() const
{ {
return fuji_width; return fuji_width;
} }
float const * get_FloatRawImage() const
{
return float_raw_image;
}
eSensorType getSensorType(); eSensorType getSensorType();
void getRgbCam (float rgbcam[3][4]); void getRgbCam (float rgbcam[3][4]);
@@ -312,6 +324,11 @@ public:
return filters == 9; return filters == 9;
} }
bool isFloat() const
{
return float_raw_image;
}
public: public:
// dcraw functions // dcraw functions
void pre_interpolate() void pre_interpolate()

View File

@@ -66,7 +66,11 @@ void scale_colors (rtengine::RawImage *ri, float scale_mul[4], float cblack[4],
if (ri->isBayer()) { if (ri->isBayer()) {
const int height = ri->get_iheight(); const int height = ri->get_iheight();
const int width = ri->get_iwidth(); 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 #ifdef _OPENMP
#pragma omp parallel for if(multiThread) #pragma omp parallel for if(multiThread)
#endif #endif
@@ -76,8 +80,15 @@ void scale_colors (rtengine::RawImage *ri, float scale_mul[4], float cblack[4],
int col = 0; int col = 0;
for (; col < width - 1; col += 2) { for (; col < width - 1; col += 2) {
float val0 = image[row * width + col][c0]; float val0;
float val1 = image[row * width + col + 1][c1]; 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]; val0 -= cblack[c0];
val1 -= cblack[c1]; val1 -= cblack[c1];
val0 *= scale_mul[c0]; 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 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 -= cblack[c0];
val0 *= scale_mul[c0]; val0 *= scale_mul[c0];
image[row * width + col][c0] = rtengine::CLIP (val0); image[row * width + col][c0] = rtengine::CLIP (val0);