File: zrle.cxx

package info (click to toggle)
vncsnapshot 1.2a-5.1
  • links: PTS
  • area: main
  • in suites: bullseye, buster, jessie, jessie-kfreebsd, stretch, wheezy
  • size: 604 kB
  • ctags: 1,088
  • sloc: ansic: 3,852; cpp: 1,394; makefile: 136; sh: 98
file content (115 lines) | stat: -rw-r--r-- 3,074 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//
// Copyright (C) 2002 RealVNC Ltd.  All Rights Reserved.
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this software; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
// USA.

//
// zrle.cxx
//
// Decode function for Zlib Run-length Encoding (ZRLE).
//

#include <rdr/ZlibInStream.h>
#include <rdr/FdInStream.h>
#include <rdr/Exception.h>

extern "C" {
#include "vncsnapshot.h"
}

// Instantiate the decoding function for 8, 16 and 32 BPP

#define IMAGE_RECT(x,y,w,h,data)                \
    CopyDataToScreen((char*)data,x,y,w,h);

#define FILL_RECT(x,y,w,h,pix)                                          \
    FillBufferRectangle(x, y, w, h, pix);

#define BPP 8
#include <rfb/zrleDecode.h>
#undef BPP

#undef FILL_RECT
#define FILL_RECT(x,y,w,h,pix)                          \
    FillBufferRectangle(x, y, w, h, pix);

#define BPP 16
#include <rfb/zrleDecode.h>
#undef BPP
#define BPP 32
#include <rfb/zrleDecode.h>
#define CPIXEL 24A
#include <rfb/zrleDecode.h>
#undef CPIXEL
#define CPIXEL 24B
#include <rfb/zrleDecode.h>
#undef CPIXEL
#undef BPP


#define BUFFER_SIZE (rfbZRLETileWidth * rfbZRLETileHeight * 4)
static char buffer[BUFFER_SIZE];

rdr::ZlibInStream zis;
extern rdr::FdInStream* fis;

Bool zrleDecode(int x, int y, int w, int h)
{
  try {
    switch (myFormat.bitsPerPixel) {

    case 8:
      zrleDecode8( x,y,w,h,fis,&zis,(rdr::U8*)buffer);
      break;

    case 16:
      zrleDecode16(x,y,w,h,fis,&zis,(rdr::U16*)buffer);
      break;

    case 32:
      bool fitsInLS3Bytes
        = ((myFormat.redMax   << myFormat.redShift)   < (1<<24) &&
           (myFormat.greenMax << myFormat.greenShift) < (1<<24) &&
           (myFormat.blueMax  << myFormat.blueShift)  < (1<<24));

      bool fitsInMS3Bytes = (myFormat.redShift   > 7  &&
                             myFormat.greenShift > 7  &&
                             myFormat.blueShift  > 7);

      if ((fitsInLS3Bytes && !myFormat.bigEndian) ||
          (fitsInMS3Bytes && myFormat.bigEndian))
      {
        zrleDecode24A(x,y,w,h,fis,&zis,(rdr::U32*)buffer);
      }
      else if ((fitsInLS3Bytes && myFormat.bigEndian) ||
               (fitsInMS3Bytes && !myFormat.bigEndian))
      {
        zrleDecode24B(x,y,w,h,fis,&zis,(rdr::U32*)buffer);
      }
      else
      {
        zrleDecode32(x,y,w,h,fis,&zis,(rdr::U32*)buffer);
      }
      break;
    }

  } catch (rdr::Exception& e) {
    fprintf(stderr,"ZRLE decoder exception: %s\n",e.str());
    return False;
  }

  return True;
}