From 784af9fa5d2e9f95b254a02fe35f7ffb6678e309 Mon Sep 17 00:00:00 2001 From: Andri Yngvason Date: Sun, 19 Sep 2021 19:54:59 +0000 Subject: [PATCH] Add transform utility functions from wayvnc --- include/transform-util.h | 24 +++++++++ src/transform-util.c | 114 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 138 insertions(+) create mode 100644 include/transform-util.h create mode 100644 src/transform-util.c diff --git a/include/transform-util.h b/include/transform-util.h new file mode 100644 index 0000000..86e66de --- /dev/null +++ b/include/transform-util.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2020 - 2021 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. + */ + +#pragma once + +#include "neatvnc.h" + +#include + +void nvnc_transform_to_pixman_transform(pixman_transform_t* dst, + enum nvnc_transform src, int width, int height); diff --git a/src/transform-util.c b/src/transform-util.c new file mode 100644 index 0000000..a5bfb32 --- /dev/null +++ b/src/transform-util.c @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2020 - 2021 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. + */ + +#include "neatvnc.h" + +#include +#include + +/* Note: This function yields the inverse pixman transform of the + * nvnc_transform. + */ +void nvnc_transform_to_pixman_transform(pixman_transform_t* dst, + enum nvnc_transform src, int width, int height) +{ +#define F1 pixman_fixed_1 + switch (src) { + case NVNC_TRANSFORM_NORMAL: + { + pixman_transform_t t = {{ + { F1, 0, 0 }, + { 0, F1, 0 }, + { 0, 0, F1 }, + }}; + *dst = t; + } + return; + case NVNC_TRANSFORM_90: + { + pixman_transform_t t = {{ + { 0, F1, 0 }, + { -F1, 0, height * F1 }, + { 0, 0, F1 }, + }}; + *dst = t; + } + return; + case NVNC_TRANSFORM_180: + { + pixman_transform_t t = {{ + { -F1, 0, width * F1 }, + { 0, -F1, height * F1 }, + { 0, 0, F1 }, + }}; + *dst = t; + } + return; + case NVNC_TRANSFORM_270: + { + pixman_transform_t t = {{ + { 0, -F1, width * F1 }, + { F1, 0, 0 }, + { 0, 0, F1 }, + }}; + *dst = t; + } + return; + case NVNC_TRANSFORM_FLIPPED: + { + pixman_transform_t t = {{ + { -F1, 0, width * F1 }, + { 0, F1, 0 }, + { 0, 0, F1 }, + }}; + *dst = t; + } + return; + case NVNC_TRANSFORM_FLIPPED_90: + { + pixman_transform_t t = {{ + { 0, F1, 0 }, + { F1, 0, 0 }, + { 0, 0, F1 }, + }}; + *dst = t; + } + return; + case NVNC_TRANSFORM_FLIPPED_180: + { + pixman_transform_t t = {{ + { F1, 0, 0 }, + { 0, -F1, height * F1 }, + { 0, 0, F1 }, + }}; + *dst = t; + } + return; + case NVNC_TRANSFORM_FLIPPED_270: + { + pixman_transform_t t = {{ + { 0, -F1, width * F1 }, + { -F1, 0, height * F1 }, + { 0, 0, F1 }, + }}; + *dst = t; + } + return; + } +#undef F1 + + abort(); +}