IDS peak ICV v1.0.0
Loading...
Searching...
No Matches
peak_icv_unpack_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
18#include <utility>
19
20namespace peak
21{
22namespace pipeline
23{
24namespace detail
25{
26
39{
40public:
47
53 ~UnpackModule() override;
54
62 UnpackModule(const UnpackModule& other) = delete;
63
69 UnpackModule(UnpackModule&& other) noexcept;
70
78 UnpackModule& operator=(const UnpackModule& other) = delete;
79
85 UnpackModule& operator=(UnpackModule&& other) noexcept;
86
92 void Serialize(peak::common::serialization::IArchive& archive) const override;
93
99 void Deserialize(const peak::common::serialization::IArchive& archive) override;
100
106 void SetEnabled(bool enable) override;
107
115 PEAK_COMMON_NO_DISCARD bool IsEnabled() const override;
116
124 PEAK_COMMON_NO_DISCARD const char* GetType() const override;
125
131 void ResetToDefault() override;
132
143 void SetTargetBitDepth(size_t bitDepth);
144
162
178
196
210 void ReleaseBuffers() const;
211
212private:
214 peak::common::PixelFormat inputFormat, size_t outputBitDepth);
215 PEAK_COMMON_NO_DISCARD size_t GetOutputBitDepth(size_t inputBitDepth) const;
216
217 PEAK_COMMON_NO_DISCARD static peak::common::PixelFormat BayerBGFormat(size_t bitDepth);
218 PEAK_COMMON_NO_DISCARD static peak::common::PixelFormat BayerGBFormat(size_t bitDepth);
219 PEAK_COMMON_NO_DISCARD static peak::common::PixelFormat BayerGRFormat(size_t bitDepth);
220 PEAK_COMMON_NO_DISCARD static peak::common::PixelFormat BayerRGFormat(size_t bitDepth);
221 PEAK_COMMON_NO_DISCARD static peak::common::PixelFormat MonoFormat(size_t bitDepth);
222
223 peak_icv_image_converter_handle m_handle{};
224
225 size_t m_targetBitDepth{ 8 };
227};
228
230{
232 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ImageConverter_Create(&m_handle);
233 });
234}
235
237{
238 if (m_handle != nullptr)
239 {
240 std::ignore = PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ImageConverter_Destroy(m_handle);
241 }
242}
243
245{
246 std::swap(m_handle, other.m_handle);
247}
248
250{
251 if (this != &other)
252 {
253 std::swap(m_handle, other.m_handle);
254 }
255
256 return *this;
257}
258
260{
261 std::ignore = archive;
262}
263
265{
266 std::ignore = archive;
267}
268
269inline void UnpackModule::SetEnabled(bool enable)
270{
271 std::ignore = enable;
272}
273
274inline bool UnpackModule::IsEnabled() const
275{
276 return true;
277}
278
279inline const char* UnpackModule::GetType() const
280{
281 return "Unpack";
282}
283
284inline peak::common::PixelFormat UnpackModule::GetOutputFormat(peak::common::PixelFormat inputFormat, size_t outputBitDepth)
285{
286 switch (inputFormat)
287 {
295 return BayerBGFormat(outputBitDepth);
296
304 return BayerGBFormat(outputBitDepth);
305
313 return BayerGRFormat(outputBitDepth);
314
322 return BayerRGFormat(outputBitDepth);
323
331 return MonoFormat(outputBitDepth);
332
337
338 default:
339 return inputFormat;
340 }
341}
342
343inline peak::common::PixelFormat UnpackModule::BayerBGFormat(size_t bitDepth)
344{
345 if (bitDepth >= 12)
346 {
348 }
349 if (bitDepth >= 10)
350 {
352 }
354}
355
356inline peak::common::PixelFormat UnpackModule::BayerGBFormat(size_t bitDepth)
357{
358 if (bitDepth >= 12)
359 {
361 }
362 if (bitDepth >= 10)
363 {
365 }
367}
368
369inline peak::common::PixelFormat UnpackModule::BayerGRFormat(size_t bitDepth)
370{
371 if (bitDepth >= 12)
372 {
374 }
375 if (bitDepth >= 10)
376 {
378 }
380}
381
382inline peak::common::PixelFormat UnpackModule::BayerRGFormat(size_t bitDepth)
383{
384 if (bitDepth >= 12)
385 {
387 }
388 if (bitDepth >= 10)
389 {
391 }
393}
394
395inline peak::common::PixelFormat UnpackModule::MonoFormat(size_t bitDepth)
396{
397 if (bitDepth >= 12)
398 {
400 }
401 if (bitDepth >= 10)
402 {
404 }
406}
407
410
411inline void UnpackModule::SetTargetBitDepth(size_t bitDepth)
412{
413 m_targetBitDepth = bitDepth;
414}
415
417{
418 m_policy = policy;
419}
420
422{
423 return Process(peak::common::Any(input)).AnyCast<peak::icv::Image>();
424}
425
426inline size_t UnpackModule::GetOutputBitDepth(const size_t inputBitDepth) const
427{
428 if (m_policy == ProcessingPolicy::Fast)
429 {
430 return (std::min)(inputBitDepth, m_targetBitDepth);
431 }
432 if (m_policy == ProcessingPolicy::Enhanced)
433 {
434 return (std::max)(inputBitDepth, m_targetBitDepth);
435 }
436 return inputBitDepth;
437}
438
440{
441 const auto& inputImage = input.AnyCast<peak::icv::Image>();
442
443 const auto inputFormat = inputImage.GetPixelFormat();
444 const auto inputBitDepth = peak::common::PixelFormatInfo(inputFormat).GetStorageBitsPerChannel();
445 const auto outputBitDepth = GetOutputBitDepth(inputBitDepth);
446 const auto outputFormat = GetOutputFormat(inputFormat, outputBitDepth);
447
448 if (inputFormat == outputFormat)
449 {
450 return input;
451 }
452
453 auto* const inputImageHandle = peak::common::detail::BackendAccessor<peak::icv::Image>::BackendHandle(inputImage);
454 peak_icv_image_handle outputHandle = nullptr;
455
457 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ImageConverter_Convert(
458 m_handle, inputImageHandle, static_cast<peak_common_pixel_format>(outputFormat), &outputHandle);
459 });
460
461 return peak::common::Any(peak::common::detail::BackendAccessor<peak::icv::Image>::CreateInstance(outputHandle));
462}
463
465{
467 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ImageConverter_ReleaseBuffers(m_handle);
468 });
469}
470
471} // namespace detail
472} // namespace pipeline
473} // 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.
size_t GetStorageBitsPerChannel() const
Returns the number of bits used per channel for storage.
Interface for a hierarchical key-value archive system.
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.
Unpack is an image pipeline module that converts packed pixel formats into corresponding unpacked Bay...
UnpackModule()
Creates an instance of class UnpackModule.
const char * GetType() const override
Returns the type of the module for serialization purposes.
void SetEnabled(bool enable) override
Does nothing for the unpack module.
void ReleaseBuffers() const
Frees unused internal buffers.
UnpackModule & operator=(const UnpackModule &other)=delete
Copy assignment for class UnpackModule is deleted.
void Serialize(peak::common::serialization::IArchive &archive) const override
This function has no effect on the Unpack module.
peak::icv::Image Process(const peak::icv::Image &input) const
Converts a packed pixel format image into an unpacked Bayer or mono format.
void Deserialize(const peak::common::serialization::IArchive &archive) override
This function has no effect on the unpack module.
void SetProcessingPolicy(ProcessingPolicy policy)
Set the processing policy.
void ResetToDefault() override
Does nothing for the unpack module.
UnpackModule(const UnpackModule &other)=delete
Copy constructor for class UnpackModule is deleted.
void SetTargetBitDepth(size_t bitDepth)
Set the target bit depth.
bool IsEnabled() const override
Returns true since the unpack module is always 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.
@ BayerRG12g24IDS
BayerRG 12-Bit grouped 24-bit (IDS)
@ RGB8
RGB 8-Bit pixel format.
@ Mono12p
Mono 12-Bit packed format.
@ Mono12
Mono 12-Bit pixel format.
@ BayerGB10
BayerGB 10-Bit pixel format.
@ BayerRG12p
BayerRG 12-Bit packed format.
@ BayerBG10
BayerBG 10-Bit pixel format.
@ Mono10g40IDS
Mono 10-Bit grouped 40-bit (IDS)
@ BayerGR10g40IDS
BayerGR 10-Bit grouped 40-bit (IDS)
@ BayerBG10p
BayerBG 10-Bit packed format.
@ BayerGB12p
BayerGB 12-Bit packed format.
@ BayerGR12
BayerGR 12-Bit pixel format.
@ BayerRG10p
BayerRG 10-Bit packed format.
@ BayerRG12
BayerRG 12-Bit pixel format.
@ BayerGR12p
BayerGR 12-Bit packed format.
@ BayerGR8
BayerGR 8-Bit pixel format.
@ BayerBG12p
BayerBG 12-Bit packed format.
@ BayerBG8
BayerBG 8-Bit pixel format.
@ Mono12g24IDS
Mono 12-Bit grouped 24-bit (IDS)
@ BayerRG10
BayerRG 10-Bit pixel format.
@ BayerGB12
BayerGB 12-Bit pixel format.
@ BayerRG8
BayerRG 8-Bit pixel format.
@ BayerGR10p
BayerGR 10-Bit packed format.
@ YUV422_8_UYVY
UYVY 4:2:2 8-Bit format.
@ YUV420_8_YY_VU_SemiplanarIDS
YUV4:2:0 8-Bit YY/VU semiplanar (IDS)
@ BayerGB8
BayerGB 8-Bit pixel format.
@ BayerGR12g24IDS
BayerGR 12-Bit grouped 24-bit (IDS)
@ YUV420_8_YY_UV_SemiplanarIDS
YUV4:2:0 8-Bit YY/UV semiplanar (IDS)
@ BayerGR10
BayerGR 10-Bit pixel format.
@ Mono10
Mono 10-Bit pixel format.
@ Mono8
Mono 8-Bit pixel format.
@ BayerBG12
BayerBG 12-Bit pixel format.
@ BayerBG10g40IDS
BayerBG 10-Bit grouped 40-bit (IDS)
@ BayerGB10p
BayerGB 10-Bit packed format.
@ BayerBG12g24IDS
BayerBG 12-Bit grouped 24-bit (IDS)
@ Mono10p
Mono 10-Bit packed format.
@ BayerRG10g40IDS
BayerRG 10-Bit grouped 40-bit (IDS)
@ BayerGB10g40IDS
BayerGB 10-Bit grouped 40-bit (IDS)
@ BayerGB12g24IDS
BayerGB 12-Bit grouped 24-bit (IDS)
ProcessingPolicy
Specifies the processing policy.
void ExecuteAndMapReturnCodes(const CallableType &callableObject)
peak_icv_image * peak_icv_image_handle