diff options
| author | Carl Hetherington <cth@carlh.net> | 2021-12-18 23:34:26 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2021-12-23 12:59:56 +0100 |
| commit | c0733033923d369cce3d76b318e969bf89a130b9 (patch) | |
| tree | 3631101ddc1dfb2366e7c6ba3d1df38dc8b921cd /test | |
| parent | f09bbf9d037975b5a6113c4d5634c82625a51683 (diff) | |
Add image_as_jpeg()
Diffstat (limited to 'test')
| m--------- | test/data | 0 | ||||
| -rw-r--r-- | test/image_test.cc | 14 | ||||
| -rw-r--r-- | test/test.cc | 17 | ||||
| -rw-r--r-- | test/wscript | 2 |
4 files changed, 31 insertions, 2 deletions
diff --git a/test/data b/test/data -Subproject 49b6ee6d90d9fc543e829cbe9f071970965263a +Subproject 0a215a080a51c29a0712275ee4f97c66b5dfad1 diff --git a/test/image_test.cc b/test/image_test.cc index 18d96d4fc..8d934bdd6 100644 --- a/test/image_test.cc +++ b/test/image_test.cc @@ -30,6 +30,7 @@ #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" @@ -384,6 +385,19 @@ BOOST_AUTO_TEST_CASE (as_png_test) } +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) diff --git a/test/test.cc b/test/test.cc index 08b37bcb1..c225fc1d8 100644 --- a/test/test.cc +++ b/test/test.cc @@ -369,8 +369,10 @@ rms_error (boost::filesystem::path ref, boost::filesystem::path check) FFmpegImageProxy check_proxy (check); auto check_image = check_proxy.image(Image::Alignment::COMPACT).image; + BOOST_REQUIRE_EQUAL (ref_image->planes(), check_image->planes()); + BOOST_REQUIRE_EQUAL (ref_image->pixel_format(), check_image->pixel_format()); - AVPixelFormat const format = ref_image->pixel_format(); + auto const format = ref_image->pixel_format(); BOOST_REQUIRE (ref_image->size() == check_image->size()); int const width = ref_image->size().width; @@ -417,6 +419,19 @@ rms_error (boost::filesystem::path ref, boost::filesystem::path check) } break; } + case AV_PIX_FMT_YUVJ420P: + { + for (int c = 0; c < ref_image->planes(); ++c) { + for (int y = 0; y < height / ref_image->vertical_factor(c); ++y) { + auto p = ref_image->data()[c] + y * ref_image->stride()[c]; + auto q = check_image->data()[c] + y * check_image->stride()[c]; + for (int x = 0; x < ref_image->line_size()[c]; ++x) { + sum_square += pow((*p++ - *q++), 2); + } + } + } + break; + } default: BOOST_REQUIRE_MESSAGE (false, "unrecognised pixel format " << format); } diff --git a/test/wscript b/test/wscript index a5366b3ec..847cab390 100644 --- a/test/wscript +++ b/test/wscript @@ -34,7 +34,7 @@ def build(bld): obj = bld(features='cxx cxxprogram') obj.name = 'unit-tests' obj.uselib = 'BOOST_TEST BOOST_THREAD BOOST_FILESYSTEM BOOST_DATETIME SNDFILE SAMPLERATE DCP FONTCONFIG CAIROMM PANGOMM XMLPP ' - obj.uselib += 'AVFORMAT AVFILTER AVCODEC AVUTIL SWSCALE SWRESAMPLE POSTPROC CXML SUB GLIB CURL SSH XMLSEC BOOST_REGEX ICU NETTLE PNG ' + obj.uselib += 'AVFORMAT AVFILTER AVCODEC AVUTIL SWSCALE SWRESAMPLE POSTPROC CXML SUB GLIB CURL SSH XMLSEC BOOST_REGEX ICU NETTLE PNG JPEG ' obj.uselib += 'LEQM_NRT ZIP ' if bld.env.TARGET_WINDOWS: obj.uselib += 'WINSOCK2 DBGHELP SHLWAPI MSWSOCK BOOST_LOCALE ' |
