IDS peak IPL v1.15.0
Loading...
Searching...
No Matches
peak_ipl_lut.hpp
Go to the documentation of this file.
1
10
11#pragma once
12
18
22namespace peak
23{
24namespace ipl
25{
26
27class Image;
28
47class Lut final
48{
49public:
53 enum class Channel
54 {
56 Red = 0,
58 Green = 1,
60 Blue = 2,
62 All = 3
63 };
64
69 enum class Selector
70 {
79 };
80
143
150 Lut();
151
158 ~Lut();
159
170 Lut(const Lut& other);
171
182 Lut& operator=(const Lut& other);
183
192 Lut(Lut&& other) noexcept;
193
202 Lut& operator=(Lut&& other) noexcept;
203
215 PEAK_IPL_NO_DISCARD uint32_t LutValue(Selector selector, Channel channel, uint32_t index) const;
216
229 void SetLutValue(Selector selector, Channel channel, uint32_t index, uint32_t value);
230
243 PEAK_IPL_NO_DISCARD std::vector<uint32_t> AllLutValues(Selector selector, Channel channel) const;
244
256 void SetAllLutValues(Selector selector, Channel channel, const std::vector<uint32_t>& values);
257
266 void SetLutPreset(Selector selector, Preset preset);
267
278
290 void ProcessInPlace(Image& image) const;
291
304 PEAK_IPL_NO_DISCARD Image Process(const Image& inputImage) const;
305
306private:
307 PEAK_IPL_LUT_HANDLE m_backendHandle{};
308};
309
310inline Lut::Lut()
311{
313}
314
315inline Lut::~Lut()
316{
317 if (m_backendHandle)
318 {
319 (void)PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Lut_Destruct(m_backendHandle);
320 }
321}
322
323inline Lut::Lut(Lut&& other) noexcept
324{
325 *this = std::move(other);
326}
327
328inline Lut::Lut(const Lut& other)
329{
330 if (other.m_backendHandle)
331 {
332 ExecuteAndMapReturnCodes([&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Lut_Acquire(other.m_backendHandle); });
333 }
334
335 m_backendHandle = other.m_backendHandle;
336}
337
338inline Lut& Lut::operator=(const Lut& other)
339{
340 if (this != &other)
341 {
342 if (m_backendHandle)
343 {
344 (void)PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Lut_Destruct(m_backendHandle);
345 }
346
347 if (other.m_backendHandle)
348 {
350 [&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Lut_Acquire(other.m_backendHandle); });
351 }
352 }
353
354 m_backendHandle = other.m_backendHandle;
355
356 return *this;
357}
358
359inline Lut& Lut::operator=(Lut&& other) noexcept
360{
361 if (this != &other)
362 {
363 if (m_backendHandle != nullptr)
364 {
365 (void)PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Lut_Destruct(m_backendHandle);
366 }
367 m_backendHandle = other.m_backendHandle;
368 other.m_backendHandle = nullptr;
369 }
370
371 return *this;
372}
373
374inline uint32_t Lut::LutValue(Selector selector, Channel channel, uint32_t index) const
375{
376 uint32_t value = 0;
377
380 m_backendHandle, static_cast<PEAK_IPL_LUT_SELECTOR>(selector), static_cast<PEAK_IPL_LUT_CHANNEL>(channel), index, &value);
381 });
382
383 return value;
384}
385
386inline void Lut::SetLutValue(Selector selector, Channel channel, uint32_t index, uint32_t value)
387{
389 return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Lut_SetLutValue(m_backendHandle,
390 static_cast<PEAK_IPL_LUT_SELECTOR>(selector), static_cast<PEAK_IPL_LUT_CHANNEL>(channel), index, value);
391 });
392}
393
394inline std::vector<uint32_t> Lut::AllLutValues(Selector selector, Channel channel) const
395{
396 size_t numLutValues = 0;
397
400 static_cast<PEAK_IPL_LUT_SELECTOR>(selector), static_cast<PEAK_IPL_LUT_CHANNEL>(channel), nullptr, &numLutValues);
401 });
402
403 std::vector<uint32_t> vector(numLutValues);
404
407 static_cast<PEAK_IPL_LUT_SELECTOR>(selector), static_cast<PEAK_IPL_LUT_CHANNEL>(channel),
408 reinterpret_cast<uint32_t*>(vector.data()), &numLutValues);
409 });
410
411 return vector;
412}
413
414inline void Lut::SetAllLutValues(Selector selector, Channel channel, const std::vector<uint32_t>& vector)
415{
418 static_cast<PEAK_IPL_LUT_SELECTOR>(selector), static_cast<PEAK_IPL_LUT_CHANNEL>(channel),
419 reinterpret_cast<const uint32_t*>(vector.data()), vector.size());
420 });
421}
422
423inline void Lut::SetLutPreset(Selector selector, Preset preset)
424{
427 m_backendHandle, static_cast<PEAK_IPL_LUT_SELECTOR>(selector), static_cast<PEAK_IPL_LUT_PRESET>(preset));
428 });
429}
430
431inline bool Lut::IsPixelFormatSupported(PixelFormatName pixelFormatName) const
432{
433 PEAK_IPL_BOOL8 isPixelFormatSupported = 0;
434
437 static_cast<PEAK_IPL_PIXEL_FORMAT>(pixelFormatName),
438 reinterpret_cast<PEAK_IPL_BOOL8*>(&isPixelFormatSupported));
439 });
440
441 return isPixelFormatSupported > 0;
442}
443
444inline void Lut::ProcessInPlace(Image& image) const
445{
448 m_backendHandle, ImageBackendAccessor::BackendHandle(image));
449 });
450}
451
452inline Image Lut::Process(const Image& inputImage) const
453{
454 PEAK_IPL_IMAGE_HANDLE outputImageHandle = nullptr;
457 m_backendHandle, ImageBackendAccessor::BackendHandle(inputImage), &outputImageHandle);
458 });
459
460 return ImageBackendAccessor::CreateImage(outputImageHandle);
461}
462
463} /* namespace ipl */
464} /* namespace peak */
Stores the pixel format, width and height of an image and the pointer to the image buffer.
Definition peak_ipl_image.hpp:41
Applies a LUT to the input image data.
Definition peak_ipl_lut.hpp:48
void ProcessInPlace(Image &image) const
Applies the LUT to the given image in place that is, it will change the input image.
Definition peak_ipl_lut.hpp:444
void SetLutValue(Selector selector, Channel channel, uint32_t index, uint32_t value)
Sets a single LUT value for a given selector and channel at an indexed position.
Definition peak_ipl_lut.hpp:386
bool IsPixelFormatSupported(PixelFormatName pixelFormatName) const
Returns whether the LUT supports the given pixel format.
Definition peak_ipl_lut.hpp:431
uint32_t LutValue(Selector selector, Channel channel, uint32_t index) const
Reads a single LUT value for a given selector and channel at an indexed position.
Definition peak_ipl_lut.hpp:374
Channel
Channel parameter to select the channel where the operation is applied.
Definition peak_ipl_lut.hpp:54
@ Blue
Definition peak_ipl_lut.hpp:60
@ All
Definition peak_ipl_lut.hpp:62
@ Green
Definition peak_ipl_lut.hpp:58
@ Red
Definition peak_ipl_lut.hpp:56
void SetLutPreset(Selector selector, Preset preset)
Applies the given preset (identity, inverse, ...) to the specified LUT.
Definition peak_ipl_lut.hpp:423
Image Process(const Image &inputImage) const
Applies the LUT to the given image.
Definition peak_ipl_lut.hpp:452
~Lut()
Destructor for the LUT instance.
Definition peak_ipl_lut.hpp:315
std::vector< uint32_t > AllLutValues(Selector selector, Channel channel) const
Reads all LUT values for a given selector and channel at once.
Definition peak_ipl_lut.hpp:394
void SetAllLutValues(Selector selector, Channel channel, const std::vector< uint32_t > &values)
Sets all LUT values for a given selector and channel at once.
Definition peak_ipl_lut.hpp:414
Selector
Selector parameter to select to which LUT the operation is applied (8/10/12/16 bit LUT)....
Definition peak_ipl_lut.hpp:70
@ Lut_10Bit
Definition peak_ipl_lut.hpp:74
@ Lut_16Bit
Definition peak_ipl_lut.hpp:78
@ Lut_8Bit
Definition peak_ipl_lut.hpp:72
@ Lut_12Bit
Definition peak_ipl_lut.hpp:76
Preset
Preset Selects a predefined LUT.
Definition peak_ipl_lut.hpp:85
@ Jet
Definition peak_ipl_lut.hpp:101
@ Hot
Definition peak_ipl_lut.hpp:107
@ Rainbow
Definition peak_ipl_lut.hpp:113
@ DigitalBlack25Percent
Definition peak_ipl_lut.hpp:136
@ OnlyRed
Definition peak_ipl_lut.hpp:118
@ Binarize
Definition peak_ipl_lut.hpp:141
@ DigitalGain2
Definition peak_ipl_lut.hpp:132
@ OnlyBlue
Definition peak_ipl_lut.hpp:128
@ Inverse
Definition peak_ipl_lut.hpp:95
@ Identity
Definition peak_ipl_lut.hpp:90
@ OnlyGreen
Definition peak_ipl_lut.hpp:123
Lut & operator=(const Lut &other)
Copy assigment for LUT instance.
Definition peak_ipl_lut.hpp:338
Lut()
Constructor for a new LUT instance.
Definition peak_ipl_lut.hpp:310
Definition peak_ipl_binning.hpp:25
PixelFormatName
Enum holding the possible pixel format names.
Definition peak_ipl_simple_types.hpp:39
void ExecuteAndMapReturnCodes(const CallableType &callableObject)
Definition peak_ipl_exception.hpp:182
The "peak::ipl" namespace contains the whole image processing library.
Definition peak_ipl_binning.hpp:23
#define PEAK_IPL_NO_DISCARD
Definition peak_ipl_attribute_defines.h:25
PEAK_IPL_C_API PEAK_IPL_Lut_GetAllLutValues(PEAK_IPL_LUT_HANDLE lutHandle, PEAK_IPL_LUT_SELECTOR lutSelector, PEAK_IPL_LUT_CHANNEL channel, uint32_t *values, size_t *sizeValues)
Returns all lut values at once in an array.
PEAK_IPL_C_API PEAK_IPL_Lut_SetLutPreset(PEAK_IPL_LUT_HANDLE lutHandle, PEAK_IPL_LUT_SELECTOR lutSelector, PEAK_IPL_LUT_PRESET preset)
Sets the lut to a preset (identity, inverse, ...)
int32_t PEAK_IPL_LUT_PRESET
Definition peak_ipl_backend.h:352
PEAK_IPL_C_API PEAK_IPL_Lut_SetLutValue(PEAK_IPL_LUT_HANDLE lutHandle, PEAK_IPL_LUT_SELECTOR lutSelector, PEAK_IPL_LUT_CHANNEL channel, uint32_t index, uint32_t value)
Sets a value in the lut.
int32_t PEAK_IPL_LUT_SELECTOR
Definition peak_ipl_backend.h:336
PEAK_IPL_C_API PEAK_IPL_Lut_Destruct(PEAK_IPL_LUT_HANDLE lutHandle)
Destroys the lut associated with the given handle.
PEAK_IPL_C_API PEAK_IPL_Lut_GetLutValue(PEAK_IPL_LUT_HANDLE lutHandle, PEAK_IPL_LUT_SELECTOR lutSelector, PEAK_IPL_LUT_CHANNEL channel, uint32_t index, uint32_t *value)
Returns a lut value at the indexed position.
PEAK_IPL_C_API PEAK_IPL_Lut_Acquire(PEAK_IPL_LUT_HANDLE lutHandle)
Increase the reference count of a lut object.
PEAK_IPL_C_API PEAK_IPL_Lut_Process(PEAK_IPL_LUT_HANDLE lutHandle, PEAK_IPL_IMAGE_HANDLE imageHandle, PEAK_IPL_IMAGE_HANDLE *outputImageHandle)
Applies the lut to the given image.
struct PEAK_IPL_IMAGE * PEAK_IPL_IMAGE_HANDLE
Definition peak_ipl_backend.h:388
struct PEAK_IPL_LUT * PEAK_IPL_LUT_HANDLE
Definition peak_ipl_backend.h:412
PEAK_IPL_C_API PEAK_IPL_Lut_SetAllLutValues(PEAK_IPL_LUT_HANDLE lutHandle, PEAK_IPL_LUT_SELECTOR lutSelector, PEAK_IPL_LUT_CHANNEL channel, const uint32_t *values, size_t sizeValues)
Sets all lut values at once over an array.
PEAK_IPL_C_API PEAK_IPL_Lut_IsPixelFormatSupported(PEAK_IPL_LUT_HANDLE lutHandle, PEAK_IPL_PIXEL_FORMAT pixelFormat, PEAK_IPL_BOOL8 *isPixelFormatSupported)
Asks the given lut whether it supports the given pixel format.
PEAK_IPL_C_API PEAK_IPL_Lut_Construct(PEAK_IPL_LUT_HANDLE *lutHandle)
Creates a lut.
int8_t PEAK_IPL_BOOL8
Definition peak_ipl_backend.h:26
PEAK_IPL_C_API PEAK_IPL_Lut_ProcessInPlace(PEAK_IPL_LUT_HANDLE lutHandle, PEAK_IPL_IMAGE_HANDLE imageHandle)
Applies lut to the given image inplace.
int32_t PEAK_IPL_LUT_CHANNEL
Definition peak_ipl_backend.h:327
int32_t PEAK_IPL_PIXEL_FORMAT
Definition peak_ipl_backend.h:173
#define PEAK_IPL_C_ABI_PREFIX
Definition peak_ipl_dll_defines.h:16