summaryrefslogtreecommitdiff
path: root/src
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
parenta7f27819cbb7db110587603c2d0717dd4c018c11 (diff)
Try again to sort out image alignment a bit.
Diffstat (limited to 'src')
-rw-r--r--src/lib/dcp_video_frame.cc6
-rw-r--r--src/lib/image.cc89
-rw-r--r--src/lib/image.h31
-rw-r--r--src/lib/imagemagick_decoder.cc2
-rw-r--r--src/lib/matcher.cc2
-rw-r--r--src/lib/server.cc4
-rw-r--r--src/lib/subtitle.cc2
-rw-r--r--src/lib/util.cc3
-rw-r--r--src/lib/video_decoder.cc2
-rw-r--r--src/wx/film_viewer.cc5
10 files changed, 50 insertions, 96 deletions
diff --git a/src/lib/dcp_video_frame.cc b/src/lib/dcp_video_frame.cc
index 996aff33f..7099f73de 100644
--- a/src/lib/dcp_video_frame.cc
+++ b/src/lib/dcp_video_frame.cc
@@ -154,10 +154,10 @@ shared_ptr<EncodedData>
DCPVideoFrame::encode_locally ()
{
if (!_post_process.empty ()) {
- _input = _input->post_process (_post_process);
+ _input = _input->post_process (_post_process, true);
}
- shared_ptr<Image> prepared = _input->scale_and_convert_to_rgb (_out_size, _padding, _scaler);
+ shared_ptr<Image> prepared = _input->scale_and_convert_to_rgb (_out_size, _padding, _scaler, true);
if (_subtitle) {
Rect tx = subtitle_transformed_area (
@@ -166,7 +166,7 @@ DCPVideoFrame::encode_locally ()
_subtitle->area(), _subtitle_offset, _subtitle_scale
);
- shared_ptr<Image> im = _subtitle->image()->scale (tx.size(), _scaler);
+ shared_ptr<Image> im = _subtitle->image()->scale (tx.size(), _scaler, true);
prepared->alpha_blend (im, tx.position());
}
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);
diff --git a/src/lib/image.h b/src/lib/image.h
index 0cd38da11..22758a6cf 100644
--- a/src/lib/image.h
+++ b/src/lib/image.h
@@ -69,9 +69,10 @@ public:
int components () const;
int lines (int) const;
- boost::shared_ptr<Image> scale_and_convert_to_rgb (Size, int, Scaler const *) const;
- boost::shared_ptr<Image> scale (Size, Scaler const *) const;
- boost::shared_ptr<Image> post_process (std::string) const;
+
+ boost::shared_ptr<Image> scale_and_convert_to_rgb (Size out_size, int padding, Scaler const * scaler, bool aligned) const;
+ boost::shared_ptr<Image> scale (Size, Scaler const *, bool aligned) const;
+ boost::shared_ptr<Image> post_process (std::string, bool aligned) const;
void alpha_blend (boost::shared_ptr<const Image> image, Position pos);
void make_black ();
@@ -111,7 +112,8 @@ private:
class SimpleImage : public Image
{
public:
- SimpleImage (AVPixelFormat, Size, boost::function<int (int, int const *)> rounder);
+ SimpleImage (AVPixelFormat, Size, bool);
+ SimpleImage (boost::shared_ptr<const Image>, bool aligned);
~SimpleImage ();
uint8_t ** data () const;
@@ -125,26 +127,7 @@ private:
uint8_t** _data; ///< array of pointers to components
int* _line_size; ///< array of sizes of the data in each line, in pixels (without any alignment padding bytes)
int* _stride; ///< array of strides for each line (including any alignment padding bytes)
-};
-
-/** @class AlignedImage
- * @brief An image whose pixel data is padded so that rows always start on 32-byte boundaries.
- */
-class AlignedImage : public SimpleImage
-{
-public:
- AlignedImage (AVPixelFormat, Size);
- AlignedImage (boost::shared_ptr<const Image>);
-};
-
-/** @class CompactImage
- * @brief An image whose pixel data is not padded, so rows may start at any pixel alignment.
- */
-class CompactImage : public SimpleImage
-{
-public:
- CompactImage (AVPixelFormat, Size);
- CompactImage (boost::shared_ptr<const Image>);
+ bool _aligned;
};
class RGBPlusAlphaImage : public SimpleImage
diff --git a/src/lib/imagemagick_decoder.cc b/src/lib/imagemagick_decoder.cc
index c0db08893..33bc5ee7b 100644
--- a/src/lib/imagemagick_decoder.cc
+++ b/src/lib/imagemagick_decoder.cc
@@ -78,7 +78,7 @@ ImageMagickDecoder::pass ()
Magick::Image* magick_image = new Magick::Image (_film->content_path ());
Size size = native_size ();
- shared_ptr<CompactImage> image (new CompactImage (PIX_FMT_RGB24, size));
+ shared_ptr<SimpleImage> image (new SimpleImage (PIX_FMT_RGB24, size, false));
uint8_t* p = image->data()[0];
for (int y = 0; y < size.height; ++y) {
diff --git a/src/lib/matcher.cc b/src/lib/matcher.cc
index 7b4434539..2dd36c11e 100644
--- a/src/lib/matcher.cc
+++ b/src/lib/matcher.cc
@@ -81,7 +81,7 @@ Matcher::process_end ()
_log->log (String::compose ("Emitting %1 frames of black video", black_video_frames));
- shared_ptr<Image> black (new CompactImage (_pixel_format.get(), _size.get()));
+ shared_ptr<Image> black (new SimpleImage (_pixel_format.get(), _size.get(), false));
black->make_black ();
for (int i = 0; i < black_video_frames; ++i) {
Video (black, shared_ptr<Subtitle>());
diff --git a/src/lib/server.cc b/src/lib/server.cc
index 38f9834ff..bea75cff8 100644
--- a/src/lib/server.cc
+++ b/src/lib/server.cc
@@ -113,13 +113,13 @@ Server::process (shared_ptr<Socket> socket)
PixelFormat pixel_format = (PixelFormat) pixel_format_int;
Scaler const * scaler = Scaler::from_id (scaler_id);
- shared_ptr<Image> image (new AlignedImage (pixel_format, in_size));
+ shared_ptr<Image> image (new SimpleImage (pixel_format, in_size, true));
image->read_from_socket (socket);
shared_ptr<Subtitle> sub;
if (subtitle_size.width && subtitle_size.height) {
- shared_ptr<Image> subtitle_image (new AlignedImage (PIX_FMT_RGBA, subtitle_size));
+ shared_ptr<Image> subtitle_image (new SimpleImage (PIX_FMT_RGBA, subtitle_size, true));
subtitle_image->read_from_socket (socket);
sub.reset (new Subtitle (subtitle_position, subtitle_image));
}
diff --git a/src/lib/subtitle.cc b/src/lib/subtitle.cc
index 282a2cde1..4b7f81947 100644
--- a/src/lib/subtitle.cc
+++ b/src/lib/subtitle.cc
@@ -54,7 +54,7 @@ TimedSubtitle::TimedSubtitle (AVSubtitle const & sub, double c)
throw DecodeError ("non-bitmap subtitles not yet supported");
}
- shared_ptr<Image> image (new AlignedImage (PIX_FMT_RGBA, Size (rect->w, rect->h)));
+ shared_ptr<Image> image (new SimpleImage (PIX_FMT_RGBA, Size (rect->w, rect->h), true));
/* Start of the first line in the subtitle */
uint8_t* sub_p = rect->pict.data[0];
diff --git a/src/lib/util.cc b/src/lib/util.cc
index b69581eba..66eaea39e 100644
--- a/src/lib/util.cc
+++ b/src/lib/util.cc
@@ -576,7 +576,8 @@ Rect::intersection (Rect const & other) const
}
/** Round a number up to the nearest multiple of another number.
- * @param a Number to round.
+ * @param c Index.
+ * @param s Array of numbers to round, indexed by c.
* @param t Multiple to round to.
* @return Rounded number.
*/
diff --git a/src/lib/video_decoder.cc b/src/lib/video_decoder.cc
index cb55b4d18..c3be2a174 100644
--- a/src/lib/video_decoder.cc
+++ b/src/lib/video_decoder.cc
@@ -56,7 +56,7 @@ void
VideoDecoder::repeat_last_video ()
{
if (!_last_image) {
- _last_image.reset (new CompactImage (pixel_format(), native_size()));
+ _last_image.reset (new SimpleImage (pixel_format(), native_size(), false));
_last_image->make_black ();
}
diff --git a/src/wx/film_viewer.cc b/src/wx/film_viewer.cc
index 15a2c4034..78b104d20 100644
--- a/src/wx/film_viewer.cc
+++ b/src/wx/film_viewer.cc
@@ -235,7 +235,8 @@ FilmViewer::raw_to_display ()
return;
}
- _display_frame = _raw_frame->scale_and_convert_to_rgb (Size (_out_width, _out_height), 0, _film->scaler());
+ /* Get a compacted image as we have to feed it to wxWidgets */
+ _display_frame = _raw_frame->scale_and_convert_to_rgb (Size (_out_width, _out_height), 0, _film->scaler(), false);
if (_raw_sub) {
Rect tx = subtitle_transformed_area (
@@ -244,7 +245,7 @@ FilmViewer::raw_to_display ()
_raw_sub->area(), _film->subtitle_offset(), _film->subtitle_scale()
);
- _display_sub.reset (new RGBPlusAlphaImage (_raw_sub->image()->scale (tx.size(), _film->scaler ())));
+ _display_sub.reset (new RGBPlusAlphaImage (_raw_sub->image()->scale (tx.size(), _film->scaler(), false)));
_display_sub_position = tx.position();
} else {
_display_sub.reset ();