1 #define CONCAT_I(a, b) a ## b
2 #define CONCAT(a, b) CONCAT_I(a, b)
3 #define pixel_t CONCAT(uint, CONCAT(BPP, _t))
5 #define NAME CONCAT(generic_, BPP)
10 #define MAX_BYTES_PER_PIXEL 4
12 static void CONCAT(send_hextile_tile_
, NAME
)(VncState
*vs
,
13 int x
, int y
, int w
, int h
,
16 int *has_bg
, int *has_fg
)
18 VncDisplay
*vd
= vs
->vd
;
19 uint8_t *row
= vnc_server_fb_ptr(vd
, x
, y
);
20 pixel_t
*irow
= (pixel_t
*)row
;
22 pixel_t
*last_bg
= (pixel_t
*)last_bg_
;
23 pixel_t
*last_fg
= (pixel_t
*)last_fg_
;
30 uint8_t data
[(MAX_BYTES_PER_PIXEL
+ 2) * 16 * 16];
34 /* Enforced by set_pixel_format() */
35 assert(vs
->client_pf
.bytes_per_pixel
<= MAX_BYTES_PER_PIXEL
);
37 for (j
= 0; j
< h
; j
++) {
38 for (i
= 0; i
< w
; i
++) {
51 if (irow
[i
] != bg
&& irow
[i
] != fg
) {
56 else if (irow
[i
] == fg
)
66 irow
+= vnc_server_fb_stride(vd
) / sizeof(pixel_t
);
69 if (n_colors
> 1 && fg_count
> bg_count
) {
75 if (!*has_bg
|| *last_bg
!= bg
) {
81 if (n_colors
< 3 && (!*has_fg
|| *last_fg
!= fg
)) {
94 irow
= (pixel_t
*)row
;
96 for (j
= 0; j
< h
; j
++) {
98 for (i
= 0; i
< w
; i
++) {
102 } else if (min_x
!= -1) {
103 hextile_enc_cord(data
+ n_data
, min_x
, j
, i
- min_x
, 1);
110 hextile_enc_cord(data
+ n_data
, min_x
, j
, i
- min_x
, 1);
114 irow
+= vnc_server_fb_stride(vd
) / sizeof(pixel_t
);
120 irow
= (pixel_t
*)row
;
122 if (!*has_bg
|| *last_bg
!= bg
)
125 for (j
= 0; j
< h
; j
++) {
128 pixel_t color
= 0; /* shut up gcc */
130 for (i
= 0; i
< w
; i
++) {
137 } else if (irow
[i
] != color
) {
140 vnc_convert_pixel(vs
, data
+ n_data
, color
);
141 n_data
+= vs
->client_pf
.bytes_per_pixel
;
143 memcpy(data
+ n_data
, &color
, sizeof(color
));
144 n_data
+= sizeof(pixel_t
);
146 hextile_enc_cord(data
+ n_data
, min_x
, j
, i
- min_x
, 1);
160 vnc_convert_pixel(vs
, data
+ n_data
, color
);
161 n_data
+= vs
->client_pf
.bytes_per_pixel
;
163 memcpy(data
+ n_data
, &color
, sizeof(color
));
164 n_data
+= sizeof(pixel_t
);
166 hextile_enc_cord(data
+ n_data
, min_x
, j
, i
- min_x
, 1);
170 irow
+= vnc_server_fb_stride(vd
) / sizeof(pixel_t
);
173 /* A SubrectsColoured subtile invalidates the foreground color */
175 if (n_data
> (w
* h
* sizeof(pixel_t
))) {
180 /* we really don't have to invalidate either the bg or fg
181 but we've lost the old values. oh well. */
195 vnc_write_u8(vs
, flags
);
198 vs
->write_pixels(vs
, last_bg
, sizeof(pixel_t
));
200 vs
->write_pixels(vs
, last_fg
, sizeof(pixel_t
));
202 vnc_write_u8(vs
, n_subtiles
);
203 vnc_write(vs
, data
, n_data
);
206 for (j
= 0; j
< h
; j
++) {
207 vs
->write_pixels(vs
, row
, w
* 4);
208 row
+= vnc_server_fb_stride(vd
);
213 #undef MAX_BYTES_PER_PIXEL