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 <tzimmermann@suse.de>
Signed-off-by: Helge Deller <deller@gmx.de>
master
Thomas Zimmermann 2026-04-07 11:23:18 +02:00 committed by Helge Deller
parent 6ad4ed8408
commit a30e9e6b01
1 changed files with 46 additions and 33 deletions

View File

@ -15,6 +15,12 @@
#include "font.h" #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, static unsigned int __font_glyph_pos(unsigned int x, unsigned int y, unsigned int bit_pitch,
unsigned int *bit) unsigned int *bit)
{ {
@ -44,18 +50,21 @@ static void font_glyph_set_bit(unsigned char *glyph, unsigned int x, unsigned in
glyph[i] |= bit; 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; unsigned int x, y;
int shift = (8 - (height % 8)) & 7; 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);
width = (width + 7) & ~7; for (y = 0; y < height; y++) {
height = (height + 7) & ~7; for (x = 0; x < width; x++) {
if (font_glyph_test_bit(glyph, x, y, bit_pitch)) {
for (i = 0; i < h; i++) { font_glyph_set_bit(out, out_bit_pitch - 1 - y - shift, x,
for (j = 0; j < w; j++) { out_bit_pitch);
if (font_glyph_test_bit(in, j, i, width)) }
font_glyph_set_bit(out, height - 1 - i - shift, j, height);
} }
} }
} }
@ -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 */ 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); 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; unsigned int x, y;
int shift = (8 - (width % 8)) & 7; unsigned int shift = (8 - (width % 8)) & 7;
unsigned int bit_pitch = font_glyph_bit_pitch(width);
width = (width + 7) & ~7; for (y = 0; y < height; y++) {
for (x = 0; x < width; x++) {
for (i = 0; i < height; i++) { if (font_glyph_test_bit(glyph, x, y, bit_pitch)) {
for (j = 0; j < width - shift; j++) { font_glyph_set_bit(out, width - (1 + x + shift), height - (1 + y),
if (font_glyph_test_bit(in, j, i, width)) bit_pitch);
font_glyph_set_bit(out, width - (1 + j + shift), }
height - (1 + i), width);
} }
} }
} }
@ -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)); 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); 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; unsigned int x, y;
int shift = (8 - (width % 8)) & 7; 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);
width = (width + 7) & ~7; for (y = 0; y < height; y++) {
height = (height + 7) & ~7; for (x = 0; x < width; x++) {
if (font_glyph_test_bit(glyph, x, y, bit_pitch))
for (i = 0; i < h; i++) { font_glyph_set_bit(out, y, bit_pitch - 1 - x - shift,
for (j = 0; j < w; j++) { out_bit_pitch);
if (font_glyph_test_bit(in, j, i, width))
font_glyph_set_bit(out, i, width - 1 - j - shift, height);
} }
} }
} }
@ -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 */ 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); EXPORT_SYMBOL_GPL(font_glyph_rotate_270);