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

Function imageEncodeFromRgba8

3rdparty/bimg/src/image_encode.cpp:57–261  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

55 static_assert(Quality::Count == BX_COUNTOF(s_astcQuality) );
56
57 void imageEncodeFromRgba8(bx::AllocatorI* _allocator, void* _dst, const void* _src, uint32_t _width, uint32_t _height, uint32_t _depth, TextureFormat::Enum _format, Quality::Enum _quality, bx::Error* _err)
58 {
59 const uint8_t* src = (const uint8_t*)_src;
60 uint8_t* dst = (uint8_t*)_dst;
61
62 const uint32_t srcPitch = _width*4;
63 const uint32_t srcSlice = _height*srcPitch;
64 const uint32_t dstBpp = getBitsPerPixel(_format);
65 const uint32_t dstPitch = _width*dstBpp/8;
66 const uint32_t dstSlice = _height*dstPitch;
67
68 for (uint32_t zz = 0; zz < _depth && _err->isOk(); ++zz, src += srcSlice, dst += dstSlice)
69 {
70 switch (_format)
71 {
72 case TextureFormat::BC1:
73 case TextureFormat::BC2:
74 case TextureFormat::BC3:
75 case TextureFormat::BC4:
76 case TextureFormat::BC5:
77 squish::CompressImage(src, _width, _height, dst
78 , s_squishQuality[_quality]
79 | (_format == TextureFormat::BC2 ? squish::kDxt3
80 : _format == TextureFormat::BC3 ? squish::kDxt5
81 : _format == TextureFormat::BC4 ? squish::kBc4
82 : _format == TextureFormat::BC5 ? squish::kBc5
83 : squish::kDxt1)
84 );
85 break;
86
87 case TextureFormat::BC6H:
88 case TextureFormat::BC7:
89 BX_ERROR_SET(_err, BIMG_ERROR, "Unable to convert between input/output formats!");
90 break;
91
92 case TextureFormat::ETC1:
93 etc1_encode_image(src, _width, _height, 4, _width*4, dst);
94 break;
95
96 case TextureFormat::ETC2:
97 {
98 const uint32_t blockWidth = (_width +3)/4;
99 const uint32_t blockHeight = (_height+3)/4;
100 uint64_t* dstBlock = (uint64_t*)dst;
101 for (uint32_t yy = 0; yy < blockHeight; ++yy)
102 {
103 for (uint32_t xx = 0; xx < blockWidth; ++xx)
104 {
105 uint8_t block[4*4*4];
106 const uint8_t* ptr = &src[(yy*srcPitch+xx*4)*4];
107
108 for (uint32_t ii = 0; ii < 16; ++ii)
109 { // BGRx
110 bx::memCopy(&block[ii*4], &ptr[(ii%4)*srcPitch + (ii&~3)], 4);
111 bx::swap(block[ii*4+0], block[ii*4+2]);
112 }
113
114 *dstBlock++ = ProcessRGB_ETC2(block);

Callers 3

convertFunction · 0.85
imageEncodeFromRgba32fFunction · 0.85
imageEncodeFunction · 0.85

Calls 13

getBitsPerPixelFunction · 0.85
CompressImageFunction · 0.85
etc1_encode_imageFunction · 0.85
memCopyFunction · 0.85
ProcessRGB_ETC2Function · 0.85
astcenc_config_initFunction · 0.85
astcenc_get_error_stringFunction · 0.85
astcenc_context_allocFunction · 0.85
astcenc_compress_imageFunction · 0.85
astcenc_context_freeFunction · 0.85
imageSwizzleBgra8Function · 0.85
imageConvertFunction · 0.85

Tested by

no test coverage detected