MCPcopy Create free account
hub / github.com/baldurk/renderdoc / DecodePixelData

Function DecodePixelData

renderdoc/maths/formatpacking.cpp:576–877  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

574}
575
576void DecodePixelData(const ResourceFormat &fmt, const byte *data, PixelValue &out, bool *success)
577{
578 out.floatValue = {0.0f, 0.0f, 0.0f, 1.0f};
579
580 if(fmt.compType == CompType::UInt || fmt.compType == CompType::SInt || fmt.compCount == 4)
581 out.floatValue[3] = 0.0f;
582
583 const uint64_t dummy[2] = {0, 0};
584 if(!data)
585 data = (const byte *)dummy;
586
587 // assume success, we'll set it to false if we hit an error
588 if(success)
589 *success = true;
590
591 if(fmt.type == ResourceFormatType::R10G10B10A2)
592 {
593 if(fmt.compType == CompType::SNorm)
594 {
595 Vec4f v = ConvertFromR10G10B10A2SNorm(*(const uint32_t *)data);
596 out.floatValue = {v.x, v.y, v.z, v.w};
597 }
598 else if(fmt.compType == CompType::UInt)
599 {
600 Vec4u v = ConvertFromR10G10B10A2UInt(*(const uint32_t *)data);
601 out.uintValue = {v.x, v.y, v.z, v.w};
602 }
603 else
604 {
605 Vec4f v = ConvertFromR10G10B10A2(*(const uint32_t *)data);
606 if(fmt.compType == CompType::SInt)
607 {
608 out.intValue = {(int32_t)v.x, (int32_t)v.y, (int32_t)v.z, (int32_t)v.w};
609 }
610 else
611 {
612 out.floatValue = {v.x, v.y, v.z, v.w};
613 }
614 }
615
616 // the different types are a union so we can ignore format and just treat it as a data swap
617 if(fmt.BGRAOrder())
618 std::swap(out.uintValue[0], out.uintValue[2]);
619 }
620 else if(fmt.type == ResourceFormatType::R11G11B10)
621 {
622 Vec3f v = ConvertFromR11G11B10(*(const uint32_t *)data);
623 out.floatValue = {v.x, v.y, v.z};
624 }
625 else if(fmt.type == ResourceFormatType::R5G5B5A1)
626 {
627 Vec4f v = ConvertFromB5G5R5A1(*(const uint16_t *)data);
628 out.floatValue = {v.x, v.y, v.z, v.w};
629
630 // conversely we *expect* BGRA order for this format and the above conversion implicitly flips
631 // when bit-unpacking. So if the format wasn't BGRA order, flip it back
632 if(!fmt.BGRAOrder())
633 std::swap(out.floatValue[0], out.floatValue[2]);

Callers 6

ReadTexelMethod · 0.50
FillInColorFunction · 0.50
ReadTexelMethod · 0.50
FillInColorFunction · 0.50
ConvertAndFillInColorFunction · 0.50

Calls 12

ConvertFromR10G10B10A2Function · 0.85
ConvertFromR11G11B10Function · 0.85
ConvertFromB5G5R5A1Function · 0.85
ConvertFromB5G6R5Function · 0.85
ConvertFromB4G4R4A4Function · 0.85
ConvertFromR4G4Function · 0.85
ConvertFromR9G9B9E5Function · 0.85
ConvertFromHalfFunction · 0.85
ConvertFromSRGB8Function · 0.85
swapFunction · 0.50

Tested by

no test coverage detected