MetaWINDOW FAQ

High-Color Display Modes

Document ID: MWFAQ033.HTM

The information in this document applies to:

  • MetaWINDOW

  • MetHICOLOR

QUESTION

What color values should I use with the MetaWINDOW PenColor() and BackColor() functions when working in a VGA "high-color" display mode?
 

ANSWER

High-color SuperVGA modes store pixel data in video RAM as 16-bit entities.  Rather than using a color lookup palette as in 16-color and 256-color mode, high-color modes store RGB intensity values directly in each 16-bit pixel (there are no color tables or palettes in high-color or true-color modes).

Unfortunately different video chipset manufacturers supported high-color modes in two different RGB formats: 15-bit (1:)5:5:5 format supporting 32768 (32K) simultaneous colors, or 16-bit 5:6:5 format supporting 65536 (64K) simultaneous colors.  Some newer cards today also support both formats.

In 15-bit (1:)5:5:5 format each of the red, green and blue intensity values range from 0 to 31 arranged in the following format within each 16-bit pixel:


    15-BIT (1:)5:5:5 HIGH-COLOR FORMAT
  FEDC BA98 7654 3210   Bit Position        
  x--- ---- ---- ----   (unused)
  -RRR RR-- ---- ----   red intensity, 0-31
  ---- --GG GGG- ----   green intensity, 0-31
  ---- ---- ---B BBBB   blue intensity, 0-31

In 16-bit 5:6:5 format each of the red and blue intensity values range from 0 to 31, and the green intensity value ranges from 0-63.  These arranged in the following format within each 16-bit pixel:


    16-BIT 5:6:5 HIGH-COLOR FORMAT
  FEDC BA98 7654 3210   Bit Position        
  RRRR R--- ---- ----   red intensity, 0-31
  ---- -GGG GGG- ----   green intensity, 0-63
  ---- ---- ---B BBBB   blue intensity, 0-31

To be fully "high-color compatible" your application should be written to support both 15-bit and 16-bit formats.  Don't make the mistake of assuming that all devices will support 16-bit high color modes, or that all devices will support 15-bit high color modes.  There are some graphic cards that only support 15-bit modes, and also some cards that only support 16-bit modes.

The MetaWINDOW "grafMap" record "mapFlags" field can be used to identify which high-color format is in use:

static BOOL  format565;   /* TRUE=5:6:5 format, FALSE=(1:)5:5:5 format */
static int   redShift, grnShift, bluShift;  /* high-color shift counts */
static int   redMask,  grnMask,  bluMask;   /* high-color masks        */

void main()
{
    int        graphicsMode;
    grafPort  *screenPort;

    /* try to select a 1024x768 64K-color 5:6:5 high-color mode               */
    /* we may get 1024x768 32K-color (1:)5:5:5 if that's all that's supported */
    graphicsMode = FindBestDisplay( 1024, 768, 65536 );
    
    /* initialize MetaWINDOW for the selected display mode */
    i = InitGraphics( graphicsMode );
    if ( i != 0 )
    {
        printf( "MetaWINDOW InitGraphics() Error %d\n", i );
        exit( i );
    }
    
    SetDisplay( GrafPg0 );      /* switch to graphics mode */
    
    /* get a pointer to the default screen port */
    GetPort( &screenPort );

    /* check which high-color display mode is currently in use */
    if ( screenPort->portMap->mapFlags & mf565 )  // <=========
    {   /* high-color format is 16-bit 5:6:5 */
        format565 = TRUE;
        redShift  = 8;       /* amount to left shift 8-bit value, 0-255  */
        redMask   = 0xF800;  /* high-color mask for red                  */
        grnShift  = 3;       /* amount to left shift 8-bit value, 0-255  */
        grnMask   = 0x07E0;  /* high-color mask for green                */
        bluShift  = 3;       /* amount to right shift 8-bit value, 0-255 */
        bluMask   = 0x001F;  /* high-color mask for blue                 */
    }
    else
    {   /* high-color format is 15-bit (1:)5:5:5 */
        format565 = FALSE;
        redShift  = 7;       /* amount to left shift 8-bit value, 0-255  */
        redMask   = 0x7C00;  /* high-color mask for red                  */
        grnShift  = 2;       /* amount to left shift 8-bit value, 0-255  */
        grnMask   = 0x03E0;  /* high-color mask for green                */
        bluShift  = 3;       /* amount to right shift 8-bit value, 0-255 */
        bluMask   = 0x001F;  /* high-color mask for blue                 */
    }
    
    /* the shift and mask values can now be used for encoding high-color values */
    /* Set PenColor() to maximum blue */
    PenColor( RGB( 0, 0, 255 ) );
    
    :
} /* main() */



/* Function RGB() converts three 8-bit RGB intensity values, 0-255,     */
/* to a color value appropriate for the current high-color display mode */ 
int  RGB( int red, int green, int blue )
{
    int  hicolor;
    
    hicolor  = ( red   << redShift ) & redMask;
    hicolor |= ( green << grnShift ) & grnMask;
    hicolor |= ( blue  >> bluShift ) & bluMask;
    
    return ( hicolor );
    
} /* RGB() */


Link To MetaWINDOW FAQ Index
Link To MetaWINDOW Home Page
Link To Metagraphics Home Page

© Copyright - Metagraphics Software Corporation. All rights reserved.