/apps/desktop/libvncserver/tableinit24.c

http://ftk.googlecode.com/ · C · 157 lines · 107 code · 19 blank · 31 comment · 20 complexity · dd0e2296703472185d850df01f6a0324 MD5 · raw file

  1. /*
  2. 24 bit
  3. */
  4. /*
  5. * OSXvnc Copyright (C) 2001 Dan McGuirk <mcguirk@incompleteness.net>.
  6. * Original Xvnc code Copyright (C) 1999 AT&T Laboratories Cambridge.
  7. * All Rights Reserved.
  8. *
  9. * This is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This software is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this software; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  22. * USA.
  23. */
  24. static void
  25. rfbInitOneRGBTable24 (uint8_t *table, int inMax, int outMax, int outShift,int swap);
  26. static void
  27. rfbInitColourMapSingleTable24(char **table, rfbPixelFormat *in,
  28. rfbPixelFormat *out,rfbColourMap* colourMap)
  29. {
  30. uint32_t i, r, g, b, outValue;
  31. uint8_t *t;
  32. uint8_t c;
  33. unsigned int nEntries = 1 << in->bitsPerPixel;
  34. int shift = colourMap->is16?16:8;
  35. if (*table) free(*table);
  36. *table = (char *)malloc(nEntries * 3 + 1);
  37. t = (uint8_t *)*table;
  38. for (i = 0; i < nEntries; i++) {
  39. r = g = b = 0;
  40. if(i < colourMap->count) {
  41. if(colourMap->is16) {
  42. r = colourMap->data.shorts[3*i+0];
  43. g = colourMap->data.shorts[3*i+1];
  44. b = colourMap->data.shorts[3*i+2];
  45. } else {
  46. r = colourMap->data.bytes[3*i+0];
  47. g = colourMap->data.bytes[3*i+1];
  48. b = colourMap->data.bytes[3*i+2];
  49. }
  50. }
  51. outValue = ((((r * (1 + out->redMax)) >> shift) << out->redShift) |
  52. (((g * (1 + out->greenMax)) >> shift) << out->greenShift) |
  53. (((b * (1 + out->blueMax)) >> shift) << out->blueShift));
  54. *(uint32_t*)&t[3*i] = outValue;
  55. if(!rfbEndianTest)
  56. memmove(t+3*i,t+3*i+1,3);
  57. if (out->bigEndian != in->bigEndian) {
  58. c = t[3*i]; t[3*i] = t[3*i+2]; t[3*i+2] = c;
  59. }
  60. }
  61. }
  62. /*
  63. * rfbInitTrueColourSingleTable sets up a single lookup table for truecolour
  64. * translation.
  65. */
  66. static void
  67. rfbInitTrueColourSingleTable24 (char **table, rfbPixelFormat *in,
  68. rfbPixelFormat *out)
  69. {
  70. int i,outValue;
  71. int inRed, inGreen, inBlue, outRed, outGreen, outBlue;
  72. uint8_t *t;
  73. uint8_t c;
  74. int nEntries = 1 << in->bitsPerPixel;
  75. if (*table) free(*table);
  76. *table = (char *)malloc(nEntries * 3 + 1);
  77. t = (uint8_t *)*table;
  78. for (i = 0; i < nEntries; i++) {
  79. inRed = (i >> in->redShift) & in->redMax;
  80. inGreen = (i >> in->greenShift) & in->greenMax;
  81. inBlue = (i >> in->blueShift) & in->blueMax;
  82. outRed = (inRed * out->redMax + in->redMax / 2) / in->redMax;
  83. outGreen = (inGreen * out->greenMax + in->greenMax / 2) / in->greenMax;
  84. outBlue = (inBlue * out->blueMax + in->blueMax / 2) / in->blueMax;
  85. outValue = ((outRed << out->redShift) |
  86. (outGreen << out->greenShift) |
  87. (outBlue << out->blueShift));
  88. *(uint32_t*)&t[3*i] = outValue;
  89. if(!rfbEndianTest)
  90. memmove(t+3*i,t+3*i+1,3);
  91. if (out->bigEndian != in->bigEndian) {
  92. c = t[3*i]; t[3*i] = t[3*i+2]; t[3*i+2] = c;
  93. }
  94. }
  95. }
  96. /*
  97. * rfbInitTrueColourRGBTables sets up three separate lookup tables for the
  98. * red, green and blue values.
  99. */
  100. static void
  101. rfbInitTrueColourRGBTables24 (char **table, rfbPixelFormat *in,
  102. rfbPixelFormat *out)
  103. {
  104. uint8_t *redTable;
  105. uint8_t *greenTable;
  106. uint8_t *blueTable;
  107. if (*table) free(*table);
  108. *table = (char *)malloc((in->redMax + in->greenMax + in->blueMax + 3)
  109. * 3 + 1);
  110. redTable = (uint8_t *)*table;
  111. greenTable = redTable + 3*(in->redMax + 1);
  112. blueTable = greenTable + 3*(in->greenMax + 1);
  113. rfbInitOneRGBTable24 (redTable, in->redMax, out->redMax,
  114. out->redShift, (out->bigEndian != in->bigEndian));
  115. rfbInitOneRGBTable24 (greenTable, in->greenMax, out->greenMax,
  116. out->greenShift, (out->bigEndian != in->bigEndian));
  117. rfbInitOneRGBTable24 (blueTable, in->blueMax, out->blueMax,
  118. out->blueShift, (out->bigEndian != in->bigEndian));
  119. }
  120. static void
  121. rfbInitOneRGBTable24 (uint8_t *table, int inMax, int outMax, int outShift,
  122. int swap)
  123. {
  124. int i;
  125. int nEntries = inMax + 1;
  126. uint32_t outValue;
  127. uint8_t c;
  128. for (i = 0; i < nEntries; i++) {
  129. outValue = ((i * outMax + inMax / 2) / inMax) << outShift;
  130. *(uint32_t *)&table[3*i] = outValue;
  131. if(!rfbEndianTest)
  132. memmove(table+3*i,table+3*i+1,3);
  133. if (swap) {
  134. c = table[3*i]; table[3*i] = table[3*i+2];
  135. table[3*i+2] = c;
  136. }
  137. }
  138. }