24bit problems

Started by
13 comments, last by Brad8383 24 years, 3 months ago
First the problem then the code. The problem is with my 24bit pixel plotting code. The results are something like using a 555 function with a 565 card. if red is 255 and g,b are 0 i get blue. If its only blue i get blue(obviously not a problem), and if its all green it turns out yellow. Now for the code. its set up right in 24bit, Pitch is the pitch, Buffer is a uchar value that holds ddsd.lpSurface. void SetPix24(int x, int y, int r, int g, int b) { PixAdr = (x+x+x)+y*Pitch; Buffer[PixAdr] = b; Buffer[PixAdr+1] = g; Buffer[PixAdr+2] = r; }
Advertisement
It looks like you are using a BYTE array to do the work. Make a RGB struct and then use an RGB pointer. That way, you can handle 24 bit the same way you would handle 8 bit.

struct RGB24
{
BYTE blue;
BYTE green;
BYTE red;
};

RGB24 *buffer; // off screen buffer

void SetPixel24(int x, int y, RGB24 color)
{
int PixAddr = x + y * Pitch;
buffer[PixAddr] = color;
}

This will work in C++, should work in C with a few changes.
This is how I do it, but i you want to stick to your way, try PixAdr = (x + (y * Pitch)) * 3;

Domini
When I lock it would i do.. buffer.blue = (BYTE)ddsd.lpSurface;?
buffer = (RGB24 *)ddsd.lpSurface;

When I redo my web page, I''ll include the source to a RGB16 and RGB24 class. Lots of overloaded operators and conversion stuff. Makes it so easy to do 16bit and 24 bit graphics.

Domini
Well I got that somewhat working. I dont know why but i had to divide the pitch by 3 because plotting at 50,50 was really 50, 150. But the color problem is exactly the same as it was. Could you send me a small exe that plotted a single red pixel. If the pixel is red then the problem is my code and if it turns out blue then its my hardware.
Try to find out the mask for each of the three colors (write them to a file , or something.).They''re in the DDPIXELFORMAT struct, I think you get the struct in some call to the surface, don''t remember wich, sorry.
There is a dwRBitMask (or something like that), a dwGBitMask and a dwBBitMask which should be something like 0xFF0000, 0x00FF00,0x0000FF for 24 bit(remember to write them if hex format). if they aren''t, your card either has a weird format or is in another format than 24 bit.

You had to divide the pitch by three because pitch
is always the length of a line in bytes.
Because buffer is an RGB24*, buffer[PixAddr]
is the same physical memory location as
((BYTE *)buffer) + (PixAddr*3).

As for your color problem, try changing RGB24 to:

struct RGB24
{
BYTE red;
BYTE green;
BYTE blue;
};
On every card have used, blue is first, and if Pitch is the width of the buffer in pixels you shouldn''t have to divide by anything. If Pitch is the (width * 3) that may be the problem.

Domini
I think that Pitch is the lPitch from the ddsd struct, wich is the width of the image in bytes, not in pixels. So you have to divide by 2 for 16 bit color, 3 for 24, 4 for 32.
Yeah he''s right. On my 16bit plotting code i divide by 2. But even when i get the coords right the colors are still distorted.

This topic is closed to new replies.

Advertisement