ZRLE sort of works now

tight-png
Andri Yngvason 2019-08-27 18:17:33 +00:00 committed by Andri Yngvason
parent 6091721a9a
commit e294685304
2 changed files with 19 additions and 11 deletions

View File

@ -450,8 +450,14 @@ static int on_client_set_encodings(struct vnc_client *client)
return sizeof(*msg) + 4 * n_encodings; return sizeof(*msg) + 4 * n_encodings;
} }
static int is_done= 0;
static int on_client_fb_update_request(struct vnc_client *client) static int on_client_fb_update_request(struct vnc_client *client)
{ {
if (is_done)
return 0;
is_done = 1;
struct rfb_client_fb_update_req_msg *msg = struct rfb_client_fb_update_req_msg *msg =
(struct rfb_client_fb_update_req_msg*)(client->msg_buffer + (struct rfb_client_fb_update_req_msg*)(client->msg_buffer +
client->buffer_index); client->buffer_index);
@ -688,7 +694,7 @@ int main(int argc, char *argv[])
struct vnc_server server = { 0 }; struct vnc_server server = { 0 };
server.fb = &fb; server.fb = &fb;
server.display.pixfmt = DRM_FORMAT_RGBX8888; server.display.pixfmt = DRM_FORMAT_XRGB8888;
server.display.width = fb.width; server.display.width = fb.width;
server.display.height = fb.height; server.display.height = fb.height;
server.display.name = argv[1]; server.display.name = argv[1];

22
zrle.c
View File

@ -155,7 +155,7 @@ void zrle_encode_tile(uint8_t *dst, const struct rfb_pixel_format *dst_fmt,
dst[0] = 0; /* Sub-encoding is raw pixel data */ dst[0] = 0; /* Sub-encoding is raw pixel data */
for (int y = 0; y < height; ++y) for (int y = 0; y < height; ++y)
pixel32_to_cpixel(dst + 1 + width * y, pixel32_to_cpixel(dst + 1 + width * y * bytes_per_cpixel,
dst_fmt, src + stride * y, dst_fmt, src + stride * y,
src_fmt, bytes_per_cpixel, width); src_fmt, bytes_per_cpixel, width);
} }
@ -177,7 +177,7 @@ int zrle_encode_box(uv_stream_t *stream, const struct rfb_pixel_format *dst_fmt,
if (!in) if (!in)
goto failure; goto failure;
if (vec_init(&out, bytes_per_cpixel * width * height / 2) < 0) if (vec_init(&out, bytes_per_cpixel * width * height * 2) < 0)
goto failure; goto failure;
r = deflateInit(&zs, Z_DEFAULT_COMPRESSION); r = deflateInit(&zs, Z_DEFAULT_COMPRESSION);
@ -204,24 +204,24 @@ int zrle_encode_box(uv_stream_t *stream, const struct rfb_pixel_format *dst_fmt,
src_fmt, stride, tile_width, tile_height); src_fmt, stride, tile_width, tile_height);
zs.next_in = in; zs.next_in = in;
zs.avail_in = tile_width * tile_height * 4; zs.avail_in = 1 + tile_width * tile_height * bytes_per_cpixel;
int flush = (i == n_tiles - 1) ? Z_FINISH : Z_NO_FLUSH; int flush = (i == n_tiles - 1) ? Z_FINISH : Z_NO_FLUSH;
do { do {
zs.next_out = ((Bytef*)out.data) + out.len; /*
r = vec_reserve(&out, out.len + chunk_size); r = vec_reserve(&out, out.len + chunk_size);
if (r < 0) if (r < 0)
goto failure; goto failure;
*/
zs.next_out = ((Bytef*)out.data) + out.len;
zs.avail_out = out.cap - out.len; zs.avail_out = out.cap - out.len;
zr = deflate(&zs, flush); zr = deflate(&zs, flush);
assert(zr != Z_STREAM_ERROR); assert(zr != Z_STREAM_ERROR);
int have = out.cap - out.len - zs.avail_out; out.len = out.cap - zs.avail_out;
out.len += have;
} while (zs.avail_out == 0); } while (zs.avail_out == 0);
assert(zs.avail_in == 0); assert(zs.avail_in == 0);
@ -232,11 +232,13 @@ int zrle_encode_box(uv_stream_t *stream, const struct rfb_pixel_format *dst_fmt,
deflateEnd(&zs); deflateEnd(&zs);
uint32_t *out_size = out.data; uint32_t *out_size = out.data;
*out_size = htonl(out.len); *out_size = htonl(out.len - 8);
r = vnc__write(stream, out.data, out.len, NULL); printf("Sending %lu bytes\n", out.len - 4);
r = vnc__write(stream, out.data, out.len - 4, NULL);
failure: failure:
vec_destroy(&out); // vec_destroy(&out);
free(in); free(in);
return r; return r;
#undef CHUNK #undef CHUNK