neatvnc/examples/png-server.c

61 lines
1.7 KiB
C
Raw Permalink Normal View History

2019-09-07 16:51:07 +00:00
/*
* Copyright (c) 2019 Andri Yngvason
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
2019-08-29 22:07:04 +00:00
#include "neatvnc.h"
#include <stdio.h>
#include <uv.h>
#include <assert.h>
#include <pixman.h>
2019-10-20 22:13:51 +00:00
struct nvnc_fb* read_png_file(const char* filename);
2019-08-29 22:07:04 +00:00
2019-10-20 22:13:51 +00:00
int main(int argc, char* argv[])
2019-08-29 22:07:04 +00:00
{
2019-10-20 22:13:51 +00:00
const char* file = argv[1];
2019-08-29 22:07:04 +00:00
if (!file) {
printf("Missing argument\n");
return 1;
}
2019-10-07 17:39:54 +00:00
struct nvnc_fb* fb = read_png_file(file);
if (!fb) {
2019-08-29 22:07:04 +00:00
printf("Failed to read png file\n");
return 1;
}
2019-10-20 22:13:51 +00:00
struct nvnc* server = nvnc_open("127.0.0.1", 5900);
2019-08-29 22:07:04 +00:00
2019-10-07 17:39:54 +00:00
int width = nvnc_fb_get_width(fb);
int height = nvnc_fb_get_height(fb);
uint32_t fourcc_format = nvnc_fb_get_fourcc_format(fb);
nvnc_set_dimensions(server, width, height, fourcc_format);
2019-08-29 22:07:04 +00:00
nvnc_set_name(server, file);
struct pixman_region16 region;
pixman_region_init_rect(&region, 0, 0, nvnc_fb_get_width(fb),
2019-10-20 22:13:51 +00:00
nvnc_fb_get_height(fb));
nvnc_feed_frame(server, fb, &region);
pixman_region_fini(&region);
2019-08-29 22:07:04 +00:00
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
nvnc_close(server);
2019-10-07 17:39:54 +00:00
nvnc_fb_unref(fb);
2019-08-29 22:07:04 +00:00
}