home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / Samples / CSAPE32.ARJ / SOURCE / OWLSCR / DISPPCCO.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-09-12  |  2.6 KB  |  89 lines

  1. /*
  2.     disppcco.c
  3.  
  4.     % Device independent pc-like color table initialization.
  5.  
  6.     2/4/90 by Ted.
  7.  
  8.     OWL 1.2a
  9.     Copyright (c) 1988, 1989 by Oakland Group, Inc.
  10.     ALL RIGHTS RESERVED.
  11.  
  12.     Revision History:
  13.     -----------------
  14.      3/28/90 jmd    ansi-fied
  15.      6/06/90 ted    Made pccols initializer in-line instead of a macro for some unix compilers.
  16.      6/22/90 ted    added "void" to no-parameter function per ansii.
  17.      9/12/90 bkd    fixed declaration of pccols to compile under SunOS (and
  18.                          hopefully others as well)
  19. */
  20.  
  21. #include "oakhead.h"
  22. #include "disppriv.h"
  23. #include "disppvs.h"
  24.  
  25. #define MAX_RADIUS    255
  26. #define PC_NCOLS    16
  27. /* -------------------------------------------------------------------------- */
  28.  
  29. void disp_MapPcColors(void)
  30. /*
  31.     Set system colors and the attribute map to look like pc colors are in their
  32.     accustomed places in the first 16 pixel values.
  33. */
  34. {
  35.     static ocolmap_struct(PC_NCOLS) pccols = { 0, PC_NCOLS, {
  36.         {{   0,   0,   0}},        /* Black                */
  37.         {{  15,  15, 171}},        /* Dim Blue                */
  38.         {{  68, 155,  68}},        /* Dim Green            */
  39.         {{  28, 202, 202}},        /* Dim Cyan                */
  40.         {{ 218,  70,  70}},        /* Dim Red                */
  41.         {{ 211, 111, 211}},        /* Dim Magenta            */
  42.         {{ 171,  78,  78}},        /* Dim Yellow (Brown)    */
  43.         {{ 216, 218, 218}},        /* Dim White            */
  44.         {{ 156, 155, 155}},        /* Gray (Bright Black    */
  45.         {{   0,   0, 255}},        /* Blue                    */
  46.         {{   0, 255,   0}},        /* Green                */
  47.         {{   0, 255, 255}},        /* Cyan                    */
  48.         {{ 255,   0,   0}},        /* Red                    */
  49.         {{ 255,   0, 255}},        /* Magenta                */
  50.         {{ 255, 255,   0}},        /* Yellow                */
  51.         {{ 255, 255, 255}}        /* White                */
  52.     }};
  53.  
  54.     disp_MapAttrColors((ocolmap_type) &pccols);
  55. }
  56. /* -------------------------------------------------------------------------- */
  57.  
  58. void disp_MapAttrColors(ocolmap_type cmap)
  59. /*
  60.     Set system colors and the attribute map to look like the given 16 colors
  61.     are in the first 16 pixel values.
  62. */
  63. {
  64.     unsigned i;
  65.     opixval ipcpix, firstpix;
  66.     opixval pcvals[PC_NCOLS];
  67.  
  68.     /* For each pc color, find a system color close to it */
  69.     firstpix = cmap->firstpix;
  70.     for (i = 0; i < cmap->nentries; i++) {
  71.         ipcpix = firstpix + i;
  72.         if (disp_GetPixval(ocolmap_entry((ocolmap_type) cmap,ipcpix),
  73.                             &pcvals[i], 1)
  74.              == -1) {
  75.             if (disp_FindPixval(ocolmap_entry((ocolmap_type) cmap,ipcpix),
  76.                                 &pcvals[i], MAX_RADIUS)
  77.                  == -1) {
  78.                 pcvals[i] = i;    /* If color can't be had, use color i */
  79.             }
  80.         }
  81.     }
  82.     /* Map the attribute table so that it refers to the pc colors */
  83.     for (i = 0; i < 256; i++) {
  84.         disp_SetAttrColors((byte) i, pcvals[i >> 4], pcvals[i & 0x0F]);
  85.     }
  86. }
  87. /* -------------------------------------------------------------------------- */
  88.  
  89.