Mercurial > hg > orthanc
annotate OrthancFramework/Sources/DicomFormat/DicomIntegerPixelAccessor.cpp @ 5660:e4d9a872998f
replaced incorrect macro WIN32 by _WIN32
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sun, 23 Jun 2024 10:24:31 +0200 |
parents | f7adfb22e20e |
children |
rev | line source |
---|---|
0 | 1 /** |
62 | 2 * Orthanc - A Lightweight, RESTful DICOM Store |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
860
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
5640
f7adfb22e20e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
f7adfb22e20e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium |
5485
48b8dae6dc77
upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
0 | 8 * |
9 * This program is free software: you can redistribute it and/or | |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
10 * modify it under the terms of the GNU Lesser General Public License |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
11 * as published by the Free Software Foundation, either version 3 of |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
12 * the License, or (at your option) any later version. |
136 | 13 * |
0 | 14 * This program is distributed in the hope that it will be useful, but |
15 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
17 * Lesser General Public License for more details. |
0 | 18 * |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
19 * You should have received a copy of the GNU Lesser General Public |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
20 * License along with this program. If not, see |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
21 * <http://www.gnu.org/licenses/>. |
0 | 22 **/ |
23 | |
24 | |
824
a811bdf8b8eb
precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
800
diff
changeset
|
25 #include "../PrecompiledHeaders.h" |
a811bdf8b8eb
precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
800
diff
changeset
|
26 |
6 | 27 #ifndef NOMINMAX |
2 | 28 #define NOMINMAX |
6 | 29 #endif |
30 | |
627 | 31 #include "DicomIntegerPixelAccessor.h" |
32 | |
79 | 33 #include "../OrthancException.h" |
0 | 34 #include <boost/lexical_cast.hpp> |
2 | 35 #include <limits> |
107
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
80
diff
changeset
|
36 #include <cassert> |
368
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
37 #include <stdio.h> |
0 | 38 |
62 | 39 namespace Orthanc |
0 | 40 { |
41 DicomIntegerPixelAccessor::DicomIntegerPixelAccessor(const DicomMap& values, | |
42 const void* pixelData, | |
43 size_t size) : | |
853
839be3022203
DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
44 information_(values), |
0 | 45 pixelData_(pixelData), |
46 size_(size) | |
47 { | |
2279
16e45af17a4d
Ability to retrieve raw frames encoded as unsigned 32-bits integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
48 if (information_.GetBitsAllocated() > 32 || |
16e45af17a4d
Ability to retrieve raw frames encoded as unsigned 32-bits integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
49 information_.GetBitsStored() >= 32) |
16e45af17a4d
Ability to retrieve raw frames encoded as unsigned 32-bits integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
50 { |
16e45af17a4d
Ability to retrieve raw frames encoded as unsigned 32-bits integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
51 // Not available, as the accessor internally uses int32_t values |
16e45af17a4d
Ability to retrieve raw frames encoded as unsigned 32-bits integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
52 throw OrthancException(ErrorCode_NotImplemented); |
16e45af17a4d
Ability to retrieve raw frames encoded as unsigned 32-bits integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
53 } |
16e45af17a4d
Ability to retrieve raw frames encoded as unsigned 32-bits integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
54 |
853
839be3022203
DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
55 frame_ = 0; |
1924
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1908
diff
changeset
|
56 frameOffset_ = information_.GetFrameSize(); |
0 | 57 |
853
839be3022203
DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
58 if (information_.GetNumberOfFrames() * frameOffset_ > size) |
0 | 59 { |
319 | 60 throw OrthancException(ErrorCode_BadFileFormat); |
0 | 61 } |
62 | |
853
839be3022203
DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
63 if (information_.IsSigned()) |
0 | 64 { |
537 | 65 // Pixels are signed |
853
839be3022203
DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
66 mask_ = (1 << (information_.GetBitsStored() - 1)) - 1; |
839be3022203
DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
67 signMask_ = (1 << (information_.GetBitsStored() - 1)); |
0 | 68 } |
69 else | |
70 { | |
537 | 71 // Pixels are unsigned |
853
839be3022203
DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
72 mask_ = (1 << information_.GetBitsStored()) - 1; |
0 | 73 signMask_ = 0; |
74 } | |
53
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
75 |
853
839be3022203
DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
76 if (information_.IsPlanar()) |
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 /** |
857 | 79 * Each color plane shall be sent contiguously. For RGB images, |
80 * this means the order of the pixel values sent is R1, R2, R3, | |
81 * ..., G1, G2, G3, ..., B1, B2, B3, etc. | |
82 **/ | |
860 | 83 rowOffset_ = information_.GetWidth() * information_.GetBytesPerValue(); |
857 | 84 } |
85 else | |
86 { | |
87 /** | |
368
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
88 * 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
|
89 * 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
|
90 * 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
|
91 * R2, G2, B2, ..., etc. |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
92 **/ |
4827
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
93 if (information_.GetBitsStored() == 1) |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
94 { |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
95 if (information_.GetChannelCount() == 1 && |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
96 information_.GetBitsAllocated() == 1) |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
97 { |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
98 assert(information_.GetWidth() % 8 == 0); // Tested by DicomImageInformation |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
99 rowOffset_ = information_.GetWidth() / 8; |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
100 } |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
101 else |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
102 { |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
103 throw OrthancException(ErrorCode_IncompatibleImageFormat, |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
104 "Image not supported (multi-channel black-and-image image)"); |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
105 } |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
106 } |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
107 else |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
108 { |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
109 rowOffset_ = information_.GetWidth() * information_.GetBytesPerValue() * information_.GetChannelCount(); |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
110 } |
368
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
111 } |
0 | 112 } |
113 | |
114 | |
115 void DicomIntegerPixelAccessor::GetExtremeValues(int32_t& min, | |
116 int32_t& max) const | |
117 { | |
853
839be3022203
DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
118 if (information_.GetHeight() == 0 || information_.GetWidth() == 0) |
0 | 119 { |
120 min = max = 0; | |
121 return; | |
122 } | |
123 | |
124 min = std::numeric_limits<int32_t>::max(); | |
125 max = std::numeric_limits<int32_t>::min(); | |
4278
9279de56a405
avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
126 |
9279de56a405
avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
127 const unsigned int height = information_.GetHeight(); |
9279de56a405
avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
128 const unsigned int width = information_.GetWidth(); |
9279de56a405
avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
129 const unsigned int channels = information_.GetChannelCount(); |
0 | 130 |
4278
9279de56a405
avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
131 for (unsigned int y = 0; y < height; y++) |
0 | 132 { |
4278
9279de56a405
avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
133 for (unsigned int x = 0; x < width; x++) |
0 | 134 { |
4278
9279de56a405
avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
135 for (unsigned int c = 0; c < channels; c++) |
368
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
136 { |
4825
381c2ca04860
fix DicomIntegerPixelAccessor::GetExtremeValues() on multi-channel images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
137 int32_t v = GetValue(x, y, c); |
368
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
138 if (v < min) |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
139 min = v; |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
140 if (v > max) |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
141 max = v; |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
142 } |
0 | 143 } |
144 } | |
145 } | |
146 | |
147 | |
368
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
148 int32_t DicomIntegerPixelAccessor::GetValue(unsigned int x, |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
149 unsigned int y, |
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
150 unsigned int channel) const |
0 | 151 { |
857 | 152 assert(x < information_.GetWidth() && |
153 y < information_.GetHeight() && | |
154 channel < information_.GetChannelCount()); | |
4827
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
155 |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
156 const uint8_t* pixel = (reinterpret_cast<const uint8_t*>(pixelData_) + |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
157 y * rowOffset_ + frame_ * frameOffset_); |
0 | 158 |
4827
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
159 if (information_.GetBitsStored() == 1) |
857 | 160 { |
4902
df86d2505df8
Orthanc 1.9.8 is now known as Orthanc 1.10.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
161 // New in Orthanc 1.10.0, notably for DICOM SEG |
4827
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
162 assert(information_.GetBitsAllocated() == 1 && |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
163 information_.GetChannelCount() == 1 && |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
164 !information_.IsPlanar()); |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
165 |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
166 uint8_t b = pixel[x / 8]; |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
167 |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
168 if (b & (1 << (x % 8))) |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
169 { |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
170 return 255; |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
171 } |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
172 else |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
173 { |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
174 return 0; |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
175 } |
857 | 176 } |
177 else | |
368
80011cd589e6
support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
319
diff
changeset
|
178 { |
4827
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
179 // http://dicom.nema.org/medical/dicom/current/output/html/part03.html#sect_C.7.6.3.1.3 |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
180 if (information_.IsPlanar()) |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
181 { |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
182 /** |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
183 * Each color plane shall be sent contiguously. For RGB images, |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
184 * this means the order of the pixel values sent is R1, R2, R3, |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
185 * ..., G1, G2, G3, ..., B1, B2, B3, etc. |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
186 **/ |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
187 assert(frameOffset_ % information_.GetChannelCount() == 0); |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
188 pixel += channel * frameOffset_ / information_.GetChannelCount() + x * information_.GetBytesPerValue(); |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
189 } |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
190 else |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
191 { |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
192 /** |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
193 * The sample values for the first pixel are followed by the |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
194 * sample values for the second pixel, etc. For RGB images, this |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
195 * means the order of the pixel values sent shall be R1, G1, B1, |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
196 * R2, G2, B2, ..., etc. |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
197 **/ |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
198 pixel += channel * information_.GetBytesPerValue() + x * information_.GetChannelCount() * information_.GetBytesPerValue(); |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
199 } |
0 | 200 |
4827
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
201 uint32_t v; |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
202 v = pixel[0]; |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
203 if (information_.GetBytesPerValue() >= 2) |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
204 v = v + (static_cast<uint32_t>(pixel[1]) << 8); |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
205 if (information_.GetBytesPerValue() >= 3) |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
206 v = v + (static_cast<uint32_t>(pixel[2]) << 16); |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
207 if (information_.GetBytesPerValue() >= 4) |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
208 v = v + (static_cast<uint32_t>(pixel[3]) << 24); |
0 | 209 |
4827
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
210 v = v >> information_.GetShift(); |
0 | 211 |
4827
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
212 if (v & signMask_) |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
213 { |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
214 // Signed value |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
215 // http://en.wikipedia.org/wiki/Two%27s_complement#Subtraction_from_2N |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
216 return -static_cast<int32_t>(mask_) + static_cast<int32_t>(v & mask_) - 1; |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
217 } |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
218 else |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
219 { |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
220 // Unsigned value |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
221 return static_cast<int32_t>(v & mask_); |
4cfd96732076
Support decoding of black-and-white images (with 1 bit per pixel), notably DICOM SEG
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4825
diff
changeset
|
222 } |
464
5987dd8e0776
fix reading signed values in dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
223 } |
0 | 224 } |
53
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
225 |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
226 |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
227 void DicomIntegerPixelAccessor::SetCurrentFrame(unsigned int frame) |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
228 { |
853
839be3022203
DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
229 if (frame >= information_.GetNumberOfFrames()) |
53
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
230 { |
62 | 231 throw OrthancException(ErrorCode_ParameterOutOfRange); |
53
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
232 } |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
233 |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
234 frame_ = frame; |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
235 } |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
236 |
0 | 237 } |