diff options
author | Mattias Andrée <maandree@kth.se> | 2021-11-10 22:50:28 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2021-11-10 22:50:28 +0100 |
commit | 0c352cad10691992d261e7d0f9ec06fdb801ed34 (patch) | |
tree | 7ac493a2b99226421979040189cd6c48cfe2b59f | |
parent | Add missing include directive (diff) | |
download | libfonts-0c352cad10691992d261e7d0f9ec06fdb801ed34.tar.gz libfonts-0c352cad10691992d261e7d0f9ec06fdb801ed34.tar.bz2 libfonts-0c352cad10691992d261e7d0f9ec06fdb801ed34.tar.xz |
Implement libfonts_calculate_subpixel_order
Signed-off-by: Mattias Andrée <maandree@kth.se>
-rw-r--r-- | Makefile | 3 | ||||
-rw-r--r-- | libfonts.h | 2 | ||||
-rw-r--r-- | libfonts_calculate_subpixel_order.c | 60 |
3 files changed, 63 insertions, 2 deletions
@@ -16,7 +16,8 @@ LIB_VERSION = $(LIB_MAJOR).$(LIB_MINOR) LIB_NAME = fonts -OBJ = +OBJ =\ + libfonts_calculate_subpixel_order.o HDR =\ 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); + } +} |