| 261 | } |
| 262 | |
| 263 | void imageEncodeFromRgba32f(bx::AllocatorI* _allocator, void* _dst, const void* _src, uint32_t _width, uint32_t _height, uint32_t _depth, TextureFormat::Enum _dstFormat, Quality::Enum _quality, bx::Error* _err) |
| 264 | { |
| 265 | BX_ERROR_SCOPE(_err); |
| 266 | |
| 267 | const uint8_t* src = (const uint8_t*)_src; |
| 268 | |
| 269 | switch (_dstFormat) |
| 270 | { |
| 271 | case TextureFormat::BC6H: |
| 272 | nvtt::compressBC6H(src, _width, _height, _width*16, _dst); |
| 273 | break; |
| 274 | |
| 275 | case TextureFormat::BC7: |
| 276 | nvtt::compressBC7(src, _width, _height, _width*16, _dst); |
| 277 | break; |
| 278 | |
| 279 | default: |
| 280 | if (!imageConvert(_allocator, _dst, _dstFormat, _src, TextureFormat::RGBA32F, _width, _height, _depth) ) |
| 281 | { |
| 282 | uint8_t* temp = (uint8_t*)bx::alloc(_allocator, _width*_height*_depth*4); |
| 283 | if (imageConvert(_allocator, temp, TextureFormat::RGBA8, _src, TextureFormat::RGBA32F, _width, _height, _depth) ) |
| 284 | { |
| 285 | for (uint32_t zz = 0; zz < _depth; ++zz) |
| 286 | { |
| 287 | const uint32_t zoffset = zz*_width*_height; |
| 288 | |
| 289 | for (uint32_t yy = 0; yy < _height; ++yy) |
| 290 | { |
| 291 | const uint32_t yoffset = zoffset + yy*_width; |
| 292 | |
| 293 | for (uint32_t xx = 0; xx < _width; ++xx) |
| 294 | { |
| 295 | const uint32_t offset = yoffset + xx; |
| 296 | const float* input = (const float*)&src[offset * 16]; |
| 297 | uint8_t* output = &temp[offset * 4]; |
| 298 | output[0] = uint8_t(bx::clamp(input[0], 0.0f, 1.0f)*255.0f + 0.5f); |
| 299 | output[1] = uint8_t(bx::clamp(input[1], 0.0f, 1.0f)*255.0f + 0.5f); |
| 300 | output[2] = uint8_t(bx::clamp(input[2], 0.0f, 1.0f)*255.0f + 0.5f); |
| 301 | output[3] = uint8_t(bx::clamp(input[3], 0.0f, 1.0f)*255.0f + 0.5f); |
| 302 | } |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | imageEncodeFromRgba8(_allocator, _dst, temp, _width, _height, _depth, _dstFormat, _quality, _err); |
| 307 | } |
| 308 | else |
| 309 | { |
| 310 | BX_ERROR_SET(_err, BIMG_ERROR, "Unable to convert between input/output formats!"); |
| 311 | } |
| 312 | |
| 313 | bx::free(_allocator, temp); |
| 314 | } |
| 315 | break; |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | 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) |
| 320 | { |
no test coverage detected