Changeset a35b458 in mainline for uspace/lib/draw/codec
- 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/codec
- Files:
-
- 3 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 }
Note:
See TracChangeset
for help on using the changeset viewer.