Jump to content
  • Advertisement
Sign in to follow this  
KevinLi

RGB-HSV use SSE

This topic is 3968 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
For starters you don't need floats, you can do it all with integer math. Secondly you don't want to rewrite the ConvertRGB2HSV() function, but instead rewrite the entire loop to make maximum use of SSE's parellization (eg. process 4 pixels at once instead of 1). I've never written any SSE though, so beyond that I can't be much help.

BTW, cross-posting the same question across multiple forums the way you have is frowned upon. Don't do it.

Share this post


Link to post
Share on other sites

This topic is 3968 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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!