Changeset d2100e2 in mainline for uspace/lib/gfxfont/src/glyph_bmp.c
- Timestamp:
- 2020-08-09T18:40:28Z (4 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 06b8383
- Parents:
- 5592c56
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/gfxfont/src/glyph_bmp.c
r5592c56 rd2100e2 35 35 36 36 #include <errno.h> 37 #include <gfx/bitmap.h> 37 38 #include <gfx/coord.h> 39 #include <gfx/font.h> 38 40 #include <gfx/glyph_bmp.h> 41 #include <io/pixelmap.h> 39 42 #include <stdlib.h> 43 #include "../private/font.h" 44 #include "../private/glyph.h" 40 45 #include "../private/glyph_bmp.h" 41 46 … … 50 55 errno_t gfx_glyph_bmp_open(gfx_glyph_t *glyph, gfx_glyph_bmp_t **rbmp) 51 56 { 57 gfx_font_t *font = glyph->font; 52 58 gfx_glyph_bmp_t *bmp; 59 pixelmap_t pmap; 60 gfx_bitmap_alloc_t alloc; 61 gfx_coord_t x, y; 62 pixel_t pixel; 63 errno_t rc; 53 64 54 65 bmp = calloc(1, sizeof(gfx_glyph_bmp_t)); … … 58 69 bmp->rect.p0.x = 0; 59 70 bmp->rect.p0.y = 0; 60 bmp->rect.p1.x = 0; 61 bmp->rect.p1.y = 0; 62 bmp->pixels = NULL; 71 bmp->rect.p1.x = glyph->rect.p1.x - glyph->rect.p0.x; 72 bmp->rect.p1.y = glyph->rect.p1.y - glyph->rect.p0.y; 73 74 bmp->pixels = calloc(bmp->rect.p1.x * bmp->rect.p1.y, sizeof(int)); 75 if (bmp->pixels == NULL) { 76 free(bmp); 77 return ENOMEM; 78 } 79 80 rc = gfx_bitmap_get_alloc(font->bitmap, &alloc); 81 if (rc != EOK) { 82 free(bmp->pixels); 83 free(bmp); 84 return rc; 85 } 86 87 assert(font->rect.p0.x == 0); 88 assert(font->rect.p0.y == 0); 89 pmap.width = font->rect.p1.x; 90 pmap.height = font->rect.p1.y; 91 pmap.data = alloc.pixels; 92 93 /* Copy pixels from font bitmap */ 94 95 for (y = 0; y < bmp->rect.p1.y; y++) { 96 for (x = 0; x < bmp->rect.p1.x; x++) { 97 pixel = pixelmap_get_pixel(&pmap, glyph->rect.p0.x + x, 98 glyph->rect.p0.y + y); 99 bmp->pixels[y * bmp->rect.p1.x + x] = 100 (pixel != 0) ? 1 : 0; 101 } 102 } 63 103 64 104 bmp->glyph = glyph; … … 74 114 errno_t gfx_glyph_bmp_save(gfx_glyph_bmp_t *bmp) 75 115 { 116 gfx_glyph_t *glyph = bmp->glyph; 117 gfx_font_t *font = glyph->font; 118 gfx_coord_t x, y; 119 pixel_t pixel; 120 pixelmap_t pmap; 121 gfx_bitmap_alloc_t alloc; 122 errno_t rc; 123 124 /* 125 * Replace glyph with empty space in the font bitmap, the width 126 * of the empty equal to new glyph bitmap width. The glyph width 127 * is adjusted. 128 */ 129 rc = gfx_font_splice_at_glyph(font, glyph, 130 bmp->rect.p1.x - bmp->rect.p0.x, bmp->rect.p1.y - bmp->rect.p0.y); 131 if (rc != EOK) 132 return rc; 133 134 rc = gfx_bitmap_get_alloc(font->bitmap, &alloc); 135 if (rc != EOK) 136 return rc; 137 138 assert(font->rect.p0.x == 0); 139 assert(font->rect.p0.y == 0); 140 pmap.width = font->rect.p1.x; 141 pmap.height = font->rect.p1.y; 142 pmap.data = alloc.pixels; 143 144 /* Copy pixels to font bitmap */ 145 146 for (y = 0; y < bmp->rect.p1.y; y++) { 147 for (x = 0; x < bmp->rect.p1.x; x++) { 148 pixel = bmp->pixels[y * bmp->rect.p1.x + x] ? 149 PIXEL(255, 255, 255, 255) : PIXEL(0, 0, 0, 0); 150 pixelmap_put_pixel(&pmap, glyph->rect.p0.x + x, 151 glyph->rect.p0.y + y, pixel); 152 } 153 } 154 76 155 return EOK; 77 156 }
Note:
See TracChangeset
for help on using the changeset viewer.