Centralization and optimization of f2xyz function; see (end of) issue #630

This commit is contained in:
Oliver Duis
2011-04-29 19:46:16 +02:00
parent 841fc32e3c
commit 68c1a27f4d
4 changed files with 29 additions and 43 deletions

View File

@@ -75,14 +75,6 @@ namespace rtengine {
#define kappa 903.29630 //24389.0/27.0;
//%%%%%%%%%%%%
#define epsilon 0.00885645 //216/24389
#define kappainv 0.00110706 //inverse of kappa
#define kapeps 8 // kappa*epsilon
#define f2xyz(f) (( (g=f*f*f) > epsilon) ? g : (116*f-16)*kappainv)
//%%%%%%%%%%%%
extern const Settings* settings;
LUTf ImProcFunctions::cachef ;

View File

@@ -132,6 +132,13 @@ class ImProcFunctions {
//void gamutmap(LabImage* );
void gamutmap(float &X, float &Y, float &Z, const double p[3][3]);
static inline float f2xyz(register float f) {
const float epsilonExpInv3 = 6.0/29.0;
const float kappaInv = 27.0/24389.0; // inverse of kappa
return (f > epsilonExpInv3) ? f*f*f : (116 * f - 16) * kappaInv;
}
};
}
#endif

View File

@@ -39,11 +39,6 @@ namespace rtengine {
#define CLIPTO(a,b,c) ((a)>(b)?((a)<(c)?(a):(c)):(b))
#define CLIP01(a) ((a)>0?((a)<1?(a):1):0)
#define epsilon 0.00885645 //216/24389
#define kappa 903.2963 //24389/27
#define kappainv 0.00110706 //inverse of kappa
#define kapeps 8 // kappa*epsilon
#define Lab2xyz(f) (( (g=f*f*f) > epsilon) ? g : (116*f-16)*kappainv)
#define D50x 0.96422
#define D50z 0.82521
@@ -83,9 +78,9 @@ void ImProcFunctions::lab2rgb (LabImage* lab, Image8* image) {
fx = (0.002 * ra[j]) / 327.68 + fy;
fz = fy - (0.005 * rb[j]) / 327.68;
x_ = Lab2xyz(fx)*D50x;//should this be 32767??? buffer is short int !!!
y_ = Lab2xyz(fy);
z_ = Lab2xyz(fz)*D50z;
x_ = f2xyz(fx)*D50x;//should this be 32767??? buffer is short int !!!
y_ = f2xyz(fy);
z_ = f2xyz(fz)*D50z;
buffer[iy++] = CLIP01(x_);
buffer[iy++] = CLIP01(y_);
@@ -118,9 +113,9 @@ void ImProcFunctions::lab2rgb (LabImage* lab, Image8* image) {
fx = (0.002 * ra[j]) / 327.68 + fy;
fz = fy - (0.005 * rb[j]) / 327.68;
x_ = 65535.0*Lab2xyz(fx)*D50x;
y_ = 65535.0*Lab2xyz(fy);
z_ = 65535.0*Lab2xyz(fz)*D50z;
x_ = 65535.0 * f2xyz(fx)*D50x;
y_ = 65535.0 * f2xyz(fy);
z_ = 65535.0 * f2xyz(fz)*D50z;
xyz2srgb(x_,y_,z_,R,G,B);
@@ -175,9 +170,9 @@ Image8* ImProcFunctions::lab2rgb (LabImage* lab, int cx, int cy, int cw, int ch,
float fx = (0.002 * ra[j])/327.68 + fy;
float fz = fy - (0.005 * rb[j])/327.68;
float x_ = 65535.0*Lab2xyz(fx)*D50x;
float y_ = 65535.0*Lab2xyz(fy);
float z_ = 65535.0*Lab2xyz(fz)*D50z;
float x_ = 65535.0 * f2xyz(fx)*D50x;
float y_ = 65535.0 * f2xyz(fy);
float z_ = 65535.0 * f2xyz(fz)*D50z;
buffer[iy++] = CLIP((int)x_);
buffer[iy++] = CLIP((int)y_);
@@ -218,9 +213,9 @@ Image8* ImProcFunctions::lab2rgb (LabImage* lab, int cx, int cy, int cw, int ch,
float fx = (0.002 * ra[j])/327.68 + fy;
float fz = fy - (0.005 * rb[j])/327.68;
float x_ = 65535.0*Lab2xyz(fx)*D50x;
float y_ = 65535.0*Lab2xyz(fy);
float z_ = 65535.0*Lab2xyz(fz)*D50z;
float x_ = 65535.0 * f2xyz(fx)*D50x;
float y_ = 65535.0 * f2xyz(fy);
float z_ = 65535.0 * f2xyz(fz)*D50z;
xyz2rgb(x_,y_,z_,R,G,B,rgb_xyz);
@@ -262,9 +257,9 @@ Image16* ImProcFunctions::lab2rgb16 (LabImage* lab, int cx, int cy, int cw, int
float fx = (0.002 * ra[j])/327.68 + fy;
float fz = fy - (0.005 * rb[j])/327.68;
float x_ = 65535.0*Lab2xyz(fx)*D50x;
float y_ = 65535.0*Lab2xyz(fy);
float z_ = 65535.0*Lab2xyz(fz)*D50z;
float x_ = 65535.0 * f2xyz(fx)*D50x;
float y_ = 65535.0 * f2xyz(fy);
float z_ = 65535.0 * f2xyz(fz)*D50z;
xa[j-cx] = CLIP((int)x_);
ya[j-cx] = CLIP((int)y_);
@@ -293,9 +288,9 @@ Image16* ImProcFunctions::lab2rgb16 (LabImage* lab, int cx, int cy, int cw, int
float fx = (0.002 * ra[j])/327.68 + fy;
float fz = fy - (0.005 * rb[j])/327.68;
float x_ = 65535.0*Lab2xyz(fx)*D50x;
float y_ = 65535.0*Lab2xyz(fy);
float z_ = 65535.0*Lab2xyz(fz)*D50z;
float x_ = 65535.0 * f2xyz(fx)*D50x;
float y_ = 65535.0 * f2xyz(fy);
float z_ = 65535.0 * f2xyz(fz)*D50z;
xyz2srgb(x_,y_,z_,R,G,B);

View File

@@ -68,13 +68,6 @@ PIX_SORT(p[4],p[7]); PIX_SORT(p[4],p[2]); PIX_SORT(p[6],p[4]); \
PIX_SORT(p[4],p[2]); median=p[4];} //a4 is the median
//%%%%%%%%%%%%
#define epsilon 0.00885645 //216/24389
#define kappainv 0.00110706 //inverse of kappa
#define kapeps 8 // kappa*epsilon
#define f2xyz(f) (( (g=f*f*f) > epsilon) ? g : (116*f-16)*kappainv)
//%%%%%%%%%%%%
RawImageSource::RawImageSource ()
:ImageSource()
@@ -1824,11 +1817,10 @@ void RawImageSource::HLRecovery_CIELab (float* rin, float* gin, float* bin, floa
// convert back to rgb
double fz = fy - y + z;
double fx = fy + x - y;
// again shouldn't this be a universal, centrally defined function???
double zr = f2xyz(fz);
double xr = f2xyz(fx);
//double zr = (fz<=0.206893) ? ((116.0*fz-16.0)/903.3) : (fz * fz * fz);
//double xr = (fx<=0.206893) ? ((116.0*fx-16.0)/903.3) : (fx * fx * fx);
double zr = ImProcFunctions::f2xyz(fz);
double xr = ImProcFunctions::f2xyz(fx);
x = xr*65535.0 ;
y = yy;
z = zr*65535.0 ;