summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2025-09-20 00:48:29 +0200
committerCarl Hetherington <cth@carlh.net>2025-09-30 00:06:04 +0200
commit1ac572e5b5d478c72fa3eb1fb0ab3bcf47532f71 (patch)
tree651a4aecd516470eba0f6a98a725c6e1745e104d /src/lib
parentb1da98c7d38bdf042d777b3a5878120c10868446 (diff)
Move DCPVideo::convert_to_xyz() to a free-standing function.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/colour_conversion.cc31
-rw-r--r--src/lib/colour_conversion.h14
-rw-r--r--src/lib/dcp_video.cc28
-rw-r--r--src/lib/dcp_video.h2
4 files changed, 47 insertions, 28 deletions
diff --git a/src/lib/colour_conversion.cc b/src/lib/colour_conversion.cc
index 588a388e3..f15847f01 100644
--- a/src/lib/colour_conversion.cc
+++ b/src/lib/colour_conversion.cc
@@ -27,10 +27,15 @@
#include <dcp/gamma_transfer_function.h>
#include <dcp/identity_transfer_function.h>
#include <dcp/modified_gamma_transfer_function.h>
+#include <dcp/openjpeg_image.h>
#include <dcp/raw_convert.h>
+#include <dcp/rgb_xyz.h>
#include <dcp/s_gamut3_transfer_function.h>
#include <dcp/warnings.h>
#include <libcxml/cxml.h>
+extern "C" {
+#include <libavutil/pixdesc.h>
+}
LIBDCP_DISABLE_WARNINGS
#include <libxml++/libxml++.h>
LIBDCP_ENABLE_WARNINGS
@@ -305,3 +310,29 @@ PresetColourConversion::from_id(string s)
DCPOMATIC_ASSERT(false);
}
+
+
+shared_ptr<dcp::OpenJPEGImage>
+convert_to_xyz(shared_ptr<const PlayerVideo> frame)
+{
+ shared_ptr<dcp::OpenJPEGImage> xyz;
+
+ auto conversion = [](AVPixelFormat fmt) {
+ return fmt == AV_PIX_FMT_XYZ12LE ? AV_PIX_FMT_XYZ12LE : AV_PIX_FMT_RGB48LE;
+ };
+
+ auto image = frame->image(conversion, VideoRange::FULL, false);
+
+ if (frame->colour_conversion()) {
+ xyz = dcp::rgb_to_xyz(
+ image->data()[0],
+ image->size(),
+ image->stride()[0],
+ frame->colour_conversion().get()
+ );
+ } else {
+ xyz = make_shared<dcp::OpenJPEGImage>(image->data()[0], image->size(), image->stride()[0]);
+ }
+
+ return xyz;
+}
diff --git a/src/lib/colour_conversion.h b/src/lib/colour_conversion.h
index 0e2fcc548..748bc4dd1 100644
--- a/src/lib/colour_conversion.h
+++ b/src/lib/colour_conversion.h
@@ -21,18 +21,28 @@
#ifndef DCPOMATIC_COLOUR_CONVERSION_H
#define DCPOMATIC_COLOUR_CONVERSION_H
+
/* Hack for OS X compile failure; see https://bugs.launchpad.net/hugin/+bug/910160 */
#ifdef check
#undef check
#endif
+
#include <dcp/colour_conversion.h>
#include <libcxml/cxml.h>
+
+namespace dcp {
+ class OpenJPEGImage;
+}
+
namespace xmlpp {
class Node;
}
+class PlayerVideo;
+
+
class ColourConversion : public dcp::ColourConversion
{
public:
@@ -77,4 +87,8 @@ bool operator==(ColourConversion const &, ColourConversion const &);
bool operator!=(ColourConversion const &, ColourConversion const &);
bool operator==(PresetColourConversion const &, PresetColourConversion const &);
+
+std::shared_ptr<dcp::OpenJPEGImage> convert_to_xyz(std::shared_ptr<const PlayerVideo> frame);
+
+
#endif
diff --git a/src/lib/dcp_video.cc b/src/lib/dcp_video.cc
index 775298091..f36410390 100644
--- a/src/lib/dcp_video.cc
+++ b/src/lib/dcp_video.cc
@@ -99,30 +99,6 @@ DCPVideo::DCPVideo(shared_ptr<const PlayerVideo> frame, shared_ptr<const cxml::N
_resolution = Resolution(node->optional_number_child<int>("Resolution").get_value_or(static_cast<int>(Resolution::TWO_K)));
}
-shared_ptr<dcp::OpenJPEGImage>
-DCPVideo::convert_to_xyz(shared_ptr<const PlayerVideo> frame)
-{
- shared_ptr<dcp::OpenJPEGImage> xyz;
-
- auto conversion = [](AVPixelFormat fmt) {
- return fmt == AV_PIX_FMT_XYZ12LE ? AV_PIX_FMT_XYZ12LE : AV_PIX_FMT_RGB48LE;
- };
-
- auto image = frame->image(conversion, VideoRange::FULL, false);
-
- if (frame->colour_conversion()) {
- xyz = dcp::rgb_to_xyz(
- image->data()[0],
- image->size(),
- image->stride()[0],
- frame->colour_conversion().get()
- );
- } else {
- xyz = make_shared<dcp::OpenJPEGImage>(image->data()[0], image->size(), image->stride()[0]);
- }
-
- return xyz;
-}
dcp::Size
DCPVideo::get_size() const
@@ -161,7 +137,7 @@ DCPVideo::encode_locally() const
int const minimum_size = 16384;
LOG_DEBUG_ENCODE("Using minimum frame size {}", minimum_size);
- auto xyz = convert_to_xyz(_frame);
+ auto xyz = ::convert_to_xyz(_frame);
int noise_amount = 2;
int pixel_skip = 16;
while (true) {
@@ -186,7 +162,7 @@ DCPVideo::encode_locally() const
* convert_to_xyz() again because compress_j2k() corrupts its xyz parameter.
*/
- xyz = convert_to_xyz(_frame);
+ xyz = ::convert_to_xyz(_frame);
auto size = xyz->size();
auto pixels = size.width * size.height;
dcpomatic::RNG rng(42);
diff --git a/src/lib/dcp_video.h b/src/lib/dcp_video.h
index 6afbedfad..8ecae20a9 100644
--- a/src/lib/dcp_video.h
+++ b/src/lib/dcp_video.h
@@ -66,8 +66,6 @@ public:
bool same(std::shared_ptr<const DCPVideo> other) const;
- static std::shared_ptr<dcp::OpenJPEGImage> convert_to_xyz(std::shared_ptr<const PlayerVideo> frame);
-
void convert_to_xyz(uint16_t* dst) const;
dcp::Size get_size() const;