Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Functions | Variables
etc1.cpp File Reference
#include "third_party/etc1/etc1.h"
#include <cstring>

Go to the source code of this file.

Classes

struct  etc_compressed
 

Functions

static etc1_byte clamp (int x)
 
static int convert4To8 (int b)
 
static int convert5To8 (int b)
 
static int convert6To8 (int b)
 
static int divideBy255 (int d)
 
static int convert8To4 (int b)
 
static int convert8To5 (int b)
 
static int convertDiff (int base, int diff)
 
static void decode_subblock (etc1_byte *pOut, int r, int g, int b, const int *table, etc1_uint32 low, bool second, bool flipped)
 
void etc1_decode_block (const etc1_byte *pIn, etc1_byte *pOut)
 
static void take_best (etc_compressed *a, const etc_compressed *b)
 
static void etc_average_colors_subblock (const etc1_byte *pIn, etc1_uint32 inMask, etc1_byte *pColors, bool flipped, bool second)
 
static int square (int x)
 
static etc1_uint32 chooseModifier (const etc1_byte *pBaseColors, const etc1_byte *pIn, etc1_uint32 *pLow, int bitIndex, const int *pModifierTable)
 
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 bool inRange4bitSigned (int color)
 
static void etc_encodeBaseColors (etc1_byte *pBaseColors, const etc1_byte *pColors, etc_compressed *pCompressed)
 
static void etc_encode_block_helper (const etc1_byte *pIn, etc1_uint32 inMask, const etc1_byte *pColors, etc_compressed *pCompressed, bool flipped)
 
static void writeBigEndian (etc1_byte *pOut, etc1_uint32 d)
 
void etc1_encode_block (const etc1_byte *pIn, etc1_uint32 inMask, etc1_byte *pOut)
 
etc1_uint32 etc1_get_encoded_data_size (etc1_uint32 width, etc1_uint32 height)
 
int etc1_encode_image (const etc1_byte *pIn, etc1_uint32 width, etc1_uint32 height, etc1_uint32 pixelSize, etc1_uint32 stride, etc1_byte *pOut)
 
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 writeBEUint16 (etc1_byte *pOut, etc1_uint32 data)
 
static etc1_uint32 readBEUint16 (const etc1_byte *pIn)
 
void etc1_pkm_format_header (etc1_byte *pHeader, etc1_uint32 width, etc1_uint32 height)
 
etc1_bool etc1_pkm_is_valid (const etc1_byte *pHeader)
 
etc1_uint32 etc1_pkm_get_width (const etc1_byte *pHeader)
 
etc1_uint32 etc1_pkm_get_height (const etc1_byte *pHeader)
 

Variables

static const int kModifierTable []
 
static const int kLookup [8] = { 0, 1, 2, 3, -4, -3, -2, -1 }
 
static const char kMagic [] = { 'P', 'K', 'M', ' ', '1', '0' }
 
static const etc1_uint32 ETC1_PKM_FORMAT_OFFSET = 6
 
static const etc1_uint32 ETC1_PKM_ENCODED_WIDTH_OFFSET = 8
 
static const etc1_uint32 ETC1_PKM_ENCODED_HEIGHT_OFFSET = 10
 
static const etc1_uint32 ETC1_PKM_WIDTH_OFFSET = 12
 
static const etc1_uint32 ETC1_PKM_HEIGHT_OFFSET = 14
 
static const etc1_uint32 ETC1_RGB_NO_MIPMAPS = 0
 

Function Documentation

◆ chooseModifier()

static etc1_uint32 chooseModifier ( const etc1_byte pBaseColors,
const etc1_byte pIn,
etc1_uint32 pLow,
int  bitIndex,
const int pModifierTable 
)
static

Definition at line 306 of file etc1.cpp.

308 {
309 etc1_uint32 bestScore = ~0;
310 int bestIndex = 0;
311 int pixelR = pIn[0];
312 int pixelG = pIn[1];
313 int pixelB = pIn[2];
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);
320 etc1_uint32 score = (etc1_uint32) (6 * square(decodedG - pixelG));
321 if (score >= bestScore) {
322 continue;
323 }
324 int decodedR = clamp(r + modifier);
325 score += (etc1_uint32) (3 * square(decodedR - pixelR));
326 if (score >= bestScore) {
327 continue;
328 }
329 int decodedB = clamp(b + modifier);
330 score += (etc1_uint32) square(decodedB - pixelB);
331 if (score < bestScore) {
332 bestScore = score;
333 bestIndex = i;
334 }
335 }
336 etc1_uint32 lowMask = (((bestIndex >> 1) << 16) | (bestIndex & 1))
337 << bitIndex;
338 *pLow |= lowMask;
339 return bestScore;
340}
static int square(int x)
Definition etc1.cpp:302
static etc1_byte clamp(int x)
Definition etc1.cpp:130
unsigned int etc1_uint32
Definition etc1.h:35
static bool b

