IDS peak ICV v1.3.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
152 void ResetToDefault() override;
153
162
170 PEAK_COMMON_NO_DISCARD virtual peak::common::PixelFormat GetOutputPixelFormat() const;
171
183 PEAK_COMMON_NO_DISCARD peak::icv::Image Process(const peak::icv::Image& input) const;
184
198 PEAK_COMMON_NO_DISCARD peak::common::Any Process(const peak::common::Any& input) const override;
199
213 void ReleaseBuffers() const;
214
215private:
216 static constexpr int moduleVersion{ 1 };
217 static constexpr auto outputPixelFormatKey{ "OutputPixelFormat" };
218
220 bool m_enabled{ true };
221 peak_icv_image_converter_handle m_handle{};
222};
223
225{
227 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ImageConverter_Create(&m_handle);
228 });
229}
230
232{
233 if (m_handle != nullptr)
234 {
235 std::ignore = PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ImageConverter_Destroy(m_handle);
236 }
237}
238
240{
241 m_outputPixelFormat = other.m_outputPixelFormat;
242 m_enabled = other.m_enabled;
243 std::swap(m_handle, other.m_handle);
244}
245
247{
248 if (this != &other)
249 {
250 m_outputPixelFormat = other.m_outputPixelFormat;
251 m_enabled = other.m_enabled;
252 std::swap(m_handle, other.m_handle);
253 }
254
255 return *this;
256}
257
259{
260 archive.SetBool("Enabled", IsEnabled());
261 archive.SetInt("Version", moduleVersion);
262
263 archive.SetString(outputPixelFormatKey, peak::common::PixelFormatInfo(m_outputPixelFormat).GetName());
264}
265
267{
268 const auto version = archive.GetInt("Version");
270
271 SetEnabled(archive.GetBool("Enabled"));
272 m_outputPixelFormat = peak::common::PixelFormatInfo(archive.GetString(outputPixelFormatKey)).GetPixelFormat();
273}
274
276{
277 m_outputPixelFormat = format;
278}
279
281{
282 return m_outputPixelFormat;
283}
284
286{
287 m_outputPixelFormat = peak::common::PixelFormat::RGB8;
288}
289
291{
292 m_enabled = enabled;
293}
294
296{
297 return m_enabled;
298}
299
300inline const char* PixelFormatConversionModule::GetType() const
301{
302 return "PixelFormatConversion";
303}
304
309
311{
312 if (!IsEnabled())
313 {
314 return input;
315 }
316
317 const auto& inputImage = input.AnyCast<peak::icv::Image>();
318
319 const auto inputFormat = inputImage.GetPixelFormat();
320
321 if (inputFormat == m_outputPixelFormat)
322 {
323 return input;
324 }
325
326 auto* const inputImageHandle = peak::common::detail::BackendAccessor<peak::icv::Image>::BackendHandle(inputImage);
327 peak_icv_image_handle outputHandle = nullptr;
328
330 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ImageConverter_Convert(
331 m_handle, inputImageHandle, peak::common::detail::CppPixelFormatToCPixelFormat(m_outputPixelFormat), &outputHandle);
332 });
333
334 return peak::common::Any(peak::common::detail::BackendAccessor<peak::icv::Image>::CreateInstance(outputHandle));
335}
336
338{
340 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ImageConverter_ReleaseBuffers(m_handle);
341 });
342}
343
344} // namespace detail
345} // namespace pipeline
346} // 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.
virtual 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.
virtual 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
Enables or disables the 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
Gets whether this 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.
constexpr peak_common_pixel_format CppPixelFormatToCPixelFormat(PixelFormat pixelFormat) noexcept
void ExecuteAndMapReturnCodes(const CallableType &callableObject)
void ValidateVersion(int64_t version, const std::string &moduleName)
peak_icv_image * peak_icv_image_handle