-template <class T>
-void
-component (
- int n,
- Image* base,
- shared_ptr<const Image> other,
- shared_ptr<const Image> rgba,
- int start_base_x, int start_base_y,
- int start_other_x, int start_other_y
- )
-{
- dcp::Size const base_size = base->sample_size(n);
- dcp::Size const other_size = other->sample_size(n);
- 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 / bhf;
- /* overlay image */
- T* op = ((T*) (other->data()[n] + oy * other->stride()[n]));
- /* original RGBA for alpha channel */
- 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 * ohf;
- }
- }
-}
-