From: Thomas Zimmermann Date: Tue, 7 Apr 2026 09:23:18 +0000 (+0200) Subject: lib/fonts: Refactor glyph-rotation helpers X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a30e9e6b018f40941a626ff77e0bf35c015038fa;p=thirdparty%2Fkernel%2Flinux.git lib/fonts: Refactor glyph-rotation helpers Change the signatures of the glyph-rotation helpers to match their public interfaces. Drop the inline qualifier. Rename several variables to better match their meaning. Especially rename variables to bit_pitch (or a variant thereof) if they store a pitch value in bits per scanline. The original code is fairly confusing about this. Move the calculation of the bit pitch into the new helper font_glyph_bit_pitch(). Signed-off-by: Thomas Zimmermann Signed-off-by: Helge Deller --- diff --git a/lib/fonts/font_rotate.c b/lib/fonts/font_rotate.c index d79ec5eef7123..09f6218e036f9 100644 --- a/lib/fonts/font_rotate.c +++ b/lib/fonts/font_rotate.c @@ -15,6 +15,12 @@ #include "font.h" +/* number of bits per line */ +static unsigned int font_glyph_bit_pitch(unsigned int width) +{ + return round_up(width, 8); +} + static unsigned int __font_glyph_pos(unsigned int x, unsigned int y, unsigned int bit_pitch, unsigned int *bit) { @@ -44,18 +50,21 @@ static void font_glyph_set_bit(unsigned char *glyph, unsigned int x, unsigned in glyph[i] |= bit; } -static inline void rotate_cw(const char *in, char *out, u32 width, u32 height) +static void __font_glyph_rotate_90(const unsigned char *glyph, + unsigned int width, unsigned int height, + unsigned char *out) { - int i, j, h = height, w = width; - int shift = (8 - (height % 8)) & 7; - - width = (width + 7) & ~7; - height = (height + 7) & ~7; - - for (i = 0; i < h; i++) { - for (j = 0; j < w; j++) { - if (font_glyph_test_bit(in, j, i, width)) - font_glyph_set_bit(out, height - 1 - i - shift, j, height); + unsigned int x, y; + unsigned int shift = (8 - (height % 8)) & 7; + unsigned int bit_pitch = font_glyph_bit_pitch(width); + unsigned int out_bit_pitch = font_glyph_bit_pitch(height); + + for (y = 0; y < height; y++) { + for (x = 0; x < width; x++) { + if (font_glyph_test_bit(glyph, x, y, bit_pitch)) { + font_glyph_set_bit(out, out_bit_pitch - 1 - y - shift, x, + out_bit_pitch); + } } } } @@ -79,22 +88,24 @@ void font_glyph_rotate_90(const unsigned char *glyph, unsigned int width, unsign { memset(out, 0, font_glyph_size(height, width)); /* flip width/height */ - rotate_cw(glyph, out, width, height); + __font_glyph_rotate_90(glyph, width, height, out); } EXPORT_SYMBOL_GPL(font_glyph_rotate_90); -static inline void rotate_ud(const char *in, char *out, u32 width, u32 height) +static void __font_glyph_rotate_180(const unsigned char *glyph, + unsigned int width, unsigned int height, + unsigned char *out) { - int i, j; - int shift = (8 - (width % 8)) & 7; - - width = (width + 7) & ~7; - - for (i = 0; i < height; i++) { - for (j = 0; j < width - shift; j++) { - if (font_glyph_test_bit(in, j, i, width)) - font_glyph_set_bit(out, width - (1 + j + shift), - height - (1 + i), width); + unsigned int x, y; + unsigned int shift = (8 - (width % 8)) & 7; + unsigned int bit_pitch = font_glyph_bit_pitch(width); + + for (y = 0; y < height; y++) { + for (x = 0; x < width; x++) { + if (font_glyph_test_bit(glyph, x, y, bit_pitch)) { + font_glyph_set_bit(out, width - (1 + x + shift), height - (1 + y), + bit_pitch); + } } } } @@ -115,22 +126,24 @@ void font_glyph_rotate_180(const unsigned char *glyph, unsigned int width, unsig { memset(out, 0, font_glyph_size(width, height)); - rotate_ud(glyph, out, width, height); + __font_glyph_rotate_180(glyph, width, height, out); } EXPORT_SYMBOL_GPL(font_glyph_rotate_180); -static inline void rotate_ccw(const char *in, char *out, u32 width, u32 height) +static void __font_glyph_rotate_270(const unsigned char *glyph, + unsigned int width, unsigned int height, + unsigned char *out) { - int i, j, h = height, w = width; - int shift = (8 - (width % 8)) & 7; - - width = (width + 7) & ~7; - height = (height + 7) & ~7; - - for (i = 0; i < h; i++) { - for (j = 0; j < w; j++) { - if (font_glyph_test_bit(in, j, i, width)) - font_glyph_set_bit(out, i, width - 1 - j - shift, height); + unsigned int x, y; + unsigned int shift = (8 - (width % 8)) & 7; + unsigned int bit_pitch = font_glyph_bit_pitch(width); + unsigned int out_bit_pitch = font_glyph_bit_pitch(height); + + for (y = 0; y < height; y++) { + for (x = 0; x < width; x++) { + if (font_glyph_test_bit(glyph, x, y, bit_pitch)) + font_glyph_set_bit(out, y, bit_pitch - 1 - x - shift, + out_bit_pitch); } } } @@ -154,6 +167,6 @@ void font_glyph_rotate_270(const unsigned char *glyph, unsigned int width, unsig { memset(out, 0, font_glyph_size(height, width)); /* flip width/height */ - rotate_ccw(glyph, out, width, height); + __font_glyph_rotate_270(glyph, width, height, out); } EXPORT_SYMBOL_GPL(font_glyph_rotate_270);