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/tableinittctemplate.cpp
Views: 11780
/*1* tableinittctemplate.c - template for initialising lookup tables for2* truecolour to truecolour translation.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 two functions for initialising7* lookup tables. One is for truecolour translation using a single lookup8* table, the other is for truecolour translation using three separate9* lookup tables for the red, green and blue values.10*11* I know this code isn't nice to read because of all the macros, but12* efficiency is important here.13*/1415#if !defined(OUTBPP)16#error "This file shouldn't be compiled."17#error "It is included as part of translate.c"18#endif1920#define OUT_T CONCAT2E(CARD,OUTBPP)21#define SwapOUT(x) CONCAT2E(Swap,OUTBPP) (x)22#define rfbInitTrueColourSingleTableOUT \23CONCAT2E(rfbInitTrueColourSingleTable,OUTBPP)24#define rfbInitTrueColourRGBTablesOUT CONCAT2E(rfbInitTrueColourRGBTables,OUTBPP)25#define rfbInitOneRGBTableOUT CONCAT2E(rfbInitOneRGBTable,OUTBPP)2627static void28rfbInitOneRGBTableOUT (OUT_T *table, int inMax, int outMax, int outShift,29int swap);303132/*33* rfbInitTrueColourSingleTable sets up a single lookup table for truecolour34* translation.35*/3637static void38rfbInitTrueColourSingleTableOUT (char **table, rfbPixelFormat *in,39rfbPixelFormat *out)40{41int i;42int inRed, inGreen, inBlue, outRed, outGreen, outBlue;43OUT_T *t;44int nEntries = 1 << in->bitsPerPixel;4546if (*table) free(*table);47*table = (char *)malloc(nEntries * sizeof(OUT_T));48if (table == NULL) return;49t = (OUT_T *)*table;5051for (i = 0; i < nEntries; i++) {52inRed = (i >> in->redShift) & in->redMax;53inGreen = (i >> in->greenShift) & in->greenMax;54inBlue = (i >> in->blueShift) & in->blueMax;5556outRed = (inRed * out->redMax + in->redMax / 2) / in->redMax;57outGreen = (inGreen * out->greenMax + in->greenMax / 2) / in->greenMax;58outBlue = (inBlue * out->blueMax + in->blueMax / 2) / in->blueMax;5960t[i] = ((outRed << out->redShift) |61(outGreen << out->greenShift) |62(outBlue << out->blueShift));63#if (OUTBPP != 8)64if (out->bigEndian != in->bigEndian) {65t[i] = SwapOUT(t[i]);66}67#endif68}69}707172/*73* rfbInitTrueColourRGBTables sets up three separate lookup tables for the74* red, green and blue values.75*/7677static void78rfbInitTrueColourRGBTablesOUT (char **table, rfbPixelFormat *in,79rfbPixelFormat *out)80{81OUT_T *redTable;82OUT_T *greenTable;83OUT_T *blueTable;8485if (*table) free(*table);86*table = (char *)malloc((in->redMax + in->greenMax + in->blueMax + 3)87* sizeof(OUT_T));88redTable = (OUT_T *)*table;89greenTable = redTable + in->redMax + 1;90blueTable = greenTable + in->greenMax + 1;9192rfbInitOneRGBTableOUT (redTable, in->redMax, out->redMax,93out->redShift, (out->bigEndian != in->bigEndian));94rfbInitOneRGBTableOUT (greenTable, in->greenMax, out->greenMax,95out->greenShift, (out->bigEndian != in->bigEndian));96rfbInitOneRGBTableOUT (blueTable, in->blueMax, out->blueMax,97out->blueShift, (out->bigEndian != in->bigEndian));98}99100static void101rfbInitOneRGBTableOUT (OUT_T *table, int inMax, int outMax, int outShift,102int swap)103{104int i;105int nEntries = inMax + 1;106107for (i = 0; i < nEntries; i++) {108table[i] = ((i * outMax + inMax / 2) / inMax) << outShift;109#if (OUTBPP != 8)110if (swap) {111table[i] = SwapOUT(table[i]);112}113#endif114}115}116117#undef OUT_T118#undef SwapOUT119#undef rfbInitTrueColourSingleTableOUT120#undef rfbInitTrueColourRGBTablesOUT121#undef rfbInitOneRGBTableOUT122123124