IDS peak ICV v1.1.0
Loading...
Searching...
No Matches
peak_icv_pixel_format_conversion_module.hpp
Go to the documentation of this file.
1
11#pragma once
12
16#include <peak_icv_c/algorithms/preprocessing/peak_icv_image_converter.h>
17
18namespace peak
19{
20namespace pipeline
21{
22namespace detail
23{
24
39{
40public:
48
55
64
71
80
87
99 void Serialize(peak::common::serialization::IArchive& archive) const override;
100
116 void Deserialize(const peak::common::serialization::IArchive& archive) override;
117
125 void SetEnabled(bool enabled) override;
126
134 PEAK_COMMON_NO_DISCARD bool IsEnabled() const override;
135
143 PEAK_COMMON_NO_DISCARD const char* GetType() const override;
144
150 void ResetToDefault() override;
151
160
168 PEAK_COMMON_NO_DISCARD peak::common::PixelFormat GetOutputPixelFormat() const;
169
181 PEAK_COMMON_NO_DISCARD peak::icv::Image Process(const peak::icv::Image& input) const;
182
196 PEAK_COMMON_NO_DISCARD peak::common::Any Process(const peak::common::Any& input) const override;
197
211 void ReleaseBuffers() const;
212
213private:
214 static constexpr int moduleVersion{ 1 };
215 static constexpr auto outputPixelFormatKey{ "OutputPixelFormat" };
216
218 bool m_enabled{ true };
219 peak_icv_image_converter_handle m_handle{};
220};
221
223{
225 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ImageConverter_Create(&m_handle);
226 });
227}
228
230{
231 if (m_handle != nullptr)
232 {
233 std::ignore = PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ImageConverter_Destroy(m_handle);
234 }
235}
236
238{
239 m_outputPixelFormat = other.m_outputPixelFormat;
240 m_enabled = other.m_enabled;
241 std::swap(m_handle, other.m_handle);
242}
243
245{
246 if (this != &other)
247 {
248 m_outputPixelFormat = other.m_outputPixelFormat;
249 m_enabled = other.m_enabled;
250 std::swap(m_handle, other.m_handle);
251 }
252
253 return *this;
254}
255
257{
258 archive.SetBool("Enabled", IsEnabled());
259 archive.SetInt("Version", moduleVersion);
260
261 archive.SetString(outputPixelFormatKey, peak::common::PixelFormatInfo(m_outputPixelFormat).GetName());
262}
263
265{
266 const auto version = archive.GetInt("Version");
268
269 SetEnabled(archive.GetBool("Enabled"));
270 m_outputPixelFormat = peak::common::PixelFormatInfo(archive.GetString(outputPixelFormatKey)).GetPixelFormat();
271}
272
274{
275 m_outputPixelFormat = format;
276}
277
279{
280 return m_outputPixelFormat;
281}
282
284{
285 m_outputPixelFormat = peak::common::PixelFormat::RGB8;
286}
287
289{
290 m_enabled = enabled;
291}
292
294{
295 return m_enabled;
296}
297
298inline const char* PixelFormatConversionModule::GetType() const
299{
300 return "PixelFormatConversion";
301}
302
307
309{
310 if (!IsEnabled())
311 {
312 return input;
313 }
314
315 const auto& inputImage = input.AnyCast<peak::icv::Image>();
316
317 const auto inputFormat = inputImage.GetPixelFormat();
318
319 if (inputFormat == m_outputPixelFormat)
320 {
321 return input;
322 }
323
324 auto* const inputImageHandle = peak::common::detail::BackendAccessor<peak::icv::Image>::BackendHandle(inputImage);
325 peak_icv_image_handle outputHandle = nullptr;
326
328 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ImageConverter_Convert(
329 m_handle, inputImageHandle, static_cast<peak_common_pixel_format>(m_outputPixelFormat), &outputHandle);
330 });
331
332 return peak::common::Any(peak::common::detail::BackendAccessor<peak::icv::Image>::CreateInstance(outputHandle));
333}
334
336{
338 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ImageConverter_ReleaseBuffers(m_handle);
339 });
340}
341
342} // namespace detail
343} // namespace pipeline
344} // namespace peak
A type-erased container for any copyable value.
T & AnyCast()
Casts the stored value to the specified type.
Provides information and utility functions for pixel formats.
peak::common::PixelFormat GetPixelFormat() const
Returns the underlying pixel format enumeration value.
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.
Pixel format conversion module that transforms images to a specified output pixel format.
void SetOutputPixelFormat(peak::common::PixelFormat format)
Sets the desired output pixel format.
const char * GetType() const override
Returns the type of the module for serialization purposes.
PixelFormatConversionModule()
Creates an instance of class PixelFormatConversionModule with default output pixelformat.
PixelFormatConversionModule & operator=(const PixelFormatConversionModule &other)=delete
Copy assignment for class PixelFormatConversionModule is deleted.
peak::common::PixelFormat GetOutputPixelFormat() const
Gets the currently set output pixel format.
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 the input image to the configured output pixel format.
void SetEnabled(bool enabled) override
Sets the enabled state of this module.
void Deserialize(const peak::common::serialization::IArchive &archive) override
Restores the object's state from the provided archive.
void ResetToDefault() override
Resets the output pixel format to its default value.
PixelFormatConversionModule(const PixelFormatConversionModule &other)=delete
Copy constructor for class PixelFormatConversionModule is deleted.
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.
@ RGB8
RGB 8-Bit pixel format.
void ExecuteAndMapReturnCodes(const CallableType &callableObject)
void ValidateVersion(int64_t version, const std::string &moduleName)
peak_icv_image * peak_icv_image_handle