]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
lib/fonts: Refactor glyph-rotation helpers
authorThomas Zimmermann <tzimmermann@suse.de>
Tue, 7 Apr 2026 09:23:18 +0000 (11:23 +0200)
committerHelge Deller <deller@gmx.de>
Tue, 7 Apr 2026 15:38:07 +0000 (17:38 +0200)
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 <tzimmermann@suse.de>
Signed-off-by: Helge Deller <deller@gmx.de>
lib/fonts/font_rotate.c

index d79ec5eef7123a09b547372107934566bc6054b4..09f6218e036f92fcb0255b2305bdcfed0a966225 100644 (file)
 
 #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);