MCPcopy Create free account
hub / github.com/crownengine/crown / imageWriteHdr

Function imageWriteHdr

3rdparty/bimg/src/image.cpp:5683–5722  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5681 }
5682
5683 int32_t imageWriteHdr(bx::WriterI* _writer, uint32_t _width, uint32_t _height, uint32_t _srcPitch, const void* _src, TextureFormat::Enum _format, bool _yflip, bx::Error* _err)
5684 {
5685 BX_ERROR_SCOPE(_err);
5686
5687 int32_t total = 0;
5688 total += bx::write(_writer, "#?RADIANCE\n" , _err);
5689 total += bx::write(_writer, "FORMAT=32-bit_rle_rgbe\n" , _err);
5690 total += bx::write(_writer, '\n' , _err);
5691
5692 total += bx::write(_writer, _err, "%cY %d +X %d\n", _yflip ? '+' : '-', _height, _width);
5693
5694 UnpackFn unpack = getUnpack(_format);
5695 const uint32_t bpp = getBitsPerPixel(_format);
5696
5697 const uint8_t* data = (const uint8_t*)_src;
5698 for (uint32_t yy = 0; yy < _height && _err->isOk(); ++yy)
5699 {
5700 for (uint32_t xx = 0; xx < _width && _err->isOk(); ++xx)
5701 {
5702 float rgba[4];
5703 unpack(rgba, &data[xx*bpp/8]);
5704
5705 const float maxVal = bx::max(rgba[0], rgba[1], rgba[2]);
5706 const float exp = bx::ceil(bx::log2(maxVal) );
5707 const float toRgb8 = 255.0f * 1.0f/bx::ldexp(1.0f, int(exp) );
5708
5709 uint8_t rgbe[4];
5710 rgbe[0] = uint8_t(rgba[0] * toRgb8);
5711 rgbe[1] = uint8_t(rgba[1] * toRgb8);
5712 rgbe[2] = uint8_t(rgba[2] * toRgb8);
5713 rgbe[3] = uint8_t(exp+128.0f);
5714
5715 total += bx::write(_writer, rgbe, 4, _err);
5716 }
5717
5718 data += _srcPitch;
5719 }
5720
5721 return total;
5722 }
5723
5724 static int32_t imageWriteDdsHeader(bx::WriterI* _writer, TextureFormat::Enum _format, bool _cubeMap, uint32_t _width, uint32_t _height, uint32_t _depth, uint8_t _numMips, uint32_t _numLayers, bx::Error* _err)
5725 {

Callers 1

mainFunction · 0.85

Calls 7

getUnpackFunction · 0.85
getBitsPerPixelFunction · 0.85
ceilFunction · 0.85
log2Function · 0.85
ldexpFunction · 0.85
writeFunction · 0.50
maxFunction · 0.50

Tested by

no test coverage detected