RGB-HSV use SSE

Started by
0 comments, last by joanusdmentia 16 years, 9 months ago

__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!
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.
"Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of Fate. This visage, no mere veneer of vanity, is a vestige of the vox populi, now vacant, vanished. However, this valorous visitation of a bygone vexation stands vivified, and has vowed to vanquish these venal and virulent vermin vanguarding vice and vouchsafing the violently vicious and voracious violation of volition. The only verdict is vengeance; a vendetta held as a votive, not in vain, for the value and veracity of such shall one day vindicate the vigilant and the virtuous. Verily, this vichyssoise of verbiage veers most verbose, so let me simply add that it's my very good honor to meet you and you may call me V.".....V

This topic is closed to new replies.

Advertisement