CVB++ 14.0
lut.hpp
1#pragma once
2
3#if defined _WIN32
4
5#include "../_cexports/c_foundation.h"
6
7#include "../global.hpp"
8#include "../image.hpp"
9#include "../exception.hpp"
10
11#include <iterator>
12#include <vector>
13#include <algorithm>
14#include <memory>
15#include <cstdint>
16
17
18namespace Cvb
19{
20CVB_BEGIN_INLINE_NS
21
22namespace Foundation
23{
24
26
30namespace Lut
31{
32
35{
39 Linear,
41 Cubic
42};
43
45
48{
50 double Level;
52 double Value;
53};
54
56
63template <class RANGE>
64inline typename TypedRange<std::unique_ptr<Image>, int, RANGE>::type ApplyLut(const ImagePlane & plane, const RANGE &values)
65{
66 return Internal::DoResCallObjectOut<Image>([&](void* & resimg)
67 {
68 return CVB_CALL_CAPI(ApplyLUT8Bit (plane.Parent().Handle (), plane.Plane (),
69 reinterpret_cast<CExports::cvbval_t *>(MakeRangeAdapter<int> (values, 256).Data ()),
70 resimg));
71 });
72}
73
75
82template <class RANGE>
83inline typename TypedRange<std::unique_ptr<Image>, std::uint8_t, RANGE>::type ApplyLut(const ImagePlane & plane, const RANGE &values)
84/*template <class ByteRange, class = Private::IsTypedRange<ByteRange, uint8_t>, class = void>
85inline std::unique_ptr<Image> ApplyLut (const ImagePlane & plane, const ByteRange &values)*/
86{
87 std::vector<int> values_int;
88 std::copy (std::begin (values), std::end (values), std::back_inserter (values_int));
89 return ApplyLut (plane, values_int);
90}
91
93
101template <class RANGE>
102inline typename TypedRange<std::unique_ptr<Image>, LutLevel, RANGE>::type ApplyLut(const ImagePlane & plane, const RANGE &levels, LutInterpolation interpolation)
103/*template <class LutLevelRange, class = Private::IsTypedRange<LutLevelRange, LutLevel>>
104inline std::unique_ptr<Image> ApplyLut (const ImagePlane & plane, const LutLevelRange &levels, LutInterpolation interpolation) */
105{
106 std::vector<double> levelData, valueData;
107 for (auto &&lutLevel : levels)
108 {
109 levelData.push_back (lutLevel.Level);
110 valueData.push_back (lutLevel.Value);
111 }
112
113 return Internal::DoResCallObjectOut<Image>([&](void* & resimg)
114 {
115 switch (interpolation)
116 {
118 return CVB_CALL_CAPI(ApplyLUTGeneric (plane.Parent().Handle (), plane.Plane (), static_cast<CExports::cvbval_t>(levelData.size()),
119 const_cast<double*>(levelData.data()), const_cast<double*>(valueData.data ()), resimg));
121 return CVB_CALL_CAPI(ApplyLUTLinear (plane.Parent().Handle (), plane.Plane (), static_cast<CExports::cvbval_t>(levelData.size()),
122 const_cast<double*>(levelData.data()), const_cast<double*>(valueData.data ()), resimg));
124 return CVB_CALL_CAPI(ApplyLUTCubic (plane.Parent().Handle (), plane.Plane (), static_cast<CExports::cvbval_t>(levelData.size()),
125 const_cast<double*>(levelData.data()), const_cast<double*>(valueData.data ()), resimg));
126 default:
127 throw std::invalid_argument ("unknown LUT interpolation mode");
128 }
129 });
130}
131
132} /* namespace Lut */
133
135using Lut::LutLevel;
136
137using Lut::ApplyLut;
138
139} /* namespace Foundation */
140CVB_END_INLINE_NS
141} /* namespace Cvb */
142
143#endif
Image plane information container.
Definition: decl_image_plane.hpp:33
LutInterpolation
Different approaches for interpolating between lookup table (LUT) values and levels.
Definition: lut.hpp:35
@ Linear
Linear interpolation between two adjacent LUT levels.
@ Constant
LUT values are constant between two LUT levels.
@ Cubic
Cubic interpolation between two adjacent LUT levels.
TypedRange< std::unique_ptr< Image >, int, RANGE >::type ApplyLut(const ImagePlane &plane, const RANGE &values)
Apply a lookup table to an 8 bit per pixel input image plane.
Definition: lut.hpp:64
Root namespace for the Image Manager interface.
Definition: c_barcode.h:24
Struct that combines a LUT (lookup table) level and the value assigned to this level.
Definition: lut.hpp:48
double Level
Gray value level at which the value applies.
Definition: lut.hpp:50
double Value
Transformed gray value, that applies to the associated gray level.
Definition: lut.hpp:52