IDS peak ICV v1.3.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{
42{
43public:
50
56 ~UnpackModule() override;
57
65 UnpackModule(const UnpackModule& other) = delete;
66
72 UnpackModule(UnpackModule&& other) noexcept;
73
81 UnpackModule& operator=(const UnpackModule& other) = delete;
82
88 UnpackModule& operator=(UnpackModule&& other) noexcept;
89
95 void Serialize(peak::common::serialization::IArchive& archive) const override;
96
102 void Deserialize(const peak::common::serialization::IArchive& archive) override;
103
111 void SetEnabled(bool enable) override;
112
122 PEAK_COMMON_NO_DISCARD bool IsEnabled() const override;
123
131 PEAK_COMMON_NO_DISCARD const char* GetType() const override;
132
142 void ResetToDefault() override;
143
165 void SetTargetBitDepth(size_t bitDepth);
166
176 size_t GetTargetBitDepth() const;
177
186
193
206 PEAK_COMMON_NO_DISCARD peak::icv::Image Process(const peak::icv::Image& input) const;
207
224 PEAK_COMMON_NO_DISCARD peak::common::Any Process(const peak::common::Any& input) const override;
225
239 void ReleaseBuffers() const;
240
241private:
242 PEAK_COMMON_NO_DISCARD static peak::common::PixelFormat GetOutputFormat(
243 peak::common::PixelFormat inputFormat, size_t outputBitDepth);
244 PEAK_COMMON_NO_DISCARD size_t GetOutputBitDepth(size_t inputBitDepth) const;
245
246 PEAK_COMMON_NO_DISCARD static peak::common::PixelFormat BayerBGFormat(size_t bitDepth);
247 PEAK_COMMON_NO_DISCARD static peak::common::PixelFormat BayerGBFormat(size_t bitDepth);
248 PEAK_COMMON_NO_DISCARD static peak::common::PixelFormat BayerGRFormat(size_t bitDepth);
249 PEAK_COMMON_NO_DISCARD static peak::common::PixelFormat BayerRGFormat(size_t bitDepth);
250 PEAK_COMMON_NO_DISCARD static peak::common::PixelFormat MonoFormat(size_t bitDepth);
251
252 peak_icv_image_converter_handle m_handle{};
253
254 size_t m_targetBitDepth{ 8 };
255 ProcessingPolicy m_policy{ ProcessingPolicy::Fast };
256};
257
259{
261 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ImageConverter_Create(&m_handle);
262 });
263}
264
266{
267 if (m_handle != nullptr)
268 {
269 std::ignore = PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ImageConverter_Destroy(m_handle);
270 }
271}
272
274{
275 std::swap(m_handle, other.m_handle);
276}
277
279{
280 if (this != &other)
281 {
282 std::swap(m_handle, other.m_handle);
283 }
284
285 return *this;
286}
287
289{
290 std::ignore = archive;
291}
292
294{
295 std::ignore = archive;
296}
297
298inline void UnpackModule::SetEnabled(bool enable)
299{
300 std::ignore = enable;
301}
302
303inline bool UnpackModule::IsEnabled() const
304{
305 return true;
306}
307
308inline const char* UnpackModule::GetType() const
309{
310 return "Unpack";
311}
312
313inline peak::common::PixelFormat UnpackModule::GetOutputFormat(
314 const peak::common::PixelFormat inputFormat, const size_t outputBitDepth)
315{
316 switch (inputFormat)
317 {
325 return BayerBGFormat(outputBitDepth);
326
334 return BayerGBFormat(outputBitDepth);
335
343 return BayerGRFormat(outputBitDepth);
344
352 return BayerRGFormat(outputBitDepth);
353
361 return MonoFormat(outputBitDepth);
362
367
368 default:
369 return inputFormat;
370 }
371}
372
373inline peak::common::PixelFormat UnpackModule::BayerBGFormat(const size_t bitDepth)
374{
375 if (bitDepth >= 12)
376 {
378 }
379 if (bitDepth >= 10)
380 {
382 }
384}
385
386inline peak::common::PixelFormat UnpackModule::BayerGBFormat(const size_t bitDepth)
387{
388 if (bitDepth >= 12)
389 {
391 }
392 if (bitDepth >= 10)
393 {
395 }
397}
398
399inline peak::common::PixelFormat UnpackModule::BayerGRFormat(const size_t bitDepth)
400{
401 if (bitDepth >= 12)
402 {
404 }
405 if (bitDepth >= 10)
406 {
408 }
410}
411
412inline peak::common::PixelFormat UnpackModule::BayerRGFormat(const size_t bitDepth)
413{
414 if (bitDepth >= 12)
415 {
417 }
418 if (bitDepth >= 10)
419 {
421 }
423}
424
425inline peak::common::PixelFormat UnpackModule::MonoFormat(const size_t bitDepth)
426{
427 if (bitDepth >= 12)
428 {
430 }
431 if (bitDepth >= 10)
432 {
434 }
436}
437
439{
440 m_policy = ProcessingPolicy::Fast;
441 m_targetBitDepth = 8;
442}
443
444inline void UnpackModule::SetTargetBitDepth(const size_t bitDepth)
445{
446 m_targetBitDepth = bitDepth;
447}
448
450{
451 return m_targetBitDepth;
452}
453
455{
456 m_policy = policy;
457}
458
460{
461 return m_policy;
462}
463
465{
466 return Process(peak::common::Any(input)).AnyCast<peak::icv::Image>();
467}
468
469inline size_t UnpackModule::GetOutputBitDepth(const size_t inputBitDepth) const
470{
471 if (m_policy == ProcessingPolicy::Fast)
472 {
473 return (std::min)(inputBitDepth, m_targetBitDepth);
474 }
475 if (m_policy == ProcessingPolicy::Enhanced)
476 {
477 return (std::max)(inputBitDepth, m_targetBitDepth);
478 }
479 return inputBitDepth;
480}
481
483{
484 const auto& inputImage = input.AnyCast<peak::icv::Image>();
485
486 const auto inputFormat = inputImage.GetPixelFormat();
487 const auto inputBitDepth = peak::common::PixelFormatInfo(inputFormat).GetStorageBitsPerChannel();
488 const auto outputBitDepth = GetOutputBitDepth(inputBitDepth);
489 const auto outputFormat = GetOutputFormat(inputFormat, outputBitDepth);
490
491 if (inputFormat == outputFormat)
492 {
493 return input;
494 }
495
496 auto* const inputImageHandle = peak::common::detail::BackendAccessor<peak::icv::Image>::BackendHandle(inputImage);
497 peak_icv_image_handle outputHandle = nullptr;
498
500 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ImageConverter_Convert(
501 m_handle, inputImageHandle, peak::common::detail::CppPixelFormatToCPixelFormat(outputFormat), &outputHandle);
502 });
503
504 return peak::common::Any(peak::common::detail::BackendAccessor<peak::icv::Image>::CreateInstance(outputHandle));
505}
506
508{
510 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ImageConverter_ReleaseBuffers(m_handle);
511 });
512}
513} // namespace detail
514} // namespace pipeline
515} // 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...
size_t GetTargetBitDepth() const
Get the target bit depth used during image processing.
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
This property cannot be changed.
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 monochrome format.
ProcessingPolicy GetProcessingPolicy() const
Get the currently configured processing policy.
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
Resets all module settings.
UnpackModule(const UnpackModule &other)=delete
Copy constructor for class UnpackModule is deleted.
void SetTargetBitDepth(size_t bitDepth)
Set the target bit depth for image processing.
bool IsEnabled() const override
Indicates whether the unpack module is enabled.
Interface for a module used within a pipeline.
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.
constexpr peak_common_pixel_format CppPixelFormatToCPixelFormat(PixelFormat pixelFormat) noexcept
void ExecuteAndMapReturnCodes(const CallableType &callableObject)
peak_icv_image * peak_icv_image_handle