17#include <peak_icv_c/algorithms/preprocessing/peak_icv_image_transformation.h>
258#ifndef DOXYGEN_SHOULD_SKIP_THIS
263 void SetMirrorEnabled(
bool enabled);
266 void SetRotationEnabled(
bool enabled);
269 static constexpr int moduleVersion{ 1 };
270 static constexpr auto mirrorKey{
"Mirror" };
271 static constexpr auto rotationKey{
"Rotation" };
272 static constexpr auto mirrorLeftRightKey{
"LeftRight" };
273 static constexpr auto mirrorUpDownKey{
"UpDown" };
274 static constexpr auto rotationAngleKey{
"Angle" };
277 bool m_leftRight{
false };
278 bool m_upDown{
false };
279 Rotation m_angle{ defaultRotation };
281 bool m_mirrorEnabled{
true };
282 bool m_rotationEnabled{
true };
287 m_mirrorEnabled = enabled;
288 m_rotationEnabled = enabled;
293 return m_mirrorEnabled || m_rotationEnabled;
298 return "TransformationModule";
303 m_leftRight = other.m_leftRight;
304 m_upDown = other.m_upDown;
305 m_angle = other.m_angle;
306 m_mirrorEnabled = other.m_mirrorEnabled;
307 m_rotationEnabled = other.m_rotationEnabled;
314 m_leftRight = other.m_leftRight;
315 m_upDown = other.m_upDown;
316 m_angle = other.m_angle;
317 m_mirrorEnabled = other.m_mirrorEnabled;
318 m_rotationEnabled = other.m_rotationEnabled;
326 archive.
SetInt(
"Version", moduleVersion);
331 mirrorArchive->SetBool(
"Enabled", m_mirrorEnabled);
332 rotationArchive->SetBool(
"Enabled", m_rotationEnabled);
334 mirrorArchive->SetBool(mirrorLeftRightKey, m_leftRight);
335 mirrorArchive->SetBool(mirrorUpDownKey, m_upDown);
337 rotationArchive->SetInt(rotationAngleKey,
static_cast<int64_t
>(m_angle));
340 archive.
SetArchive(rotationKey, rotationArchive);
345 const auto version = archive.
GetInt(
"Version");
348 const auto mirrorArchive = archive.
GetArchive(mirrorKey);
349 const auto rotationArchive = archive.
GetArchive(rotationKey);
351 m_mirrorEnabled = mirrorArchive->GetBool(
"Enabled");
352 m_rotationEnabled = rotationArchive->GetBool(
"Enabled");
354 m_leftRight = mirrorArchive->GetBool(mirrorLeftRightKey);
355 m_upDown = mirrorArchive->GetBool(mirrorUpDownKey);
357 const auto rotation = rotationArchive->GetInt(rotationAngleKey);
358 if (rotation != 0 && rotation != 90 && rotation != 180 && rotation != 270)
362 m_angle =
static_cast<Rotation>(rotation);
369 m_angle = defaultRotation;
374 m_leftRight = enabled;
394 if (
static_cast<uint32_t
>(angle) % 90 != 0 ||
static_cast<uint32_t
>(angle) > 270)
413 const auto mirrorNeedsProcessing = m_mirrorEnabled && (m_leftRight || m_upDown);
414 const auto rotationNeedsProcessing = m_rotationEnabled && (m_angle !=
Rotation::None);
416 if (!mirrorNeedsProcessing && !rotationNeedsProcessing)
423 auto*
const inputImageHandle = peak::common::detail::BackendAccessor<peak::icv::Image>::BackendHandle(inputImage);
425 const peak_icv_preprocessing_transformation_parameters parameters{ m_mirrorEnabled && m_leftRight, m_mirrorEnabled && m_upDown,
426 m_rotationEnabled ?
static_cast<peak_icv_preprocessing_transformation_rotation_angle
>(m_angle) :
427 PEAK_ICV_PREPROCESSING_TRANSFORMATION_ROTATION_NONE };
429 peak_common_pixel_format outputPixelFormat;
432 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Transformation_GetOutputPixelFormat(
433 static_cast<peak_common_pixel_format
>(inputImage.GetPixelFormat()), parameters, &outputPixelFormat);
437 const auto outputSize = transpose ? inputImage.GetSize().Transposed() : inputImage.GetSize();
439 auto*
const outputImageHandle = peak::common::detail::BackendAccessor<peak::icv::Image>::BackendHandle(outputImage);
442 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Transformation_Process(inputImageHandle, parameters, outputImageHandle);
448inline void TransformationModule::SetMirrorEnabled(
bool enabled)
450 m_mirrorEnabled = enabled;
453inline bool TransformationModule::IsMirrorEnabled()
const
455 return m_mirrorEnabled;
458inline void TransformationModule::SetRotationEnabled(
bool enabled)
460 m_rotationEnabled = enabled;
463inline bool TransformationModule::IsRotationEnabled()
const
465 return m_rotationEnabled;
A type-erased container for any copyable value.
T & AnyCast()
Casts the stored value to the specified type.
Thrown when an unsupported operation or feature is used.
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.
Thrown when a requested operation is not implemented or supported.
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.
#define PEAK_COMMON_NO_DISCARD
Compatability macro for the nodiscard attribute.
PixelFormat
Enum listing all supported pixel formats and their internal IDs.
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.
void ExecuteAndMapReturnCodes(const CallableType &callableObject)
void ValidateVersion(int64_t version, const std::string &moduleName)