◆ clamp()

static etc1_byte clamp ( int  x)
inlinestatic

Definition at line 130 of file etc1.cpp.

130 {
131 return (etc1_byte) (x >= 0 ? (x < 255 ? x : 255) : 0);
132}
unsigned char etc1_byte
Definition etc1.h:33
double x

◆ convert4To8()

static int convert4To8 ( int  b)
inlinestatic

Definition at line 135 of file etc1.cpp.

135 {
136 int c = b & 0xf;
137 return (c << 4) | c;
138}

◆ convert5To8()

static int convert5To8 ( int  b)
inlinestatic

Definition at line 141 of file etc1.cpp.

141 {
142 int c = b & 0x1f;
143 return (c << 3) | (c >> 2);
144}

◆ convert6To8()

static int convert6To8 ( int  b)
inlinestatic

Definition at line 147 of file etc1.cpp.

147 {
148 int c = b & 0x3f;
149 return (c << 2) | (c >> 4);
150}

◆ convert8To4()

static int convert8To4 ( int  b)
inlinestatic

Definition at line 158 of file etc1.cpp.

158 {
159 int c = b & 0xff;
160 return divideBy255(c * 15);
161}
static int divideBy255(int d)
Definition etc1.cpp:153

◆ convert8To5()

static int convert8To5 ( int  b)
inlinestatic

Definition at line 164 of file etc1.cpp.

164 {
165 int c = b & 0xff;
166 return divideBy255(c * 31);
167}

◆ convertDiff()

static int convertDiff ( int  base,
int  diff 
)
inlinestatic

Definition at line 170 of file etc1.cpp.

170 {
171 return convert5To8((0x1f & base) + kLookup[0x7 & diff]);
172}
static const int kLookup[8]
Definition etc1.cpp:128
static int convert5To8(int b)
Definition etc1.cpp:141

◆ decode_subblock()

static void decode_subblock ( etc1_byte pOut,
int  r,
int  g,
int  b,
const int table,
etc1_uint32  low,
bool  second,
bool  flipped 
)
static

Definition at line 175 of file etc1.cpp.

176 {
177 int baseX = 0;
178 int baseY = 0;
179 if (second) {
180 if (flipped) {
181 baseY = 2;
182 } else {
183 baseX = 2;
184 }
185 }
186 for (int i = 0; i < 8; i++) {
187 int x, y;
188 if (flipped) {
189 x = baseX + (i >> 1);
190 y = baseY + (i & 1);
191 } else {
192 x = baseX + (i >> 2);
193 y = baseY + (i & 3);
194 }
195 int k = y + (x * 4);
196 int offset = ((low >> k) & 1) | ((low >> (k + 15)) & 2);
197 int delta = table[offset];
198 etc1_byte* q = pOut + 3 * (x + 4 * y);
199 *q++ = clamp(r + delta);
200 *q++ = clamp(g + delta);
201 *q++ = clamp(b + delta);
202 }
203}
SI F table(const skcms_Curve *curve, F v)
double y
Point offset

◆ divideBy255()

static int divideBy255 ( int  d)
inlinestatic

Definition at line 153 of file etc1.cpp.

153 {
154 return (d + 128 + (d >> 8)) >> 8;
155}
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition main.cc:19

◆ etc1_decode_block()

void etc1_decode_block ( const etc1_byte pIn,
etc1_byte pOut 
)

Definition at line 208 of file etc1.cpp.

