MCPcopy Create free account
hub / github.com/IENT/YUView / readImage

Function readImage

YUViewLib/src/decoder/decoderTarga.cpp:492–559  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

490}
491
492dec::Targa::Image readImage(std::ifstream &file, const Header &header)
493{
494 dec::Targa::Image image;
495 image.size.width = header.width;
496 image.size.height = header.height;
497 image.data.resize(header.width * 4 * header.height);
498
499 // Bit 4 means right-to-left, else left-to-right
500 // Bit 5 means top-to-bottom, else bottom-to-top
501
502 for (int y = 0; y < header.height; ++y)
503 {
504 if (header.imageType == ImageType::UncompressedIndexed)
505 {
506 assert(header.bitsPerPixel == 8);
507 for (int x = 0; x < header.width; ++x)
508 {
509 auto colormapIdx = read8(file);
510 auto color = header.colormap[colormapIdx];
511 setColorInImage(image, color, x, y, header);
512 }
513 }
514 else if (header.imageType == ImageType::UncompressedRgb)
515 {
516 color_t color{};
517 for (int x = 0; x < header.width; ++x)
518 {
519 switch (header.bitsPerPixel)
520 {
521 case 15:
522 case 16:
523 color = read16AsRgb(file, header.hasAlpha);
524 break;
525 case 24:
526 color = read24AsRgb(file);
527 break;
528 case 32:
529 color = read32AsRgb(file, header.hasAlpha);
530 break;
531 default:
532 assert(false);
533 break;
534 }
535 setColorInImage(image, color, x, y, header);
536 }
537 }
538 else if (header.imageType == ImageType::UncompressedGray)
539 {
540 assert(header.bitsPerPixel == 8);
541 for (int x = 0; x < header.width; ++x)
542 {
543 auto greyValue = read8(file);
544 setColorInImage(image, rgba(greyValue, greyValue, greyValue, 255), x, y, header);
545 }
546 }
547 else if (header.imageType == ImageType::RleIndexed || header.imageType == ImageType::RleGray)
548 {
549 assert(header.bitsPerPixel == 8);

Callers 1

loadTgaFromFileMethod · 0.85

Calls 8

read8Function · 0.85
setColorInImageFunction · 0.85
read16AsRgbFunction · 0.85
read24AsRgbFunction · 0.85
read32AsRgbFunction · 0.85
rgbaFunction · 0.85
resizeMethod · 0.80

Tested by

no test coverage detected