Well in debug version, but not in release version [Updated] [modified]
-
Updated: I add /Op as a compiler option for release version, it's ok. It quite likes a comparing inaccuracy problem. Try tomorrow... zzzzzz ----------------------- I use these functions to change the lum of an rgb color. The debug version and release versions have different result. Why? Thanks.
void RGB2HSL(COLORREF rgb,REAL *pH,REAL *pS,REAL *pL)
{
REAL var_R=REAL(GetRValue(rgb))/255.f;
REAL var_G=REAL(GetGValue(rgb))/255.f;
REAL var_B=REAL(GetBValue(rgb))/255.f;
REAL var_min=min(var_R,var_G);
var_min=min(var_min,var_B);
REAL var_max=max(var_R,var_G);
var_max=max(var_max,var_B);
REAL delta_max=var_max-var_min;\*pL=(var\_max+var\_min)\*0.5f; if (delta\_max==0.f) { \*pH=0.f; \*pS=0.f; } else { if (\*pL<0.5f) \*pS=delta\_max/(var\_max+var\_min); else \*pS=delta\_max/(2.f-var\_max-var\_min); REAL delta\_R=(((var\_max-var\_R)/6.f)+(delta\_max\*0.5f))/delta\_max; REAL delta\_G=(((var\_max-var\_G)/6.f)+(delta\_max\*0.5f))/delta\_max; REAL delta\_B=(((var\_max-var\_B)/6.f)+(delta\_max\*0.5f))/delta\_max; if (var\_R==var\_max) \*pH=delta\_B-delta\_G; else if (var\_G==var\_max) \*pH=(1.f/3.f)+delta\_R-delta\_B; else if (var\_B==var\_max) \*pH=(2.f/3.f)+delta\_G-delta\_R; if (\*pH<0.f) ++\*pH; if (\*pH>1.f) --\*pH; }
}
inline REAL Hue_2_RGB(REAL v1,REAL v2,REAL vH)
{
if(vH<0.f)
++vH;
if(vH>1.f)
--vH;
if((vH*6.f)<1.f)
return(v1+(v2-v1)*vH*6.f);
if((vH*2.f)<1.f)
return(v2);
if((vH*3.f)<2.f)
return(v1+(v2-v1)*((2.f/3.f)-vH)*6.f);
return(v1);
}void HSL2RGB(REAL H,REAL S,REAL L,COLORREF &rgb)
{
REAL R,G,B;
if (S==0.f) {
R=L*255.f;
G=L*255.f;
B=L*255.f;
} else {
REAL var_1,var_2;
if (L<0.5f)
var_2=L*(1.f+S);
else
var_2=(L+S)-(S*L);
var_1=L*2.f-var_2;
R=Hue_2_RGB(var_1,var_2,H+(1.f/3.f))*255.f;
G=Hue_2_RGB(var_1,var_2,H)*255.f;
B=Hue_2_RGB(var_1,var_2,H-(1.f/3.f))*255.f;
}
rgb=RGB(R,G,B);
}modified on Saturday, February 02, 2008 1:02:11 PM
-
Updated: I add /Op as a compiler option for release version, it's ok. It quite likes a comparing inaccuracy problem. Try tomorrow... zzzzzz ----------------------- I use these functions to change the lum of an rgb color. The debug version and release versions have different result. Why? Thanks.
void RGB2HSL(COLORREF rgb,REAL *pH,REAL *pS,REAL *pL)
{
REAL var_R=REAL(GetRValue(rgb))/255.f;
REAL var_G=REAL(GetGValue(rgb))/255.f;
REAL var_B=REAL(GetBValue(rgb))/255.f;
REAL var_min=min(var_R,var_G);
var_min=min(var_min,var_B);
REAL var_max=max(var_R,var_G);
var_max=max(var_max,var_B);
REAL delta_max=var_max-var_min;\*pL=(var\_max+var\_min)\*0.5f; if (delta\_max==0.f) { \*pH=0.f; \*pS=0.f; } else { if (\*pL<0.5f) \*pS=delta\_max/(var\_max+var\_min); else \*pS=delta\_max/(2.f-var\_max-var\_min); REAL delta\_R=(((var\_max-var\_R)/6.f)+(delta\_max\*0.5f))/delta\_max; REAL delta\_G=(((var\_max-var\_G)/6.f)+(delta\_max\*0.5f))/delta\_max; REAL delta\_B=(((var\_max-var\_B)/6.f)+(delta\_max\*0.5f))/delta\_max; if (var\_R==var\_max) \*pH=delta\_B-delta\_G; else if (var\_G==var\_max) \*pH=(1.f/3.f)+delta\_R-delta\_B; else if (var\_B==var\_max) \*pH=(2.f/3.f)+delta\_G-delta\_R; if (\*pH<0.f) ++\*pH; if (\*pH>1.f) --\*pH; }
}
inline REAL Hue_2_RGB(REAL v1,REAL v2,REAL vH)
{
if(vH<0.f)
++vH;
if(vH>1.f)
--vH;
if((vH*6.f)<1.f)
return(v1+(v2-v1)*vH*6.f);
if((vH*2.f)<1.f)
return(v2);
if((vH*3.f)<2.f)
return(v1+(v2-v1)*((2.f/3.f)-vH)*6.f);
return(v1);
}void HSL2RGB(REAL H,REAL S,REAL L,COLORREF &rgb)
{
REAL R,G,B;
if (S==0.f) {
R=L*255.f;
G=L*255.f;
B=L*255.f;
} else {
REAL var_1,var_2;
if (L<0.5f)
var_2=L*(1.f+S);
else
var_2=(L+S)-(S*L);
var_1=L*2.f-var_2;
R=Hue_2_RGB(var_1,var_2,H+(1.f/3.f))*255.f;
G=Hue_2_RGB(var_1,var_2,H)*255.f;
B=Hue_2_RGB(var_1,var_2,H-(1.f/3.f))*255.f;
}
rgb=RGB(R,G,B);
}modified on Saturday, February 02, 2008 1:02:11 PM
So what is the difference while compile (or executable) in kind of two mode?
-
So what is the difference while compile (or executable) in kind of two mode?
-
So what is the difference while compile (or executable) in kind of two mode?
-
I chnaged the way of equality comparison from
S==0.f
toS>-0.000001f && S<0.000001f
It seems ok, and must be faster than using"/Op"
orpragma optimize("p",on)
I'm not complete sure on what is the problem because i never worked before on such like works-area just as go deeply into it. You might use to the
#ifdef
statement at this like condition.#ifdef _DEBUG #pragma optimize("p", on or off
-
I'm not complete sure on what is the problem because i never worked before on such like works-area just as go deeply into it. You might use to the
#ifdef
statement at this like condition.#ifdef _DEBUG #pragma optimize("p", on or off