Mercurial > hg > orthanc-stone
comparison Framework/Scene2D/LookupTableTextureSceneLayer.cpp @ 769:4ba8892870a2
improved interface for lookup tables
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 23 May 2019 20:37:19 +0200 |
parents | 55411e7da2f7 |
children | 11fc84650e4b |
comparison
equal
deleted
inserted
replaced
768:55411e7da2f7 | 769:4ba8892870a2 |
---|---|
50 | 50 |
51 Orthanc::ImageProcessing::Convert(*t, texture); | 51 Orthanc::ImageProcessing::Convert(*t, texture); |
52 SetTexture(t.release()); | 52 SetTexture(t.release()); |
53 } | 53 } |
54 | 54 |
55 SetLookupTableGrayscale(1); | 55 SetLookupTableGrayscale(); |
56 SetRange(0, 1); | 56 SetRange(0, 1); |
57 } | 57 } |
58 | 58 |
59 | 59 |
60 void LookupTableTextureSceneLayer::SetLookupTableGrayscale(float alpha) | 60 void LookupTableTextureSceneLayer::SetLookupTableGrayscale() |
61 { | 61 { |
62 std::vector<uint8_t> rgb(3 * 256); | 62 std::vector<uint8_t> rgb(3 * 256); |
63 | 63 |
64 for (size_t i = 0; i < 256; i++) | 64 for (size_t i = 0; i < 256; i++) |
65 { | 65 { |
66 rgb[3 * i] = i; | 66 rgb[3 * i] = i; |
67 rgb[3 * i + 1] = i; | 67 rgb[3 * i + 1] = i; |
68 rgb[3 * i + 2] = i; | 68 rgb[3 * i + 2] = i; |
69 } | 69 } |
70 | 70 |
71 SetLookupTableRgb(rgb, alpha); | 71 SetLookupTableRgb(rgb); |
72 } | 72 } |
73 | 73 |
74 | 74 |
75 void LookupTableTextureSceneLayer::SetLookupTableRgb(const std::vector<uint8_t>& lut, | 75 void LookupTableTextureSceneLayer::SetLookupTableRgb(const std::vector<uint8_t>& lut) |
76 float alpha) | |
77 { | 76 { |
78 if (lut.size() != 3 * 256 || | 77 if (lut.size() != 3 * 256) |
79 alpha < 0 || | |
80 alpha > 1) | |
81 { | 78 { |
82 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | 79 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
83 } | 80 } |
84 | 81 |
85 lut_.resize(4 * 256); | 82 lut_.resize(4 * 256); |
86 | 83 |
87 for (size_t i = 0; i < 256; i++) | 84 for (size_t i = 0; i < 256; i++) |
96 lut_[4 * i + 2] = 0; // B | 93 lut_[4 * i + 2] = 0; // B |
97 lut_[4 * i + 3] = 0; // A | 94 lut_[4 * i + 3] = 0; // A |
98 } | 95 } |
99 else | 96 else |
100 { | 97 { |
101 float r = static_cast<float>(lut[3 * i]) * alpha; | 98 float a = static_cast<float>(i) / 255.0f; |
102 float g = static_cast<float>(lut[3 * i + 1]) * alpha; | 99 |
103 float b = static_cast<float>(lut[3 * i + 2]) * alpha; | 100 float r = static_cast<float>(lut[3 * i]) * a; |
101 float g = static_cast<float>(lut[3 * i + 1]) * a; | |
102 float b = static_cast<float>(lut[3 * i + 2]) * a; | |
104 | 103 |
105 lut_[4 * i] = static_cast<uint8_t>(std::floor(r)); | 104 lut_[4 * i] = static_cast<uint8_t>(std::floor(r)); |
106 lut_[4 * i + 1] = static_cast<uint8_t>(std::floor(g)); | 105 lut_[4 * i + 1] = static_cast<uint8_t>(std::floor(g)); |
107 lut_[4 * i + 2] = static_cast<uint8_t>(std::floor(b)); | 106 lut_[4 * i + 2] = static_cast<uint8_t>(std::floor(b)); |
108 lut_[4 * i + 3] = static_cast<uint8_t>(std::floor(alpha * 255.0f)); | 107 lut_[4 * i + 3] = static_cast<uint8_t>(std::floor(a * 255.0f)); |
109 } | 108 } |
110 } | 109 } |
111 | 110 |
112 IncrementRevision(); | 111 IncrementRevision(); |
113 } | 112 } |
114 | 113 |
115 | 114 |
116 void LookupTableTextureSceneLayer::SetLookupTableRgb(const std::string& lut, | |
117 float alpha) | |
118 { | |
119 std::vector<uint8_t> tmp; | |
120 StringToVector(tmp, lut); | |
121 SetLookupTableRgb(tmp, alpha); | |
122 } | |
123 | |
124 | |
125 void LookupTableTextureSceneLayer::SetLookupTable(const std::vector<uint8_t>& lut) | 115 void LookupTableTextureSceneLayer::SetLookupTable(const std::vector<uint8_t>& lut) |
126 { | 116 { |
127 if (lut.size() != 4 * 256) | 117 if (lut.size() == 4 * 256) |
118 { | |
119 lut_ = lut; | |
120 IncrementRevision(); | |
121 } | |
122 else if (lut.size() == 3 * 256) | |
123 { | |
124 SetLookupTableRgb(lut); | |
125 } | |
126 else | |
128 { | 127 { |
129 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | 128 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
130 } | 129 } |
131 | |
132 lut_ = lut; | |
133 | |
134 IncrementRevision(); | |
135 } | 130 } |
136 | 131 |
137 | 132 |
138 void LookupTableTextureSceneLayer::SetLookupTable(const std::string& lut) | 133 void LookupTableTextureSceneLayer::SetLookupTable(const std::string& lut) |
139 { | 134 { |