Please, add BC4 encoding
tbdbj opened this issue · 5 comments
tbdbj commented
Please, add BC4 encoding
ivalylo commented
BC4 and BC5 are very easy to implement even if you don't know ISPC.
inline void load_block_interleaved_alpha(float block[16], uniform rgba_surface* uniform src, int xx, uniform int yy)
{
for (uniform int y = 0; y<4; y++)
for (uniform int x = 0; x<4; x++)
{
uniform uint8* uniform src_ptr = &src->ptr[min((yy * 4 + y), src->height-1)*src->stride];
uint8* rgb = src_ptr + min((xx * 4 + x), src->width-1);
block[y*4+x] = (int)rgb[0];
}
}
inline void CompressBlockBC4(uniform rgba_surface src[], int xx, uniform int yy, uniform uint8 dst[])
{
float block[16];
uint32 data[2];
load_block_interleaved_alpha(block, src, xx, yy);
CompressBlockBC3_alpha(block, data);
store_data(dst, (src->width+3)&~3, xx, yy, data, 2);
}
export void CompressBlocksBC4_ispc(uniform rgba_surface src[], uniform uint8 dst[])
{
for (uniform int yy = 0; yy<(src->height+3)/4; yy++)
foreach (xx = 0 ... (src->width+3)/4)
{
CompressBlockBC4(src, xx, yy, dst);
}
}
This also support non multiple of 4 textures
alecazam commented
These are missing from the binary builds, and result in an incomplete BC compressor. These formats are important, and as suggested the change is small since BC3 alpha can be reused. Also the BC3 alpha compression issue reported in another Issue should be fixed prior to re-using that code for BC4/BC5.
zopsicle commented
The pull request was merged. Can this be closed?
telecran-telecrit commented
@tbdbj @ivalylo It applied here too https://github.com/telecran-telecrit/ISPCTextureCompressor (for BC4 and BC5).