Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Macros | Typedefs | Functions
etc1.h File Reference

Go to the source code of this file.

Macros

#define ETC1_ENCODED_BLOCK_SIZE   8
 
#define ETC1_DECODED_BLOCK_SIZE   48
 
#define ETC1_RGB8_OES   0x8D64
 
#define ETC_PKM_HEADER_SIZE   16
 

Typedefs

typedef unsigned char etc1_byte
 
typedef int etc1_bool
 
typedef unsigned int etc1_uint32
 

Functions

void etc1_encode_block (const etc1_byte *pIn, etc1_uint32 validPixelMask, etc1_byte *pOut)
 
void etc1_decode_block (const etc1_byte *pIn, 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)
 
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)
 

Macro Definition Documentation

◆ ETC1_DECODED_BLOCK_SIZE

#define ETC1_DECODED_BLOCK_SIZE   48

Definition at line 27 of file etc1.h.

◆ ETC1_ENCODED_BLOCK_SIZE

#define ETC1_ENCODED_BLOCK_SIZE   8

Definition at line 26 of file etc1.h.

◆ ETC1_RGB8_OES

#define ETC1_RGB8_OES   0x8D64

Definition at line 30 of file etc1.h.

◆ ETC_PKM_HEADER_SIZE

#define ETC_PKM_HEADER_SIZE   16

Definition at line 92 of file etc1.h.

Typedef Documentation

◆ etc1_bool

typedef int etc1_bool

Definition at line 34 of file etc1.h.

◆ etc1_byte

typedef unsigned char etc1_byte

Definition at line 33 of file etc1.h.

◆ etc1_uint32

typedef unsigned int etc1_uint32

Definition at line 35 of file etc1.h.

Function Documentation

◆ 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 convert5To8(int b)
Definition etc1.cpp:141
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
unsigned int etc1_uint32
Definition etc1.h:35

◆ 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
unsigned char etc1_byte
Definition etc1.h:33
static bool b
double y
double x
int32_t height
int32_t width

◆ etc1_encode_block()

void etc1_encode_block ( const etc1_byte pIn,
etc1_uint32  validPixelMask,
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