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

Function postProcessImage

YUViewLib/src/decoder/decoderTarga.cpp:561–605  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

559}
560
561void postProcessImage(dec::Targa::Image &image, const Header &header)
562{
563 // The post-processing is only for RGB images with possible invalid
564 // alpha information.
565 if (!header.isRgb() || !header.hasAlpha)
566 return;
567
568 bool transparentImage = true;
569 bool blackImage = true;
570
571 for (unsigned y = 0; y < header.height; ++y)
572 {
573 for (unsigned x = 0; x < header.width; ++x)
574 {
575 auto idx = y * header.width * 4 + x * 4;
576 auto r = image.data.at(idx);
577 auto g = image.data.at(idx + 1);
578 auto b = image.data.at(idx + 2);
579 auto a = image.data.at(idx + 3);
580 if (transparentImage && a != 0)
581 {
582 transparentImage = false;
583 }
584 if (blackImage && (r != 0 || g != 0 || b != 0))
585 {
586 blackImage = false;
587 }
588 }
589 }
590
591 // If the image is fully transparent (all pixels with alpha=0) and
592 // there are pixels with RGB != 0 (!blackImage), we have to make the
593 // image completely opaque (alpha=255).
594 if (transparentImage && !blackImage)
595 {
596 for (unsigned y = 0; y < header.height; ++y)
597 {
598 for (unsigned x = 0; x < header.width; ++x)
599 {
600 auto idx = y * header.width * 4 + x * 4;
601 image.data.at(idx + 3) = 255;
602 }
603 }
604 }
605}
606
607} // namespace
608

Callers 1

loadTgaFromFileMethod · 0.85

Calls 2

isRgbMethod · 0.80
atMethod · 0.45

Tested by

no test coverage detected