From 8ef2e66318923cc644d71f5b7e495875c07eb290 Mon Sep 17 00:00:00 2001 From: falsycat Date: Sat, 28 Aug 2021 10:45:25 +0900 Subject: [PATCH] Fixes size calcution in GlichPosteffect. --- src/GlitchPosteffect.h | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/GlitchPosteffect.h b/src/GlitchPosteffect.h index e62c487..e34d44f 100644 --- a/src/GlitchPosteffect.h +++ b/src/GlitchPosteffect.h @@ -27,16 +27,19 @@ class GlitchPosteffect : public iDrawable { float* ptr = fb.ptr(); for (int32_t y = 0; y < h; ++y) { - const double shift = (XorShift(seed+y)%100/100.*2-1)*maxShift; - const int32_t s = static_cast(w*shift); - if (std::abs(shift) > 1) continue; + if (XorShift(seed+y)%10 == 0) continue; - const size_t offset = static_cast(y) * w; - float* src = ptr + offset; - float* dst = ptr + offset + s; - if (src > dst) std::swap(src, dst); + const double shift = (XorShift(seed+y+h)%100/100.*2-1)*maxShift; + if (std::abs(shift) > 1) continue; - std::memmove(dst, src, static_cast(w) - std::abs(s)); + const int32_t s = static_cast(w*shift); + const int32_t as = std::abs(s); + + float* src = ptr + static_cast(y) * w; + float* dst = src + as; + if (s < 0) std::swap(src, dst); + + std::memmove(dst, src, (static_cast(w) - as)*sizeof(*ptr)); } }