208 {
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;
212 if (high & 2) {
213 // differential
214 int rBase = high >> 27;
215 int gBase = high >> 19;
216 int bBase = high >> 11;
217 r1 = convert5To8(rBase);
218 r2 = convertDiff(rBase, high >> 24);
219 g1 = convert5To8(gBase);
220 g2 = convertDiff(gBase, high >> 16);
221 b1 = convert5To8(bBase);
222 b2 = convertDiff(bBase, high >> 8);
223 } else {
224 // not differential
225 r1 = convert4To8(high >> 28);
226 r2 = convert4To8(high >> 24);
227 g1 = convert4To8(high >> 20);
228 g2 = convert4To8(high >> 16);
229 b1 = convert4To8(high >> 12);
230 b2 = convert4To8(high >> 8);
231 }
232 int tableIndexA = 7 & (high >> 5);
233 int tableIndexB = 7 & (high >> 2);
234 const int* tableA = kModifierTable + tableIndexA * 4;
235 const int* tableB = kModifierTable + tableIndexB * 4;
236 bool flipped = (high & 1) != 0;
237 decode_subblock(pOut, r1, g1, b1, tableA, low, false, flipped);
238 decode_subblock(pOut, r2, g2, b2, tableB, low, true, flipped);
239}
static int convert4To8(int b)
Definition etc1.cpp:135
static const int kModifierTable[]
Definition etc1.cpp:118
static int convertDiff(int base, int diff)
Definition etc1.cpp:170
static void decode_subblock(etc1_byte *pOut, int r, int g, int b, const int *table, etc1_uint32 low, bool second, bool flipped)
Definition etc1.cpp:175

◆ etc1_decode_image()

int etc1_decode_image ( const etc1_byte pIn,
etc1_byte pOut,
etc1_uint32  width,
etc1_uint32  height,
etc1_uint32  pixelSize,
etc1_uint32  stride 
)

Definition at line 573 of file etc1.cpp.

575 {
576 if (pixelSize < 2 || pixelSize > 3) {
577 return -1;
578 }
580
581 etc1_uint32 encodedWidth = (width + 3) & ~3;
582 etc1_uint32 encodedHeight = (height + 3) & ~3;
583
584 for (etc1_uint32 y = 0; y < encodedHeight; y += 4) {
585 etc1_uint32 yEnd = height - y;
586 if (yEnd > 4) {
587 yEnd = 4;
588 }
589 for (etc1_uint32 x = 0; x < encodedWidth; x += 4) {
590 etc1_uint32 xEnd = width - x;
591 if (xEnd > 4) {
592 xEnd = 4;
593 }
594 etc1_decode_block(pIn, block);
596 for (etc1_uint32 cy = 0; cy < yEnd; cy++) {
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);
601 } else {
602 for (etc1_uint32 cx = 0; cx < xEnd; cx++) {
603 etc1_byte r = *q++;
604 etc1_byte g = *q++;
605 etc1_byte b = *q++;
606 etc1_uint32 pixel = ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3);
607 *p++ = (etc1_byte) pixel;
608 *p++ = (etc1_byte) (pixel >> 8);
609 }
610 }
611 }
612 }
613 }
614 return 0;
615}
void etc1_decode_block(const etc1_byte *pIn, etc1_byte *pOut)
Definition etc1.cpp:208
#define ETC1_ENCODED_BLOCK_SIZE
Definition etc1.h:26
#define ETC1_DECODED_BLOCK_SIZE
Definition etc1.h:27
int32_t height
int32_t width

◆ etc1_encode_block()

void etc1_encode_block ( const etc1_byte pIn,
etc1_uint32  inMask,
etc1_byte pOut 
)

Definition at line 489 of file etc1.cpp.

490 {
491 etc1_byte colors[6];
492 etc1_byte flippedColors[6];
493 etc_average_colors_subblock(pIn, inMask, colors, false, false);
494 etc_average_colors_subblock(pIn, inMask, colors + 3, false, true);
495 etc_average_colors_subblock(pIn, inMask, flippedColors, true, false);
496 etc_average_colors_subblock(pIn, inMask, flippedColors + 3, true, true);
497
499 etc_encode_block_helper(pIn, inMask, colors, &a, false);
500 etc_encode_block_helper(pIn, inMask, flippedColors, &b, true);
501 take_best(&a, &b);
502 writeBigEndian(pOut, a.high);
503 writeBigEndian(pOut + 4, a.low);
504}
static void etc_encode_block_helper(const etc1_byte *pIn, etc1_uint32 inMask, const etc1_byte *pColors, etc_compressed *pCompressed, bool flipped)
Definition etc1.cpp:438
static void writeBigEndian(etc1_byte *pOut, etc1_uint32 d)
Definition etc1.cpp:477
static void etc_average_colors_subblock(const etc1_byte *pIn, etc1_uint32 inMask, etc1_byte *pColors, bool flipped, bool second)
Definition etc1.cpp:255
static void take_best(etc_compressed *a, const etc_compressed *b)
Definition etc1.cpp:248
struct MyStruct a[10]
PODArray< SkColor > colors
Definition SkRecords.h:276

