|
|
@@ -196,6 +196,94 @@ namespace bimg
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ void imageEncode(bx::AllocatorI* _allocator, void* _dst, const void* _src, TextureFormat::Enum _srcFormat, uint32_t _width, uint32_t _height, uint32_t _depth, TextureFormat::Enum _dstFormat, Quality::Enum _quality, bx::Error* _err)
|
|
|
+ {
|
|
|
+ switch (_dstFormat)
|
|
|
+ {
|
|
|
+ case bimg::TextureFormat::BC1:
|
|
|
+ case bimg::TextureFormat::BC2:
|
|
|
+ case bimg::TextureFormat::BC3:
|
|
|
+ case bimg::TextureFormat::BC4:
|
|
|
+ case bimg::TextureFormat::BC5:
|
|
|
+ case bimg::TextureFormat::ETC1:
|
|
|
+ case bimg::TextureFormat::ETC2:
|
|
|
+ case bimg::TextureFormat::PTC14:
|
|
|
+ case bimg::TextureFormat::PTC14A:
|
|
|
+ {
|
|
|
+ uint8_t* temp = (uint8_t*)BX_ALLOC(_allocator, _width*_height*_depth*4);
|
|
|
+ imageDecodeToRgba8(temp, _src, _width, _height, _width*4, _srcFormat);
|
|
|
+ imageEncodeFromRgba8(_dst, temp, _width, _height, _depth, _dstFormat, _quality, _err);
|
|
|
+ BX_FREE(_allocator, temp);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ case bimg::TextureFormat::BC6H:
|
|
|
+ case bimg::TextureFormat::BC7:
|
|
|
+ {
|
|
|
+ uint8_t* temp = (uint8_t*)BX_ALLOC(_allocator, _width*_height*_depth*16);
|
|
|
+ imageDecodeToRgba32f(_allocator, temp, _src, _width, _height, _depth, _width*16, _srcFormat);
|
|
|
+ imageEncodeFromRgba32f(_allocator, _dst, temp, _width, _height, _depth, _dstFormat, _quality, _err);
|
|
|
+ BX_FREE(_allocator, temp);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ default:
|
|
|
+ BX_ERROR_SET(_err, BIMG_ERROR, "Unable to convert between input/output formats!");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ ImageContainer* imageEncode(bx::AllocatorI* _allocator, TextureFormat::Enum _dstFormat, Quality::Enum _quality, const ImageContainer& _input)
|
|
|
+ {
|
|
|
+ ImageContainer* output = imageAlloc(_allocator
|
|
|
+ , _dstFormat
|
|
|
+ , uint16_t(_input.m_width)
|
|
|
+ , uint16_t(_input.m_height)
|
|
|
+ , uint16_t(_input.m_depth)
|
|
|
+ , _input.m_numLayers
|
|
|
+ , _input.m_cubeMap
|
|
|
+ , 1 < _input.m_numMips
|
|
|
+ );
|
|
|
+
|
|
|
+ const uint16_t numSides = _input.m_numLayers * (_input.m_cubeMap ? 6 : 1);
|
|
|
+
|
|
|
+ bx::Error err;
|
|
|
+
|
|
|
+ for (uint16_t side = 0; side < numSides && err.isOk(); ++side)
|
|
|
+ {
|
|
|
+ for (uint8_t lod = 0, num = _input.m_numMips; lod < num && err.isOk(); ++lod)
|
|
|
+ {
|
|
|
+ ImageMip mip;
|
|
|
+ if (imageGetRawData(_input, side, lod, _input.m_data, _input.m_size, mip) )
|
|
|
+ {
|
|
|
+ ImageMip dstMip;
|
|
|
+ imageGetRawData(*output, side, lod, output->m_data, output->m_size, dstMip);
|
|
|
+ uint8_t* dstData = const_cast<uint8_t*>(dstMip.m_data);
|
|
|
+
|
|
|
+ imageEncode(_allocator
|
|
|
+ , dstData
|
|
|
+ , mip.m_data
|
|
|
+ , mip.m_format
|
|
|
+ , mip.m_width
|
|
|
+ , mip.m_height
|
|
|
+ , mip.m_depth
|
|
|
+ , _dstFormat
|
|
|
+ , _quality
|
|
|
+ , &err
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (err.isOk() )
|
|
|
+ {
|
|
|
+ return output;
|
|
|
+ }
|
|
|
+
|
|
|
+ imageFree(output);
|
|
|
+ return NULL;
|
|
|
+ }
|
|
|
+
|
|
|
void imageRgba32f11to01(void* _dst, uint32_t _width, uint32_t _height, uint32_t _depth, uint32_t _pitch, const void* _src)
|
|
|
{
|
|
|
const uint8_t* src = (const uint8_t*)_src;
|