IDS peak IPL v1.18.0
Loading...
Searching...
No Matches
peak_ipl_lut.hpp
Go to the documentation of this file.
1
5
6#pragma once
7
13
18
19namespace peak
20{
21namespace ipl
22{
23
24class Image;
25
45class Lut final
46{
47public:
51 enum class Channel
52 {
54 Red = 0,
56 Green = 1,
58 Blue = 2,
60 All = 3
61 };
62
67 enum class Selector
68 {
77 };
78
141
148 Lut();
149
156 ~Lut();
157
168 Lut(const Lut& other);
169
180 Lut& operator=(const Lut& other);
181
190 Lut(Lut&& other) noexcept;
191
200 Lut& operator=(Lut&& other) noexcept;
201
213 PEAK_IPL_NO_DISCARD uint32_t LutValue(Selector selector, Channel channel, uint32_t index) const;
214
227 void SetLutValue(Selector selector, Channel channel, uint32_t index, uint32_t value);
228
241 PEAK_IPL_NO_DISCARD std::vector<uint32_t> AllLutValues(Selector selector, Channel channel) const;
242
254 void SetAllLutValues(Selector selector, Channel channel, const std::vector<uint32_t>& values);
255
264 void SetLutPreset(Selector selector, Preset preset);
265
276
288 void ProcessInPlace(Image& image) const;
289
302 PEAK_IPL_NO_DISCARD Image Process(const Image& inputImage) const;
303
304private:
305 PEAK_IPL_LUT_HANDLE m_backendHandle{};
306};
307
308inline Lut::Lut()
309{
311}
312
313inline Lut::~Lut()
314{
315 if (m_backendHandle)
316 {
317 (void)PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Lut_Destruct(m_backendHandle);
318 }
319}
320
321inline Lut::Lut(Lut&& other) noexcept
322{
323 *this = std::move(other);
324}
325
326inline Lut::Lut(const Lut& other)
327{
328 if (other.m_backendHandle)
329 {
330 ExecuteAndMapReturnCodes([&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Lut_Acquire(other.m_backendHandle); });
331 }
332
333 m_backendHandle = other.m_backendHandle;
334}
335
336inline Lut& Lut::operator=(const Lut& other)
337{
338 if (this != &other)
339 {
340 if (m_backendHandle)
341 {
342 (void)PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Lut_Destruct(m_backendHandle);
343 }
344
345 if (other.m_backendHandle)
346 {
348 [&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Lut_Acquire(other.m_backendHandle); });
349 }
350 }
351
352 m_backendHandle = other.m_backendHandle;
353
354 return *this;
355}
356
357inline Lut& Lut::operator=(Lut&& other) noexcept
358{
359 if (this != &other)
360 {
361 if (m_backendHandle != nullptr)
362 {
363 (void)PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Lut_Destruct(m_backendHandle);
364 }
365 m_backendHandle = other.m_backendHandle;
366 other.m_backendHandle = nullptr;
367 }
368
369 return *this;
370}
371
372inline uint32_t Lut::LutValue(Selector selector, Channel channel, uint32_t index) const
373{
374 uint32_t value = 0;
375
378 m_backendHandle, static_cast<PEAK_IPL_LUT_SELECTOR>(selector), static_cast<PEAK_IPL_LUT_CHANNEL>(channel), index, &value);
379 });
380
381 return value;
382}
383
384inline void Lut::SetLutValue(Selector selector, Channel channel, uint32_t index, uint32_t value)
385{
387 return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Lut_SetLutValue(m_backendHandle,
388 static_cast<PEAK_IPL_LUT_SELECTOR>(selector), static_cast<PEAK_IPL_LUT_CHANNEL>(channel), index, value);
389 });
390}
391
392inline std::vector<uint32_t> Lut::AllLutValues(Selector selector, Channel channel) const
393{
394 size_t numLutValues = 0;
395
398 static_cast<PEAK_IPL_LUT_SELECTOR>(selector), static_cast<PEAK_IPL_LUT_CHANNEL>(channel), nullptr, &numLutValues);
399 });
400
401 std::vector<uint32_t> vector(numLutValues);
402
405 static_cast<PEAK_IPL_LUT_SELECTOR>(selector), static_cast<PEAK_IPL_LUT_CHANNEL>(channel),
406 reinterpret_cast<uint32_t*>(vector.data()), &numLutValues);
407 });
408
409 return vector;
410}
411
412inline void Lut::SetAllLutValues(Selector selector, Channel channel, const std::vector<uint32_t>& vector)
413{
416 static_cast<PEAK_IPL_LUT_SELECTOR>(selector), static_cast<PEAK_IPL_LUT_CHANNEL>(channel),
417 reinterpret_cast<const uint32_t*>(vector.data()), vector.size());
418 });
419}
420
421inline void Lut::SetLutPreset(Selector selector, Preset preset)
422{
425 m_backendHandle, static_cast<PEAK_IPL_LUT_SELECTOR>(selector), static_cast<PEAK_IPL_LUT_PRESET>(preset));
426 });
427}
428
429inline bool Lut::IsPixelFormatSupported(PixelFormatName pixelFormatName) const
430{
431 PEAK_IPL_BOOL8 isPixelFormatSupported = 0;
432
435 static_cast<PEAK_IPL_PIXEL_FORMAT>(pixelFormatName),
436 reinterpret_cast<PEAK_IPL_BOOL8*>(&isPixelFormatSupported));
437 });
438
439 return isPixelFormatSupported > 0;
440}
441
442inline void Lut::ProcessInPlace(Image& image) const
443{
446 m_backendHandle, ImageBackendAccessor::BackendHandle(image));
447 });
448}
449
450inline Image Lut::Process(const Image& inputImage) const
451{
452 PEAK_IPL_IMAGE_HANDLE outputImageHandle = nullptr;
455 m_backendHandle, ImageBackendAccessor::BackendHandle(inputImage), &outputImageHandle);
456 });
457
458 return ImageBackendAccessor::CreateImage(outputImageHandle);
459}
460
461} /* namespace ipl */
462} /* namespace peak */
Stores the pixel format, width and height of an image and the pointer to the image buffer.
Definition peak_ipl_image.hpp:42
Applies a LUT to the input image data.
Definition peak_ipl_lut.hpp:46
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:442
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:384
bool IsPixelFormatSupported(PixelFormatName pixelFormatName) const
Returns whether the LUT supports the given pixel format.
Definition peak_ipl_lut.hpp:429
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:372
Channel
Channel parameter to select the channel where the operation is applied.
Definition peak_ipl_lut.hpp:52
@ Blue
Definition peak_ipl_lut.hpp:58
@ All
Definition peak_ipl_lut.hpp:60
@ Green
Definition peak_ipl_lut.hpp:56
@ Red
Definition peak_ipl_lut.hpp:54
void SetLutPreset(Selector selector, Preset preset)
Applies the given preset (identity, inverse, ...) to the specified LUT.
Definition peak_ipl_lut.hpp:421
Image Process(const Image &inputImage) const
Applies the LUT to the given image.
Definition peak_ipl_lut.hpp:450
~Lut()
Destructor for the LUT instance.
Definition peak_ipl_lut.hpp:313
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:392
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:412
Selector
Selector parameter to select to which LUT the operation is applied (8/10/12/16 bit LUT)....
Definition peak_ipl_lut.hpp:68
@ Lut_10Bit
Definition peak_ipl_lut.hpp:72
@ Lut_16Bit
Definition peak_ipl_lut.hpp:76
@ Lut_8Bit
Definition peak_ipl_lut.hpp:70
@ Lut_12Bit
Definition peak_ipl_lut.hpp:74
Preset
Preset Selects a predefined LUT.
Definition peak_ipl_lut.hpp:83
@ Jet
Definition peak_ipl_lut.hpp:99
@ Hot
Definition peak_ipl_lut.hpp:105
@ Rainbow
Definition peak_ipl_lut.hpp:111
@ DigitalBlack25Percent
Definition peak_ipl_lut.hpp:134
@ OnlyRed
Definition peak_ipl_lut.hpp:116
@ Binarize
Definition peak_ipl_lut.hpp:139
@ DigitalGain2
Definition peak_ipl_lut.hpp:130
@ OnlyBlue
Definition peak_ipl_lut.hpp:126
@ Inverse
Definition peak_ipl_lut.hpp:93
@ Identity
Definition peak_ipl_lut.hpp:88
@ OnlyGreen
Definition peak_ipl_lut.hpp:121
Lut & operator=(const Lut &other)
Copy assigment for LUT instance.
Definition peak_ipl_lut.hpp:336
Lut()
Constructor for a new LUT instance.
Definition peak_ipl_lut.hpp:308
PixelFormatName
Enum holding the possible pixel format names.
Definition peak_ipl_simple_types.hpp:38
The "peak::ipl" namespace contains the whole image processing library.
void ExecuteAndMapReturnCodes(const CallableType &callableObject)
Definition peak_ipl_exception.hpp:284
#define PEAK_IPL_NO_DISCARD
Definition peak_ipl_attribute_defines.h:20
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:349
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:333
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:402
struct PEAK_IPL_LUT * PEAK_IPL_LUT_HANDLE
Definition peak_ipl_backend.h:426
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:23
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:324
int32_t PEAK_IPL_PIXEL_FORMAT
Definition peak_ipl_backend.h:170
#define PEAK_IPL_C_ABI_PREFIX
Definition peak_ipl_dll_defines.h:11