Mercurial > hg > orthanc-stone
comparison OrthancStone/Sources/Scene2D/Internals/CairoFloatTextureRenderer.cpp @ 1512:244ad1e4e76a
reorganization of folders
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 07 Jul 2020 16:21:02 +0200 |
parents | Framework/Scene2D/Internals/CairoFloatTextureRenderer.cpp@7ec8fea061b9 |
children | 4fb8fdf03314 |
comparison
equal
deleted
inserted
replaced
1511:9dfeee74c1e6 | 1512:244ad1e4e76a |
---|---|
1 /** | |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium | |
6 * | |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Affero General Public License | |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
22 #include "CairoFloatTextureRenderer.h" | |
23 | |
24 #include "CairoColorTextureRenderer.h" | |
25 #include "../FloatTextureSceneLayer.h" | |
26 | |
27 namespace OrthancStone | |
28 { | |
29 namespace Internals | |
30 { | |
31 void CairoFloatTextureRenderer::Update(const ISceneLayer& layer) | |
32 { | |
33 const FloatTextureSceneLayer& l = dynamic_cast<const FloatTextureSceneLayer&>(layer); | |
34 | |
35 textureTransform_ = l.GetTransform(); | |
36 isLinearInterpolation_ = l.IsLinearInterpolation(); | |
37 | |
38 float windowCenter, windowWidth; | |
39 l.GetWindowing(windowCenter, windowWidth); | |
40 | |
41 const float a = windowCenter - windowWidth / 2.0f; | |
42 const float slope = 256.0f / windowWidth; | |
43 | |
44 const Orthanc::ImageAccessor& source = l.GetTexture(); | |
45 const unsigned int width = source.GetWidth(); | |
46 const unsigned int height = source.GetHeight(); | |
47 texture_.SetSize(width, height, false); | |
48 | |
49 Orthanc::ImageAccessor target; | |
50 texture_.GetWriteableAccessor(target); | |
51 | |
52 assert(source.GetFormat() == Orthanc::PixelFormat_Float32 && | |
53 target.GetFormat() == Orthanc::PixelFormat_BGRA32 && | |
54 sizeof(float) == 4); | |
55 | |
56 static const float LOG_NORMALIZATION = 255.0f / log(1.0f + 255.0f); | |
57 | |
58 for (unsigned int y = 0; y < height; y++) | |
59 { | |
60 const float* p = reinterpret_cast<const float*>(source.GetConstRow(y)); | |
61 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); | |
62 | |
63 for (unsigned int x = 0; x < width; x++) | |
64 { | |
65 float v = (*p - a) * slope; | |
66 if (v <= 0) | |
67 { | |
68 v = 0; | |
69 } | |
70 else if (v >= 255) | |
71 { | |
72 v = 255; | |
73 } | |
74 | |
75 if (l.IsApplyLog()) | |
76 { | |
77 // https://theailearner.com/2019/01/01/log-transformation/ | |
78 v = LOG_NORMALIZATION * log(1.0f + static_cast<float>(v)); | |
79 } | |
80 | |
81 assert(v >= 0.0f && v <= 255.0f); | |
82 | |
83 uint8_t vv = static_cast<uint8_t>(v); | |
84 | |
85 if (l.IsInverted()) | |
86 { | |
87 vv = 255 - vv; | |
88 } | |
89 | |
90 q[0] = vv; | |
91 q[1] = vv; | |
92 q[2] = vv; | |
93 | |
94 p++; | |
95 q += 4; | |
96 } | |
97 } | |
98 } | |
99 | |
100 | |
101 void CairoFloatTextureRenderer::Render(const AffineTransform2D& transform, | |
102 unsigned int canvasWidth, | |
103 unsigned int canvasHeight) | |
104 { | |
105 CairoColorTextureRenderer::RenderColorTexture(target_, transform, texture_, | |
106 textureTransform_, isLinearInterpolation_); | |
107 } | |
108 } | |
109 } |