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#undef ZYWRLE_ANALYZE
66#undef ZYWRLE_SYNTHESIZE
67
68#define ZYWRLE_SUFFIX ZRLE_CONCAT2(ZRLE_BPP,ZRLE_ENDIAN_SUFFIX)
69
70#define ZYWRLE_ANALYZE ZRLE_CONCAT2(zywrle_analyze_, ZYWRLE_SUFFIX)
71#define ZYWRLE_SYNTHESIZE ZRLE_CONCAT2(zywrle_synthesize_,ZYWRLE_SUFFIX)
72
73#define ZYWRLE_RGBYUV ZRLE_CONCAT2(zywrle_rgbyuv_, ZYWRLE_SUFFIX)
74#define ZYWRLE_YUVRGB ZRLE_CONCAT2(zywrle_yuvrgb_, ZYWRLE_SUFFIX)
75#define ZYWRLE_YMASK ZRLE_CONCAT2(ZYWRLE_YMASK, ZRLE_BPP)
76#define ZYWRLE_UVMASK ZRLE_CONCAT2(ZYWRLE_UVMASK, ZRLE_BPP)
77#define ZYWRLE_LOAD_PIXEL ZRLE_CONCAT2(ZYWRLE_LOAD_PIXEL, ZRLE_BPP)
78#define ZYWRLE_SAVE_PIXEL ZRLE_CONCAT2(ZYWRLE_SAVE_PIXEL, ZRLE_BPP)
79
80
81
82#undef S_0
83#undef S_1
84#undef L_0
85#undef L_1
86#undef L_2
87
88#if ZYWRLE_ENDIAN == ENDIAN_BIG
89# define S_0 1
90# define S_1 0
91# define L_0 3
92# define L_1 2
93# define L_2 1
94#else
95# define S_0 0
96# define S_1 1
97# define L_0 0
98# define L_1 1
99# define L_2 2
100#endif
101
102#define ZYWRLE_QUANTIZE
103#include "vnc-enc-zywrle.h"
104
105#ifndef ZRLE_COMPACT_PIXEL
106static inline void ZYWRLE_RGBYUV(int *buf, ZRLE_PIXEL *data,
107 int width, int height, int scanline)
108{
109 int r, g, b;
110 int y, u, v;
111 int *line;
112 int *end;
113
114 end = buf + height * width;
115 while (buf < end) {
116 line = buf + width;
117 while (buf < line) {
118 ZYWRLE_LOAD_PIXEL(data, r, g, b);
119 ZYWRLE_RGBYUV_(r, g, b, y, u, v, ZYWRLE_YMASK, ZYWRLE_UVMASK);
120 ZYWRLE_SAVE_COEFF(buf, v, y, u);
121 buf++;
122 data++;
123 }
124 data += scanline - width;
125 }
126}
127
128static ZRLE_PIXEL *ZYWRLE_ANALYZE(ZRLE_PIXEL *dst, ZRLE_PIXEL *src,
129 int w, int h, int scanline, int level,
130 int *buf) {
131 int l;
132 int uw = w;
133 int uh = h;
134 int *top;
135 int *end;
136 int *line;
137 ZRLE_PIXEL *p;
138 int r, g, b;
139 int s;
140 int *ph;
141
142 zywrle_calc_size(&w, &h, level);
143
144 if (w == 0 || h == 0) {
145 return NULL;
146 }
147 uw -= w;
148 uh -= h;
149
150 p = dst;
151 ZYWRLE_LOAD_UNALIGN(src,*(ZRLE_PIXEL*)top = *p;);
152 ZYWRLE_RGBYUV(buf, src, w, h, scanline);
153 wavelet(buf, w, h, level);
154 for (l = 0; l < level; l++) {
155 ZYWRLE_PACK_COEFF(buf, dst, 3, w, h, scanline, l);
156 ZYWRLE_PACK_COEFF(buf, dst, 2, w, h, scanline, l);
157 ZYWRLE_PACK_COEFF(buf, dst, 1, w, h, scanline, l);
158 if (l == level - 1) {
159 ZYWRLE_PACK_COEFF(buf, dst, 0, w, h, scanline, l);
160 }
161 }
162 ZYWRLE_SAVE_UNALIGN(dst,*dst = *(ZRLE_PIXEL*)top;);
163 return dst;
164}
165#endif
166
167#undef ZYWRLE_RGBYUV
168#undef ZYWRLE_YUVRGB
169#undef ZYWRLE_LOAD_PIXEL
170#undef ZYWRLE_SAVE_PIXEL
171