18#include <peak_icv_c/algorithms/preprocessing/peak_icv_image_converter.h>
47 return "BayerAndMono";
57 const auto policyStr = std::to_string(
static_cast<int>(policy));
63 if (policy ==
"BayerAndMono")
67 if (policy ==
"BayerOnly")
71 if (policy ==
"Bypass")
265 m_targetBitDepth = bitDepth;
343 static constexpr int moduleVersion{ 1 };
344 static constexpr auto conversionPolicyKey{
"ConversionPolicy" };
345 static constexpr auto channelLayoutKey{
"ChannelLayout" };
347 peak_icv_image_converter_handle m_handle{};
351 size_t m_targetBitDepth{ 8 };
354 bool m_enabled{
true };
360 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ImageConverter_Create(&m_handle);
366 if (m_handle !=
nullptr)
368 std::ignore = PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ImageConverter_Destroy(m_handle);
374 m_channelLayout = other.m_channelLayout;
375 m_conversionPolicy = other.m_conversionPolicy;
376 m_enabled = other.m_enabled;
378 std::swap(m_handle, other.m_handle);
385 m_channelLayout = other.m_channelLayout;
386 m_conversionPolicy = other.m_conversionPolicy;
387 m_enabled = other.m_enabled;
388 std::swap(m_handle, other.m_handle);
397 archive.
SetInt(
"Version", moduleVersion);
405 const auto version = archive.
GetInt(
"Version");
436 ValidateChannelLayout(layout);
437 m_channelLayout = layout;
442 return m_channelLayout;
447 ValidateConversionPolicy(policy);
448 m_conversionPolicy = policy;
453 return m_conversionPolicy;
456inline size_t DebayerModule::GetOutputBitDepth(
const size_t inputBitDepth)
const
460 return (std::min)(inputBitDepth, m_targetBitDepth);
464 return (std::max)(inputBitDepth, m_targetBitDepth);
466 return inputBitDepth;
478 if (!info.IsSingleChannel())
484 const auto isMono = info.HasIntensityChannel();
491 const auto inputBitDepth = info.GetStorageBitsPerChannel();
492 const auto outputBitDepth = GetOutputBitDepth(inputBitDepth);
494 if (outputBitDepth <= 8)
496 switch (m_channelLayout)
508 if (outputBitDepth <= 10)
510 switch (m_channelLayout)
523 switch (m_channelLayout)
535 std::ostringstream oss;
536 oss <<
"0x" << std::uppercase << std::hex << static_cast<int>(inputFormat);
560 m_processingPolicy = policy;
578 const auto outputFormat = GetOutputFormat(inputFormat);
580 if (inputFormat == outputFormat)
585 auto*
const inputImageHandle = peak::common::detail::BackendAccessor<peak::icv::Image>::BackendHandle(inputImage);
589 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ImageConverter_Convert(
590 m_handle, inputImageHandle,
static_cast<peak_common_pixel_format
>(outputFormat), &outputHandle);
593 return peak::common::Any(peak::common::detail::BackendAccessor<peak::icv::Image>::CreateInstance(outputHandle));
599 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ImageConverter_ReleaseBuffers(m_handle);
A type-erased container for any copyable value.
T & AnyCast()
Casts the stored value to the specified type.
Interface for a hierarchical key-value archive system.
virtual void SetBool(const std::string &key, bool value)=0
Stores a boolean value.
virtual void SetInt(const std::string &key, int64_t value)=0
Stores a 64-bit signed integer.
virtual int64_t GetInt(const std::string &key) const =0
Retrieves a 64-bit signed integer by key.
virtual std::string GetString(const std::string &key) const =0
Retrieves a string value by key.
virtual bool GetBool(const std::string &key) const =0
Retrieves a boolean value by key.
virtual void SetString(const std::string &key, const std::string &value)=0
Stores a UTF-8 string.
For detailed information about the use of ids_peak_icv Image refer to the Image Guide.
peak::common::PixelFormat GetPixelFormat() const
Provides the pixel format of the image.
Thrown when a requested operation is not implemented or supported.
Debayer is an image pipeline module that converts Bayer RAW images into standard color formats.
const char * GetType() const override
Returns the type of the module for serialization purposes.
~DebayerModule() override
DebayerChannelLayout GetChannelLayout() const
Gets the current channel layout setting.
DebayerModule()
Creates an instance of class DebayerModule with default settings.
void ReleaseBuffers() const
Frees unused internal buffers.
DebayerModule(const DebayerModule &other)=delete
Copy constructor for class DebayerModule is deleted.
void Serialize(peak::common::serialization::IArchive &archive) const override
Serializes the object's internal state into the provided archive.
peak::icv::Image Process(const peak::icv::Image &input) const
Converts a Bayer or mono image to a color image, or passes through unmodified images.
void SetEnabled(bool enabled) override
Sets the enabled state of this module.
DebayerModule & operator=(const DebayerModule &other)=delete
Copy assignment for class DebayerModule is deleted.
void SetConversionPolicy(DebayerConversionPolicy policy)
Sets the conversion policy for the Debayer module.
void SetChannelLayout(DebayerChannelLayout layout)
Sets the desired channel layout for the output image.
void Deserialize(const peak::common::serialization::IArchive &archive) override
Restores the object's state from the provided archive.
void SetProcessingPolicy(ProcessingPolicy policy)
Set the processing policy.
void ResetToDefault() override
Resets the channel layout and the conversion policy to the default settings.
void SetTargetBitDepth(size_t bitDepth)
Set the target bit depth.
DebayerConversionPolicy GetConversionPolicy() const
Retrieves the current conversion policy.
bool IsEnabled() const override
Checks if the module is currently enabled.
Interface for a module used within a pipeline.
#define PEAK_COMMON_NO_DISCARD
Compatability macro for the nodiscard attribute.
PixelFormat
Enum listing all supported pixel formats and their internal IDs.
@ RGBa10
RGBA 10-Bit pixel format.
@ RGB8
RGB 8-Bit pixel format.
@ RGBa8
RGBA 8-Bit pixel format.
@ RGBa12
RGBA 12-Bit pixel format.
@ BGRa12
BGRA 12-Bit pixel format.
@ BGR12
BGR 12-Bit pixel format.
@ RGB10
RGB 10-Bit pixel format.
@ BGR10
BGR 10-Bit pixel format.
@ RGB12
RGB 12-Bit pixel format.
@ BGRa8
BGRA 8-Bit pixel format.
@ BGRa10
BGRA 10-Bit pixel format.
@ BGR8
BGR 8-Bit pixel format.
DebayerChannelLayout
Specifies the desired channel layout of the output image.
ProcessingPolicy
Specifies the processing policy.
@ BGR
Blue-Green-Red format with 3 channels.
@ BGRA
Blue-Green-Red-Alpha format with 4 channels.
@ RGB
Red-Green-Blue format with 3 channels.
@ RGBA
Red-Green-Blue-Alpha format with 4 channels.
@ Enhanced
Prefer quality.
void ExecuteAndMapReturnCodes(const CallableType &callableObject)
DebayerConversionPolicy
Defines the conditions under which the Debayer module performs color conversion.
@ Bypass
Do not convert images.
@ BayerOnly
Convert only Bayer-pattern images.
@ BayerAndMono
Convert both Bayer-pattern and monochrome images.
std::string ToString(const DebayerConversionPolicy &policy)
DebayerConversionPolicy ToDebayerConversionPolicy(const std::string &policy)
DebayerChannelLayout ToDebayerChannelLayout(const std::string &layout)
Converts a string representation to a DebayerChannelLayout enum value.
void ValidateVersion(int64_t version, const std::string &moduleName)
peak_icv_image * peak_icv_image_handle