IDS peak ICV v1.0.0
Loading...
Searching...
No Matches
peak_icv_mono_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
37{
38public:
45
51 ~MonoConversionModule() override;
52
61
68
77
84
96 void Serialize(peak::common::serialization::IArchive& archive) const override;
97
98
113 void Deserialize(const peak::common::serialization::IArchive& archive) override;
114
122 void SetEnabled(bool enabled) override;
123
131 PEAK_COMMON_NO_DISCARD bool IsEnabled() const override;
132
140 PEAK_COMMON_NO_DISCARD const char* GetType() const override;
141
147 void ResetToDefault() override
148 {}
149
165
184
198 void ReleaseBuffers() const;
199
200private:
202
203 constexpr static int moduleVersion{ 1 };
204
205 bool m_enabled{ true };
206 peak_icv_image_converter_handle m_handle{};
207};
208
210{
212 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ImageConverter_Create(&m_handle);
213 });
214}
215
217{
218 if (m_handle != nullptr)
219 {
220 std::ignore = PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ImageConverter_Destroy(m_handle);
221 }
222}
223
225{
226 m_enabled = other.m_enabled;
227 std::swap(m_handle, other.m_handle);
228}
229
231{
232 if (this != &other)
233 {
234 m_enabled = other.m_enabled;
235 std::swap(m_handle, other.m_handle);
236 }
237
238 return *this;
239}
240
242{
243 archive.SetBool("Enabled", IsEnabled());
244 archive.SetInt("Version", moduleVersion);
245}
246
248{
249 const auto version = archive.GetInt("Version");
251
252 SetEnabled(archive.GetBool("Enabled"));
253}
254
255inline void MonoConversionModule::SetEnabled(bool enabled)
256{
257 m_enabled = enabled;
258}
259
261{
262 return m_enabled;
263}
264
265inline const char* MonoConversionModule::GetType() const
266{
267 return "MonoConversion";
268}
269
270inline peak::common::PixelFormat MonoConversionModule::GetOutputFormat(peak::common::PixelFormat inputFormat)
271{
272 const peak::common::PixelFormatInfo info(inputFormat);
273
274 if (info.IsSingleChannel() && info.HasIntensityChannel())
275 {
276 return inputFormat;
277 }
278
279 const auto bitDepth = info.GetStorageBitsPerChannel();
280
281 if (bitDepth <= 8)
282 {
284 }
285 if (bitDepth <= 10)
286 {
288 }
289 if (bitDepth <= 12)
290 {
292 }
294}
295
297{
298 return Process(peak::common::Any(input)).AnyCast<peak::icv::Image>();
299}
300
302{
303 if (!IsEnabled())
304 {
305 return input;
306 }
307
308 const auto& inputImage = input.AnyCast<peak::icv::Image>();
309
310 const auto inputFormat = inputImage.GetPixelFormat();
311 const auto outputFormat = GetOutputFormat(inputFormat);
312
313 if (inputFormat == outputFormat)
314 {
315 return input;
316 }
317
318 auto* const inputImageHandle = peak::common::detail::BackendAccessor<peak::icv::Image>::BackendHandle(inputImage);
319 peak_icv_image_handle outputHandle = nullptr;
320
322 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ImageConverter_Convert(
323 m_handle, inputImageHandle, static_cast<peak_common_pixel_format>(outputFormat), &outputHandle);
324 });
325
326 return peak::common::Any(peak::common::detail::BackendAccessor<peak::icv::Image>::CreateInstance(outputHandle));
327}
328
330{
332 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ImageConverter_ReleaseBuffers(m_handle);
333 });
334}
335
336} // namespace detail
337} // namespace pipeline
338} // 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.
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 bool GetBool(const std::string &key) const =0
Retrieves a boolean value by key.
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.
Mono conversion is an image pipeline module that converts images to a monochrome format.
MonoConversionModule()
Creates an instance of class MonoConversion.
const char * GetType() const override
Returns the type of the module for serialization purposes.
MonoConversionModule(const MonoConversionModule &other)=delete
Copy constructor for class MonoConversionModule is deleted.
void ReleaseBuffers() const
Frees unused internal buffers.
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
Processes the input image, performing mono conversion if enabled.
void SetEnabled(bool enabled) override
Sets the enabled state of this module.
MonoConversionModule & operator=(const MonoConversionModule &other)=delete
Copy assignment for class MonoConversionModule is deleted.
void Deserialize(const peak::common::serialization::IArchive &archive) override
Restores the object's state from the provided archive.
void ResetToDefault() override
Does nothing for the mono conversion module.
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.
@ Mono12
Mono 12-Bit pixel format.
@ Mono16
Mono 16-Bit pixel format.
@ Mono10
Mono 10-Bit pixel format.
@ Mono8
Mono 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