◆ etc1_encode_image()

int etc1_encode_image ( const etc1_byte pIn,
etc1_uint32  width,
etc1_uint32  height,
etc1_uint32  pixelSize,
etc1_uint32  stride,
etc1_byte pOut 
)

Definition at line 517 of file etc1.cpp.

518 {
519 if (pixelSize < 2 || pixelSize > 3) {
520 return -1;
521 }
522 static const unsigned short kYMask[] = { 0x0, 0xf, 0xff, 0xfff, 0xffff };
523 static const unsigned short kXMask[] = { 0x0, 0x1111, 0x3333, 0x7777,
524 0xffff };
527
528 etc1_uint32 encodedWidth = (width + 3) & ~3;
529 etc1_uint32 encodedHeight = (height + 3) & ~3;
530
531 for (etc1_uint32 y = 0; y < encodedHeight; y += 4) {
532 etc1_uint32 yEnd = height - y;
533 if (yEnd > 4) {
534 yEnd = 4;
535 }
536 int ymask = kYMask[yEnd];
537 for (etc1_uint32 x = 0; x < encodedWidth; x += 4) {
538 etc1_uint32 xEnd = width - x;
539 if (xEnd > 4) {
540 xEnd = 4;
541 }
542 int mask = ymask & kXMask[xEnd];
543 for (etc1_uint32 cy = 0; cy < yEnd; cy++) {
544 etc1_byte* q = block + (cy * 4) * 3;
545 const etc1_byte* p = pIn + pixelSize * x + stride * (y + cy);
546 if (pixelSize == 3) {
547 memcpy(q, p, xEnd * 3);
548 } else {
549 for (etc1_uint32 cx = 0; cx < xEnd; cx++) {
550 int pixel = (p[1] << 8) | p[0];
551 *q++ = convert5To8(pixel >> 11);
552 *q++ = convert6To8(pixel >> 5);
553 *q++ = convert5To8(pixel);
554 p += pixelSize;
555 }
556 }
557 }
558 etc1_encode_block(block, mask, encoded);
559 memcpy(pOut, encoded, sizeof(encoded));
560 pOut += sizeof(encoded);
561 }
562 }
563 return 0;
564}
static int convert6To8(int b)
Definition etc1.cpp:147
void etc1_encode_block(const etc1_byte *pIn, etc1_uint32 inMask, etc1_byte *pOut)
Definition etc1.cpp:489

◆ etc1_get_encoded_data_size()

etc1_uint32 etc1_get_encoded_data_size ( etc1_uint32  width,
etc1_uint32  height 
)

Definition at line 508 of file etc1.cpp.

508 {
509 return (((width + 3) & ~3) * ((height + 3) & ~3)) >> 1;
510}

◆ etc1_pkm_format_header()

void etc1_pkm_format_header ( etc1_byte pHeader,
etc1_uint32  width,
etc1_uint32  height 
)

Definition at line 638 of file etc1.cpp.

638 {
639 memcpy(pHeader, kMagic, sizeof(kMagic));
640 etc1_uint32 encodedWidth = (width + 3) & ~3;
641 etc1_uint32 encodedHeight = (height + 3) & ~3;
643 writeBEUint16(pHeader + ETC1_PKM_ENCODED_WIDTH_OFFSET, encodedWidth);
644 writeBEUint16(pHeader + ETC1_PKM_ENCODED_HEIGHT_OFFSET, encodedHeight);
647}
static void writeBEUint16(etc1_byte *pOut, etc1_uint32 data)
Definition etc1.cpp:627
static const etc1_uint32 ETC1_PKM_ENCODED_HEIGHT_OFFSET
Definition etc1.cpp:621
static const etc1_uint32 ETC1_PKM_FORMAT_OFFSET
Definition etc1.cpp:619
static const etc1_uint32 ETC1_PKM_WIDTH_OFFSET
Definition etc1.cpp:622
static const etc1_uint32 ETC1_PKM_ENCODED_WIDTH_OFFSET
Definition etc1.cpp:620
static const etc1_uint32 ETC1_RGB_NO_MIPMAPS
Definition etc1.cpp:625
static const etc1_uint32 ETC1_PKM_HEIGHT_OFFSET
Definition etc1.cpp:623
static const char kMagic[]
Definition etc1.cpp:617

