2 Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include "picture_mxf.h"
22 #include "exceptions.h"
23 #include "xyz_frame.h"
24 #include "picture_mxf_writer.h"
25 #include "compose.hpp"
27 #include "KM_fileio.h"
28 #include <libxml++/nodes/element.h>
30 #include <boost/filesystem.hpp>
41 using std::stringstream;
46 using boost::shared_ptr;
49 PictureMXF::PictureMXF (boost::filesystem::path file)
55 PictureMXF::PictureMXF (Fraction edit_rate)
62 PictureMXF::read_picture_descriptor (ASDCP::JP2K::PictureDescriptor const & desc)
64 _size.width = desc.StoredWidth;
65 _size.height = desc.StoredHeight;
66 _edit_rate = Fraction (desc.EditRate.Numerator, desc.EditRate.Denominator);
67 _intrinsic_duration = desc.ContainerDuration;
68 _frame_rate = Fraction (desc.SampleRate.Numerator, desc.SampleRate.Denominator);
69 _screen_aspect_ratio = Fraction (desc.AspectRatio.Numerator, desc.AspectRatio.Denominator);
73 PictureMXF::descriptor_equals (
74 ASDCP::JP2K::PictureDescriptor const & a, ASDCP::JP2K::PictureDescriptor const & b, boost::function<void (NoteType, string)> note
78 a.EditRate != b.EditRate ||
79 a.SampleRate != b.SampleRate ||
80 a.StoredWidth != b.StoredWidth ||
81 a.StoredHeight != b.StoredHeight ||
82 a.AspectRatio != b.AspectRatio ||
86 a.XOsize != b.XOsize ||
87 a.YOsize != b.YOsize ||
88 a.XTsize != b.XTsize ||
89 a.YTsize != b.YTsize ||
90 a.XTOsize != b.XTOsize ||
91 a.YTOsize != b.YTOsize ||
93 // a.CodingStyleDefault != b.CodingStyleDefault ||
94 // a.QuantizationDefault != b.QuantizationDefault
97 note (ERROR, "video MXF picture descriptors differ");
101 if (a.ContainerDuration != b.ContainerDuration) {
102 note (ERROR, "video container durations differ");
105 // for (unsigned int j = 0; j < ASDCP::JP2K::MaxComponents; ++j) {
106 // if (a.ImageComponents[j] != b.ImageComponents[j]) {
107 // notes.pack_start ("video MXF picture descriptors differ");
115 PictureMXF::frame_buffer_equals (
116 int frame, EqualityOptions opt, boost::function<void (NoteType, string)> note,
117 uint8_t const * data_A, unsigned int size_A, uint8_t const * data_B, unsigned int size_B
120 if (size_A == size_B && memcmp (data_A, data_B, size_A) == 0) {
121 note (NOTE, "J2K identical");
122 /* Easy result; the J2K data is identical */
126 /* Decompress the images to bitmaps */
127 shared_ptr<XYZFrame> image_A = decompress_j2k (const_cast<uint8_t*> (data_A), size_A, 0);
128 shared_ptr<XYZFrame> image_B = decompress_j2k (const_cast<uint8_t*> (data_B), size_B, 0);
132 vector<int> abs_diffs (image_A->size().width * image_A->size().height * 3);
136 for (int c = 0; c < 3; ++c) {
138 if (image_A->size() != image_B->size()) {
139 note (ERROR, String::compose ("image sizes for frame %1 differ", frame));
143 int const pixels = image_A->size().width * image_A->size().height;
144 for (int j = 0; j < pixels; ++j) {
145 int const t = abs (image_A->data(c)[j] - image_B->data(c)[j]);
147 max_diff = max (max_diff, t);
152 for (vector<int>::iterator j = abs_diffs.begin(); j != abs_diffs.end(); ++j) {
156 double const mean = double (total) / abs_diffs.size ();
158 uint64_t total_squared_deviation = 0;
159 for (vector<int>::iterator j = abs_diffs.begin(); j != abs_diffs.end(); ++j) {
160 total_squared_deviation += pow (*j - mean, 2);
163 double const std_dev = sqrt (double (total_squared_deviation) / abs_diffs.size());
165 note (NOTE, String::compose ("mean difference %1, deviation %2", mean, std_dev));
167 if (mean > opt.max_mean_pixel_error) {
170 String::compose ("mean %1 out of range %2 in frame %3", mean, opt.max_mean_pixel_error, frame)
176 if (std_dev > opt.max_std_dev_pixel_error) {
179 String::compose ("standard deviation %1 out of range %2 in frame %3", std_dev, opt.max_std_dev_pixel_error, frame)
189 PictureMXF::key_type () const