42 return (c << 3) | (c >> 2);
46 static const int kLookup[8] = { 0, 1, 2, 3, -4, -3, -2, -1 };
63 { 33, 106, -33, -106 },
64 { 47, 183, -47, -183 }
68 return ((size + 3) & ~3) >> 2;
88 int r8 =
SkTPin(col.
fR + delta, 0, 255);
89 int g8 =
SkTPin(col.
fG + delta, 0, 255);
90 int b8 =
SkTPin(col.
fB + delta, 0, 255);
101 for (
int y = 0;
y < numYBlocks; ++
y) {
102 for (
int x = 0;
x < numXBlocks; ++
x) {
103 const ETC1Block* curBlock1 = &srcBlocks[
y * numXBlocks +
x];
128 int tableIndex0 = (high >> 5) & 0x7;
129 int tableIndex1 = (high >> 2) & 0x7;
130 const int* tables[2] = {
137 for (
int i = 0; i < 4; ++i, ++baseShift) {
138 for (
int j = 0; j < 4; ++j) {
139 if (
offsetX + j >= dst->width() ||
offsetY + i >= dst->height()) {
146 int pixelIndex = ((low >> (baseShift+(j*4))) & 0x1) |
147 (low >> (baseShift+(j*4)+15) & 0x2);
149 SkASSERT(subBlockIndex == 0 || subBlockIndex == 1);
150 SkASSERT(pixelIndex >= 0 && pixelIndex < 4);
152 int delta = tables[subBlockIndex][pixelIndex];
198 for (
int y = 0;
y < numYBlocks; ++
y) {
199 for (
int x = 0;
x < numXBlocks; ++
x) {
200 const BC1Block* curBlock = &srcBlocks[
y * numXBlocks +
x];
213 colors[2] =
lerp(2.0f/3.0f, colors[0], colors[1]);
214 colors[3] =
lerp(1.0f/3.0f, colors[0], colors[1]);
219 for (
int i = 0; i < 4; ++i) {
220 for (
int j = 0; j < 4; ++j, shift += 2) {
221 if (
offsetX + j >= dst->width() ||
offsetY + i >= dst->height()) {
227 int index = (curBlock->
fIndices >> shift) & 0x3;
243 const uint8_t* bytes = data->bytes();
244 switch (compressionType) {
245 case Type::kNone:
return false;
246 case Type::kETC2_RGB8_UNORM:
return decompress_etc1(dimensions, bytes, dst);
247 case Type::kBC1_RGB8_UNORM:
return decompress_bc1(dimensions, bytes,
true, dst);
248 case Type::kBC1_RGBA8_UNORM:
return decompress_bc1(dimensions, bytes,
false, dst);
256 SkASSERT(!individualMipOffsets || individualMipOffsets->
empty());
258 int numMipLevels = 1;
263 size_t totalSize = 0;
270 for (
int i = 0; i < numMipLevels; ++i) {
274 if (individualMipOffsets) {
275 individualMipOffsets->
push_back(totalSize);
279 totalSize += numBlocks *
sizeof(
ETC1Block);
281 dimensions = {std::max(1, dimensions.width()/2), std::max(1, dimensions.height()/2)};
304 SkISize dimensions,
bool mipmapped) {
static const uint16_t rgb565[kNumPixels]
static unsigned SkB16ToB32(unsigned b)
static unsigned SkG16ToG32(unsigned g)
static unsigned SkR16ToR32(unsigned r)
#define SkGetPackedB32(packed)
#define SkGetPackedR32(packed)
#define SkGetPackedA32(packed)
#define SkGetPackedG32(packed)
static SkPMColor SkPackARGB32(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
bool SkDecompress(sk_sp< SkData > data, SkISize dimensions, SkTextureCompressionType compressionType, SkBitmap *dst)
static int extend_5To8bits(int b)
static SkPMColor lerp(float t, SkPMColor col0, SkPMColor col1)
static const int kNumETC1PixelIndices
static bool decompress_bc1(SkISize dimensions, const uint8_t *srcData, bool isOpaque, SkBitmap *dst)
static int xy_to_subblock_index(int x, int y, bool flip)
static int num_4x4_blocks(int size)
static SkPMColor add_delta_and_clamp(const IColor &col, int delta)
size_t SkCompressedFormatDataSize(SkTextureCompressionType compressionType, SkISize dimensions, bool mipmapped)
constexpr uint32_t kDiffBit
static const int kNumETC1ModifierTables
static bool decompress_etc1(SkISize dimensions, const uint8_t *srcData, SkBitmap *dst)
size_t SkCompressedDataSize(SkTextureCompressionType type, SkISize dimensions, TArray< size_t > *individualMipOffsets, bool mipmapped)
static int extend_4To8bits(int b)
static const int kETC1ModifierTables[kNumETC1ModifierTables][kNumETC1PixelIndices]
static SkPMColor from565(uint16_t rgb565)
static int extend_5plus3To8Bits(int base, int diff)
constexpr uint32_t kFlipBit
size_t SkCompressedBlockSize(SkTextureCompressionType type)
static uint32_t SkBSwap32(uint32_t v)
#define SkScalarRoundToInt(x)
static constexpr const T & SkTPin(const T &x, const T &lo, const T &hi)
static constexpr bool SkToBool(const T &x)
static int ComputeLevelCount(int baseWidth, int baseHeight)
static const int kLookup[8]
constexpr int32_t width() const
constexpr int32_t height() const