Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Scene2D/Internals/CairoFloatTextureRenderer.cpp @ 1925:a7a77488ddb1
fix
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 23 Mar 2022 14:21:22 +0100 |
parents | 7053b8a0aaec |
children | 07964689cb0b |
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 | |
1871
7053b8a0aaec
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1870
diff
changeset
|
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium |
7053b8a0aaec
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1870
diff
changeset
|
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
597 | 7 * |
8 * 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
|
9 * modify it under the terms of the GNU Lesser General Public License |
597 | 10 * as published by the Free Software Foundation, either version 3 of |
11 * the License, or (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, but | |
14 * 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
|
15 * 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
|
16 * Lesser General Public License for more details. |
1596
4fb8fdf03314
removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
17 * |
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
|
18 * 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
|
19 * 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
|
20 * <http://www.gnu.org/licenses/>. |
597 | 21 **/ |
22 | |
23 | |
24 #include "CairoFloatTextureRenderer.h" | |
25 | |
768
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
597
diff
changeset
|
26 #include "CairoColorTextureRenderer.h" |
597 | 27 #include "../FloatTextureSceneLayer.h" |
28 | |
29 namespace OrthancStone | |
30 { | |
31 namespace Internals | |
32 { | |
33 void CairoFloatTextureRenderer::Update(const ISceneLayer& layer) | |
34 { | |
35 const FloatTextureSceneLayer& l = dynamic_cast<const FloatTextureSceneLayer&>(layer); | |
36 | |
37 textureTransform_ = l.GetTransform(); | |
38 isLinearInterpolation_ = l.IsLinearInterpolation(); | |
39 | |
40 float windowCenter, windowWidth; | |
41 l.GetWindowing(windowCenter, windowWidth); | |
42 | |
771 | 43 const float a = windowCenter - windowWidth / 2.0f; |
770 | 44 const float slope = 256.0f / windowWidth; |
597 | 45 |
46 const Orthanc::ImageAccessor& source = l.GetTexture(); | |
47 const unsigned int width = source.GetWidth(); | |
48 const unsigned int height = source.GetHeight(); | |
49 texture_.SetSize(width, height, false); | |
50 | |
51 Orthanc::ImageAccessor target; | |
52 texture_.GetWriteableAccessor(target); | |
53 | |
54 assert(source.GetFormat() == Orthanc::PixelFormat_Float32 && | |
55 target.GetFormat() == Orthanc::PixelFormat_BGRA32 && | |
56 sizeof(float) == 4); | |
57 | |
1179
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
889
diff
changeset
|
58 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
|
59 |
597 | 60 for (unsigned int y = 0; y < height; y++) |
61 { | |
62 const float* p = reinterpret_cast<const float*>(source.GetConstRow(y)); | |
63 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); | |
64 | |
65 for (unsigned int x = 0; x < width; x++) | |
66 { | |
67 float v = (*p - a) * slope; | |
68 if (v <= 0) | |
69 { | |
70 v = 0; | |
71 } | |
72 else if (v >= 255) | |
73 { | |
74 v = 255; | |
75 } | |
76 | |
1179
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
889
diff
changeset
|
77 if (l.IsApplyLog()) |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
889
diff
changeset
|
78 { |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
889
diff
changeset
|
79 // 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
|
80 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
|
81 } |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
889
diff
changeset
|
82 |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
889
diff
changeset
|
83 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
|
84 |
597 | 85 uint8_t vv = static_cast<uint8_t>(v); |
86 | |
773
b8dfd966b5f4
FloatTextureSceneLayer::SetInverted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
87 if (l.IsInverted()) |
b8dfd966b5f4
FloatTextureSceneLayer::SetInverted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
88 { |
b8dfd966b5f4
FloatTextureSceneLayer::SetInverted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
89 vv = 255 - vv; |
b8dfd966b5f4
FloatTextureSceneLayer::SetInverted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
90 } |
b8dfd966b5f4
FloatTextureSceneLayer::SetInverted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
91 |
597 | 92 q[0] = vv; |
93 q[1] = vv; | |
94 q[2] = vv; | |
95 | |
96 p++; | |
97 q += 4; | |
98 } | |
99 } | |
100 } | |
101 | |
102 | |
888
6e888cf6a48b
renderers now have access to canvas width/height
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
773
diff
changeset
|
103 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
|
104 unsigned int canvasWidth, |
6e888cf6a48b
renderers now have access to canvas width/height
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
773
diff
changeset
|
105 unsigned int canvasHeight) |
597 | 106 { |
768
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
597
diff
changeset
|
107 CairoColorTextureRenderer::RenderColorTexture(target_, transform, texture_, |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
597
diff
changeset
|
108 textureTransform_, isLinearInterpolation_); |
597 | 109 } |
110 } | |
111 } |