Mercurial > hg > orthanc
annotate OrthancFramework/Sources/DicomFormat/DicomImageInformation.cpp @ 4105:c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 06 Jul 2020 13:48:10 +0200 |
parents | eab8010c05fc |
children | bf7b9edf6b81 |
rev | line source |
---|---|
853 | 1 /** |
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:
1206
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
3640
94f4a18a79cc
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3519
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
853 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU General Public License as | |
9 * published by the Free Software Foundation, either version 3 of the | |
10 * License, or (at your option) any later version. | |
11 * | |
12 * In addition, as a special exception, the copyright holders of this | |
13 * program give permission to link the code of its release with the | |
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
15 * that use the same license as the "OpenSSL" library), and distribute | |
16 * the linked executables. You must obey the GNU General Public License | |
17 * in all respects for all of the code used other than "OpenSSL". If you | |
18 * modify file(s) with this exception, you may extend this exception to | |
19 * your version of the file(s), but you are not obligated to do so. If | |
20 * you do not wish to do so, delete this exception statement from your | |
21 * version. If you delete this exception statement from all source files | |
22 * in the program, then also delete it here. | |
3007 | 23 * |
853 | 24 * This program is distributed in the hope that it will be useful, but |
25 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
27 * General Public License for more details. | |
28 * | |
29 * You should have received a copy of the GNU General Public License | |
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
31 **/ | |
32 | |
33 | |
34 #include "../PrecompiledHeaders.h" | |
35 | |
36 #ifndef NOMINMAX | |
37 #define NOMINMAX | |
38 #endif | |
39 | |
40 #include "DicomImageInformation.h" | |
41 | |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
42 #include "../Compatibility.h" |
853 | 43 #include "../OrthancException.h" |
1206
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
44 #include "../Toolbox.h" |
853 | 45 #include <boost/lexical_cast.hpp> |
46 #include <limits> | |
47 #include <cassert> | |
48 #include <stdio.h> | |
2870 | 49 #include <memory> |
853 | 50 |
51 namespace Orthanc | |
52 { | |
53 DicomImageInformation::DicomImageInformation(const DicomMap& values) | |
54 { | |
4076
eab8010c05fc
avoid relying on boost::bad_lexical_cast in DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
55 uint32_t pixelRepresentation = 0; |
eab8010c05fc
avoid relying on boost::bad_lexical_cast in DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
56 uint32_t planarConfiguration = 0; |
853 | 57 |
58 try | |
59 { | |
1737
ec66a16aa398
removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
60 std::string p = values.GetValue(DICOM_TAG_PHOTOMETRIC_INTERPRETATION).GetContent(); |
1206
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
61 Toolbox::ToUpperCase(p); |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
62 |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
63 if (p == "RGB") |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
64 { |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
65 photometric_ = PhotometricInterpretation_RGB; |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
66 } |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
67 else if (p == "MONOCHROME1") |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
68 { |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
69 photometric_ = PhotometricInterpretation_Monochrome1; |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
70 } |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
71 else if (p == "MONOCHROME2") |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
72 { |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
73 photometric_ = PhotometricInterpretation_Monochrome2; |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
74 } |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
75 else if (p == "PALETTE COLOR") |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
76 { |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
77 photometric_ = PhotometricInterpretation_Palette; |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
78 } |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
79 else if (p == "HSV") |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
80 { |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
81 photometric_ = PhotometricInterpretation_HSV; |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
82 } |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
83 else if (p == "ARGB") |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
84 { |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
85 photometric_ = PhotometricInterpretation_ARGB; |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
86 } |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
87 else if (p == "CMYK") |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
88 { |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
89 photometric_ = PhotometricInterpretation_CMYK; |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
90 } |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
91 else if (p == "YBR_FULL") |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
92 { |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
93 photometric_ = PhotometricInterpretation_YBRFull; |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
94 } |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
95 else if (p == "YBR_FULL_422") |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
96 { |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
97 photometric_ = PhotometricInterpretation_YBRFull422; |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
98 } |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
99 else if (p == "YBR_PARTIAL_420") |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
100 { |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
101 photometric_ = PhotometricInterpretation_YBRPartial420; |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
102 } |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
103 else if (p == "YBR_PARTIAL_422") |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
104 { |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
105 photometric_ = PhotometricInterpretation_YBRPartial422; |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
106 } |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
107 else if (p == "YBR_ICT") |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
108 { |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
109 photometric_ = PhotometricInterpretation_YBR_ICT; |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
110 } |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
111 else if (p == "YBR_RCT") |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
112 { |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
113 photometric_ = PhotometricInterpretation_YBR_RCT; |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
114 } |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
115 else |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
116 { |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
117 photometric_ = PhotometricInterpretation_Unknown; |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
118 } |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
119 |
3519
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
120 values.GetValue(DICOM_TAG_COLUMNS).ParseFirstUnsignedInteger(width_); // in some US images, we've seen tag values of "800\0"; that's why we parse the 'first' value |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
121 values.GetValue(DICOM_TAG_ROWS).ParseFirstUnsignedInteger(height_); |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
122 |
4076
eab8010c05fc
avoid relying on boost::bad_lexical_cast in DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
123 if (!values.ParseUnsignedInteger32(bitsAllocated_, DICOM_TAG_BITS_ALLOCATED)) |
853 | 124 { |
4076
eab8010c05fc
avoid relying on boost::bad_lexical_cast in DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
125 throw OrthancException(ErrorCode_BadFileFormat); |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
126 } |
4076
eab8010c05fc
avoid relying on boost::bad_lexical_cast in DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
127 |
eab8010c05fc
avoid relying on boost::bad_lexical_cast in DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
128 if (!values.ParseUnsignedInteger32(samplesPerPixel_, DICOM_TAG_SAMPLES_PER_PIXEL)) |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
129 { |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
130 samplesPerPixel_ = 1; // Assume 1 color channel |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
131 } |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
132 |
4076
eab8010c05fc
avoid relying on boost::bad_lexical_cast in DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
133 if (!values.ParseUnsignedInteger32(bitsStored_, DICOM_TAG_BITS_STORED)) |
853 | 134 { |
135 bitsStored_ = bitsAllocated_; | |
136 } | |
137 | |
4076
eab8010c05fc
avoid relying on boost::bad_lexical_cast in DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
138 if (!values.ParseUnsignedInteger32(highBit_, DICOM_TAG_HIGH_BIT)) |
853 | 139 { |
140 highBit_ = bitsStored_ - 1; | |
141 } | |
142 | |
4076
eab8010c05fc
avoid relying on boost::bad_lexical_cast in DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
143 if (!values.ParseUnsignedInteger32(pixelRepresentation, DICOM_TAG_PIXEL_REPRESENTATION)) |
853 | 144 { |
145 pixelRepresentation = 0; // Assume unsigned pixels | |
146 } | |
147 | |
148 if (samplesPerPixel_ > 1) | |
149 { | |
150 // The "Planar Configuration" is only set when "Samples per Pixels" is greater than 1 | |
1908
5096681efce6
direct hyperlinks to the DICOM standard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1905
diff
changeset
|
151 // http://dicom.nema.org/medical/dicom/current/output/html/part03.html#sect_C.7.6.3.1.3 |
4076
eab8010c05fc
avoid relying on boost::bad_lexical_cast in DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
152 |
eab8010c05fc
avoid relying on boost::bad_lexical_cast in DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
153 if (!values.ParseUnsignedInteger32(planarConfiguration, DICOM_TAG_PLANAR_CONFIGURATION)) |
853 | 154 { |
155 planarConfiguration = 0; // Assume interleaved color channels | |
156 } | |
157 } | |
158 } | |
159 catch (boost::bad_lexical_cast&) | |
160 { | |
161 throw OrthancException(ErrorCode_NotImplemented); | |
162 } | |
163 catch (OrthancException&) | |
164 { | |
165 throw OrthancException(ErrorCode_NotImplemented); | |
166 } | |
167 | |
4076
eab8010c05fc
avoid relying on boost::bad_lexical_cast in DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
168 |
2416
feb0d2dcfa9b
try and fix compiler bugs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2279
diff
changeset
|
169 if (values.HasTag(DICOM_TAG_NUMBER_OF_FRAMES)) |
853 | 170 { |
4076
eab8010c05fc
avoid relying on boost::bad_lexical_cast in DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
171 if (!values.ParseUnsignedInteger32(numberOfFrames_, DICOM_TAG_NUMBER_OF_FRAMES)) |
2416
feb0d2dcfa9b
try and fix compiler bugs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2279
diff
changeset
|
172 { |
feb0d2dcfa9b
try and fix compiler bugs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2279
diff
changeset
|
173 throw OrthancException(ErrorCode_NotImplemented); |
feb0d2dcfa9b
try and fix compiler bugs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2279
diff
changeset
|
174 } |
853 | 175 } |
2416
feb0d2dcfa9b
try and fix compiler bugs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2279
diff
changeset
|
176 else |
853 | 177 { |
2416
feb0d2dcfa9b
try and fix compiler bugs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2279
diff
changeset
|
178 numberOfFrames_ = 1; |
853 | 179 } |
180 | |
3007 | 181 if (bitsAllocated_ != 8 && bitsAllocated_ != 16 && |
182 bitsAllocated_ != 24 && bitsAllocated_ != 32) | |
853 | 183 { |
3007 | 184 throw OrthancException(ErrorCode_IncompatibleImageFormat, "Image not supported: " + boost::lexical_cast<std::string>(bitsAllocated_) + " bits allocated"); |
185 } | |
186 else if (numberOfFrames_ == 0) | |
187 { | |
188 throw OrthancException(ErrorCode_IncompatibleImageFormat, "Image not supported (no frames)"); | |
189 } | |
190 else if (planarConfiguration != 0 && planarConfiguration != 1) | |
191 { | |
192 throw OrthancException(ErrorCode_IncompatibleImageFormat, "Image not supported: planar configuration is " + boost::lexical_cast<std::string>(planarConfiguration)); | |
853 | 193 } |
194 | |
195 if (samplesPerPixel_ == 0) | |
196 { | |
3007 | 197 throw OrthancException(ErrorCode_IncompatibleImageFormat, "Image not supported: samples per pixel is 0"); |
853 | 198 } |
199 | |
860 | 200 bytesPerValue_ = bitsAllocated_ / 8; |
853 | 201 |
202 isPlanar_ = (planarConfiguration != 0 ? true : false); | |
203 isSigned_ = (pixelRepresentation != 0 ? true : false); | |
204 } | |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
205 |
2870 | 206 DicomImageInformation* DicomImageInformation::Clone() const |
207 { | |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
208 std::unique_ptr<DicomImageInformation> target(new DicomImageInformation); |
2870 | 209 target->width_ = width_; |
210 target->height_ = height_; | |
211 target->samplesPerPixel_ = samplesPerPixel_; | |
212 target->numberOfFrames_ = numberOfFrames_; | |
213 target->isPlanar_ = isPlanar_; | |
214 target->isSigned_ = isSigned_; | |
215 target->bytesPerValue_ = bytesPerValue_; | |
216 target->bitsAllocated_ = bitsAllocated_; | |
217 target->bitsStored_ = bitsStored_; | |
218 target->highBit_ = highBit_; | |
219 target->photometric_ = photometric_; | |
220 | |
221 return target.release(); | |
222 } | |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
223 |
1905
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
224 bool DicomImageInformation::ExtractPixelFormat(PixelFormat& format, |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
225 bool ignorePhotometricInterpretation) const |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
226 { |
1905
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
227 if (photometric_ == PhotometricInterpretation_Palette) |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
228 { |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2416
diff
changeset
|
229 if (GetBitsStored() == 8 && GetChannelCount() == 1 && !IsSigned()) |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2416
diff
changeset
|
230 { |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2416
diff
changeset
|
231 format = PixelFormat_RGB24; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2416
diff
changeset
|
232 return true; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2416
diff
changeset
|
233 } |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2416
diff
changeset
|
234 |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2416
diff
changeset
|
235 if (GetBitsStored() == 16 && GetChannelCount() == 1 && !IsSigned()) |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2416
diff
changeset
|
236 { |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2416
diff
changeset
|
237 format = PixelFormat_RGB48; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2416
diff
changeset
|
238 return true; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2416
diff
changeset
|
239 } |
1905
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
240 } |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2416
diff
changeset
|
241 |
1905
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
242 if (ignorePhotometricInterpretation || |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
243 photometric_ == PhotometricInterpretation_Monochrome1 || |
1206
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
244 photometric_ == PhotometricInterpretation_Monochrome2) |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
245 { |
1206
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
246 if (GetBitsStored() == 8 && GetChannelCount() == 1 && !IsSigned()) |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
247 { |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
248 format = PixelFormat_Grayscale8; |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
249 return true; |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
250 } |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
251 |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
252 if (GetBitsAllocated() == 16 && GetChannelCount() == 1 && !IsSigned()) |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
253 { |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
254 format = PixelFormat_Grayscale16; |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
255 return true; |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
256 } |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
257 |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
258 if (GetBitsAllocated() == 16 && GetChannelCount() == 1 && IsSigned()) |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
259 { |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
260 format = PixelFormat_SignedGrayscale16; |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
261 return true; |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
262 } |
2838
f3a2d109e361
new orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
263 |
f3a2d109e361
new orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
264 if (GetBitsAllocated() == 32 && GetChannelCount() == 1 && !IsSigned()) |
f3a2d109e361
new orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
265 { |
f3a2d109e361
new orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
266 format = PixelFormat_Grayscale32; |
f3a2d109e361
new orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
267 return true; |
f3a2d109e361
new orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
268 } |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
269 } |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
270 |
3007 | 271 if (GetBitsStored() == 8 && |
272 GetChannelCount() == 3 && | |
1206
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
273 !IsSigned() && |
1905
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
274 (ignorePhotometricInterpretation || photometric_ == PhotometricInterpretation_RGB)) |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
275 { |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
276 format = PixelFormat_RGB24; |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
277 return true; |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
278 } |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
279 |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
280 return false; |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
281 } |
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
|
282 |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1908
diff
changeset
|
283 |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1908
diff
changeset
|
284 size_t DicomImageInformation::GetFrameSize() const |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1908
diff
changeset
|
285 { |
3007 | 286 return (GetHeight() * |
287 GetWidth() * | |
288 GetBytesPerValue() * | |
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
|
289 GetChannelCount()); |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1908
diff
changeset
|
290 } |
853 | 291 } |