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;
254#ifndef DOXYGEN_SHOULD_SKIP_THIS
259 void SetMirrorEnabled(
bool enabled);
260 PEAK_COMMON_NO_DISCARD
bool IsMirrorEnabled()
const;
262 void SetRotationEnabled(
bool enabled);
263 PEAK_COMMON_NO_DISCARD
bool IsRotationEnabled()
const;
265 static constexpr int moduleVersion{ 1 };
266 static constexpr auto mirrorKey{
"Mirror" };
267 static constexpr auto rotationKey{
"Rotation" };
268 static constexpr auto mirrorLeftRightKey{
"LeftRight" };
269 static constexpr auto mirrorUpDownKey{
"UpDown" };
270 static constexpr auto rotationAngleKey{
"Angle" };
273 bool m_leftRight{
false };
274 bool m_upDown{
false };
275 Rotation m_angle{ defaultRotation };
277 bool m_mirrorEnabled{
true };
278 bool m_rotationEnabled{
true };
283 m_mirrorEnabled = enabled;
284 m_rotationEnabled = enabled;
289 return m_mirrorEnabled || m_rotationEnabled;
294 return "TransformationModule";
299 m_leftRight = other.m_leftRight;
300 m_upDown = other.m_upDown;
301 m_angle = other.m_angle;
302 m_mirrorEnabled = other.m_mirrorEnabled;
303 m_rotationEnabled = other.m_rotationEnabled;
310 m_leftRight = other.m_leftRight;
311 m_upDown = other.m_upDown;
312 m_angle = other.m_angle;
313 m_mirrorEnabled = other.m_mirrorEnabled;
314 m_rotationEnabled = other.m_rotationEnabled;
322 archive.
SetInt(
"Version", moduleVersion);
327 mirrorArchive->SetBool(
"Enabled", m_mirrorEnabled);
328 rotationArchive->SetBool(
"Enabled", m_rotationEnabled);
330 mirrorArchive->SetBool(mirrorLeftRightKey, m_leftRight);
331 mirrorArchive->SetBool(mirrorUpDownKey, m_upDown);
333 rotationArchive->SetInt(rotationAngleKey,
static_cast<int64_t
>(m_angle));
336 archive.
SetArchive(rotationKey, rotationArchive);
341 const auto version = archive.
GetInt(
"Version");
344 const auto mirrorArchive = archive.
GetArchive(mirrorKey);
345 const auto rotationArchive = archive.
GetArchive(rotationKey);
346 const auto rotation = rotationArchive->GetInt(rotationAngleKey);
347 if (rotation != 0 && rotation != 90 && rotation != 180 && rotation != 270)
352 m_mirrorEnabled = mirrorArchive->GetBool(
"Enabled");
353 m_rotationEnabled = rotationArchive->GetBool(
"Enabled");
355 m_leftRight = mirrorArchive->GetBool(mirrorLeftRightKey);
356 m_upDown = mirrorArchive->GetBool(mirrorUpDownKey);
358 m_angle =
static_cast<Rotation
>(rotation);
365 m_angle = defaultRotation;
370 m_leftRight = enabled;
390 if (
static_cast<uint32_t
>(angle) % 90 != 0 ||
static_cast<uint32_t
>(angle) > 270)
409 const auto mirrorNeedsProcessing = m_mirrorEnabled && (m_leftRight || m_upDown);
410 const auto rotationNeedsProcessing = m_rotationEnabled && (m_angle !=
Rotation::None);
412 if (!mirrorNeedsProcessing && !rotationNeedsProcessing)
419 auto*
const inputImageHandle = peak::common::detail::BackendAccessor<peak::icv::Image>::BackendHandle(inputImage);
421 const peak_icv_preprocessing_transformation_parameters parameters{ m_mirrorEnabled && m_leftRight, m_mirrorEnabled && m_upDown,
422 m_rotationEnabled ?
static_cast<peak_icv_preprocessing_transformation_rotation_angle
>(m_angle) :
423 PEAK_ICV_PREPROCESSING_TRANSFORMATION_ROTATION_NONE };
425 peak_common_pixel_format outputPixelFormat;
428 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Transformation_GetOutputPixelFormat(
433 const auto outputSize = transpose ? inputImage.GetSize().Transposed() : inputImage.GetSize();
435 auto*
const outputImageHandle = peak::common::detail::BackendAccessor<peak::icv::Image>::BackendHandle(outputImage);
438 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_Transformation_Process(inputImageHandle, parameters, outputImageHandle);
444inline void TransformationModule::SetMirrorEnabled(
bool enabled)
446 m_mirrorEnabled = enabled;
449inline bool TransformationModule::IsMirrorEnabled()
const
451 return m_mirrorEnabled;
454inline void TransformationModule::SetRotationEnabled(
bool enabled)
456 m_rotationEnabled = enabled;
459inline bool TransformationModule::IsRotationEnabled()
const
461 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.
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.
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)