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")
193 PEAK_COMMON_NO_DISCARD
bool IsEnabled()
const override;
202 PEAK_COMMON_NO_DISCARD
const char*
GetType()
const override;
266 m_targetBitDepth = bitDepth;
339 PEAK_COMMON_NO_DISCARD
size_t GetOutputBitDepth(
size_t inputBitDepth)
const;
344 static constexpr int moduleVersion{ 1 };
345 static constexpr auto conversionPolicyKey{
"ConversionPolicy" };
346 static constexpr auto channelLayoutKey{
"ChannelLayout" };
348 peak_icv_image_converter_handle m_handle{};
352 size_t m_targetBitDepth{ 8 };
355 bool m_enabled{
true };
361 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ImageConverter_Create(&m_handle);
367 if (m_handle !=
nullptr)
369 std::ignore = PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ImageConverter_Destroy(m_handle);
375 m_channelLayout = other.m_channelLayout;
376 m_conversionPolicy = other.m_conversionPolicy;
377 m_enabled = other.m_enabled;
379 std::swap(m_handle, other.m_handle);
386 m_channelLayout = other.m_channelLayout;
387 m_conversionPolicy = other.m_conversionPolicy;
388 m_enabled = other.m_enabled;
389 std::swap(m_handle, other.m_handle);
398 archive.
SetInt(
"Version", moduleVersion);
406 const auto version = archive.
GetInt(
"Version");
437 ValidateChannelLayout(layout);
438 m_channelLayout = layout;
443 return m_channelLayout;
448 ValidateConversionPolicy(policy);
449 m_conversionPolicy = policy;
454 return m_conversionPolicy;
457inline size_t DebayerModule::GetOutputBitDepth(
const size_t inputBitDepth)
const
461 return (std::min)(inputBitDepth, m_targetBitDepth);
465 return (std::max)(inputBitDepth, m_targetBitDepth);
467 return inputBitDepth;
479 if (!info.IsSingleChannel())
485 const auto isMono = info.HasIntensityChannel();
492 const auto inputBitDepth = info.GetStorageBitsPerChannel();
493 const auto outputBitDepth = GetOutputBitDepth(inputBitDepth);
495 if (outputBitDepth <= 8)
497 switch (m_channelLayout)
509 if (outputBitDepth <= 10)
511 switch (m_channelLayout)
524 switch (m_channelLayout)
536 std::ostringstream oss;
537 oss <<
"0x" << std::uppercase << std::hex << static_cast<int>(inputFormat);
561 m_processingPolicy = policy;
579 const auto outputFormat = GetOutputFormat(inputFormat);
581 if (inputFormat == outputFormat)
586 auto*
const inputImageHandle = peak::common::detail::BackendAccessor<peak::icv::Image>::BackendHandle(inputImage);
590 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ImageConverter_Convert(
591 m_handle, inputImageHandle,
static_cast<peak_common_pixel_format
>(outputFormat), &outputHandle);
594 return peak::common::Any(peak::common::detail::BackendAccessor<peak::icv::Image>::CreateInstance(outputHandle));
600 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.
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
Defines the conditions under which the Debayer module performs color conversion.
DebayerChannelLayout
Specifies the desired channel layout of the output image.
ProcessingPolicy
Specifies the processing policy.
@ Bypass
Do not convert images.
@ BayerOnly
Convert only Bayer-pattern images.
@ BayerAndMono
Convert both Bayer-pattern and monochrome images.
@ 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)
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