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 (
_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());
}
}
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(),
* @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(),
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
* @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()) {
* @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;
}
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));
}
}
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());
}
}
-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)
}
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);
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 ();
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;
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
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) {
_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>());
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));
}
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];
}
/** 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.
*/
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 ();
}
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 (
_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 ();
BOOST_AUTO_TEST_CASE (client_server_test)
{
- shared_ptr<Image> image (new CompactImage (PIX_FMT_RGB24, Size (1998, 1080)));
+ shared_ptr<Image> image (new SimpleImage (PIX_FMT_RGB24, Size (1998, 1080), false));
uint8_t* p = image->data()[0];
for (int y = 0; y < 1080; ++y) {
}
}
- shared_ptr<Image> sub_image (new CompactImage (PIX_FMT_RGBA, Size (100, 200)));
+ shared_ptr<Image> sub_image (new SimpleImage (PIX_FMT_RGBA, Size (100, 200), false));
p = sub_image->data()[0];
for (int y = 0; y < 200; ++y) {
for (int x = 0; x < 100; ++x) {