19#include <peak_icv_c/algorithms/preprocessing/peak_icv_downsampling.h>
54 return "BinningAverage";
64 const auto modeStr = std::to_string(
static_cast<int>(mode));
70 if (mode ==
"BinningAverage")
74 if (mode ==
"BinningSum")
78 if (mode ==
"Decimation")
183 PEAK_COMMON_NO_DISCARD
bool IsEnabled()
const override;
267 PEAK_COMMON_NO_DISCARD
const char*
GetType()
const override;
292 void SetX(uint32_t x);
301 void SetY(uint32_t y);
310 PEAK_COMMON_NO_DISCARD uint32_t
GetX()
const;
319 PEAK_COMMON_NO_DISCARD uint32_t
GetY()
const;
349 static constexpr auto modeKey{
"Mode" };
350 static constexpr auto xKey =
"X";
351 static constexpr auto yKey =
"Y";
352 static constexpr auto defaultModeKey =
"DefaultMode";
354 static constexpr int moduleVersion = 1;
358 peak_icv_downsampling_handle m_handle{};
359 bool m_enabled{
true };
361 std::string m_customType;
369 : m_defaultMode{ defaultMode }
370 , m_customType{ std::move(customName) }
373 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Downsampling_Create(
374 &m_handle, peak_icv_downsampling_factor{ 1, 1 },
static_cast<peak_icv_downsampling_mode
>(m_defaultMode));
380 if (m_handle !=
nullptr)
382 std::ignore = PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Downsampling_Destroy(m_handle);
388 , m_handle{ std::exchange(other.m_handle,
nullptr) }
389 , m_enabled{ std::exchange(other.m_enabled,
false) }
396 if (m_handle !=
nullptr)
399 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Downsampling_Destroy(m_handle);
403 m_handle = std::exchange(other.m_handle,
nullptr);
404 m_enabled = std::exchange(other.m_enabled,
false);
423 archive.
SetInt(
"Version", moduleVersion);
437 const auto version = archive.
GetInt(
"Version");
442 SetX(
static_cast<uint32_t
>(archive.
GetInt(xKey)));
443 SetY(
static_cast<uint32_t
>(archive.
GetInt(yKey)));
456 auto needsProcessing = [&] {
459 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Downsampling_NeedsProcessing(m_handle, &value);
470 auto*
const inputImageHandle = peak::common::detail::BackendAccessor<peak::icv::Image>::BackendHandle(inputImage);
472 peak_common_size outputImageSize{};
474 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Downsampling_GetOutputImageSize(m_handle, inputImageHandle, &outputImageSize);
477 peak::icv::Image outputImage{ inputImage.GetPixelFormat(), { outputImageSize.width, outputImageSize.height } };
478 auto*
const outputImageHandle = peak::common::detail::BackendAccessor<peak::icv::Image>::BackendHandle(outputImage);
481 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Downsampling_Process(m_handle, inputImageHandle, outputImageHandle);
489 if (!m_customType.empty())
491 return m_customType.c_str();
493 return "Downsampling";
506 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Downsampling_SetFactor(m_handle, peak_icv_downsampling_factor{ x,
GetY() });
513 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Downsampling_SetFactor(m_handle, peak_icv_downsampling_factor{
GetX(), y });
519 peak_icv_downsampling_factor factor{};
522 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Downsampling_GetFactor(m_handle, &factor);
530 peak_icv_downsampling_factor factor{};
533 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Downsampling_GetFactor(m_handle, &factor);
541 peak_common_interval_u cRange{};
544 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Downsampling_GetRange(m_handle, &cRange);
547 return { cRange.minimum, cRange.maximum };
553 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Downsampling_SetMode(
554 m_handle,
static_cast<peak_icv_downsampling_mode
>(mode));
560 peak_icv_downsampling_mode mode{};
563 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Downsampling_GetMode(m_handle, &mode);
A type-erased container for any copyable value.
T & AnyCast()
Casts the stored value to the specified type.
Represents a continuous numeric interval with inclusive lower and upper bounds.
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.
Thrown when a requested operation is not implemented or supported.
Downsampling is used to decrease the image size.
uint32_t GetY() const
Returns the current number of rows used for downsampling.
DownsamplingModule(const DownsamplingModule &other)=delete
Copy constructor for class DownsamplingModule is deleted.
const char * GetType() const override
Returns the type of the module for serialization purposes or the custom type, if defined.
DownsamplingModule()
Creates a DownsamplingModule with default values.
void SetCustomType(const std::string &type)
Sets the custom type of the module for serialization purposes.
DownsamplingMode GetMode() const
Returns the current DownsamplingMode.
void SetMode(const DownsamplingMode &mode)
Sets the DownsamplingMode.
void Serialize(peak::common::serialization::IArchive &archive) const override
Serializes the object's internal state into the provided archive.
uint32_t GetX() const
Returns the current number of columns used for downsampling.
peak::icv::Image Process(const peak::icv::Image &input) const
Applies the downsampling factors and mode to the input image and returns a downsampled copy based on ...
void SetEnabled(bool enabled) override
Sets the enabled state of this module.
void SetY(uint32_t y)
Sets the number of rows to downsample.
void SetX(uint32_t x)
Sets the number of columns to downsample.
void Deserialize(const peak::common::serialization::IArchive &archive) override
Restores the object's state from the provided archive.
DownsamplingModule & operator=(const DownsamplingModule &other)=delete
Copy assignment for class DownsamplingModule is deleted.
peak::common::IntervalU GetRange() const
Returns the valid range for downsampling factors x and y.
void ResetToDefault() override
Resets all settings to default values, except the CustomType.
~DownsamplingModule() override
bool IsEnabled() const override
Checks if the module is currently enabled.
Interface for a module used within a pipeline.
DownsamplingMode
Mode parameter for the downsampling algorithm.
@ BinningAverage
The averaged pixel values of neighboring rows and/or columns are computed during binning.
@ BinningSum
The pixel values of neighboring rows and/or columns are summed during binning.
@ Decimation
The additional pixel values of neighboring rows and/or columns are skipped during decimation.
void ExecuteAndMapReturnCodes(const CallableType &callableObject)
std::string ToString(const DebayerConversionPolicy &policy)
void ValidateVersion(int64_t version, const std::string &moduleName)
DownsamplingMode ToMode(const std::string &mode)