◆ etc1_pkm_get_height()

etc1_uint32 etc1_pkm_get_height ( const etc1_byte pHeader)

Definition at line 673 of file etc1.cpp.

673 {
674 return readBEUint16(pHeader + ETC1_PKM_HEIGHT_OFFSET);
675}
static etc1_uint32 readBEUint16(const etc1_byte *pIn)
Definition etc1.cpp:632

◆ etc1_pkm_get_width()

etc1_uint32 etc1_pkm_get_width ( const etc1_byte pHeader)

Definition at line 667 of file etc1.cpp.

667 {
668 return readBEUint16(pHeader + ETC1_PKM_WIDTH_OFFSET);
669}

◆ etc1_pkm_is_valid()

etc1_bool etc1_pkm_is_valid ( const etc1_byte pHeader)

Definition at line 651 of file etc1.cpp.

651 {
652 if (memcmp(pHeader, kMagic, sizeof(kMagic))) {
653 return false;
654 }
660 return format == ETC1_RGB_NO_MIPMAPS &&
661 encodedWidth >= width && encodedWidth - width < 4 &&
662 encodedHeight >= height && encodedHeight - height < 4;
663}
uint32_t uint32_t * format

◆ etc_average_colors_subblock()

static void etc_average_colors_subblock ( const etc1_byte pIn,
etc1_uint32  inMask,
etc1_byte pColors,
bool  flipped,
bool  second 
)
static

Definition at line 255 of file etc1.cpp.

256 {
257 int r = 0;
258 int g = 0;
259 int b = 0;
260
261 if (flipped) {
262 int by = 0;
263 if (second) {
264 by = 2;
265 }
266 for (int y = 0; y < 2; y++) {
267 int yy = by + y;
268 for (int x = 0; x < 4; x++) {
269 int i = x + 4 * yy;
270 if (inMask & (1 << i)) {
271 const etc1_byte* p = pIn + i * 3;
272 r += *(p++);
273 g += *(p++);
274 b += *(p++);
275 }
276 }
277 }
278 } else {
279 int bx = 0;
280 if (second) {
281 bx = 2;
282 }
283 for (int y = 0; y < 4; y++) {
284 for (int x = 0; x < 2; x++) {
285 int xx = bx + x;
286 int i = xx + 4 * y;
287 if (inMask & (1 << i)) {
288 const etc1_byte* p = pIn + i * 3;
289 r += *(p++);
290 g += *(p++);
291 b += *(p++);
292 }
293 }
294 }
295 }
296 pColors[0] = (etc1_byte)((r + 4) >> 3);
297 pColors[1] = (etc1_byte)((g + 4) >> 3);
298 pColors[2] = (etc1_byte)((b + 4) >> 3);
299}

◆ etc_encode_block_helper()

static void etc_encode_block_helper ( const etc1_byte pIn,
etc1_uint32  inMask,
const etc1_byte pColors,
etc_compressed pCompressed,
bool  flipped 
)
static

Definition at line 438 of file etc1.cpp.

439 {
440 pCompressed->score = ~0;
441 pCompressed->high = (flipped ? 1 : 0);
442 pCompressed->low = 0;
443
444 etc1_byte pBaseColors[6];
445
446 etc_encodeBaseColors(pBaseColors, pColors, pCompressed);
447
448 int originalHigh = pCompressed->high;
449
450 const int* pModifierTable = kModifierTable;
451 for (int i = 0; i < 8; i++, pModifierTable += 4) {
452 etc_compressed temp;
453 temp.score = 0;
454 temp.high = originalHigh | (i << 5);
455 temp.low = 0;
456 etc_encode_subblock_helper(pIn, inMask, &temp, flipped, false,
457 pBaseColors, pModifierTable);
458 take_best(pCompressed, &temp);
459 }
460 pModifierTable = kModifierTable;
461 etc_compressed firstHalf = *pCompressed;
462 for (int i = 0; i < 8; i++, pModifierTable += 4) {
463 etc_compressed temp;
464 temp.score = firstHalf.score;
465 temp.high = firstHalf.high | (i << 2);
466 temp.low = firstHalf.low;
467 etc_encode_subblock_helper(pIn, inMask, &temp, flipped, true,
468 pBaseColors + 3, pModifierTable);
469 if (i == 0) {
470 *pCompressed = temp;
471 } else {
472 take_best(pCompressed, &temp);
473 }
474 }
475}
static void etc_encodeBaseColors(etc1_byte *pBaseColors, const etc1_byte *pColors, etc_compressed *pCompressed)
Definition etc1.cpp:385
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)
Definition etc1.cpp:343
etc1_uint32 score
Definition etc1.cpp:244
etc1_uint32 low
Definition etc1.cpp:243
etc1_uint32 high
Definition etc1.cpp:242

