From 0c352cad10691992d261e7d0f9ec06fdb801ed34 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Wed, 10 Nov 2021 22:50:28 +0100 Subject: Implement libfonts_calculate_subpixel_order MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- Makefile | 3 +- libfonts.h | 2 +- libfonts_calculate_subpixel_order.c | 60 +++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 libfonts_calculate_subpixel_order.c diff --git a/Makefile b/Makefile index 28289b7..2ea54db 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,8 @@ LIB_VERSION = $(LIB_MAJOR).$(LIB_MINOR) LIB_NAME = fonts -OBJ = +OBJ =\ + libfonts_calculate_subpixel_order.o HDR =\ libfonts.h diff --git a/libfonts.h b/libfonts.h index 211e391..6a988a5 100644 --- a/libfonts.h +++ b/libfonts.h @@ -20,7 +20,7 @@ enum libfonts_subpixel_order { /* For any value V, a rotation of 90⋅R degrees, R integer, * clockwise, of the physical output, will yeild a subpixel - * order represented with the value (V + R) Mod 4 + ⌊V / 4⌋, + * order represented with the value (V + R) Mod 4 + 4⋅⌊V / 4⌋, * if V ≥ 4, otherwise V asis. A rotation that is not * divisible by 90 degrees, will yeild the subpixel order * LIBFONTS_SUBPIXEL_ORDER_NONLINEAR if V is greater or equal diff --git a/libfonts_calculate_subpixel_order.c b/libfonts_calculate_subpixel_order.c new file mode 100644 index 0000000..6d26921 --- /dev/null +++ b/libfonts_calculate_subpixel_order.c @@ -0,0 +1,60 @@ +/* See LICENSE file for copyright and license details. */ +#include "libfonts.h" + + +enum libfonts_subpixel_order +libfonts_calculate_subpixel_order(enum libfonts_subpixel_order unrotated, enum libfonts_orientation rotation) +{ + int rot; + + switch (rotation) { + case LIBFONTS_ORIENTATION_UNKNOWN: + default: + switch (unrotated) { + case LIBFONTS_SUBPIXEL_ORDER_UNKNOWN: + case LIBFONTS_SUBPIXEL_ORDER_NONRGB: + case LIBFONTS_SUBPIXEL_ORDER_NONLINEAR: + case LIBFONTS_SUBPIXEL_ORDER_OTHER: + return unrotated; + default: + return LIBFONTS_SUBPIXEL_ORDER_UNKNOWN; + } + break; + + case LIBFONTS_ORIENTATION_0_DEGREES_CLOCKWISE: + return unrotated; + + case LIBFONTS_ORIENTATION_90_DEGREES_CLOCKWISE: + rot = 1; + break; + + case LIBFONTS_ORIENTATION_180_DEGREES_CLOCKWISE: + rot = 2; + break; + + case LIBFONTS_ORIENTATION_270_DEGREES_CLOCKWISE: + rot = 3; + break; + + case LIBFONTS_ORIENTATION_OTHER: + switch (unrotated) { + case LIBFONTS_SUBPIXEL_ORDER_UNKNOWN: + case LIBFONTS_SUBPIXEL_ORDER_NONRGB: + case LIBFONTS_SUBPIXEL_ORDER_NONLINEAR: + return unrotated; + default: + return LIBFONTS_SUBPIXEL_ORDER_NONLINEAR; + } + break; + } + + switch (unrotated) { + case LIBFONTS_SUBPIXEL_ORDER_UNKNOWN: + case LIBFONTS_SUBPIXEL_ORDER_NONRGB: + case LIBFONTS_SUBPIXEL_ORDER_NONLINEAR: + case LIBFONTS_SUBPIXEL_ORDER_OTHER: + return unrotated; + default: + return ((unrotated + rot) & 3) + (unrotated & ~3); + } +} -- cgit v1.2.3-70-g09d2