Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/external/source/vncdll/winvnc/tableinitcmtemplate.cpp
Views: 11780
/*1* tableinitcmtemplate.c - template for initialising lookup tables for2* translation from a colour map to true colour.3*4* This file shouldn't be compiled. It is included multiple times by5* translate.c, each time with a different definition of the macro OUTBPP.6* For each value of OUTBPP, this file defines a function which allocates an7* appropriately sized lookup table and initialises it.8*9* I know this code isn't nice to read because of all the macros, but10* efficiency is important here.11*/1213#if !defined(OUTBPP)14#error "This file shouldn't be compiled."15#error "It is included as part of translate.c"16#endif1718#define OUT_T CONCAT2E(CARD,OUTBPP)19#define SwapOUT(x) CONCAT2E(Swap,OUTBPP) (x)20#define rfbInitColourMapSingleTableOUT \21CONCAT2E(rfbInitColourMapSingleTable,OUTBPP)2223// THIS CODE HAS BEEN MODIFIED FROM THE ORIGINAL UNIX SOURCE24// TO WORK FOR WINVNC. THE PALETTE SHOULD REALLY BE RETRIEVED25// FROM THE VNCDESKTOP OBJECT, RATHER THAN FROM THE OS DIRECTLY2627static void28rfbInitColourMapSingleTableOUT (char **table,29rfbPixelFormat *in,30rfbPixelFormat *out)31{32// ALLOCATE SPACE FOR COLOUR TABLE3334int nEntries = 1 << in->bitsPerPixel;3536// Allocate the table37if (*table) free(*table);38*table = (char *)malloc(nEntries * sizeof(OUT_T));39if (*table == NULL)40{41return;42}4344// Obtain the system palette45HDC hDC = GetDC(NULL);46PALETTEENTRY palette[256];47if (GetSystemPaletteEntries(hDC,480, 256, palette) == 0)49{50ReleaseDC(NULL, hDC);51return;52}53ReleaseDC(NULL, hDC);5455// COLOUR TRANSLATION5657// We now have the colour table intact. Map it into a translation table58int i, r, g, b;59OUT_T *t = (OUT_T *)*table;6061for (i = 0; i < nEntries; i++)62{63// Split down the RGB data64r = palette[i].peRed;65g = palette[i].peGreen;66b = palette[i].peBlue;6768// Now translate it69t[i] = ((((r * out->redMax + 127) / 255) << out->redShift) |70(((g * out->greenMax + 127) / 255) << out->greenShift) |71(((b * out->blueMax + 127) / 255) << out->blueShift));72#if (OUTBPP != 8)73if (out->bigEndian != in->bigEndian)74{75t[i] = SwapOUT(t[i]);76}77#endif78}7980}8182#undef OUT_T83#undef SwapOUT84#undef rfbInitColourMapSingleTableOUT858687