IDS peak ICV v1.0.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
115 void Deserialize(const peak::common::serialization::IArchive& archive) override;
116
124 void SetEnabled(bool enabled) override;
125
133 PEAK_COMMON_NO_DISCARD bool IsEnabled() const override;
134
142 PEAK_COMMON_NO_DISCARD const char* GetType() const override;
143
149 void ResetToDefault() override;
150
159
168
181
196
210 void ReleaseBuffers() const;
211
212private:
213 static constexpr int moduleVersion{ 1 };
214 static constexpr auto outputPixelFormatKey{ "OutputPixelFormat" };
215
217 bool m_enabled{ true };
218 peak_icv_image_converter_handle m_handle{};
219};
220
222{
224 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ImageConverter_Create(&m_handle);
225 });
226}
227
229{
230 if (m_handle != nullptr)
231 {
232 std::ignore = PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ImageConverter_Destroy(m_handle);
233 }
234}
235
237{
238 m_outputPixelFormat = other.m_outputPixelFormat;
239 m_enabled = other.m_enabled;
240 std::swap(m_handle, other.m_handle);
241}
242
244{
245 if (this != &other)
246 {
247 m_outputPixelFormat = other.m_outputPixelFormat;
248 m_enabled = other.m_enabled;
249 std::swap(m_handle, other.m_handle);
250 }
251
252 return *this;
253}
254
256{
257 archive.SetBool("Enabled", IsEnabled());
258 archive.SetInt("Version", moduleVersion);
259
260 archive.SetString(outputPixelFormatKey, peak::common::PixelFormatInfo(m_outputPixelFormat).GetName());
261}
262
264{
265 const auto version = archive.GetInt("Version");
267
268 SetEnabled(archive.GetBool("Enabled"));
269 m_outputPixelFormat = peak::common::PixelFormatInfo(archive.GetString(outputPixelFormatKey)).GetPixelFormat();
270}
271
273{
274 m_outputPixelFormat = format;
275}
276
278{
279 return m_outputPixelFormat;
280}
281
283{
284 m_outputPixelFormat = peak::common::PixelFormat::RGB8;
285}
286
288{
289 m_enabled = enabled;
290}
291
293{
294 return m_enabled;
295}
296
297inline const char* PixelFormatConversionModule::GetType() const
298{
299 return "PixelFormatConversion";
300}
301
306
308{
309 if (!IsEnabled())
310 {
311 return input;
312 }
313
314 const auto& inputImage = input.AnyCast<peak::icv::Image>();
315
316 const auto inputFormat = inputImage.GetPixelFormat();
317
318 if (inputFormat == m_outputPixelFormat)
319 {
320 return input;
321 }
322
323 auto* const inputImageHandle = peak::common::detail::BackendAccessor<peak::icv::Image>::BackendHandle(inputImage);
324 peak_icv_image_handle outputHandle = nullptr;
325
327 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ImageConverter_Convert(
328 m_handle, inputImageHandle, static_cast<peak_common_pixel_format>(m_outputPixelFormat), &outputHandle);
329 });
330
331 return peak::common::Any(peak::common::detail::BackendAccessor<peak::icv::Image>::CreateInstance(outputHandle));
332}
333
335{
337 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ImageConverter_ReleaseBuffers(m_handle);
338 });
339}
340
341} // namespace detail
342} // namespace pipeline
343} // 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.
#define PEAK_COMMON_NO_DISCARD
Compatability macro for the nodiscard attribute.
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