Mail Archives: djgpp/1998/06/12/15:30:28
On Thu, 11 Jun 1998, Steven S. Falls wrote:
> Hi, I am trying to write a 16bit color graphics lib and I don't know
> how to set the palette in that mode. I tryed using the 8 bit way but it
> crashed.
> thanks,
> -Ardy
> http://www.addr.com/~ardy/
There is no palette in 16 bit colour modes. Each 16-bit word in video
memory represents the RGB value of a pixel, with (usually) the first 5
bits for the red component, the second 6 bits for the green component and
the last 5 bits for the blue component. Other formats are possible, for
instance 5-5-5/1-5-5-5 (where the first bit is ignored ).
Here is a short header file containing pixel classes for 15/16/24/32 bit
pixels. The constructors take red, green and blue values between
(0..255,0..255,0..255) and convert them to the appropriate pixel format.
The class member functions red(), green() and blue() extract the red,
green and blue values of pixels in a particular format and return a value
in the range 0..255.
To use simply include the header file and do stuff like
Pixel15 buffer[100];
buffer[2] = Pixel15(0,0,255);
buffer[3] = buffer[2];
or
Pixel15 *videomem = (Pixel15 *)0xa0000 + __djgpp_conventional_base;
Pixel15 colour = Pixel15(24,36,45);
for( int i=0; i<320; i++)videomem[i] = colour;
etc.
Hope this helps.
Cheers,
Elliott Oti
kamer 104, tel (030-253) 2516 (RvG)
http://www.fys.ruu.nl/~oti
============== File Pixel.h ========================
#ifndef PIXEL_H_
#define PIXEL_H_
class Pixel15
{
public:
unsigned short rgb;
Pixel15(){}
Pixel15(int r, int g, int b)
{ rgb = ((r & 0x000000F8)<<7) +
((g & 0x000000F8)<<2) +
((b )>>3); }
~Pixel15(){}
inline int red(){ return ( rgb & 0x7C00 ) >>7; }
inline int green(){ return ( rgb & 0x03E0 ) >> 2; }
inline int blue(){ return ( rgb & 0x001F ) << 3; }
};
class Pixel16
{
public:
unsigned short rgb;
Pixel16(){}
Pixel16(int r, int g, int b)
{ rgb = ((r & 0x000000F8)<<8) +
((g & 0x000000FC)<<3) +
((b )>>3); }
~Pixel16(){}
inline int red(){ return ( rgb & 0xF800 ) >>8; }
inline int green(){ return ( rgb & 0x07E0 ) >> 3; }
inline int blue(){ return ( rgb & 0x001F ) << 3; }
};
class Pixel24
{
public:
unsigned char rgb[3];
Pixel24(){}
Pixel24(int r, int g, int b)
{ rgb[0] = r; rgb[1] = g; rgb[2] = b; }
~Pixel24(){}
inline int red(){ return rgb[0]; }
inline int green(){ return rgb[1]; }
inline int blue(){ return rgb[2]; }
};
class Pixel32
{
public:
unsigned long rgb;
Pixel32(){}
Pixel32(int r, int g, int b)
{ rgb = (r << 16) + (g << 8) + b; }
~Pixel32(){}
inline int red(){ return ( rgb & 0x00FF0000 ) >> 16; }
inline int green(){ return ( rgb & 0x0000FF00 ) >> 8; }
inline int blue(){ return ( rgb & 0x000000FF ); }
};
#endif
- Raw text -