Mercurial > hg > orthanc-stone
comparison Framework/Scene2D/Internals/OpenGLLookupTableTextureRenderer.cpp @ 1179:177e7d431cd1 broker
log scale in textures, remove redundant code for LUTs
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 20 Nov 2019 15:24:20 +0100 |
parents | f6be9412e42a |
children | 0ca50d275b9a |
comparison
equal
deleted
inserted
replaced
1178:3c7cdbf32e2a | 1179:177e7d431cd1 |
---|---|
34 { | 34 { |
35 const Orthanc::ImageAccessor& source = layer.GetTexture(); | 35 const Orthanc::ImageAccessor& source = layer.GetTexture(); |
36 const unsigned int width = source.GetWidth(); | 36 const unsigned int width = source.GetWidth(); |
37 const unsigned int height = source.GetHeight(); | 37 const unsigned int height = source.GetHeight(); |
38 | 38 |
39 if ((texture_.get() == NULL) || | 39 if (texture_.get() == NULL || |
40 (texture_->GetWidth() != width) || | 40 texture_->GetWidth() != width || |
41 (texture_->GetHeight() != height)) | 41 texture_->GetHeight() != height) |
42 { | 42 { |
43 | 43 texture_.reset(new Orthanc::Image(Orthanc::PixelFormat_RGBA32, width, height, false)); |
44 texture_.reset(new Orthanc::Image( | |
45 Orthanc::PixelFormat_RGBA32, | |
46 width, | |
47 height, | |
48 false)); | |
49 } | 44 } |
50 | 45 |
51 { | 46 layer.Render(*texture_); |
52 | |
53 const float a = layer.GetMinValue(); | |
54 float slope = 0; | |
55 | |
56 if (layer.GetMinValue() >= layer.GetMaxValue()) | |
57 { | |
58 slope = 0; | |
59 } | |
60 else | |
61 { | |
62 slope = 256.0f / (layer.GetMaxValue() - layer.GetMinValue()); | |
63 } | |
64 | |
65 Orthanc::ImageAccessor target; | |
66 texture_->GetWriteableAccessor(target); | |
67 | |
68 const std::vector<uint8_t>& lut = layer.GetLookupTable(); | |
69 if (lut.size() != 4 * 256) | |
70 { | |
71 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
72 } | |
73 | |
74 assert(source.GetFormat() == Orthanc::PixelFormat_Float32 && | |
75 target.GetFormat() == Orthanc::PixelFormat_RGBA32 && | |
76 sizeof(float) == 4); | |
77 | |
78 for (unsigned int y = 0; y < height; y++) | |
79 { | |
80 const float* p = reinterpret_cast<const float*>(source.GetConstRow(y)); | |
81 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); | |
82 | |
83 for (unsigned int x = 0; x < width; x++) | |
84 { | |
85 float v = (*p - a) * slope; | |
86 if (v <= 0) | |
87 { | |
88 v = 0; | |
89 } | |
90 else if (v >= 255) | |
91 { | |
92 v = 255; | |
93 } | |
94 | |
95 uint8_t vv = static_cast<uint8_t>(v); | |
96 | |
97 q[0] = lut[4 * vv + 0]; // R | |
98 q[1] = lut[4 * vv + 1]; // G | |
99 q[2] = lut[4 * vv + 2]; // B | |
100 q[3] = lut[4 * vv + 3]; // A | |
101 | |
102 p++; | |
103 q += 4; | |
104 } | |
105 } | |
106 } | |
107 | 47 |
108 context_.MakeCurrent(); | 48 context_.MakeCurrent(); |
109 glTexture_.reset(new OpenGL::OpenGLTexture(context_)); | 49 glTexture_.reset(new OpenGL::OpenGLTexture(context_)); |
110 glTexture_->Load(*texture_, layer.IsLinearInterpolation()); | 50 glTexture_->Load(*texture_, layer.IsLinearInterpolation()); |
111 layerTransform_ = layer.GetTransform(); | 51 layerTransform_ = layer.GetTransform(); |