diff options
author | Mattias Andrée <maandree@kth.se> | 2023-01-21 12:04:25 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2023-01-21 12:04:25 +0100 |
commit | 5bd71990de55e5c944559a3829a8d4e1fb96153f (patch) | |
tree | caa2ef62bf8db35e65ed127ed850bc7dd4754275 | |
parent | Add libfonts_create_transcoding_table (diff) | |
download | libfonts-5bd71990de55e5c944559a3829a8d4e1fb96153f.tar.gz libfonts-5bd71990de55e5c944559a3829a8d4e1fb96153f.tar.bz2 libfonts-5bd71990de55e5c944559a3829a8d4e1fb96153f.tar.xz |
Add libfonts_get_subpixel_expansion
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | libfonts.h | 32 | ||||
-rw-r--r-- | libfonts_get_subpixel_expansion.c | 52 |
3 files changed, 81 insertions, 4 deletions
@@ -34,6 +34,7 @@ PUBLIC_OBJ =\ libfonts_get_font_root_dirs.o\ libfonts_get_output_dpi.o\ libfonts_get_output_rendering_settings.o\ + libfonts_get_subpixel_expansion.o\ libfonts_get_subpixel_order_class.o\ libfonts_parse_alias_line.o\ libfonts_parse_dir_line.o\ @@ -303,7 +303,8 @@ enum libfonts_subpixel_order_class { * * Cells 2 and 3 have the aspect ratio * (width to height) 3:4 and cell 1 has - * the aspect ratio 6:2 + * the aspect ratio 6:2; cell 1 occupies + * a third of the pixel's height */ LIBFONTS_SUBPIXEL_ORDER_CLASS_BALANCED_11_23, @@ -322,7 +323,8 @@ enum libfonts_subpixel_order_class { * * Cells 2 and 3 have the aspect ratio * (width to height) 4:3 and cell 1 has - * the aspect ratio 2:6 + * the aspect ratio 2:6; cell 1 occupies + * a third of the pixel's width */ LIBFONTS_SUBPIXEL_ORDER_CLASS_BALANCED_21_31, @@ -341,7 +343,8 @@ enum libfonts_subpixel_order_class { * * Cells 2 and 3 have the aspect ratio * (width to height) 3:4 and cell 1 has - * the aspect ratio 6:2 + * the aspect ratio 6:2; cell 1 occupies + * a third of the pixel's height */ LIBFONTS_SUBPIXEL_ORDER_CLASS_BALANCED_32_11, @@ -360,7 +363,8 @@ enum libfonts_subpixel_order_class { * * Cells 2 and 3 have the aspect ratio * (width to height) 4:3 and cell 1 has - * the aspect ratio 2:6 + * the aspect ratio 2:6; cell 1 occupies + * a third of the pixel's width */ LIBFONTS_SUBPIXEL_ORDER_CLASS_BALANCED_13_12 }; @@ -2441,5 +2445,25 @@ int libfonts_unget_subpixel_order_class(enum libfonts_subpixel_order *, enum libfonts_subpixel_colour, enum libfonts_subpixel_colour); +/** + * Get the width and height multipliers needed to + * turn a raster of pixel cells into a raster of + * subpixel cells + * + * `*widthmulp` * `*heightmulp` will never exceed + * `SIZE_MAX` (or even be close to it) + * + * @param layout The subpixel layout + * @param widthmulp Output parameter for the width multiplier, + * this value is always positive + * @param heightmulp Output parameter for the height multiplier, + * this value is always positive + * @return 0 on success, -1 on failure + * + * @throws EINVAL `layout` is `LIBFONTS_SUBPIXEL_ORDER_CLASS_OTHER` + * @throws EINVAL `layout` is unrecognised + */ +int libfonts_get_subpixel_expansion(enum libfonts_subpixel_order_class, size_t *restrict, size_t *restrict); + #endif diff --git a/libfonts_get_subpixel_expansion.c b/libfonts_get_subpixel_expansion.c new file mode 100644 index 0000000..99f72ba --- /dev/null +++ b/libfonts_get_subpixel_expansion.c @@ -0,0 +1,52 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +int +libfonts_get_subpixel_expansion(enum libfonts_subpixel_order_class layout, size_t *restrict widthmulp, size_t *restrict heightmulp) +{ + size_t w, h; + + if (layout == LIBFONTS_SUBPIXEL_ORDER_CLASS_123) { + w = 3; + h = 1; + } else if (layout == LIBFONTS_SUBPIXEL_ORDER_CLASS_1_2_3) { + w = 1; + h = 3; + } else if (layout >= LIBFONTS_SUBPIXEL_ORDER_CLASS_11_23 && + layout <= LIBFONTS_SUBPIXEL_ORDER_CLASS_13_12) { + w = 2; + h = 2; + } else if (layout == LIBFONTS_SUBPIXEL_ORDER_CLASS_BALANCED_11_23 || + layout == LIBFONTS_SUBPIXEL_ORDER_CLASS_BALANCED_32_11) { + w = 2; + h = 3; + } else if (layout == LIBFONTS_SUBPIXEL_ORDER_CLASS_BALANCED_21_31 || + layout == LIBFONTS_SUBPIXEL_ORDER_CLASS_BALANCED_13_12) { + w = 3; + h = 2; + } else { + errno = EINVAL; + return -1; + } + + if (widthmulp) + *widthmulp = w; + if (heightmulp) + *heightmulp = h; + return 0; +} + + +#else + + +int +main(void) +{ + return 0; +} + + +#endif |