aboutsummaryrefslogtreecommitdiffstats
path: root/libfonts_get_subpixel_expansion.c
blob: e63d729a177a9ef251bb2e8f2223b05426609e1b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/* 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)
{
	size_t w, h;

#define T(L)\
	do {\
		errno = 0;\
		ASSERT(libfonts_get_subpixel_expansion(L, NULL, NULL) == -1);\
		ASSERT(errno == EINVAL);\
		\
		errno = 0;\
		ASSERT(libfonts_get_subpixel_expansion(L, &w, NULL) == -1);\
		ASSERT(errno == EINVAL);\
		\
		errno = 0;\
		ASSERT(libfonts_get_subpixel_expansion(L, NULL, &h) == -1);\
		ASSERT(errno == EINVAL);\
		\
		errno = 0;\
		ASSERT(libfonts_get_subpixel_expansion(L, &w, &h) == -1);\
		ASSERT(errno == EINVAL);\
	} while (0)

	T(LIBFONTS_SUBPIXEL_ORDER_CLASS_OTHER);
	T((enum libfonts_subpixel_order_class)999);

#undef T

#define T(L, W, H)\
	do {\
		w = 0, h = 0;\
		ASSERT(!libfonts_get_subpixel_expansion(L, NULL, NULL));\
		\
		w = 0, h = 0;\
		ASSERT(!libfonts_get_subpixel_expansion(L, &w, NULL));\
		ASSERT(w == (W));\
		\
		w = 0, h = 0;\
		ASSERT(!libfonts_get_subpixel_expansion(L, NULL, &h));\
		ASSERT(h == (H));\
		\
		w = 0, h = 0;\
		ASSERT(!libfonts_get_subpixel_expansion(L, &w, &h));\
		ASSERT(w == (W));\
		ASSERT(h == (H));\
	} while (0)

	errno = EDOM;
	T(LIBFONTS_SUBPIXEL_ORDER_CLASS_123, 3, 1);
	T(LIBFONTS_SUBPIXEL_ORDER_CLASS_1_2_3, 1, 3);
	T(LIBFONTS_SUBPIXEL_ORDER_CLASS_11_23, 2, 2);
	T(LIBFONTS_SUBPIXEL_ORDER_CLASS_21_31, 2, 2);
	T(LIBFONTS_SUBPIXEL_ORDER_CLASS_32_11, 2, 2);
	T(LIBFONTS_SUBPIXEL_ORDER_CLASS_13_12, 2, 2);
	T(LIBFONTS_SUBPIXEL_ORDER_CLASS_BALANCED_11_23, 2, 3);
	T(LIBFONTS_SUBPIXEL_ORDER_CLASS_BALANCED_21_31, 3, 2);
	T(LIBFONTS_SUBPIXEL_ORDER_CLASS_BALANCED_32_11, 2, 3);
	T(LIBFONTS_SUBPIXEL_ORDER_CLASS_BALANCED_13_12, 3, 2);
	ASSERT(errno == EDOM);

	return 0;
}


#endif