using dcp::Size;
int
-Image::line_factor (int n) const
+Image::vertical_factor (int n) const
{
if (n == 0) {
return 1;
return pow (2.0f, d->log2_chroma_h);
}
-/** @param n Component index.
- * @return Number of samples (i.e. pixels, unless sub-sampled) in each direction for this component.
- */
-dcp::Size
-Image::sample_size (int n) const
+int
+Image::horizontal_factor (int n) const
{
int horizontal_factor = 1;
if (n > 0) {
}
horizontal_factor = pow (2.0f, d->log2_chroma_w);
}
+ return horizontal_factor;
+}
+/** @param n Component index.
+ * @return Number of samples (i.e. pixels, unless sub-sampled) in each direction for this component.
+ */
+dcp::Size
+Image::sample_size (int n) const
+{
return dcp::Size (
- lrint (ceil (static_cast<double>(size().width) / horizontal_factor)),
- lrint (ceil (static_cast<double>(size().height) / line_factor (n)))
+ lrint (ceil (static_cast<double>(size().width) / horizontal_factor (n))),
+ lrint (ceil (static_cast<double>(size().height) / vertical_factor (n)))
);
}
we've cropped all of its Y-channel pixels.
*/
int const x = lrintf (bytes_per_pixel(c) * crop.left) & ~ ((int) desc->log2_chroma_w);
- scale_in_data[c] = data()[c] + x + stride()[c] * (crop.top / line_factor(c));
+ scale_in_data[c] = data()[c] + x + stride()[c] * (crop.top / vertical_factor(c));
}
/* Corner of the image within out_size */
memset (data()[0], 0, sample_size(0).height * stride()[0]);
}
+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);
+ for (int by = start_base_y, oy = start_other_y; by < base_size.height && oy < other_size.height; ++by, ++oy) {
+ /* base image */
+ T* bp = ((T*) (base->data()[n] + by * base->stride()[n])) + start_base_x;
+ /* 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) {
+ float const alpha = float (rp[3]) / 255;
+ *bp = *op * alpha + *bp * (1 - alpha);
+ ++bp;
+ ++op;
+ rp += 4;
+ }
+ }
+}
+
void
Image::alpha_blend (shared_ptr<const Image> other, Position<int> position)
{
}
break;
}
+ case AV_PIX_FMT_YUV420P:
+ {
+ shared_ptr<Image> yuv = other->scale (other->size(), dcp::YUV_TO_RGB_REC709, _pixel_format, false, false);
+ component<uint8_t> (0, this, yuv, other, start_tx, start_ty, start_ox, start_oy);
+ component<uint8_t> (1, this, yuv, other, start_tx, start_ty, start_ox, start_oy);
+ component<uint8_t> (2, this, yuv, other, start_tx, start_ty, start_ox, start_oy);
+ break;
+ }
+ case AV_PIX_FMT_YUV420P10:
+ {
+ shared_ptr<Image> yuv = other->scale (other->size(), dcp::YUV_TO_RGB_REC709, _pixel_format, false, false);
+ component<uint16_t> (0, this, yuv, other, start_tx, start_ty, start_ox, start_oy);
+ component<uint8_t> (1, this, yuv, other, start_tx, start_ty, start_ox, start_oy);
+ component<uint8_t> (2, this, yuv, other, start_tx, start_ty, start_ox, start_oy);
+ break;
+ }
default:
throw PixelFormatError ("alpha_blend()", _pixel_format);
}