-FilterBufferImage::FilterBufferImage (AVPixelFormat p, AVFilterBufferRef* b)
- : Image (p)
- , _buffer (b)
-{
- _line_size = (int *) av_malloc (4 * sizeof (int));
- _line_size[0] = _line_size[1] = _line_size[2] = _line_size[3] = 0;
-
- for (int i = 0; i < components(); ++i) {
- _line_size[i] = size().width * bytes_per_pixel(i);
- }
-}
-
-FilterBufferImage::~FilterBufferImage ()
-{
- avfilter_unref_buffer (_buffer);
- av_free (_line_size);
-}
-
-uint8_t **
-FilterBufferImage::data () const
-{
- return _buffer->data;
-}
-
-int *
-FilterBufferImage::line_size () const
-{
- return _line_size;
-}
-
-int *
-FilterBufferImage::stride () const
-{
- /* I've seen images where the _buffer->linesize is larger than the width
- (by a small amount), suggesting that _buffer->linesize is what we call
- stride. But I'm not sure.
- */
- return _buffer->linesize;
-}
-
-libdcp::Size
-FilterBufferImage::size () const
-{
- return libdcp::Size (_buffer->video->w, _buffer->video->h);
-}
-
-bool
-FilterBufferImage::aligned () const
-{
- /* XXX? */
- return true;
-}
-
-RGBPlusAlphaImage::RGBPlusAlphaImage (shared_ptr<const Image> im)
- : SimpleImage (im->pixel_format(), im->size(), false)
-{
- assert (im->pixel_format() == PIX_FMT_RGBA);
-
- _alpha = (uint8_t *) av_malloc (im->size().width * im->size().height);
-
- uint8_t* in = im->data()[0];
- uint8_t* out = data()[0];
- uint8_t* out_alpha = _alpha;
- for (int y = 0; y < im->size().height; ++y) {
- uint8_t* in_r = in;
- for (int x = 0; x < im->size().width; ++x) {
- *out++ = *in_r++;
- *out++ = *in_r++;
- *out++ = *in_r++;
- *out_alpha++ = *in_r++;
- }
-
- in += im->stride()[0];
- }
-}
-
-RGBPlusAlphaImage::~RGBPlusAlphaImage ()
-{
- av_free (_alpha);
-}
-