}
shared_ptr<Image>
-Image::scale (libdcp::Size out_size, Scaler const * scaler, bool result_aligned) const
+Image::scale (libdcp::Size out_size, Scaler const * scaler, AVPixelFormat result_format, bool result_aligned) const
{
assert (scaler);
/* Empirical testing suggests that sws_scale() will crash if
*/
assert (aligned ());
- shared_ptr<Image> scaled (new Image (pixel_format(), out_size, result_aligned));
+ shared_ptr<Image> scaled (new Image (result_format, out_size, result_aligned));
struct SwsContext* scale_context = sws_getContext (
size().width, size().height, pixel_format(),
- out_size.width, out_size.height, pixel_format(),
+ out_size.width, out_size.height, result_format,
scaler->ffmpeg_id (), 0, 0, 0
);
return scaled;
}
-/** Scale this image to a given size and convert it to RGB.
- * @param out_size Output image size in pixels.
- * @param scaler Scaler to use.
- */
-shared_ptr<Image>
-Image::scale_and_convert_to_rgb (libdcp::Size out_size, Scaler const * scaler, bool result_aligned) const
-{
- assert (scaler);
- /* Empirical testing suggests that sws_scale() will crash if
- the input image is not aligned.
- */
- assert (aligned ());
-
- shared_ptr<Image> rgb (new Image (PIX_FMT_RGB24, out_size, result_aligned));
-
- struct SwsContext* scale_context = sws_getContext (
- size().width, size().height, pixel_format(),
- out_size.width, out_size.height, PIX_FMT_RGB24,
- scaler->ffmpeg_id (), 0, 0, 0
- );
-
- /* Scale and convert to RGB from whatever its currently in (which may be RGB) */
- sws_scale (
- scale_context,
- data(), stride(),
- 0, size().height,
- rgb->data(), rgb->stride()
- );
-
- sws_freeContext (scale_context);
-
- return rgb;
-}
-
/** Run a FFmpeg post-process on this image and return the processed version.
* @param pp Flags for the required set of post processes.
* @return Post-processed image.
int line_factor (int) const;
int lines (int) const;
- boost::shared_ptr<Image> scale_and_convert_to_rgb (libdcp::Size, Scaler const *, bool) const;
- boost::shared_ptr<Image> scale (libdcp::Size, Scaler const *, bool aligned) const;
+ boost::shared_ptr<Image> scale (libdcp::Size, Scaler const *, AVPixelFormat, bool aligned) const;
boost::shared_ptr<Image> post_process (std::string, bool aligned) const;
void alpha_blend (boost::shared_ptr<const Image> image, Position<int> pos);
void copy (boost::shared_ptr<const Image> image, Position<int> pos);
libdcp::Size const image_size = content->ratio()->size (_video_container_size);
- work_image = work_image->scale_and_convert_to_rgb (image_size, _film->scaler(), true);
+ work_image = work_image->scale (image_size, _film->scaler(), PIX_FMT_RGB24, true);
Time time = content->position() + relative_time - content->trim_start ();
_out_subtitle.position.x = rint (_video_container_size.width * (in_rect.x + (in_rect.width * (1 - sc->subtitle_scale ()) / 2)));
_out_subtitle.position.y = rint (_video_container_size.height * (in_rect.y + (in_rect.height * (1 - sc->subtitle_scale ()) / 2)));
- _out_subtitle.image = _in_subtitle.image->scale (libdcp::Size (scaled_size.width, scaled_size.height), Scaler::from_id ("bicubic"), true);
+ _out_subtitle.image = _in_subtitle.image->scale (
+ scaled_size,
+ Scaler::from_id ("bicubic"),
+ _in_subtitle.image->pixel_format (),
+ true
+ );
_out_subtitle.from = _in_subtitle.from + piece->content->position ();
_out_subtitle.to = _in_subtitle.to + piece->content->position ();
}
image = image->crop (crop, true);
/* Convert it back to RGB to make comparison to black easier */
- image = image->scale_and_convert_to_rgb (image->size(), Scaler::from_id ("bicubic"), true);
+ image = image->scale (image->size(), Scaler::from_id ("bicubic"), PIX_FMT_RGB24, true);
/* Check that its still black after the crop */
uint8_t* p = image->data()[0];
for (list<AVPixelFormat>::const_iterator i = pix_fmts.begin(); i != pix_fmts.end(); ++i) {
boost::shared_ptr<Image> foo (new Image (*i, in_size, true));
foo->make_black ();
- boost::shared_ptr<Image> bar = foo->scale_and_convert_to_rgb (out_size, Scaler::from_id ("bicubic"), true);
+ boost::shared_ptr<Image> bar = foo->scale (out_size, Scaler::from_id ("bicubic"), PIX_FMT_RGB24, true);
uint8_t* p = bar->data()[0];
for (int y = 0; y < bar->size().height; ++y) {