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: Provide helpers for calculating glyph pitch and size

Implement pitch and size calculation for a single font glyph in the
new helpers font_glyph_pitch() and font_glyph_size(). Replace the
instances where the calculations are open-coded.

Note that in the case of fbcon console rotation, the parameters for
a glyph's width and height might be reversed. This is intentional.

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
97df8960 c713b964

+61 -21
+2 -3
drivers/tty/vt/vt.c
··· 71 71 * by Adam Tla/lka <atlka@pg.gda.pl>, Aug 2006 72 72 */ 73 73 74 - #include <linux/math.h> 75 74 #include <linux/module.h> 76 75 #include <linux/types.h> 77 76 #include <linux/sched/signal.h> ··· 243 244 */ 244 245 unsigned int vc_font_pitch(const struct vc_font *font) 245 246 { 246 - return DIV_ROUND_UP(font->width, 8); 247 + return font_glyph_pitch(font->width); 247 248 } 248 249 EXPORT_SYMBOL_GPL(vc_font_pitch); 249 250 ··· 260 261 */ 261 262 unsigned int vc_font_size(const struct vc_font *font) 262 263 { 263 - return font->height * vc_font_pitch(font) * font->charcount; 264 + return font_glyph_size(font->width, font->height) * font->charcount; 264 265 } 265 266 EXPORT_SYMBOL_GPL(vc_font_size); 266 267
+6 -5
drivers/video/fbdev/core/fbcon_ccw.c
··· 26 26 struct vc_data *vc) 27 27 { 28 28 int i, j, offset = (vc->vc_font.height < 10) ? 1 : 2; 29 - int width = (vc->vc_font.height + 7) >> 3; 29 + int width = font_glyph_pitch(vc->vc_font.height); 30 30 int mod = vc->vc_font.height % 8; 31 31 u8 c, msk = ~(0xff << offset), msk1 = 0; 32 32 ··· 101 101 { 102 102 struct fbcon_par *par = info->fbcon_par; 103 103 u16 charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff; 104 - u32 idx = (vc->vc_font.height + 7) >> 3; 104 + u32 idx = font_glyph_pitch(vc->vc_font.height); 105 105 u8 *src; 106 106 107 107 while (cnt--) { ··· 131 131 { 132 132 struct fb_image image; 133 133 struct fbcon_par *par = info->fbcon_par; 134 - u32 width = (vc->vc_font.height + 7)/8; 134 + u32 width = font_glyph_pitch(vc->vc_font.height); 135 135 u32 cellsize = width * vc->vc_font.width; 136 136 u32 maxcnt = info->pixmap.size/cellsize; 137 137 u32 scan_align = info->pixmap.scan_align - 1; ··· 223 223 struct fb_cursor cursor; 224 224 struct fbcon_par *par = info->fbcon_par; 225 225 unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff; 226 - int w = (vc->vc_font.height + 7) >> 3, c; 226 + int w = font_glyph_pitch(vc->vc_font.height); 227 + int c; 227 228 int y = real_y(par->p, vc->state.y); 228 229 int attribute, use_sw = vc->vc_cursor_type & CUR_SW; 229 230 int err = 1, dx, dy; ··· 298 297 char *tmp, *mask = kmalloc_array(w, vc->vc_font.width, 299 298 GFP_ATOMIC); 300 299 int cur_height, size, i = 0; 301 - int width = (vc->vc_font.width + 7)/8; 300 + int width = font_glyph_pitch(vc->vc_font.width); 302 301 303 302 if (!mask) 304 303 return;
+6 -5
drivers/video/fbdev/core/fbcon_cw.c
··· 26 26 struct vc_data *vc) 27 27 { 28 28 int i, j, offset = (vc->vc_font.height < 10) ? 1 : 2; 29 - int width = (vc->vc_font.height + 7) >> 3; 29 + int width = font_glyph_pitch(vc->vc_font.height); 30 30 u8 c, msk = ~(0xff >> offset); 31 31 32 32 for (i = 0; i < vc->vc_font.width; i++) { ··· 86 86 { 87 87 struct fbcon_par *par = info->fbcon_par; 88 88 u16 charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff; 89 - u32 idx = (vc->vc_font.height + 7) >> 3; 89 + u32 idx = font_glyph_pitch(vc->vc_font.height); 90 90 u8 *src; 91 91 92 92 while (cnt--) { ··· 116 116 { 117 117 struct fb_image image; 118 118 struct fbcon_par *par = info->fbcon_par; 119 - u32 width = (vc->vc_font.height + 7)/8; 119 + u32 width = font_glyph_pitch(vc->vc_font.height); 120 120 u32 cellsize = width * vc->vc_font.width; 121 121 u32 maxcnt = info->pixmap.size/cellsize; 122 122 u32 scan_align = info->pixmap.scan_align - 1; ··· 206 206 struct fb_cursor cursor; 207 207 struct fbcon_par *par = info->fbcon_par; 208 208 unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff; 209 - int w = (vc->vc_font.height + 7) >> 3, c; 209 + int w = font_glyph_pitch(vc->vc_font.height); 210 + int c; 210 211 int y = real_y(par->p, vc->state.y); 211 212 int attribute, use_sw = vc->vc_cursor_type & CUR_SW; 212 213 int err = 1, dx, dy; ··· 281 280 char *tmp, *mask = kmalloc_array(w, vc->vc_font.width, 282 281 GFP_ATOMIC); 283 282 int cur_height, size, i = 0; 284 - int width = (vc->vc_font.width + 7)/8; 283 + int width = font_glyph_pitch(vc->vc_font.width); 285 284 286 285 if (!mask) 287 286 return;
+2 -4
drivers/video/fbdev/core/fbcon_rotate.c
··· 33 33 src = par->fontdata = vc->vc_font.data; 34 34 par->cur_rotate = par->p->con_rotate; 35 35 len = vc->vc_font.charcount; 36 - s_cellsize = ((vc->vc_font.width + 7)/8) * 37 - vc->vc_font.height; 36 + s_cellsize = font_glyph_size(vc->vc_font.width, vc->vc_font.height); 38 37 d_cellsize = s_cellsize; 39 38 40 39 if (par->rotate == FB_ROTATE_CW || 41 40 par->rotate == FB_ROTATE_CCW) 42 - d_cellsize = ((vc->vc_font.height + 7)/8) * 43 - vc->vc_font.width; 41 + d_cellsize = font_glyph_size(vc->vc_font.height, vc->vc_font.width); 44 42 45 43 if (info->fbops->fb_sync) 46 44 info->fbops->fb_sync(info);
+4 -3
drivers/video/fbdev/core/fbcon_ud.c
··· 26 26 struct vc_data *vc) 27 27 { 28 28 int i, offset = (vc->vc_font.height < 10) ? 1 : 2; 29 - int width = (vc->vc_font.width + 7) >> 3; 29 + int width = font_glyph_pitch(vc->vc_font.width); 30 30 unsigned int cellsize = vc->vc_font.height * width; 31 31 u8 c; 32 32 ··· 153 153 { 154 154 struct fb_image image; 155 155 struct fbcon_par *par = info->fbcon_par; 156 - u32 width = (vc->vc_font.width + 7)/8; 156 + u32 width = font_glyph_pitch(vc->vc_font.width); 157 157 u32 cellsize = width * vc->vc_font.height; 158 158 u32 maxcnt = info->pixmap.size/cellsize; 159 159 u32 scan_align = info->pixmap.scan_align - 1; ··· 253 253 struct fb_cursor cursor; 254 254 struct fbcon_par *par = info->fbcon_par; 255 255 unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff; 256 - int w = (vc->vc_font.width + 7) >> 3, c; 256 + int w = font_glyph_pitch(vc->vc_font.width); 257 + int c; 257 258 int y = real_y(par->p, vc->state.y); 258 259 int attribute, use_sw = vc->vc_cursor_type & CUR_SW; 259 260 int err = 1, dx, dy;
+40
include/linux/font.h
··· 11 11 #ifndef _VIDEO_FONT_H 12 12 #define _VIDEO_FONT_H 13 13 14 + #include <linux/math.h> 14 15 #include <linux/types.h> 15 16 16 17 struct console_font; 18 + 19 + /* 20 + * Glyphs 21 + */ 22 + 23 + /** 24 + * font_glyph_pitch - Calculates the number of bytes per scanline 25 + * @width: The glyph width in bits per scanline 26 + * 27 + * A glyph's pitch is the number of bytes in a single scanline, rounded 28 + * up to the next full byte. The parameter @width receives the number 29 + * of visible bits per scanline. For example, if width is 14 bytes per 30 + * scanline, the pitch is 2 bytes per scanline. If width is 8 bits per 31 + * scanline, the pitch is 1 byte per scanline. 32 + * 33 + * Returns: 34 + * The number of bytes in a single scanline of the glyph 35 + */ 36 + static inline unsigned int font_glyph_pitch(unsigned int width) 37 + { 38 + return DIV_ROUND_UP(width, 8); 39 + } 40 + 41 + /** 42 + * font_glyph_size - Calculates the number of bytes per glyph 43 + * @width: The glyph width in bits per scanline 44 + * @vpitch: The number of scanlines in the glyph 45 + * 46 + * The number of bytes in a glyph depends on the pitch and the number 47 + * of scanlines. font_glyph_size automatically calculates the pitch 48 + * from the given width. The parameter @vpitch gives the number of 49 + * scanlines, which is usually the glyph's height in scanlines. Fonts 50 + * coming from user space can sometimes have a different vertical pitch 51 + * with empty scanlines between two adjacent glyphs. 52 + */ 53 + static inline unsigned int font_glyph_size(unsigned int width, unsigned int vpitch) 54 + { 55 + return font_glyph_pitch(width) * vpitch; 56 + } 17 57 18 58 /* 19 59 * font_data_t and helpers
+1 -1
lib/fonts/fonts.c
··· 26 26 27 27 #include "font.h" 28 28 29 - #define console_font_pitch(font) DIV_ROUND_UP((font)->width, 8) 29 + #define console_font_pitch(font) font_glyph_pitch((font)->width) 30 30 31 31 /* 32 32 * Helpers for font_data_t