From ac9648e018f06d11be985f55984f6afe8b6bb97e Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 3 Jan 2018 00:45:27 +0000 Subject: [PATCH] Fix incorrect alpha-blend in some cases. --- src/lib/image.cc | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/lib/image.cc b/src/lib/image.cc index 989187c12..33a0077db 100644 --- a/src/lib/image.cc +++ b/src/lib/image.cc @@ -449,19 +449,23 @@ component ( { dcp::Size const base_size = base->sample_size(n); dcp::Size const other_size = other->sample_size(n); - for (int by = start_base_y, oy = start_other_y; by < base_size.height && oy < other_size.height; ++by, ++oy) { + int const bhf = base->horizontal_factor(n); + int const bvf = base->vertical_factor(n); + int const ohf = other->horizontal_factor(n); + int const ovf = other->vertical_factor(n); + for (int by = start_base_y / bvf, oy = start_other_y / ovf, ry = start_other_y; by < base_size.height && oy < other_size.height; ++by, ++oy, ry += ovf) { /* base image */ - T* bp = ((T*) (base->data()[n] + by * base->stride()[n])) + start_base_x; + T* bp = ((T*) (base->data()[n] + by * base->stride()[n])) + start_base_x / bhf; /* overlay image */ T* op = ((T*) (other->data()[n] + oy * other->stride()[n])); /* original RGBA for alpha channel */ - uint8_t* rp = rgba->data()[0] + oy * rgba->stride()[0]; - for (int bx = start_base_x, ox = start_other_x; bx < base_size.width && ox < other_size.width; ++bx, ++ox) { + uint8_t* rp = rgba->data()[0] + ry * rgba->stride()[0]; + for (int bx = start_base_x / bhf, ox = start_other_x / ohf; bx < base_size.width && ox < other_size.width; ++bx, ++ox) { float const alpha = float (rp[3]) / 255; *bp = *op * alpha + *bp * (1 - alpha); ++bp; ++op; - rp += 4; + rp += 4 * ohf; } } } -- 2.30.2