MCPcopy Create free account
hub / github.com/axmolengine/axmol / initWithPVRv3Data

Method initWithPVRv3Data

core/platform/Image.cpp:1715–1973  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1713}
1714
1715bool Image::initWithPVRv3Data(uint8_t* data, ssize_t dataLen, bool ownData)
1716{
1717 if (static_cast<size_t>(dataLen) < sizeof(PVRv3TexHeader))
1718 {
1719 return false;
1720 }
1721
1722 const PVRv3TexHeader* header = static_cast<const PVRv3TexHeader*>(static_cast<const void*>(data));
1723
1724 // validate version
1725 if (AX_SWAP_INT32_BIG_TO_HOST(header->version) != 0x50565203)
1726 {
1727 AXLOGW("axmol: WARNING: pvr file version mismatch");
1728 return false;
1729 }
1730
1731 // parse pixel format
1732 PVR3TexturePixelFormat pixelFormat = static_cast<PVR3TexturePixelFormat>(header->pixelFormat);
1733
1734 if (!testFormatForPvr3TCSupport(pixelFormat))
1735 {
1736 AXLOGW(
1737 "axmol:WARNING: Unsupported PVR Pixel Format: 0x{:016X}. Re-encode it with a OpenGL pixel format "
1738 "variant",
1739 static_cast<unsigned long long>(pixelFormat));
1740 return false;
1741 }
1742
1743 if (v3_pixel_formathash.find(pixelFormat) == v3_pixel_formathash.end())
1744 {
1745 AXLOGW(
1746 "axmol:WARNING: Unsupported PVR Pixel Format: 0x{:016X}. Re-encode it with a OpenGL pixel format "
1747 "variant",
1748 static_cast<unsigned long long>(pixelFormat));
1749 return false;
1750 }
1751
1752 auto finalPixelFormat = getDevicePVRPixelFormat(v3_pixel_formathash.at(pixelFormat));
1753 auto& info = backend::PixelFormatUtils::getFormatDescriptor(finalPixelFormat);
1754 int bpp = info.bpp;
1755 if (!info.bpp)
1756 {
1757 AXLOGW(
1758 "axmol:WARNING: Unsupported PVR Pixel Format: 0x{:016X}. Re-encode it with a OpenGL pixel format "
1759 "variant",
1760 static_cast<unsigned long long>(pixelFormat));
1761 return false;
1762 }
1763
1764 _pixelFormat = finalPixelFormat;
1765
1766 // flags
1767 int flags = AX_SWAP_INT32_LITTLE_TO_HOST(header->flags);
1768
1769 // PVRv3 specifies premultiply alpha in a flag -- should always respect this in PVRv3 files
1770 if (flags & (unsigned int)PVR3TextureFlag::PremultipliedAlpha)
1771 {
1772 _hasPremultipliedAlpha = true;

Callers

nothing calls this directly

Calls 13

getDevicePVRPixelFormatFunction · 0.85
getInstanceFunction · 0.85
PVRTDecompressPVRTCFunction · 0.85
etc2_decode_imageFunction · 0.85
astc_decompress_imageFunction · 0.85
supportsPVRTCMethod · 0.80
supportsETC1Method · 0.80
supportsBGRA8888Method · 0.80
supportsASTCMethod · 0.80
findMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected