Mercurial > hg > orthanc
annotate Core/DicomFormat/DicomIntegerPixelAccessor.cpp @ 656:08eca5d86aad
fixes to cppcheck
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 04 Nov 2013 11:19:31 +0100 |
parents | b8f738685ad2 |
children | 2d0a347e8cfc |
rev | line source |
---|---|
0 | 1 /** |
62 | 2 * Orthanc - A Lightweight, RESTful DICOM Store |
398 | 3 * Copyright (C) 2012-2013 Medical Physics Department, CHU of Liege, |
0 | 4 * Belgium |
5 * | |
6 * This program is free software: you can redistribute it and/or | |
7 * modify it under the terms of the GNU General Public License as | |
8 * published by the Free Software Foundation, either version 3 of the | |
9 * License, or (at your option) any later version. | |
136 | 10 * |
11 * In addition, as a special exception, the copyright holders of this | |
12 * program give permission to link the code of its release with the | |
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
14 * that use the same license as the "OpenSSL" library), and distribute | |
15 * the linked executables. You must obey the GNU General Public License | |
16 * in all respects for all of the code used other than "OpenSSL". If you | |
17 * modify file(s) with this exception, you may extend this exception to | |
18 * your version of the file(s), but you are not obligated to do so. If | |
19 * you do not wish to do so, delete this exception statement from your | |
20 * version. If you delete this exception statement from all source files | |
21 * in the program, then also delete it here. | |
0 | 22 * |
23 * This program is distributed in the hope that it will be useful, but | |
24 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
26 * General Public License for more details. | |
27 * | |
28 * You should have received a copy of the GNU General Public License | |
29 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
30 **/ | |
31 | |
32 | |
6 | 33 #ifndef NOMINMAX |
2 | 34 #define NOMINMAX |
6 | 35 #endif |
36 | |
627 | 37 #include "DicomIntegerPixelAccessor.h" |
38 | |
79 | 39 #include "../OrthancException.h" |
0 | 40 #include <boost/lexical_cast.hpp> |
2 | 41 #include <limits> |
107
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
80
diff
changeset
|
42 #include <cassert> |
368
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
43 #include <stdio.h> |
0 | 44 |
62 | 45 namespace Orthanc |
0 | 46 { |
77 | 47 static const DicomTag COLUMNS(0x0028, 0x0011); |
48 static const DicomTag ROWS(0x0028, 0x0010); | |
49 static const DicomTag SAMPLES_PER_PIXEL(0x0028, 0x0002); | |
50 static const DicomTag BITS_ALLOCATED(0x0028, 0x0100); | |
51 static const DicomTag BITS_STORED(0x0028, 0x0101); | |
52 static const DicomTag HIGH_BIT(0x0028, 0x0102); | |
53 static const DicomTag PIXEL_REPRESENTATION(0x0028, 0x0103); | |
368
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
54 static const DicomTag PLANAR_CONFIGURATION(0x0028, 0x0006); |
77 | 55 |
0 | 56 DicomIntegerPixelAccessor::DicomIntegerPixelAccessor(const DicomMap& values, |
57 const void* pixelData, | |
58 size_t size) : | |
59 pixelData_(pixelData), | |
60 size_(size) | |
61 { | |
62 unsigned int bitsAllocated; | |
63 unsigned int bitsStored; | |
64 unsigned int highBit; | |
65 unsigned int pixelRepresentation; | |
368
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
66 planarConfiguration_ = 0; |
0 | 67 |
68 try | |
69 { | |
77 | 70 width_ = boost::lexical_cast<unsigned int>(values.GetValue(COLUMNS).AsString()); |
71 height_ = boost::lexical_cast<unsigned int>(values.GetValue(ROWS).AsString()); | |
72 samplesPerPixel_ = boost::lexical_cast<unsigned int>(values.GetValue(SAMPLES_PER_PIXEL).AsString()); | |
73 bitsAllocated = boost::lexical_cast<unsigned int>(values.GetValue(BITS_ALLOCATED).AsString()); | |
74 bitsStored = boost::lexical_cast<unsigned int>(values.GetValue(BITS_STORED).AsString()); | |
75 highBit = boost::lexical_cast<unsigned int>(values.GetValue(HIGH_BIT).AsString()); | |
76 pixelRepresentation = boost::lexical_cast<unsigned int>(values.GetValue(PIXEL_REPRESENTATION).AsString()); | |
368
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
77 |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
78 if (samplesPerPixel_ > 1) |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
79 { |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
80 // The "Planar Configuration" is only set when "Samples per Pixels" is greater than 1 |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
81 // https://www.dabsoft.ch/dicom/3/C.7.6.3.1.3/ |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
82 planarConfiguration_ = boost::lexical_cast<unsigned int>(values.GetValue(PLANAR_CONFIGURATION).AsString()); |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
83 } |
0 | 84 } |
85 catch (boost::bad_lexical_cast) | |
86 { | |
62 | 87 throw OrthancException(ErrorCode_NotImplemented); |
0 | 88 } |
368
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
89 catch (OrthancException) |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
90 { |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
91 throw OrthancException(ErrorCode_NotImplemented); |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
92 } |
0 | 93 |
53
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
94 frame_ = 0; |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
95 try |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
96 { |
80 | 97 numberOfFrames_ = boost::lexical_cast<unsigned int>(values.GetValue(DICOM_TAG_NUMBER_OF_FRAMES).AsString()); |
53
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
98 } |
62 | 99 catch (OrthancException) |
53
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
100 { |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
101 // If the tag "NumberOfFrames" is absent, assume there is a single frame |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
102 numberOfFrames_ = 1; |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
103 } |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
104 catch (boost::bad_lexical_cast) |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
105 { |
62 | 106 throw OrthancException(ErrorCode_NotImplemented); |
53
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
107 } |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
108 |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
109 if ((bitsAllocated != 8 && bitsAllocated != 16 && |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
110 bitsAllocated != 24 && bitsAllocated != 32) || |
368
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
111 numberOfFrames_ == 0 || |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
112 (planarConfiguration_ != 0 && planarConfiguration_ != 1)) |
0 | 113 { |
62 | 114 throw OrthancException(ErrorCode_NotImplemented); |
0 | 115 } |
116 | |
117 if (bitsAllocated > 32 || | |
118 bitsStored >= 32) | |
119 { | |
120 // Not available, as the accessor internally uses int32_t values | |
62 | 121 throw OrthancException(ErrorCode_NotImplemented); |
0 | 122 } |
53
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
123 |
369
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
124 if (samplesPerPixel_ == 0) |
0 | 125 { |
62 | 126 throw OrthancException(ErrorCode_NotImplemented); |
0 | 127 } |
128 | |
368
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
129 bytesPerPixel_ = bitsAllocated / 8; |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
130 shift_ = highBit + 1 - bitsStored; |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
131 frameOffset_ = height_ * width_ * bytesPerPixel_ * samplesPerPixel_; |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
132 |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
133 if (numberOfFrames_ * frameOffset_ > size) |
0 | 134 { |
319 | 135 throw OrthancException(ErrorCode_BadFileFormat); |
0 | 136 } |
137 | |
53
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
138 /*printf("%d %d %d %d %d %d %d %d\n", width_, height_, samplesPerPixel_, bitsAllocated, |
368
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
139 bitsStored, highBit, pixelRepresentation, numberOfFrames_);*/ |
0 | 140 |
141 if (pixelRepresentation) | |
142 { | |
537 | 143 // Pixels are signed |
0 | 144 mask_ = (1 << (bitsStored - 1)) - 1; |
145 signMask_ = (1 << (bitsStored - 1)); | |
146 } | |
147 else | |
148 { | |
537 | 149 // Pixels are unsigned |
0 | 150 mask_ = (1 << bitsStored) - 1; |
151 signMask_ = 0; | |
152 } | |
53
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
153 |
368
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
154 if (planarConfiguration_ == 0) |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
155 { |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
156 /** |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
157 * The sample values for the first pixel are followed by the |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
158 * sample values for the second pixel, etc. For RGB images, this |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
159 * means the order of the pixel values sent shall be R1, G1, B1, |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
160 * R2, G2, B2, ..., etc. |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
161 **/ |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
162 rowOffset_ = width_ * bytesPerPixel_ * samplesPerPixel_; |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
163 } |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
164 else |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
165 { |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
166 /** |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
167 * Each color plane shall be sent contiguously. For RGB images, |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
168 * this means the order of the pixel values sent is R1, R2, R3, |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
169 * ..., G1, G2, G3, ..., B1, B2, B3, etc. |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
170 **/ |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
171 rowOffset_ = width_ * bytesPerPixel_; |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
172 } |
0 | 173 } |
174 | |
175 | |
176 void DicomIntegerPixelAccessor::GetExtremeValues(int32_t& min, | |
177 int32_t& max) const | |
178 { | |
179 if (height_ == 0 || width_ == 0) | |
180 { | |
181 min = max = 0; | |
182 return; | |
183 } | |
184 | |
185 min = std::numeric_limits<int32_t>::max(); | |
186 max = std::numeric_limits<int32_t>::min(); | |
187 | |
188 for (unsigned int y = 0; y < height_; y++) | |
189 { | |
190 for (unsigned int x = 0; x < width_; x++) | |
191 { | |
368
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
192 for (unsigned int c = 0; c < GetChannelCount(); c++) |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
193 { |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
194 int32_t v = GetValue(x, y); |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
195 if (v < min) |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
196 min = v; |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
197 if (v > max) |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
198 max = v; |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
199 } |
0 | 200 } |
201 } | |
202 } | |
203 | |
204 | |
368
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
205 int32_t DicomIntegerPixelAccessor::GetValue(unsigned int x, |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
206 unsigned int y, |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
207 unsigned int channel) const |
0 | 208 { |
368
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
209 assert(x < width_ && y < height_ && channel < samplesPerPixel_); |
0 | 210 |
53
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
211 const uint8_t* pixel = reinterpret_cast<const uint8_t*>(pixelData_) + |
368
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
212 y * rowOffset_ + frame_ * frameOffset_; |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
213 |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
214 // https://www.dabsoft.ch/dicom/3/C.7.6.3.1.3/ |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
215 if (planarConfiguration_ == 0) |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
216 { |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
217 /** |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
218 * The sample values for the first pixel are followed by the |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
219 * sample values for the second pixel, etc. For RGB images, this |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
220 * means the order of the pixel values sent shall be R1, G1, B1, |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
221 * R2, G2, B2, ..., etc. |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
222 **/ |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
223 pixel += channel * bytesPerPixel_ + x * samplesPerPixel_ * bytesPerPixel_; |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
224 } |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
225 else |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
226 { |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
227 /** |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
228 * Each color plane shall be sent contiguously. For RGB images, |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
229 * this means the order of the pixel values sent is R1, R2, R3, |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
230 * ..., G1, G2, G3, ..., B1, B2, B3, etc. |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
231 **/ |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
232 assert(frameOffset_ % samplesPerPixel_ == 0); |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
233 pixel += channel * frameOffset_ / samplesPerPixel_ + x * bytesPerPixel_; |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
234 } |
0 | 235 |
464
5987dd8e0776
fix reading signed values in dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
236 uint32_t v; |
0 | 237 v = pixel[0]; |
238 if (bytesPerPixel_ >= 2) | |
464
5987dd8e0776
fix reading signed values in dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
239 v = v + (static_cast<uint32_t>(pixel[1]) << 8); |
0 | 240 if (bytesPerPixel_ >= 3) |
464
5987dd8e0776
fix reading signed values in dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
241 v = v + (static_cast<uint32_t>(pixel[2]) << 16); |
0 | 242 if (bytesPerPixel_ >= 4) |
464
5987dd8e0776
fix reading signed values in dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
243 v = v + (static_cast<uint32_t>(pixel[3]) << 24); |
0 | 244 |
464
5987dd8e0776
fix reading signed values in dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
245 v = v >> shift_; |
0 | 246 |
247 if (v & signMask_) | |
248 { | |
464
5987dd8e0776
fix reading signed values in dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
249 // Signed value |
465
7a966b440f19
signed images to PNG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
464
diff
changeset
|
250 // http://en.wikipedia.org/wiki/Two%27s_complement#Subtraction_from_2N |
7a966b440f19
signed images to PNG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
464
diff
changeset
|
251 return -static_cast<int32_t>(mask_) + static_cast<int32_t>(v & mask_) - 1; |
0 | 252 } |
464
5987dd8e0776
fix reading signed values in dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
253 else |
5987dd8e0776
fix reading signed values in dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
254 { |
5987dd8e0776
fix reading signed values in dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
255 // Unsigned value |
5987dd8e0776
fix reading signed values in dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
256 return static_cast<int32_t>(v & mask_); |
5987dd8e0776
fix reading signed values in dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
257 } |
0 | 258 } |
53
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
259 |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
260 |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
261 void DicomIntegerPixelAccessor::SetCurrentFrame(unsigned int frame) |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
262 { |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
263 if (frame >= numberOfFrames_) |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
264 { |
62 | 265 throw OrthancException(ErrorCode_ParameterOutOfRange); |
53
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
266 } |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
267 |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
268 frame_ = frame; |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
269 } |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
270 |
0 | 271 } |