Remove Image and ARGBImage and just dump RGB data into
authorCarl Hetherington <cth@carlh.net>
Mon, 2 Feb 2015 22:33:27 +0000 (22:33 +0000)
committerCarl Hetherington <cth@carlh.net>
Mon, 2 Feb 2015 22:33:27 +0000 (22:33 +0000)
uint8_t* buffers.  This is hopefully simpler than trying
to come up with some Image hierarchy that suits everything.

21 files changed:
examples/read_dcp.cc
src/argb_image.cc [deleted file]
src/argb_image.h [deleted file]
src/image.cc [deleted file]
src/image.h [deleted file]
src/mono_picture_frame.cc
src/mono_picture_frame.h
src/rgb_xyz.cc
src/rgb_xyz.h
src/stereo_picture_frame.cc
src/stereo_picture_frame.h
src/types.h
src/util.cc
src/util.h
src/wscript
test/argb_image_test.cc [deleted file]
test/decryption_test.cc
test/image_test.cc [deleted file]
test/rgb_xyz_test.cc
test/round_trip_test.cc
test/wscript

index 901ef8ce6b349d1e662b0d45085cdbdd262dd46b..d1416b28a9779956884d68ac72c0fe532448eadb 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    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.
@@ -80,10 +83,14 @@ main ()
        /* 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;
diff --git a/src/argb_image.cc b/src/argb_image.cc
deleted file mode 100644 (file)
index 79dcd85..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
-    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;
-}
diff --git a/src/argb_image.h b/src/argb_image.h
deleted file mode 100644 (file)
index 805d0a2..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
-    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
-};
-
-}
diff --git a/src/image.cc b/src/image.cc
deleted file mode 100644 (file)
index 15ff24d..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
-    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);
-}
diff --git a/src/image.h b/src/image.h
deleted file mode 100644 (file)
index 7033564..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
-    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;
-};
-
-}
index 1edfd4119575e13b552ce239c9b8c96da4eac54a..689a8b21f6c199b6ce6d7fb39cacd94c43161607 100644 (file)
@@ -23,7 +23,6 @@
 
 #include "mono_picture_frame.h"
 #include "exceptions.h"
-#include "argb_image.h"
 #include "util.h"
 #include "rgb_xyz.h"
 #include "colour_conversion.h"
@@ -112,29 +111,9 @@ MonoPictureFrame::j2k_size () const
 /** @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);
 }
index c9183a12a961033869a8952c1d53cbf569b751d9..9108926203b57b936aefc7e4941b48ccee682281 100644 (file)
@@ -38,8 +38,7 @@ namespace ASDCP {
 
 namespace dcp {
 
-class ARGBImage;
-class Image;
+class XYZImage;
 
 /** @class MonoPictureFrame
  *  @brief A single frame of a 2D (monoscopic) picture asset.
@@ -52,8 +51,8 @@ public:
        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;
index f44b1a304ee438d5e1bcd452b8b78878ea3138fc..97755b78d3c7b320ab0e7f93584bbbec4563cb31 100644 (file)
@@ -18,9 +18,7 @@
 */
 
 #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"
@@ -36,14 +34,26 @@ using namespace dcp;
 
 #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;
@@ -60,16 +70,16 @@ dcp::xyz_to_rgba (
        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);
                        
