* Converts 96/128bpp to 64bpp RGBA floating-point image. * Note that FreeImage doesn't support 16-bit float formats. */
| 247 | * Note that FreeImage doesn't support 16-bit float formats. |
| 248 | */ |
| 249 | static FIBITMAP* convertToRGBA16Float(FIBITMAP* pDib) |
| 250 | { |
| 251 | const auto type = FreeImage_GetImageType(pDib); |
| 252 | const uint32_t bpp = FreeImage_GetBPP(pDib); |
| 253 | FALCOR_CHECK(type == FIT_RGBF || type == FIT_RGBAF, "Image type must be RGB/RGBA with 32-bit float per channel."); |
| 254 | FALCOR_CHECK(bpp == 96 || bpp == 128, "Image must be 96 or 128bpp."); |
| 255 | |
| 256 | const uint32_t width = FreeImage_GetWidth(pDib); |
| 257 | const uint32_t height = FreeImage_GetHeight(pDib); |
| 258 | |
| 259 | auto pNew = FreeImage_AllocateT(FIT_RGBA16, width, height); |
| 260 | FreeImage_CloneMetadata(pNew, pDib); |
| 261 | |
| 262 | const uint32_t src_pitch = FreeImage_GetPitch(pDib); |
| 263 | const uint32_t dst_pitch = FreeImage_GetPitch(pNew); |
| 264 | |
| 265 | const BYTE* src_bits = (BYTE*)FreeImage_GetBits(pDib); |
| 266 | BYTE* dst_bits = (BYTE*)FreeImage_GetBits(pNew); |
| 267 | |
| 268 | for (uint32_t y = 0; y < height; y++) |
| 269 | { |
| 270 | const FIRGBAF* src_pixel = (FIRGBAF*)src_bits; |
| 271 | FIRGBA16* dst_pixel = (tagFIRGBA16*)dst_bits; |
| 272 | |
| 273 | for (uint32_t x = 0; x < width; x++) |
| 274 | { |
| 275 | // Convert pixels to float16_t directly, while adding a "dummy" alpha of 1.0 if source format doesn't have alpha. |
| 276 | dst_pixel[x].red = float16_t(src_pixel[x].red).toBits(); |
| 277 | dst_pixel[x].green = float16_t(src_pixel[x].green).toBits(); |
| 278 | dst_pixel[x].blue = float16_t(src_pixel[x].blue).toBits(); |
| 279 | dst_pixel[x].alpha = float16_t(type == FIT_RGBAF ? src_pixel[x].alpha : 1.0f).toBits(); |
| 280 | } |
| 281 | src_bits += src_pitch; |
| 282 | dst_bits += dst_pitch; |
| 283 | } |
| 284 | return pNew; |
| 285 | } |
| 286 | Bitmap::UniqueConstPtr Bitmap::create(uint32_t width, uint32_t height, ResourceFormat format, const uint8_t* pData) |
| 287 | { |
| 288 | return Bitmap::UniqueConstPtr(new Bitmap(width, height, format, pData)); |
no test coverage detected