127
127
memcpy(tmp, matrix, sizeof(float)*9);
128
128
if(mat3inv (matrix, tmp)) return 3;
129
129
// also need to reverse gamma, to apply reverse before matrix multiplication:
130
cmsToneCurve* rev_red = cmsReverseToneCurveEx(0xffff, red_curve);
131
cmsToneCurve* rev_green = cmsReverseToneCurveEx(0xffff, green_curve);
132
cmsToneCurve* rev_blue = cmsReverseToneCurveEx(0xffff, blue_curve);
130
cmsToneCurve* rev_red = cmsReverseToneCurveEx(0x8000, red_curve);
131
cmsToneCurve* rev_green = cmsReverseToneCurveEx(0x8000, green_curve);
132
cmsToneCurve* rev_blue = cmsReverseToneCurveEx(0x8000, blue_curve);
133
133
if(!rev_red || !rev_green || !rev_blue)
135
135
cmsFreeToneCurve(rev_red);
618
618
if(sqlite3_step(stmt) == SQLITE_ROW)
620
620
params = sqlite3_column_blob(stmt, 0);
621
strncpy(profile, params->iccprofile, 1024);
621
g_strlcpy(profile, params->iccprofile, 1024);
623
623
sqlite3_finalize(stmt);
625
625
if(!overprofile && profile[0] == '\0')
626
strncpy(profile, "sRGB", 1024);
627
if(profile[0] == '\0')
628
strncpy(profile, overprofile, 1024);
627
g_strlcpy(profile, "sRGB", 1024);
629
else if(profile[0] == '\0')
631
g_strlcpy(profile, overprofile, 1024);
631
639
cmsHPROFILE output = NULL;
671
677
for(int k=0; k<3; k++) mat[c][j] += rgb_to_xyz[c][k]*cmatrix[k][j];
679
return dt_colorspaces_create_xyzmatrix_profile(mat);
683
dt_colorspaces_create_xyzimatrix_profile(float mat[3][3])
687
mat3inv ((float *)imat, (float *)mat);
688
return dt_colorspaces_create_xyzmatrix_profile(imat);
692
dt_colorspaces_create_xyzmatrix_profile(float mat[3][3])
673
697
for(int k=0; k<3; k++)
675
699
const float norm = mat[0][k] + mat[1][k] + mat[2][k];
742
766
for(e=makermodel; c<maker+strlen(maker) && *c != ' '; c++,e++) *e = *c;
743
767
// separate with space
745
// and continue with model:
746
snprintf(e, size - (d-maker), "%s", model);
769
// and continue with model.
770
// replace MAXXUM with DYNAX for wb presets.
771
if(!strcmp(maker, "MINOLTA") && !strncmp(model, "MAXXUM", 6))
772
snprintf(e, size - (d-maker), "DYNAX %s", model+7);
773
else snprintf(e, size - (d-maker), "%s", model);
748
775
// strip trailing spaces
749
776
e = makermodel + strlen(makermodel) - 1;
764
void rgb2hsl(float r,float g,float b,float *h,float *s,float *l)
791
void rgb2hsl(const float rgb[3],float *h,float *s,float *l)
793
const float r=rgb[0], g=rgb[1], b=rgb[2];
766
794
float pmax=fmax(r,fmax(g,b));
767
795
float pmin=fmin(r,fmin(g,b));
768
796
float delta=(pmax-pmin);
798
float hv=0,sv=0,lv=(pmin+pmax)/2.0;
775
*s=*l<0.5?delta/(pmax+pmin):delta/(2.0-pmax-pmin);
802
sv=lv<0.5?delta/(pmax+pmin):delta/(2.0-pmax-pmin);
777
if(pmax==r) *h=(g-b)/delta;
778
if(pmax==g) *h=2.0+(b-r)/delta;
779
if(pmax==b) *h=4.0+(r-g)/delta;
782
else if(*h>1.0) *h-=1.0;
804
if(pmax==r) hv=(g-b)/delta;
805
else if(pmax==g) hv=2.0+(b-r)/delta;
806
else if(pmax==b) hv=4.0+(r-g)/delta;
809
else if(hv>1.0) hv-=1.0;
786
void hue2rgb(float m1,float m2,float hue,float *channel)
816
static inline float hue2rgb(float m1,float m2,float hue)
788
818
if(hue<0.0) hue+=1.0;
789
819
else if(hue>1.0) hue-=1.0;
791
if( (6.0*hue) < 1.0) *channel=(m1+(m2-m1)*hue*6.0);
792
else if((2.0*hue) < 1.0) *channel=m2;
793
else if((3.0*hue) < 2.0) *channel=(m1+(m2-m1)*((2.0/3.0)-hue)*6.0);
821
if( hue < 1.0/6.0) return (m1+(m2-m1)*hue*6.0);
822
else if(hue < 1.0/2.0) return m2;
823
else if(hue < 2.0/3.0) return (m1+(m2-m1)*((2.0/3.0)-hue)*6.0);
797
void hsl2rgb(float *r,float *g,float *b,float h,float s,float l)
827
void hsl2rgb(float rgb[3],float h,float s,float l)
831
rgb[0]=rgb[1]=rgb[2]=l;
802
834
m2=l<0.5?l*(1.0+s):l+s-l*s;
804
hue2rgb(m1,m2,h +(1.0/3.0), r);
806
hue2rgb(m1,m2,h - (1.0/3.0), b);
836
rgb[0] = hue2rgb(m1,m2,h + (1.0/3.0));
837
rgb[1] = hue2rgb(m1,m2,h);
838
rgb[2] = hue2rgb(m1,m2,h - (1.0/3.0));
842
// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-space on;