128static const int kLookup[8] = { 0, 1, 2, 3, -4, -3, -2, -1 };
143 return (c << 3) | (c >> 2);
149 return (c << 2) | (c >> 4);
154 return (
d + 128 + (
d >> 8)) >> 8;
186 for (
int i = 0;
i < 8;
i++) {
189 x = baseX + (
i >> 1);
192 x = baseX + (
i >> 2);
196 int offset = ((low >> k) & 1) | ((low >> (k + 15)) & 2);
209 etc1_uint32 high = (pIn[0] << 24) | (pIn[1] << 16) | (pIn[2] << 8) | pIn[3];
210 etc1_uint32 low = (pIn[4] << 24) | (pIn[5] << 16) | (pIn[6] << 8) | pIn[7];
211 int r1, r2, g1, g2, b1, b2;
214 int rBase = high >> 27;
215 int gBase = high >> 19;
216 int bBase = high >> 11;
232 int tableIndexA = 7 & (high >> 5);
233 int tableIndexB = 7 & (high >> 2);
236 bool flipped = (high & 1) != 0;
249 if (
a->score >
b->score) {
256 etc1_byte* pColors,
bool flipped,
bool second) {
266 for (
int y = 0;
y < 2;
y++) {
268 for (
int x = 0;
x < 4;
x++) {
270 if (inMask & (1 <<
i)) {
283 for (
int y = 0;
y < 4;
y++) {
284 for (
int x = 0;
x < 2;
x++) {
287 if (inMask & (1 <<
i)) {
308 const int* pModifierTable) {
314 int r = pBaseColors[0];
315 int g = pBaseColors[1];
316 int b = pBaseColors[2];
317 for (
int i = 0;
i < 4;
i++) {
318 int modifier = pModifierTable[
i];
319 int decodedG =
clamp(g + modifier);
321 if (score >= bestScore) {
324 int decodedR =
clamp(r + modifier);
326 if (score >= bestScore) {
329 int decodedB =
clamp(
b + modifier);
331 if (score < bestScore) {
336 etc1_uint32 lowMask = (((bestIndex >> 1) << 16) | (bestIndex & 1))
345 const etc1_byte* pBaseColors,
const int* pModifierTable) {
346 int score = pCompressed->
score;
352 for (
int y = 0;
y < 2;
y++) {
354 for (
int x = 0;
x < 4;
x++) {
356 if (inMask & (1 <<
i)) {
358 &pCompressed->
low, yy +
x * 4, pModifierTable);
367 for (
int y = 0;
y < 4;
y++) {
368 for (
int x = 0;
x < 2;
x++) {
371 if (inMask & (1 <<
i)) {
373 &pCompressed->
low,
y + xx * 4, pModifierTable);
378 pCompressed->
score = score;
387 int r1, g1, b1, r2, g2, b2;
411 pCompressed->
high |= (r51 << 27) | ((7 &
dr) << 24) | (g51 << 19)
412 | ((7 &
dg) << 16) | (b51 << 11) | ((7 &
db) << 8) | 2;
426 pCompressed->
high |= (r41 << 28) | (r42 << 24) | (g41 << 20) | (g42
427 << 16) | (b41 << 12) | (b42 << 8);
440 pCompressed->
score = ~0;
441 pCompressed->
high = (flipped ? 1 : 0);
442 pCompressed->
low = 0;
448 int originalHigh = pCompressed->
high;
451 for (
int i = 0;
i < 8;
i++, pModifierTable += 4) {
454 temp.
high = originalHigh | (
i << 5);
457 pBaseColors, pModifierTable);
462 for (
int i = 0;
i < 8;
i++, pModifierTable += 4) {
468 pBaseColors + 3, pModifierTable);
509 return (((
width + 3) & ~3) * ((
height + 3) & ~3)) >> 1;
519 if (pixelSize < 2 || pixelSize > 3) {
522 static const unsigned short kYMask[] = { 0x0, 0xf, 0xff, 0xfff, 0xffff };
523 static const unsigned short kXMask[] = { 0x0, 0x1111, 0x3333, 0x7777,
536 int ymask = kYMask[yEnd];
542 int mask = ymask & kXMask[xEnd];
545 const etc1_byte*
p = pIn + pixelSize *
x + stride * (
y + cy);
546 if (pixelSize == 3) {
547 memcpy(q,
p, xEnd * 3);
550 int pixel = (
p[1] << 8) |
p[0];
559 memcpy(pOut, encoded,
sizeof(encoded));
560 pOut +=
sizeof(encoded);
576 if (pixelSize < 2 || pixelSize > 3) {
597 const etc1_byte* q = block + (cy * 4) * 3;
598 etc1_byte*
p = pOut + pixelSize *
x + stride * (
y + cy);
599 if (pixelSize == 3) {
600 memcpy(
p, q, xEnd * 3);
606 etc1_uint32 pixel = ((r >> 3) << 11) | ((g >> 2) << 5) | (
b >> 3);
617static const char kMagic[] = {
'P',
'K',
'M',
' ',
'1',
'0' };
633 return (pIn[0] << 8) | pIn[1];
661 encodedWidth >=
width && encodedWidth -
width < 4 &&
static void etc_encode_block_helper(const etc1_byte *pIn, etc1_uint32 inMask, const etc1_byte *pColors, etc_compressed *pCompressed, bool flipped)
static void writeBEUint16(etc1_byte *pOut, etc1_uint32 data)
static int convert4To8(int b)
etc1_uint32 etc1_pkm_get_height(const etc1_byte *pHeader)
static const int kLookup[8]
static const int kModifierTable[]
static int divideBy255(int d)
static const etc1_uint32 ETC1_PKM_ENCODED_HEIGHT_OFFSET
static bool inRange4bitSigned(int color)
static const etc1_uint32 ETC1_PKM_FORMAT_OFFSET
static int convert5To8(int b)
static const etc1_uint32 ETC1_PKM_WIDTH_OFFSET
static etc1_uint32 chooseModifier(const etc1_byte *pBaseColors, const etc1_byte *pIn, etc1_uint32 *pLow, int bitIndex, const int *pModifierTable)
static int convert8To5(int b)
static int convert6To8(int b)
static void writeBigEndian(etc1_byte *pOut, etc1_uint32 d)
void etc1_encode_block(const etc1_byte *pIn, etc1_uint32 inMask, etc1_byte *pOut)
static int convertDiff(int base, int diff)
static const etc1_uint32 ETC1_PKM_ENCODED_WIDTH_OFFSET
void etc1_pkm_format_header(etc1_byte *pHeader, etc1_uint32 width, etc1_uint32 height)
etc1_bool etc1_pkm_is_valid(const etc1_byte *pHeader)
void etc1_decode_block(const etc1_byte *pIn, etc1_byte *pOut)
static etc1_uint32 readBEUint16(const etc1_byte *pIn)
static const etc1_uint32 ETC1_RGB_NO_MIPMAPS
static void etc_encodeBaseColors(etc1_byte *pBaseColors, const etc1_byte *pColors, etc_compressed *pCompressed)
etc1_uint32 etc1_get_encoded_data_size(etc1_uint32 width, etc1_uint32 height)
static etc1_byte clamp(int x)
static void decode_subblock(etc1_byte *pOut, int r, int g, int b, const int *table, etc1_uint32 low, bool second, bool flipped)
static const etc1_uint32 ETC1_PKM_HEIGHT_OFFSET
etc1_uint32 etc1_pkm_get_width(const etc1_byte *pHeader)
static void etc_encode_subblock_helper(const etc1_byte *pIn, etc1_uint32 inMask, etc_compressed *pCompressed, bool flipped, bool second, const etc1_byte *pBaseColors, const int *pModifierTable)
static const char kMagic[]
static int convert8To4(int b)
int etc1_decode_image(const etc1_byte *pIn, etc1_byte *pOut, etc1_uint32 width, etc1_uint32 height, etc1_uint32 pixelSize, etc1_uint32 stride)
static void etc_average_colors_subblock(const etc1_byte *pIn, etc1_uint32 inMask, etc1_byte *pColors, bool flipped, bool second)
int etc1_encode_image(const etc1_byte *pIn, etc1_uint32 width, etc1_uint32 height, etc1_uint32 pixelSize, etc1_uint32 stride, etc1_byte *pOut)
static void take_best(etc_compressed *a, const etc_compressed *b)
#define ETC1_ENCODED_BLOCK_SIZE
#define ETC1_DECODED_BLOCK_SIZE
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
uint32_t uint32_t * format
PODArray< SkColor > colors
std::shared_ptr< const fml::Mapping > data