How to Use _remappalette() in EGA ModesLast reviewed: July 17, 1997Article ID: Q43330 |
5.10 6.00 6.00a 6.00ax 7.00 | 1.00 1.50
MS-DOS | WINDOWSkbprg kbcode
The information in this article applies to:
SUMMARYWhen attempting to remap the palette in the EGA modes, follow the required format to form the argument passed to the remapping functions. This article uses _remappalette as an example. What is said about lColor (see function prototype below) also applies to the element of the array slColors for _remapallpalette. The function prototypes are as follows:
short far _remappalette (nPixel, lColor) ; short nPixel ; /* Pixel value to reassign */ long lColor ; /* Color number to assign to nPixel */ short far _remapallpalette (slColors) ; long far * slColors ; Color arraylColor is a long int formed by the following four bytes:
00, blue byte, green byte, red byteThe four bytes are arranged from the most significant byte to the least significant byte (left to right). The most significant byte is always 0 (zero). Each of the remaining three bytes can have the value of either 00, 2a, 15, or 3f. (In VGA mode, each byte can take any value between 00 and 3f.) Combinations of different values in the three bytes form the complete palette of 64 colors for the EGA graphics modes. The manifest constants for the EGA modes are _MRES16COLOR, _HRES16COLOR, and _ERESCOLOR, which are used with the function _setvideomode. Please refer to the include file GRAPH.H for the default values of the 16 colors in an EGA mode.
MORE INFORMATIONAn algorithm is provided in this section to convert a color represented by an arbitrary number from 0 to 63 to the required format. A sample program is included that implements the algorithm. Suppose the color is represented by a byte, as follows:
bit7 , bit6 , bit5 , bit4 , bit3 , bit2 , bit1 , bit0
bit3 , bit0 ; bit4 , bit1 ; bit5 , bit2 ;
bitX bitY MappedXY 0 0 00 0 1 2a 1 0 15 1 1 3f The order (from high to low) of the three bytes is as follows:
blue byte , green byte , red byte Color 43 has bit pattern 0 0 1 0 1 0 1 1. This pattern is transformed to three pairs: 11, 01, 10. The three pairs are mapped to 3f, 2a, 15. The mapped color represented in long integer format is 0x3f2a15. The following program uses _remappalette() to remap the color "0" (which defaults to black) to the 64 different colors. For more information on this subject, refer to the "Programmer's Guide to PC and PS/2 Video Systems" by Richard Wilton, published by Microsoft Press.
Sample Code
/* * Pallette.c */ #include <stdio.h> #include <graph.h> #include <conio.h> #define NUMCOLOR 64 #define MASK 0x0001unsigned long ConvertColNum (unsigned int) ; unsigned char ConvertArr [4] = { 0x00, 0x2a, 0x15, 0x3f } ;
void main (void){ unsigned short nColor = 0 ; unsigned int i ;unsigned long lMappedColor ; if (!_setvideomode (_ERESCOLOR)) return ;puts ("Press any key to continue ...") ; getch () ; for (i = 0 ; i < NUMCOLOR ; i++) { lMappedColor = ConvertColNum (i) ; if (_remappalette (nColor, lMappedColor) == -1L) puts ("\x007Mapping color failed : ") ; // beep if fails printf ("Color number = %u, lMappedColor = %08lx\n", i, lMappedColor); if (getch () == 'q') break ; }_setvideomode (_DEFAULTMODE) ; } unsigned long ConvertColNum (unsigned int nOrgColor) { unsigned long lColor, lTemp ; int j, temp ; lColor = 0L ; for (j = 0 ; j < 3 ; j++) { // get the pair temp = ((nOrgColor >> (j + 3) & MASK) << 1 ) | (nOrgColor >> j & MASK) ; lTemp = (unsigned long) ConvertArr [ temp ] ; lColor |= lTemp << ((2-j) << 3) ; // (2-j) * 8 } return (lColor) ;}
|
Additional reference words: kbinf 1.00 1.50 5.10 6.00 6.00a 6.00ax 7.00
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |