Check that the image used to make a Cairo::ImageSurface is the right alignment and...
authorCarl Hetherington <cth@carlh.net>
Thu, 23 Sep 2021 21:54:13 +0000 (23:54 +0200)
committerCarl Hetherington <cth@carlh.net>
Mon, 27 Sep 2021 11:41:46 +0000 (13:41 +0200)
src/lib/render_text.cc

index 76c0fb79d0917ca0b81ae95d3113363381a44586..94b41285627270868d97a95792659445cae102ce 100644 (file)
@@ -93,7 +93,9 @@ set_source_rgba (Cairo::RefPtr<Cairo::Context> context, dcp::Colour colour, floa
 static shared_ptr<Image>
 create_image (dcp::Size size)
 {
-       /* FFmpeg BGRA means first byte blue, second byte green, third byte red, fourth byte alpha */
+       /* FFmpeg BGRA means first byte blue, second byte green, third byte red, fourth byte alpha.
+        * This must be COMPACT as we're using it with Cairo::ImageSurface::create
+        */
        auto image = make_shared<Image>(AV_PIX_FMT_BGRA, size, Image::Alignment::COMPACT);
        image->make_black ();
        return image;
@@ -103,6 +105,11 @@ create_image (dcp::Size size)
 static Cairo::RefPtr<Cairo::ImageSurface>
 create_surface (shared_ptr<Image> image)
 {
+       /* XXX: I don't think it's guaranteed that format_stride_for_width will return a stride without any padding,
+        * so it's lucky that this works.
+        */
+       DCPOMATIC_ASSERT (image->alignment() == Image::Alignment::COMPACT);
+       DCPOMATIC_ASSERT (image->pixel_format() == AV_PIX_FMT_BGRA);
        return Cairo::ImageSurface::create (
                image->data()[0],
                Cairo::FORMAT_ARGB32,