Mercurial > hg > orthanc-stone
annotate Framework/Deprecated/Layers/GrayscaleFrameRenderer.cpp @ 1313:f30905f5d246 broker
Added support for OnGenericSdlEvent to GuiAdapter.
This makes it possible to piggyback app-specific logic
to special events (here, to support the Viewport refresh
events)
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Mon, 16 Mar 2020 11:12:39 +0100 |
parents | 8a0a62189f46 |
children | 30deba7bc8e2 |
rev | line source |
---|---|
0 | 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:
732
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
0 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
47 | 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. | |
0 | 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 | |
47 | 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 | |
0 | 18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 **/ | |
20 | |
21 | |
22 #include "GrayscaleFrameRenderer.h" | |
23 | |
378 | 24 #include <Core/Images/Image.h> |
212
5412adf19980
resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
25 #include <Core/OrthancException.h> |
0 | 26 |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
27 namespace Deprecated |
0 | 28 { |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
29 OrthancStone::CairoSurface* GrayscaleFrameRenderer::GenerateDisplay(const RenderStyle& style) |
0 | 30 { |
338 | 31 assert(frame_->GetFormat() == Orthanc::PixelFormat_Float32); |
32 | |
1298
8a0a62189f46
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1270
diff
changeset
|
33 std::unique_ptr<OrthancStone::CairoSurface> result; |
0 | 34 |
35 float windowCenter, windowWidth; | |
36 style.ComputeWindowing(windowCenter, windowWidth, | |
37 defaultWindowCenter_, defaultWindowWidth_); | |
38 | |
39 float x0 = windowCenter - windowWidth / 2.0f; | |
40 float x1 = windowCenter + windowWidth / 2.0f; | |
41 | |
42 //LOG(INFO) << "Window: " << x0 << " => " << x1; | |
43 | |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
44 result.reset(new OrthancStone::CairoSurface(frame_->GetWidth(), frame_->GetHeight(), false /* no alpha */)); |
0 | 45 |
46 const uint8_t* lut = NULL; | |
47 if (style.applyLut_) | |
48 { | |
49 if (Orthanc::EmbeddedResources::GetFileResourceSize(style.lut_) != 3 * 256) | |
50 { | |
51 // Invalid colormap | |
52 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
53 } | |
54 | |
55 lut = reinterpret_cast<const uint8_t*>(Orthanc::EmbeddedResources::GetFileResourceBuffer(style.lut_)); | |
56 } | |
106 | 57 |
316
ce48c3b3b0e9
fix for new ImageAccessor API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
58 Orthanc::ImageAccessor target; |
ce48c3b3b0e9
fix for new ImageAccessor API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
59 result->GetWriteableAccessor(target); |
ce48c3b3b0e9
fix for new ImageAccessor API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
60 |
106 | 61 const unsigned int width = target.GetWidth(); |
62 const unsigned int height = target.GetHeight(); | |
63 | |
64 for (unsigned int y = 0; y < height; y++) | |
0 | 65 { |
66 const float* p = reinterpret_cast<const float*>(frame_->GetConstRow(y)); | |
67 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); | |
68 | |
106 | 69 for (unsigned int x = 0; x < width; x++, p++, q += 4) |
0 | 70 { |
71 uint8_t v = 0; | |
72 if (windowWidth >= 0.001f) // Avoid division by zero | |
73 { | |
74 if (*p >= x1) | |
75 { | |
76 v = 255; | |
77 } | |
78 else if (*p <= x0) | |
79 { | |
80 v = 0; | |
81 } | |
82 else | |
83 { | |
84 // https://en.wikipedia.org/wiki/Linear_interpolation | |
85 v = static_cast<uint8_t>(255.0f * (*p - x0) / (x1 - x0)); | |
86 } | |
87 | |
328
c80b5bddf86b
support of monochrome1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
318
diff
changeset
|
88 if (style.reverse_ ^ (photometric_ == Orthanc::PhotometricInterpretation_Monochrome1)) |
0 | 89 { |
90 v = 255 - v; | |
91 } | |
92 } | |
93 | |
94 if (style.applyLut_) | |
95 { | |
96 assert(lut != NULL); | |
97 q[3] = 255; | |
98 q[2] = lut[3 * v]; | |
99 q[1] = lut[3 * v + 1]; | |
100 q[0] = lut[3 * v + 2]; | |
101 } | |
102 else | |
103 { | |
104 q[3] = 255; | |
105 q[2] = v; | |
106 q[1] = v; | |
107 q[0] = v; | |
108 } | |
109 } | |
110 } | |
111 | |
112 return result.release(); | |
113 } | |
114 | |
115 | |
378 | 116 GrayscaleFrameRenderer::GrayscaleFrameRenderer(const Orthanc::ImageAccessor& frame, |
714
d2c0e347ddc2
deprecating DicomFrameConverter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
561
diff
changeset
|
117 const Deprecated::DicomFrameConverter& converter, |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
118 const OrthancStone::CoordinateSystem3D& framePlane, |
0 | 119 double pixelSpacingX, |
120 double pixelSpacingY, | |
121 bool isFullQuality) : | |
394
17d54c028805
rename ILayerRenderer::GetLayerSlice() to GetLayerPlane()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
378
diff
changeset
|
122 FrameRenderer(framePlane, pixelSpacingX, pixelSpacingY, isFullQuality), |
378 | 123 frame_(Orthanc::Image::Clone(frame)), |
516
11fa6f00e33c
Dummy changes (warnings, dummy dtor to check proper deletion, line wrapping) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
439
diff
changeset
|
124 defaultWindowCenter_(static_cast<float>(converter.GetDefaultWindowCenter())), |
11fa6f00e33c
Dummy changes (warnings, dummy dtor to check proper deletion, line wrapping) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
439
diff
changeset
|
125 defaultWindowWidth_(static_cast<float>(converter.GetDefaultWindowWidth())), |
328
c80b5bddf86b
support of monochrome1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
318
diff
changeset
|
126 photometric_(converter.GetPhotometricInterpretation()) |
0 | 127 { |
378 | 128 if (frame_.get() == NULL) |
0 | 129 { |
130 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
131 } | |
132 | |
338 | 133 converter.ConvertFrameInplace(frame_); |
0 | 134 assert(frame_.get() != NULL); |
135 | |
136 if (frame_->GetFormat() != Orthanc::PixelFormat_Float32) | |
137 { | |
138 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat); | |
139 } | |
140 } | |
141 } |