summaryrefslogtreecommitdiff
path: root/src/lib/image.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2012-12-16 23:43:22 +0000
committerCarl Hetherington <cth@carlh.net>2012-12-16 23:43:22 +0000
commit4e79cb88c22a7b2d52381f0a1a1ffdb5015fa617 (patch)
tree8f199cd05396353a263e156448ca2ef1bf30eaa6 /src/lib/image.cc
parenta7f27819cbb7db110587603c2d0717dd4c018c11 (diff)
Try again to sort out image alignment a bit.
Diffstat (limited to 'src/lib/image.cc')
-rw-r--r--src/lib/image.cc89
1 files changed, 29 insertions, 60 deletions
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>
-Image::scale (Size out_size, Scaler const * scaler) const
+Image::scale (Size out_size, Scaler const * scaler, bool aligned) const
{
assert (scaler);
- shared_ptr<Image> scaled (new AlignedImage (pixel_format(), out_size));
+ shared_ptr<Image> 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>
-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<Image> rgb (new CompactImage (PIX_FMT_RGB24, content_size));
+ shared_ptr<Image> 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<Image> padded_rgb (new AlignedImage (PIX_FMT_RGB24, out_size));
+ shared_ptr<Image> 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>
-Image::post_process (string pp) const
+Image::post_process (string pp, bool aligned) const
{
- shared_ptr<Image> out (new AlignedImage (pixel_format(), size ()));
+ shared_ptr<Image> 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> socket) const
* @param p Pixel format.
* @param s Size in pixels.
*/
-SimpleImage::SimpleImage (AVPixelFormat p, Size s, function<int (int, int const *)> 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<int (int, int const
}
for (int i = 0; i < components(); ++i) {
- _stride[i] = stride_computer (i, _line_size);
+ _stride[i] = stride_round_up (i, _line_size, _aligned ? 32 : 1);
_data[i] = (uint8_t *) av_malloc (_stride[i] * lines (i));
}
}
@@ -346,38 +347,8 @@ SimpleImage::~SimpleImage ()
av_free (_stride);
}
-uint8_t **
-SimpleImage::data () const
-{
- return _data;
-}
-
-int *
-SimpleImage::line_size () const
-{
- return _line_size;
-}
-
-int *
-SimpleImage::stride () const
-{
- return _stride;
-}
-
-Size
-SimpleImage::size () const
-{
- return _size;
-}
-
-AlignedImage::AlignedImage (AVPixelFormat f, Size s)
- : SimpleImage (f, s, boost::bind (stride_round_up, _1, _2, 32))
-{
-
-}
-
-AlignedImage::AlignedImage (shared_ptr<const Image> im)
- : SimpleImage (im->pixel_format(), im->size(), boost::bind (stride_round_up, _1, _2, 32))
+SimpleImage::SimpleImage (shared_ptr<const Image> im, bool aligned)
+ : Image (im->pixel_format())
{
assert (components() == im->components());
@@ -396,30 +367,28 @@ AlignedImage::AlignedImage (shared_ptr<const Image> 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<const Image> 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<const Image> 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);