Changeset a35b458 in mainline for uspace/lib/draw
- Timestamp:
- 2018-03-02T20:10:49Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f1380b7
- Parents:
- 3061bc1
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
- Location:
- uspace/lib/draw
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/draw/codec/tga.c
r3061bc1 ra35b458 46 46 uint8_t cmap_type; 47 47 uint8_t img_type; 48 48 49 49 uint16_t cmap_first_entry; 50 50 uint16_t cmap_entries; 51 51 uint8_t cmap_bpp; 52 52 53 53 uint16_t startx; 54 54 uint16_t starty; … … 79 79 cmap_type_t cmap_type; 80 80 img_type_t img_type; 81 81 82 82 uint16_t cmap_first_entry; 83 83 uint16_t cmap_entries; 84 84 uint8_t cmap_bpp; 85 85 86 86 uint16_t startx; 87 87 uint16_t starty; … … 91 91 uint8_t img_alpha_bpp; 92 92 uint8_t img_alpha_dir; 93 93 94 94 void *id_data; 95 95 size_t id_length; 96 96 97 97 void *cmap_data; 98 98 size_t cmap_length; 99 99 100 100 void *img_data; 101 101 size_t img_length; … … 117 117 if (size < sizeof(tga_header_t)) 118 118 return false; 119 119 120 120 tga_header_t *head = (tga_header_t *) data; 121 121 122 122 /* Image ID field */ 123 123 tga->id_data = data + sizeof(tga_header_t); 124 124 tga->id_length = head->id_length; 125 125 126 126 if (size < sizeof(tga_header_t) + tga->id_length) 127 127 return false; 128 128 129 129 /* Color map type */ 130 130 tga->cmap_type = head->cmap_type; 131 131 132 132 /* Image type */ 133 133 tga->img_type = head->img_type; 134 134 135 135 /* Color map specification */ 136 136 tga->cmap_first_entry = uint16_t_le2host(head->cmap_first_entry); … … 139 139 tga->cmap_data = tga->id_data + tga->id_length; 140 140 tga->cmap_length = ALIGN_UP(tga->cmap_entries * tga->cmap_bpp, 8) >> 3; 141 141 142 142 if (size < sizeof(tga_header_t) + tga->id_length + 143 143 tga->cmap_length) 144 144 return false; 145 145 146 146 /* Image specification */ 147 147 tga->startx = uint16_t_le2host(head->startx); … … 154 154 tga->img_data = tga->cmap_data + tga->cmap_length; 155 155 tga->img_length = ALIGN_UP(tga->width * tga->height * tga->img_bpp, 8) >> 3; 156 156 157 157 if (size < sizeof(tga_header_t) + tga->id_length + 158 158 tga->cmap_length + tga->img_length) 159 159 return false; 160 160 161 161 return true; 162 162 } … … 182 182 if (!decode_tga_header(data, size, &tga)) 183 183 return NULL; 184 184 185 185 /* 186 186 * Check for unsupported features. 187 187 */ 188 188 189 189 switch (tga.cmap_type) { 190 190 case CMAP_NOT_PRESENT: … … 194 194 return NULL; 195 195 } 196 196 197 197 switch (tga.img_type) { 198 198 case IMG_BGRA: … … 208 208 return NULL; 209 209 } 210 210 211 211 if (tga.img_alpha_bpp != 0) 212 212 return NULL; 213 213 214 214 sysarg_t twidth = tga.startx + tga.width; 215 215 sysarg_t theight = tga.starty + tga.height; 216 216 217 217 surface_t *surface = surface_create(twidth, theight, NULL, flags); 218 218 if (surface == NULL) 219 219 return NULL; 220 220 221 221 /* 222 222 * TGA is encoded in a bottom-up manner, the true-color 223 223 * variant is in BGR 8:8:8 encoding. 224 224 */ 225 225 226 226 switch (tga.img_type) { 227 227 case IMG_BGRA: … … 230 230 size_t offset = 231 231 ((y - tga.starty) * tga.width + (x - tga.startx)) * 3; 232 232 233 233 pixel_t pixel = 234 234 bgr_888_2pixel(((uint8_t *) tga.img_data) + offset); … … 242 242 size_t offset = 243 243 (y - tga.starty) * tga.width + (x - tga.startx); 244 244 245 245 pixel_t pixel = 246 246 gray_8_2pixel(((uint8_t *) tga.img_data) + offset); … … 252 252 break; 253 253 } 254 254 255 255 return surface; 256 256 } -
uspace/lib/draw/codec/tga.gz.c
r3061bc1 ra35b458 58 58 void *data_expanded; 59 59 size_t size_expanded; 60 60 61 61 errno_t ret = gzip_expand(data, size, &data_expanded, &size_expanded); 62 62 if (ret != EOK) 63 63 return NULL; 64 64 65 65 surface_t *surface = decode_tga(data_expanded, size_expanded, flags); 66 66 67 67 free(data_expanded); 68 68 return surface; -
uspace/lib/draw/codec/webp.c
r3061bc1 ra35b458 84 84 bool alpha_used; 85 85 uint8_t version; 86 86 87 87 uint8_t *src; /**< Input buffer */ 88 88 size_t srclen; /**< Input buffer size */ 89 89 size_t srccnt; /**< Position in the input buffer */ 90 90 91 91 uint32_t bitbuf; /**< Bit buffer */ 92 92 size_t bitlen; /**< Number of bits in the bit buffer */ 93 93 94 94 bool overrun; /**< Overrun condition */ 95 95 } webp_t; … … 107 107 /* Bit accumulator for at least 36 bits */ 108 108 uint64_t val = state->bitbuf; 109 109 110 110 while (state->bitlen < cnt) { 111 111 if (state->srccnt == state->srclen) { … … 113 113 return 0; 114 114 } 115 115 116 116 /* Load 8 more bits */ 117 117 val |= ((uint64_t) state->src[state->srccnt]) << state->bitlen; … … 119 119 state->bitlen += 8; 120 120 } 121 121 122 122 /* Update bits in the buffer */ 123 123 state->bitbuf = (uint32_t) (val >> cnt); 124 124 state->bitlen -= cnt; 125 125 126 126 return ((uint32_t) (val & ((1 << cnt) - 1))); 127 127 } … … 143 143 (size - sizeof(riff_header_t) < sizeof(webp_header_t))) 144 144 return false; 145 145 146 146 riff_header_t *riff_header = (riff_header_t *) data; 147 147 if (riff_header->fourcc != FOURCC_RIFF) 148 148 return false; 149 149 150 150 /* Check payload size */ 151 151 size_t payload_size = uint32_t_le2host(riff_header->payload_size); 152 152 if (payload_size + sizeof(riff_header_t) > size) 153 153 return false; 154 154 155 155 data += sizeof(riff_header_t); 156 156 webp_header_t *webp_header = (webp_header_t *) data; 157 157 if (webp_header->fourcc != FOURCC_WEBP) 158 158 return false; 159 159 160 160 /* Only lossless encoding supported so far */ 161 161 if (webp_header->encoding != FOURCC_WEBP_LOSSLESS) 162 162 return false; 163 163 164 164 webp->stream_size = uint32_t_le2host(webp_header->stream_size); 165 165 if (webp->stream_size + sizeof(riff_header_t) + 166 166 sizeof(webp_header_t) > size) 167 167 return false; 168 168 169 169 if (webp_header->signature != SIGNATURE_WEBP_LOSSLESS) 170 170 return false; 171 171 172 172 data += sizeof(webp_header_t); 173 173 174 174 /* Setup decoding state */ 175 175 webp->src = (uint8_t *) data; … … 179 179 webp->bitlen = 0; 180 180 webp->overrun = false; 181 181 182 182 /* Decode the rest of the metadata */ 183 183 webp->width = get_bits(webp, 14) + 1; 184 184 CHECK_OVERRUN(*webp, false); 185 185 186 186 webp->height = get_bits(webp, 14) + 1; 187 187 CHECK_OVERRUN(*webp, false); 188 188 189 189 webp->alpha_used = get_bits(webp, 1); 190 190 CHECK_OVERRUN(*webp, false); 191 191 192 192 webp->version = get_bits(webp, 3); 193 193 CHECK_OVERRUN(*webp, false); 194 194 195 195 if (webp->version != 0) 196 196 return false; 197 197 198 198 return true; 199 199 } … … 218 218 if (!decode_webp_header(data, size, &webp)) 219 219 return NULL; 220 220 221 221 bool transform_present = false; 222 222 223 223 do { 224 224 transform_present = get_bits(&webp, 1); 225 225 CHECK_OVERRUN(webp, NULL); 226 226 227 227 if (transform_present) { 228 228 webp_transform_t transform = get_bits(&webp, 2); 229 229 CHECK_OVERRUN(webp, NULL); 230 230 231 231 if (transform == TRANSFORM_PREDICTOR) { 232 232 // FIXME TODO 233 233 } else 234 234 return NULL; 235 235 236 236 // FIXME: decode other transforms 237 237 } 238 238 } while (transform_present); 239 239 240 240 // FIXME: decode image data 241 241 242 242 return NULL; 243 243 } -
uspace/lib/draw/cursor/embedded.c
r3061bc1 ra35b458 47 47 assert(state_count); 48 48 assert(data); 49 49 50 50 (*state_count) = 1; 51 51 (*data) = NULL; … … 56 56 if (state != 0) 57 57 return NULL; 58 58 59 59 surface_t *surface = surface_create(CURSOR_WIDTH, CURSOR_HEIGHT, NULL, 0); 60 60 if (!surface) 61 61 return NULL; 62 62 63 63 for (unsigned int y = 0; y < CURSOR_HEIGHT; ++y) { 64 64 for (unsigned int x = 0; x < CURSOR_WIDTH; ++x) { … … 67 67 pixel_t pixel = (cursor_texture[offset] & (1 << (x % 8))) ? 68 68 PIXEL(255, 0, 0, 0) : PIXEL(255, 255, 255, 255); 69 69 70 70 if (visible) 71 71 surface_put_pixel(surface, x, y, pixel); 72 72 } 73 73 } 74 74 75 75 return surface; 76 76 } -
uspace/lib/draw/font.c
r3061bc1 ra35b458 48 48 if (font == NULL) 49 49 return NULL; 50 50 51 51 font->backend = backend; 52 52 font->backend_data = backend_data; 53 53 54 54 return font; 55 55 } … … 97 97 if (c == 0) 98 98 break; 99 99 100 100 glyph_id_t glyph_id; 101 101 rc = font_resolve_glyph(font, c, &glyph_id); … … 106 106 } 107 107 } 108 108 109 109 glyph_metrics_t glyph_metrics; 110 110 rc = font_get_glyph_metrics(font, glyph_id, &glyph_metrics); 111 111 if (rc != EOK) 112 112 return rc; 113 113 114 114 x += glyph_metrics_get_advancement(&glyph_metrics); 115 115 } … … 140 140 if (c == 0) 141 141 break; 142 142 143 143 glyph_id_t glyph_id; 144 144 rc = font_resolve_glyph(font, c, &glyph_id); … … 149 149 } 150 150 } 151 151 152 152 glyph_metrics_t glyph_metrics; 153 153 rc = font_get_glyph_metrics(font, glyph_id, &glyph_metrics); -
uspace/lib/draw/font.h
r3061bc1 ra35b458 51 51 /* Horizontal distance between origin and left side of the glyph */ 52 52 metric_t left_side_bearing; 53 53 54 54 /* Width of the actual glyph drawn */ 55 55 metric_t width; 56 56 57 57 /* Horizontal distance between right side of the glyph and origin 58 58 of the next glyph */ 59 59 metric_t right_side_bearing; 60 60 61 61 /* Vertical distance between baseline and top of the glyph 62 62 (positive to top) */ 63 63 metric_t ascender; 64 64 65 65 /* Height of the actual glyph drawn */ 66 66 metric_t height; … … 80 80 /* Distance between top of the line and baseline */ 81 81 metric_t ascender; 82 82 83 83 /* Distance between baseline and bottom of the line */ 84 84 metric_t descender; 85 85 86 86 /* Distance between bottom of the line and top of the next line */ 87 87 metric_t leading; -
uspace/lib/draw/font/bitmap_backend.c
r3061bc1 ra35b458 62 62 { 63 63 bitmap_backend_data_t *data = (bitmap_backend_data_t *) backend_data; 64 64 65 65 *font_metrics = data->font_metrics; 66 66 67 67 return EOK; 68 68 } … … 78 78 { 79 79 bitmap_backend_data_t *data = (bitmap_backend_data_t *) backend_data; 80 80 81 81 if (glyph_id >= data->glyph_count) 82 82 return ENOENT; 83 83 84 84 if (data->glyph_cache[glyph_id].metrics_loaded) { 85 85 *glyph_metrics = data->glyph_cache[glyph_id].metrics; 86 86 return EOK; 87 87 } 88 88 89 89 glyph_metrics_t gm; 90 90 91 91 errno_t rc = data->decoder->load_glyph_metrics(data->decoder_data, glyph_id, 92 92 &gm); 93 93 if (rc != EOK) 94 94 return rc; 95 95 96 96 if (data->scale) { 97 97 gm.left_side_bearing = (metric_t) … … 106 106 (data->scale_ratio * gm.height + 0.5); 107 107 } 108 109 110 108 109 110 111 111 data->glyph_cache[glyph_id].metrics = gm; 112 112 data->glyph_cache[glyph_id].metrics_loaded = true; … … 120 120 if (glyph_id >= data->glyph_count) 121 121 return ENOENT; 122 122 123 123 if (data->glyph_cache[glyph_id].surface != NULL) { 124 124 *result = data->glyph_cache[glyph_id].surface; 125 125 return EOK; 126 126 } 127 127 128 128 surface_t *raw_surface; 129 129 errno_t rc = data->decoder->load_glyph_surface(data->decoder_data, glyph_id, … … 131 131 if (rc != EOK) 132 132 return rc; 133 133 134 134 sysarg_t w; 135 135 sysarg_t h; 136 136 surface_get_resolution(raw_surface, &w, &h); 137 137 138 138 if (!data->scale) { 139 139 *result = raw_surface; 140 140 return EOK; 141 141 } 142 142 143 143 source_t source; 144 144 source_init(&source); … … 167 167 168 168 surface_destroy(raw_surface); 169 169 170 170 data->glyph_cache[glyph_id].surface = scaled_surface; 171 171 *result = scaled_surface; … … 177 177 { 178 178 bitmap_backend_data_t *data = (bitmap_backend_data_t *) backend_data; 179 179 180 180 glyph_metrics_t glyph_metrics; 181 181 errno_t rc = bb_get_glyph_metrics(backend_data, glyph_id, &glyph_metrics); 182 182 if (rc != EOK) 183 183 return rc; 184 184 185 185 surface_t *glyph_surface; 186 186 rc = get_glyph_surface(data, glyph_id, &glyph_surface); 187 187 if (rc != EOK) 188 188 return rc; 189 189 190 190 native_t x = ox + glyph_metrics.left_side_bearing; 191 191 native_t y = oy - glyph_metrics.ascender; 192 192 193 193 transform_t transform; 194 194 transform_identity(&transform); … … 230 230 if (glyph_count == 0) 231 231 return EINVAL; 232 232 233 233 bitmap_backend_data_t *data = malloc(sizeof(bitmap_backend_data_t)); 234 234 if (data == NULL) … … 275 275 return ENOMEM; 276 276 } 277 277 278 278 *out_font = font; 279 279 return EOK; -
uspace/lib/draw/font/embedded.c
r3061bc1 ra35b458 51 51 if (!found) 52 52 return ENOENT; 53 53 54 54 *glyph_id = glyph; 55 55 return EOK; … … 62 62 if (!surface) 63 63 return ENOMEM; 64 64 65 65 for (unsigned int y = 0; y < FONT_SCANLINES; ++y) { 66 66 for (unsigned int x = 0; x < FONT_WIDTH; ++x) { … … 70 70 } 71 71 } 72 72 73 73 *out_surface = surface; 74 74 return EOK; … … 84 84 gm->ascender = FONT_ASCENDER; 85 85 gm->height = FONT_SCANLINES; 86 86 87 87 return EOK; 88 88 } -
uspace/lib/draw/font/pcf.c
r3061bc1 ra35b458 151 151 { 152 152 pcf_data_t *data = (pcf_data_t *) opaque_data; 153 153 154 154 /* TODO is this correct? */ 155 155 uint8_t byte1 = (chr >> 8) & 0xff; … … 160 160 (byte1 - e->min_byte1) * (e->max_byte2 - e->min_byte2 + 1) + 161 161 (byte2 - e->min_byte2); 162 162 163 163 aoff64_t entry_offset = data->encodings_table.offset + 164 164 (sizeof(uint32_t) + 5 * sizeof(uint16_t)) + 165 165 entry_index * sizeof(uint16_t); 166 166 167 167 int rc = fseek(data->file, entry_offset, SEEK_SET); 168 168 if (rc != 0) 169 169 return errno; 170 170 171 171 uint16_t glyph = 0; 172 172 size_t records_read = fread(&glyph, sizeof(uint16_t), 1, data->file); 173 173 if (records_read != 1) 174 174 return EINVAL; 175 175 176 176 glyph = uint16_t_pcf2host(glyph, data->encodings_table.format); 177 177 178 178 if (glyph == 0xffff) 179 179 return ENOENT; 180 180 181 181 *glyph_id = glyph; 182 182 183 183 return EOK; 184 184 } … … 190 190 int rc; 191 191 size_t records_read; 192 192 193 193 if (table->format & PCF_FORMAT_COMPRESSED_METRICS) { 194 194 offset = table->offset + sizeof(uint32_t) + sizeof(uint16_t) + 195 195 glyph_id * sizeof(pcf_compressed_metrics_t); 196 196 197 197 rc = fseek(data->file, offset, SEEK_SET); 198 198 if (rc != 0) 199 199 return errno; 200 200 201 201 pcf_compressed_metrics_t compressed_metrics; 202 202 records_read = fread(&compressed_metrics, … … 204 204 if (records_read != 1) 205 205 return EINVAL; 206 206 207 207 metrics->left_side_bearing = 208 208 compressed2int(compressed_metrics.left_side_bearing); … … 220 220 offset = table->offset + 2 * sizeof(uint32_t) + 221 221 glyph_id * sizeof(pcf_default_metrics_t); 222 222 223 223 rc = fseek(data->file, offset, SEEK_SET); 224 224 if (rc != 0) 225 225 return errno; 226 226 227 227 pcf_default_metrics_t uncompressed_metrics; 228 228 records_read = fread(&uncompressed_metrics, … … 230 230 if (records_read != 1) 231 231 return EINVAL; 232 232 233 233 metrics->left_side_bearing = 234 234 int16_t_pcf2host(uncompressed_metrics.left_side_bearing, … … 250 250 table->format); 251 251 } 252 252 253 253 return EOK; 254 254 } … … 258 258 { 259 259 pcf_data_t *data = (pcf_data_t *) opaque_data; 260 260 261 261 pcf_default_metrics_t pcf_metrics; 262 262 memset(&pcf_metrics, 0, sizeof(pcf_default_metrics_t)); … … 265 265 if (rc != EOK) 266 266 return rc; 267 267 268 268 aoff64_t offset = data->bitmap_table.offset + (2 * sizeof(uint32_t)) + 269 269 (glyph_id * sizeof(uint32_t)); 270 270 271 271 if (fseek(data->file, offset, SEEK_SET) < 0) 272 272 return errno; 273 273 274 274 uint32_t bitmap_offset = 0; 275 275 size_t records_read = fread(&bitmap_offset, sizeof(uint32_t), 1, … … 279 279 bitmap_offset = uint32_t_pcf2host(bitmap_offset, 280 280 data->bitmap_table.format); 281 281 282 282 offset = data->bitmap_table.offset + (2 * sizeof(uint32_t)) + 283 283 (data->glyph_count * sizeof(uint32_t)) + (4 * sizeof(uint32_t)) 284 284 + bitmap_offset; 285 285 286 286 if (fseek(data->file, offset, SEEK_SET) < 0) 287 287 return errno; 288 288 289 289 surface_coord_t width = pcf_metrics.character_width; 290 290 surface_coord_t height = pcf_metrics.character_ascent + … … 294 294 size_t row_bytes = ALIGN_UP(ALIGN_UP(width, 8) / 8, row_padding_bytes); 295 295 size_t bitmap_bytes = height * row_bytes; 296 296 297 297 uint8_t *bitmap = malloc(bitmap_bytes); 298 298 if (bitmap == NULL) 299 299 return ENOMEM; 300 300 301 301 records_read = fread(bitmap, sizeof(uint8_t), bitmap_bytes, 302 302 data->file); 303 303 304 304 surface_t *surface = surface_create(width, height, NULL, 0); 305 305 if (!surface) { … … 307 307 return ENOMEM; 308 308 } 309 309 310 310 for (unsigned int y = 0; y < height; ++y) { 311 311 size_t row_offset = row_bytes * y; … … 334 334 } 335 335 } 336 336 337 337 *out_surface = surface; 338 338 free(bitmap); … … 344 344 { 345 345 pcf_data_t *data = (pcf_data_t *) opaque_data; 346 346 347 347 pcf_default_metrics_t pcf_metrics; 348 348 memset(&pcf_metrics, 0, sizeof(pcf_default_metrics_t)); … … 351 351 if (rc != EOK) 352 352 return rc; 353 353 354 354 gm->left_side_bearing = pcf_metrics.left_side_bearing; 355 355 gm->width = pcf_metrics.character_width; … … 359 359 pcf_metrics.character_ascent; 360 360 gm->ascender = pcf_metrics.character_ascent; 361 361 362 362 return EOK; 363 363 } … … 366 366 { 367 367 pcf_data_t *data = (pcf_data_t *) opaque_data; 368 368 369 369 fclose(data->file); 370 370 free(data); … … 383 383 if (rc != 0) 384 384 return errno; 385 385 386 386 aoff64_t file_size = ftell(data->file); 387 387 388 388 rc = fseek(data->file, 0, SEEK_SET); 389 389 if (rc != 0) 390 390 return errno; 391 391 392 392 char header[4]; 393 393 size_t records_read = fread(header, sizeof(char), 4, data->file); 394 394 if (records_read != 4) 395 395 return EINVAL; 396 396 397 397 if (header[0] != 1 || header[1] != 'f' || header[2] != 'c' || 398 398 header[3] != 'p') 399 399 return EINVAL; 400 400 401 401 uint32_t table_count; 402 402 records_read = fread(&table_count, sizeof(uint32_t), 1, … … 404 404 if (records_read != 1) 405 405 return EINVAL; 406 406 407 407 table_count = uint32_t_le2host(table_count); 408 408 409 409 bool found_bitmap_table = false; 410 410 bool found_metrics_table = false; 411 411 bool found_encodings_table = false; 412 412 bool found_accelerators_table = false; 413 413 414 414 for (uint32_t index = 0; index < table_count; index++) { 415 415 pcf_toc_entry_t toc_entry; … … 420 420 toc_entry.size = uint32_t_le2host(toc_entry.size); 421 421 toc_entry.offset = uint32_t_le2host(toc_entry.offset); 422 422 423 423 if (toc_entry.offset >= file_size) 424 424 continue; 425 425 426 426 aoff64_t end = ((aoff64_t) toc_entry.offset) + ((aoff64_t) toc_entry.size); 427 427 if (end > file_size) 428 428 continue; 429 429 430 430 if (toc_entry.type == PCF_TABLE_BITMAPS) { 431 431 if (found_bitmap_table) … … 453 453 } 454 454 } 455 455 456 456 if (!found_bitmap_table || !found_metrics_table || 457 457 !found_encodings_table || !found_accelerators_table) 458 458 return EINVAL; 459 459 460 460 return EOK; 461 461 } … … 467 467 if (rc != 0) 468 468 return errno; 469 469 470 470 size_t records_read = fread(&format, sizeof(uint32_t), 1, data->file); 471 471 if (records_read != 1) 472 472 return EINVAL; 473 473 474 474 format = uint32_t_le2host(format); 475 475 if (format != table->format) 476 476 return EINVAL; 477 477 478 478 return EOK; 479 479 } … … 484 484 if (rc != EOK) 485 485 return rc; 486 486 487 487 if ((data->bitmap_table.format & PCF_FORMAT_MASK) != PCF_FORMAT_DEFAULT) 488 488 return EINVAL; 489 489 490 490 uint32_t glyph_count = 0; 491 491 size_t records_read = fread(&glyph_count, sizeof(uint32_t), 1, … … 504 504 if (rc != EOK) 505 505 return rc; 506 506 507 507 size_t records_read; 508 508 uint32_t metrics_count; … … 525 525 data->metrics_table.format); 526 526 } 527 527 528 528 if (metrics_count != data->glyph_count) 529 529 return EINVAL; 530 530 531 531 return EOK; 532 532 } … … 537 537 if (rc != EOK) 538 538 return rc; 539 539 540 540 pcf_encoding_t encoding; 541 541 size_t records_read = fread(&encoding, sizeof(pcf_encoding_t), 1, … … 543 543 if (records_read != 1) 544 544 return EINVAL; 545 545 546 546 encoding.min_byte1 = uint16_t_pcf2host(encoding.min_byte1, 547 547 data->encodings_table.format); … … 554 554 encoding.default_char = uint16_t_pcf2host(encoding.default_char, 555 555 data->encodings_table.format); 556 556 557 557 data->encoding = encoding; 558 558 return EOK; … … 564 564 if (rc != EOK) 565 565 return rc; 566 566 567 567 pcf_accelerators_t accelerators; 568 568 size_t records_read = fread(&accelerators, sizeof(pcf_accelerators_t), … … 570 570 if (records_read != 1) 571 571 return EINVAL; 572 572 573 573 data->font_metrics.ascender = int32_t_pcf2host(accelerators.font_ascent, 574 574 data->accelerators_table.format); … … 576 576 data->accelerators_table.format); 577 577 data->font_metrics.leading = 0; 578 578 579 579 return EOK; 580 580 } … … 586 586 if (data == NULL) 587 587 return ENOMEM; 588 588 589 589 data->file = fopen(filename, "rb"); 590 590 if (data->file == NULL) 591 591 goto read_error; 592 592 593 593 rc = pcf_read_toc(data); 594 594 if (rc != EOK) 595 595 goto error; 596 596 597 597 rc = pcf_read_bitmap_table_header(data); 598 598 if (rc != EOK) 599 599 goto error; 600 600 601 601 rc = pcf_read_metrics_table_header(data); 602 602 if (rc != EOK) 603 603 goto error; 604 604 605 605 rc = pcf_read_encodings_table_header(data); 606 606 if (rc != EOK) 607 607 goto error; 608 608 609 609 rc = pcf_read_accelerators_table(data); 610 610 if (rc != EOK) 611 611 goto error; 612 612 613 613 rc = bitmap_font_create(&fd_pcf, data, data->glyph_count, 614 614 data->font_metrics, points, font); 615 615 if (rc != EOK) 616 616 goto error; 617 617 618 618 return EOK; 619 619 read_error: -
uspace/lib/draw/gfx/font-8x16.c
r3061bc1 ra35b458 51 51 if (found) 52 52 *found = true; 53 53 54 54 if (ch == 0x0000) 55 55 return 0; 56 56 57 57 if ((ch >= 0x0020) && (ch <= 0x007f)) 58 58 return (ch - 32); 59 59 60 60 if ((ch >= 0x00a0) && (ch <= 0x021f)) 61 61 return (ch - 64); 62 62 63 63 if ((ch >= 0x0222) && (ch <= 0x0233)) 64 64 return (ch - 66); 65 65 66 66 if ((ch >= 0x0250) && (ch <= 0x02ad)) 67 67 return (ch - 94); 68 68 69 69 if ((ch >= 0x02b0) && (ch <= 0x02cf)) 70 70 return (ch - 96); 71 71 72 72 if ((ch >= 0x02d8) && (ch <= 0x02dd)) 73 73 return (ch - 104); 74 74 75 75 if (ch == 0x02ee) 76 76 return 630; 77 77 78 78 if ((ch >= 0x0300) && (ch <= 0x0301)) 79 79 return (ch - 137); 80 80 81 81 if (ch == 0x0303) 82 82 return 633; 83 83 84 84 if (ch == 0x0309) 85 85 return 634; 86 86 87 87 if ((ch >= 0x0312) && (ch <= 0x0314)) 88 88 return (ch - 151); 89 89 90 90 if (ch == 0x0323) 91 91 return 638; 92 92 93 93 if ((ch >= 0x0340) && (ch <= 0x0341)) 94 94 return (ch - 193); 95 95 96 96 if ((ch >= 0x0374) && (ch <= 0x0375)) 97 97 return (ch - 243); 98 98 99 99 if (ch == 0x037a) 100 100 return 643; 101 101 102 102 if (ch == 0x037e) 103 103 return 644; 104 104 105 105 if ((ch >= 0x0384) && (ch <= 0x038a)) 106 106 return (ch - 255); 107 107 108 108 if (ch == 0x038c) 109 109 return 652; 110 110 111 111 if ((ch >= 0x038e) && (ch <= 0x03a1)) 112 112 return (ch - 257); 113 113 114 114 if ((ch >= 0x03a3) && (ch <= 0x03ce)) 115 115 return (ch - 258); 116 116 117 117 if ((ch >= 0x03d0) && (ch <= 0x03d7)) 118 118 return (ch - 259); 119 119 120 120 if ((ch >= 0x03da) && (ch <= 0x03f3)) 121 121 return (ch - 261); 122 122 123 123 if ((ch >= 0x0400) && (ch <= 0x0486)) 124 124 return (ch - 273); 125 125 126 126 if ((ch >= 0x0488) && (ch <= 0x04ce)) 127 127 return (ch - 274); 128 128 129 129 if ((ch >= 0x04d0) && (ch <= 0x04f5)) 130 130 return (ch - 275); 131 131 132 132 if ((ch >= 0x04f8) && (ch <= 0x04f9)) 133 133 return (ch - 277); 134 134 135 135 if ((ch >= 0x0500) && (ch <= 0x050f)) 136 136 return (ch - 283); 137 137 138 138 if ((ch >= 0x0530) && (ch <= 0x0556)) 139 139 return (ch - 315); 140 140 141 141 if ((ch >= 0x0559) && (ch <= 0x055f)) 142 142 return (ch - 317); 143 143 144 144 if ((ch >= 0x0561) && (ch <= 0x0587)) 145 145 return (ch - 318); 146 146 147 147 if ((ch >= 0x0589) && (ch <= 0x058a)) 148 148 return (ch - 319); 149 149 150 150 if ((ch >= 0x0591) && (ch <= 0x05a1)) 151 151 return (ch - 325); 152 152 153 153 if ((ch >= 0x05a3) && (ch <= 0x05b9)) 154 154 return (ch - 326); 155 155 156 156 if ((ch >= 0x05bb) && (ch <= 0x05c4)) 157 157 return (ch - 327); 158 158 159 159 if ((ch >= 0x05d0) && (ch <= 0x05ea)) 160 160 return (ch - 338); 161 161 162 162 if ((ch >= 0x05f0) && (ch <= 0x05f4)) 163 163 return (ch - 343); 164 164 165 165 if (ch == 0x060c) 166 166 return 1182; 167 167 168 168 if (ch == 0x061b) 169 169 return 1183; 170 170 171 171 if (ch == 0x061f) 172 172 return 1184; 173 173 174 174 if ((ch >= 0x0621) && (ch <= 0x063a)) 175 175 return (ch - 384); 176 176 177 177 if ((ch >= 0x0640) && (ch <= 0x0655)) 178 178 return (ch - 389); 179 179 180 180 if ((ch >= 0x0660) && (ch <= 0x066d)) 181 181 return (ch - 399); 182 182 183 183 if ((ch >= 0x0670) && (ch <= 0x06ed)) 184 184 return (ch - 401); 185 185 186 186 if ((ch >= 0x06f0) && (ch <= 0x06fe)) 187 187 return (ch - 403); 188 188 189 189 if (ch == 0x10d3) 190 190 return 1388; 191 191 192 192 if (ch == 0x10d7) 193 193 return 1389; 194 194 195 195 if (ch == 0x10da) 196 196 return 1390; 197 197 198 198 if (ch == 0x10dd) 199 199 return 1391; 200 200 201 201 if (ch == 0x10e6) 202 202 return 1392; 203 203 204 204 if ((ch >= 0x1e00) && (ch <= 0x1e9b)) 205 205 return (ch - 6287); 206 206 207 207 if ((ch >= 0x1ea0) && (ch <= 0x1ef9)) 208 208 return (ch - 6291); 209 209 210 210 if ((ch >= 0x1f00) && (ch <= 0x1f07)) 211 211 return (ch - 6297); 212 212 213 213 if ((ch >= 0x2000) && (ch <= 0x2027)) 214 214 return (ch - 6545); 215 215 216 216 if ((ch >= 0x2030) && (ch <= 0x2046)) 217 217 return (ch - 6553); 218 218 219 219 if ((ch >= 0x2048) && (ch <= 0x204d)) 220 220 return (ch - 6554); 221 221 222 222 if (ch == 0x2070) 223 223 return 1716; 224 224 225 225 if ((ch >= 0x2074) && (ch <= 0x208f)) 226 226 return (ch - 6591); 227 227 228 228 if ((ch >= 0x20a0) && (ch <= 0x20af)) 229 229 return (ch - 6607); 230 230 231 231 if ((ch >= 0x2100) && (ch <= 0x213a)) 232 232 return (ch - 6687); 233 233 234 234 if ((ch >= 0x2153) && (ch <= 0x2183)) 235 235 return (ch - 6711); 236 236 237 237 if ((ch >= 0x2190) && (ch <= 0x21f3)) 238 238 return (ch - 6723); 239 239 240 240 if ((ch >= 0x2200) && (ch <= 0x22f1)) 241 241 return (ch - 6735); 242 242 243 243 if (ch == 0x2300) 244 244 return 2211; 245 245 246 246 if (ch == 0x2302) 247 247 return 2212; 248 248 249 249 if ((ch >= 0x2308) && (ch <= 0x230b)) 250 250 return (ch - 6755); 251 251 252 252 if (ch == 0x2310) 253 253 return 2217; 254 254 255 255 if (ch == 0x2318) 256 256 return 2218; 257 257 258 258 if ((ch >= 0x231a) && (ch <= 0x231b)) 259 259 return (ch - 6767); 260 260 261 261 if ((ch >= 0x2320) && (ch <= 0x2321)) 262 262 return (ch - 6771); 263 263 264 264 if ((ch >= 0x2329) && (ch <= 0x232a)) 265 265 return (ch - 6778); 266 266 267 267 if ((ch >= 0x239b) && (ch <= 0x23bd)) 268 268 return (ch - 6890); 269 269 270 270 if (ch == 0x23ce) 271 271 return 2260; 272 272 273 273 if ((ch >= 0x2409) && (ch <= 0x240d)) 274 274 return (ch - 6964); 275 275 276 276 if ((ch >= 0x2423) && (ch <= 0x2424)) 277 277 return (ch - 6985); 278 278 279 279 if (ch == 0x2426) 280 280 return 2268; 281 281 282 282 if ((ch >= 0x2500) && (ch <= 0x2595)) 283 283 return (ch - 7203); 284 284 285 285 if ((ch >= 0x25a0) && (ch <= 0x25f7)) 286 286 return (ch - 7213); 287 287 288 288 if ((ch >= 0x2600) && (ch <= 0x2602)) 289 289 return (ch - 7221); 290 290 291 291 if ((ch >= 0x2605) && (ch <= 0x260d)) 292 292 return (ch - 7223); 293 293 294 294 if ((ch >= 0x2610) && (ch <= 0x2613)) 295 295 return (ch - 7225); 296 296 297 297 if (ch == 0x2620) 298 298 return 2523; 299 299 300 300 if (ch == 0x2622) 301 301 return 2524; 302 302 303 303 if (ch == 0x2626) 304 304 return 2525; 305 305 306 306 if ((ch >= 0x2628) && (ch <= 0x262b)) 307 307 return (ch - 7242); 308 308 309 309 if ((ch >= 0x262e) && (ch <= 0x2637)) 310 310 return (ch - 7244); 311 311 312 312 if ((ch >= 0x2639) && (ch <= 0x2653)) 313 313 return (ch - 7245); 314 314 315 315 if ((ch >= 0x2660) && (ch <= 0x2667)) 316 316 return (ch - 7257); 317 317 318 318 if ((ch >= 0x2669) && (ch <= 0x266f)) 319 319 return (ch - 7258); 320 320 321 321 if ((ch >= 0xfb00) && (ch <= 0xfb05)) 322 322 return (ch - 61674); 323 323 324 324 if ((ch >= 0xfb50) && (ch <= 0xfbb1)) 325 325 return (ch - 61748); 326 326 327 327 if ((ch >= 0xfbd3) && (ch <= 0xfbe9)) 328 328 return (ch - 61781); 329 329 330 330 if ((ch >= 0xfbfc) && (ch <= 0xfbff)) 331 331 return (ch - 61799); 332 332 333 333 if ((ch >= 0xfc5b) && (ch <= 0xfc63)) 334 334 return (ch - 61890); 335 335 336 336 if (ch == 0xfc90) 337 337 return 2722; 338 338 339 339 if ((ch >= 0xfcf2) && (ch <= 0xfcf4)) 340 340 return (ch - 62031); 341 341 342 342 if ((ch >= 0xfd3c) && (ch <= 0xfd3f)) 343 343 return (ch - 62102); 344 344 345 345 if (ch == 0xfdf2) 346 346 return 2730; 347 347 348 348 if ((ch >= 0xfe50) && (ch <= 0xfe52)) 349 349 return (ch - 62373); 350 350 351 351 if ((ch >= 0xfe54) && (ch <= 0xfe66)) 352 352 return (ch - 62374); 353 353 354 354 if ((ch >= 0xfe68) && (ch <= 0xfe6b)) 355 355 return (ch - 62375); 356 356 357 357 if ((ch >= 0xfe70) && (ch <= 0xfe72)) 358 358 return (ch - 62379); 359 359 360 360 if (ch == 0xfe74) 361 361 return 2760; 362 362 363 363 if ((ch >= 0xfe76) && (ch <= 0xfefc)) 364 364 return (ch - 62381); 365 365 366 366 if (ch == 0xfeff) 367 367 return 2896; 368 368 369 369 if (found) 370 370 *found = false; 371 371 372 372 return 2898; 373 373 } … … 3272 3272 {0xf1, 0x35, 0x55, 0x8a, 0xe0, 0x06, 0x95, 0xd6, 0xb5, 0x97, 0x00, 0xee, 0x8a, 0xee, 0x28, 0xe8}, 3273 3273 {0x00, 0x38, 0x7c, 0x7c, 0xc6, 0x92, 0xf2, 0xe6, 0xfe, 0xe6, 0x7c, 0x7c, 0x38, 0x00, 0x00, 0x00}, 3274 3274 3275 3275 /* Special glyph for unknown character */ 3276 3276 {0x00, 0x00, 0x7c, 0xc6, 0xc6, 0x0c, 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00} -
uspace/lib/draw/path.c
r3061bc1 ra35b458 83 83 step->to_y = path->cur_y; 84 84 list_append(&step->link, &path->list); 85 85 86 86 } 87 87 } -
uspace/lib/draw/source.c
r3061bc1 ra35b458 42 42 transform_identity(&source->transform); 43 43 source->filter = filter_nearest; 44 44 45 45 source->color = PIXEL(0, 0, 0, 0); 46 46 source->texture = NULL; -
uspace/lib/draw/surface.c
r3061bc1 ra35b458 59 59 return NULL; 60 60 } 61 61 62 62 size_t pixbuf_size = width * height * sizeof(pixel_t); 63 63 … … 124 124 assert(width); 125 125 assert(height); 126 126 127 127 *width = surface->pixmap.width; 128 128 *height = surface->pixmap.height;
Note:
See TracChangeset
for help on using the changeset viewer.