Fix incorrect alpha-blend in some cases.
authorCarl Hetherington <cth@carlh.net>
Wed, 3 Jan 2018 00:45:27 +0000 (00:45 +0000)
committerCarl Hetherington <cth@carlh.net>
Wed, 3 Jan 2018 00:45:27 +0000 (00:45 +0000)
src/lib/image.cc

index 989187c12fb64b0862c8495930d7292bd09dcc97..33a0077db8e40d49bc40902a6c5879b4bba69e3d 100644 (file)
@@ -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;
                }
        }
 }