ed644ce3c2a1193b97766c5274d643076a177aa5
[dcpomatic.git] / test / image_test.cc
1 /*
2     Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21
22 /** @file  test/image_test.cc
23  *  @brief Test Image class.
24  *  @ingroup selfcontained
25  *  @see test/pixel_formats_test.cc
26  */
27
28
29 #include "lib/compose.hpp"
30 #include "lib/image.h"
31 #include "lib/ffmpeg_image_proxy.h"
32 #include "test.h"
33 #include <boost/test/unit_test.hpp>
34 #include <iostream>
35
36
37 using std::cout;
38 using std::list;
39 using std::make_shared;
40 using std::shared_ptr;
41 using std::string;
42
43
44 BOOST_AUTO_TEST_CASE (aligned_image_test)
45 {
46         auto s = new Image (AV_PIX_FMT_RGB24, dcp::Size (50, 50), true);
47         BOOST_CHECK_EQUAL (s->planes(), 1);
48         /* 192 is 150 aligned to the nearest 64 bytes */
49         BOOST_CHECK_EQUAL (s->stride()[0], 192);
50         BOOST_CHECK_EQUAL (s->line_size()[0], 150);
51         BOOST_CHECK (s->data()[0]);
52         BOOST_CHECK (!s->data()[1]);
53         BOOST_CHECK (!s->data()[2]);
54         BOOST_CHECK (!s->data()[3]);
55
56         /* copy constructor */
57         auto t = new Image (*s);
58         BOOST_CHECK_EQUAL (t->planes(), 1);
59         BOOST_CHECK_EQUAL (t->stride()[0], 192);
60         BOOST_CHECK_EQUAL (t->line_size()[0], 150);
61         BOOST_CHECK (t->data()[0]);
62         BOOST_CHECK (!t->data()[1]);
63         BOOST_CHECK (!t->data()[2]);
64         BOOST_CHECK (!t->data()[3]);
65         BOOST_CHECK (t->data() != s->data());
66         BOOST_CHECK (t->data()[0] != s->data()[0]);
67         BOOST_CHECK (t->line_size() != s->line_size());
68         BOOST_CHECK_EQUAL (t->line_size()[0], s->line_size()[0]);
69         BOOST_CHECK (t->stride() != s->stride());
70         BOOST_CHECK_EQUAL (t->stride()[0], s->stride()[0]);
71
72         /* assignment operator */
73         auto u = new Image (AV_PIX_FMT_YUV422P, dcp::Size (150, 150), false);
74         *u = *s;
75         BOOST_CHECK_EQUAL (u->planes(), 1);
76         BOOST_CHECK_EQUAL (u->stride()[0], 192);
77         BOOST_CHECK_EQUAL (u->line_size()[0], 150);
78         BOOST_CHECK (u->data()[0]);
79         BOOST_CHECK (!u->data()[1]);
80         BOOST_CHECK (!u->data()[2]);
81         BOOST_CHECK (!u->data()[3]);
82         BOOST_CHECK (u->data() != s->data());
83         BOOST_CHECK (u->data()[0] != s->data()[0]);
84         BOOST_CHECK (u->line_size() != s->line_size());
85         BOOST_CHECK_EQUAL (u->line_size()[0], s->line_size()[0]);
86         BOOST_CHECK (u->stride() != s->stride());
87         BOOST_CHECK_EQUAL (u->stride()[0], s->stride()[0]);
88
89         delete s;
90         delete t;
91         delete u;
92 }
93
94
95 BOOST_AUTO_TEST_CASE (compact_image_test)
96 {
97         auto s = new Image (AV_PIX_FMT_RGB24, dcp::Size (50, 50), false);
98         BOOST_CHECK_EQUAL (s->planes(), 1);
99         BOOST_CHECK_EQUAL (s->stride()[0], 50 * 3);
100         BOOST_CHECK_EQUAL (s->line_size()[0], 50 * 3);
101         BOOST_CHECK (s->data()[0]);
102         BOOST_CHECK (!s->data()[1]);
103         BOOST_CHECK (!s->data()[2]);
104         BOOST_CHECK (!s->data()[3]);
105
106         /* copy constructor */
107         auto t = new Image (*s);
108         BOOST_CHECK_EQUAL (t->planes(), 1);
109         BOOST_CHECK_EQUAL (t->stride()[0], 50 * 3);
110         BOOST_CHECK_EQUAL (t->line_size()[0], 50 * 3);
111         BOOST_CHECK (t->data()[0]);
112         BOOST_CHECK (!t->data()[1]);
113         BOOST_CHECK (!t->data()[2]);
114         BOOST_CHECK (!t->data()[3]);
115         BOOST_CHECK (t->data() != s->data());
116         BOOST_CHECK (t->data()[0] != s->data()[0]);
117         BOOST_CHECK (t->line_size() != s->line_size());
118         BOOST_CHECK_EQUAL (t->line_size()[0], s->line_size()[0]);
119         BOOST_CHECK (t->stride() != s->stride());
120         BOOST_CHECK_EQUAL (t->stride()[0], s->stride()[0]);
121
122         /* assignment operator */
123         auto u = new Image (AV_PIX_FMT_YUV422P, dcp::Size (150, 150), true);
124         *u = *s;
125         BOOST_CHECK_EQUAL (u->planes(), 1);
126         BOOST_CHECK_EQUAL (u->stride()[0], 50 * 3);
127         BOOST_CHECK_EQUAL (u->line_size()[0], 50 * 3);
128         BOOST_CHECK (u->data()[0]);
129         BOOST_CHECK (!u->data()[1]);
130         BOOST_CHECK (!u->data()[2]);
131         BOOST_CHECK (!u->data()[3]);
132         BOOST_CHECK (u->data() != s->data());
133         BOOST_CHECK (u->data()[0] != s->data()[0]);
134         BOOST_CHECK (u->line_size() != s->line_size());
135         BOOST_CHECK_EQUAL (u->line_size()[0], s->line_size()[0]);
136         BOOST_CHECK (u->stride() != s->stride());
137         BOOST_CHECK_EQUAL (u->stride()[0], s->stride()[0]);
138
139         delete s;
140         delete t;
141         delete u;
142 }
143
144
145 void
146 alpha_blend_test_one (AVPixelFormat format, string suffix)
147 {
148         auto proxy = make_shared<FFmpegImageProxy>(TestPaths::private_data() / "prophet_frame.tiff", VideoRange::FULL);
149         auto raw = proxy->image().image;
150         auto background = raw->convert_pixel_format (dcp::YUVToRGB::REC709, format, true, false);
151
152         auto overlay = make_shared<Image>(AV_PIX_FMT_BGRA, dcp::Size(431, 891), true);
153         overlay->make_transparent ();
154
155         for (int y = 0; y < 128; ++y) {
156                 auto p = overlay->data()[0] + y * overlay->stride()[0];
157                 for (int x = 0; x < 128; ++x) {
158                         p[x * 4 + 2] = 255;
159                         p[x * 4 + 3] = 255;
160                 }
161         }
162
163         for (int y = 128; y < 256; ++y) {
164                 auto p = overlay->data()[0] + y * overlay->stride()[0];
165                 for (int x = 0; x < 128; ++x) {
166                         p[x * 4 + 1] = 255;
167                         p[x * 4 + 3] = 255;
168                 }
169         }
170
171         for (int y = 256; y < 384; ++y) {
172                 auto p = overlay->data()[0] + y * overlay->stride()[0];
173                 for (int x = 0; x < 128; ++x) {
174                         p[x * 4] = 255;
175                         p[x * 4 + 3] = 255;
176                 }
177         }
178
179         background->alpha_blend (overlay, Position<int> (13, 17));
180
181         auto save = background->convert_pixel_format (dcp::YUVToRGB::REC709, AV_PIX_FMT_RGB24, false, false);
182
183         write_image (save, "build/test/image_test_" + suffix + ".png");
184         check_image ("build/test/image_test_" + suffix + ".png", TestPaths::private_data() / ("image_test_" + suffix + ".png"));
185 }
186
187
188 /** Test Image::alpha_blend */
189 BOOST_AUTO_TEST_CASE (alpha_blend_test)
190 {
191         alpha_blend_test_one (AV_PIX_FMT_RGB24, "rgb24");
192         alpha_blend_test_one (AV_PIX_FMT_BGRA, "bgra");
193         alpha_blend_test_one (AV_PIX_FMT_RGBA, "rgba");
194         alpha_blend_test_one (AV_PIX_FMT_RGB48LE, "rgb48le");
195         alpha_blend_test_one (AV_PIX_FMT_YUV420P, "yuv420p");
196         alpha_blend_test_one (AV_PIX_FMT_YUV420P10, "yuv420p10");
197         alpha_blend_test_one (AV_PIX_FMT_YUV422P10LE, "yuv422p10le");
198 }
199
200
201 /** Test merge (list<PositionImage>) with a single image */
202 BOOST_AUTO_TEST_CASE (merge_test1)
203 {
204         int const stride = 48 * 4;
205
206         auto A = make_shared<Image>(AV_PIX_FMT_BGRA, dcp::Size (48, 48), false);
207         A->make_transparent ();
208         auto a = A->data()[0];
209
210         for (int y = 0; y < 48; ++y) {
211                 auto p = a + y * stride;
212                 for (int x = 0; x < 16; ++x) {
213                         /* blue */
214                         p[x * 4] = 255;
215                         /* opaque */
216                         p[x * 4 + 3] = 255;
217                 }
218         }
219
220         list<PositionImage> all;
221         all.push_back (PositionImage (A, Position<int>(0, 0)));
222         auto merged = merge (all);
223
224         BOOST_CHECK (merged.position == Position<int>(0, 0));
225         BOOST_CHECK_EQUAL (memcmp (merged.image->data()[0], A->data()[0], stride * 48), 0);
226 }
227
228
229 /** Test merge (list<PositionImage>) with two images */
230 BOOST_AUTO_TEST_CASE (merge_test2)
231 {
232         auto A = make_shared<Image>(AV_PIX_FMT_BGRA, dcp::Size (48, 1), false);
233         A->make_transparent ();
234         auto a = A->data()[0];
235         for (int x = 0; x < 16; ++x) {
236                 /* blue */
237                 a[x * 4] = 255;
238                 /* opaque */
239                 a[x * 4 + 3] = 255;
240         }
241
242         auto B = make_shared<Image>(AV_PIX_FMT_BGRA, dcp::Size (48, 1), false);
243         B->make_transparent ();
244         auto b = B->data()[0];
245         for (int x = 0; x < 16; ++x) {
246                 /* red */
247                 b[(x + 32) * 4 + 2] = 255;
248                 /* opaque */
249                 b[(x + 32) * 4 + 3] = 255;
250         }
251
252         list<PositionImage> all;
253         all.push_back (PositionImage(A, Position<int>(0, 0)));
254         all.push_back (PositionImage(B, Position<int>(0, 0)));
255         auto merged = merge (all);
256
257         BOOST_CHECK (merged.position == Position<int>(0, 0));
258
259         auto m = merged.image->data()[0];
260
261         for (int x = 0; x < 16; ++x) {
262                 BOOST_CHECK_EQUAL (m[x * 4], 255);
263                 BOOST_CHECK_EQUAL (m[x * 4 + 3], 255);
264                 BOOST_CHECK_EQUAL (m[(x + 16) * 4 + 3], 0);
265                 BOOST_CHECK_EQUAL (m[(x + 32) * 4 + 2], 255);
266                 BOOST_CHECK_EQUAL (m[(x + 32) * 4 + 3], 255);
267         }
268 }
269
270
271 /** Test Image::crop_scale_window with YUV420P and some windowing */
272 BOOST_AUTO_TEST_CASE (crop_scale_window_test)
273 {
274         auto proxy = make_shared<FFmpegImageProxy>("test/data/flat_red.png", VideoRange::FULL);
275         auto raw = proxy->image().image;
276         auto out = raw->crop_scale_window(
277                 Crop(), dcp::Size(1998, 836), dcp::Size(1998, 1080), dcp::YUVToRGB::REC709, VideoRange::FULL, AV_PIX_FMT_YUV420P, VideoRange::FULL, true, false
278                 );
279         auto save = out->scale(dcp::Size(1998, 1080), dcp::YUVToRGB::REC709, AV_PIX_FMT_RGB24, false, false);
280         write_image(save, "build/test/crop_scale_window_test.png");
281         check_image("test/data/crop_scale_window_test.png", "build/test/crop_scale_window_test.png");
282 }
283
284
285 /** Special cases of Image::crop_scale_window which triggered some valgrind warnings */
286 BOOST_AUTO_TEST_CASE (crop_scale_window_test2)
287 {
288         auto image = make_shared<Image>(AV_PIX_FMT_XYZ12LE, dcp::Size(2048, 858), true);
289         image->crop_scale_window (
290                 Crop(279, 0, 0, 0), dcp::Size(1069, 448), dcp::Size(1069, 578), dcp::YUVToRGB::REC709, VideoRange::FULL, AV_PIX_FMT_RGB24, VideoRange::FULL, false, false
291                 );
292         image->crop_scale_window (
293                 Crop(2048, 0, 0, 0), dcp::Size(1069, 448), dcp::Size(1069, 578), dcp::YUVToRGB::REC709, VideoRange::FULL, AV_PIX_FMT_RGB24, VideoRange::FULL, false, false
294                 );
295 }
296
297
298 BOOST_AUTO_TEST_CASE (crop_scale_window_test3)
299 {
300         auto proxy = make_shared<FFmpegImageProxy>(TestPaths::private_data() / "player_seek_test_0.png", VideoRange::FULL);
301         auto xyz = proxy->image().image->convert_pixel_format(dcp::YUVToRGB::REC709, AV_PIX_FMT_RGB24, true, false);
302         auto cropped = xyz->crop_scale_window(
303                 Crop(512, 0, 0, 0), dcp::Size(1486, 1080), dcp::Size(1998, 1080), dcp::YUVToRGB::REC709, VideoRange::FULL, AV_PIX_FMT_RGB24, VideoRange::FULL, false, false
304                 );
305         write_image(cropped, "build/test/crop_scale_window_test3.png");
306         check_image("test/data/crop_scale_window_test3.png", "build/test/crop_scale_window_test3.png");
307 }
308
309
310 BOOST_AUTO_TEST_CASE (crop_scale_window_test4)
311 {
312         auto proxy = make_shared<FFmpegImageProxy>(TestPaths::private_data() / "player_seek_test_0.png", VideoRange::FULL);
313         auto xyz = proxy->image().image->convert_pixel_format(dcp::YUVToRGB::REC709, AV_PIX_FMT_RGB24, true, false);
314         auto cropped = xyz->crop_scale_window(
315                 Crop(512, 0, 0, 0), dcp::Size(1486, 1080), dcp::Size(1998, 1080), dcp::YUVToRGB::REC709, VideoRange::FULL, AV_PIX_FMT_XYZ12LE, VideoRange::FULL, false, false
316                 );
317         write_image(cropped, "build/test/crop_scale_window_test4.png");
318         check_image("test/data/crop_scale_window_test4.png", "build/test/crop_scale_window_test4.png", 35000);
319 }
320
321
322 BOOST_AUTO_TEST_CASE (crop_scale_window_test5)
323 {
324         auto proxy = make_shared<FFmpegImageProxy>(TestPaths::private_data() / "player_seek_test_0.png", VideoRange::FULL);
325         auto xyz = proxy->image().image->convert_pixel_format(dcp::YUVToRGB::REC709, AV_PIX_FMT_XYZ12LE, true, false);
326         auto cropped = xyz->crop_scale_window(
327                 Crop(512, 0, 0, 0), dcp::Size(1486, 1080), dcp::Size(1998, 1080), dcp::YUVToRGB::REC709, VideoRange::FULL, AV_PIX_FMT_RGB24, VideoRange::FULL, false, false
328                 );
329         write_image(cropped, "build/test/crop_scale_window_test5.png");
330         check_image("test/data/crop_scale_window_test5.png", "build/test/crop_scale_window_test5.png");
331 }
332
333
334 BOOST_AUTO_TEST_CASE (crop_scale_window_test6)
335 {
336         auto proxy = make_shared<FFmpegImageProxy>(TestPaths::private_data() / "player_seek_test_0.png", VideoRange::FULL);
337         auto xyz = proxy->image().image->convert_pixel_format(dcp::YUVToRGB::REC709, AV_PIX_FMT_XYZ12LE, true, false);
338         auto cropped = xyz->crop_scale_window(
339                 Crop(512, 0, 0, 0), dcp::Size(1486, 1080), dcp::Size(1998, 1080), dcp::YUVToRGB::REC709, VideoRange::FULL, AV_PIX_FMT_XYZ12LE, VideoRange::FULL, false, false
340                 );
341         write_image(cropped, "build/test/crop_scale_window_test6.png");
342         check_image("test/data/crop_scale_window_test6.png", "build/test/crop_scale_window_test6.png", 35000);
343 }
344
345
346 /** Test some small crops with an image that shows up errors in registration of the YUV planes (#1872) */
347 BOOST_AUTO_TEST_CASE (crop_scale_window_test7)
348 {
349         using namespace boost::filesystem;
350         for (int left_crop = 0; left_crop < 8; ++left_crop) {
351                 auto proxy = make_shared<FFmpegImageProxy>("test/data/rgb_grey_testcard.png", VideoRange::FULL);
352                 auto yuv = proxy->image().image->convert_pixel_format(dcp::YUVToRGB::REC709, AV_PIX_FMT_YUV420P, true, false);
353                 int rounded = left_crop - (left_crop % 2);
354                 auto cropped = yuv->crop_scale_window(
355                         Crop(left_crop, 0, 0, 0),
356                         dcp::Size(1998 - rounded, 1080),
357                         dcp::Size(1998 - rounded, 1080),
358                         dcp::YUVToRGB::REC709,
359                         VideoRange::VIDEO,
360                         AV_PIX_FMT_RGB24,
361                         VideoRange::VIDEO,
362                         true,
363                         false
364                         );
365                 path file = String::compose("crop_scale_window_test7-%1.png", left_crop);
366                 write_image(cropped, path("build") / "test" / file);
367                 check_image(path("test") / "data" / file, path("build") / "test" / file, 10);
368         }
369 }
370
371
372 BOOST_AUTO_TEST_CASE (as_png_test)
373 {
374         auto proxy = make_shared<FFmpegImageProxy>("test/data/3d_test/000001.png", VideoRange::FULL);
375         auto image_rgb = proxy->image().image;
376         auto image_bgr = image_rgb->convert_pixel_format(dcp::YUVToRGB::REC709, AV_PIX_FMT_BGRA, true, false);
377         image_rgb->as_png().write ("build/test/as_png_rgb.png");
378         image_bgr->as_png().write ("build/test/as_png_bgr.png");
379
380         check_image ("test/data/3d_test/000001.png", "build/test/as_png_rgb.png");
381         check_image ("test/data/3d_test/000001.png", "build/test/as_png_bgr.png");
382 }
383
384
385 /* Very dumb test to fade black to make sure it stays black */
386 static void
387 fade_test_format_black (AVPixelFormat f, string name)
388 {
389         Image yuv (f, dcp::Size(640, 480), true);
390         yuv.make_black ();
391         yuv.fade (0);
392         string const filename = "fade_test_black_" + name + ".png";
393         yuv.convert_pixel_format(dcp::YUVToRGB::REC709, AV_PIX_FMT_RGBA, true, false)->as_png().write("build/test/" + filename);
394         check_image ("test/data/" + filename, "build/test/" + filename);
395 }
396
397
398 /* Fade red to make sure it stays red */
399 static void
400 fade_test_format_red (AVPixelFormat f, float amount, string name)
401 {
402         auto proxy = make_shared<FFmpegImageProxy>("test/data/flat_red.png", VideoRange::FULL);
403         auto red = proxy->image().image->convert_pixel_format(dcp::YUVToRGB::REC709, f, true, false);
404         red->fade (amount);
405         string const filename = "fade_test_red_" + name + ".png";
406         red->convert_pixel_format(dcp::YUVToRGB::REC709, AV_PIX_FMT_RGBA, true, false)->as_png().write("build/test/" + filename);
407         check_image ("test/data/" + filename, "build/test/" + filename);
408 }
409
410
411 BOOST_AUTO_TEST_CASE (fade_test)
412 {
413         fade_test_format_black (AV_PIX_FMT_YUV420P,   "yuv420p");
414         fade_test_format_black (AV_PIX_FMT_YUV422P10, "yuv422p10");
415         fade_test_format_black (AV_PIX_FMT_RGB24,     "rgb24");
416         fade_test_format_black (AV_PIX_FMT_XYZ12LE,   "xyz12le");
417         fade_test_format_black (AV_PIX_FMT_RGB48LE,   "rgb48le");
418
419         fade_test_format_red   (AV_PIX_FMT_YUV420P,   0,   "yuv420p_0");
420         fade_test_format_red   (AV_PIX_FMT_YUV420P,   0.5, "yuv420p_50");
421         fade_test_format_red   (AV_PIX_FMT_YUV420P,   1,   "yuv420p_100");
422         fade_test_format_red   (AV_PIX_FMT_YUV422P10, 0,   "yuv422p10_0");
423         fade_test_format_red   (AV_PIX_FMT_YUV422P10, 0.5, "yuv422p10_50");
424         fade_test_format_red   (AV_PIX_FMT_YUV422P10, 1,   "yuv422p10_100");
425         fade_test_format_red   (AV_PIX_FMT_RGB24,     0,   "rgb24_0");
426         fade_test_format_red   (AV_PIX_FMT_RGB24,     0.5, "rgb24_50");
427         fade_test_format_red   (AV_PIX_FMT_RGB24,     1,   "rgb24_100");
428         fade_test_format_red   (AV_PIX_FMT_XYZ12LE,   0,   "xyz12le_0");
429         fade_test_format_red   (AV_PIX_FMT_XYZ12LE,   0.5, "xyz12le_50");
430         fade_test_format_red   (AV_PIX_FMT_XYZ12LE,   1,   "xyz12le_100");
431         fade_test_format_red   (AV_PIX_FMT_RGB48LE,   0,   "rgb48le_0");
432         fade_test_format_red   (AV_PIX_FMT_RGB48LE,   0.5, "rgb48le_50");
433         fade_test_format_red   (AV_PIX_FMT_RGB48LE,   1,   "rgb48le_100");
434 }
435
436
437 BOOST_AUTO_TEST_CASE (make_black_test)
438 {
439         dcp::Size in_size (512, 512);
440         dcp::Size out_size (1024, 1024);
441
442         list<AVPixelFormat> pix_fmts = {
443                 AV_PIX_FMT_RGB24, // 2
444                 AV_PIX_FMT_ARGB,
445                 AV_PIX_FMT_RGBA,
446                 AV_PIX_FMT_ABGR,
447                 AV_PIX_FMT_BGRA,
448                 AV_PIX_FMT_YUV420P, // 0
449                 AV_PIX_FMT_YUV411P,
450                 AV_PIX_FMT_YUV422P10LE,
451                 AV_PIX_FMT_YUV422P16LE,
452                 AV_PIX_FMT_YUV444P9LE,
453                 AV_PIX_FMT_YUV444P9BE,
454                 AV_PIX_FMT_YUV444P10LE,
455                 AV_PIX_FMT_YUV444P10BE,
456                 AV_PIX_FMT_UYVY422,
457                 AV_PIX_FMT_YUVJ420P,
458                 AV_PIX_FMT_YUVJ422P,
459                 AV_PIX_FMT_YUVJ444P,
460                 AV_PIX_FMT_YUVA420P9BE,
461                 AV_PIX_FMT_YUVA422P9BE,
462                 AV_PIX_FMT_YUVA444P9BE,
463                 AV_PIX_FMT_YUVA420P9LE,
464                 AV_PIX_FMT_YUVA422P9LE,
465                 AV_PIX_FMT_YUVA444P9LE,
466                 AV_PIX_FMT_YUVA420P10BE,
467                 AV_PIX_FMT_YUVA422P10BE,
468                 AV_PIX_FMT_YUVA444P10BE,
469                 AV_PIX_FMT_YUVA420P10LE,
470                 AV_PIX_FMT_YUVA422P10LE,
471                 AV_PIX_FMT_YUVA444P10LE,
472                 AV_PIX_FMT_YUVA420P16BE,
473                 AV_PIX_FMT_YUVA422P16BE,
474                 AV_PIX_FMT_YUVA444P16BE,
475                 AV_PIX_FMT_YUVA420P16LE,
476                 AV_PIX_FMT_YUVA422P16LE,
477                 AV_PIX_FMT_YUVA444P16LE,
478                 AV_PIX_FMT_RGB555LE, // 46
479         };
480
481         int N = 0;
482         for (auto i: pix_fmts) {
483                 auto foo = make_shared<Image>(i, in_size, true);
484                 foo->make_black ();
485                 auto bar = foo->scale (out_size, dcp::YUVToRGB::REC601, AV_PIX_FMT_RGB24, true, false);
486
487                 uint8_t* p = bar->data()[0];
488                 for (int y = 0; y < bar->size().height; ++y) {
489                         uint8_t* q = p;
490                         for (int x = 0; x < bar->line_size()[0]; ++x) {
491                                 if (*q != 0) {
492                                         std::cerr << "x=" << x << ", (x%3)=" << (x%3) << "\n";
493                                 }
494                                 BOOST_CHECK_EQUAL (*q++, 0);
495                         }
496                         p += bar->stride()[0];
497                 }
498
499                 ++N;
500         }
501 }
502
503
504 /** Make sure the image isn't corrupted if it is cropped too much.  This can happen when a
505  *  filler 128x128 black frame is emitted from the FFmpegDecoder and the overall crop in either direction
506  *  is greater than 128 pixels.
507  */
508 BOOST_AUTO_TEST_CASE (over_crop_test)
509 {
510         auto image = make_shared<Image>(AV_PIX_FMT_RGB24, dcp::Size(128, 128), true);
511         image->make_black ();
512         auto scaled = image->crop_scale_window (
513                 Crop(0, 0, 128, 128), dcp::Size(1323, 565), dcp::Size(1349, 565), dcp::YUVToRGB::REC709, VideoRange::FULL, AV_PIX_FMT_RGB24, VideoRange::FULL, true, true
514                 );
515         string const filename = "over_crop_test.png";
516         write_image (scaled, "build/test/" + filename);
517         check_image ("test/data/" + filename, "build/test/" + filename);
518 }