Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /* Copyright (C) 2000-2003 Constantin Kaplinsky. All Rights Reserved.
  2. * Copyright 2004-2005 Cendio AB.
  3. * Copyright 2009-2015 Pierre Ossman for Cendio AB
  4. * Copyright (C) 2011 D. R. Commander. All Rights Reserved.
  5. *
  6. * This is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This software is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this software; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  19. * USA.
  20. */
  21. //
  22. // Tight decoding functions.
  23. //
  24. // This file is #included after having set the following macro:
  25. // BPP - 8, 16 or 32
  26. namespace rfb {
  27. // CONCAT2E concatenates its arguments, expanding them if they are macros
  28. #ifndef CONCAT2E
  29. #define CONCAT2(a,b) a##b
  30. #define CONCAT2E(a,b) CONCAT2(a,b)
  31. #endif
  32. #define PIXEL_T rdr::CONCAT2E(U,BPP)
  33. #if BPP == 32
  34. void
  35. TightDecoder::FilterGradient24(const rdr::U8 *inbuf,
  36. const PixelFormat& pf, PIXEL_T* outbuf,
  37. int stride, const Rect& r)
  38. {
  39. int x, y, c;
  40. rdr::U8 prevRow[TIGHT_MAX_WIDTH*3];
  41. rdr::U8 thisRow[TIGHT_MAX_WIDTH*3];
  42. rdr::U8 pix[3];
  43. int est[3];
  44. memset(prevRow, 0, sizeof(prevRow));
  45. // Set up shortcut variables
  46. int rectHeight = r.height();
  47. int rectWidth = r.width();
  48. for (y = 0; y < rectHeight; y++) {
  49. /* First pixel in a row */
  50. for (c = 0; c < 3; c++) {
  51. pix[c] = inbuf[y*rectWidth*3+c] + prevRow[c];
  52. thisRow[c] = pix[c];
  53. }
  54. pf.bufferFromRGB((rdr::U8*)&outbuf[y*stride], pix, 1);
  55. /* Remaining pixels of a row */
  56. for (x = 1; x < rectWidth; x++) {
  57. for (c = 0; c < 3; c++) {
  58. est[c] = prevRow[x*3+c] + pix[c] - prevRow[(x-1)*3+c];
  59. if (est[c] > 0xff) {
  60. est[c] = 0xff;
  61. } else if (est[c] < 0) {
  62. est[c] = 0;
  63. }
  64. pix[c] = inbuf[(y*rectWidth+x)*3+c] + est[c];
  65. thisRow[x*3+c] = pix[c];
  66. }
  67. pf.bufferFromRGB((rdr::U8*)&outbuf[y*stride+x], pix, 1);
  68. }
  69. memcpy(prevRow, thisRow, sizeof(prevRow));
  70. }
  71. }
  72. #endif
  73. #if BPP != 8
  74. void TightDecoder::FilterGradient(const rdr::U8* inbuf,
  75. const PixelFormat& pf, PIXEL_T* outbuf,
  76. int stride, const Rect& r)
  77. {
  78. int x, y, c;
  79. static rdr::U8 prevRow[TIGHT_MAX_WIDTH*3];
  80. static rdr::U8 thisRow[TIGHT_MAX_WIDTH*3];
  81. rdr::U8 pix[3];
  82. int est[3];
  83. memset(prevRow, 0, sizeof(prevRow));
  84. // Set up shortcut variables
  85. int rectHeight = r.height();
  86. int rectWidth = r.width();
  87. for (y = 0; y < rectHeight; y++) {
  88. /* First pixel in a row */
  89. pf.rgbFromBuffer(pix, &inbuf[y*rectWidth], 1);
  90. for (c = 0; c < 3; c++)
  91. pix[c] += prevRow[c];
  92. memcpy(thisRow, pix, sizeof(pix));
  93. pf.bufferFromRGB((rdr::U8*)&outbuf[y*stride], pix, 1);
  94. /* Remaining pixels of a row */
  95. for (x = 1; x < rectWidth; x++) {
  96. for (c = 0; c < 3; c++) {
  97. est[c] = prevRow[x*3+c] + pix[c] - prevRow[(x-1)*3+c];
  98. if (est[c] > 255) {
  99. est[c] = 255;
  100. } else if (est[c] < 0) {
  101. est[c] = 0;
  102. }
  103. }
  104. pf.rgbFromBuffer(pix, &inbuf[y*rectWidth+x], 1);
  105. for (c = 0; c < 3; c++)
  106. pix[c] += est[c];
  107. memcpy(&thisRow[x*3], pix, sizeof(pix));
  108. pf.bufferFromRGB((rdr::U8*)&outbuf[y*stride+x], pix, 1);
  109. }
  110. memcpy(prevRow, thisRow, sizeof(prevRow));
  111. }
  112. }
  113. #endif
  114. void TightDecoder::FilterPalette(const PIXEL_T* palette, int palSize,
  115. const rdr::U8* inbuf, PIXEL_T* outbuf,
  116. int stride, const Rect& r)
  117. {
  118. // Indexed color
  119. int x, h = r.height(), w = r.width(), b, pad = stride - w;
  120. PIXEL_T* ptr = outbuf;
  121. rdr::U8 bits;
  122. const rdr::U8* srcPtr = inbuf;
  123. if (palSize <= 2) {
  124. // 2-color palette
  125. while (h > 0) {
  126. for (x = 0; x < w / 8; x++) {
  127. bits = *srcPtr++;
  128. for (b = 7; b >= 0; b--) {
  129. *ptr++ = palette[bits >> b & 1];
  130. }
  131. }
  132. if (w % 8 != 0) {
  133. bits = *srcPtr++;
  134. for (b = 7; b >= 8 - w % 8; b--) {
  135. *ptr++ = palette[bits >> b & 1];
  136. }
  137. }
  138. ptr += pad;
  139. h--;
  140. }
  141. } else {
  142. // 256-color palette
  143. while (h > 0) {
  144. PIXEL_T *endOfRow = ptr + w;
  145. while (ptr < endOfRow) {
  146. *ptr++ = palette[*srcPtr++];
  147. }
  148. ptr += pad;
  149. h--;
  150. }
  151. }
  152. }
  153. #undef PIXEL_T
  154. }