diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2023-03-02 16:54:39 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-03-02 16:54:56 +0100 |
commit | fea104b14632e3d51be7ce1abf71195e4f6b1a8d (patch) | |
tree | b31f0cf864eb7c4556e8137e5c93180666b71f5c | |
parent | 0a1524f4f6f791fde05e681fbabd0787636ebced (diff) |
src/anim-atlas: add bitmap optimization attempt
-rw-r--r-- | src/anim-atlas.cpp | 29 |
1 files changed, 13 insertions, 16 deletions
diff --git a/src/anim-atlas.cpp b/src/anim-atlas.cpp index 8ddd73d6..c32cf42d 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 auto width = size[1], height = size[0], - stride = (std::size_t)pixels.stride()[0], width0 = width & ~7u; + const std::size_t width = size[1], height = size[0], + stride = (std::size_t)pixels.stride()[0], width8 = width >> 3; const auto* const data = (const unsigned char*)pixels.data(); - auto* const dest = (unsigned char*)array.data(); + auto* const array_ = (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; - auto i = 0_uz; - for (; i < width0; i += 8) + const unsigned char* buf = &data[j*stride+3]; + auto* dest = &array_[j*width >> 3]; + + for (auto i = 0_uz; i < width8; i++) { - 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,16 +156,13 @@ 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[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); + *dest++ = value; + buf += 8*4; } + if (auto i = width8 << 3; i < width) + do + array.set(j*width + i, data[(j*stride + i*4)+3] >= amin); + while (++i < width); } } |