Open nicastel opened 10 years ago
Having this would be great
I have found some code here https://github.com/hglm/texgenpack/blob/master/etc2.c It is only decoding code but it helps to understand how different mode are encoded.
This method particularly :
int draw_block4x4_etc2_punchthrough(const unsigned char bitstring, unsigned int image_buffer, int flags) {
int R = (bitstring[0] & 0xF8);
R += complement3bitshifted(bitstring[0] & 7);
int G = (bitstring[1] & 0xF8);
G += complement3bitshifted(bitstring[1] & 7);
int B = (bitstring[2] & 0xF8);
B += complement3bitshifted(bitstring[2] & 7);
int opaque = bitstring[3] & 2;
if (R & 0xFF07) {
// T mode.
if ((flags & ETC2_MODE_ALLOWED_T) == 0)
return 0;
if (opaque) {
draw_block4x4_rgb8_etc2_T_or_H_mode(bitstring, image_buffer, 0);
return 1;
}
// T mode with punchthrough alpha.
draw_block4x4_etc2_punchthrough_T_or_H_mode(bitstring, image_buffer, 0);
return 1;
}
else
if (G & 0xFF07) {
// H mode.
if ((flags & ETC2_MODE_ALLOWED_H) == 0)
return 0;
if (opaque) {
draw_block4x4_rgb8_etc2_T_or_H_mode(bitstring, image_buffer, 1);
return 1;
}
// H mode with punchthrough alpha.
draw_block4x4_etc2_punchthrough_T_or_H_mode(bitstring, image_buffer, 0);
return 1;
}
else
if (B & 0xFF07) {
// Planar mode.
if ((flags & ETC2_MODE_ALLOWED_PLANAR) == 0)
return 0;
// Opaque always set.
draw_block4x4_rgb8_etc2_planar_mode(bitstring, image_buffer);
return 1;
}
else {
// Differential mode.
if (opaque)
return draw_block4x4_etc1(bitstring, image_buffer, flags);
// Differential mode with punchthrough alpha.
draw_block4x4_etc2_punchthrough_differential(bitstring, image_buffer);
return 1;
}
}
ETC2 have 5 mode :
ETC2 also come with the EAC compression format wich is dedicated for alpha.
Google just mad a open-source ETC2/ETC1 encode : https://github.com/google/etc2comp
ETC2 is the improved successor of ETC1 and it will be soon available on all new Android terminals. It will be interesting to add a compressor for this format. The algorithm basic principle are very similar so it should not be too much difficult to implement it.
Reference : http://www.jacobstrom.com/publications/StromPetterssonGH07.pdf http://www.graphicshardware.org/previous/www_2007/presentations/strom-etc2-gh07.pdf https://www.khronos.org/assets/uploads/developers/library/2012-siggraph-opengl-es-bof/Ericsson-ETC2-SIGGRAPH_Aug12.pdf