/apps/desktop/libvncserver/tableinitcmtemplate.c

http://ftk.googlecode.com/ · C · 84 lines · 45 code · 7 blank · 32 comment · 8 complexity · 5b291add26ee0b6fbc795804ebe5e015 MD5 · raw file

  1. /*
  2. * tableinitcmtemplate.c - template for initialising lookup tables for
  3. * translation from a colour map to true colour.
  4. *
  5. * This file shouldn't be compiled. It is included multiple times by
  6. * translate.c, each time with a different definition of the macro OUT.
  7. * For each value of OUT, this file defines a function which allocates an
  8. * appropriately sized lookup table and initialises it.
  9. *
  10. * I know this code isn't nice to read because of all the macros, but
  11. * efficiency is important here.
  12. */
  13. /*
  14. * OSXvnc Copyright (C) 2001 Dan McGuirk <mcguirk@incompleteness.net>.
  15. * Original Xvnc code Copyright (C) 1999 AT&T Laboratories Cambridge.
  16. * All Rights Reserved.
  17. *
  18. * This is free software; you can redistribute it and/or modify
  19. * it under the terms of the GNU General Public License as published by
  20. * the Free Software Foundation; either version 2 of the License, or
  21. * (at your option) any later version.
  22. *
  23. * This software is distributed in the hope that it will be useful,
  24. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. * GNU General Public License for more details.
  27. *
  28. * You should have received a copy of the GNU General Public License
  29. * along with this software; if not, write to the Free Software
  30. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  31. * USA.
  32. */
  33. #if !defined(OUT)
  34. #error "This file shouldn't be compiled."
  35. #error "It is included as part of translate.c"
  36. #endif
  37. #define OUT_T CONCAT3E(uint,OUT,_t)
  38. #define SwapOUT(x) CONCAT2E(Swap,OUT(x))
  39. #define rfbInitColourMapSingleTableOUT \
  40. CONCAT2E(rfbInitColourMapSingleTable,OUT)
  41. static void
  42. rfbInitColourMapSingleTableOUT(char **table, rfbPixelFormat *in,
  43. rfbPixelFormat *out,rfbColourMap* colourMap)
  44. {
  45. uint32_t i, r, g, b;
  46. OUT_T *t;
  47. uint32_t nEntries = 1 << in->bitsPerPixel;
  48. int shift = colourMap->is16?16:8;
  49. if (*table) free(*table);
  50. *table = (char *)malloc(nEntries * sizeof(OUT_T));
  51. t = (OUT_T *)*table;
  52. for (i = 0; i < nEntries; i++) {
  53. r = g = b = 0;
  54. if(i < colourMap->count) {
  55. if(colourMap->is16) {
  56. r = colourMap->data.shorts[3*i+0];
  57. g = colourMap->data.shorts[3*i+1];
  58. b = colourMap->data.shorts[3*i+2];
  59. } else {
  60. r = colourMap->data.bytes[3*i+0];
  61. g = colourMap->data.bytes[3*i+1];
  62. b = colourMap->data.bytes[3*i+2];
  63. }
  64. }
  65. t[i] = ((((r * (1 + out->redMax)) >> shift) << out->redShift) |
  66. (((g * (1 + out->greenMax)) >> shift) << out->greenShift) |
  67. (((b * (1 + out->blueMax)) >> shift) << out->blueShift));
  68. #if (OUT != 8)
  69. if (out->bigEndian != in->bigEndian) {
  70. t[i] = SwapOUT(t[i]);
  71. }
  72. #endif
  73. }
  74. }
  75. #undef OUT_T
  76. #undef SwapOUT
  77. #undef rfbInitColourMapSingleTableOUT