31 const auto expectedSize =
static_cast<size_t>(size.
width) *
static_cast<size_t>(size.
height) * 4;
32 if (src.size() != expectedSize) {
36 std::vector<uint32_t> pixels(
static_cast<size_t>(paddedWidth) *
static_cast<size_t>(paddedHeight));
37 for (
int y = 0; y < paddedHeight; y++) {
38 const int srcY = std::min(y, size.
height - 1);
39 for (
int x = 0; x < paddedWidth; x++) {
40 const int srcX = std::min(x, size.
width - 1);
41 const auto srcOffset = (
static_cast<size_t>(srcY) *
static_cast<size_t>(size.
width) +
static_cast<size_t>(srcX)) * 4;
42 const uint8_t bgra[4] = {
48 std::memcpy(&pixels[
static_cast<size_t>(y) *
static_cast<size_t>(paddedWidth) +
static_cast<size_t>(x)], bgra, 4);
64 const size_t blocks = blockCount(size.width, size.height);
65 const size_t expectedSize = blocks * 8;
66 if (src.size() != expectedSize) {
67 HAIO_FAIL(InvalidInput,
"invalid etc1 data size");
70 const int paddedWidth = paddedSize(size.width);
71 const int paddedHeight = paddedSize(size.height);
72 std::vector<uint64_t> compressed(blocks);
73 std::memcpy(compressed.data(), src.data(), expectedSize);
75 std::vector<uint32_t> paddedRGBA(
static_cast<size_t>(paddedWidth) *
static_cast<size_t>(paddedHeight));
76 DecodeRGB(compressed.data(), paddedRGBA.data(), paddedWidth, paddedHeight);
78 std::vector<uint8_t> buffer(
static_cast<size_t>(size.width) *
static_cast<size_t>(size.height) * 4);
79 for (
int y = 0; y < size.height; y++) {
80 for (
int x = 0; x < size.width; x++) {
81 const auto srcOffset =
static_cast<size_t>(y) *
static_cast<size_t>(paddedWidth) +
static_cast<size_t>(x);
82 const auto dstOffset = (
static_cast<size_t>(y) *
static_cast<size_t>(size.width) +
static_cast<size_t>(x)) * 4;
83 std::memcpy(buffer.data() + dstOffset, &paddedRGBA[srcOffset], 4);
84 buffer[dstOffset + 3] = 255;
89 std::memcpy(dst.data(), buffer.data(), std::min(dst.size(), buffer.size()));