Mercurial > hg > orthanc-stone
annotate Framework/Scene2D/Internals/CairoFloatTextureRenderer.cpp @ 1144:7d23c43ba555 broker
integration mainline->broker
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 08 Nov 2019 18:14:59 +0100 |
parents | 6e79e8c9021c |
children | 177e7d431cd1 2d8ab34c8c91 |
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 | |
5 * Copyright (C) 2017-2019 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 | |
768
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
597
diff
changeset
|
24 #include "CairoColorTextureRenderer.h" |
597 | 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 | |
771 | 41 const float a = windowCenter - windowWidth / 2.0f; |
770 | 42 const float slope = 256.0f / windowWidth; |
597 | 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 for (unsigned int y = 0; y < height; y++) | |
57 { | |
58 const float* p = reinterpret_cast<const float*>(source.GetConstRow(y)); | |
59 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); | |
60 | |
61 for (unsigned int x = 0; x < width; x++) | |
62 { | |
63 float v = (*p - a) * slope; | |
64 if (v <= 0) | |
65 { | |
66 v = 0; | |
67 } | |
68 else if (v >= 255) | |
69 { | |
70 v = 255; | |
71 } | |
72 | |
73 uint8_t vv = static_cast<uint8_t>(v); | |
74 | |
773
b8dfd966b5f4
FloatTextureSceneLayer::SetInverted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
75 if (l.IsInverted()) |
b8dfd966b5f4
FloatTextureSceneLayer::SetInverted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
76 { |
b8dfd966b5f4
FloatTextureSceneLayer::SetInverted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
77 vv = 255 - vv; |
b8dfd966b5f4
FloatTextureSceneLayer::SetInverted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
78 } |
b8dfd966b5f4
FloatTextureSceneLayer::SetInverted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
79 |
597 | 80 q[0] = vv; |
81 q[1] = vv; | |
82 q[2] = vv; | |
83 | |
84 p++; | |
85 q += 4; | |
86 } | |
87 } | |
88 } | |
89 | |
90 | |
888
6e888cf6a48b
renderers now have access to canvas width/height
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
773
diff
changeset
|
91 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
|
92 unsigned int canvasWidth, |
6e888cf6a48b
renderers now have access to canvas width/height
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
773
diff
changeset
|
93 unsigned int canvasHeight) |
597 | 94 { |
768
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
597
diff
changeset
|
95 CairoColorTextureRenderer::RenderColorTexture(target_, transform, texture_, |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
597
diff
changeset
|
96 textureTransform_, isLinearInterpolation_); |
597 | 97 } |
98 } | |
99 } |