| 306 | } |
| 307 | |
| 308 | color_t readRunLengthColor(std::ifstream &file, const Header &header) |
| 309 | { |
| 310 | color_t color{}; |
| 311 | if (header.imageType == ImageType::RleIndexed) |
| 312 | { |
| 313 | auto colormapIndex = read8(file); |
| 314 | color = header.colormap[colormapIndex]; |
| 315 | } |
| 316 | else if (header.imageType == ImageType::RleGray) |
| 317 | { |
| 318 | auto greyValue = read8(file); |
| 319 | color = rgba(greyValue, greyValue, greyValue); |
| 320 | } |
| 321 | else if (header.imageType == ImageType::RleRgb) |
| 322 | { |
| 323 | switch (header.bitsPerPixel) |
| 324 | { |
| 325 | case 15: |
| 326 | case 16: |
| 327 | color = read16AsRgb(file, header.hasAlpha); |
| 328 | break; |
| 329 | case 24: |
| 330 | color = read24AsRgb(file); |
| 331 | break; |
| 332 | case 32: |
| 333 | color = read32AsRgb(file, header.hasAlpha); |
| 334 | break; |
| 335 | default: |
| 336 | assert(false); |
| 337 | break; |
| 338 | } |
| 339 | } |
| 340 | else |
| 341 | assert(false); |
| 342 | return color; |
| 343 | } |
| 344 | |
| 345 | // In the best case (TGA 2.0 spec) this should read just one |
| 346 | // scanline, but in old TGA versions (1.0) it was possible to save |
no test coverage detected