-FrameImage::FrameImage (AVFrame* frame)
- : Image (static_cast<AVPixelFormat> (frame->format))
- , _frame (frame)
-{
- _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);
- }
-}
-
-FrameImage::~FrameImage ()
-{
- av_frame_free (&_frame);
- av_free (_line_size);
-}
-
-uint8_t **
-FrameImage::data () const
-{
- return _frame->data;
-}
-
-int *
-FrameImage::line_size () const
-{
- return _line_size;
-}
-
-int *
-FrameImage::stride () const
-{
- /* AVFrame's `linesize' is what we call `stride' */
- return _frame->linesize;
-}
-
-libdcp::Size
-FrameImage::size () const
-{
- return libdcp::Size (_frame->width, _frame->height);
-}
-
-bool
-FrameImage::aligned () const
-{
- 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);
-}
-