0

I am acquiring images using a digital camera. At first, I was using a mono camera, but recently I upgraded to a color camera. With the mono camera I was having some palette issues until I found this bit of code to alter the palette to a grayscale palette:

for(int i=0; i<256; i++)
{
    pbmi->bmiColors[i].rgbRed = BYTE(i);
    pbmi->bmiColors[i].rgbGreen = BYTE(i);
    pbmi->bmiColors[i].rgbBlue = BYTE(i);
    pbmi->bmiColors[i].rgbReserved = BYTE(0);
}

where pbmi is a BITMAPINFO*.

This worked just fine for the mono camera. But now with the color camera I obviously don't want to make the images grayscale. However, if I remove that chunk of code I get the same palette issues that I was getting before with the mono camera. So it seems to me like I need to do something similar as I did before and create a palette, only this time a color palette.

For reference, here is the rest of the pbmi's settings:

//// INFO ////
BITMAPINFO* pbmi = (BITMAPINFO*)alloca( sizeof(BITMAPINFOHEADER) +
    sizeof(RGBQUAD)*256);
pbmi->bmiHeader.biSize = sizeof (pbmi->bmiHeader);
pbmi->bmiHeader.biWidth = 2752;
pbmi->bmiHeader.biHeight = -2200;
pbmi->bmiHeader.biPlanes = 1;
pbmi->bmiHeader.biBitCount = 8;
pbmi->bmiHeader.biCompression = BI_RGB;
pbmi->bmiHeader.biSizeImage = 0;
pbmi->bmiHeader.biXPelsPerMeter = 14173;
pbmi->bmiHeader.biYPelsPerMeter = 14173;
pbmi->bmiHeader.biClrUsed = 0;
pbmi->bmiHeader.biClrImportant = 0;

So far, I have tried the following:

for(int i=0,a = 0; i < 64; i++)
{
    pbmi->bmiColors[i].rgbRed = BYTE(a);
    pbmi->bmiColors[i+64].rgbGreen = BYTE(a);
    pbmi->bmiColors[i+64+64].rgbBlue = BYTE(a);
    pbmi->bmiColors[i+64+64+64].rgbReserved = BYTE(0);
    a += 4;
}
//This created a palette consisting only of cyan, yellow, and magenta colors.
//Didn't work.

for(int i=0,r=0,g=0,b=0; b <= 255; i++)
{
    if(r >= 256)
    {
        r = 0;
        g++;
    }
    if(g >= 256)
    {
        g = 0;
        b++;
    }
    pbmi->bmiColors[i].rgbRed = BYTE(r);
    pbmi->bmiColors[i].rgbGreen = BYTE(g);
    pbmi->bmiColors[i].rgbBlue = BYTE(b);
    pbmi->bmiColors[i].rgbReserved = BYTE(0);

    r++;
}
//Here I was trying to basically count up hexadecimally from 000000 to FFFFFF.
//Caused an access violation error.

I've also tried each of those after changing pbmi->bmiHeader.biBitCount to 16, 24, and 32, none of which worked.

So my question is: How do I create a color palette based on the BITMAPINFO settings I have provided?

xcdemon05
  • 1,372
  • 5
  • 25
  • 49
  • 1
    You need to check the documentation for your camera. How many bytes are generated for each frame? – Mark Ransom May 01 '13 at 19:46
  • Well each image is 2752x2200, which is 6054400 pixels. So (correct me if this isn't accurate) I would assume that each image is 6054400*3 bytes in size. – xcdemon05 May 01 '13 at 19:55
  • Please don't assume. I'm asking in an attempt to decipher the video format. – Mark Ransom May 01 '13 at 19:57
  • 1
    I'm looking through the documentation now. Here is the camera I am using (AVT Prosilica GT2750C): http://www.alliedvisiontec.com/us/products/cameras/gigabit-ethernet/prosilica-gt/gt2750.html – xcdemon05 May 01 '13 at 19:59
  • 1
    The camera specs say it has 6 different colors modes. If you set it for `BGR8Packed` you shouldn't need a palette. – Mark Ransom May 01 '13 at 20:06
  • Hmm setting it to BGR8Packed just made every frame a blank white image. – xcdemon05 May 01 '13 at 20:15
  • 1
    You also need to set `biBitCount` to 24. – Mark Ransom May 01 '13 at 20:21
  • As a followup question, what would I have to change to make the images display properly in BayerRG8 mode (the camera's default)? As of now it only displays an image in BayerRG8 mode when the bitcount is set to 8, however the image comes up in black and white rather than color even without my grayscale palette code. – xcdemon05 May 02 '13 at 13:09
  • I'm not familiar with BayerRG8, you're on your own. – Mark Ransom May 02 '13 at 13:31

1 Answers1

0

If you are trying to create a simple RGB pallete, you just need to change the R, G e B values from 0 to 255:

const int MaxIndex = 255;

for(int r=0; r <= MaxIndex; r++)
    for(int g=0; g <= MaxIndex; g++)
        for(int b=0; b <= MaxIndex; b++)
        {
            i = r * MaxIndex * MaxIndex + g * MaxIndex + b
            pbmi->bmiColors[i].rgbRed = BYTE(r);
            pbmi->bmiColors[i].rgbGreen = BYTE(g);
            pbmi->bmiColors[i].rgbBlue = BYTE(b);
            pbmi->bmiColors[i].rgbReserved = BYTE(0);
        }
Hugo Corrá
  • 14,546
  • 3
  • 27
  • 39
  • Where is the `i` coming from in your example? How and where is it incremented? – xcdemon05 May 01 '13 at 19:35
  • Sorry, I've forgot about te i, fixed now. – Hugo Corrá May 01 '13 at 19:52
  • That will generate a 16MB colour table, which is completely redundant. The colour values in the 'palette' simply end up being the table indices from 0 (black) to 16777215 (white). For true-colour images you don't need a palette. –  May 01 '13 at 19:53