// Return which sub-block a given x,y location in the overall 4x4 block belongs to staticint xy_to_subblock_index(int x, int y, bool flip) {
SkASSERT(x >= 0 && x < 4);
SkASSERT(y >= 0 && y < 4);
if (flip) { return y < 2 ? 0 : 1; // sub-block 1 is on top of sub-block 2
} else { return x < 2 ? 0 : 1; // sub-block 1 is to the left of sub-block 2
}
}
struct IColor { int fR, fG, fB;
};
static SkPMColor add_delta_and_clamp(const IColor& col, int delta) { int r8 = SkTPin(col.fR + delta, 0, 255); int g8 = SkTPin(col.fG + delta, 0, 255); int b8 = SkTPin(col.fB + delta, 0, 255);
int baseShift = 0; int offsetX = 4 * x, offsetY = 4 * y; for (int i = 0; i < 4; ++i, ++baseShift) { for (int j = 0; j < 4; ++j) { if (offsetX + j >= dst->width() || offsetY + i >= dst->height()) { // This can happen for the topmost levels of a mipmap and for // non-multiple of 4 textures continue;
}
int subBlockIndex = xy_to_subblock_index(j, i, flipped); int pixelIndex = ((low >> (baseShift+(j*4))) & 0x1) |
(low >> (baseShift+(j*4)+15) & 0x2);
int numXBlocks = num_4x4_blocks(dimensions.width()); int numYBlocks = num_4x4_blocks(dimensions.height());
SkPMColor colors[4];
for (int y = 0; y < numYBlocks; ++y) { for (int x = 0; x < numXBlocks; ++x) { const BC1Block* curBlock = &srcBlocks[y * numXBlocks + x];
colors[0] = from565(curBlock->fColor0);
colors[1] = from565(curBlock->fColor1); if (curBlock->fColor0 <= curBlock->fColor1) { // signal for a transparent block
colors[2] = SkPackARGB32(
0xFF,
(SkGetPackedR32(colors[0]) + SkGetPackedR32(colors[1])) >> 1,
(SkGetPackedG32(colors[0]) + SkGetPackedG32(colors[1])) >> 1,
(SkGetPackedB32(colors[0]) + SkGetPackedB32(colors[1])) >> 1); // The opacity of the overall texture trumps the per-block transparency
colors[3] = SkPackARGB32(isOpaque ? 0xFF : 0, 0, 0, 0);
} else {
colors[2] = lerp(2.0f/3.0f, colors[0], colors[1]);
colors[3] = lerp(1.0f/3.0f, colors[0], colors[1]);
}
int shift = 0; int offsetX = 4 * x, offsetY = 4 * y; for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j, shift += 2) { if (offsetX + j >= dst->width() || offsetY + i >= dst->height()) { // This can happen for the topmost levels of a mipmap and for // non-multiple of 4 textures continue;
}
int index = (curBlock->fIndices >> shift) & 0x3;
*dst->getAddr32(offsetX + j, offsetY + i) = colors[index];
}
}
}
}
returntrue;
}
bool SkDecompress(sk_sp<SkData> data,
SkISize dimensions,
SkTextureCompressionType compressionType,
SkBitmap* dst) { using Type = SkTextureCompressionType;
const uint8_t* bytes = data->bytes(); switch (compressionType) { case Type::kNone: returnfalse; case Type::kETC2_RGB8_UNORM: return decompress_etc1(dimensions, bytes, dst); case Type::kBC1_RGB8_UNORM: return decompress_bc1(dimensions, bytes, true, dst); case Type::kBC1_RGBA8_UNORM: return decompress_bc1(dimensions, bytes, false, dst);
}
int numMipLevels = 1; if (mipmapped) {
numMipLevels = SkMipmap::ComputeLevelCount(dimensions.width(), dimensions.height()) + 1;
}
size_t totalSize = 0; switch (type) { case SkTextureCompressionType::kNone: break; case SkTextureCompressionType::kETC2_RGB8_UNORM: case SkTextureCompressionType::kBC1_RGB8_UNORM: case SkTextureCompressionType::kBC1_RGBA8_UNORM: { for (int i = 0; i < numMipLevels; ++i) { int numBlocks = num_4x4_blocks(dimensions.width()) *
num_4x4_blocks(dimensions.height());
if (individualMipOffsets) {
individualMipOffsets->push_back(totalSize);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.