Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Scene2D/Internals/CairoFloatTextureRenderer.cpp @ 1640:52b8b96cb55f
cleaning namespaces
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 10 Nov 2020 16:55:22 +0100 |
parents | 8563ea5d8ae4 |
children | 9ac2a65d4172 |
rev | line source |
---|---|
597 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
1270
2d8ab34c8c91
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
889
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
597 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public License |
597 | 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 | |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
15 * Lesser General Public License for more details. |
1596
4fb8fdf03314
removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
16 * |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
17 * You should have received a copy of the GNU Lesser General Public |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
18 * License along with this program. If not, see |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
19 * <http://www.gnu.org/licenses/>. |
597 | 20 **/ |
21 | |
22 | |
23 #include "CairoFloatTextureRenderer.h" | |
24 | |
768
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
597
diff
changeset
|
25 #include "CairoColorTextureRenderer.h" |
597 | 26 #include "../FloatTextureSceneLayer.h" |
27 | |
28 namespace OrthancStone | |
29 { | |
30 namespace Internals | |
31 { | |
32 void CairoFloatTextureRenderer::Update(const ISceneLayer& layer) | |
33 { | |
34 const FloatTextureSceneLayer& l = dynamic_cast<const FloatTextureSceneLayer&>(layer); | |
35 | |
36 textureTransform_ = l.GetTransform(); | |
37 isLinearInterpolation_ = l.IsLinearInterpolation(); | |
38 | |
39 float windowCenter, windowWidth; | |
40 l.GetWindowing(windowCenter, windowWidth); | |
41 | |
771 | 42 const float a = windowCenter - windowWidth / 2.0f; |
770 | 43 const float slope = 256.0f / windowWidth; |
597 | 44 |
45 const Orthanc::ImageAccessor& source = l.GetTexture(); | |
46 const unsigned int width = source.GetWidth(); | |
47 const unsigned int height = source.GetHeight(); | |
48 texture_.SetSize(width, height, false); | |
49 | |
50 Orthanc::ImageAccessor target; | |
51 texture_.GetWriteableAccessor(target); | |
52 | |
53 assert(source.GetFormat() == Orthanc::PixelFormat_Float32 && | |
54 target.GetFormat() == Orthanc::PixelFormat_BGRA32 && | |
55 sizeof(float) == 4); | |
56 | |
1179
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
889
diff
changeset
|
57 static const float LOG_NORMALIZATION = 255.0f / log(1.0f + 255.0f); |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
889
diff
changeset
|
58 |
597 | 59 for (unsigned int y = 0; y < height; y++) |
60 { | |
61 const float* p = reinterpret_cast<const float*>(source.GetConstRow(y)); | |
62 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); | |
63 | |
64 for (unsigned int x = 0; x < width; x++) | |
65 { | |
66 float v = (*p - a) * slope; | |
67 if (v <= 0) | |
68 { | |
69 v = 0; | |
70 } | |
71 else if (v >= 255) | |
72 { | |
73 v = 255; | |
74 } | |
75 | |
1179
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
889
diff
changeset
|
76 if (l.IsApplyLog()) |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
889
diff
changeset
|
77 { |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
889
diff
changeset
|
78 // https://theailearner.com/2019/01/01/log-transformation/ |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
889
diff
changeset
|
79 v = LOG_NORMALIZATION * log(1.0f + static_cast<float>(v)); |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
889
diff
changeset
|
80 } |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
889
diff
changeset
|
81 |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
889
diff
changeset
|
82 assert(v >= 0.0f && v <= 255.0f); |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
889
diff
changeset
|
83 |
597 | 84 uint8_t vv = static_cast<uint8_t>(v); |
85 | |
773
b8dfd966b5f4
FloatTextureSceneLayer::SetInverted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
86 if (l.IsInverted()) |
b8dfd966b5f4
FloatTextureSceneLayer::SetInverted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
87 { |
b8dfd966b5f4
FloatTextureSceneLayer::SetInverted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
88 vv = 255 - vv; |
b8dfd966b5f4
FloatTextureSceneLayer::SetInverted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
89 } |
b8dfd966b5f4
FloatTextureSceneLayer::SetInverted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
90 |
597 | 91 q[0] = vv; |
92 q[1] = vv; | |
93 q[2] = vv; | |
94 | |
95 p++; | |
96 q += 4; | |
97 } | |
98 } | |
99 } | |
100 | |
101 | |
888
6e888cf6a48b
renderers now have access to canvas width/height
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
773
diff
changeset
|
102 void CairoFloatTextureRenderer::Render(const AffineTransform2D& transform, |
6e888cf6a48b
renderers now have access to canvas width/height
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
773
diff
changeset
|
103 unsigned int canvasWidth, |
6e888cf6a48b
renderers now have access to canvas width/height
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
773
diff
changeset
|
104 unsigned int canvasHeight) |
597 | 105 { |
768
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
597
diff
changeset
|
106 CairoColorTextureRenderer::RenderColorTexture(target_, transform, texture_, |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
597
diff
changeset
|
107 textureTransform_, isLinearInterpolation_); |
597 | 108 } |
109 } | |
110 } |