Board index » cppbuilder » Fastest way to retrieve RGB values from a pixel.
Star
![]() CBuilder Developer |
Star
![]() CBuilder Developer |
Fastest way to retrieve RGB values from a pixel.2004-01-22 04:24:07 AM cppbuilder11 Hi, I was using ScanLine to get these values. Something like this: Byte *ptr ptr = (Byte *)pBitmap->ScanLine[y]; // RGB values are stored here: ptr[3*x+0] ptr[3*x+1] ptr[3*x+2] However, I need something faster. I've read that you can use DIB to do that. Would it be faster? Anyone has any example to do the same using DIBs? Thanks |
Hans Galema
![]() CBuilder Developer |
2004-01-22 05:46:13 AM
Re:Fastest way to retrieve RGB values from a pixel.
Star wrote:
Quote// RGB values are stored here: much longer than additions. You could begin with bringing back the multiplications to one. But yet better get rid of all multiplications. int X = 3*x-1; now the RGB values are stored in: ptr[++X] ptr[++X] ptr[++X] Hans. |
Star
![]() CBuilder Developer |
2004-01-22 06:02:52 AM
Re:Fastest way to retrieve RGB values from a pixel.QuoteWhat we see here are three multiplications. Multiplications take This code processes the whole image. for (int y = 0; y < pBitmap->Height; y++) { ptr = (Byte *)pBitmap->ScanLine[y]; x=0; while ( x< pBitmap->Width ) { nRGB1 = ptr[3*x+0] ; nRGB2 = ptr[3*x+1] ; nRGB3 = ptr[3*x+2] ; x++; } } What I would like to know if using DIBs would be faster than this method. Thanks {smallsort} |
Hans Galema
![]() CBuilder Developer |
2004-01-22 06:41:20 AM
Re:Fastest way to retrieve RGB values from a pixel.
Star wrote:
QuoteWhat I would like to know if using DIBs would be faster than this method. |
Star
![]() CBuilder Developer |
2004-01-22 11:47:28 AM
Re:Fastest way to retrieve RGB values from a pixel.QuoteSorry, I have no experience with doing that with DIBs. |
Michel Leunen
![]() CBuilder Developer |
2004-01-22 04:06:50 PM
Re:Fastest way to retrieve RGB values from a pixel.
Star wrote:
QuoteI've read that you can use DIB to do that. individual bits and then convert the DIB back to a bitmap. You can see that article here: www.leunen.com/cbuilder/rotbmp.html HTH Michel -- ---------------------------------------- Michel Leunen mailto: XXXX@XXXXX.COM C++Builder, C++BuilderX, BCC5.5.1 Web site: www.leunen.com/ ---------------------------------------- |
Star
![]() CBuilder Developer |
2004-01-22 11:18:34 PM
Re:Fastest way to retrieve RGB values from a pixel.
Thanks, Michel! I'll take a look.
|
Cagatay Undeger
![]() CBuilder Developer |
2004-01-29 03:37:07 AM
Re:Fastest way to retrieve RGB values from a pixel.
Indeed I don't think DIB will be much faster than the following code unless
DIB is supported by the hardware. first of all don't use such an access (pBitmap->Width) inside a loop. pBitmap->PixelFormat = pf24bit; int lastpixel; int height = pBitmap->Height; int width = pBitmap->Width; int width3 = width*3; unsigned char * buffer; for (int y = 0; y<height; y++) { buffer = (unsigned char *)pBitmap->ScanLine[y]; lastpixel = buffer + width3; while ( buffer<lastpixel ) { r = buffer++; g = buffer++; b = buffer++; } } Cagatay "Star" < XXXX@XXXXX.COM >wrote in message Quote>What we see here are three multiplications. Multiplications take |
Harold Howe [TeamB]
![]() CBuilder Developer |
2004-02-10 01:51:06 AM
Re:Fastest way to retrieve RGB values from a pixel.QuoteByte *ptr for(int y=0; y<height; ++y) { RGBTRIPLE *rgb = (RGBTRIPLE *)pBitmap->ScanLine[y]; for (int x=0; x<width; ++x) { rgb[x].rgbtRed = ... rgb[x].rgbtGreen = ... rgb[x].rgbtBlue = ... } } or for(int y=0; y<height; ++y) { RGBTRIPLE *rgb = (RGBTRIPLE *)pBitmap->ScanLine[y]; for (int x=0; x<width; ++x, ++rgb) { rgb->rgbtRed = ... rgb->rgbtGreen = ... rgb->rgbtBlue = ... } } One advantage of the RGBTRIPLE structure is that you can copy an entire pixel easily. rgb[0] = rgb[1]; h^2 |