◆ etc_encode_subblock_helper()

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

Definition at line 343 of file etc1.cpp.

345 {
346 int score = pCompressed->score;
347 if (flipped) {
348 int by = 0;
349 if (second) {
350 by = 2;
351 }
352 for (int y = 0; y < 2; y++) {
353 int yy = by + y;
354 for (int x = 0; x < 4; x++) {
355 int i = x + 4 * yy;
356 if (inMask & (1 << i)) {
357 score += chooseModifier(pBaseColors, pIn + i * 3,
358 &pCompressed->low, yy + x * 4, pModifierTable);
359 }
360 }
361 }
362 } else {
363 int bx = 0;
364 if (second) {
365 bx = 2;
366 }
367 for (int y = 0; y < 4; y++) {
368 for (int x = 0; x < 2; x++) {
369 int xx = bx + x;
370 int i = xx + 4 * y;
371 if (inMask & (1 << i)) {
372 score += chooseModifier(pBaseColors, pIn + i * 3,
373 &pCompressed->low, y + xx * 4, pModifierTable);
374 }
375 }
376 }
377 }
378 pCompressed->score = score;
379}
static etc1_uint32 chooseModifier(const etc1_byte *pBaseColors, const etc1_byte *pIn, etc1_uint32 *pLow, int bitIndex, const int *pModifierTable)
Definition etc1.cpp:306

◆ etc_encodeBaseColors()

static void etc_encodeBaseColors ( etc1_byte pBaseColors,
const etc1_byte pColors,
etc_compressed pCompressed 
)
static

Definition at line 385 of file etc1.cpp.

386 {
387 int r1, g1, b1, r2, g2, b2; // 8 bit base colors for sub-blocks
388 bool differential;
389
390 int r51 = convert8To5(pColors[0]);
391 int g51 = convert8To5(pColors[1]);
392 int b51 = convert8To5(pColors[2]);
393 int r52 = convert8To5(pColors[3]);
394 int g52 = convert8To5(pColors[4]);
395 int b52 = convert8To5(pColors[5]);
396
397 r1 = convert5To8(r51);
398 g1 = convert5To8(g51);
399 b1 = convert5To8(b51);
400
401 int dr = r52 - r51;
402 int dg = g52 - g51;
403 int db = b52 - b51;
404
405 differential = inRange4bitSigned(dr) && inRange4bitSigned(dg)
406 && inRange4bitSigned(db);
407 if (differential) {
408 r2 = convert5To8(r51 + dr);
409 g2 = convert5To8(g51 + dg);
410 b2 = convert5To8(b51 + db);
411 pCompressed->high |= (r51 << 27) | ((7 & dr) << 24) | (g51 << 19)
412 | ((7 & dg) << 16) | (b51 << 11) | ((7 & db) << 8) | 2;
413 } else {
414 int r41 = convert8To4(pColors[0]);
415 int g41 = convert8To4(pColors[1]);
416 int b41 = convert8To4(pColors[2]);
417 int r42 = convert8To4(pColors[3]);
418 int g42 = convert8To4(pColors[4]);
419 int b42 = convert8To4(pColors[5]);
420 r1 = convert4To8(r41);
421 g1 = convert4To8(g41);
422 b1 = convert4To8(b41);
423 r2 = convert4To8(r42);
424 g2 = convert4To8(g42);
425 b2 = convert4To8(b42);
426 pCompressed->high |= (r41 << 28) | (r42 << 24) | (g41 << 20) | (g42
427 << 16) | (b41 << 12) | (b42 << 8);
428 }
429 pBaseColors[0] = r1;
430 pBaseColors[1] = g1;
431 pBaseColors[2] = b1;
432 pBaseColors[3] = r2;
433 pBaseColors[4] = g2;
434 pBaseColors[5] = b2;
435}
static bool inRange4bitSigned(int color)
Definition etc1.cpp:381
static int convert8To5(int b)
Definition etc1.cpp:164
static int convert8To4(int b)
Definition etc1.cpp:158

