annotate OrthancFramework/Sources/DicomFormat/DicomIntegerPixelAccessor.cpp @ 4831:7053502fbf97

added copyright UCLouvain
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 25 Nov 2021 19:01:11 +0100
parents 4cfd96732076
children 43e613a7756b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 57
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
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
4437
d9473bd5ed43 upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium
4831
7053502fbf97 added copyright UCLouvain
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4827
diff changeset
6 * Copyright (C) 2021-2021 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * 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
9 * 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
10 * 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
11 * the License, or (at your option) any later version.
136
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
12 *
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful, but
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * 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
16 * Lesser General Public License for more details.
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 *
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
18 * 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
19 * 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
20 * <http://www.gnu.org/licenses/>.
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 **/
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
824
a811bdf8b8eb precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 800
diff changeset
24 #include "../PrecompiledHeaders.h"
a811bdf8b8eb precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 800
diff changeset
25
6
9d483cf71d17 fix warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
26 #ifndef NOMINMAX
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
27 #define NOMINMAX
6
9d483cf71d17 fix warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
28 #endif
9d483cf71d17 fix warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
29
627
b8f738685ad2 fix for visual studio
jodogne
parents: 537
diff changeset
30 #include "DicomIntegerPixelAccessor.h"
b8f738685ad2 fix for visual studio
jodogne
parents: 537
diff changeset
31
79
297bad4e1019 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 78
diff changeset
32 #include "../OrthancException.h"
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 #include <boost/lexical_cast.hpp>
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
34 #include <limits>
107
3b45473c0a73 replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 80
diff changeset
35 #include <cassert>
368
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
36 #include <stdio.h>
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 57
diff changeset
38 namespace Orthanc
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 DicomIntegerPixelAccessor::DicomIntegerPixelAccessor(const DicomMap& values,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 const void* pixelData,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 size_t size) :
853
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
43 information_(values),
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 pixelData_(pixelData),
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 size_(size)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 {
2279
16e45af17a4d Ability to retrieve raw frames encoded as unsigned 32-bits integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
47 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
48 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
49 {
16e45af17a4d Ability to retrieve raw frames encoded as unsigned 32-bits integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
50 // 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
51 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
52 }
16e45af17a4d Ability to retrieve raw frames encoded as unsigned 32-bits integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
53
853
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
54 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
55 frameOffset_ = information_.GetFrameSize();
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56
853
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
57 if (information_.GetNumberOfFrames() * frameOffset_ > size)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 {
319
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
59 throw OrthancException(ErrorCode_BadFileFormat);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61
853
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
62 if (information_.IsSigned())
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 {
537
2890721b0f57 comment
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 465
diff changeset
64 // Pixels are signed
853
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
65 mask_ = (1 << (information_.GetBitsStored() - 1)) - 1;
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
66 signMask_ = (1 << (information_.GetBitsStored() - 1));
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 {
537
2890721b0f57 comment
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 465
diff changeset
70 // Pixels are unsigned
853
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
71 mask_ = (1 << information_.GetBitsStored()) - 1;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 signMask_ = 0;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 }
53
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
74
853
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
75 if (information_.IsPlanar())
368
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
76 {
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
77 /**
857
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
78 * Each color plane shall be sent contiguously. For RGB images,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
79 * this means the order of the pixel values sent is R1, R2, R3,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
80 * ..., G1, G2, G3, ..., B1, B2, B3, etc.
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
81 **/
860
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 857
diff changeset
82 rowOffset_ = information_.GetWidth() * information_.GetBytesPerValue();
857
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
83 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
84 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
85 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
86 /**
368
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
87 * 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
88 * 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
89 * 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
90 * R2, G2, B2, ..., etc.
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
91 **/
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
92 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
93 {
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 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
95 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
96 {
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 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
98 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
99 }
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 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
101 {
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 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
103 "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
104 }
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 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
107 {
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 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
109 }
368
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
110 }
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 void DicomIntegerPixelAccessor::GetExtremeValues(int32_t& min,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 int32_t& max) const
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 {
853
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
117 if (information_.GetHeight() == 0 || information_.GetWidth() == 0)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 min = max = 0;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 return;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 min = std::numeric_limits<int32_t>::max();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 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
125
9279de56a405 avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
126 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
127 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
128 const unsigned int channels = information_.GetChannelCount();
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129
4278
9279de56a405 avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
130 for (unsigned int y = 0; y < height; y++)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 {
4278
9279de56a405 avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
132 for (unsigned int x = 0; x < width; x++)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 {
4278
9279de56a405 avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
134 for (unsigned int c = 0; c < channels; c++)
368
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
135 {
4825
381c2ca04860 fix DicomIntegerPixelAccessor::GetExtremeValues() on multi-channel images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
136 int32_t v = GetValue(x, y, c);
368
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
137 if (v < min)
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
138 min = v;
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
139 if (v > max)
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
140 max = v;
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
141 }
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146
368
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
147 int32_t DicomIntegerPixelAccessor::GetValue(unsigned int x,
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
148 unsigned int y,
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
149 unsigned int channel) const
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 {
857
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
151 assert(x < information_.GetWidth() &&
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
152 y < information_.GetHeight() &&
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
153 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
154
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 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
156 y * rowOffset_ + frame_ * frameOffset_);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157
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
158 if (information_.GetBitsStored() == 1)
857
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
159 {
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
160 // New in Orthanc 1.9.8, notably for DICOM SEG
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
161 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
162 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
163 !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
164
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 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
166
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 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
168 {
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 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
170 }
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 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
172 {
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 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
174 }
857
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
175 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
176 else
368
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
177 {
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
178 // 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
179 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
180 {
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 * 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
183 * 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
184 * ..., 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
185 **/
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 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
187 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
188 }
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 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
190 {
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 * 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
193 * 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
194 * 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
195 * 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
196 **/
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 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
198 }
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199
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
200 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
201 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
202 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
203 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
204 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
205 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
206 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
207 v = v + (static_cast<uint32_t>(pixel[3]) << 24);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208
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
209 v = v >> information_.GetShift();
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210
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
211 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
212 {
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 // 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
214 // 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
215 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
216 }
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 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
218 {
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 // 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
220 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
221 }
464
5987dd8e0776 fix reading signed values in dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
222 }
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 }
53
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
224
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 void DicomIntegerPixelAccessor::SetCurrentFrame(unsigned int frame)
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
227 {
853
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
228 if (frame >= information_.GetNumberOfFrames())
53
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
229 {
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 57
diff changeset
230 throw OrthancException(ErrorCode_ParameterOutOfRange);
53
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
231 }
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 frame_ = frame;
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
234 }
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
235
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 }