@@ -103,26 +113,27 @@ dcp::xyz_to_rgba (
                        *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
        )
 {
@@ -144,7 +155,7 @@ dcp::xyz_to_rgb (
        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++;
@@ -203,16 +214,21 @@ dcp::xyz_to_rgb (
        }
 }
 
-/** 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;
@@ -227,9 +243,9 @@ dcp::rgb_to_xyz (
        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];
@@ -263,18 +279,19 @@ dcp::rgb_to_xyz (
 }
 
 
-/** 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;
index cd0125cb04a4b8827601b5e49ec72838b15d9829..5d1a4d172a8f24807edadbdaf2d68aa1e731ed3a 100644 (file)
@@ -29,14 +29,21 @@ class XYZImage;
 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);
        
 }
index 0eae758357949d2e20304408af58045387c72a6c..ac7d7bf19acd8095eb1fc5da12f0a7026018dd85 100644 (file)
@@ -19,7 +19,6 @@
 
 #include "stereo_picture_frame.h"
 #include "exceptions.h"
-#include "argb_image.h"
 #include "util.h"
 #include "rgb_xyz.h"
 #include "colour_conversion.h"
@@ -67,43 +66,18 @@ StereoPictureFrame::~StereoPictureFrame ()
  *  @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 *
index ba78d92203f28f77507f55d3c7c6bfc379c25b37..0aeb68493931033e6d5cc02b348ac242cdf20dd1 100644 (file)
@@ -28,13 +28,11 @@ namespace ASDCP {
        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
@@ -44,11 +42,12 @@ public:
        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;
index 594bd7b7676c64b3512b8399e24666f34888795e..4c303e0d96474bc4b4c103d89d214870a2ca2d9a 100644 (file)
@@ -35,6 +35,29 @@ namespace parse {
        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
index 89b563ae7ff437d90af28723f50c110f8685bfc6..044801b79ba6376dd1a723f50c4b18b59eee81e4 100644 (file)
@@ -24,7 +24,6 @@
 #include "util.h"
 #include "exceptions.h"
 #include "types.h"
-#include "argb_image.h"
 #include "certificates.h"
 #include "xyz_image.h"
 #include "dcp_assert.h"
index 5bc3a78d55a9acb7dd78204a716719f0ee8e46f9..dbcec78ccb4789713939b97bce76a5158e0fb3c9 100644 (file)
@@ -43,29 +43,6 @@ class ARGBImage;
 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);
index af7b823e47253f186a9af3bc1c6fd4139daa12fa..f85b00328e47905b54653aa2aaeb002403b5a949 100644 (file)
@@ -2,7 +2,6 @@ from waflib import TaskGen
 
 def build(bld):
     source = """
-             argb_image.cc
              asset.cc
              certificate_chain.cc
              certificates.cc
@@ -19,7 +18,6 @@ def build(bld):
              file.cc
              font.cc
              gamma_transfer_function.cc
-             image.cc
              interop_load_font.cc
              interop_subtitle_content.cc
              key.cc
@@ -78,7 +76,6 @@ def build(bld):
               encrypted_kdm.h
               exceptions.h
               gamma_transfer_function.h
-              image.h
               interop_load_font.h
               interop_subtitle_content.h
               key.h
@@ -104,7 +101,6 @@ def build(bld):
               reel_stereo_picture_asset.h
               reel_subtitle_asset.h
               ref.h
-              argb_image.h
               signer.h
               smpte_load_font.h
               smpte_subtitle_content.h
diff --git a/test/argb_image_test.cc b/test/argb_image_test.cc
deleted file mode 100644 (file)
index e88d208..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
-    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));
-}
index a28f3c640e2f3a70e022f8039cae9c13feb2a55c..282e74f391ad0ad63fd80374a59e44038397fcec 100644 (file)
 
 */
 
-#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 ();
@@ -41,7 +47,11 @@ get_frame (dcp::DCP const & dcp)
 
        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 */
@@ -68,14 +78,24 @@ BOOST_AUTO_TEST_CASE (decryption_test)
        
        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 */
diff --git a/test/image_test.cc b/test/image_test.cc
deleted file mode 100644 (file)
index 216c3c5..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
-    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 ());
-}
index 6ee62dbf2a86b5ad89d59d61e7dd5ee27dc7b2fd..26411870914f56d17eaee383637c2b0b1d75f3ee 100644 (file)
 
 */
 
-#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)
@@ -65,9 +37,9 @@ 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) {
@@ -77,10 +49,10 @@ BOOST_AUTO_TEST_CASE (rgb_xyz_test)
                }
        }
 
-       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;
@@ -159,10 +131,10 @@ BOOST_AUTO_TEST_CASE (xyz_rgb_range_test)
        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 (&note_handler, _1, _2)));
+       dcp::xyz_to_rgb (xyz, dcp::ColourConversion::xyz_to_srgb (), rgb.get(), 2 * 6, boost::optional<dcp::NoteHandler> (boost::bind (&note_handler, _1, _2)));
 
        /* The 6 out-of-range samples should have been noted */
        BOOST_REQUIRE_EQUAL (notes.size(), 6);
@@ -178,7 +150,7 @@ BOOST_AUTO_TEST_CASE (xyz_rgb_range_test)
           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]);
index 6f5372ecabad5f4b256524229ebb4c49e9398d4b..dcaa6939999326d39b2c6b0b4ca8a70d43df6718 100644 (file)
 #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)
@@ -102,9 +106,16 @@ 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);
 }
index b723f54c357e7be18f4495ecf2a700dcec8454ae..09bcb13233a90ef62571ad02743fcdcf56bb6baa 100644 (file)
@@ -25,7 +25,6 @@ def build(bld):
     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
@@ -38,7 +37,6 @@ def build(bld):
                  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