summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2015-01-07 10:55:47 +0000
committerCarl Hetherington <cth@carlh.net>2015-01-07 10:55:47 +0000
commit107482fc19404e20db544e989d880752377fde26 (patch)
treee6d8dc6857d79bf355d08248df4287bb4a838ef1 /src
parent1ec06907de2eb4382e5f0e6f9953e3026f1461e7 (diff)
Clamp out-of-range XYZ values in xyz_to_rgb() and pass notes about their existance.
Diffstat (limited to 'src')
-rw-r--r--src/rgb_xyz.cc38
-rw-r--r--src/rgb_xyz.h9
2 files changed, 40 insertions, 7 deletions
diff --git a/src/rgb_xyz.cc b/src/rgb_xyz.cc
index a3f7b424..a839dfa0 100644
--- a/src/rgb_xyz.cc
+++ b/src/rgb_xyz.cc
@@ -25,11 +25,13 @@
#include "colour_conversion.h"
#include "transfer_function.h"
#include "dcp_assert.h"
+#include "compose.hpp"
#include <cmath>
using std::min;
using std::max;
using boost::shared_ptr;
+using boost::optional;
using namespace dcp;
#define DCI_COEFFICIENT (48.0 / 52.37)
@@ -119,7 +121,8 @@ void
dcp::xyz_to_rgb (
boost::shared_ptr<const XYZFrame> xyz_frame,
ColourConversion const & conversion,
- uint16_t* buffer
+ uint16_t* buffer,
+ optional<NoteHandler> note
)
{
struct {
@@ -143,12 +146,35 @@ dcp::xyz_to_rgb (
uint16_t* buffer_line = buffer;
for (int x = 0; x < xyz_frame->size().width; ++x) {
- DCP_ASSERT (*xyz_x >= 0 && *xyz_y >= 0 && *xyz_z >= 0 && *xyz_x < 4096 && *xyz_y < 4096 && *xyz_z < 4096);
-
+ int cx = *xyz_x++;
+ int cy = *xyz_y++;
+ int cz = *xyz_z++;
+
+ if (cx < 0 || cx > 4095) {
+ if (note) {
+ note.get() (DCP_NOTE, String::compose ("XYZ value %1 out of range", cx));
+ }
+ cx = max (min (cx, 4095), 0);
+ }
+
+ if (cy < 0 || cy > 4095) {
+ if (note) {
+ note.get() (DCP_NOTE, String::compose ("XYZ value %1 out of range", cy));
+ }
+ cy = max (min (cy, 4095), 0);
+ }
+
+ if (cz < 0 || cz > 4095) {
+ if (note) {
+ note.get() (DCP_NOTE, String::compose ("XYZ value %1 out of range", cz));
+ }
+ cz = max (min (cz, 4095), 0);
+ }
+
/* In gamma LUT */
- s.x = lut_in[*xyz_x++];
- s.y = lut_in[*xyz_y++];
- s.z = lut_in[*xyz_z++];
+ s.x = lut_in[cx];
+ s.y = lut_in[cy];
+ s.z = lut_in[cz];
/* DCI companding */
s.x /= DCI_COEFFICIENT;
diff --git a/src/rgb_xyz.h b/src/rgb_xyz.h
index 4dd25b28..53568350 100644
--- a/src/rgb_xyz.h
+++ b/src/rgb_xyz.h
@@ -17,7 +17,9 @@
*/
+#include "types.h"
#include <boost/shared_ptr.hpp>
+#include <boost/optional.hpp>
#include <stdint.h>
namespace dcp {
@@ -28,7 +30,12 @@ class Image;
class ColourConversion;
extern boost::shared_ptr<ARGBFrame> xyz_to_rgba (boost::shared_ptr<const XYZFrame>, ColourConversion const & conversion);
-extern void xyz_to_rgb (boost::shared_ptr<const XYZFrame>, ColourConversion const & conversion, uint16_t* buffer);
+extern void xyz_to_rgb (
+ boost::shared_ptr<const XYZFrame>,
+ ColourConversion const & conversion,
+ uint16_t* buffer,
+ boost::optional<NoteHandler> note = boost::optional<NoteHandler> ()
+ );
extern boost::shared_ptr<XYZFrame> rgb_to_xyz (boost::shared_ptr<const Image>, ColourConversion const & conversion);
extern boost::shared_ptr<XYZFrame> xyz_to_xyz (boost::shared_ptr<const Image>);