From 603142e23528061e7ba5bdbcb466e676237745a8 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 8 Jan 2023 22:19:02 +0100 Subject: Fix warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- common.h | 17 ++++++++++++++- libfonts.h | 31 ++++++++++++++++++--------- libfonts_calculate_subpixel_order.c | 22 ++++++++----------- libfonts_decode_font_description.c | 8 +++---- libfonts_get_default_font.c | 5 +++++ libfonts_get_default_font_name.c | 2 +- libfonts_get_output_dpi.c | 39 ++++++++++++++++++++++------------ libfonts_get_subpixel_order_class.c | 14 ++++++------ libfonts_parse_double__.c | 2 ++ libfonts_unget_subpixel_order_class.c | 40 ++++++++++++++++++----------------- 10 files changed, 111 insertions(+), 69 deletions(-) diff --git a/common.h b/common.h index 082f806..0759f5c 100644 --- a/common.h +++ b/common.h @@ -15,6 +15,7 @@ #define DOUBLE_TOLERANCE 0.000001 + #define LIST_RENDERING_SETTINGS(X, _)\ X(0, "dpi-x", dpi_x, 96, libfonts_parse_double__) _\ X(1, "dpi-y", dpi_y, 96, libfonts_parse_double__) _\ @@ -43,12 +44,21 @@ transform(double *x_out, double *y_out, double x, double y, const struct libfont } +#if defined(__GNUC__) && !defined(__clang__) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wunsuffixed-float-constants" +#endif + static inline int eq(double a, double b) { return b - DOUBLE_TOLERANCE <= a && a <= b + DOUBLE_TOLERANCE; } +#if defined(__GNUC__) && !defined(__clang__) +# pragma GCC diagnostic pop +#endif + const char *libfonts_getenv__(const char *name, struct libfonts_context *ctx); char *libfonts_gethome__(struct libfonts_context *ctx); @@ -66,9 +76,14 @@ int libfonts_parse_aa__(enum libfonts_antialiasing *outp, const char *value); # define ASSERT(ASSERTION)\ do {\ if (!(ASSERTION)) {\ - fprintf(stderr, "Failed assertion at line %u: %s\n", __LINE__, #ASSERTION);\ + fprintf(stderr, "Failed assertion at line %i: %s\n", __LINE__, #ASSERTION);\ exit(1);\ }\ } while (0) + +#if defined(__clang__) +# pragma clang diagnostic ignored "-Wassign-enum" +#endif + #endif diff --git a/libfonts.h b/libfonts.h index bdf9163..2c7202a 100644 --- a/libfonts.h +++ b/libfonts.h @@ -12,6 +12,12 @@ #define LIBFONTS_CONTEXT_VERSION 0 +#if defined(__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wpadded" +#endif + + /** * Style-based default fonts */ @@ -1242,12 +1248,6 @@ struct libfonts_rendering_settings { */ uint32_t reference_height; - /** - * The output device's physical subpixel order, - * when it is not rotated - */ - enum libfonts_subpixel_order subpixel_order; - /** * If the product of the applicable pixel densities * (horizontal and vertical) is less than this @@ -1267,6 +1267,12 @@ struct libfonts_rendering_settings { */ double min_dpsqi_for_subpixel; + /** + * The output device's physical subpixel order, + * when it is not rotated + */ + enum libfonts_subpixel_order subpixel_order; + /** * Antialiasing mode for horizontal (on unrotated output), grey text */ @@ -1343,14 +1349,14 @@ struct libfonts_output { int output_screen; /** - * Transformation that is applied to the output + * The output's subpixel order, disregarding applied rotation */ - struct libfonts_transformation output_transformation; + enum libfonts_subpixel_order unrotated_subpixel_order; /** - * The output's subpixel order, disregarding applied rotation + * Transformation that is applied to the output */ - enum libfonts_subpixel_order unrotated_subpixel_order; + struct libfonts_transformation output_transformation; /** * The output's horizontal pixel density (pixels per inch), @@ -1619,6 +1625,11 @@ struct libfonts_context { }; +#if defined(__clang__) +# pragma clang diagnostic pop +#endif + + /** * `NULL`-terminated list of environment variables * that affect the execution of the library diff --git a/libfonts_calculate_subpixel_order.c b/libfonts_calculate_subpixel_order.c index 81a58f6..5727fc9 100644 --- a/libfonts_calculate_subpixel_order.c +++ b/libfonts_calculate_subpixel_order.c @@ -19,15 +19,11 @@ libfonts_calculate_subpixel_order(enum libfonts_subpixel_order unrotated, const double x[4], y[4], xmin, ymin, xmax, ymax, t1, t2; int trans, i, j; - switch (unrotated) { - case LIBFONTS_SUBPIXEL_ORDER_UNKNOWN: - case LIBFONTS_SUBPIXEL_ORDER_NONRGB: - case LIBFONTS_SUBPIXEL_ORDER_NONLINEAR: - case LIBFONTS_SUBPIXEL_ORDER_OTHER: + if (unrotated == LIBFONTS_SUBPIXEL_ORDER_UNKNOWN || + unrotated == LIBFONTS_SUBPIXEL_ORDER_NONRGB || + unrotated == LIBFONTS_SUBPIXEL_ORDER_NONLINEAR || + unrotated == LIBFONTS_SUBPIXEL_ORDER_OTHER) return unrotated; - default: - break; - } for (i = 0; i < 3; i++) for (j = 0; j < 3; j++) @@ -108,7 +104,7 @@ known: if (unrotated <= LIBFONTS_SUBPIXEL_ORDER_G_R_B) return unrotated ^ 1; else - return 7 - (unrotated & 7) + (unrotated & ~7); + return 7 - (unrotated & 7) + (unrotated & (enum libfonts_subpixel_order)~7U); case FLOPPED: if (unrotated <= LIBFONTS_SUBPIXEL_ORDER_G_R_B) @@ -126,7 +122,7 @@ known: return unrotated; default: - return ((unrotated + trans) & 3) + (unrotated & ~3); + return (enum libfonts_subpixel_order)((((int)unrotated + trans) & 3) + ((int)unrotated & ~3)); } } @@ -250,9 +246,9 @@ test(int xtrans, int ytrans, int zscale, int xscale, int yscale) {-xscale, 0, ytrans}, { 0, 0, zscale}}}; struct libfonts_transformation nonlinear_matrix = {.m = { - {+xscale, +yscale / 2., xtrans}, - { 0, +yscale, ytrans}, - { 0, 0, zscale}}}; + {+xscale, +yscale / (double)2, xtrans}, + { 0, +yscale, ytrans}, + { 0, 0, zscale}}}; struct libfonts_transformation unknown_matrix = {.m = { {0, 0, 0}, {0, 0, 0}, diff --git a/libfonts_decode_font_description.c b/libfonts_decode_font_description.c index 2348d97..74a9571 100644 --- a/libfonts_decode_font_description.c +++ b/libfonts_decode_font_description.c @@ -123,16 +123,16 @@ fix_charset_subset(char *out, const char *in) saved.last = ranges[i].last; } else { if (saved.first == saved.last) - out += sprintf(out, "%"PRId32" ", saved.first); + out += sprintf(out, "%"PRIu32" ", saved.first); else - out += sprintf(out, "%"PRId32"-%"PRId32" ", saved.first, saved.last); + out += sprintf(out, "%"PRIu32"-%"PRIu32" ", saved.first, saved.last); saved = ranges[i]; } } if (saved.first == saved.last) - out += sprintf(out, "%"PRId32" ", saved.first); + out += sprintf(out, "%"PRIu32" ", saved.first); else - out += sprintf(out, "%"PRId32"-%"PRId32" ", saved.first, saved.last); + out += sprintf(out, "%"PRIu32"-%"PRIu32" ", saved.first, saved.last); out[-1] = '\0'; return 0; diff --git a/libfonts_get_default_font.c b/libfonts_get_default_font.c index f8809bc..69d2729 100644 --- a/libfonts_get_default_font.c +++ b/libfonts_get_default_font.c @@ -6,6 +6,11 @@ static int find(char **outp, const char *dir_part1, const char *dir_part2, const char *dir_part3, struct libfonts_context *ctx) { + (void) outp; + (void) dir_part1; + (void) dir_part2; + (void) dir_part3; + (void) ctx; return 0; /* TODO */ } diff --git a/libfonts_get_default_font_name.c b/libfonts_get_default_font_name.c index 66d14cb..877f44c 100644 --- a/libfonts_get_default_font_name.c +++ b/libfonts_get_default_font_name.c @@ -67,7 +67,7 @@ main(void) } while (0) errno = 0; - ASSERT(libfonts_get_default_font_name(-1, 0, &r) == -1); + ASSERT(libfonts_get_default_font_name((enum libfonts_default_font)~1, 0, &r) == -1); ASSERT(errno == EINVAL); errno = 0; diff --git a/libfonts_get_output_dpi.c b/libfonts_get_output_dpi.c index 6377fb9..c56cc49 100644 --- a/libfonts_get_output_dpi.c +++ b/libfonts_get_output_dpi.c @@ -100,8 +100,8 @@ libfonts_get_output_dpi(struct libfonts_output *output, const char *edid) if (!width || !height) return 0; - output->dpi_x = (double)output->unrotated_output_width / (double)width * 2.54; - output->dpi_y = (double)output->unrotated_output_height / (double)height * 2.54; + output->dpi_x = (double)output->unrotated_output_width / (double)width * 254 / 100; + output->dpi_y = (double)output->unrotated_output_height / (double)height * 254 / 100; } if (!invert(&invtrans, &output->output_transformation)) { @@ -155,6 +155,17 @@ main(void) #define ASIS(MAT) T(MAT, 100, 150) #define SWAPS(MAT) T(MAT, 150, 100) +#if defined(__GNUC__) && !defined(__clang__) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wunsuffixed-float-constants" +#endif + + const double sqrt1half = 0.7071067811865475; + +#if defined(__GNUC__) && !defined(__clang__) +# pragma GCC diagnostic pop +#endif + char edid[512]; struct libfonts_output output; struct libfonts_transformation asis_matrix = {.m = { @@ -222,9 +233,9 @@ main(void) {+1, +1, 0}, { 0, 0, 1}}}; struct libfonts_transformation rot45cw_matrix = {.m = { - {+0.7071067811865475, -0.7071067811865475, 0}, - {+0.7071067811865475, +0.7071067811865475, 0}, - { 0, 0, 1}}}; + {+sqrt1half, -sqrt1half, 0}, + {+sqrt1half, +sqrt1half, 0}, + { 0, 0, 1}}}; struct libfonts_transformation uninvertable_matrix = {.m = { {1, 1, 0}, {1, 1, 0}, @@ -254,7 +265,7 @@ main(void) T(xshear_matrix, 150, 150); /* not important */ T(yshear_matrix, 100, 150); /* not important */ - T(rot45cw_matrix, 150 * 0.7071067811865475, 150 * 0.7071067811865475); /* not important */ + T(rot45cw_matrix, 150 * sqrt1half, 150 * sqrt1half); /* not important */ T_(uninvertable_matrix, 0, 0, 0); T_(null_matrix, 0, 0, 0); @@ -367,8 +378,8 @@ main(void) edid[256] = '\0'; memcpy(&output.output_transformation, &asis_matrix, sizeof(struct libfonts_transformation)); ASSERT(libfonts_get_output_dpi(&output, edid) == 1); - ASSERT(eq(output.dpi_x, 2.54 * 400 / 0xAA)); - ASSERT(eq(output.dpi_y, 2.54 * 500 / 0xAA)); + ASSERT(eq(output.dpi_x, (double)254 / 100 * 400 / 0xAA)); + ASSERT(eq(output.dpi_y, (double)254 / 100 * 500 / 0xAA)); output.unrotated_output_width = 400; output.unrotated_output_height = 500; @@ -383,8 +394,8 @@ main(void) edid[256] = '\0'; memcpy(&output.output_transformation, &asis_matrix, sizeof(struct libfonts_transformation)); ASSERT(libfonts_get_output_dpi(&output, edid) == 1); - ASSERT(eq(output.dpi_x, 2.54 * 400 / 0x99)); - ASSERT(eq(output.dpi_y, 2.54 * 500 / 0x88)); + ASSERT(eq(output.dpi_x, (double)254 / 100 * 400 / 0x99)); + ASSERT(eq(output.dpi_y, (double)254 / 100 * 500 / 0x88)); output.unrotated_output_width = 400; output.unrotated_output_height = 500; @@ -399,8 +410,8 @@ main(void) edid[256] = '\0'; memcpy(&output.output_transformation, &rot90cw_matrix, sizeof(struct libfonts_transformation)); ASSERT(libfonts_get_output_dpi(&output, edid) == 1); - ASSERT(eq(output.dpi_y, 2.54 * 400 / 0x99)); - ASSERT(eq(output.dpi_x, 2.54 * 500 / 0x88)); + ASSERT(eq(output.dpi_y, (double)254 / 100 * 400 / 0x99)); + ASSERT(eq(output.dpi_x, (double)254 / 100 * 500 / 0x88)); output.unrotated_output_width = 400; output.unrotated_output_height = 500; @@ -415,8 +426,8 @@ main(void) edid[400] = '\0'; memcpy(&output.output_transformation, &rot90cw_matrix, sizeof(struct libfonts_transformation)); ASSERT(libfonts_get_output_dpi(&output, edid) == 1); - ASSERT(eq(output.dpi_y, 2.54 * 400 / 0x99)); - ASSERT(eq(output.dpi_x, 2.54 * 500 / 0x88)); + ASSERT(eq(output.dpi_y, (double)254 / 100 * 400 / 0x99)); + ASSERT(eq(output.dpi_x, (double)254 / 100 * 500 / 0x88)); return 0; } diff --git a/libfonts_get_subpixel_order_class.c b/libfonts_get_subpixel_order_class.c index 2c6e3bc..10d441c 100644 --- a/libfonts_get_subpixel_order_class.c +++ b/libfonts_get_subpixel_order_class.c @@ -11,18 +11,18 @@ libfonts_get_subpixel_order_class(enum libfonts_subpixel_order order, { enum libfonts_subpixel_colour c1, c2, c3; enum libfonts_subpixel_order_class layout; - int i; /* RGB, RBG, GRB, GBR, BRG, BGR */ + unsigned 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]; + i = (unsigned int)(order - LIBFONTS_SUBPIXEL_ORDER_RGB) / 2; + i = ((unsigned 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; + i = (unsigned int)(order - LIBFONTS_SUBPIXEL_ORDER_RR_GB) / 4 % 6; } else { layout = LIBFONTS_SUBPIXEL_ORDER_CLASS_OTHER; @@ -61,7 +61,7 @@ main(void) #define T_(ORDER, LAYOUT, C1, C2, C3)\ do {\ errno = 0;\ - c1 = c2 = c3 = -1;\ + c1 = c2 = c3 = (enum libfonts_subpixel_colour)~0;\ ASSERT(libfonts_get_subpixel_order_class(ORDER, &c1, &c2, &c3) == LAYOUT);\ ASSERT(c1 == C1);\ ASSERT(c2 == C2);\ @@ -85,8 +85,8 @@ main(void) T(NONRGB, OTHER, R, G, B); T(NONLINEAR, OTHER, R, G, B); T(OTHER, OTHER, R, G, B); - T(UNKNOWN - 1000, OTHER, R, G, B); - T(UNKNOWN + 9999, OTHER, R, G, B); + T_((enum libfonts_subpixel_order)~1, LIBFONTS_SUBPIXEL_ORDER_CLASS_OTHER, R, G, B); + T_(9999, LIBFONTS_SUBPIXEL_ORDER_CLASS_OTHER, R, G, B); T(RGB, 123, R, G, B); T(R_G_B, 1_2_3, R, G, B); diff --git a/libfonts_parse_double__.c b/libfonts_parse_double__.c index 30fc61d..2fb182c 100644 --- a/libfonts_parse_double__.c +++ b/libfonts_parse_double__.c @@ -6,6 +6,8 @@ int libfonts_parse_double__(double *outp, const char *value) { + (void) outp; + (void) value; return 0; /* TODO implement */ } diff --git a/libfonts_unget_subpixel_order_class.c b/libfonts_unget_subpixel_order_class.c index 47d8366..01c980a 100644 --- a/libfonts_unget_subpixel_order_class.c +++ b/libfonts_unget_subpixel_order_class.c @@ -10,11 +10,11 @@ libfonts_unget_subpixel_order_class(enum libfonts_subpixel_order *orderp, enum libfonts_subpixel_colour cell2, enum libfonts_subpixel_colour cell3) { - int i; + unsigned int i; - if (cell1 < 0 || cell1 > 2 || - cell2 < 0 || cell2 > 2 || - cell3 < 0 || cell3 > 2 || + if ((uintmax_t)cell1 > 2 || + (uintmax_t)cell2 > 2 || + (uintmax_t)cell3 > 2 || cell1 == cell2 || cell2 == cell3 || cell3 == cell1) { @@ -30,9 +30,11 @@ libfonts_unget_subpixel_order_class(enum libfonts_subpixel_order *orderp, } 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; + i = (unsigned int)((cell2 + 2) % 3) * 2; + i += (unsigned int)(cell1 < cell3) ^ (cell2 == LIBFONTS_SUBPIXEL_COLOUR_GREEN); + *orderp = (enum libfonts_subpixel_order)(i * 2 + + (layout == LIBFONTS_SUBPIXEL_ORDER_CLASS_1_2_3) + + LIBFONTS_SUBPIXEL_ORDER_RGB); } return 1; @@ -41,7 +43,7 @@ libfonts_unget_subpixel_order_class(enum libfonts_subpixel_order *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; + *orderp += (enum libfonts_subpixel_order)((layout >= LIBFONTS_SUBPIXEL_ORDER_CLASS_BALANCED_11_23) * 24); } return 1; @@ -69,7 +71,7 @@ main(void) #define T_(ORDER, LAYOUT, C1, C2, C3)\ do {\ errno = 0;\ - order = -1;\ + order = (enum libfonts_subpixel_order)~1;\ ASSERT(libfonts_unget_subpixel_order_class(&order, LAYOUT, C1, C2, C3) == 1);\ ASSERT(order == ORDER);\ ASSERT(!errno);\ @@ -82,7 +84,7 @@ main(void) #define TU_(LAYOUT, C1, C2, C3)\ do {\ errno = 0;\ - order = -1;\ + order = (enum libfonts_subpixel_order)~1;\ ASSERT(libfonts_unget_subpixel_order_class(&order, LAYOUT, C1, C2, C3) == 0);\ ASSERT(order == LIBFONTS_SUBPIXEL_ORDER_UNKNOWN);\ ASSERT(!errno);\ @@ -111,18 +113,18 @@ main(void) TU(OTHER, G, R, B); TU(OTHER, B, G, R); - TE(OTHER, -1, G, B); - TE(OTHER, R, -1, B); - TE(OTHER, R, G, -1); - TE(OTHER, -1, -2, B); + TE(OTHER, (enum libfonts_subpixel_colour)~1, G, B); + TE(OTHER, R, (enum libfonts_subpixel_colour)~1, B); + TE(OTHER, R, G, (enum libfonts_subpixel_colour)~1); + TE(OTHER, (enum libfonts_subpixel_colour)~1, (enum libfonts_subpixel_colour)~2, B); TE(OTHER, 3, G, B); TE(OTHER, R, 3, B); TE(OTHER, R, G, 3); TE(OTHER, R, 3, 4); - TE(123, -1, G, B); - TE(123, R, -1, B); - TE(123, R, G, -1); - TE(123, -1, -2, B); + TE(123, (enum libfonts_subpixel_colour)~1, G, B); + TE(123, R, (enum libfonts_subpixel_colour)~1, B); + TE(123, R, G, (enum libfonts_subpixel_colour)~1); + TE(123, (enum libfonts_subpixel_colour)~1, (enum libfonts_subpixel_colour)~2, B); TE(123, 3, G, B); TE(123, R, 3, B); TE(123, R, G, 3); @@ -130,7 +132,7 @@ main(void) TE(123, R, R, G); TE(123, R, G, R); TE(123, R, G, G); - TE_(-1, R, G, B); + TE_((enum libfonts_subpixel_order_class)~1, R, G, B); TE_(9999, R, G, B); T(RGB, 123, R, G, B); -- cgit v1.2.3-70-g09d2