diff options
Diffstat (limited to 'libass/ass_bitmap.c')
-rw-r--r-- | libass/ass_bitmap.c | 57 |
1 files changed, 28 insertions, 29 deletions
diff --git a/libass/ass_bitmap.c b/libass/ass_bitmap.c index b11fcfa..191eeaa 100644 --- a/libass/ass_bitmap.c +++ b/libass/ass_bitmap.c @@ -58,6 +58,34 @@ #endif +static void be_blur_pre(uint8_t *buf, intptr_t stride, intptr_t width, intptr_t height) +{ + for (int y = 0; y < height; ++y) + { + for (int x = 0; x < width; ++x) + { + // This is equivalent to (value * 64 + 127) / 255 for all + // values from 0 to 256 inclusive. Assist vectorizing + // compilers by noting that all temporaries fit in 8 bits. + buf[y * stride + x] = + (uint8_t) ((buf[y * stride + x] >> 1) + 1) >> 1; + } + } +} + +static void be_blur_post(uint8_t *buf, intptr_t stride, intptr_t width, intptr_t height) +{ + for (int y = 0; y < height; ++y) + { + for (int x = 0; x < width; ++x) + { + // This is equivalent to (value * 255 + 32) / 64 for all values + // from 0 to 96 inclusive, and we only care about 0 to 64. + uint8_t value = buf[y * stride + x]; + buf[y * stride + x] = (value << 2) - (value > 32); + } + } +} void ass_synth_blur(const BitmapEngine *engine, Bitmap *bm, int be, double blur_r2) @@ -319,35 +347,6 @@ void ass_be_blur_c(uint8_t *buf, intptr_t stride, } } -void be_blur_pre(uint8_t *buf, intptr_t stride, intptr_t width, intptr_t height) -{ - for (int y = 0; y < height; ++y) - { - for (int x = 0; x < width; ++x) - { - // This is equivalent to (value * 64 + 127) / 255 for all - // values from 0 to 256 inclusive. Assist vectorizing - // compilers by noting that all temporaries fit in 8 bits. - buf[y * stride + x] = - (uint8_t) ((buf[y * stride + x] >> 1) + 1) >> 1; - } - } -} - -void be_blur_post(uint8_t *buf, intptr_t stride, intptr_t width, intptr_t height) -{ - for (int y = 0; y < height; ++y) - { - for (int x = 0; x < width; ++x) - { - // This is equivalent to (value * 255 + 32) / 64 for all values - // from 0 to 96 inclusive, and we only care about 0 to 64. - uint8_t value = buf[y * stride + x]; - buf[y * stride + x] = (value << 2) - (value > 32); - } - } -} - /* * To find these values, simulate blur on the border between two * half-planes, one zero-filled (background) and the other filled |