Jump to content
  • Advertisement
Sign in to follow this  
KevinLi

RGB-HSV use SSE

This topic is 4022 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

__inline void ConvertRGB2HSV(
unsigned char sR,unsigned char sG,unsigned char sB,int *dH,int *dS,int *dV)
{
      float fTemp,fDelta;
      int nMin,nMax;
      nMin = min( sR, min( sG, sB ));
      nMax = max( sR, max( sG, sB ));
      fDelta = nMax - nMin;
      *dV = nMax;
      if(nMax == nMin)
             *dH = *dS = 0;
      else
      {
             fTemp = fDelta / nMax;
             *dS= (int) (fTemp * 255);
             if(sR == nMax)
                   fTemp = (float)(sG - sB) / fDelta;
             else if(sG == nMax)
                   fTemp = 2.0 + ((float)(sB - sR) / fDelta);
             else
                   fTemp = 4.0 + ((float)(sR - sG) / fDelta);
             fTemp *= 60;
             if(fTemp < 0)
                   fTemp += 360;
             if(fTemp == 360)
                   fTemp = 0;
             *dH = (int)fTemp;
      }
}

unsinged char sR,sG,sB;
int dH,dS,dV;
int nMaxH,nMinH,nMaxS,nMinS,nMaxV,nMinV;
nMaxH = nMaxS = nMaxV = 0;
nMinH = nMinS = nMinV = 360;
RGBTRIPLE *pPixel = (RGBTRIPLE *)pSourceBuffer;
//for(int j = 0; j < 576; j++)
//for(int i = 0; i < 768; i++)
int i=0;
while(i++ < 768 * 576)
{
      sR = pPixel->rgbtRed;
      sG = pPixel->rgbtGreen;
      sB = pPixel->rgbtBlue;
      ConvertRGB2HSV( sR, sG, sB, &dH, &dS, &dV);
      if( dH > nMaxH)
            nMaxH = dH;
      if( dH < nMinH)
            nMinH = dH;
      if( dS > nMaxS)
            nMaxS = dS;
      if( dS < nMinS)
            nMinS = dS;
      if( dV > nMaxV)
            nMaxV = dV;
      if( dV < nMinV)
            nMinV = dV;
      pPixel++;
}
ConvertRGB2HSV(...) is too slow.I want to rewrite this function (or the all code)using SSE (C++ code with inline Assembly ,like as: _asm{ movaps xmm1,xmm2 ... }) The compiler is VC6(SP5),support inline assembly with SSE instructions. I want to use SSE,Who can help me?Please!

Share this post


Link to post
Share on other sites
Advertisement

This topic is 4022 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!