Skip to content
This repository has been archived by the owner on Sep 23, 2024. It is now read-only.

Please, add BC4 encoding #11

Open
tbdbj opened this issue Dec 26, 2016 · 5 comments
Open

Please, add BC4 encoding #11

tbdbj opened this issue Dec 26, 2016 · 5 comments

Comments

@tbdbj
Copy link

tbdbj commented Dec 26, 2016

No description provided.

@ivalylo
Copy link

ivalylo commented Jun 4, 2017

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
Copy link

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.

@iOrange
Copy link
Contributor

iOrange commented Feb 1, 2022

Made a pull-request with BC4 and BC5 API.
#31

@zopsicle
Copy link

zopsicle commented Dec 8, 2022

The pull request was merged. Can this be closed?

@telecran-telecrit
Copy link

@tbdbj @ivalylo It applied here too https://github.com/telecran-telecrit/ISPCTextureCompressor (for BC4 and BC5).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants