Round image line sizes up to 32. Seems to help with LHS image corruption with both...
authorCarl Hetherington <cth@carlh.net>
Sun, 14 Oct 2012 19:29:20 +0000 (20:29 +0100)
committerCarl Hetherington <cth@carlh.net>
Sun, 14 Oct 2012 19:29:20 +0000 (20:29 +0100)
src/lib/dcp_video_frame.cc
src/lib/filter.cc
src/lib/image.cc
src/lib/util.cc
src/lib/util.h

index ce660add54075b46db6ce5b29700d3cbf98354d9..3e5c4b3aaa4cb5b7433712d8215ea14351a7b1a2 100644 (file)
@@ -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 */
index ab5a6316f93873eacd30ed2a9eb1773aaad0fa1f..446cc111dcdeeb7f0e22027969213aab6353a4fc 100644 (file)
@@ -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", ""));
index ce44ec95b4ebf479313260cb60b9b026aa173784..c8849303cac99e8ed01c1e6f6d5e80bffade6706 100644 (file)
@@ -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);
index 82aaf8ff5ca17ac208f67ca0b897756b106405a3..c3dd13d7c69d96a99f8466c274261010c41a8e69 100644 (file)
@@ -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);
+}
index 66c052c48f4865d57261cee3c1bddbc769b0eddf..244c018554e958b36bbec842d0335401353afeec 100644 (file)
@@ -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