From ed70b4faf0f53b106aebd4b9195ccc81da97880e Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 10 Oct 2012 20:35:05 +0100 Subject: Thumbs sort of have subs. --- src/lib/util.cc | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/lib/util.cc') diff --git a/src/lib/util.cc b/src/lib/util.cc index 935566440..82aaf8ff5 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -600,3 +600,16 @@ Socket::read_indefinite (uint8_t* data, int size, int timeout) assert (size >= _buffer_data); memcpy (data, _buffer, size); } + +Rectangle +Rectangle::intersection (Rectangle const & other) const +{ + int const tx = max (x, other.x); + int const ty = max (y, other.y); + + return Rectangle ( + tx, ty, + min (x + w, other.x + other.w) - tx, + min (y + h, other.y + other.h) - ty + ); +} -- cgit v1.2.3 From 129afab72bfc026b5704c41a6bfc0f4b3a2c4033 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 14 Oct 2012 20:29:20 +0100 Subject: Round image line sizes up to 32. Seems to help with LHS image corruption with both crop and a post-processing filter. --- src/lib/dcp_video_frame.cc | 58 ++++++++++++++++++++++++++++------------------ src/lib/filter.cc | 1 + src/lib/image.cc | 10 ++++---- src/lib/util.cc | 7 ++++++ src/lib/util.h | 1 + 5 files changed, 49 insertions(+), 28 deletions(-) (limited to 'src/lib/util.cc') diff --git a/src/lib/dcp_video_frame.cc b/src/lib/dcp_video_frame.cc index ce660add5..3e5c4b3aa 100644 --- a/src/lib/dcp_video_frame.cc +++ b/src/lib/dcp_video_frame.cc @@ -176,8 +176,6 @@ DCPVideoFrame::encode_locally () create_openjpeg_container (); - int const size = _out_size.width * _out_size.height; - struct { double r, g, b; } s; @@ -188,27 +186,41 @@ DCPVideoFrame::encode_locally () /* Copy our RGB into the openjpeg container, converting to XYZ in the process */ - uint8_t* p = prepared->data()[0]; - for (int i = 0; i < size; ++i) { - /* In gamma LUT (converting 8-bit input to 12-bit) */ - s.r = lut_in[_colour_lut_index][*p++ << 4]; - s.g = lut_in[_colour_lut_index][*p++ << 4]; - s.b = lut_in[_colour_lut_index][*p++ << 4]; - - /* RGB to XYZ Matrix */ - d.x = ((s.r * color_matrix[_colour_lut_index][0][0]) + (s.g * color_matrix[_colour_lut_index][0][1]) + (s.b * color_matrix[_colour_lut_index][0][2])); - d.y = ((s.r * color_matrix[_colour_lut_index][1][0]) + (s.g * color_matrix[_colour_lut_index][1][1]) + (s.b * color_matrix[_colour_lut_index][1][2])); - d.z = ((s.r * color_matrix[_colour_lut_index][2][0]) + (s.g * color_matrix[_colour_lut_index][2][1]) + (s.b * color_matrix[_colour_lut_index][2][2])); - - /* DCI companding */ - d.x = d.x * DCI_COEFFICENT * (DCI_LUT_SIZE - 1); - d.y = d.y * DCI_COEFFICENT * (DCI_LUT_SIZE - 1); - d.z = d.z * DCI_COEFFICENT * (DCI_LUT_SIZE - 1); - - /* Out gamma LUT */ - _image->comps[0].data[i] = lut_out[LO_DCI][(int) d.x]; - _image->comps[1].data[i] = lut_out[LO_DCI][(int) d.y]; - _image->comps[2].data[i] = lut_out[LO_DCI][(int) d.z]; + int jn = 0; + for (int y = 0; y < _out_size.height; ++y) { + uint8_t* p = prepared->data()[0] + y * prepared->line_size()[0]; + for (int x = 0; x < _out_size.width; ++x) { + + /* In gamma LUT (converting 8-bit input to 12-bit) */ + s.r = lut_in[_colour_lut_index][*p++ << 4]; + s.g = lut_in[_colour_lut_index][*p++ << 4]; + s.b = lut_in[_colour_lut_index][*p++ << 4]; + + /* RGB to XYZ Matrix */ + d.x = ((s.r * color_matrix[_colour_lut_index][0][0]) + + (s.g * color_matrix[_colour_lut_index][0][1]) + + (s.b * color_matrix[_colour_lut_index][0][2])); + + d.y = ((s.r * color_matrix[_colour_lut_index][1][0]) + + (s.g * color_matrix[_colour_lut_index][1][1]) + + (s.b * color_matrix[_colour_lut_index][1][2])); + + d.z = ((s.r * color_matrix[_colour_lut_index][2][0]) + + (s.g * color_matrix[_colour_lut_index][2][1]) + + (s.b * color_matrix[_colour_lut_index][2][2])); + + /* DCI companding */ + d.x = d.x * DCI_COEFFICENT * (DCI_LUT_SIZE - 1); + d.y = d.y * DCI_COEFFICENT * (DCI_LUT_SIZE - 1); + d.z = d.z * DCI_COEFFICENT * (DCI_LUT_SIZE - 1); + + /* Out gamma LUT */ + _image->comps[0].data[jn] = lut_out[LO_DCI][(int) d.x]; + _image->comps[1].data[jn] = lut_out[LO_DCI][(int) d.y]; + _image->comps[2].data[jn] = lut_out[LO_DCI][(int) d.z]; + + ++jn; + } } /* Set the max image and component sizes based on frame_rate */ diff --git a/src/lib/filter.cc b/src/lib/filter.cc index ab5a6316f..446cc111d 100644 --- a/src/lib/filter.cc +++ b/src/lib/filter.cc @@ -72,6 +72,7 @@ Filter::setup_filters () _filters.push_back (new Filter ("ppl5", "FIR low-pass deinterlacer", "", "l5")); _filters.push_back (new Filter ("mcdeint", "Motion compensating deinterlacer", "mcdeint", "")); _filters.push_back (new Filter ("kerndeint", "Kernel deinterlacer", "kerndeint", "")); + _filters.push_back (new Filter ("yadif", "Yet Another Deinterlacing Filter", "yadif", "")); _filters.push_back (new Filter ("pptn", "Temporal noise reducer", "", "tn")); _filters.push_back (new Filter ("ppfq", "Force quantizer", "", "fq")); _filters.push_back (new Filter ("gradfun", "Gradient debander", "gradfun", "")); diff --git a/src/lib/image.cc b/src/lib/image.cc index ce44ec95b..c8849303c 100644 --- a/src/lib/image.cc +++ b/src/lib/image.cc @@ -260,15 +260,15 @@ SimpleImage::SimpleImage (PixelFormat p, Size s) switch (p) { case PIX_FMT_RGB24: - _line_size[0] = s.width * 3; + _line_size[0] = round_up (s.width * 3, 32); break; case PIX_FMT_RGBA: - _line_size[0] = s.width * 4; + _line_size[0] = round_up (s.width * 4, 32); break; case PIX_FMT_YUV420P: - _line_size[0] = s.width; - _line_size[1] = s.width / 2; - _line_size[2] = s.width / 2; + _line_size[0] = round_up (s.width, 32); + _line_size[1] = round_up (s.width / 2, 32); + _line_size[2] = round_up (s.width / 2, 32); break; default: assert (false); diff --git a/src/lib/util.cc b/src/lib/util.cc index 82aaf8ff5..c3dd13d7c 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -613,3 +613,10 @@ Rectangle::intersection (Rectangle const & other) const min (y + h, other.y + other.h) - ty ); } + +int +round_up (int a, int t) +{ + a += (t - 1); + return a - (a % t); +} diff --git a/src/lib/util.h b/src/lib/util.h index 66c052c48..244c01855 100644 --- a/src/lib/util.h +++ b/src/lib/util.h @@ -149,6 +149,7 @@ struct Rectangle extern std::string crop_string (Position, Size); extern int dcp_audio_sample_rate (int); extern std::string colour_lut_index_to_name (int index); +extern int round_up (int, int); /** @class Socket * @brief A class to wrap a boost::asio::ip::tcp::socket with some things -- cgit v1.2.3