root / ui / vnc-enc-tight.h @ d2d979c6
History | View | Annotate | Download (8.3 kB)
1 | 380282b0 | Corentin Chary | /*
|
---|---|---|---|
2 | 380282b0 | Corentin Chary | * QEMU VNC display driver: tight encoding
|
3 | 380282b0 | Corentin Chary | *
|
4 | 380282b0 | Corentin Chary | * From libvncserver/rfb/rfbproto.h
|
5 | 380282b0 | Corentin Chary | * Copyright (C) 2005 Rohit Kumar, Johannes E. Schindelin
|
6 | 380282b0 | Corentin Chary | * Copyright (C) 2000-2002 Constantin Kaplinsky. All Rights Reserved.
|
7 | 380282b0 | Corentin Chary | * Copyright (C) 2000 Tridia Corporation. All Rights Reserved.
|
8 | 380282b0 | Corentin Chary | * Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
|
9 | 380282b0 | Corentin Chary | *
|
10 | 380282b0 | Corentin Chary | *
|
11 | 380282b0 | Corentin Chary | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
12 | 380282b0 | Corentin Chary | * of this software and associated documentation files (the "Software"), to deal
|
13 | 380282b0 | Corentin Chary | * in the Software without restriction, including without limitation the rights
|
14 | 380282b0 | Corentin Chary | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
15 | 380282b0 | Corentin Chary | * copies of the Software, and to permit persons to whom the Software is
|
16 | 380282b0 | Corentin Chary | * furnished to do so, subject to the following conditions:
|
17 | 380282b0 | Corentin Chary | *
|
18 | 380282b0 | Corentin Chary | * The above copyright notice and this permission notice shall be included in
|
19 | 380282b0 | Corentin Chary | * all copies or substantial portions of the Software.
|
20 | 380282b0 | Corentin Chary | *
|
21 | 380282b0 | Corentin Chary | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
22 | 380282b0 | Corentin Chary | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
23 | 380282b0 | Corentin Chary | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
24 | 380282b0 | Corentin Chary | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
25 | 380282b0 | Corentin Chary | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
26 | 380282b0 | Corentin Chary | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
27 | 380282b0 | Corentin Chary | * THE SOFTWARE.
|
28 | 380282b0 | Corentin Chary | */
|
29 | 380282b0 | Corentin Chary | |
30 | 380282b0 | Corentin Chary | #ifndef VNC_ENCODING_TIGHT_H
|
31 | 380282b0 | Corentin Chary | #define VNC_ENCODING_TIGHT_H
|
32 | 380282b0 | Corentin Chary | |
33 | 380282b0 | Corentin Chary | /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
34 | 380282b0 | Corentin Chary | * Tight Encoding.
|
35 | 380282b0 | Corentin Chary | *
|
36 | 380282b0 | Corentin Chary | *-- The first byte of each Tight-encoded rectangle is a "compression control
|
37 | 380282b0 | Corentin Chary | * byte". Its format is as follows (bit 0 is the least significant one):
|
38 | 380282b0 | Corentin Chary | *
|
39 | 380282b0 | Corentin Chary | * bit 0: if 1, then compression stream 0 should be reset;
|
40 | 380282b0 | Corentin Chary | * bit 1: if 1, then compression stream 1 should be reset;
|
41 | 380282b0 | Corentin Chary | * bit 2: if 1, then compression stream 2 should be reset;
|
42 | 380282b0 | Corentin Chary | * bit 3: if 1, then compression stream 3 should be reset;
|
43 | 380282b0 | Corentin Chary | * bits 7-4: if 1000 (0x08), then the compression type is "fill",
|
44 | 380282b0 | Corentin Chary | * if 1001 (0x09), then the compression type is "jpeg",
|
45 | efe556ad | Corentin Chary | * if 1010 (0x0A), then the compression type is "png",
|
46 | 380282b0 | Corentin Chary | * if 0xxx, then the compression type is "basic",
|
47 | efe556ad | Corentin Chary | * values greater than 1010 are not valid.
|
48 | 380282b0 | Corentin Chary | *
|
49 | 380282b0 | Corentin Chary | * If the compression type is "basic", then bits 6..4 of the
|
50 | 380282b0 | Corentin Chary | * compression control byte (those xxx in 0xxx) specify the following:
|
51 | 380282b0 | Corentin Chary | *
|
52 | 380282b0 | Corentin Chary | * bits 5-4: decimal representation is the index of a particular zlib
|
53 | 380282b0 | Corentin Chary | * stream which should be used for decompressing the data;
|
54 | 380282b0 | Corentin Chary | * bit 6: if 1, then a "filter id" byte is following this byte.
|
55 | 380282b0 | Corentin Chary | *
|
56 | 380282b0 | Corentin Chary | *-- The data that follows after the compression control byte described
|
57 | efe556ad | Corentin Chary | * above depends on the compression type ("fill", "jpeg", "png" or "basic").
|
58 | 380282b0 | Corentin Chary | *
|
59 | 380282b0 | Corentin Chary | *-- If the compression type is "fill", then the only pixel value follows, in
|
60 | 380282b0 | Corentin Chary | * client pixel format (see NOTE 1). This value applies to all pixels of the
|
61 | 380282b0 | Corentin Chary | * rectangle.
|
62 | 380282b0 | Corentin Chary | *
|
63 | efe556ad | Corentin Chary | *-- If the compression type is "jpeg" or "png", the following data stream
|
64 | efe556ad | Corentin Chary | * looks like this:
|
65 | 380282b0 | Corentin Chary | *
|
66 | 380282b0 | Corentin Chary | * 1..3 bytes: data size (N) in compact representation;
|
67 | efe556ad | Corentin Chary | * N bytes: JPEG or PNG image.
|
68 | 380282b0 | Corentin Chary | *
|
69 | 380282b0 | Corentin Chary | * Data size is compactly represented in one, two or three bytes, according
|
70 | 380282b0 | Corentin Chary | * to the following scheme:
|
71 | 380282b0 | Corentin Chary | *
|
72 | 380282b0 | Corentin Chary | * 0xxxxxxx (for values 0..127)
|
73 | 380282b0 | Corentin Chary | * 1xxxxxxx 0yyyyyyy (for values 128..16383)
|
74 | 380282b0 | Corentin Chary | * 1xxxxxxx 1yyyyyyy zzzzzzzz (for values 16384..4194303)
|
75 | 380282b0 | Corentin Chary | *
|
76 | 380282b0 | Corentin Chary | * Here each character denotes one bit, xxxxxxx are the least significant 7
|
77 | 380282b0 | Corentin Chary | * bits of the value (bits 0-6), yyyyyyy are bits 7-13, and zzzzzzzz are the
|
78 | 380282b0 | Corentin Chary | * most significant 8 bits (bits 14-21). For example, decimal value 10000
|
79 | 380282b0 | Corentin Chary | * should be represented as two bytes: binary 10010000 01001110, or
|
80 | 380282b0 | Corentin Chary | * hexadecimal 90 4E.
|
81 | 380282b0 | Corentin Chary | *
|
82 | 380282b0 | Corentin Chary | *-- If the compression type is "basic" and bit 6 of the compression control
|
83 | 380282b0 | Corentin Chary | * byte was set to 1, then the next (second) byte specifies "filter id" which
|
84 | 380282b0 | Corentin Chary | * tells the decoder what filter type was used by the encoder to pre-process
|
85 | 380282b0 | Corentin Chary | * pixel data before the compression. The "filter id" byte can be one of the
|
86 | 380282b0 | Corentin Chary | * following:
|
87 | 380282b0 | Corentin Chary | *
|
88 | 380282b0 | Corentin Chary | * 0: no filter ("copy" filter);
|
89 | 380282b0 | Corentin Chary | * 1: "palette" filter;
|
90 | 380282b0 | Corentin Chary | * 2: "gradient" filter.
|
91 | 380282b0 | Corentin Chary | *
|
92 | 380282b0 | Corentin Chary | *-- If bit 6 of the compression control byte is set to 0 (no "filter id"
|
93 | 380282b0 | Corentin Chary | * byte), or if the filter id is 0, then raw pixel values in the client
|
94 | 380282b0 | Corentin Chary | * format (see NOTE 1) will be compressed. See below details on the
|
95 | 380282b0 | Corentin Chary | * compression.
|
96 | 380282b0 | Corentin Chary | *
|
97 | 380282b0 | Corentin Chary | *-- The "gradient" filter pre-processes pixel data with a simple algorithm
|
98 | 380282b0 | Corentin Chary | * which converts each color component to a difference between a "predicted"
|
99 | 380282b0 | Corentin Chary | * intensity and the actual intensity. Such a technique does not affect
|
100 | 380282b0 | Corentin Chary | * uncompressed data size, but helps to compress photo-like images better.
|
101 | 380282b0 | Corentin Chary | * Pseudo-code for converting intensities to differences is the following:
|
102 | 380282b0 | Corentin Chary | *
|
103 | 380282b0 | Corentin Chary | * P[i,j] := V[i-1,j] + V[i,j-1] - V[i-1,j-1];
|
104 | 380282b0 | Corentin Chary | * if (P[i,j] < 0) then P[i,j] := 0;
|
105 | 380282b0 | Corentin Chary | * if (P[i,j] > MAX) then P[i,j] := MAX;
|
106 | 380282b0 | Corentin Chary | * D[i,j] := V[i,j] - P[i,j];
|
107 | 380282b0 | Corentin Chary | *
|
108 | 380282b0 | Corentin Chary | * Here V[i,j] is the intensity of a color component for a pixel at
|
109 | 380282b0 | Corentin Chary | * coordinates (i,j). MAX is the maximum value of intensity for a color
|
110 | 380282b0 | Corentin Chary | * component.
|
111 | 380282b0 | Corentin Chary | *
|
112 | 380282b0 | Corentin Chary | *-- The "palette" filter converts true-color pixel data to indexed colors
|
113 | 380282b0 | Corentin Chary | * and a palette which can consist of 2..256 colors. If the number of colors
|
114 | 380282b0 | Corentin Chary | * is 2, then each pixel is encoded in 1 bit, otherwise 8 bits is used to
|
115 | 380282b0 | Corentin Chary | * encode one pixel. 1-bit encoding is performed such way that the most
|
116 | 380282b0 | Corentin Chary | * significant bits correspond to the leftmost pixels, and each raw of pixels
|
117 | 380282b0 | Corentin Chary | * is aligned to the byte boundary. When "palette" filter is used, the
|
118 | 380282b0 | Corentin Chary | * palette is sent before the pixel data. The palette begins with an unsigned
|
119 | 380282b0 | Corentin Chary | * byte which value is the number of colors in the palette minus 1 (i.e. 1
|
120 | 380282b0 | Corentin Chary | * means 2 colors, 255 means 256 colors in the palette). Then follows the
|
121 | 380282b0 | Corentin Chary | * palette itself which consist of pixel values in client pixel format (see
|
122 | 380282b0 | Corentin Chary | * NOTE 1).
|
123 | 380282b0 | Corentin Chary | *
|
124 | 380282b0 | Corentin Chary | *-- The pixel data is compressed using the zlib library. But if the data
|
125 | 380282b0 | Corentin Chary | * size after applying the filter but before the compression is less then 12,
|
126 | 380282b0 | Corentin Chary | * then the data is sent as is, uncompressed. Four separate zlib streams
|
127 | 380282b0 | Corentin Chary | * (0..3) can be used and the decoder should read the actual stream id from
|
128 | 380282b0 | Corentin Chary | * the compression control byte (see NOTE 2).
|
129 | 380282b0 | Corentin Chary | *
|
130 | 380282b0 | Corentin Chary | * If the compression is not used, then the pixel data is sent as is,
|
131 | 380282b0 | Corentin Chary | * otherwise the data stream looks like this:
|
132 | 380282b0 | Corentin Chary | *
|
133 | 380282b0 | Corentin Chary | * 1..3 bytes: data size (N) in compact representation;
|
134 | 380282b0 | Corentin Chary | * N bytes: zlib-compressed data.
|
135 | 380282b0 | Corentin Chary | *
|
136 | 380282b0 | Corentin Chary | * Data size is compactly represented in one, two or three bytes, just like
|
137 | 380282b0 | Corentin Chary | * in the "jpeg" compression method (see above).
|
138 | 380282b0 | Corentin Chary | *
|
139 | 380282b0 | Corentin Chary | *-- NOTE 1. If the color depth is 24, and all three color components are
|
140 | 380282b0 | Corentin Chary | * 8-bit wide, then one pixel in Tight encoding is always represented by
|
141 | 380282b0 | Corentin Chary | * three bytes, where the first byte is red component, the second byte is
|
142 | 380282b0 | Corentin Chary | * green component, and the third byte is blue component of the pixel color
|
143 | 380282b0 | Corentin Chary | * value. This applies to colors in palettes as well.
|
144 | 380282b0 | Corentin Chary | *
|
145 | 380282b0 | Corentin Chary | *-- NOTE 2. The decoder must reset compression streams' states before
|
146 | 380282b0 | Corentin Chary | * decoding the rectangle, if some of bits 0,1,2,3 in the compression control
|
147 | 380282b0 | Corentin Chary | * byte are set to 1. Note that the decoder must reset zlib streams even if
|
148 | efe556ad | Corentin Chary | * the compression type is "fill", "jpeg" or "png".
|
149 | 380282b0 | Corentin Chary | *
|
150 | 380282b0 | Corentin Chary | *-- NOTE 3. The "gradient" filter and "jpeg" compression may be used only
|
151 | 380282b0 | Corentin Chary | * when bits-per-pixel value is either 16 or 32, not 8.
|
152 | 380282b0 | Corentin Chary | *
|
153 | 380282b0 | Corentin Chary | *-- NOTE 4. The width of any Tight-encoded rectangle cannot exceed 2048
|
154 | 380282b0 | Corentin Chary | * pixels. If a rectangle is wider, it must be split into several rectangles
|
155 | 380282b0 | Corentin Chary | * and each one should be encoded separately.
|
156 | 380282b0 | Corentin Chary | *
|
157 | 380282b0 | Corentin Chary | */
|
158 | 380282b0 | Corentin Chary | |
159 | 380282b0 | Corentin Chary | #define VNC_TIGHT_EXPLICIT_FILTER 0x04 |
160 | 380282b0 | Corentin Chary | #define VNC_TIGHT_FILL 0x08 |
161 | 380282b0 | Corentin Chary | #define VNC_TIGHT_JPEG 0x09 |
162 | efe556ad | Corentin Chary | #define VNC_TIGHT_PNG 0x0A |
163 | efe556ad | Corentin Chary | #define VNC_TIGHT_MAX_SUBENCODING 0x0A |
164 | 380282b0 | Corentin Chary | |
165 | 380282b0 | Corentin Chary | /* Filters to improve compression efficiency */
|
166 | 380282b0 | Corentin Chary | #define VNC_TIGHT_FILTER_COPY 0x00 |
167 | 380282b0 | Corentin Chary | #define VNC_TIGHT_FILTER_PALETTE 0x01 |
168 | 380282b0 | Corentin Chary | #define VNC_TIGHT_FILTER_GRADIENT 0x02 |
169 | 380282b0 | Corentin Chary | |
170 | 380282b0 | Corentin Chary | /* Note: The following constant should not be changed. */
|
171 | 380282b0 | Corentin Chary | #define VNC_TIGHT_MIN_TO_COMPRESS 12 |
172 | 380282b0 | Corentin Chary | |
173 | 380282b0 | Corentin Chary | /* The parameters below may be adjusted. */
|
174 | 380282b0 | Corentin Chary | #define VNC_TIGHT_MIN_SPLIT_RECT_SIZE 4096 |
175 | 380282b0 | Corentin Chary | #define VNC_TIGHT_MIN_SOLID_SUBRECT_SIZE 2048 |
176 | 380282b0 | Corentin Chary | #define VNC_TIGHT_MAX_SPLIT_TILE_SIZE 16 |
177 | 380282b0 | Corentin Chary | |
178 | 2f6f5c7a | Corentin Chary | #define VNC_TIGHT_JPEG_MIN_RECT_SIZE 4096 |
179 | 2f6f5c7a | Corentin Chary | #define VNC_TIGHT_DETECT_SUBROW_WIDTH 7 |
180 | 2f6f5c7a | Corentin Chary | #define VNC_TIGHT_DETECT_MIN_WIDTH 8 |
181 | 2f6f5c7a | Corentin Chary | #define VNC_TIGHT_DETECT_MIN_HEIGHT 8 |
182 | 2f6f5c7a | Corentin Chary | |
183 | 380282b0 | Corentin Chary | #endif /* VNC_ENCODING_TIGHT_H */ |