17#include <peak_icv_c/algorithms/preprocessing/peak_icv_image_transformation.h>
138 PEAK_COMMON_NO_DISCARD
bool IsEnabled()
const override;
147 PEAK_COMMON_NO_DISCARD
const char*
GetType()
const override;
256#ifndef DOXYGEN_SHOULD_SKIP_THIS
261 void SetMirrorEnabled(
bool enabled);
262 PEAK_COMMON_NO_DISCARD
bool IsMirrorEnabled()
const;
264 void SetRotationEnabled(
bool enabled);
265 PEAK_COMMON_NO_DISCARD
bool IsRotationEnabled()
const;
267 static constexpr int moduleVersion{ 1 };
268 static constexpr auto mirrorKey{
"Mirror" };
269 static constexpr auto rotationKey{
"Rotation" };
270 static constexpr auto mirrorLeftRightKey{
"LeftRight" };
271 static constexpr auto mirrorUpDownKey{
"UpDown" };
272 static constexpr auto rotationAngleKey{
"Angle" };
275 bool m_leftRight{
false };
276 bool m_upDown{
false };
277 Rotation m_angle{ defaultRotation };
279 bool m_mirrorEnabled{
true };
280 bool m_rotationEnabled{
true };
285 m_mirrorEnabled = enabled;
286 m_rotationEnabled = enabled;
291 return m_mirrorEnabled || m_rotationEnabled;
296 return "TransformationModule";
301 m_leftRight = other.m_leftRight;
302 m_upDown = other.m_upDown;
303 m_angle = other.m_angle;
304 m_mirrorEnabled = other.m_mirrorEnabled;
305 m_rotationEnabled = other.m_rotationEnabled;
312 m_leftRight = other.m_leftRight;
313 m_upDown = other.m_upDown;
314 m_angle = other.m_angle;
315 m_mirrorEnabled = other.m_mirrorEnabled;
316 m_rotationEnabled = other.m_rotationEnabled;
324 archive.
SetInt(
"Version", moduleVersion);
329 mirrorArchive->SetBool(
"Enabled", m_mirrorEnabled);
330 rotationArchive->SetBool(
"Enabled", m_rotationEnabled);
332 mirrorArchive->SetBool(mirrorLeftRightKey, m_leftRight);
333 mirrorArchive->SetBool(mirrorUpDownKey, m_upDown);
335 rotationArchive->SetInt(rotationAngleKey,
static_cast<int64_t
>(m_angle));
338 archive.
SetArchive(rotationKey, rotationArchive);
343 const auto version = archive.
GetInt(
"Version");
346 const auto mirrorArchive = archive.
GetArchive(mirrorKey);
347 const auto rotationArchive = archive.
GetArchive(rotationKey);
348 const auto rotation = rotationArchive->GetInt(rotationAngleKey);
349 if (rotation != 0 && rotation != 90 && rotation != 180 && rotation != 270)
354 m_mirrorEnabled = mirrorArchive->GetBool(
"Enabled");
355 m_rotationEnabled = rotationArchive->GetBool(
"Enabled");
357 m_leftRight = mirrorArchive->GetBool(mirrorLeftRightKey);
358 m_upDown = mirrorArchive->GetBool(mirrorUpDownKey);
360 m_angle =
static_cast<Rotation>(rotation);
367 m_angle = defaultRotation;
372 m_leftRight = enabled;
392 if (
static_cast<uint32_t
>(angle) % 90 != 0 ||
static_cast<uint32_t
>(angle) > 270)
411 const auto mirrorNeedsProcessing = m_mirrorEnabled && (m_leftRight || m_upDown);
412 const auto rotationNeedsProcessing = m_rotationEnabled && (m_angle !=
Rotation::None);
414 if (!mirrorNeedsProcessing && !rotationNeedsProcessing)
421 auto*
const inputImageHandle = peak::common::detail::BackendAccessor<peak::icv::Image>::BackendHandle(inputImage);
423 const peak_icv_preprocessing_transformation_parameters parameters{ m_mirrorEnabled && m_leftRight, m_mirrorEnabled && m_upDown,
424 m_rotationEnabled ?
static_cast<peak_icv_preprocessing_transformation_rotation_angle
>(m_angle) :
425 PEAK_ICV_PREPROCESSING_TRANSFORMATION_ROTATION_NONE };
427 peak_common_pixel_format outputPixelFormat;
430 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Transformation_GetOutputPixelFormat(
435 const auto outputSize = transpose ? inputImage.GetSize().Transposed() : inputImage.GetSize();
437 auto*
const outputImageHandle = peak::common::detail::BackendAccessor<peak::icv::Image>::BackendHandle(outputImage);
440 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Transformation_Process(inputImageHandle, parameters, outputImageHandle);
446inline void TransformationModule::SetMirrorEnabled(
bool enabled)
448 m_mirrorEnabled = enabled;
451inline bool TransformationModule::IsMirrorEnabled()
const
453 return m_mirrorEnabled;
456inline void TransformationModule::SetRotationEnabled(
bool enabled)
458 m_rotationEnabled = enabled;
461inline bool TransformationModule::IsRotationEnabled()
const
463 return m_rotationEnabled;
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 std::shared_ptr< IArchive > GetArchive(const std::string &key) const =0
Retrieves a nested archive by key.
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::shared_ptr< IArchive > CreateArchive() const =0
Creates a new, empty archive instance.
virtual void SetArchive(const std::string &key, const std::shared_ptr< IArchive > &value)=0
Stores a nested archive object.
For detailed information about the use of ids_peak_icv Image refer to the Image Guide.
Occurs when a requested operation is not implemented or supported (e.g., exporting to an unsupported ...
Mirror provides functionality to flip the image left-right or up-down.
Rotation provides fixed-angle rotation functionality.
Interface for a module used within a pipeline.
Rotation
Angle parameter for the rotation algorithm.
@ None
No rotation applied to the image.
@ Degree90Counterclockwise
Rotate the image 90 degrees counterclockwise.
@ Degree90Clockwise
Rotate the image 90 degrees clockwise.
constexpr peak_common_pixel_format CppPixelFormatToCPixelFormat(PixelFormat pixelFormat) noexcept
constexpr PixelFormat CPixelFormatToCppPixelFormat(peak_common_pixel_format pixelFormat) noexcept
void ExecuteAndMapReturnCodes(const CallableType &callableObject)
void ValidateVersion(int64_t version, const std::string &moduleName)