/apps/desktop/libvncserver/tabletranstemplate.c

http://ftk.googlecode.com/ · C · 117 lines · 61 code · 14 blank · 42 comment · 5 complexity · 50362bf1dd062effce254fb9b274cb6a MD5 · raw file

  1. /*
  2. * tabletranstemplate.c - template for translation using lookup tables.
  3. *
  4. * This file shouldn't be compiled. It is included multiple times by
  5. * translate.c, each time with different definitions of the macros IN and OUT.
  6. *
  7. * For each pair of values IN and OUT, this file defines two functions for
  8. * translating a given rectangle of pixel data. One uses a single lookup
  9. * table, and the other uses three separate lookup tables for the red, green
  10. * and blue values.
  11. *
  12. * I know this code isn't nice to read because of all the macros, but
  13. * efficiency is important here.
  14. */
  15. /*
  16. * OSXvnc Copyright (C) 2001 Dan McGuirk <mcguirk@incompleteness.net>.
  17. * Original Xvnc code Copyright (C) 1999 AT&T Laboratories Cambridge.
  18. * All Rights Reserved.
  19. *
  20. * This is free software; you can redistribute it and/or modify
  21. * it under the terms of the GNU General Public License as published by
  22. * the Free Software Foundation; either version 2 of the License, or
  23. * (at your option) any later version.
  24. *
  25. * This software is distributed in the hope that it will be useful,
  26. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  27. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  28. * GNU General Public License for more details.
  29. *
  30. * You should have received a copy of the GNU General Public License
  31. * along with this software; if not, write to the Free Software
  32. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  33. * USA.
  34. */
  35. #if !defined(IN) || !defined(OUT)
  36. #error "This file shouldn't be compiled."
  37. #error "It is included as part of translate.c"
  38. #endif
  39. #define IN_T CONCAT3E(uint,IN,_t)
  40. #define OUT_T CONCAT3E(uint,OUT,_t)
  41. #define rfbTranslateWithSingleTableINtoOUT \
  42. CONCAT4E(rfbTranslateWithSingleTable,IN,to,OUT)
  43. #define rfbTranslateWithRGBTablesINtoOUT \
  44. CONCAT4E(rfbTranslateWithRGBTables,IN,to,OUT)
  45. /*
  46. * rfbTranslateWithSingleTableINtoOUT translates a rectangle of pixel data
  47. * using a single lookup table.
  48. */
  49. static void
  50. rfbTranslateWithSingleTableINtoOUT (char *table, rfbPixelFormat *in,
  51. rfbPixelFormat *out,
  52. char *iptr, char *optr,
  53. int bytesBetweenInputLines,
  54. int width, int height)
  55. {
  56. IN_T *ip = (IN_T *)iptr;
  57. OUT_T *op = (OUT_T *)optr;
  58. int ipextra = bytesBetweenInputLines / sizeof(IN_T) - width;
  59. OUT_T *opLineEnd;
  60. OUT_T *t = (OUT_T *)table;
  61. while (height > 0) {
  62. opLineEnd = op + width;
  63. while (op < opLineEnd) {
  64. *(op++) = t[*(ip++)];
  65. }
  66. ip += ipextra;
  67. height--;
  68. }
  69. }
  70. /*
  71. * rfbTranslateWithRGBTablesINtoOUT translates a rectangle of pixel data
  72. * using three separate lookup tables for the red, green and blue values.
  73. */
  74. static void
  75. rfbTranslateWithRGBTablesINtoOUT (char *table, rfbPixelFormat *in,
  76. rfbPixelFormat *out,
  77. char *iptr, char *optr,
  78. int bytesBetweenInputLines,
  79. int width, int height)
  80. {
  81. IN_T *ip = (IN_T *)iptr;
  82. OUT_T *op = (OUT_T *)optr;
  83. int ipextra = bytesBetweenInputLines / sizeof(IN_T) - width;
  84. OUT_T *opLineEnd;
  85. OUT_T *redTable = (OUT_T *)table;
  86. OUT_T *greenTable = redTable + in->redMax + 1;
  87. OUT_T *blueTable = greenTable + in->greenMax + 1;
  88. while (height > 0) {
  89. opLineEnd = &op[width];
  90. while (op < opLineEnd) {
  91. *(op++) = (redTable[(*ip >> in->redShift) & in->redMax] |
  92. greenTable[(*ip >> in->greenShift) & in->greenMax] |
  93. blueTable[(*ip >> in->blueShift) & in->blueMax]);
  94. ip++;
  95. }
  96. ip += ipextra;
  97. height--;
  98. }
  99. }
  100. #undef IN_T
  101. #undef OUT_T
  102. #undef rfbTranslateWithSingleTableINtoOUT
  103. #undef rfbTranslateWithRGBTablesINtoOUT