| 5245 | } |
| 5246 | |
| 5247 | bool imageGetRawData(const ImageContainer& _imageContainer, uint16_t _side, uint8_t _lod, const void* _data, uint32_t _size, ImageMip& _mip) |
| 5248 | { |
| 5249 | uint32_t offset = _imageContainer.m_offset; |
| 5250 | TextureFormat::Enum format = TextureFormat::Enum(_imageContainer.m_format); |
| 5251 | bool hasAlpha = _imageContainer.m_hasAlpha; |
| 5252 | |
| 5253 | const ImageBlockInfo& blockInfo = s_imageBlockInfo[format]; |
| 5254 | const uint8_t bpp = blockInfo.bitsPerPixel; |
| 5255 | const uint32_t blockSize = blockInfo.blockSize; |
| 5256 | const uint32_t blockWidth = blockInfo.blockWidth; |
| 5257 | const uint32_t blockHeight = blockInfo.blockHeight; |
| 5258 | const uint32_t minBlockX = blockInfo.minBlockX; |
| 5259 | const uint32_t minBlockY = blockInfo.minBlockY; |
| 5260 | |
| 5261 | if (UINT32_MAX == _imageContainer.m_offset) |
| 5262 | { |
| 5263 | if (NULL == _imageContainer.m_data) |
| 5264 | { |
| 5265 | return false; |
| 5266 | } |
| 5267 | |
| 5268 | offset = 0; |
| 5269 | _data = _imageContainer.m_data; |
| 5270 | _size = _imageContainer.m_size; |
| 5271 | } |
| 5272 | |
| 5273 | const uint8_t* data = (const uint8_t*)_data; |
| 5274 | const uint16_t numSides = _imageContainer.m_numLayers * (_imageContainer.m_cubeMap ? 6 : 1); |
| 5275 | |
| 5276 | if (_imageContainer.m_ktx || _imageContainer.m_pvr3) |
| 5277 | { |
| 5278 | uint32_t width = _imageContainer.m_width; |
| 5279 | uint32_t height = _imageContainer.m_height; |
| 5280 | uint32_t depth = _imageContainer.m_depth; |
| 5281 | |
| 5282 | for (uint8_t lod = 0, num = _imageContainer.m_numMips; lod < num; ++lod) |
| 5283 | { |
| 5284 | width = bx::max<uint32_t>(blockWidth * minBlockX, ( (width + blockWidth - 1) / blockWidth )*blockWidth); |
| 5285 | height = bx::max<uint32_t>(blockHeight * minBlockY, ( (height + blockHeight - 1) / blockHeight)*blockHeight); |
| 5286 | depth = bx::max<uint32_t>(1, depth); |
| 5287 | |
| 5288 | const uint32_t mipSize = width/blockWidth * height/blockHeight * depth * blockSize; |
| 5289 | |
| 5290 | if (_imageContainer.m_ktx) |
| 5291 | { |
| 5292 | const uint32_t size = _imageContainer.m_numLayers == 1 && _imageContainer.m_cubeMap ? mipSize : mipSize * numSides; |
| 5293 | uint32_t imageSize = bx::toHostEndian(*(const uint32_t*)&data[offset], _imageContainer.m_ktxLE); |
| 5294 | BX_ASSERT(size == imageSize, "KTX: Image size mismatch %d (expected %d).", size, imageSize); |
| 5295 | BX_UNUSED(size, imageSize); |
| 5296 | |
| 5297 | offset += sizeof(uint32_t); |
| 5298 | } |
| 5299 | |
| 5300 | for (uint16_t side = 0; side < numSides; ++side) |
| 5301 | { |
| 5302 | BX_ASSERT(offset <= _size, "Reading past size of data buffer! (offset %d, size %d)", offset, _size); |
| 5303 | |
| 5304 | if (side == _side |
no test coverage detected