Working in 24bpp mode

I have some doubts about 24bpp mode. The examples use this to put a pixel
on the screen, but I don’t understand it very well:


Uint8 *bufp;

bufp = (Uint8 ) screen->pixels + yscreen->pitch + x;
*(bufp+screen->format->Rshift/8) = R;
*(bufp+screen->format->Gshift/8) = G;
*(bufp+screen->format->Bshift/8) = B;

Shouldn’t I consider that one pixel is 3 bytes after the previous one, when
calculating the base address?
Drawing, for example, an orizontal line, should I increment the address of
3, for obtaining the next pixel base address?

Marco Iannaccone @Marco_Iannaccone
ICQ: 18748121 Tolkien

“I’ve… seen things you people wouldn’t believe. Attack ships on fire off
the shoulder of Orion.
I watched C-beams… glitter in the dark near the Tanhauser Gate. All
those… moments will be lost… in time…, like… tears… in… rain.”

FAQ it.comp.lang.c: http://www.programmazione.it/linguaggi/c/itcomplangc.htm
FAQ it.comp.lang.c++: http://www.programmazione.it/linguaggi/c/lang_faq.htm

Marco Iannaccone wrote:

I have some doubts about 24bpp mode. The examples use
this to put a pixel on the screen, but I don’t understand
it very well:


Uint8 *bufp;

bufp = (Uint8 ) screen->pixels + yscreen->pitch + x;
*(bufp+screen->format->Rshift/8) = R;
*(bufp+screen->format->Gshift/8) = G;
*(bufp+screen->format->Bshift/8) = B;

Shouldn’t I consider that one pixel is 3 bytes after the
previous one, when calculating the base address?
Drawing, for example, an orizontal line, should I increment
the address of 3, for obtaining the next pixel base address?

Try using “screen->format->BytesPerPixel” as follows:

Uint8 *bufp, bpp;

/* load bytes per pixel */
bpp = screen->format->BytesPerPixel;

/* calculate buffer pointer /
bufp = (Uint8 ) screen->pixels + yscreen->pitch + x
bpp;

/* advance buffer pointer to the right */
bufp += bpp;

/* advance buffer pointer down */
bufp += screen->pitch;

  • Randi

Regimental Command
Generic Armored Combat System
http://regcom.sourceforge.net

Try using “screen->format->BytesPerPixel” as follows:

Uint8 *bufp, bpp;

/* load bytes per pixel */
bpp = screen->format->BytesPerPixel;

/* calculate buffer pointer /
bufp = (Uint8 ) screen->pixels + yscreen->pitch + x
bpp;

/* advance buffer pointer to the right */
bufp += bpp;

/* advance buffer pointer down */
bufp += screen->pitch;

That’s just what I meant. The example should be wrong, isn’t it?

Marco Iannaccone @Marco_Iannaccone
ICQ: 18748121 Tolkien

“I’ve… seen things you people wouldn’t believe. Attack ships on fire off
the shoulder of Orion.
I watched C-beams… glitter in the dark near the Tanhauser Gate. All
those… moments will be lost… in time…, like… tears… in… rain.”

FAQ it.comp.lang.c: http://www.programmazione.it/linguaggi/c/itcomplangc.htm
FAQ it.comp.lang.c++: http://www.programmazione.it/linguaggi/c/lang_faq.htm

Marco Iannaccone wrote:

Try using “screen->format->BytesPerPixel” as
follows:

That’s just what I meant. The example should be
wrong, isn’t it?

Where did you get the example? The only thing I can think of is that the
particular example might have had an implied 8-bit surface. But then the
rest of the RGB stuff would not have made sense. The use of "BytesPerPixel"
is correct so the example needs to be looked at in context and fixed if
necessary.

  • Randi

Regimental Command
Generic Armored Combat System
http://regcom.sourceforge.net

I took it on the SDL website.
It was an example of universal function fur putting a pixel on the
creen( it handled all the modes…)

Marco Iannaccone @Marco_Iannaccone
ICQ: 18748121 Tolkien

“I’ve… seen things you people wouldn’t believe. Attack ships on fire off
the shoulder of Orion.
I watched C-beams… glitter in the dark near the Tanhauser Gate. All
those… moments will be lost… in time…, like… tears… in… rain.”

FAQ it.comp.lang.c: http://www.programmazione.it/linguaggi/c/itcomplangc.htm
FAQ it.comp.lang.c++: http://www.programmazione.it/linguaggi/c/lang_faq.htm> ----- Original Message -----

From: rjrelander@users.sourceforge.net (Randi J. Relander)
Newsgroups: loki.open-source.sdl
To:
Sent: Thursday, August 31, 2000 4:46 PM
Subject: [SDL] Re: Working in 24bpp mode

Marco Iannaccone wrote:

Try using “screen->format->BytesPerPixel” as
follows:

That’s just what I meant. The example should be
wrong, isn’t it?

Where did you get the example? The only thing I can think of is that the
particular example might have had an implied 8-bit surface. But then the
rest of the RGB stuff would not have made sense. The use of
"BytesPerPixel"
is correct so the example needs to be looked at in context and fixed if
necessary.

  • Randi

Regimental Command
Generic Armored Combat System
http://regcom.sourceforge.net