From 4e79cb88c22a7b2d52381f0a1a1ffdb5015fa617 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 16 Dec 2012 23:43:22 +0000 Subject: Try again to sort out image alignment a bit. --- src/lib/image.cc | 89 ++++++++++++++++++-------------------------------------- 1 file changed, 29 insertions(+), 60 deletions(-) (limited to 'src/lib/image.cc') diff --git a/src/lib/image.cc b/src/lib/image.cc index 2e4c18323..fb72d1aee 100644 --- a/src/lib/image.cc +++ b/src/lib/image.cc @@ -89,11 +89,11 @@ Image::components () const } shared_ptr -Image::scale (Size out_size, Scaler const * scaler) const +Image::scale (Size out_size, Scaler const * scaler, bool aligned) const { assert (scaler); - shared_ptr scaled (new AlignedImage (pixel_format(), out_size)); + shared_ptr scaled (new SimpleImage (pixel_format(), out_size, aligned)); struct SwsContext* scale_context = sws_getContext ( size().width, size().height, pixel_format(), @@ -118,14 +118,14 @@ Image::scale (Size out_size, Scaler const * scaler) const * @param scaler Scaler to use. */ shared_ptr -Image::scale_and_convert_to_rgb (Size out_size, int padding, Scaler const * scaler) const +Image::scale_and_convert_to_rgb (Size out_size, int padding, Scaler const * scaler, bool aligned) const { assert (scaler); Size content_size = out_size; content_size.width -= (padding * 2); - shared_ptr rgb (new CompactImage (PIX_FMT_RGB24, content_size)); + shared_ptr rgb (new SimpleImage (PIX_FMT_RGB24, content_size, aligned)); struct SwsContext* scale_context = sws_getContext ( size().width, size().height, pixel_format(), @@ -146,7 +146,7 @@ Image::scale_and_convert_to_rgb (Size out_size, int padding, Scaler const * scal scheme of things. */ if (padding > 0) { - shared_ptr padded_rgb (new AlignedImage (PIX_FMT_RGB24, out_size)); + shared_ptr padded_rgb (new SimpleImage (PIX_FMT_RGB24, out_size, aligned)); padded_rgb->make_black (); /* XXX: we are cheating a bit here; we know the frame is RGB so we can @@ -173,9 +173,9 @@ Image::scale_and_convert_to_rgb (Size out_size, int padding, Scaler const * scal * @return Post-processed image. */ shared_ptr -Image::post_process (string pp) const +Image::post_process (string pp, bool aligned) const { - shared_ptr out (new AlignedImage (pixel_format(), size ())); + shared_ptr out (new SimpleImage (pixel_format(), size (), aligned)); int pp_format = 0; switch (pixel_format()) { @@ -293,9 +293,10 @@ Image::write_to_socket (shared_ptr socket) const * @param p Pixel format. * @param s Size in pixels. */ -SimpleImage::SimpleImage (AVPixelFormat p, Size s, function stride_computer) +SimpleImage::SimpleImage (AVPixelFormat p, Size s, bool aligned) : Image (p) , _size (s) + , _aligned (aligned) { _data = (uint8_t **) av_malloc (4 * sizeof (uint8_t *)); _data[0] = _data[1] = _data[2] = _data[3] = 0; @@ -329,7 +330,7 @@ SimpleImage::SimpleImage (AVPixelFormat p, Size s, function im) - : SimpleImage (im->pixel_format(), im->size(), boost::bind (stride_round_up, _1, _2, 32)) +SimpleImage::SimpleImage (shared_ptr im, bool aligned) + : Image (im->pixel_format()) { assert (components() == im->components()); @@ -396,30 +367,28 @@ AlignedImage::AlignedImage (shared_ptr im) } } -CompactImage::CompactImage (AVPixelFormat f, Size s) - : SimpleImage (f, s, boost::bind (stride_round_up, _1, _2, 1)) +uint8_t ** +SimpleImage::data () const { - + return _data; } -CompactImage::CompactImage (shared_ptr im) - : SimpleImage (im->pixel_format(), im->size(), boost::bind (stride_round_up, _1, _2, 1)) +int * +SimpleImage::line_size () const { - assert (components() == im->components()); - - for (int c = 0; c < components(); ++c) { + return _line_size; +} - assert (line_size()[c] == im->line_size()[c]); +int * +SimpleImage::stride () const +{ + return _stride; +} - uint8_t* t = data()[c]; - uint8_t* o = im->data()[c]; - - for (int y = 0; y < lines(c); ++y) { - memcpy (t, o, line_size()[c]); - t += stride()[c]; - o += im->stride()[c]; - } - } +Size +SimpleImage::size () const +{ + return _size; } FilterBufferImage::FilterBufferImage (AVPixelFormat p, AVFilterBufferRef* b) @@ -460,7 +429,7 @@ FilterBufferImage::size () const } RGBPlusAlphaImage::RGBPlusAlphaImage (shared_ptr im) - : SimpleImage (im->pixel_format(), im->size(), boost::bind (stride_round_up, _1, _2, 1)) + : SimpleImage (im->pixel_format(), im->size(), false) { assert (im->pixel_format() == PIX_FMT_RGBA); -- cgit v1.2.3