Use Image16 instead of Imagefloat for CLUT

Gain speed and reduce memory by using Image16 instead of Imagefloat for
the CLUT.
This commit is contained in:
Flössie 2016-04-18 20:38:23 +02:00
parent e495093b18
commit f639cd6b82
3 changed files with 23 additions and 16 deletions

View File

@ -1,18 +1,22 @@
#include <algorithm>
#include "clutstore.h" #include "clutstore.h"
#include "rt_math.h"
#include "image16.h"
#include "imagefloat.h"
#include "stdimagesource.h" #include "stdimagesource.h"
#include "../rtgui/options.h" #include "../rtgui/options.h"
namespace namespace
{ {
std::unique_ptr<rtengine::Imagefloat> loadFile( std::unique_ptr<rtengine::Image16> loadFile(
const Glib::ustring& filename, const Glib::ustring& filename,
const Glib::ustring& working_color_space, const Glib::ustring& working_color_space,
unsigned int& clut_level unsigned int& clut_level
) )
{ {
std::unique_ptr<rtengine::Imagefloat> result; std::unique_ptr<rtengine::Image16> result;
rtengine::StdImageSource img_src; rtengine::StdImageSource img_src;
@ -38,17 +42,19 @@ std::unique_ptr<rtengine::Imagefloat> loadFile(
if (valid) { if (valid) {
rtengine::ColorTemp curr_wb = img_src.getWB(); rtengine::ColorTemp curr_wb = img_src.getWB();
result = std::unique_ptr<rtengine::Imagefloat>(new rtengine::Imagefloat(fw, fh)); std::unique_ptr<rtengine::Imagefloat> img_float = std::unique_ptr<rtengine::Imagefloat>(new rtengine::Imagefloat(fw, fh));
const PreviewProps pp(0, 0, fw, fh, 1); const PreviewProps pp(0, 0, fw, fh, 1);
rtengine::procparams::ColorManagementParams icm; rtengine::procparams::ColorManagementParams icm;
icm.working = working_color_space; icm.working = working_color_space;
img_src.getImage(curr_wb, TR_NONE, result.get(), pp, rtengine::procparams::ToneCurveParams(), icm, rtengine::procparams::RAWParams()); img_src.getImage(curr_wb, TR_NONE, img_float.get(), pp, rtengine::procparams::ToneCurveParams(), icm, rtengine::procparams::RAWParams());
if (!working_color_space.empty()) { if (!working_color_space.empty()) {
img_src.convertColorSpace(result.get(), icm, curr_wb); img_src.convertColorSpace(img_float.get(), icm, curr_wb);
} }
result = std::unique_ptr<rtengine::Image16>(img_float->to16());
} }
return result; return result;
@ -100,6 +106,8 @@ void rtengine::CLUT::splitClutFilename(
rtengine::HaldCLUT::HaldCLUT() : rtengine::HaldCLUT::HaldCLUT() :
clut_level(0), clut_level(0),
flevel_minus_one(0.0f),
flevel_minus_two(0.0f),
clut_profile("sRGB") clut_profile("sRGB")
{ {
} }
@ -116,6 +124,9 @@ bool rtengine::HaldCLUT::load(const Glib::ustring& filename)
if (clut_image) { if (clut_image) {
clut_filename = filename; clut_filename = filename;
clut_level *= clut_level;
flevel_minus_one = static_cast<float>(clut_level - 1) / 65535.0f;
flevel_minus_two = static_cast<float>(clut_level - 2);
return true; return true;
} }
@ -139,10 +150,7 @@ Glib::ustring rtengine::HaldCLUT::getProfile() const
void rtengine::HaldCLUT::getRGB(float r, float g, float b, float& out_r, float& out_g, float& out_b) const void rtengine::HaldCLUT::getRGB(float r, float g, float b, float& out_r, float& out_g, float& out_b) const
{ {
const unsigned int level = clut_level * clut_level; const unsigned int level = clut_level; // This is important
const float flevel_minus_one = static_cast<float>(level - 1) / 65535.0f;
const float flevel_minus_two = static_cast<float>(level - 2);
const unsigned int red = std::min(flevel_minus_two, r * flevel_minus_one); const unsigned int red = std::min(flevel_minus_two, r * flevel_minus_one);
const unsigned int green = std::min(flevel_minus_two, g * flevel_minus_one); const unsigned int green = std::min(flevel_minus_two, g * flevel_minus_one);

View File

@ -4,12 +4,13 @@
#include <gtkmm.h> #include <gtkmm.h>
#include "imagefloat.h"
#include "cache.h" #include "cache.h"
namespace rtengine namespace rtengine
{ {
class Image16;
class CLUT class CLUT
{ {
public: public:
@ -50,8 +51,10 @@ public:
void getRGB(float r, float g, float b, float& out_r, float& out_g, float& out_b) const; void getRGB(float r, float g, float b, float& out_r, float& out_g, float& out_b) const;
private: private:
std::unique_ptr<Imagefloat> clut_image; std::unique_ptr<Image16> clut_image;
unsigned int clut_level; unsigned int clut_level;
float flevel_minus_one;
float flevel_minus_two;
Glib::ustring clut_filename; Glib::ustring clut_filename;
Glib::ustring clut_profile; Glib::ustring clut_profile;
}; };

View File

@ -4337,8 +4337,6 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer
//Film Simulations //Film Simulations
if ( colorLUT ) { if ( colorLUT ) {
MyTime start, stop;
start.set();
for (int i = istart, ti = 0; i < tH; i++, ti++) { for (int i = istart, ti = 0; i < tH; i++, ti++) {
for (int j = jstart, tj = 0; j < tW; j++, tj++) { for (int j = jstart, tj = 0; j < tW; j++, tj++) {
float &sourceR = rtemp[ti * TS + tj]; float &sourceR = rtemp[ti * TS + tj];
@ -4377,8 +4375,6 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer
} }
} }
stop.set();
printf("Film simulation took %dus.\n", stop.etime(start));
} }