40 #include "compose.hpp"
49 #include <asdcp/AS_DCP.h>
50 #include <asdcp/KM_fileio.h>
51 #include <libxml++/nodes/element.h>
52 #include <boost/filesystem.hpp>
63 using std::shared_ptr;
82 J2KPictureAsset::read_picture_descriptor (ASDCP::JP2K::PictureDescriptor
const & desc)
84 _size.width = desc.StoredWidth;
85 _size.height = desc.StoredHeight;
86 _edit_rate =
Fraction (desc.EditRate.Numerator, desc.EditRate.Denominator);
88 _frame_rate =
Fraction (desc.SampleRate.Numerator, desc.SampleRate.Denominator);
89 _screen_aspect_ratio =
Fraction (desc.AspectRatio.Numerator, desc.AspectRatio.Denominator);
94 J2KPictureAsset::descriptor_equals (
95 ASDCP::JP2K::PictureDescriptor
const & a, ASDCP::JP2K::PictureDescriptor
const & b, NoteHandler note
99 a.EditRate != b.EditRate ||
100 a.SampleRate != b.SampleRate ||
101 a.StoredWidth != b.StoredWidth ||
102 a.StoredHeight != b.StoredHeight ||
103 a.AspectRatio != b.AspectRatio ||
104 a.Rsize != b.Rsize ||
105 a.Xsize != b.Xsize ||
106 a.Ysize != b.Ysize ||
107 a.XOsize != b.XOsize ||
108 a.YOsize != b.YOsize ||
109 a.XTsize != b.XTsize ||
110 a.YTsize != b.YTsize ||
111 a.XTOsize != b.XTOsize ||
112 a.YTOsize != b.YTOsize ||
118 note (NoteType::ERROR,
"video MXF picture descriptors differ");
122 if (a.ContainerDuration != b.ContainerDuration) {
123 note (NoteType::ERROR,
"video container durations differ");
137 J2KPictureAsset::frame_buffer_equals (
139 uint8_t
const * data_A,
unsigned int size_A, uint8_t
const * data_B,
unsigned int size_B
142 if (size_A == size_B && memcmp (data_A, data_B, size_A) == 0) {
143 note (NoteType::NOTE,
"J2K identical");
149 auto image_A =
decompress_j2k (
const_cast<uint8_t*
>(data_A), size_A, 0);
150 auto image_B =
decompress_j2k (
const_cast<uint8_t*
>(data_B), size_B, 0);
154 vector<int> abs_diffs (image_A->size().width * image_A->size().height * 3);
158 for (
int c = 0; c < 3; ++c) {
160 if (image_A->size() != image_B->size()) {
161 note (NoteType::ERROR, String::compose (
"image sizes for frame %1 differ", frame));
165 int const pixels = image_A->size().width * image_A->size().height;
166 for (
int j = 0; j < pixels; ++j) {
167 int const t = abs (image_A->data(c)[j] - image_B->data(c)[j]);
169 max_diff = max (max_diff, t);
174 for (vector<int>::iterator j = abs_diffs.begin(); j != abs_diffs.end(); ++j) {
178 double const mean = double (total) / abs_diffs.size ();
180 uint64_t total_squared_deviation = 0;
181 for (
auto j: abs_diffs) {
182 total_squared_deviation += pow (j - mean, 2);
185 auto const std_dev = sqrt (
double (total_squared_deviation) / abs_diffs.size());
187 note (NoteType::NOTE, String::compose(
"mean difference %1 deviation %2", mean, std_dev));
201 String::compose (
"standard deviation %1 out of range %2 in frame %3", std_dev, opt.
max_std_dev_pixel_error, frame)
212 J2KPictureAsset::static_pkl_type (Standard standard)
215 case Standard::INTEROP:
216 return "application/x-smpte-mxf;asdcpKind=Picture";
217 case Standard::SMPTE:
218 return "application/mxf";
228 return static_pkl_type (standard);
A class to describe what "equality" means for a particular test.
double max_mean_pixel_error
double max_std_dev_pixel_error
A fraction (i.e. a thing with an integer numerator and an integer denominator).
J2KPictureAsset(boost::filesystem::path file)
std::string pkl_type(Standard standard) const override
int64_t _intrinsic_duration
Class to describe what equality means when calling Asset::equals().
Exceptions thrown by libdcp.
J2KPictureAssetWriter and FrameInfo classes.
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)
Utility methods and classes.