summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mono_picture_frame.cc10
-rw-r--r--src/mono_picture_frame.h1
-rw-r--r--src/rgb_xyz.cc70
-rw-r--r--src/rgb_xyz.h5
-rw-r--r--src/stereo_picture_frame.cc16
-rw-r--r--src/stereo_picture_frame.h1
6 files changed, 103 insertions, 0 deletions
diff --git a/src/mono_picture_frame.cc b/src/mono_picture_frame.cc
index ec60104d..c2503a64 100644
--- a/src/mono_picture_frame.cc
+++ b/src/mono_picture_frame.cc
@@ -96,3 +96,13 @@ MonoPictureFrame::argb_frame (int reduce, float srgb_gamma) const
GammaLUT::cache.get (12, DCI_GAMMA, false), GammaLUT::cache.get (12, 1 / srgb_gamma, false)
);
}
+
+void
+MonoPictureFrame::rgb_frame (uint8_t* buffer) const
+{
+ xyz_to_rgb (
+ decompress_j2k (const_cast<uint8_t*> (_buffer->RoData()), _buffer->Size(), 0),
+ GammaLUT::cache.get (12, DCI_GAMMA, false), GammaLUT::cache.get (12, 1 / 2.4, false),
+ buffer
+ );
+}
diff --git a/src/mono_picture_frame.h b/src/mono_picture_frame.h
index cc6096cd..57e890a8 100644
--- a/src/mono_picture_frame.h
+++ b/src/mono_picture_frame.h
@@ -49,6 +49,7 @@ public:
~MonoPictureFrame ();
boost::shared_ptr<ARGBFrame> argb_frame (int reduce = 0, float srgb_gamma = 2.4) const;
+ void rgb_frame (uint8_t* buffer) const;
uint8_t const * j2k_data () const;
int j2k_size () const;
diff --git a/src/rgb_xyz.cc b/src/rgb_xyz.cc
index 42f48cde..6966a323 100644
--- a/src/rgb_xyz.cc
+++ b/src/rgb_xyz.cc
@@ -106,6 +106,76 @@ dcp::xyz_to_rgba (
return argb_frame;
}
+/** Convert an openjpeg XYZ image to RGB.
+ * @param xyz_frame Frame in XYZ.
+ * @param lut_in Input Gamma LUT to use.
+ * @param lut_out Output Gamma LUT to use.
+ * @param buffer Buffer to write RGB data to; will be written
+ * as one byte R, one byte G, one byte B, one byte R etc. with
+ * no padding at line ends.
+ */
+void
+dcp::xyz_to_rgb (
+ boost::shared_ptr<const XYZFrame> xyz_frame,
+ boost::shared_ptr<const GammaLUT> lut_in,
+ boost::shared_ptr<const GammaLUT> lut_out,
+ uint8_t* buffer
+ )
+{
+ int const max_colour = pow (2, lut_out->bit_depth()) - 1;
+
+ struct {
+ double x, y, z;
+ } s;
+
+ struct {
+ double r, g, b;
+ } d;
+
+ int* xyz_x = xyz_frame->data (0);
+ int* xyz_y = xyz_frame->data (1);
+ int* xyz_z = xyz_frame->data (2);
+
+ for (int y = 0; y < xyz_frame->size().height; ++y) {
+ uint8_t* buffer_line = buffer;
+ for (int x = 0; x < xyz_frame->size().width; ++x) {
+
+ assert (*xyz_x >= 0 && *xyz_y >= 0 && *xyz_z >= 0 && *xyz_x < 4096 && *xyz_y < 4096 && *xyz_z < 4096);
+
+ /* In gamma LUT */
+ s.x = lut_in->lut()[*xyz_x++];
+ s.y = lut_in->lut()[*xyz_y++];
+ s.z = lut_in->lut()[*xyz_z++];
+
+ /* DCI companding */
+ s.x /= DCI_COEFFICIENT;
+ s.y /= DCI_COEFFICIENT;
+ s.z /= DCI_COEFFICIENT;
+
+ /* XYZ to RGB */
+ d.r = ((s.x * colour_matrix::xyz_to_rgb[0][0]) + (s.y * colour_matrix::xyz_to_rgb[0][1]) + (s.z * colour_matrix::xyz_to_rgb[0][2]));
+ d.g = ((s.x * colour_matrix::xyz_to_rgb[1][0]) + (s.y * colour_matrix::xyz_to_rgb[1][1]) + (s.z * colour_matrix::xyz_to_rgb[1][2]));
+ d.b = ((s.x * colour_matrix::xyz_to_rgb[2][0]) + (s.y * colour_matrix::xyz_to_rgb[2][1]) + (s.z * colour_matrix::xyz_to_rgb[2][2]));
+
+ d.r = min (d.r, 1.0);
+ d.r = max (d.r, 0.0);
+
+ d.g = min (d.g, 1.0);
+ d.g = max (d.g, 0.0);
+
+ d.b = min (d.b, 1.0);
+ d.b = max (d.b, 0.0);
+
+ /* Out gamma LUT */
+ *buffer_line++ = lut_out->lut()[(int) (d.r * max_colour)] * 0xff;
+ *buffer_line++ = lut_out->lut()[(int) (d.g * max_colour)] * 0xff;
+ *buffer_line++ = lut_out->lut()[(int) (d.b * max_colour)] * 0xff;
+ }
+
+ buffer += xyz_frame->size().width * 3;
+ }
+}
+
shared_ptr<dcp::XYZFrame>
dcp::rgb_to_xyz (
boost::shared_ptr<const Image> rgb,
diff --git a/src/rgb_xyz.h b/src/rgb_xyz.h
index 998c6401..ee354d53 100644
--- a/src/rgb_xyz.h
+++ b/src/rgb_xyz.h
@@ -18,6 +18,7 @@
*/
#include <boost/shared_ptr.hpp>
+#include <stdint.h>
namespace dcp {
@@ -30,6 +31,10 @@ extern boost::shared_ptr<ARGBFrame> xyz_to_rgba (
boost::shared_ptr<const XYZFrame>, boost::shared_ptr<const GammaLUT>, boost::shared_ptr<const GammaLUT>
);
+extern void xyz_to_rgb (
+ boost::shared_ptr<const XYZFrame>, boost::shared_ptr<const GammaLUT>, boost::shared_ptr<const GammaLUT>, uint8_t* buffer
+ );
+
extern boost::shared_ptr<XYZFrame> rgb_to_xyz (
boost::shared_ptr<const Image>, boost::shared_ptr<const GammaLUT>, boost::shared_ptr<const GammaLUT>, double const colour_matrix[3][3]
);
diff --git a/src/stereo_picture_frame.cc b/src/stereo_picture_frame.cc
index 293573bd..9d9bef7d 100644
--- a/src/stereo_picture_frame.cc
+++ b/src/stereo_picture_frame.cc
@@ -87,6 +87,22 @@ StereoPictureFrame::argb_frame (Eye eye, int reduce, float srgb_gamma) const
return xyz_to_rgba (xyz_frame, GammaLUT::cache.get (12, DCI_GAMMA, false), GammaLUT::cache.get (12, 1 / srgb_gamma, false));
}
+void
+StereoPictureFrame::rgb_frame (Eye eye, uint8_t* buffer) const
+{
+ shared_ptr<XYZFrame> xyz_frame;
+ switch (eye) {
+ case LEFT:
+ xyz_frame = decompress_j2k (const_cast<uint8_t*> (_buffer->Left.RoData()), _buffer->Left.Size(), 0);
+ break;
+ case RIGHT:
+ xyz_frame = decompress_j2k (const_cast<uint8_t*> (_buffer->Right.RoData()), _buffer->Right.Size(), 0);
+ break;
+ }
+
+ return xyz_to_rgb (xyz_frame, GammaLUT::cache.get (12, DCI_GAMMA, false), GammaLUT::cache.get (12, 1 / 2.4, false), buffer);
+}
+
uint8_t const *
StereoPictureFrame::left_j2k_data () const
{
diff --git a/src/stereo_picture_frame.h b/src/stereo_picture_frame.h
index fe363da5..ed407cf9 100644
--- a/src/stereo_picture_frame.h
+++ b/src/stereo_picture_frame.h
@@ -43,6 +43,7 @@ public:
~StereoPictureFrame ();
boost::shared_ptr<ARGBFrame> argb_frame (Eye eye, int reduce = 0, float srgb_gamma = 2.4) const;
+ void rgb_frame (Eye eye, uint8_t* buffer) const;
uint8_t const * left_j2k_data () const;
int left_j2k_size () const;
uint8_t const * right_j2k_data () const;