46 #include "compose.hpp"
48 #include <asdcp/AS_DCP.h>
49 #include <asdcp/KM_fileio.h>
50 #include <libxml++/nodes/element.h>
51 #include <boost/filesystem.hpp>
62 using std::shared_ptr;
68 , _intrinsic_duration (0)
76 , _edit_rate (edit_rate)
77 , _intrinsic_duration (0)
84 PictureAsset::read_picture_descriptor (ASDCP::JP2K::PictureDescriptor
const & desc)
86 _size.width = desc.StoredWidth;
87 _size.height = desc.StoredHeight;
88 _edit_rate =
Fraction (desc.EditRate.Numerator, desc.EditRate.Denominator);
90 _frame_rate =
Fraction (desc.SampleRate.Numerator, desc.SampleRate.Denominator);
91 _screen_aspect_ratio =
Fraction (desc.AspectRatio.Numerator, desc.AspectRatio.Denominator);
96 PictureAsset::descriptor_equals (
97 ASDCP::JP2K::PictureDescriptor
const & a, ASDCP::JP2K::PictureDescriptor
const & b, NoteHandler note
101 a.EditRate != b.EditRate ||
102 a.SampleRate != b.SampleRate ||
103 a.StoredWidth != b.StoredWidth ||
104 a.StoredHeight != b.StoredHeight ||
105 a.AspectRatio != b.AspectRatio ||
106 a.Rsize != b.Rsize ||
107 a.Xsize != b.Xsize ||
108 a.Ysize != b.Ysize ||
109 a.XOsize != b.XOsize ||
110 a.YOsize != b.YOsize ||
111 a.XTsize != b.XTsize ||
112 a.YTsize != b.YTsize ||
113 a.XTOsize != b.XTOsize ||
114 a.YTOsize != b.YTOsize ||
120 note (NoteType::ERROR,
"video MXF picture descriptors differ");
124 if (a.ContainerDuration != b.ContainerDuration) {
125 note (NoteType::ERROR,
"video container durations differ");
139 PictureAsset::frame_buffer_equals (
141 uint8_t
const * data_A,
unsigned int size_A, uint8_t
const * data_B,
unsigned int size_B
144 if (size_A == size_B && memcmp (data_A, data_B, size_A) == 0) {
145 note (NoteType::NOTE,
"J2K identical");
151 auto image_A =
decompress_j2k (
const_cast<uint8_t*
>(data_A), size_A, 0);
152 auto image_B =
decompress_j2k (
const_cast<uint8_t*
>(data_B), size_B, 0);
156 vector<int> abs_diffs (image_A->size().width * image_A->size().height * 3);
160 for (
int c = 0; c < 3; ++c) {
162 if (image_A->size() != image_B->size()) {
163 note (NoteType::ERROR, String::compose (
"image sizes for frame %1 differ", frame));
167 int const pixels = image_A->size().width * image_A->size().height;
168 for (
int j = 0; j < pixels; ++j) {
169 int const t = abs (image_A->data(c)[j] - image_B->data(c)[j]);
171 max_diff = max (max_diff, t);
176 for (vector<int>::iterator j = abs_diffs.begin(); j != abs_diffs.end(); ++j) {
180 double const mean = double (total) / abs_diffs.size ();
182 uint64_t total_squared_deviation = 0;
183 for (
auto j: abs_diffs) {
184 total_squared_deviation += pow (j - mean, 2);
187 auto const std_dev = sqrt (
double (total_squared_deviation) / abs_diffs.size());
189 note (NoteType::NOTE, String::compose(
"mean difference %1 deviation %2", mean, std_dev));
203 String::compose (
"standard deviation %1 out of range %2 in frame %3", std_dev, opt.
max_std_dev_pixel_error, frame)
214 PictureAsset::static_pkl_type (Standard standard)
217 case Standard::INTEROP:
218 return "application/x-smpte-mxf;asdcpKind=Picture";
219 case Standard::SMPTE:
220 return "application/mxf";
230 return static_pkl_type (standard);
Parent class for DCP assets, i.e. picture, sound, subtitles, closed captions, CPLs,...
A fraction (i.e. a thing with an integer numerator and an integer denominator).
Parent for classes which represent MXF files.
int64_t _intrinsic_duration
PictureAsset(boost::filesystem::path file)
std::string pkl_type(Standard standard) const override
Exceptions thrown by libdcp.
Methods to encode and decode JPEG2000.
Namespace for everything in libdcp.
std::shared_ptr< OpenJPEGImage > decompress_j2k(uint8_t const *data, int64_t size, int reduce)
PictureAssetWriter and FrameInfo classes.
A class to describe what "equality" means for a particular test.
double max_mean_pixel_error
double max_std_dev_pixel_error
Utility methods and classes.