aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2021-11-10 22:50:28 +0100
committerMattias Andrée <maandree@kth.se>2021-11-10 22:50:28 +0100
commit0c352cad10691992d261e7d0f9ec06fdb801ed34 (patch)
tree7ac493a2b99226421979040189cd6c48cfe2b59f
parentAdd missing include directive (diff)
downloadlibfonts-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--Makefile3
-rw-r--r--libfonts.h2
-rw-r--r--libfonts_calculate_subpixel_order.c60
3 files changed, 63 insertions, 2 deletions
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);
+ }
+}