Mercurial > hg > orthanc
annotate OrthancFramework/Sources/DicomFormat/DicomImageInformation.cpp @ 4196:37310bb1cd30
Fix handling of "ModalitiesInStudy" (0008,0061) in C-FIND and "/tools/find"
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 16 Sep 2020 13:22:30 +0200 |
parents | bf7b9edf6b81 |
children | ab4d015af660 |
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 | |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4076
diff
changeset
|
8 * 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:
4076
diff
changeset
|
9 * 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:
4076
diff
changeset
|
10 * the License, or (at your option) any later version. |
3007 | 11 * |
853 | 12 * This program is distributed in the hope that it will be useful, but |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * 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:
4076
diff
changeset
|
15 * Lesser General Public License for more details. |
853 | 16 * |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4076
diff
changeset
|
17 * 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:
4076
diff
changeset
|
18 * 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:
4076
diff
changeset
|
19 * <http://www.gnu.org/licenses/>. |
853 | 20 **/ |
21 | |
22 | |
23 #include "../PrecompiledHeaders.h" | |
24 | |
25 #ifndef NOMINMAX | |
26 #define NOMINMAX | |
27 #endif | |
28 | |
29 #include "DicomImageInformation.h" | |
30 | |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
31 #include "../Compatibility.h" |
853 | 32 #include "../OrthancException.h" |
1206
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
33 #include "../Toolbox.h" |
853 | 34 #include <boost/lexical_cast.hpp> |
35 #include <limits> | |
36 #include <cassert> | |
37 #include <stdio.h> | |
2870 | 38 #include <memory> |
853 | 39 |
40 namespace Orthanc | |
41 { | |
42 DicomImageInformation::DicomImageInformation(const DicomMap& values) | |
43 { | |
4076
eab8010c05fc
avoid relying on boost::bad_lexical_cast in DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
44 uint32_t pixelRepresentation = 0; |
eab8010c05fc
avoid relying on boost::bad_lexical_cast in DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
45 uint32_t planarConfiguration = 0; |
853 | 46 |
47 try | |
48 { | |
1737
ec66a16aa398
removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
49 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
|
50 Toolbox::ToUpperCase(p); |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
51 |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
52 if (p == "RGB") |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
53 { |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
54 photometric_ = PhotometricInterpretation_RGB; |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
55 } |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
56 else if (p == "MONOCHROME1") |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
57 { |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
58 photometric_ = PhotometricInterpretation_Monochrome1; |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
59 } |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
60 else if (p == "MONOCHROME2") |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
61 { |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
62 photometric_ = PhotometricInterpretation_Monochrome2; |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
63 } |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
64 else if (p == "PALETTE COLOR") |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
65 { |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
66 photometric_ = PhotometricInterpretation_Palette; |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
67 } |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
68 else if (p == "HSV") |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
69 { |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
70 photometric_ = PhotometricInterpretation_HSV; |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
71 } |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
72 else if (p == "ARGB") |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
73 { |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
74 photometric_ = PhotometricInterpretation_ARGB; |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
75 } |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
76 else if (p == "CMYK") |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
77 { |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
78 photometric_ = PhotometricInterpretation_CMYK; |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
79 } |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
80 else if (p == "YBR_FULL") |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
81 { |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
82 photometric_ = PhotometricInterpretation_YBRFull; |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
83 } |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
84 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
|
85 { |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
86 photometric_ = PhotometricInterpretation_YBRFull422; |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
87 } |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
88 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
|
89 { |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
90 photometric_ = PhotometricInterpretation_YBRPartial420; |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
91 } |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
92 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
|
93 { |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
94 photometric_ = PhotometricInterpretation_YBRPartial422; |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
95 } |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
96 else if (p == "YBR_ICT") |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
97 { |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
98 photometric_ = PhotometricInterpretation_YBR_ICT; |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
99 } |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
100 else if (p == "YBR_RCT") |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
101 { |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
102 photometric_ = PhotometricInterpretation_YBR_RCT; |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
103 } |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
104 else |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
105 { |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
106 photometric_ = PhotometricInterpretation_Unknown; |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
107 } |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
108 |
3519
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
109 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
|
110 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
|
111 |
4076
eab8010c05fc
avoid relying on boost::bad_lexical_cast in DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
112 if (!values.ParseUnsignedInteger32(bitsAllocated_, DICOM_TAG_BITS_ALLOCATED)) |
853 | 113 { |
4076
eab8010c05fc
avoid relying on boost::bad_lexical_cast in DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
114 throw OrthancException(ErrorCode_BadFileFormat); |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
115 } |
4076
eab8010c05fc
avoid relying on boost::bad_lexical_cast in DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
116 |
eab8010c05fc
avoid relying on boost::bad_lexical_cast in DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
117 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
|
118 { |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
119 samplesPerPixel_ = 1; // Assume 1 color channel |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
120 } |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
121 |
4076
eab8010c05fc
avoid relying on boost::bad_lexical_cast in DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
122 if (!values.ParseUnsignedInteger32(bitsStored_, DICOM_TAG_BITS_STORED)) |
853 | 123 { |
124 bitsStored_ = bitsAllocated_; | |
125 } | |
126 | |
4076
eab8010c05fc
avoid relying on boost::bad_lexical_cast in DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
127 if (!values.ParseUnsignedInteger32(highBit_, DICOM_TAG_HIGH_BIT)) |
853 | 128 { |
129 highBit_ = bitsStored_ - 1; | |
130 } | |
131 | |
4076
eab8010c05fc
avoid relying on boost::bad_lexical_cast in DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
132 if (!values.ParseUnsignedInteger32(pixelRepresentation, DICOM_TAG_PIXEL_REPRESENTATION)) |
853 | 133 { |
134 pixelRepresentation = 0; // Assume unsigned pixels | |
135 } | |
136 | |
137 if (samplesPerPixel_ > 1) | |
138 { | |
139 // 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
|
140 // 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
|
141 |
eab8010c05fc
avoid relying on boost::bad_lexical_cast in DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
142 if (!values.ParseUnsignedInteger32(planarConfiguration, DICOM_TAG_PLANAR_CONFIGURATION)) |
853 | 143 { |
144 planarConfiguration = 0; // Assume interleaved color channels | |
145 } | |
146 } | |
147 } | |
148 catch (boost::bad_lexical_cast&) | |
149 { | |
150 throw OrthancException(ErrorCode_NotImplemented); | |
151 } | |
152 catch (OrthancException&) | |
153 { | |
154 throw OrthancException(ErrorCode_NotImplemented); | |
155 } | |
156 | |
4076
eab8010c05fc
avoid relying on boost::bad_lexical_cast in DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
157 |
2416
feb0d2dcfa9b
try and fix compiler bugs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2279
diff
changeset
|
158 if (values.HasTag(DICOM_TAG_NUMBER_OF_FRAMES)) |
853 | 159 { |
4076
eab8010c05fc
avoid relying on boost::bad_lexical_cast in DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
160 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
|
161 { |
feb0d2dcfa9b
try and fix compiler bugs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2279
diff
changeset
|
162 throw OrthancException(ErrorCode_NotImplemented); |
feb0d2dcfa9b
try and fix compiler bugs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2279
diff
changeset
|
163 } |
853 | 164 } |
2416
feb0d2dcfa9b
try and fix compiler bugs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2279
diff
changeset
|
165 else |
853 | 166 { |
2416
feb0d2dcfa9b
try and fix compiler bugs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2279
diff
changeset
|
167 numberOfFrames_ = 1; |
853 | 168 } |
169 | |
3007 | 170 if (bitsAllocated_ != 8 && bitsAllocated_ != 16 && |
171 bitsAllocated_ != 24 && bitsAllocated_ != 32) | |
853 | 172 { |
3007 | 173 throw OrthancException(ErrorCode_IncompatibleImageFormat, "Image not supported: " + boost::lexical_cast<std::string>(bitsAllocated_) + " bits allocated"); |
174 } | |
175 else if (numberOfFrames_ == 0) | |
176 { | |
177 throw OrthancException(ErrorCode_IncompatibleImageFormat, "Image not supported (no frames)"); | |
178 } | |
179 else if (planarConfiguration != 0 && planarConfiguration != 1) | |
180 { | |
181 throw OrthancException(ErrorCode_IncompatibleImageFormat, "Image not supported: planar configuration is " + boost::lexical_cast<std::string>(planarConfiguration)); | |
853 | 182 } |
183 | |
184 if (samplesPerPixel_ == 0) | |
185 { | |
3007 | 186 throw OrthancException(ErrorCode_IncompatibleImageFormat, "Image not supported: samples per pixel is 0"); |
853 | 187 } |
188 | |
860 | 189 bytesPerValue_ = bitsAllocated_ / 8; |
853 | 190 |
191 isPlanar_ = (planarConfiguration != 0 ? true : false); | |
192 isSigned_ = (pixelRepresentation != 0 ? true : false); | |
193 } | |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
194 |
2870 | 195 DicomImageInformation* DicomImageInformation::Clone() const |
196 { | |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
197 std::unique_ptr<DicomImageInformation> target(new DicomImageInformation); |
2870 | 198 target->width_ = width_; |
199 target->height_ = height_; | |
200 target->samplesPerPixel_ = samplesPerPixel_; | |
201 target->numberOfFrames_ = numberOfFrames_; | |
202 target->isPlanar_ = isPlanar_; | |
203 target->isSigned_ = isSigned_; | |
204 target->bytesPerValue_ = bytesPerValue_; | |
205 target->bitsAllocated_ = bitsAllocated_; | |
206 target->bitsStored_ = bitsStored_; | |
207 target->highBit_ = highBit_; | |
208 target->photometric_ = photometric_; | |
209 | |
210 return target.release(); | |
211 } | |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
212 |
1905
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
213 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
|
214 bool ignorePhotometricInterpretation) const |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
215 { |
1905
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
216 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
|
217 { |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2416
diff
changeset
|
218 if (GetBitsStored() == 8 && GetChannelCount() == 1 && !IsSigned()) |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2416
diff
changeset
|
219 { |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2416
diff
changeset
|
220 format = PixelFormat_RGB24; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2416
diff
changeset
|
221 return true; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2416
diff
changeset
|
222 } |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2416
diff
changeset
|
223 |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2416
diff
changeset
|
224 if (GetBitsStored() == 16 && GetChannelCount() == 1 && !IsSigned()) |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2416
diff
changeset
|
225 { |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2416
diff
changeset
|
226 format = PixelFormat_RGB48; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2416
diff
changeset
|
227 return true; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2416
diff
changeset
|
228 } |
1905
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
229 } |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2416
diff
changeset
|
230 |
1905
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
231 if (ignorePhotometricInterpretation || |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
232 photometric_ == PhotometricInterpretation_Monochrome1 || |
1206
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
233 photometric_ == PhotometricInterpretation_Monochrome2) |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
234 { |
1206
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
235 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
|
236 { |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
237 format = PixelFormat_Grayscale8; |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
238 return true; |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
239 } |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
240 |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
241 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
|
242 { |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
243 format = PixelFormat_Grayscale16; |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
244 return true; |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
245 } |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
246 |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
247 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
|
248 { |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
249 format = PixelFormat_SignedGrayscale16; |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
250 return true; |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
251 } |
2838
f3a2d109e361
new orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
252 |
f3a2d109e361
new orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
253 if (GetBitsAllocated() == 32 && GetChannelCount() == 1 && !IsSigned()) |
f3a2d109e361
new orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
254 { |
f3a2d109e361
new orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
255 format = PixelFormat_Grayscale32; |
f3a2d109e361
new orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
256 return true; |
f3a2d109e361
new orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
257 } |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
258 } |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
259 |
3007 | 260 if (GetBitsStored() == 8 && |
261 GetChannelCount() == 3 && | |
1206
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
262 !IsSigned() && |
1905
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
263 (ignorePhotometricInterpretation || photometric_ == PhotometricInterpretation_RGB)) |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
264 { |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
265 format = PixelFormat_RGB24; |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
266 return true; |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
267 } |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
268 |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
269 return false; |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
270 } |
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
|
271 |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1908
diff
changeset
|
272 |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1908
diff
changeset
|
273 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
|
274 { |
3007 | 275 return (GetHeight() * |
276 GetWidth() * | |
277 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
|
278 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
|
279 } |
853 | 280 } |