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

Method initWithPVRv2Data

core/platform/Image.cpp:1550–1713  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1548}
1549
1550bool Image::initWithPVRv2Data(uint8_t* data, ssize_t dataLen, bool ownData)
1551{
1552 int blockSize = 0, widthBlocks = 0, heightBlocks = 0;
1553 int width = 0, height = 0;
1554
1555 // Cast first sizeof(PVRTexHeader) bytes of data stream as PVRTexHeader
1556 const PVRv2TexHeader* header = static_cast<const PVRv2TexHeader*>(static_cast<const void*>(data));
1557
1558 // Make sure that tag is in correct formatting
1559 if (memcmp(&header->pvrTag, gPVRTexIdentifier, strlen(gPVRTexIdentifier)) != 0)
1560 {
1561 return false;
1562 }
1563
1564 Configuration* configuration = Configuration::getInstance();
1565
1566 // can not detect the premultiplied alpha from pvr file, use _PVRHaveAlphaPremultiplied instead.
1567 _hasPremultipliedAlpha = isCompressedImageHavePMA(CompressedImagePMAFlag::PVR);
1568
1569 unsigned int flags = AX_SWAP_INT32_LITTLE_TO_HOST(header->flags);
1570 PVR2TexturePixelFormat formatFlags = static_cast<PVR2TexturePixelFormat>(flags & PVR_TEXTURE_FLAG_TYPE_MASK);
1571 bool flipped = (flags & (unsigned int)PVR2TextureFlag::VerticalFlip) ? true : false;
1572 if (flipped)
1573 {
1574 AXLOGD("WARNING: Image is flipped. Regenerate it using PVRTexTool");
1575 }
1576
1577 if (!configuration->supportsNPOT() && (static_cast<int>(header->width) != utils::nextPOT(header->width) ||
1578 static_cast<int>(header->height) != utils::nextPOT(header->height)))
1579 {
1580 AXLOGD("ERROR: Loading an NPOT texture ({}x{}) but is not supported on this device", header->width,
1581 header->height);
1582 return false;
1583 }
1584
1585 if (!testFormatForPvr2TCSupport(formatFlags))
1586 {
1587 AXLOGD("WARNING: Unsupported PVR Pixel Format: {:02X}. Re-encode it with a OpenGL pixel format variant",
1588 (int)formatFlags);
1589 return false;
1590 }
1591
1592 if (v2_pixel_formathash.find(formatFlags) == v2_pixel_formathash.end())
1593 {
1594 AXLOGD("WARNING: Unsupported PVR Pixel Format: {:02X}. Re-encode it with a OpenGL pixel format variant",
1595 (int)formatFlags);
1596 return false;
1597 }
1598
1599 auto pixelFormat = getDevicePVRPixelFormat(v2_pixel_formathash.at(formatFlags));
1600 auto& info = backend::PixelFormatUtils::getFormatDescriptor(pixelFormat);
1601 int bpp = info.bpp;
1602 if (!bpp)
1603 {
1604 AXLOGD("WARNING: Unsupported PVR Pixel Format: {:02X}. Re-encode it with a OpenGL pixel format variant",
1605 (int)formatFlags);
1606 return false;
1607 }

Callers

nothing calls this directly

Calls 11

getInstanceFunction · 0.85
nextPOTFunction · 0.85
getDevicePVRPixelFormatFunction · 0.85
PVRTDecompressPVRTCFunction · 0.85
supportsNPOTMethod · 0.80
supportsPVRTCMethod · 0.80
supportsBGRA8888Method · 0.80
findMethod · 0.45
endMethod · 0.45
atMethod · 0.45

Tested by

no test coverage detected