diff options
| author | Carl Hetherington <cth@carlh.net> | 2012-11-12 23:45:44 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2012-11-12 23:45:44 +0000 |
| commit | 5161626c3c28ba528511a8b211286a5e81a0f02a (patch) | |
| tree | 2690e09169d7d0e36167c842eb8260ae7a2cfe04 /src | |
| parent | c8b0b0f61a1188b3ce8010a65e4c617a0e66eaa1 (diff) | |
Untested; extend CompactImage to return a AVPicture.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/decoder.cc | 2 | ||||
| -rw-r--r-- | src/lib/decoder.h | 2 | ||||
| -rw-r--r-- | src/lib/filter_graph.cc | 2 | ||||
| -rw-r--r-- | src/lib/filter_graph.h | 2 | ||||
| -rw-r--r-- | src/lib/image.cc | 63 | ||||
| -rw-r--r-- | src/lib/image.h | 24 | ||||
| -rw-r--r-- | src/lib/imagemagick_decoder.cc | 4 | ||||
| -rw-r--r-- | src/lib/tiff_decoder.cc | 4 |
8 files changed, 25 insertions, 78 deletions
diff --git a/src/lib/decoder.cc b/src/lib/decoder.cc index 97f1bc92f..e91b5e19e 100644 --- a/src/lib/decoder.cc +++ b/src/lib/decoder.cc @@ -97,7 +97,7 @@ Decoder::process_audio (shared_ptr<AudioBuffers> audio) * @param frame to decode; caller manages memory. */ void -Decoder::process_video (AVFrame* frame) +Decoder::process_video (AVFrame const * frame) { shared_ptr<FilterGraph> graph; diff --git a/src/lib/decoder.h b/src/lib/decoder.h index 71dfed1e0..a458c348b 100644 --- a/src/lib/decoder.h +++ b/src/lib/decoder.h @@ -99,7 +99,7 @@ protected: virtual PixelFormat pixel_format () const = 0; - void process_video (AVFrame *); + void process_video (AVFrame const *); void process_audio (boost::shared_ptr<AudioBuffers>); void process_subtitle (boost::shared_ptr<TimedSubtitle>); void repeat_last_video (); diff --git a/src/lib/filter_graph.cc b/src/lib/filter_graph.cc index 1418384b8..72bb8deb7 100644 --- a/src/lib/filter_graph.cc +++ b/src/lib/filter_graph.cc @@ -134,7 +134,7 @@ FilterGraph::FilterGraph (shared_ptr<Film> film, Decoder* decoder, bool crop, Si } list<shared_ptr<Image> > -FilterGraph::process (AVFrame* frame) +FilterGraph::process (AVFrame const * frame) { list<shared_ptr<Image> > images; diff --git a/src/lib/filter_graph.h b/src/lib/filter_graph.h index 53908738e..4ff10dece 100644 --- a/src/lib/filter_graph.h +++ b/src/lib/filter_graph.h @@ -32,7 +32,7 @@ public: FilterGraph (boost::shared_ptr<Film> film, Decoder* decoder, bool crop, Size s, AVPixelFormat p); bool can_process (Size s, AVPixelFormat p) const; - std::list<boost::shared_ptr<Image> > process (AVFrame* frame); + std::list<boost::shared_ptr<Image> > process (AVFrame const * frame); private: AVFilterContext* _buffer_src_context; diff --git a/src/lib/image.cc b/src/lib/image.cc index c8303115b..05270954d 100644 --- a/src/lib/image.cc +++ b/src/lib/image.cc @@ -379,7 +379,7 @@ AlignedImage::AlignedImage (AVPixelFormat f, Size s) CompactImage::CompactImage (AVPixelFormat f, Size s) : SimpleImage (f, s, boost::bind (round_up, _1, 1)) { - + setup_picture (); } CompactImage::CompactImage (shared_ptr<Image> im) @@ -400,6 +400,17 @@ CompactImage::CompactImage (shared_ptr<Image> im) o += im->stride()[c]; } } + + setup_picture (); +} + +void +CompactImage::setup_picture () +{ + for (int c = 0; c < components(); ++c) { + _picture.data[c] = data()[c]; + _picture.linesize[c] = line_size()[c]; + } } FilterBufferImage::FilterBufferImage (AVPixelFormat p, AVFilterBufferRef* b) @@ -439,53 +450,3 @@ FilterBufferImage::size () const return Size (_buffer->video->w, _buffer->video->h); } -/** XXX: this could be generalised to use any format, but I don't - * understand how avpicture_fill is supposed to be called with - * multi-planar images. - */ -RGBFrameImage::RGBFrameImage (Size s) - : Image (PIX_FMT_RGB24) - , _size (s) -{ - _frame = avcodec_alloc_frame (); - if (_frame == 0) { - throw EncodeError ("could not allocate frame"); - } - - _data = (uint8_t *) av_malloc (size().width * size().height * 3); - avpicture_fill ((AVPicture *) _frame, _data, PIX_FMT_RGB24, size().width, size().height); - _frame->width = size().width; - _frame->height = size().height; - _frame->format = PIX_FMT_RGB24; -} - -RGBFrameImage::~RGBFrameImage () -{ - av_free (_data); - av_free (_frame); -} - -uint8_t ** -RGBFrameImage::data () const -{ - return _frame->data; -} - -int * -RGBFrameImage::line_size () const -{ - return _frame->linesize; -} - -int * -RGBFrameImage::stride () const -{ - /* XXX? */ - return line_size (); -} - -Size -RGBFrameImage::size () const -{ - return _size; -} diff --git a/src/lib/image.h b/src/lib/image.h index b2b987279..bb4a32319 100644 --- a/src/lib/image.h +++ b/src/lib/image.h @@ -138,29 +138,15 @@ class CompactImage : public SimpleImage public: CompactImage (AVPixelFormat, Size); CompactImage (boost::shared_ptr<Image>); -}; - -/** @class RGBFrameImage - * @brief An RGB image that is held within an AVFrame. - */ -class RGBFrameImage : public Image -{ -public: - RGBFrameImage (Size); - ~RGBFrameImage (); - uint8_t ** data () const; - int * line_size () const; - int * stride () const; - Size size () const; - AVFrame * frame () const { - return _frame; + AVPicture const * picture () const { + return &_picture; } private: - Size _size; - AVFrame* _frame; - uint8_t* _data; + void setup_picture (); + + AVPicture _picture; }; #endif diff --git a/src/lib/imagemagick_decoder.cc b/src/lib/imagemagick_decoder.cc index cc2fd9d23..fd4e5b18d 100644 --- a/src/lib/imagemagick_decoder.cc +++ b/src/lib/imagemagick_decoder.cc @@ -50,7 +50,7 @@ ImageMagickDecoder::pass () } Size size = native_size (); - RGBFrameImage image (size); + CompactImage image (PIX_FMT_RGB24, size); uint8_t* p = image.data()[0]; for (int y = 0; y < size.height; ++y) { @@ -63,7 +63,7 @@ ImageMagickDecoder::pass () } - process_video (image.frame ()); + process_video ((AVFrame const *) image.picture()); _done = true; return false; diff --git a/src/lib/tiff_decoder.cc b/src/lib/tiff_decoder.cc index c92e080d7..7e9bda139 100644 --- a/src/lib/tiff_decoder.cc +++ b/src/lib/tiff_decoder.cc @@ -147,7 +147,7 @@ TIFFDecoder::pass () throw DecodeError ("could not read TIFF data"); } - RGBFrameImage image (Size (width, height)); + CompactImage image (PIX_FMT_RGB24, Size (width, height)); uint8_t* p = image.data()[0]; for (uint32_t y = 0; y < height; ++y) { @@ -162,7 +162,7 @@ TIFFDecoder::pass () _TIFFfree (raster); TIFFClose (t); - process_video (image.frame ()); + process_video ((AVFrame const *) image.picture ()); ++_iter; return false; |
