Cleanup: use some more make_shared.
[dcpomatic.git] / test / image_test.cc
index 7369bd24feac9ec03e4a21d2fb86aaa8bef7389d..8d934bdd62fd429b77e454daf4fcc7917b7e1676 100644 (file)
@@ -30,6 +30,8 @@
 #include "lib/image.h"
 #include "lib/image_content.h"
 #include "lib/image_decoder.h"
+#include "lib/image_jpeg.h"
+#include "lib/image_png.h"
 #include "lib/ffmpeg_image_proxy.h"
 #include "test.h"
 #include <boost/test/unit_test.hpp>
@@ -375,14 +377,27 @@ BOOST_AUTO_TEST_CASE (as_png_test)
        auto proxy = make_shared<FFmpegImageProxy>("test/data/3d_test/000001.png");
        auto image_rgb = proxy->image(Image::Alignment::PADDED).image;
        auto image_bgr = image_rgb->convert_pixel_format(dcp::YUVToRGB::REC709, AV_PIX_FMT_BGRA, Image::Alignment::PADDED, false);
-       image_rgb->as_png().write ("build/test/as_png_rgb.png");
-       image_bgr->as_png().write ("build/test/as_png_bgr.png");
+       image_as_png(image_rgb).write ("build/test/as_png_rgb.png");
+       image_as_png(image_bgr).write ("build/test/as_png_bgr.png");
 
        check_image ("test/data/3d_test/000001.png", "build/test/as_png_rgb.png");
        check_image ("test/data/3d_test/000001.png", "build/test/as_png_bgr.png");
 }
 
 
+BOOST_AUTO_TEST_CASE (as_jpeg_test)
+{
+       auto proxy = make_shared<FFmpegImageProxy>("test/data/3d_test/000001.png");
+       auto image_rgb = proxy->image(Image::Alignment::PADDED).image;
+       auto image_bgr = image_rgb->convert_pixel_format(dcp::YUVToRGB::REC709, AV_PIX_FMT_BGRA, Image::Alignment::PADDED, false);
+       image_as_jpeg(image_rgb, 60).write("build/test/as_jpeg_rgb.jpeg");
+       image_as_jpeg(image_bgr, 60).write("build/test/as_jpeg_bgr.jpeg");
+
+       check_image ("test/data/as_jpeg_rgb.jpeg", "build/test/as_jpeg_rgb.jpeg");
+       check_image ("test/data/as_jpeg_bgr.jpeg", "build/test/as_jpeg_bgr.jpeg");
+}
+
+
 /* Very dumb test to fade black to make sure it stays black */
 static void
 fade_test_format_black (AVPixelFormat f, string name)
@@ -391,7 +406,7 @@ fade_test_format_black (AVPixelFormat f, string name)
        yuv.make_black ();
        yuv.fade (0);
        string const filename = "fade_test_black_" + name + ".png";
-       yuv.convert_pixel_format(dcp::YUVToRGB::REC709, AV_PIX_FMT_RGBA, Image::Alignment::PADDED, false)->as_png().write("build/test/" + filename);
+       image_as_png(yuv.convert_pixel_format(dcp::YUVToRGB::REC709, AV_PIX_FMT_RGBA, Image::Alignment::PADDED, false)).write("build/test/" + filename);
        check_image ("test/data/" + filename, "build/test/" + filename);
 }
 
@@ -404,7 +419,7 @@ fade_test_format_red (AVPixelFormat f, float amount, string name)
        auto red = proxy->image(Image::Alignment::PADDED).image->convert_pixel_format(dcp::YUVToRGB::REC709, f, Image::Alignment::PADDED, false);
        red->fade (amount);
        string const filename = "fade_test_red_" + name + ".png";
-       red->convert_pixel_format(dcp::YUVToRGB::REC709, AV_PIX_FMT_RGBA, Image::Alignment::PADDED, false)->as_png().write("build/test/" + filename);
+       image_as_png(red->convert_pixel_format(dcp::YUVToRGB::REC709, AV_PIX_FMT_RGBA, Image::Alignment::PADDED, false)).write("build/test/" + filename);
        check_image ("test/data/" + filename, "build/test/" + filename);
 }