www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/06/12/15:30:28

Newsgroups: comp.os.msdos.djgpp
From: Elliott Oti <oti AT phys DOT uu DOT nl>
Subject: Re: HELP:Palettes under 16bit graphics
Sender: usenet AT fys DOT ruu DOT nl (News system Tijgertje)
Message-ID: <Pine.OSF.3.95.980612135141.6911B-100000@ruunf0.fys.ruu.nl>
In-Reply-To: <3580C80B.6FA0CF3A@earthlink.net>
Date: Fri, 12 Jun 1998 12:12:06 GMT
References: <3580C80B DOT 6FA0CF3A AT earthlink DOT net>
Mime-Version: 1.0
Organization: Physics and Astronomy, University of Utrecht, The Netherlands
Lines: 131
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019