Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 1 | /* Copyright (C) 2000-2003 Constantin Kaplinsky. All Rights Reserved. |
Peter Åstrand | d69bcc4 | 2011-09-28 12:52:53 +0000 | [diff] [blame] | 2 | * Copyright 2004-2005 Cendio AB. |
DRC | 33c15e3 | 2011-11-03 18:49:21 +0000 | [diff] [blame] | 3 | * Copyright (C) 2011 D. R. Commander. All Rights Reserved. |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 4 | * |
| 5 | * This is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This software is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this software; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
| 18 | * USA. |
| 19 | */ |
| 20 | |
| 21 | // |
| 22 | // Tight decoding functions. |
| 23 | // |
| 24 | // This file is #included after having set the following macros: |
| 25 | // BPP - 8, 16 or 32 |
| 26 | // EXTRA_ARGS - optional extra arguments |
| 27 | // FILL_RECT - fill a rectangle with a single color |
| 28 | // IMAGE_RECT - draw a rectangle of pixel data from a buffer |
| 29 | |
| 30 | #include <rdr/InStream.h> |
| 31 | #include <rdr/ZlibInStream.h> |
| 32 | #include <rfb/Exception.h> |
| 33 | #include <assert.h> |
| 34 | |
| 35 | namespace rfb { |
| 36 | |
| 37 | // CONCAT2E concatenates its arguments, expanding them if they are macros |
| 38 | |
| 39 | #ifndef CONCAT2E |
| 40 | #define CONCAT2(a,b) a##b |
| 41 | #define CONCAT2E(a,b) CONCAT2(a,b) |
| 42 | #endif |
| 43 | |
| 44 | #define PIXEL_T rdr::CONCAT2E(U,BPP) |
| 45 | #define READ_PIXEL CONCAT2E(readOpaque,BPP) |
DRC | 33c15e3 | 2011-11-03 18:49:21 +0000 | [diff] [blame] | 46 | #define TIGHT_DECODE TightDecoder::CONCAT2E(tightDecode,BPP) |
| 47 | #define DECOMPRESS_JPEG_RECT TightDecoder::CONCAT2E(DecompressJpegRect,BPP) |
| 48 | #define FILTER_GRADIENT TightDecoder::CONCAT2E(FilterGradient,BPP) |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 49 | |
| 50 | #define TIGHT_MIN_TO_COMPRESS 12 |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 51 | |
| 52 | // Main function implementing Tight decoder |
| 53 | |
DRC | 33c15e3 | 2011-11-03 18:49:21 +0000 | [diff] [blame] | 54 | void TIGHT_DECODE (const Rect& r) |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 55 | { |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 56 | bool cutZeros = false; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 57 | #if BPP == 32 |
DRC | 33c15e3 | 2011-11-03 18:49:21 +0000 | [diff] [blame] | 58 | if (serverpf.is888()) { |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 59 | cutZeros = true; |
| 60 | } |
| 61 | #endif |
| 62 | |
| 63 | rdr::U8 comp_ctl = is->readU8(); |
| 64 | |
| 65 | // Flush zlib streams if we are told by the server to do so. |
| 66 | for (int i = 0; i < 4; i++) { |
| 67 | if (comp_ctl & 1) { |
| 68 | zis[i].reset(); |
| 69 | } |
| 70 | comp_ctl >>= 1; |
| 71 | } |
| 72 | |
| 73 | // "Fill" compression type. |
| 74 | if (comp_ctl == rfbTightFill) { |
| 75 | PIXEL_T pix; |
| 76 | if (cutZeros) { |
DRC | 33c15e3 | 2011-11-03 18:49:21 +0000 | [diff] [blame] | 77 | rdr::U8 bytebuf[3]; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 78 | is->readBytes(bytebuf, 3); |
DRC | 33c15e3 | 2011-11-03 18:49:21 +0000 | [diff] [blame] | 79 | serverpf.bufferFromRGB((rdr::U8*)&pix, bytebuf, 1, NULL); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 80 | } else { |
| 81 | pix = is->READ_PIXEL(); |
| 82 | } |
DRC | 4f24c1a | 2011-11-03 23:56:10 +0000 | [diff] [blame^] | 83 | FILL_RECT(r, pix); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 84 | return; |
| 85 | } |
| 86 | |
| 87 | // "JPEG" compression type. |
| 88 | if (comp_ctl == rfbTightJpeg) { |
DRC | 33c15e3 | 2011-11-03 18:49:21 +0000 | [diff] [blame] | 89 | DECOMPRESS_JPEG_RECT(r); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 90 | return; |
| 91 | } |
| 92 | |
| 93 | // Quit on unsupported compression type. |
| 94 | if (comp_ctl > rfbTightMaxSubencoding) { |
| 95 | throw Exception("TightDecoder: bad subencoding value received"); |
| 96 | return; |
| 97 | } |
| 98 | |
| 99 | // "Basic" compression type. |
| 100 | int palSize = 0; |
| 101 | static PIXEL_T palette[256]; |
| 102 | bool useGradient = false; |
| 103 | |
| 104 | if ((comp_ctl & rfbTightExplicitFilter) != 0) { |
| 105 | rdr::U8 filterId = is->readU8(); |
| 106 | |
| 107 | switch (filterId) { |
| 108 | case rfbTightFilterPalette: |
| 109 | palSize = is->readU8() + 1; |
| 110 | if (cutZeros) { |
Pierre Ossman | 7c4efd7 | 2010-09-30 11:30:20 +0000 | [diff] [blame] | 111 | rdr::U8 elem[3]; |
| 112 | for (int i = 0;i < palSize;i++) { |
| 113 | is->readBytes(elem, 3); |
DRC | 33c15e3 | 2011-11-03 18:49:21 +0000 | [diff] [blame] | 114 | serverpf.bufferFromRGB((rdr::U8*)&palette[i], elem, 1, NULL); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 115 | } |
| 116 | } else { |
DRC | 33c15e3 | 2011-11-03 18:49:21 +0000 | [diff] [blame] | 117 | for (int i = 0; i < palSize; i++) |
| 118 | palette[i] = is->READ_PIXEL(); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 119 | } |
| 120 | break; |
| 121 | case rfbTightFilterGradient: |
| 122 | useGradient = true; |
| 123 | break; |
| 124 | case rfbTightFilterCopy: |
| 125 | break; |
| 126 | default: |
| 127 | throw Exception("TightDecoder: unknown filter code received"); |
| 128 | return; |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | int bppp = BPP; |
| 133 | if (palSize != 0) { |
| 134 | bppp = (palSize <= 2) ? 1 : 8; |
| 135 | } else if (cutZeros) { |
| 136 | bppp = 24; |
| 137 | } |
| 138 | |
| 139 | // Determine if the data should be decompressed or just copied. |
| 140 | int rowSize = (r.width() * bppp + 7) / 8; |
| 141 | int dataSize = r.height() * rowSize; |
| 142 | int streamId = -1; |
| 143 | rdr::InStream *input; |
| 144 | if (dataSize < TIGHT_MIN_TO_COMPRESS) { |
| 145 | input = is; |
| 146 | } else { |
| 147 | int length = is->readCompactLength(); |
| 148 | streamId = comp_ctl & 0x03; |
| 149 | zis[streamId].setUnderlying(is, length); |
| 150 | input = &zis[streamId]; |
| 151 | } |
| 152 | |
DRC | 33c15e3 | 2011-11-03 18:49:21 +0000 | [diff] [blame] | 153 | PIXEL_T *buf; |
| 154 | int stride = r.width(); |
| 155 | if (directDecode) buf = (PIXEL_T *)handler->getRawPixelsRW(r, &stride); |
| 156 | else buf = (PIXEL_T *)reader->getImageBuf(r.area()); |
| 157 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 158 | if (palSize == 0) { |
| 159 | // Truecolor data |
| 160 | if (useGradient) { |
| 161 | #if BPP == 32 |
| 162 | if (cutZeros) { |
DRC | 33c15e3 | 2011-11-03 18:49:21 +0000 | [diff] [blame] | 163 | FilterGradient24(input, buf, stride, r, dataSize); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 164 | } else |
| 165 | #endif |
DRC | 33c15e3 | 2011-11-03 18:49:21 +0000 | [diff] [blame] | 166 | { |
| 167 | FILTER_GRADIENT(input, buf, stride, r, dataSize); |
| 168 | } |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 169 | } else { |
DRC | 33c15e3 | 2011-11-03 18:49:21 +0000 | [diff] [blame] | 170 | // Copy |
| 171 | int h = r.height(); |
| 172 | PIXEL_T *ptr = buf; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 173 | if (cutZeros) { |
DRC | 33c15e3 | 2011-11-03 18:49:21 +0000 | [diff] [blame] | 174 | int w = r.width(), pad = stride - w; |
Pierre Ossman | 7c4efd7 | 2010-09-30 11:30:20 +0000 | [diff] [blame] | 175 | rdr::U8 elem[3]; |
DRC | 33c15e3 | 2011-11-03 18:49:21 +0000 | [diff] [blame] | 176 | while (h > 0) { |
| 177 | PIXEL_T *endOfRow = ptr + w; |
| 178 | while (ptr < endOfRow) { |
| 179 | input->readBytes(elem, 3); |
| 180 | serverpf.bufferFromRGB((rdr::U8*)ptr++, elem, 1, NULL); |
| 181 | } |
| 182 | ptr += pad; |
| 183 | h--; |
Pierre Ossman | 7c4efd7 | 2010-09-30 11:30:20 +0000 | [diff] [blame] | 184 | } |
| 185 | } else { |
DRC | 33c15e3 | 2011-11-03 18:49:21 +0000 | [diff] [blame] | 186 | while (h > 0) { |
| 187 | input->readBytes(ptr, rowSize); |
| 188 | ptr += stride; |
| 189 | h--; |
| 190 | } |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 191 | } |
| 192 | } |
| 193 | } else { |
DRC | 33c15e3 | 2011-11-03 18:49:21 +0000 | [diff] [blame] | 194 | // Indexed color |
| 195 | int x, h = r.height(), w = r.width(), b, pad = stride - w; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 196 | PIXEL_T *ptr = buf; |
| 197 | rdr::U8 bits; |
| 198 | if (palSize <= 2) { |
| 199 | // 2-color palette |
DRC | 33c15e3 | 2011-11-03 18:49:21 +0000 | [diff] [blame] | 200 | while (h > 0) { |
| 201 | for (x = 0; x < w / 8; x++) { |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 202 | bits = input->readU8(); |
| 203 | for (b = 7; b >= 0; b--) { |
| 204 | *ptr++ = palette[bits >> b & 1]; |
DRC | 33c15e3 | 2011-11-03 18:49:21 +0000 | [diff] [blame] | 205 | } |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 206 | } |
DRC | 33c15e3 | 2011-11-03 18:49:21 +0000 | [diff] [blame] | 207 | if (w % 8 != 0) { |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 208 | bits = input->readU8(); |
DRC | 33c15e3 | 2011-11-03 18:49:21 +0000 | [diff] [blame] | 209 | for (b = 7; b >= 8 - w % 8; b--) { |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 210 | *ptr++ = palette[bits >> b & 1]; |
| 211 | } |
| 212 | } |
DRC | 33c15e3 | 2011-11-03 18:49:21 +0000 | [diff] [blame] | 213 | ptr += pad; |
| 214 | h--; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 215 | } |
| 216 | } else { |
| 217 | // 256-color palette |
DRC | 33c15e3 | 2011-11-03 18:49:21 +0000 | [diff] [blame] | 218 | while (h > 0) { |
| 219 | PIXEL_T *endOfRow = ptr + w; |
| 220 | while (ptr < endOfRow) { |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 221 | *ptr++ = palette[input->readU8()]; |
DRC | 33c15e3 | 2011-11-03 18:49:21 +0000 | [diff] [blame] | 222 | } |
| 223 | ptr += pad; |
| 224 | h--; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 225 | } |
| 226 | } |
| 227 | } |
| 228 | |
DRC | 33c15e3 | 2011-11-03 18:49:21 +0000 | [diff] [blame] | 229 | if (directDecode) handler->releaseRawPixels(r); |
| 230 | else IMAGE_RECT(r, buf); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 231 | |
| 232 | if (streamId != -1) { |
| 233 | zis[streamId].reset(); |
| 234 | } |
| 235 | } |
| 236 | |
DRC | 33c15e3 | 2011-11-03 18:49:21 +0000 | [diff] [blame] | 237 | void |
| 238 | DECOMPRESS_JPEG_RECT(const Rect& r) |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 239 | { |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 240 | // Read length |
| 241 | int compressedLen = is->readCompactLength(); |
| 242 | if (compressedLen <= 0) { |
| 243 | throw Exception("Incorrect data received from the server.\n"); |
| 244 | } |
| 245 | |
| 246 | // Allocate netbuf and read in data |
| 247 | rdr::U8* netbuf = new rdr::U8[compressedLen]; |
| 248 | if (!netbuf) { |
| 249 | throw Exception("rfb::tightDecode unable to allocate buffer"); |
| 250 | } |
| 251 | is->readBytes(netbuf, compressedLen); |
| 252 | |
DRC | 33c15e3 | 2011-11-03 18:49:21 +0000 | [diff] [blame] | 253 | // We always use direct decoding with JPEG images |
| 254 | int stride; |
| 255 | rdr::U8 *buf = handler->getRawPixelsRW(r, &stride); |
| 256 | jd.decompress(netbuf, compressedLen, buf, stride * clientpf.bpp / 8, r, |
| 257 | clientpf); |
| 258 | handler->releaseRawPixels(r); |
DRC | e420dcb | 2009-04-06 07:20:34 +0000 | [diff] [blame] | 259 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 260 | delete [] netbuf; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | #if BPP == 32 |
| 264 | |
DRC | 33c15e3 | 2011-11-03 18:49:21 +0000 | [diff] [blame] | 265 | void |
| 266 | TightDecoder::FilterGradient24(rdr::InStream* is, PIXEL_T* buf, int stride, |
| 267 | const Rect& r, int dataSize) |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 268 | { |
| 269 | int x, y, c; |
| 270 | static rdr::U8 prevRow[TIGHT_MAX_WIDTH*3]; |
| 271 | static rdr::U8 thisRow[TIGHT_MAX_WIDTH*3]; |
| 272 | rdr::U8 pix[3]; |
| 273 | int est[3]; |
| 274 | |
| 275 | memset(prevRow, 0, sizeof(prevRow)); |
| 276 | |
| 277 | // Allocate netbuf and read in data |
| 278 | rdr::U8 *netbuf = new rdr::U8[dataSize]; |
| 279 | if (!netbuf) { |
| 280 | throw Exception("rfb::tightDecode unable to allocate buffer"); |
| 281 | } |
| 282 | is->readBytes(netbuf, dataSize); |
| 283 | |
| 284 | // Set up shortcut variables |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 285 | int rectHeight = r.height(); |
| 286 | int rectWidth = r.width(); |
| 287 | |
| 288 | for (y = 0; y < rectHeight; y++) { |
| 289 | /* First pixel in a row */ |
| 290 | for (c = 0; c < 3; c++) { |
| 291 | pix[c] = netbuf[y*rectWidth*3+c] + prevRow[c]; |
| 292 | thisRow[c] = pix[c]; |
| 293 | } |
DRC | 33c15e3 | 2011-11-03 18:49:21 +0000 | [diff] [blame] | 294 | serverpf.bufferFromRGB((rdr::U8*)&buf[y*stride], pix, 1, NULL); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 295 | |
| 296 | /* Remaining pixels of a row */ |
| 297 | for (x = 1; x < rectWidth; x++) { |
| 298 | for (c = 0; c < 3; c++) { |
DRC | 33c15e3 | 2011-11-03 18:49:21 +0000 | [diff] [blame] | 299 | est[c] = prevRow[x*3+c] + pix[c] - prevRow[(x-1)*3+c]; |
| 300 | if (est[c] > 0xff) { |
| 301 | est[c] = 0xff; |
| 302 | } else if (est[c] < 0) { |
| 303 | est[c] = 0; |
| 304 | } |
| 305 | pix[c] = netbuf[(y*rectWidth+x)*3+c] + est[c]; |
| 306 | thisRow[x*3+c] = pix[c]; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 307 | } |
DRC | 33c15e3 | 2011-11-03 18:49:21 +0000 | [diff] [blame] | 308 | serverpf.bufferFromRGB((rdr::U8*)&buf[y*stride+x], pix, 1, NULL); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | memcpy(prevRow, thisRow, sizeof(prevRow)); |
| 312 | } |
| 313 | |
| 314 | delete [] netbuf; |
| 315 | } |
| 316 | |
| 317 | #endif |
| 318 | |
DRC | 33c15e3 | 2011-11-03 18:49:21 +0000 | [diff] [blame] | 319 | void |
| 320 | FILTER_GRADIENT(rdr::InStream* is, PIXEL_T* buf, int stride, const Rect& r, |
| 321 | int dataSize) |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 322 | { |
| 323 | int x, y, c; |
| 324 | static rdr::U8 prevRow[TIGHT_MAX_WIDTH*sizeof(PIXEL_T)]; |
| 325 | static rdr::U8 thisRow[TIGHT_MAX_WIDTH*sizeof(PIXEL_T)]; |
Pierre Ossman | 67b2b2f | 2009-03-06 10:12:55 +0000 | [diff] [blame] | 326 | rdr::U8 pix[3]; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 327 | int est[3]; |
| 328 | |
| 329 | memset(prevRow, 0, sizeof(prevRow)); |
| 330 | |
| 331 | // Allocate netbuf and read in data |
| 332 | PIXEL_T *netbuf = (PIXEL_T*)new rdr::U8[dataSize]; |
| 333 | if (!netbuf) { |
| 334 | throw Exception("rfb::tightDecode unable to allocate buffer"); |
| 335 | } |
| 336 | is->readBytes(netbuf, dataSize); |
| 337 | |
| 338 | // Set up shortcut variables |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 339 | int rectHeight = r.height(); |
| 340 | int rectWidth = r.width(); |
| 341 | |
| 342 | for (y = 0; y < rectHeight; y++) { |
| 343 | /* First pixel in a row */ |
DRC | 33c15e3 | 2011-11-03 18:49:21 +0000 | [diff] [blame] | 344 | serverpf.rgbFromBuffer(pix, (rdr::U8*)&netbuf[y*rectWidth], 1, NULL); |
Pierre Ossman | 67b2b2f | 2009-03-06 10:12:55 +0000 | [diff] [blame] | 345 | for (c = 0; c < 3; c++) |
| 346 | pix[c] += prevRow[c]; |
| 347 | |
| 348 | memcpy(thisRow, pix, sizeof(pix)); |
| 349 | |
DRC | 33c15e3 | 2011-11-03 18:49:21 +0000 | [diff] [blame] | 350 | serverpf.bufferFromRGB((rdr::U8*)&buf[y*stride], pix, 1, NULL); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 351 | |
| 352 | /* Remaining pixels of a row */ |
| 353 | for (x = 1; x < rectWidth; x++) { |
| 354 | for (c = 0; c < 3; c++) { |
Pierre Ossman | 67b2b2f | 2009-03-06 10:12:55 +0000 | [diff] [blame] | 355 | est[c] = prevRow[x*3+c] + pix[c] - prevRow[(x-1)*3+c]; |
| 356 | if (est[c] > 255) { |
| 357 | est[c] = 255; |
| 358 | } else if (est[c] < 0) { |
| 359 | est[c] = 0; |
| 360 | } |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 361 | } |
Pierre Ossman | 67b2b2f | 2009-03-06 10:12:55 +0000 | [diff] [blame] | 362 | |
DRC | 33c15e3 | 2011-11-03 18:49:21 +0000 | [diff] [blame] | 363 | serverpf.rgbFromBuffer(pix, (rdr::U8*)&netbuf[y*rectWidth+x], 1, NULL); |
Pierre Ossman | 67b2b2f | 2009-03-06 10:12:55 +0000 | [diff] [blame] | 364 | for (c = 0; c < 3; c++) |
| 365 | pix[c] += est[c]; |
| 366 | |
| 367 | memcpy(&thisRow[x*3], pix, sizeof(pix)); |
| 368 | |
DRC | 33c15e3 | 2011-11-03 18:49:21 +0000 | [diff] [blame] | 369 | serverpf.bufferFromRGB((rdr::U8*)&buf[y*stride+x], pix, 1, NULL); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | memcpy(prevRow, thisRow, sizeof(prevRow)); |
| 373 | } |
| 374 | |
| 375 | delete [] netbuf; |
| 376 | } |
| 377 | |
| 378 | #undef TIGHT_MIN_TO_COMPRESS |
DRC | 33c15e3 | 2011-11-03 18:49:21 +0000 | [diff] [blame] | 379 | #undef FILTER_GRADIENT |
| 380 | #undef DECOMPRESS_JPEG_RECT |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 381 | #undef TIGHT_DECODE |
| 382 | #undef READ_PIXEL |
| 383 | #undef PIXEL_T |
| 384 | } |