Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

lib/fonts: Refactor glyph-pattern helpers

Change the signatures of the pattern helpers to align them with other
font-glyph helpers: use the font_glyph_ prefix and pass the glyph
buffer first.

Calculating the position of the involved bit is somewhat obfuscated
in the original implementation. Move it into the new helper
__font_glyph_pos() and use the result as array index and bit position.

Note that these bit helpers use a bit pitch, while other code uses a
byte pitch. This is intentional and required here.

v2:
- fix typos in commit message

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Signed-off-by: Helge Deller <deller@gmx.de>

authored by

Thomas Zimmermann and committed by
Helge Deller
6ad4ed84 bdfd9432

+27 -18
+27 -18
lib/fonts/font_rotate.c
··· 15 15 16 16 #include "font.h" 17 17 18 - static inline int pattern_test_bit(u32 x, u32 y, u32 pitch, const char *pat) 18 + static unsigned int __font_glyph_pos(unsigned int x, unsigned int y, unsigned int bit_pitch, 19 + unsigned int *bit) 19 20 { 20 - u32 tmp = (y * pitch) + x, index = tmp / 8, bit = tmp % 8; 21 + unsigned int off = y * bit_pitch + x; 22 + unsigned int bit_shift = off % 8; 21 23 22 - pat += index; 23 - return (*pat) & (0x80 >> bit); 24 + *bit = 0x80 >> bit_shift; /* MSB has position 0, LSB has position 7 */ 25 + 26 + return off / 8; 24 27 } 25 28 26 - static inline void pattern_set_bit(u32 x, u32 y, u32 pitch, char *pat) 29 + static bool font_glyph_test_bit(const unsigned char *glyph, unsigned int x, unsigned int y, 30 + unsigned int bit_pitch) 27 31 { 28 - u32 tmp = (y * pitch) + x, index = tmp / 8, bit = tmp % 8; 32 + unsigned int bit; 33 + unsigned int i = __font_glyph_pos(x, y, bit_pitch, &bit); 29 34 30 - pat += index; 35 + return glyph[i] & bit; 36 + } 31 37 32 - (*pat) |= 0x80 >> bit; 38 + static void font_glyph_set_bit(unsigned char *glyph, unsigned int x, unsigned int y, 39 + unsigned int bit_pitch) 40 + { 41 + unsigned int bit; 42 + unsigned int i = __font_glyph_pos(x, y, bit_pitch, &bit); 43 + 44 + glyph[i] |= bit; 33 45 } 34 46 35 47 static inline void rotate_cw(const char *in, char *out, u32 width, u32 height) ··· 54 42 55 43 for (i = 0; i < h; i++) { 56 44 for (j = 0; j < w; j++) { 57 - if (pattern_test_bit(j, i, width, in)) 58 - pattern_set_bit(height - 1 - i - shift, j, 59 - height, out); 45 + if (font_glyph_test_bit(in, j, i, width)) 46 + font_glyph_set_bit(out, height - 1 - i - shift, j, height); 60 47 } 61 48 } 62 49 } ··· 92 81 93 82 for (i = 0; i < height; i++) { 94 83 for (j = 0; j < width - shift; j++) { 95 - if (pattern_test_bit(j, i, width, in)) 96 - pattern_set_bit(width - (1 + j + shift), 97 - height - (1 + i), 98 - width, out); 84 + if (font_glyph_test_bit(in, j, i, width)) 85 + font_glyph_set_bit(out, width - (1 + j + shift), 86 + height - (1 + i), width); 99 87 } 100 88 } 101 89 } ··· 129 119 130 120 for (i = 0; i < h; i++) { 131 121 for (j = 0; j < w; j++) { 132 - if (pattern_test_bit(j, i, width, in)) 133 - pattern_set_bit(i, width - 1 - j - shift, 134 - height, out); 122 + if (font_glyph_test_bit(in, j, i, width)) 123 + font_glyph_set_bit(out, i, width - 1 - j - shift, height); 135 124 } 136 125 } 137 126 }