Skip to content

Demosaiced floating point DNGs #7264

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 43 additions & 3 deletions rtengine/rawimage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ int RawImage::loadRaw(bool loadData, unsigned int imageNum, bool closeFile, Prog
{
ifname = filename.c_str();
image = nullptr;
image_from_float.reset();
verbose = settings->verbose;
oprof = nullptr;

Expand Down Expand Up @@ -531,7 +532,7 @@ int RawImage::loadRaw(bool loadData, unsigned int imageNum, bool closeFile, Prog
} else if (err != LIBRAW_SUCCESS) {
decoder = Decoder::LIBRAW;
return err;
} else if (libraw->is_floating_point() && libraw->imgdata.idata.dng_version) {
} else if (libraw->is_floating_point() && libraw->imgdata.idata.dng_version && libraw->imgdata.idata.filters) {
return err;
}

Expand Down Expand Up @@ -785,6 +786,7 @@ int RawImage::loadRaw(bool loadData, unsigned int imageNum, bool closeFile, Prog
(this->*load_raw)();
} else if (decoder == Decoder::LIBRAW) {
libraw->imgdata.rawparams.shot_select = shot_select;
libraw->imgdata.rawparams.options &= ~LIBRAW_RAWOPTIONS_CONVERTFLOAT_TO_INT;

int err = libraw->open_buffer(ifp->data, ifp->size);
if (err) {
Expand All @@ -810,6 +812,24 @@ int RawImage::loadRaw(bool loadData, unsigned int imageNum, bool closeFile, Prog
float_raw_image[idx] = rd.float_image[idx];
}
}
} else if (rd.float3_image) {
const auto image_size = static_cast<unsigned int>(height) * static_cast<unsigned int>(width);
try {
image_from_float.reset(new std::remove_pointer<dcrawImage_t>::type[image_size]);
} catch (const std::bad_alloc &e) {
return 200;
}
std::fill(&image_from_float[0][0], &image_from_float[0][0] + image_size, 0);

float_raw_image = new float[3 * raw_width * raw_height];
for (int y = 0; y < raw_height; ++y) {
for (int x = 0; x < raw_width; ++x) {
const size_t idx = y * raw_width + x;
for (int c = 0; c < 3; ++c) {
float_raw_image[3 * idx + c] = rd.float3_image[idx][c];
}
}
}
} else {
#ifdef LIBRAW_USE_OPENMP
MyMutex::MyLock lock(*librawMutex);
Expand Down Expand Up @@ -1101,9 +1121,14 @@ int RawImage::loadRaw(bool loadData, unsigned int imageNum, bool closeFile, Prog
return 0;
}

DCraw::dcrawImage_t RawImage::get_image()
{
return image ? image : image_from_float.get();
}

float** RawImage::compress_image(unsigned int frameNum, bool freeImage)
{
if (!image) {
if (!image && !image_from_float) {
return nullptr;
}

Expand Down Expand Up @@ -1139,7 +1164,7 @@ float** RawImage::compress_image(unsigned int frameNum, bool freeImage)
}

// copy pixel raw data: the compressed format earns space
if (float_raw_image) {
if (float_raw_image && filters) {
#ifdef _OPENMP
#pragma omp parallel for
#endif
Expand All @@ -1149,6 +1174,20 @@ float** RawImage::compress_image(unsigned int frameNum, bool freeImage)
this->data[row][col] = float_raw_image[(row + top_margin) * raw_width + col + left_margin];
}

delete [] float_raw_image;
float_raw_image = nullptr;
} else if (float_raw_image) {
#ifdef _OPENMP
#pragma omp parallel for
#endif

for (int row = 0; row < height; row++)
for (int col = 0; col < width; col++) {
for (int c = 0; c < 3; ++c) {
this->data[row][3 * col + c] = float_raw_image[3 * ((row + top_margin) * raw_width + col + left_margin) + c];
}
}

delete [] float_raw_image;
float_raw_image = nullptr;
} else if (merged_pixelshift.is_merged_pixelshift) {
Expand Down Expand Up @@ -1240,6 +1279,7 @@ float** RawImage::compress_image(unsigned int frameNum, bool freeImage)
libraw->recycle();
}
image = nullptr;
image_from_float.reset();
}

return data;
Expand Down
6 changes: 2 additions & 4 deletions rtengine/rawimage.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ class RawImage: public DCraw
filters &= ~((filters & 0x55555555) << 1);
}
}
dcrawImage_t get_image()
{
return image;
}
dcrawImage_t get_image();
float** compress_image(unsigned int frameNum, bool freeImage = true); // revert to compressed pixels format and release image data
float** data; // holds pixel values, data[i][j] corresponds to the ith row and jth column
unsigned prefilters; // original filters saved ( used for 4 color processing )
Expand All @@ -78,6 +75,7 @@ class RawImage: public DCraw
int maximum_c4[4];
Decoder decoder{Decoder::DCRAW};
std::unique_ptr<LibRaw> libraw;
std::unique_ptr<std::remove_pointer<dcrawImage_t>::type[]> image_from_float;
bool isFoveon() const
{
return is_foveon;
Expand Down
5 changes: 3 additions & 2 deletions rtengine/rtthumbnail.cc
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,14 @@ void scale_colors (rtengine::RawImage *ri, float scale_mul[4], float cblack[4],
}
}
} else if (isFloat) {
const auto colors = ri->get_colors();
#ifdef _OPENMP
#pragma omp parallel for if(multiThread)
#endif
for (int row = 0; row < height; ++row) {
for (int col = 0; col < width; ++col) {
for (int i = 0; i < ri->get_colors(); ++i) {
float val = float_raw_image[(row + top_margin) * raw_width + col + left_margin + i];
for (int i = 0; i < colors; ++i) {
float val = float_raw_image[colors * ((row + top_margin) * raw_width + col + left_margin) + i];
val -= cblack[i];
val *= scale_mul[i];
image[row * width + col][i] = val;
Expand Down
Loading