Changes in uspace/lib/draw/codec/tga.c [9250517:a35b458] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/draw/codec/tga.c
r9250517 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 }
Note:
See TracChangeset
for help on using the changeset viewer.