/*
- Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
#include "stereo_picture_mxf.h"
#include "sound_mxf.h"
#include "subtitle_content.h"
-#include "argb_image.h"
+#include "xyz_image.h"
+#include "colour_conversion.h"
+#include "rgb_xyz.h"
#include <Magick++.h>
+#include <boost/scoped_array.hpp>
/** @file examples/read_dcp.cc
* @brief Shows how to read a DCP.
/* Get the 1000th frame of it */
boost::shared_ptr<const dcp::MonoPictureFrame> picture_frame_j2k = picture_mxf->get_frame(999);
- /* Get a ARGB copy of it */
- boost::shared_ptr<dcp::ARGBImage> picture_image_rgb = picture_frame_j2k->argb_image ();
+ /* Get the frame as an XYZ image */
+ boost::shared_ptr<const dcp::XYZImage> picture_image_xyz = picture_frame_j2k->xyz_image ();
- Magick::Image image (picture_image_rgb->size().width, picture_image_rgb->size().height, "BGRA", Magick::CharPixel, picture_image_rgb->data ());
+ /* Convert to ARGB */
+ boost::scoped_array<uint8_t> rgba (new uint8_t[picture_image_xyz->size().width * picture_image_xyz->size().height * 4]);
+ dcp::xyz_to_rgba (picture_image_xyz, dcp::ColourConversion::xyz_to_srgb(), rgba.get ());
+
+ Magick::Image image (picture_image_xyz->size().width, picture_image_xyz->size().height, "BGRA", Magick::CharPixel, rgba.get ());
image.write ("frame.png");
return 0;
+++ /dev/null
-/*
- Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-*/
-
-/** @file src/argb_image.cc
- * @brief ARGBImage class.
- */
-
-#include "argb_image.h"
-
-using namespace dcp;
-
-/** Construct an empty ARGBImage of a given size and with
- * undefined contents.
- * @param size Size in pixels.
- */
-ARGBImage::ARGBImage (Size size)
- : _size (size)
-{
- _data = new uint8_t[_size.width * _size.height * 4];
-}
-
-
-ARGBImage::~ARGBImage ()
-{
- delete[] _data;
-}
-
-/** @return The stride, in bytes; that is, the number of bytes per row of the image */
-int
-ARGBImage::stride () const
-{
- return _size.width * 4;
-}
+++ /dev/null
-/*
- Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-*/
-
-/** @file src/argb_image.h
- * @brief ARGBImage class.
- */
-
-#include "util.h"
-#include <stdint.h>
-
-namespace dcp
-{
-
-/** @class ARGBImage
- * @brief A single frame of picture data held in an ARGB buffer.
- *
- * The format of the data is:
- *
- * <pre>
- * Byte /- 0 -------|- 1 --------|- 2 --------|- 3 --------|- 4 --------|- 5 --------| ...
- * |(0, 0) Blue|(0, 0)Green |(0, 0) Red |(0, 0) Alpha|(0, 1) Blue |(0, 1) Green| ...
- * </pre>
- *
- * So that the first byte is the blue component of the pixel at x=0, y=0, the second
- * is the green component, and so on.
- *
- * Lines are packed so that the second row directly follows the first.
- *
- * XXX: this should probably be an Image...?
- */
-class ARGBImage : boost::noncopyable
-{
-public:
- ARGBImage (Size size);
- ~ARGBImage ();
-
- /** @return pointer to the image data */
- uint8_t* data () const {
- return _data;
- }
-
- /** @return length of one picture row in bytes */
- int stride () const;
-
- /** @return size of the picture in pixels */
- Size size () const {
- return _size;
- }
-
-private:
- Size _size; ///< frame size in pixels
- uint8_t* _data; ///< pointer to image data
-};
-
-}
+++ /dev/null
-/*
- Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-*/
-
-#include "image.h"
-
-using boost::shared_ptr;
-using namespace dcp;
-
-Image::Image (Size s)
- : _size (s)
-{
-
-}
-
-Image::Image (Image const & other)
- : _size (other._size)
-{
-
-}
-
-Image::Image (boost::shared_ptr<const Image> other)
- : _size (other->_size)
-{
-
-}
-
-void
-Image::swap (Image& other)
-{
- std::swap (_size, other._size);
-}
+++ /dev/null
-/*
- Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-*/
-
-#include "util.h"
-
-namespace dcp {
-
-class Image
-{
-public:
- Image (Size);
- Image (Image const &);
- Image (boost::shared_ptr<const Image>);
-
- virtual ~Image () {}
- virtual uint8_t * const * data () const = 0;
- /** @return array of strides in bytes */
- virtual int const * stride () const = 0;
-
- Size size () const {
- return _size;
- }
-
-protected:
- virtual void swap (Image& other);
-
- Size _size;
-};
-
-}
#include "mono_picture_frame.h"
#include "exceptions.h"
-#include "argb_image.h"
#include "util.h"
#include "rgb_xyz.h"
#include "colour_conversion.h"
/** @param reduce a factor by which to reduce the resolution
* of the image, expressed as a power of two (pass 0 for no
* reduction).
- * @param srgb_gamma Reciprocal of output gamma to use after
- * the conversion from XYZ to RGB.
- *
- * @return An ARGB representation of this frame. This is ARGB in the
- * Cairo sense, so that each pixel takes up 4 bytes; the first byte
- * is blue, second green, third red and fourth alpha (always 255).
*/
-shared_ptr<ARGBImage>
-MonoPictureFrame::argb_image (int reduce) const
+shared_ptr<XYZImage>
+MonoPictureFrame::xyz_image (int reduce) const
{
- return xyz_to_rgba (
- decompress_j2k (const_cast<uint8_t*> (_buffer->RoData()), _buffer->Size(), reduce),
- ColourConversion::xyz_to_srgb ()
- );
-}
-
-void
-MonoPictureFrame::rgb_frame (shared_ptr<Image> rgb, optional<NoteHandler> note) const
-{
- xyz_to_rgb (
- decompress_j2k (const_cast<uint8_t*> (_buffer->RoData()), _buffer->Size(), 0),
- ColourConversion::xyz_to_srgb (),
- rgb,
- note
- );
+ return decompress_j2k (const_cast<uint8_t*> (_buffer->RoData()), _buffer->Size(), reduce);
}
namespace dcp {
-class ARGBImage;
-class Image;
+class XYZImage;
/** @class MonoPictureFrame
* @brief A single frame of a 2D (monoscopic) picture asset.
MonoPictureFrame ();
~MonoPictureFrame ();
- boost::shared_ptr<ARGBImage> argb_image (int reduce = 0) const;
- void rgb_frame (boost::shared_ptr<Image> rgb, boost::optional<NoteHandler> note = boost::optional<NoteHandler> ()) const;
+ boost::shared_ptr<XYZImage> xyz_image (int reduce = 0) const;
+
uint8_t const * j2k_data () const;
uint8_t* j2k_data ();
int j2k_size () const;
*/
#include "rgb_xyz.h"
-#include "argb_image.h"
#include "xyz_image.h"
-#include "image.h"
#include "colour_matrix.h"
#include "colour_conversion.h"
#include "transfer_function.h"
#define DCI_COEFFICIENT (48.0 / 52.37)
-/** Convert an openjpeg XYZ image to RGBA.
+/** Convert an XYZ image to RGBA.
* @param xyz_image Image in XYZ.
- * @return RGB image.
+ * @param conversion Colour conversion to use.
+ * @param argb Buffer to fill with RGBA data. The format of the data is:
+ *
+ * <pre>
+ * Byte /- 0 -------|- 1 --------|- 2 --------|- 3 --------|- 4 --------|- 5 --------| ...
+ * |(0, 0) Blue|(0, 0)Green |(0, 0) Red |(0, 0) Alpha|(0, 1) Blue |(0, 1) Green| ...
+ * </pre>
+ *
+ * So that the first byte is the blue component of the pixel at x=0, y=0, the second
+ * is the green component, and so on.
+ *
+ * Lines are packed so that the second row directly follows the first.
*/
-shared_ptr<ARGBImage>
+void
dcp::xyz_to_rgba (
boost::shared_ptr<const XYZImage> xyz_image,
- ColourConversion const & conversion
+ ColourConversion const & conversion,
+ uint8_t* argb
)
{
int const max_colour = pow (2, 12) - 1;
int* xyz_y = xyz_image->data (1);
int* xyz_z = xyz_image->data (2);
- shared_ptr<ARGBImage> argb_image (new ARGBImage (xyz_image->size ()));
- uint8_t* argb = argb_image->data ();
-
double const * lut_in = conversion.in()->lut (16);
double const * lut_out = conversion.out()->lut (12);
boost::numeric::ublas::matrix<double> matrix = conversion.matrix ();
- for (int y = 0; y < xyz_image->size().height; ++y) {
+ int const height = xyz_image->size().height;
+ int const width = xyz_image->size().width;
+
+ for (int y = 0; y < height; ++y) {
uint8_t* argb_line = argb;
- for (int x = 0; x < xyz_image->size().width; ++x) {
+ for (int x = 0; x < width; ++x) {
DCP_ASSERT (*xyz_x >= 0 && *xyz_y >= 0 && *xyz_z >= 0 && *xyz_x < 4096 && *xyz_y < 4096 && *xyz_z < 4096);
*argb_line++ = lut_out[int(rint(d.r * max_colour))] * 0xff;
*argb_line++ = 0xff;
}
-
- argb += argb_image->stride ();
- }
- return argb_image;
+ /* 4 bytes per pixel */
+ argb += width * 4;
+ }
}
-/** Convert an openjpeg XYZ image to RGB.
+/** Convert an XYZ image to 48bpp RGB.
* @param xyz_image Frame in XYZ.
* @param conversion Colour conversion to use.
- * @param rgb Image to write RGB data to; must have space to be
- * filled with packed RGB 16:16:16, 48bpp, 16R, 16G, 16B,
- * with the 2-byte value for each R/G/B component stored as
- * little-endian; i.e. AV_PIX_FMT_RGB48LE.
+ * @param rgb Buffer to fill with RGB data. Format is packed RGB
+ * 16:16:16, 48bpp, 16R, 16G, 16B, with the 2-byte value for each
+ * R/G/B component stored as little-endian; i.e. AV_PIX_FMT_RGB48LE.
+ * @param stride Stride for RGB data in bytes.
+ * @param note Optional handler for any notes that may be made during the conversion (e.g. when clamping occurs).
*/
void
dcp::xyz_to_rgb (
shared_ptr<const XYZImage> xyz_image,
ColourConversion const & conversion,
- shared_ptr<Image> rgb,
+ uint8_t* rgb,
+ int stride,
optional<NoteHandler> note
)
{
boost::numeric::ublas::matrix<double> matrix = conversion.matrix ();
for (int y = 0; y < xyz_image->size().height; ++y) {
- uint16_t* rgb_line = reinterpret_cast<uint16_t*> (rgb->data()[0] + y * rgb->stride()[0]);
+ uint16_t* rgb_line = reinterpret_cast<uint16_t*> (rgb + y * stride);
for (int x = 0; x < xyz_image->size().width; ++x) {
int cx = *xyz_x++;
}
}
-/** rgb must be packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, with the 2-byte value for each R/G/B component stored as little-endian;
- * i.e. AV_PIX_FMT_RGB48LE.
+/** @param rgb RGB data; packed RGB 16:16:16, 48bpp, 16R, 16G, 16B,
+ * with the 2-byte value for each R/G/B component stored as
+ * little-endian; i.e. AV_PIX_FMT_RGB48LE.
+ * @param size of RGB image in pixels.
+ * @param stride of RGB data in bytes.
*/
shared_ptr<dcp::XYZImage>
dcp::rgb_to_xyz (
- boost::shared_ptr<const Image> rgb,
+ uint8_t const * rgb,
+ dcp::Size size,
+ int stride,
ColourConversion const & conversion
)
{
- shared_ptr<XYZImage> xyz (new XYZImage (rgb->size ()));
+ shared_ptr<XYZImage> xyz (new XYZImage (size));
struct {
double r, g, b;
boost::numeric::ublas::matrix<double> matrix = conversion.matrix ();
int jn = 0;
- for (int y = 0; y < rgb->size().height; ++y) {
- uint16_t* p = reinterpret_cast<uint16_t*> (rgb->data()[0] + y * rgb->stride()[0]);
- for (int x = 0; x < rgb->size().width; ++x) {
+ for (int y = 0; y < size.height; ++y) {
+ uint16_t const * p = reinterpret_cast<uint16_t const *> (rgb + y * stride);
+ for (int x = 0; x < size.width; ++x) {
/* In gamma LUT (converting 16-bit to 12-bit) */
s.r = lut_in[*p++ >> 4];
}
-/** Image must be packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, with the 2-byte value for each R/G/B component stored as little-endian;
- * i.e. AV_PIX_FMT_RGB48LE.
+/** @param xyz_16 XYZ image data in packed 16:16:16, 48bpp, 16X, 16Y,
+ * 16Z, with the 2-byte value for each X/Y/Z component stored as
+ * little-endian.
*/
shared_ptr<dcp::XYZImage>
-dcp::xyz_to_xyz (shared_ptr<const Image> xyz_16)
+dcp::xyz_to_xyz (uint8_t const * xyz_16, dcp::Size size, int stride)
{
- shared_ptr<XYZImage> xyz_12 (new XYZImage (xyz_16->size ()));
+ shared_ptr<XYZImage> xyz_12 (new XYZImage (size));
int jn = 0;
- for (int y = 0; y < xyz_16->size().height; ++y) {
- uint16_t* p = reinterpret_cast<uint16_t*> (xyz_16->data()[0] + y * xyz_16->stride()[0]);
- for (int x = 0; x < xyz_16->size().width; ++x) {
+ for (int y = 0; y < size.height; ++y) {
+ uint16_t const * p = reinterpret_cast<uint16_t const *> (xyz_16 + y * stride);
+ for (int x = 0; x < size.width; ++x) {
/* Truncate 16-bit to 12-bit */
xyz_12->data(0)[jn] = *p++ >> 4;
xyz_12->data(1)[jn] = *p++ >> 4;
class Image;
class ColourConversion;
-extern boost::shared_ptr<ARGBImage> xyz_to_rgba (boost::shared_ptr<const XYZImage>, ColourConversion const & conversion);
+extern void xyz_to_rgba (
+ boost::shared_ptr<const XYZImage>,
+ ColourConversion const & conversion,
+ uint8_t* rgba
+ );
+
extern void xyz_to_rgb (
boost::shared_ptr<const XYZImage>,
ColourConversion const & conversion,
- boost::shared_ptr<Image> rgb,
+ uint8_t* rgb,
+ int stride,
boost::optional<NoteHandler> note = boost::optional<NoteHandler> ()
);
-extern boost::shared_ptr<XYZImage> rgb_to_xyz (boost::shared_ptr<const Image>, ColourConversion const & conversion);
-extern boost::shared_ptr<XYZImage> xyz_to_xyz (boost::shared_ptr<const Image>);
+
+extern boost::shared_ptr<XYZImage> rgb_to_xyz (uint8_t const * rgb, dcp::Size size, int stride, ColourConversion const & conversion);
+extern boost::shared_ptr<XYZImage> xyz_to_xyz (uint8_t const * xyz, dcp::Size size, int stride);
}
#include "stereo_picture_frame.h"
#include "exceptions.h"
-#include "argb_image.h"
#include "util.h"
#include "rgb_xyz.h"
#include "colour_conversion.h"
* @param reduce a factor by which to reduce the resolution
* of the image, expressed as a power of two (pass 0 for no
* reduction).
- *
- * @return An ARGB representation of one of the eyes (left or right)
- * of this frame. This is ARGB in the Cairo sense, so that each
- * pixel takes up 4 bytes; the first byte is blue, second green,
- * third red and fourth alpha (always 255).
- *
*/
-shared_ptr<ARGBImage>
-StereoPictureFrame::argb_image (Eye eye, int reduce) const
+shared_ptr<XYZImage>
+StereoPictureFrame::xyz_image (Eye eye, int reduce) const
{
- shared_ptr<XYZImage> xyz_image;
switch (eye) {
case LEFT:
- xyz_image = decompress_j2k (const_cast<uint8_t*> (_buffer->Left.RoData()), _buffer->Left.Size(), reduce);
- break;
+ return decompress_j2k (const_cast<uint8_t*> (_buffer->Left.RoData()), _buffer->Left.Size(), reduce);
case RIGHT:
- xyz_image = decompress_j2k (const_cast<uint8_t*> (_buffer->Right.RoData()), _buffer->Right.Size(), reduce);
- break;
+ return decompress_j2k (const_cast<uint8_t*> (_buffer->Right.RoData()), _buffer->Right.Size(), reduce);
}
- return xyz_to_rgba (xyz_image, ColourConversion::xyz_to_srgb ());
-}
-
-void
-StereoPictureFrame::rgb_frame (Eye eye, shared_ptr<Image> image) const
-{
- shared_ptr<XYZImage> xyz_image;
- switch (eye) {
- case LEFT:
- xyz_image = decompress_j2k (const_cast<uint8_t*> (_buffer->Left.RoData()), _buffer->Left.Size(), 0);
- break;
- case RIGHT:
- xyz_image = decompress_j2k (const_cast<uint8_t*> (_buffer->Right.RoData()), _buffer->Right.Size(), 0);
- break;
- }
-
- return xyz_to_rgb (xyz_image, ColourConversion::xyz_to_srgb (), image);
+ return shared_ptr<XYZImage> ();
}
uint8_t const *
namespace JP2K {
struct SFrameBuffer;
}
- class AESDecContext;
}
namespace dcp {
-class ARGBImage;
-class Image;
+class XYZImage;
/** A single frame of a 3D (stereoscopic) picture asset */
class StereoPictureFrame : public boost::noncopyable
StereoPictureFrame ();
~StereoPictureFrame ();
- boost::shared_ptr<ARGBImage> argb_image (Eye eye, int reduce = 0) const;
- void rgb_frame (Eye eye, boost::shared_ptr<Image>) const;
+ boost::shared_ptr<XYZImage> xyz_image (Eye eye, int reduce = 0) const;
+
uint8_t const * left_j2k_data () const;
uint8_t* left_j2k_data ();
int left_j2k_size () const;
+
uint8_t const * right_j2k_data () const;
uint8_t* right_j2k_data ();
int right_j2k_size () const;
class AssetMap;
}
+/** @struct Size
+ * @brief The integer, two-dimensional size of something.
+ */
+struct Size
+{
+ Size ()
+ : width (0)
+ , height (0)
+ {}
+
+ Size (int w, int h)
+ : width (w)
+ , height (h)
+ {}
+
+ float ratio () const {
+ return float (width) / height;
+ }
+
+ int width;
+ int height;
+};
+
/** Identifier for a sound channel */
enum Channel {
LEFT = 0, ///< left
#include "util.h"
#include "exceptions.h"
#include "types.h"
-#include "argb_image.h"
#include "certificates.h"
#include "xyz_image.h"
#include "dcp_assert.h"
class CertificateChain;
class GammaLUT;
class XYZImage;
-
-/** @struct Size
- * @brief The integer, two-dimensional size of something.
- */
-struct Size
-{
- Size ()
- : width (0)
- , height (0)
- {}
-
- Size (int w, int h)
- : width (w)
- , height (h)
- {}
-
- float ratio () const {
- return float (width) / height;
- }
-
- int width;
- int height;
-};
extern bool operator== (Size const & a, Size const & b);
extern bool operator!= (Size const & a, Size const & b);
def build(bld):
source = """
- argb_image.cc
asset.cc
certificate_chain.cc
certificates.cc
file.cc
font.cc
gamma_transfer_function.cc
- image.cc
interop_load_font.cc
interop_subtitle_content.cc
key.cc
encrypted_kdm.h
exceptions.h
gamma_transfer_function.h
- image.h
interop_load_font.h
interop_subtitle_content.h
key.h
reel_stereo_picture_asset.h
reel_subtitle_asset.h
ref.h
- argb_image.h
signer.h
smpte_load_font.h
smpte_subtitle_content.h
+++ /dev/null
-/*
- Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-*/
-
-#include "argb_image.h"
-#include <boost/test/unit_test.hpp>
-
-/** Very simple tests of ARGBImage */
-BOOST_AUTO_TEST_CASE (argb_image_test)
-{
- dcp::ARGBImage f (dcp::Size (100, 200));
-
- BOOST_CHECK (f.data() != 0);
- BOOST_CHECK_EQUAL (f.stride(), 100 * 4);
- BOOST_CHECK_EQUAL (f.size(), dcp::Size (100, 200));
-}
*/
-#include <boost/test/unit_test.hpp>
#include "dcp.h"
#include "mono_picture_frame.h"
#include "cpl.h"
#include "decrypted_kdm.h"
#include "encrypted_kdm.h"
-#include "argb_image.h"
#include "mono_picture_mxf.h"
#include "reel_picture_asset.h"
#include "reel.h"
#include "test.h"
+#include "xyz_image.h"
+#include "rgb_xyz.h"
+#include "colour_conversion.h"
+#include <boost/test/unit_test.hpp>
+#include <boost/scoped_array.hpp>
+using std::pair;
+using std::make_pair;
using boost::dynamic_pointer_cast;
using boost::shared_ptr;
+using boost::scoped_array;
-static shared_ptr<const dcp::ARGBImage>
+pair<uint8_t*, dcp::Size>
get_frame (dcp::DCP const & dcp)
{
shared_ptr<const dcp::Reel> reel = dcp.cpls().front()->reels().front ();
shared_ptr<const dcp::MonoPictureMXF> mono_picture = dynamic_pointer_cast<const dcp::MonoPictureMXF> (picture);
shared_ptr<const dcp::MonoPictureFrame> j2k_frame = mono_picture->get_frame (0);
- return j2k_frame->argb_image ();
+ shared_ptr<dcp::XYZImage> xyz = j2k_frame->xyz_image();
+
+ uint8_t* argb = new uint8_t[xyz->size().width * xyz->size().height * 4];
+ dcp::xyz_to_rgba (j2k_frame->xyz_image(), dcp::ColourConversion::xyz_to_srgb(), argb);
+ return make_pair (argb, xyz->size ());
}
/** Decrypt an encrypted test DCP and check that its first frame is the same as the unencrypted version */
encrypted.add (kdm);
- shared_ptr<const dcp::ARGBImage> plaintext_frame = get_frame (plaintext);
- shared_ptr<const dcp::ARGBImage> encrypted_frame = get_frame (encrypted);
+ pair<uint8_t *, dcp::Size> plaintext_frame = get_frame (plaintext);
+ pair<uint8_t *, dcp::Size> encrypted_frame = get_frame (encrypted);
/* Check that plaintext and encrypted are the same */
- BOOST_CHECK_EQUAL (plaintext_frame->stride(), encrypted_frame->stride());
- BOOST_CHECK_EQUAL (plaintext_frame->size().width, encrypted_frame->size().width);
- BOOST_CHECK_EQUAL (plaintext_frame->size().height, encrypted_frame->size().height);
- BOOST_CHECK_EQUAL (memcmp (plaintext_frame->data(), encrypted_frame->data(), plaintext_frame->stride() * plaintext_frame->size().height), 0);
+
+ BOOST_CHECK_EQUAL (plaintext_frame.second, encrypted_frame.second);
+
+ BOOST_CHECK_EQUAL (
+ memcmp (
+ plaintext_frame.first,
+ encrypted_frame.first,
+ plaintext_frame.second.width * plaintext_frame.second.height * 4
+ ),
+ 0
+ );
+
+ delete[] plaintext_frame.first;
+ delete[] encrypted_frame.first;
}
/** Load in a KDM that didn't work at first */
+++ /dev/null
-/*
- Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-*/
-
-#include "image.h"
-#include <boost/test/unit_test.hpp>
-
-using std::string;
-using boost::shared_ptr;
-
-class TestImage : public dcp::Image
-{
-public:
- TestImage (dcp::Size s)
- : Image (s)
- {
-
- }
-
- TestImage (TestImage const & other)
- : Image (other)
- {
-
- }
-
- TestImage (shared_ptr<const TestImage> other)
- : Image (other)
- {
-
- }
-
- uint8_t * const * data () const {
- return 0;
- }
-
- int const * stride () const {
- return 0;
- }
-};
-
-/** Token test for Image class to keep gcov happy */
-BOOST_AUTO_TEST_CASE (image_test)
-{
- TestImage im (dcp::Size (412, 930));
- BOOST_CHECK_EQUAL (im.size (), dcp::Size (412, 930));
-
- TestImage im2 (im);
- BOOST_CHECK_EQUAL (im2.size (), im.size ());
-
- shared_ptr<TestImage> im3 (new TestImage (dcp::Size (1203, 1294)));
- TestImage im4 (im3);
- BOOST_CHECK_EQUAL (im4.size (), im3->size ());
-}
*/
-#include "image.h"
#include "rgb_xyz.h"
#include "xyz_image.h"
#include "colour_conversion.h"
#include <boost/test/unit_test.hpp>
#include <boost/bind.hpp>
+#include <boost/scoped_array.hpp>
using std::max;
using std::list;
using std::string;
using boost::shared_ptr;
using boost::optional;
-
-class SimpleImage : public dcp::Image
-{
-public:
- SimpleImage (dcp::Size size)
- : Image (size)
- {
- /* 48bpp */
- _stride[0] = _size.width * 6;
- _data[0] = new uint8_t[size.height * stride()[0]];
- }
-
- ~SimpleImage ()
- {
- delete[] _data[0];
- }
-
- uint8_t * const * data () const {
- return _data;
- }
-
- int const * stride () const {
- return _stride;
- }
-
-private:
- uint8_t* _data[1];
- int _stride[1];
-};
+using boost::scoped_array;
/** Convert a test image from sRGB to XYZ and check that the transforms are right */
BOOST_AUTO_TEST_CASE (rgb_xyz_test)
unsigned int seed = 0;
dcp::Size const size (640, 480);
- shared_ptr<const dcp::Image> rgb (new SimpleImage (size));
+ scoped_array<uint8_t> rgb (new uint8_t[size.width * size.height * 6]);
for (int y = 0; y < size.height; ++y) {
- uint16_t* p = reinterpret_cast<uint16_t*> (rgb->data()[0] + y * rgb->stride()[0]);
+ uint16_t* p = reinterpret_cast<uint16_t*> (rgb.get() + y * size.width * 6);
for (int x = 0; x < size.width; ++x) {
/* Write a 12-bit random number for each component */
for (int c = 0; c < 3; ++c) {
}
}
- shared_ptr<dcp::XYZImage> xyz = dcp::rgb_to_xyz (rgb, dcp::ColourConversion::srgb_to_xyz ());
+ shared_ptr<dcp::XYZImage> xyz = dcp::rgb_to_xyz (rgb.get(), size, size.width * 6, dcp::ColourConversion::srgb_to_xyz ());
for (int y = 0; y < size.height; ++y) {
- uint16_t* p = reinterpret_cast<uint16_t*> (rgb->data()[0] + y * rgb->stride()[0]);
+ uint16_t* p = reinterpret_cast<uint16_t*> (rgb.get() + y * size.width * 6);
for (int x = 0; x < size.width; ++x) {
double cr = *p++ / 65535.0;
xyz->data(2)[2] = 0;
xyz->data(2)[3] = 4095;
- shared_ptr<SimpleImage> image (new SimpleImage (dcp::Size (2, 2)));
+ scoped_array<uint8_t> rgb (new uint8_t[2 * 2 * 6]);
notes.clear ();
- dcp::xyz_to_rgb (xyz, dcp::ColourConversion::xyz_to_srgb (), image, boost::optional<dcp::NoteHandler> (boost::bind (¬e_handler, _1, _2)));
+ dcp::xyz_to_rgb (xyz, dcp::ColourConversion::xyz_to_srgb (), rgb.get(), 2 * 6, boost::optional<dcp::NoteHandler> (boost::bind (¬e_handler, _1, _2)));
/* The 6 out-of-range samples should have been noted */
BOOST_REQUIRE_EQUAL (notes.size(), 6);
as inputs at the extremes (0 and 4095).
*/
- uint16_t* buffer = reinterpret_cast<uint16_t*> (image->data()[0]);
+ uint16_t* buffer = reinterpret_cast<uint16_t*> (rgb.get ());
BOOST_REQUIRE_EQUAL (buffer[0 * 3 + 0], buffer[2 * 3 + 1]);
BOOST_REQUIRE_EQUAL (buffer[0 * 3 + 1], buffer[2 * 3 + 1]);
BOOST_REQUIRE_EQUAL (buffer[0 * 3 + 2], buffer[2 * 3 + 2]);
#include "test.h"
#include "cpl.h"
#include "mono_picture_frame.h"
-#include "argb_image.h"
#include "certificate_chain.h"
#include "mono_picture_mxf_writer.h"
#include "reel_picture_asset.h"
#include "reel_mono_picture_asset.h"
#include "file.h"
+#include "xyz_image.h"
+#include "rgb_xyz.h"
+#include "colour_conversion.h"
#include <boost/test/unit_test.hpp>
+#include <boost/scoped_array.hpp>
#include <iostream>
using std::list;
using boost::shared_ptr;
+using boost::scoped_array;
/* Build an encrypted picture MXF and a KDM for it and check that the KDM can be decrypted */
BOOST_AUTO_TEST_CASE (round_trip_test)
BOOST_CHECK (!kdm_B.keys().empty ());
mxf_B->set_key (kdm_B.keys().front().key());
- shared_ptr<dcp::ARGBImage> frame_A = mxf_A->get_frame(0)->argb_image ();
- shared_ptr<dcp::ARGBImage> frame_B = mxf_B->get_frame(0)->argb_image ();
- BOOST_CHECK_EQUAL (frame_A->size().width, frame_B->size().width);
- BOOST_CHECK_EQUAL (frame_A->size().height, frame_B->size().height);
- BOOST_CHECK_EQUAL (memcmp (frame_A->data(), frame_B->data(), frame_A->size().width * frame_A->size().height), 0);
+ shared_ptr<dcp::XYZImage> xyz_A = mxf_A->get_frame(0)->xyz_image ();
+ shared_ptr<dcp::XYZImage> xyz_B = mxf_B->get_frame(0)->xyz_image ();
+
+ scoped_array<uint8_t> frame_A (new uint8_t[xyz_A->size().width * xyz_A->size().height * 4]);
+ dcp::xyz_to_rgba (xyz_A, dcp::ColourConversion::xyz_to_srgb(), frame_A.get());
+
+ scoped_array<uint8_t> frame_B (new uint8_t[xyz_B->size().width * xyz_B->size().height * 4]);
+ dcp::xyz_to_rgba (xyz_B, dcp::ColourConversion::xyz_to_srgb(), frame_B.get());
+
+ BOOST_CHECK_EQUAL (xyz_A->size().width, xyz_B->size().width);
+ BOOST_CHECK_EQUAL (xyz_A->size().height, xyz_B->size().height);
+ BOOST_CHECK_EQUAL (memcmp (frame_A.get(), frame_B.get(), xyz_A->size().width * xyz_A->size().height * 4), 0);
}
else:
obj.use = 'libdcp%s' % bld.env.API_VERSION
obj.source = """
- argb_image_test.cc
certificates_test.cc
colour_test.cc
colour_conversion_test.cc
exception_test.cc
fraction_test.cc
frame_info_test.cc
- image_test.cc
interop_load_font_test.cc
local_time_test.cc
kdm_test.cc