In the best case (TGA 2.0 spec) this should read just one scanline, but in old TGA versions (1.0) it was possible to save several scanlines with the same RLE data. Returns true when are are done.
| 348 | // |
| 349 | // Returns true when are are done. |
| 350 | bool readRunLengthDataIntoImage(std::ifstream & file, |
| 351 | const Header & header, |
| 352 | dec::Targa::Image &image, |
| 353 | unsigned yStart) |
| 354 | { |
| 355 | unsigned y = yStart; |
| 356 | unsigned x = 0; |
| 357 | for (int j = 0; j < header.width && !file.eof();) |
| 358 | { |
| 359 | int c = read8(file); |
| 360 | if (c & 0x80) |
| 361 | { |
| 362 | c = (c & 0x7f) + 1; |
| 363 | j += c; |
| 364 | |
| 365 | auto color = readRunLengthColor(file, header); |
| 366 | while (c-- > 0) |
| 367 | { |
| 368 | setColorInImage(image, color, x, y, header); |
| 369 | x++; |
| 370 | if (x >= header.width) |
| 371 | { |
| 372 | y++; |
| 373 | x = 0; |
| 374 | } |
| 375 | } |
| 376 | } |
| 377 | else |
| 378 | { |
| 379 | ++c; |
| 380 | j += c; |
| 381 | while (c-- > 0) |
| 382 | { |
| 383 | auto color = readRunLengthColor(file, header); |
| 384 | setColorInImage(image, color, x, y, header); |
| 385 | x++; |
| 386 | if (x >= header.width) |
| 387 | { |
| 388 | y++; |
| 389 | x = 0; |
| 390 | } |
| 391 | } |
| 392 | } |
| 393 | } |
| 394 | return false; |
| 395 | } |
| 396 | |
| 397 | std::optional<Header> readHeader(std::ifstream &file) |
| 398 | { |
no test coverage detected