diff options
author | Mattias Andrée <maandree@kth.se> | 2023-01-07 20:24:56 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2023-01-07 20:24:56 +0100 |
commit | a0a215b02de9a4f32097a8e98208f911c8d1e027 (patch) | |
tree | bd11effbe838b1a0b731877774bddcde6b8edb53 | |
parent | Add LIBFONTS_SUBPIXEL_ORDER_BALANCED_??_?? subpixels orders (diff) | |
download | libfonts-a0a215b02de9a4f32097a8e98208f911c8d1e027.tar.gz libfonts-a0a215b02de9a4f32097a8e98208f911c8d1e027.tar.bz2 libfonts-a0a215b02de9a4f32097a8e98208f911c8d1e027.tar.xz |
Add libfonts_{get,unget}_subpixel_order_class
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | libfonts.h | 176 | ||||
-rw-r--r-- | libfonts_get_subpixel_order_class.c | 41 | ||||
-rw-r--r-- | libfonts_unget_subpixel_order_class.c | 51 |
4 files changed, 271 insertions, 1 deletions
@@ -21,7 +21,9 @@ OBJ =\ libfonts_decode_font_description.o\ libfonts_encode_font_description.o\ libfonts_get_default_font_name.o\ - libfonts_get_output_dpi.o + libfonts_get_output_dpi.o\ + libfonts_get_subpixel_order_class.o\ + libfonts_unget_subpixel_order_class.o HDR =\ common.h\ @@ -68,6 +68,142 @@ enum libfonts_antialiasing { /** + * Output subpixel colour + */ +enum libfonts_subpixel_colour { + /** + * Red primary + */ + LIBFONTS_SUBPIXEL_COLOUR_RED = 0, + + /** + * Green primary + */ + LIBFONTS_SUBPIXEL_COLOUR_GREEN = 1, + + /** + * Blue primary + */ + LIBFONTS_SUBPIXEL_COLOUR_BLUE = 2 +}; + +/** + * Output subpixel order class + */ +enum libfonts_subpixel_order_class { + /** + * `LIBFONTS_SUBPIXEL_ORDER_UNKNOWN`, + * `LIBFONTS_SUBPIXEL_ORDER_NONRGB`, + * `LIBFONTS_SUBPIXEL_ORDER_NONLINEAR`, or + * `LIBFONTS_SUBPIXEL_ORDER_OTHER` + */ + LIBFONTS_SUBPIXEL_ORDER_CLASS_OTHER, + + /** + * ┌───┬───┬───┐ + * │ │ │ │ + * │ │ │ │ + * │ 1 │ 2 │ 3 │ + * │ │ │ │ + * │ │ │ │ + * └───┴───┴───┘ + */ + LIBFONTS_SUBPIXEL_ORDER_CLASS_123, + + /** + * ┌───────────┐ + * │ 1 │ + * ├───────────┤ + * │ 2 │ + * ├───────────┤ + * │ 3 │ + * └───────────┘ + */ + LIBFONTS_SUBPIXEL_ORDER_CLASS_1_2_3, + + /** + * ┌───────┐ + * │ 1 │ + * ├───┬───┤ + * │ 2 │ 3 │ + * └───┴───┘ + */ + LIBFONTS_SUBPIXEL_ORDER_CLASS_11_23, + + /** + * ┌───┬───┐ + * │ 2 │ │ + * ├───┤ 1 │ + * │ 3 │ │ + * └───┴───┘ + */ + LIBFONTS_SUBPIXEL_ORDER_CLASS_21_31, + + /** + * ┌───┬───┐ + * │ 3 │ 2 │ + * ├───┴───┤ + * │ 1 │ + * └───────┘ + */ + LIBFONTS_SUBPIXEL_ORDER_CLASS_32_11, + + /** + * ┌───┬───┐ + * │ │ 3 │ + * │ 1 ├───┤ + * │ │ 2 │ + * └───┴───┘ + */ + LIBFONTS_SUBPIXEL_ORDER_CLASS_13_12, + + /** + * ┌───────────┐ + * │ 1 │ + * ├─────┬─────┤ + * │ │ │ + * │ 2 │ 3 │ + * │ │ │ + * └─────┴─────┘ + */ + LIBFONTS_SUBPIXEL_ORDER_CLASS_BALANCED_11_23, + + /** + * ┌───────┬───┐ + * │ 2 │ │ + * │ │ │ + * ├───────┤ 1 │ + * │ 3 │ │ + * │ │ │ + * └───────┴───┘ + */ + LIBFONTS_SUBPIXEL_ORDER_CLASS_BALANCED_21_31, + + /** + * ┌─────┬─────┐ + * │ │ │ + * │ 3 │ 2 │ + * │ │ │ + * ├─────┴─────┤ + * │ 1 │ + * └───────────┘ + */ + LIBFONTS_SUBPIXEL_ORDER_CLASS_BALANCED_32_11, + + /** + * ┌───┬───────┐ + * │ │ 3 │ + * │ │ │ + * │ 1 ├───────┤ + * │ │ 2 │ + * │ │ │ + * └───┴───────┘ + */ + LIBFONTS_SUBPIXEL_ORDER_CLASS_BALANCED_13_12 +}; + + +/** * Output subpixel order */ enum libfonts_subpixel_order { @@ -1342,5 +1478,45 @@ int libfonts_get_output_dpi(struct libfonts_output *, const char *); */ enum libfonts_subpixel_order libfonts_calculate_subpixel_order(enum libfonts_subpixel_order, const struct libfonts_transformation *); +/** + * Get the general subpixel layout, as well + * as which primary is contained in which + * cell in the layout, from a specific + * subpixel order + * + * @param order The subpixel order + * @param cell1p Output parameter for the primary contained in cell 1 + * @param cell2p Output parameter for the primary contained in cell 2 + * @param cell3p Output parameter for the primary contained in cell 3 + * @return The subpixel layout + */ +enum libfonts_subpixel_order_class libfonts_get_subpixel_order_class(enum libfonts_subpixel_order, + enum libfonts_subpixel_colour *, + enum libfonts_subpixel_colour *, + enum libfonts_subpixel_colour *); + +/** + * Get the general subpixel layout, as well + * as which primary is contained in which + * cell in the layout, from a specific + * subpixel order + * + * @param orderp Output parameter for the subpixel order + * @param layout The subpixel layout + * @param cell1 The primary contained in cell 1 + * @param cell2 The primary contained in cell 2 + * @param cell3 The primary contained in cell 3 + * @return Normally 1, but 0 if `layout` is `LIBFONTS_SUBPIXEL_ORDER_CLASS_OTHER`; + * -1 on failure + * + * @throws EINVAL Unrecognised value in `layout`, `cell1`, `cell2`, or `cell3` + * @throws EINVAL The values of `cell1`, `cell2`, and `cell3` are not unique + */ +int libfonts_unget_subpixel_order_class(enum libfonts_subpixel_order *, + enum libfonts_subpixel_order_class, + enum libfonts_subpixel_colour, + enum libfonts_subpixel_colour, + enum libfonts_subpixel_colour); + #endif diff --git a/libfonts_get_subpixel_order_class.c b/libfonts_get_subpixel_order_class.c new file mode 100644 index 0000000..577b0f0 --- /dev/null +++ b/libfonts_get_subpixel_order_class.c @@ -0,0 +1,41 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" + + +enum libfonts_subpixel_order_class +libfonts_get_subpixel_order_class(enum libfonts_subpixel_order order, + enum libfonts_subpixel_colour *cell1p, + enum libfonts_subpixel_colour *cell2p, + enum libfonts_subpixel_colour *cell3p) +{ + enum libfonts_subpixel_colour c1, c2, c3; + enum libfonts_subpixel_order_class layout; + int i; /* RGB, RBG, GRB, GBR, BRG, BGR */ + + if (order >= LIBFONTS_SUBPIXEL_ORDER_RGB && order <= LIBFONTS_SUBPIXEL_ORDER_G_R_B) { + layout = ((order - LIBFONTS_SUBPIXEL_ORDER_RGB) & 1) + LIBFONTS_SUBPIXEL_ORDER_CLASS_123; + i = (order - LIBFONTS_SUBPIXEL_ORDER_RGB) / 2; + i = ((int []){0, 5, 3, 1, 4, 2})[i]; + + } else if (order >= LIBFONTS_SUBPIXEL_ORDER_RR_GB && order <= LIBFONTS_SUBPIXEL_ORDER_BALANCED_BR_BG) { + layout = ((order - LIBFONTS_SUBPIXEL_ORDER_RR_GB) & 3) + LIBFONTS_SUBPIXEL_ORDER_CLASS_11_23; + if (order >= LIBFONTS_SUBPIXEL_ORDER_BALANCED_RR_GB) + layout += 4; + i = (order - LIBFONTS_SUBPIXEL_ORDER_RR_GB) / 4 % 6; + + } else { + layout = LIBFONTS_SUBPIXEL_ORDER_CLASS_OTHER; + i = 0; + } + + c1 = i / 2; + c2 = (i + 1 + i / 3) % 3; + c3 = 3 - c1 - c2; + if (cell1p) + *cell1p = c1; + if (cell2p) + *cell2p = c2; + if (cell3p) + *cell3p = c3; + return layout; +} diff --git a/libfonts_unget_subpixel_order_class.c b/libfonts_unget_subpixel_order_class.c new file mode 100644 index 0000000..5fa9274 --- /dev/null +++ b/libfonts_unget_subpixel_order_class.c @@ -0,0 +1,51 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" + + +int +libfonts_unget_subpixel_order_class(enum libfonts_subpixel_order *orderp, + enum libfonts_subpixel_order_class layout, + enum libfonts_subpixel_colour cell1, + enum libfonts_subpixel_colour cell2, + enum libfonts_subpixel_colour cell3) +{ + int i; + + if (cell1 < 0 || cell1 > 2 || + cell2 < 0 || cell2 > 2 || + cell3 < 0 || cell3 > 2 || + cell1 == cell2 || + cell2 == cell3 || + cell3 == cell1) { + errno = EINVAL; + return -1; + } + + if (layout == LIBFONTS_SUBPIXEL_ORDER_CLASS_OTHER) { + if (orderp) + *orderp = LIBFONTS_SUBPIXEL_ORDER_UNKNOWN; + return 0; + + } else if (layout == LIBFONTS_SUBPIXEL_ORDER_CLASS_123 || layout == LIBFONTS_SUBPIXEL_ORDER_CLASS_1_2_3) { + if (orderp) { + /* RGB, BGR, GBR, RBG, BRG, GRB */ + i = ((cell2 + 2) % 3) * 2; + i += (cell1 < cell3) ^ (cell2 == LIBFONTS_SUBPIXEL_COLOUR_GREEN); + *orderp = i * 2 + (layout == LIBFONTS_SUBPIXEL_ORDER_CLASS_1_2_3) + LIBFONTS_SUBPIXEL_ORDER_RGB; + } + return 1; + + } else if (layout >= LIBFONTS_SUBPIXEL_ORDER_CLASS_11_23 || layout <= LIBFONTS_SUBPIXEL_ORDER_CLASS_BALANCED_13_12) { + if (orderp) { + /* RGB, RBG, GRB, GBR, BRG, BGR */ + i = (cell1 * 2) + (cell2 > cell3); + *orderp = i * 4 + (layout - LIBFONTS_SUBPIXEL_ORDER_CLASS_11_23) % 4 + LIBFONTS_SUBPIXEL_ORDER_RR_GB; + *orderp = (layout >= LIBFONTS_SUBPIXEL_ORDER_CLASS_BALANCED_11_23) * 24; + } + return 1; + + } else { + errno = EINVAL; + return -1; + } +} |