◆ inRange4bitSigned()

static bool inRange4bitSigned ( int  color)
static

Definition at line 381 of file etc1.cpp.

381 {
382 return color >= -4 && color <= 3;
383}
SkColor4f color

◆ readBEUint16()

static etc1_uint32 readBEUint16 ( const etc1_byte pIn)
static

Definition at line 632 of file etc1.cpp.

632 {
633 return (pIn[0] << 8) | pIn[1];
634}

◆ square()

static int square ( int  x)
inlinestatic

Definition at line 302 of file etc1.cpp.

302 {
303 return x * x;
304}

◆ take_best()

static void take_best ( etc_compressed a,
const etc_compressed b 
)
inlinestatic

Definition at line 248 of file etc1.cpp.

248 {
249 if (a->score > b->score) {
250 *a = *b;
251 }
252}

◆ writeBEUint16()

static void writeBEUint16 ( etc1_byte pOut,
etc1_uint32  data 
)
static

Definition at line 627 of file etc1.cpp.

627 {
628 pOut[0] = (etc1_byte) (data >> 8);
629 pOut[1] = (etc1_byte) data;
630}

◆ writeBigEndian()

static void writeBigEndian ( etc1_byte pOut,
etc1_uint32  d 
)
static

Definition at line 477 of file etc1.cpp.

477 {
478 pOut[0] = (etc1_byte) (d >> 24);
479 pOut[1] = (etc1_byte)((d >> 16) & 0xFF);
480 pOut[2] = (etc1_byte)((d >> 8) & 0xFF);
481 pOut[3] = (etc1_byte)((d >> 0) & 0xFF);
482}

Variable Documentation

◆ ETC1_PKM_ENCODED_HEIGHT_OFFSET

const etc1_uint32 ETC1_PKM_ENCODED_HEIGHT_OFFSET = 10
static

Definition at line 621 of file etc1.cpp.

◆ ETC1_PKM_ENCODED_WIDTH_OFFSET

const etc1_uint32 ETC1_PKM_ENCODED_WIDTH_OFFSET = 8
static

Definition at line 620 of file etc1.cpp.

◆ ETC1_PKM_FORMAT_OFFSET

const etc1_uint32 ETC1_PKM_FORMAT_OFFSET = 6
static

Definition at line 619 of file etc1.cpp.

◆ ETC1_PKM_HEIGHT_OFFSET

const etc1_uint32 ETC1_PKM_HEIGHT_OFFSET = 14
static

Definition at line 623 of file etc1.cpp.

◆ ETC1_PKM_WIDTH_OFFSET

const etc1_uint32 ETC1_PKM_WIDTH_OFFSET = 12
static

Definition at line 622 of file etc1.cpp.

◆ ETC1_RGB_NO_MIPMAPS

const etc1_uint32 ETC1_RGB_NO_MIPMAPS = 0
static

Definition at line 625 of file etc1.cpp.

◆ kLookup

const int kLookup[8] = { 0, 1, 2, 3, -4, -3, -2, -1 }
static

Definition at line 128 of file etc1.cpp.

128{ 0, 1, 2, 3, -4, -3, -2, -1 };

◆ kMagic

const char kMagic[] = { 'P', 'K', 'M', ' ', '1', '0' }
static

Definition at line 617 of file etc1.cpp.

617{ 'P', 'K', 'M', ' ', '1', '0' };

◆ kModifierTable

const int kModifierTable[]
static
Initial value:
= {
2, 8, -2, -8,
5, 17, -5, -17,
9, 29, -9, -29,
13, 42, -13, -42,
18, 60, -18, -60,
24, 80, -24, -80,
33, 106, -33, -106,
47, 183, -47, -183 }

Definition at line 118 of file etc1.cpp.

118 {
119/* 0 */2, 8, -2, -8,
120/* 1 */5, 17, -5, -17,
121/* 2 */9, 29, -9, -29,
122/* 3 */13, 42, -13, -42,
123/* 4 */18, 60, -18, -60,
124/* 5 */24, 80, -24, -80,
125/* 6 */33, 106, -33, -106,
126/* 7 */47, 183, -47, -183 };