ISPCTextureCompressor icon indicating copy to clipboard operation
ISPCTextureCompressor copied to clipboard

Please, add BC4 encoding

Open tbdbj opened this issue 9 years ago • 5 comments

tbdbj avatar Dec 26 '16 01:12 tbdbj

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

ivalylo avatar Jun 04 '17 16:06 ivalylo

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.

alecazam avatar Jun 20 '18 04:06 alecazam

Made a pull-request with BC4 and BC5 API. https://github.com/GameTechDev/ISPCTextureCompressor/pull/31

iOrange avatar Feb 01 '22 18:02 iOrange

The pull request was merged. Can this be closed?

zopsicle avatar Dec 08 '22 10:12 zopsicle