annotate Core/DicomFormat/DicomIntegerPixelAccessor.cpp @ 405:97a00b30abcc

sending of studies and patients with orthanc explorer
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 30 Apr 2013 15:23:23 +0200
parents bdd72233b105
children 5987dd8e0776
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
398
bdd72233b105 copyright update
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
3 * Copyright (C) 2012-2013 Medical Physics Department, CHU of Liege,
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Belgium
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 *
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * This program is free software: you can redistribute it and/or
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * modify it under the terms of the GNU General Public License as
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * published by the Free Software Foundation, either version 3 of the
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * License, or (at your option) any later version.
136
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
10 *
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
11 * In addition, as a special exception, the copyright holders of this
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
12 * program give permission to link the code of its release with the
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
14 * that use the same license as the "OpenSSL" library), and distribute
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
15 * the linked executables. You must obey the GNU General Public License
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
16 * in all respects for all of the code used other than "OpenSSL". If you
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
17 * modify file(s) with this exception, you may extend this exception to
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
18 * your version of the file(s), but you are not obligated to do so. If
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
19 * you do not wish to do so, delete this exception statement from your
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
20 * version. If you delete this exception statement from all source files
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
21 * in the program, then also delete it here.
0
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 * 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
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * General Public License for more details.
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 *
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 * You should have received a copy of the GNU General Public License
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 **/
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 #include "DicomIntegerPixelAccessor.h"
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
6
9d483cf71d17 fix warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
35 #ifndef NOMINMAX
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
36 #define NOMINMAX
6
9d483cf71d17 fix warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
37 #endif
9d483cf71d17 fix warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
38
79
297bad4e1019 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 78
diff changeset
39 #include "../OrthancException.h"
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 #include <boost/lexical_cast.hpp>
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 57
diff changeset
45 namespace Orthanc
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 {
77
b8dfde8d64e8 new dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 62
diff changeset
47 static const DicomTag COLUMNS(0x0028, 0x0011);
b8dfde8d64e8 new dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 62
diff changeset
48 static const DicomTag ROWS(0x0028, 0x0010);
b8dfde8d64e8 new dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 62
diff changeset
49 static const DicomTag SAMPLES_PER_PIXEL(0x0028, 0x0002);
b8dfde8d64e8 new dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 62
diff changeset
50 static const DicomTag BITS_ALLOCATED(0x0028, 0x0100);
b8dfde8d64e8 new dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 62
diff changeset
51 static const DicomTag BITS_STORED(0x0028, 0x0101);
b8dfde8d64e8 new dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 62
diff changeset
52 static const DicomTag HIGH_BIT(0x0028, 0x0102);
b8dfde8d64e8 new dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 62
diff changeset
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
b8dfde8d64e8 new dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 62
diff changeset
55
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 DicomIntegerPixelAccessor::DicomIntegerPixelAccessor(const DicomMap& values,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 const void* pixelData,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 size_t size) :
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 pixelData_(pixelData),
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 size_(size)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 unsigned int bitsAllocated;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 unsigned int bitsStored;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 unsigned int highBit;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 unsigned int pixelRepresentation;
368
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
66 planarConfiguration_ = 0;
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 try
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 {
77
b8dfde8d64e8 new dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 62
diff changeset
70 width_ = boost::lexical_cast<unsigned int>(values.GetValue(COLUMNS).AsString());
b8dfde8d64e8 new dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 62
diff changeset
71 height_ = boost::lexical_cast<unsigned int>(values.GetValue(ROWS).AsString());
b8dfde8d64e8 new dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 62
diff changeset
72 samplesPerPixel_ = boost::lexical_cast<unsigned int>(values.GetValue(SAMPLES_PER_PIXEL).AsString());
b8dfde8d64e8 new dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 62
diff changeset
73 bitsAllocated = boost::lexical_cast<unsigned int>(values.GetValue(BITS_ALLOCATED).AsString());
b8dfde8d64e8 new dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 62
diff changeset
74 bitsStored = boost::lexical_cast<unsigned int>(values.GetValue(BITS_STORED).AsString());
b8dfde8d64e8 new dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 62
diff changeset
75 highBit = boost::lexical_cast<unsigned int>(values.GetValue(HIGH_BIT).AsString());
b8dfde8d64e8 new dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 62
diff changeset
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 catch (boost::bad_lexical_cast)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 {
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 57
diff changeset
87 throw OrthancException(ErrorCode_NotImplemented);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
6212bf978584 status of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 79
diff changeset
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
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 57
diff changeset
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
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 57
diff changeset
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 {
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 57
diff changeset
114 throw OrthancException(ErrorCode_NotImplemented);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 if (bitsAllocated > 32 ||
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 bitsStored >= 32)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 // Not available, as the accessor internally uses int32_t values
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 57
diff changeset
121 throw OrthancException(ErrorCode_NotImplemented);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 {
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 57
diff changeset
126 throw OrthancException(ErrorCode_NotImplemented);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 {
319
760d0f32cb34 PMSCT_RLE1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
135 throw OrthancException(ErrorCode_BadFileFormat);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 if (pixelRepresentation)
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 mask_ = (1 << (bitsStored - 1)) - 1;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 signMask_ = (1 << (bitsStored - 1));
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 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 mask_ = (1 << bitsStored) - 1;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 signMask_ = 0;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 }
53
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
151
368
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
152 if (planarConfiguration_ == 0)
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
153 {
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
154 /**
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
155 * 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
156 * 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
157 * 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
158 * R2, G2, B2, ..., etc.
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
159 **/
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
160 rowOffset_ = width_ * bytesPerPixel_ * samplesPerPixel_;
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 else
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 /**
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
165 * 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
166 * 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
167 * ..., G1, G2, G3, ..., B1, B2, B3, etc.
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
168 **/
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
169 rowOffset_ = width_ * bytesPerPixel_;
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
170 }
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 void DicomIntegerPixelAccessor::GetExtremeValues(int32_t& min,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 int32_t& max) const
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 if (height_ == 0 || width_ == 0)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 min = max = 0;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 return;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 min = std::numeric_limits<int32_t>::max();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 max = std::numeric_limits<int32_t>::min();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 for (unsigned int y = 0; y < height_; y++)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 for (unsigned int x = 0; x < width_; x++)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 {
368
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
190 for (unsigned int c = 0; c < GetChannelCount(); c++)
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
191 {
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
192 int32_t v = GetValue(x, y);
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
193 if (v < min)
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
194 min = v;
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
195 if (v > max)
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
196 max = v;
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
197 }
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202
368
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
203 int32_t DicomIntegerPixelAccessor::GetValue(unsigned int x,
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
204 unsigned int y,
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
205 unsigned int channel) const
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 {
368
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
207 assert(x < width_ && y < height_ && channel < samplesPerPixel_);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208
53
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
209 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
210 y * rowOffset_ + frame_ * frameOffset_;
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
211
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
212 // 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
213 if (planarConfiguration_ == 0)
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
214 {
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
215 /**
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
216 * 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
217 * 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
218 * 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
219 * R2, G2, B2, ..., etc.
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
220 **/
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
221 pixel += channel * bytesPerPixel_ + x * samplesPerPixel_ * bytesPerPixel_;
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 else
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 /**
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
226 * 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
227 * 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
228 * ..., G1, G2, G3, ..., B1, B2, B3, etc.
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
229 **/
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
230 assert(frameOffset_ % samplesPerPixel_ == 0);
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
231 pixel += channel * frameOffset_ / samplesPerPixel_ + x * bytesPerPixel_;
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
232 }
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 int32_t v;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 v = pixel[0];
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 if (bytesPerPixel_ >= 2)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 v = v + (static_cast<int32_t>(pixel[1]) << 8);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 if (bytesPerPixel_ >= 3)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 v = v + (static_cast<int32_t>(pixel[2]) << 16);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 if (bytesPerPixel_ >= 4)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 v = v + (static_cast<int32_t>(pixel[3]) << 24);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 v = (v >> shift_) & mask_;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 if (v & signMask_)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 // Signed value: Not implemented yet
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 57
diff changeset
248 //throw OrthancException(ErrorCode_NotImplemented);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 v = 0;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 return v;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 }
53
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
254
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
255
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
256 void DicomIntegerPixelAccessor::SetCurrentFrame(unsigned int frame)
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
257 {
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
258 if (frame >= numberOfFrames_)
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
259 {
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 57
diff changeset
260 throw OrthancException(ErrorCode_ParameterOutOfRange);
53
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
261 }
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 frame_ = frame;
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
264 }
293038baf8f1 access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
265
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 }