Jump to content

  • Log In with Google      Sign In   
  • Create Account


24bit problems


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
14 replies to this topic

#1 Brad8383   Members   -  Reputation: 122

Like
Likes
Like

Posted 27 January 2000 - 04:20 AM

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; }

Sponsor:

#2 Domini   Members   -  Reputation: 126

Like
Likes
Like

Posted 27 January 2000 - 06:55 AM

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

#3 Brad8383   Members   -  Reputation: 122

Like
Likes
Like

Posted 27 January 2000 - 07:15 AM

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

#4 Domini   Members   -  Reputation: 126

Like
Likes
Like

Posted 27 January 2000 - 08:39 AM

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

#5 Brad8383   Members   -  Reputation: 122

Like
Likes
Like

Posted 27 January 2000 - 03:41 PM

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.

#6 alexmoura   GDNet+   -  Reputation: 450

Like
Likes
Like

Posted 27 January 2000 - 09:51 PM

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.

#7 LordFoul   Members   -  Reputation: 122

Like
Likes
Like

Posted 27 January 2000 - 10:43 PM


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;
};

#8 Domini   Members   -  Reputation: 126

Like
Likes
Like

Posted 28 January 2000 - 06:03 AM

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

#9 alexmoura   GDNet+   -  Reputation: 450

Like
Likes
Like

Posted 28 January 2000 - 06:20 AM

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.

#10 Brad8383   Members   -  Reputation: 122

Like
Likes
Like

Posted 28 January 2000 - 07:02 AM

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.

#11 Domini   Members   -  Reputation: 126

Like
Likes
Like

Posted 28 January 2000 - 09:32 AM

Have you tried

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

Pitch being 3 times the width and buffer being a RGB24 *
If that doesn''t work, the only thing I can think of, is somewhere in your code, PixAddr is has been either incremented or decremented, causing the alignment to be off. I believe blue is first, you can try switching it with red.

Domini

#12 Brad8383   Members   -  Reputation: 122

Like
Likes
Like

Posted 28 January 2000 - 01:00 PM

Yep ive tried your methods and all the other peoples at xtreme games. Right now the code was set up to plot using 32bits and the last 8 being 0. It works on my friends computer perfectly. I have a stealth 2 s220 and it probably doesnt work right in 24bit. What would happen if i set it in 24bit mode without checking the errors and it didnt support it? Oh yeah and how can i tell if the card needs to use your RGB24 method(using exactly 24bits) and using 32 bits but having the last 8 set to 0?

#13 Domini   Members   -  Reputation: 126

Like
Likes
Like

Posted 29 January 2000 - 03:58 AM

You have been using 32bit modes, not 24 bit ones. With the 32 bit modes I belive that extra 8 bits is an alpha channel. I don''t have much experience with 32 bit modes, but I''ll see what I can find out.

Domini

#14 Brad8383   Members   -  Reputation: 122

Like
Likes
Like

Posted 29 January 2000 - 05:47 AM

Yes but when i tried 24bit with your RGB24 method and the method in TWGPG it gave the same results. Remember on some cards though 24bit is represented with 32 bits cause some cards cant address that way. At least thats what ive read. But anyway it works perfect on my friends computer and I do have an old card. Im not really going to use this anyway but I wanted to put it in my wrapper just to be complete.

#15 Domini   Members   -  Reputation: 126

Like
Likes
Like

Posted 29 January 2000 - 03:55 PM

I am creating a windows wrapper that handles the overhead and Direct X. It works with 24 and 16 bit modes, so I have a RGB16 and a RGB24 and two sets of my graphics functions. You can do the same thing and call your RGB32 graphics functions if the mode is 32 bpp. I may add RGB32 to my wrapper.

Domini




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS