diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2023-03-02 16:55:12 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-03-02 16:55:12 +0100 |
commit | 1c00f3fb3ca4a0e47cf66d59966788e8451ae3b4 (patch) | |
tree | ac127563886006ac537faaaf34f0c20b6261309f | |
parent | fea104b14632e3d51be7ce1abf71195e4f6b1a8d (diff) |
Revert "src/anim-atlas: add bitmap optimization attempt"
This reverts commit fea104b14632e3d51be7ce1abf71195e4f6b1a8d.
Now it lives in the repo history.
-rw-r--r-- | src/anim-atlas.cpp | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/src/anim-atlas.cpp b/src/anim-atlas.cpp index c32cf42d..8ddd73d6 100644 --- a/src/anim-atlas.cpp +++ b/src/anim-atlas.cpp @@ -131,10 +131,10 @@ void anim_atlas::make_bitmask_(const ImageView2D& tex, BitArray& array) { const auto pixels = tex.pixels(); const auto size = pixels.size(); - const std::size_t width = size[1], height = size[0], - stride = (std::size_t)pixels.stride()[0], width8 = width >> 3; + const auto width = size[1], height = size[0], + stride = (std::size_t)pixels.stride()[0], width0 = width & ~7u; const auto* const data = (const unsigned char*)pixels.data(); - auto* const array_ = (unsigned char*)array.data(); + auto* const dest = (unsigned char*)array.data(); fm_assert(tex.pixelSize() == 4); fm_assert(pixels.stride()[1] == 4); @@ -142,11 +142,11 @@ void anim_atlas::make_bitmask_(const ImageView2D& tex, BitArray& array) for (auto j = 0_uz; j < height; j++) { constexpr unsigned char amin = 32; - const unsigned char* buf = &data[j*stride+3]; - auto* dest = &array_[j*width >> 3]; - - for (auto i = 0_uz; i < width8; i++) + auto i = 0_uz; + for (; i < width0; i += 8) { + const auto src_idx = (j*stride + i*4)+3, dst_idx = (height-j-1)*width+i >> 3; + const unsigned char* buf = data + src_idx; auto value = (unsigned char)( (unsigned char)(buf[0*4] >= amin) << 0 | (unsigned char)(buf[1*4] >= amin) << 1 | @@ -156,13 +156,16 @@ void anim_atlas::make_bitmask_(const ImageView2D& tex, BitArray& array) (unsigned char)(buf[5*4] >= amin) << 5 | (unsigned char)(buf[6*4] >= amin) << 6 | (unsigned char)(buf[7*4] >= amin) << 7); - *dest++ = value; - buf += 8*4; + dest[dst_idx] = value; + } + if (i < width) + { + dest[(height-j-1)*width+i >> 3] = 0; + do { + unsigned char alpha = data[(j*stride + i*4)+3]; + array.set((height-j-1)*width + i, alpha >= amin); + } while (++i < width); } - if (auto i = width8 << 3; i < width) - do - array.set(j*width + i, data[(j*stride + i*4)+3] >= amin); - while (++i < width); } } |