Fix auto-crop with DCPs (#2999).
authorCarl Hetherington <cth@carlh.net>
Wed, 19 Mar 2025 20:53:20 +0000 (21:53 +0100)
committerCarl Hetherington <cth@carlh.net>
Wed, 19 Mar 2025 20:53:20 +0000 (21:53 +0100)
src/lib/guess_crop.cc
test/guess_crop_test.cc

index 7089d245d4f652b0ba3b695bcad0819a9b8cd39c..7213eb668ca6b445e0e6c24264e603b5cec46f6b 100644 (file)
@@ -109,6 +109,16 @@ guess_crop_by_brightness(shared_ptr<const Image> image, double threshold)
                        }
                        break;
                }
+               case AV_PIX_FMT_XYZ12LE:
+               {
+                       uint16_t const* data = reinterpret_cast<uint16_t*>(image->data()[0] + (start_x * 6) + (start_y * image->stride()[0]));
+                       for (int p = 0; p < pixels; ++p) {
+                               /* Just using Y */
+                               brightest = std::max(brightest, static_cast<double>(data[1]) / 4096);
+                               data += rows ? 3 : (image->stride()[0] / 2);
+                       }
+                       break;
+               }
                default:
                        throw PixelFormatError("guess_crop_by_brightness()", image->pixel_format());
                }
index b62042d1a42fb42a8f91711da72f3f861f1de81a..9ce089a802b61ae3aa0172885caba50f00f49171 100644 (file)
 
 #include "lib/content.h"
 #include "lib/content_factory.h"
+#include "lib/dcp_content.h"
 #include "lib/guess_crop.h"
 #include "lib/video_content.h"
 #include "test.h"
 #include <boost/test/unit_test.hpp>
-#include <iostream>
 #include <vector>
 
 
+using std::make_shared;
 using namespace dcpomatic;
 
 
@@ -57,3 +58,13 @@ BOOST_AUTO_TEST_CASE (guess_crop_image_test3)
 
        BOOST_CHECK(guess_crop_by_brightness(film, content[0], 0.1, {}) == Crop(113, 262, 0, 0));
 }
+
+
+BOOST_AUTO_TEST_CASE(guess_crop_image_dcp_test)
+{
+       auto content = make_shared<DCPContent>("test/data/scaling_test_133_185");
+       auto film = new_test_film("guess_crop_image_dcp_test", { content });
+
+       BOOST_CHECK(guess_crop_by_brightness(film, content, 0.1, {}) == Crop(279, 279, 0, 0));
+}
+