18#include <peak_icv_c/algorithms/preprocessing/peak_icv_image_converter.h>
45 if (policy == DebayerConversionPolicy::BayerAndMono)
47 return "BayerAndMono";
49 if (policy == DebayerConversionPolicy::BayerOnly)
53 if (policy == DebayerConversionPolicy::Bypass)
57 const auto policyStr = std::to_string(
static_cast<int>(policy));
63 if (policy ==
"BayerAndMono")
65 return DebayerConversionPolicy::BayerAndMono;
67 if (policy ==
"BayerOnly")
69 return DebayerConversionPolicy::BayerOnly;
71 if (policy ==
"Bypass")
73 return DebayerConversionPolicy::Bypass;
194 PEAK_COMMON_NO_DISCARD
bool IsEnabled()
const override;
203 PEAK_COMMON_NO_DISCARD
const char*
GetType()
const override;
270 m_targetBitDepth = bitDepth;
346 PEAK_COMMON_NO_DISCARD
size_t GetOutputBitDepth(
size_t inputBitDepth)
const;
351 static constexpr int moduleVersion{ 1 };
352 static constexpr auto conversionPolicyKey{
"ConversionPolicy" };
353 static constexpr auto channelLayoutKey{
"ChannelLayout" };
355 peak_icv_image_converter_handle m_handle{};
359 size_t m_targetBitDepth{ 8 };
362 bool m_enabled{
true };
368 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ImageConverter_Create(&m_handle);
374 if (m_handle !=
nullptr)
376 std::ignore = PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ImageConverter_Destroy(m_handle);
382 m_channelLayout = other.m_channelLayout;
383 m_conversionPolicy = other.m_conversionPolicy;
384 m_enabled = other.m_enabled;
386 std::swap(m_handle, other.m_handle);
393 m_channelLayout = other.m_channelLayout;
394 m_conversionPolicy = other.m_conversionPolicy;
395 m_enabled = other.m_enabled;
396 std::swap(m_handle, other.m_handle);
405 archive.
SetInt(
"Version", moduleVersion);
413 const auto version = archive.
GetInt(
"Version");
423 m_channelLayout = DebayerChannelLayout::RGB;
424 m_conversionPolicy = DebayerConversionPolicy::BayerOnly;
444 ValidateChannelLayout(layout);
445 m_channelLayout = layout;
450 return m_channelLayout;
455 ValidateConversionPolicy(policy);
456 m_conversionPolicy = policy;
461 return m_conversionPolicy;
464inline size_t DebayerModule::GetOutputBitDepth(
const size_t inputBitDepth)
const
466 if (m_processingPolicy == ProcessingPolicy::Fast)
468 return (std::min)(inputBitDepth, m_targetBitDepth);
470 if (m_processingPolicy == ProcessingPolicy::Enhanced)
472 return (std::max)(inputBitDepth, m_targetBitDepth);
474 return inputBitDepth;
479 if (m_conversionPolicy == DebayerConversionPolicy::Bypass)
486 if (!info.IsSingleChannel())
492 const auto isMono = info.HasIntensityChannel();
494 if (!isBayer && (!isMono || m_conversionPolicy != DebayerConversionPolicy::BayerAndMono))
499 const auto inputBitDepth = info.GetStorageBitsPerChannel();
500 const auto outputBitDepth = GetOutputBitDepth(inputBitDepth);
502 if (outputBitDepth <= 8)
504 switch (m_channelLayout)
506 case DebayerChannelLayout::RGB:
508 case DebayerChannelLayout::BGR:
510 case DebayerChannelLayout::RGBA:
512 case DebayerChannelLayout::BGRA:
516 if (outputBitDepth <= 10)
518 switch (m_channelLayout)
520 case DebayerChannelLayout::RGB:
522 case DebayerChannelLayout::BGR:
524 case DebayerChannelLayout::RGBA:
526 case DebayerChannelLayout::BGRA:
531 switch (m_channelLayout)
533 case DebayerChannelLayout::RGB:
535 case DebayerChannelLayout::BGR:
537 case DebayerChannelLayout::RGBA:
539 case DebayerChannelLayout::BGRA:
543 std::ostringstream oss;
544 oss <<
"0x" << std::uppercase << std::hex << static_cast<int>(inputFormat);
550 if (layout != DebayerChannelLayout::RGB && layout != DebayerChannelLayout::BGR && layout != DebayerChannelLayout::RGBA
551 && layout != DebayerChannelLayout::BGRA)
559 if (policy != DebayerConversionPolicy::BayerOnly && policy != DebayerConversionPolicy::BayerAndMono
560 && policy != DebayerConversionPolicy::Bypass)
568 m_processingPolicy = policy;
586 const auto outputFormat = GetOutputFormat(inputFormat);
588 if (inputFormat == outputFormat)
593 auto*
const inputImageHandle = peak::common::detail::BackendAccessor<peak::icv::Image>::BackendHandle(inputImage);
597 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ImageConverter_Convert(
601 return peak::common::Any(peak::common::detail::BackendAccessor<peak::icv::Image>::CreateInstance(outputHandle));
607 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ImageConverter_ReleaseBuffers(m_handle);
IDSImaging.Peak.ICV.Pipeline.Types.DebayerChannelLayout DebayerChannelLayout
IDSImaging.Peak.ICV.Pipeline.Types.ProcessingPolicy ProcessingPolicy
IDSImaging.Peak.ICV.Pipeline.Types.DebayerConversionPolicy DebayerConversionPolicy
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.
Occurs when a requested operation is not implemented or supported (e.g., exporting to an unsupported ...
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 returns the input image unchanged.
void SetEnabled(bool enabled) override
Enables or disables the module.
DebayerModule & operator=(const DebayerModule &other)=delete
Copy assignment for class DebayerModule is deleted.
void SetConversionPolicy(DebayerConversionPolicy policy)
Set the debayer conversion policy.
void SetChannelLayout(DebayerChannelLayout layout)
Set the output channel layout for debayered images.
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 all module settings to its default settings.
void SetTargetBitDepth(size_t bitDepth)
Set the target bit depth for processed images.
DebayerConversionPolicy GetConversionPolicy() const
Retrieves the current conversion policy.
bool IsEnabled() const override
Gets whether this module is currently enabled.
Interface for a module used within a pipeline.
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.
DebayerConversionPolicy
Specifies 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.
DebayerChannelLayout
Specifies the channel layout used by the debayer module in image processing pipelines.
ProcessingPolicy
Specifies the processing policy.
constexpr peak_common_pixel_format CppPixelFormatToCPixelFormat(PixelFormat pixelFormat) noexcept
void ExecuteAndMapReturnCodes(const CallableType &callableObject)
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