Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Well in debug version, but not in release version [Updated] [modified]

Well in debug version, but not in release version [Updated] [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
announcementdebugginghelpquestion
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    followait
    wrote on last edited by
    #1

    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

    M 1 Reply Last reply
    0
    • F followait

      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

      M Offline
      M Offline
      Mr Surprise
      wrote on last edited by
      #2

      So what is the difference while compile (or executable) in kind of two mode?

      F 2 Replies Last reply
      0
      • M Mr Surprise

        So what is the difference while compile (or executable) in kind of two mode?

        F Offline
        F Offline
        followait
        wrote on last edited by
        #3

        I don't known in detail. I'm finding a quick answer. :)

        1 Reply Last reply
        0
        • M Mr Surprise

          So what is the difference while compile (or executable) in kind of two mode?

          F Offline
          F Offline
          followait
          wrote on last edited by
          #4

          I chnaged the way of equality comparison from S==0.f to S>-0.000001f && S<0.000001f It seems ok, and must be faster than using "/Op" or pragma optimize("p",on)

          M 1 Reply Last reply
          0
          • F followait

            I chnaged the way of equality comparison from S==0.f to S>-0.000001f && S<0.000001f It seems ok, and must be faster than using "/Op" or pragma optimize("p",on)

            M Offline
            M Offline
            Mr Surprise
            wrote on last edited by
            #5

            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

            F 1 Reply Last reply
            0
            • M Mr Surprise

              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

              F Offline
              F Offline
              followait
              wrote on last edited by
              #6

              Fine, another good choice.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups