Mercurial > hg > orthanc
annotate OrthancFramework/Sources/DicomFormat/DicomStreamReader.cpp @ 4775:add0337b928a
refactoring parsing of numbers
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 30 Aug 2021 10:24:36 +0200 |
parents | 39192eb9b43d |
children | 7053502fbf97 |
rev | line source |
---|---|
4220
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 /** |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 * Orthanc - A Lightweight, RESTful DICOM Store |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
4437
d9473bd5ed43
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium |
4220
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 * |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public License |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * as published by the Free Software Foundation, either version 3 of |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 * the License, or (at your option) any later version. |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 * |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * This program is distributed in the hope that it will be useful, but |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * WITHOUT ANY WARRANTY; without even the implied warranty of |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * Lesser General Public License for more details. |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * You should have received a copy of the GNU Lesser General Public |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 * License along with this program. If not, see |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 * <http://www.gnu.org/licenses/>. |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 **/ |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 #include "../PrecompiledHeaders.h" |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 #include "DicomStreamReader.h" |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 #include "../OrthancException.h" |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 |
4304 | 28 #include <cassert> |
4493
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
29 #include <sstream> |
4494
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
30 #include <boost/iostreams/device/array.hpp> |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
31 #include <boost/iostreams/stream.hpp> |
4493
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
32 |
4304 | 33 |
4494
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
34 #include <iostream> |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
35 |
4220
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 namespace Orthanc |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 { |
4221
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
38 static bool IsNormalizationNeeded(const std::string& source, |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
39 ValueRepresentation vr) |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
40 { |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
41 return (!source.empty() && |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
42 (source[source.size() - 1] == ' ' || |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
43 source[source.size() - 1] == '\0') && |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
44 // Normalization only applies to string-based VR |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
45 (vr == ValueRepresentation_ApplicationEntity || |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
46 vr == ValueRepresentation_AgeString || |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
47 vr == ValueRepresentation_CodeString || |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
48 vr == ValueRepresentation_DecimalString || |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
49 vr == ValueRepresentation_IntegerString || |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
50 vr == ValueRepresentation_LongString || |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
51 vr == ValueRepresentation_LongText || |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
52 vr == ValueRepresentation_PersonName || |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
53 vr == ValueRepresentation_ShortString || |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
54 vr == ValueRepresentation_ShortText || |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
55 vr == ValueRepresentation_UniqueIdentifier || |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
56 vr == ValueRepresentation_UnlimitedText)); |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
57 } |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
58 |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
59 |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
60 static void NormalizeValue(std::string& inplace, |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
61 ValueRepresentation vr) |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
62 { |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
63 if (IsNormalizationNeeded(inplace, vr)) |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
64 { |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
65 assert(!inplace.empty()); |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
66 inplace.resize(inplace.size() - 1); |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
67 } |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
68 } |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
69 |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
70 |
4220
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
71 static uint16_t ReadUnsignedInteger16(const char* dicom, |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
72 bool littleEndian) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
73 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
74 const uint8_t* p = reinterpret_cast<const uint8_t*>(dicom); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
75 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
76 if (littleEndian) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
77 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
78 return (static_cast<uint16_t>(p[0]) | |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
79 (static_cast<uint16_t>(p[1]) << 8)); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
80 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
81 else |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
82 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
83 return (static_cast<uint16_t>(p[1]) | |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
84 (static_cast<uint16_t>(p[0]) << 8)); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
85 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
86 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
87 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
88 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
89 static uint32_t ReadUnsignedInteger32(const char* dicom, |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
90 bool littleEndian) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
91 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
92 const uint8_t* p = reinterpret_cast<const uint8_t*>(dicom); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
93 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
94 if (littleEndian) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
95 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
96 return (static_cast<uint32_t>(p[0]) | |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
97 (static_cast<uint32_t>(p[1]) << 8) | |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
98 (static_cast<uint32_t>(p[2]) << 16) | |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
99 (static_cast<uint32_t>(p[3]) << 24)); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
100 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
101 else |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
102 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
103 return (static_cast<uint32_t>(p[3]) | |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
104 (static_cast<uint32_t>(p[2]) << 8) | |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
105 (static_cast<uint32_t>(p[1]) << 16) | |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
106 (static_cast<uint32_t>(p[0]) << 24)); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
107 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
108 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
109 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
110 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
111 static DicomTag ReadTag(const char* dicom, |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
112 bool littleEndian) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
113 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
114 return DicomTag(ReadUnsignedInteger16(dicom, littleEndian), |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
115 ReadUnsignedInteger16(dicom + 2, littleEndian)); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
116 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
117 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
118 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
119 static bool IsShortExplicitTag(ValueRepresentation vr) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
120 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
121 /** |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
122 * Are we in the case of Table 7.1-2? "Data Element with |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
123 * Explicit VR of AE, AS, AT, CS, DA, DS, DT, FL, FD, IS, LO, |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
124 * LT, PN, SH, SL, SS, ST, TM, UI, UL and US" |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
125 * http://dicom.nema.org/medical/dicom/current/output/chtml/part05/chapter_7.html#sect_7.1.2 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
126 **/ |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
127 return (vr == ValueRepresentation_ApplicationEntity /* AE */ || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
128 vr == ValueRepresentation_AgeString /* AS */ || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
129 vr == ValueRepresentation_AttributeTag /* AT */ || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
130 vr == ValueRepresentation_CodeString /* CS */ || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
131 vr == ValueRepresentation_Date /* DA */ || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
132 vr == ValueRepresentation_DecimalString /* DS */ || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
133 vr == ValueRepresentation_DateTime /* DT */ || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
134 vr == ValueRepresentation_FloatingPointSingle /* FL */ || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
135 vr == ValueRepresentation_FloatingPointDouble /* FD */ || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
136 vr == ValueRepresentation_IntegerString /* IS */ || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
137 vr == ValueRepresentation_LongString /* LO */ || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
138 vr == ValueRepresentation_LongText /* LT */ || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
139 vr == ValueRepresentation_PersonName /* PN */ || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
140 vr == ValueRepresentation_ShortString /* SH */ || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
141 vr == ValueRepresentation_SignedLong /* SL */ || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
142 vr == ValueRepresentation_SignedShort /* SS */ || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
143 vr == ValueRepresentation_ShortText /* ST */ || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
144 vr == ValueRepresentation_Time /* TM */ || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
145 vr == ValueRepresentation_UniqueIdentifier /* UI */ || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
146 vr == ValueRepresentation_UnsignedLong /* UL */ || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
147 vr == ValueRepresentation_UnsignedShort /* US */); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
148 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
149 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
150 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
151 bool DicomStreamReader::IsLittleEndian() const |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
152 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
153 return (transferSyntax_ != DicomTransferSyntax_BigEndianExplicit); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
154 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
155 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
156 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
157 void DicomStreamReader::HandlePreamble(IVisitor& visitor, |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
158 const std::string& block) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
159 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
160 assert(block.size() == 144u); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
161 assert(reader_.GetProcessedBytes() == 144u); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
162 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
163 /** |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
164 * The "DICOM file meta information" is always encoded using |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
165 * "Explicit VR Little Endian Transfer Syntax" |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
166 * http://dicom.nema.org/medical/dicom/current/output/chtml/part10/chapter_7.html |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
167 **/ |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
168 if (block[128] != 'D' || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
169 block[129] != 'I' || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
170 block[130] != 'C' || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
171 block[131] != 'M' || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
172 ReadTag(block.c_str() + 132, true) != DicomTag(0x0002, 0x0000) || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
173 block[136] != 'U' || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
174 block[137] != 'L' || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
175 ReadUnsignedInteger16(block.c_str() + 138, true) != 4) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
176 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
177 throw OrthancException(ErrorCode_BadFileFormat); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
178 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
179 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
180 uint32_t length = ReadUnsignedInteger32(block.c_str() + 140, true); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
181 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
182 reader_.Schedule(length); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
183 state_ = State_MetaHeader; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
184 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
185 |
4221
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
186 |
4220
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
187 void DicomStreamReader::HandleMetaHeader(IVisitor& visitor, |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
188 const std::string& block) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
189 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
190 size_t pos = 0; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
191 const char* p = block.c_str(); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
192 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
193 bool hasTransferSyntax = false; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
194 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
195 while (pos + 8 <= block.size()) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
196 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
197 DicomTag tag = ReadTag(p + pos, true); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
198 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
199 ValueRepresentation vr = StringToValueRepresentation(std::string(p + pos + 4, 2), true); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
200 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
201 if (IsShortExplicitTag(vr)) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
202 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
203 uint16_t length = ReadUnsignedInteger16(p + pos + 6, true); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
204 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
205 std::string value; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
206 value.assign(p + pos + 8, length); |
4221
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
207 NormalizeValue(value, vr); |
4220
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
208 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
209 if (tag.GetGroup() == 0x0002) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
210 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
211 visitor.VisitMetaHeaderTag(tag, vr, value); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
212 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
213 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
214 if (tag == DICOM_TAG_TRANSFER_SYNTAX_UID) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
215 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
216 if (LookupTransferSyntax(transferSyntax_, value)) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
217 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
218 hasTransferSyntax = true; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
219 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
220 else |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
221 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
222 throw OrthancException(ErrorCode_NotImplemented, "Unsupported transfer syntax: " + value); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
223 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
224 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
225 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
226 pos += length + 8; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
227 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
228 else if (pos + 12 <= block.size()) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
229 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
230 uint16_t reserved = ReadUnsignedInteger16(p + pos + 6, true); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
231 if (reserved != 0) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
232 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
233 break; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
234 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
235 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
236 uint32_t length = ReadUnsignedInteger32(p + pos + 8, true); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
237 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
238 if (tag.GetGroup() == 0x0002) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
239 { |
4221
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
240 std::string value; |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
241 value.assign(p + pos + 12, length); |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
242 NormalizeValue(value, vr); |
4220
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
243 visitor.VisitMetaHeaderTag(tag, vr, value); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
244 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
245 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
246 pos += length + 12; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
247 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
248 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
249 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
250 if (pos != block.size()) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
251 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
252 throw OrthancException(ErrorCode_BadFileFormat); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
253 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
254 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
255 if (!hasTransferSyntax) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
256 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
257 throw OrthancException(ErrorCode_BadFileFormat, "DICOM file meta-header without transfer syntax UID"); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
258 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
259 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
260 visitor.VisitTransferSyntax(transferSyntax_); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
261 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
262 reader_.Schedule(8); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
263 state_ = State_DatasetTag; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
264 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
265 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
266 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
267 void DicomStreamReader::HandleDatasetTag(const std::string& block, |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
268 const DicomTag& untilTag) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
269 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
270 static const DicomTag DICOM_TAG_SEQUENCE_ITEM(0xfffe, 0xe000); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
271 static const DicomTag DICOM_TAG_SEQUENCE_DELIMITATION_ITEM(0xfffe, 0xe00d); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
272 static const DicomTag DICOM_TAG_SEQUENCE_DELIMITATION_SEQUENCE(0xfffe, 0xe0dd); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
273 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
274 assert(block.size() == 8u); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
275 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
276 const bool littleEndian = IsLittleEndian(); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
277 DicomTag tag = ReadTag(block.c_str(), littleEndian); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
278 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
279 if (sequenceDepth_ == 0 && |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
280 tag >= untilTag) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
281 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
282 state_ = State_Done; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
283 return; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
284 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
285 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
286 if (tag == DICOM_TAG_SEQUENCE_ITEM || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
287 tag == DICOM_TAG_SEQUENCE_DELIMITATION_ITEM || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
288 tag == DICOM_TAG_SEQUENCE_DELIMITATION_SEQUENCE) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
289 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
290 // The special sequence items are encoded like "Implicit VR" |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
291 uint32_t length = ReadUnsignedInteger32(block.c_str() + 4, littleEndian); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
292 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
293 if (tag == DICOM_TAG_SEQUENCE_ITEM) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
294 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
295 if (length == 0xffffffffu) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
296 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
297 // Undefined length: Need to loop over the tags of the nested dataset |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
298 reader_.Schedule(8); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
299 state_ = State_DatasetTag; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
300 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
301 else |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
302 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
303 // Explicit length: Can skip the full sequence at once |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
304 reader_.Schedule(length); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
305 state_ = State_DatasetValue; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
306 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
307 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
308 else if (tag == DICOM_TAG_SEQUENCE_DELIMITATION_ITEM || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
309 tag == DICOM_TAG_SEQUENCE_DELIMITATION_SEQUENCE) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
310 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
311 if (length != 0 || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
312 sequenceDepth_ == 0) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
313 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
314 throw OrthancException(ErrorCode_BadFileFormat); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
315 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
316 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
317 if (tag == DICOM_TAG_SEQUENCE_DELIMITATION_SEQUENCE) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
318 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
319 sequenceDepth_ --; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
320 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
321 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
322 reader_.Schedule(8); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
323 state_ = State_DatasetTag; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
324 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
325 else |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
326 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
327 throw OrthancException(ErrorCode_InternalError); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
328 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
329 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
330 else |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
331 { |
4493
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
332 assert(reader_.GetProcessedBytes() >= block.size()); |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
333 const uint64_t tagOffset = reader_.GetProcessedBytes() - block.size(); |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
334 |
4220
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
335 ValueRepresentation vr = ValueRepresentation_Unknown; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
336 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
337 if (transferSyntax_ == DicomTransferSyntax_LittleEndianImplicit) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
338 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
339 if (sequenceDepth_ == 0) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
340 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
341 danglingTag_ = tag; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
342 danglingVR_ = vr; |
4493
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
343 danglingOffset_ = tagOffset; |
4220
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
344 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
345 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
346 uint32_t length = ReadUnsignedInteger32(block.c_str() + 4, true /* little endian */); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
347 HandleDatasetExplicitLength(length); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
348 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
349 else |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
350 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
351 // This in an explicit transfer syntax |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
352 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
353 vr = StringToValueRepresentation( |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
354 std::string(block.c_str() + 4, 2), false /* ignore unknown VR */); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
355 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
356 if (vr == ValueRepresentation_Sequence) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
357 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
358 sequenceDepth_ ++; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
359 reader_.Schedule(4); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
360 state_ = State_SequenceExplicitLength; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
361 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
362 else if (IsShortExplicitTag(vr)) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
363 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
364 uint16_t length = ReadUnsignedInteger16(block.c_str() + 6, littleEndian); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
365 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
366 reader_.Schedule(length); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
367 state_ = State_DatasetValue; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
368 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
369 else |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
370 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
371 uint16_t reserved = ReadUnsignedInteger16(block.c_str() + 6, littleEndian); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
372 if (reserved != 0) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
373 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
374 throw OrthancException(ErrorCode_BadFileFormat); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
375 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
376 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
377 reader_.Schedule(4); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
378 state_ = State_DatasetExplicitLength; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
379 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
380 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
381 if (sequenceDepth_ == 0) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
382 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
383 danglingTag_ = tag; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
384 danglingVR_ = vr; |
4493
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
385 danglingOffset_ = tagOffset; |
4220
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
386 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
387 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
388 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
389 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
390 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
391 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
392 void DicomStreamReader::HandleDatasetExplicitLength(uint32_t length) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
393 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
394 if (length == 0xffffffffu) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
395 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
396 /** |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
397 * This is the case of pixel data with compressed transfer |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
398 * syntaxes. Schedule the reading of the first tag of the |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
399 * nested dataset. |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
400 * http://dicom.nema.org/medical/dicom/current/output/chtml/part05/sect_7.5.html |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
401 **/ |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
402 state_ = State_DatasetTag; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
403 reader_.Schedule(8); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
404 sequenceDepth_ ++; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
405 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
406 else |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
407 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
408 reader_.Schedule(length); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
409 state_ = State_DatasetValue; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
410 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
411 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
412 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
413 |
4493
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
414 void DicomStreamReader::HandleDatasetExplicitLength(IVisitor& visitor, |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
415 const std::string& block) |
4220
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
416 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
417 assert(block.size() == 4); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
418 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
419 uint32_t length = ReadUnsignedInteger32(block.c_str(), IsLittleEndian()); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
420 HandleDatasetExplicitLength(length); |
4493
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
421 |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
422 std::string empty; |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
423 if (!visitor.VisitDatasetTag(danglingTag_, danglingVR_, empty, IsLittleEndian(), danglingOffset_)) |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
424 { |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
425 state_ = State_Done; |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
426 } |
4220
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
427 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
428 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
429 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
430 void DicomStreamReader::HandleSequenceExplicitLength(const std::string& block) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
431 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
432 assert(block.size() == 4); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
433 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
434 uint32_t length = ReadUnsignedInteger32(block.c_str(), IsLittleEndian()); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
435 if (length == 0xffffffffu) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
436 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
437 state_ = State_DatasetTag; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
438 reader_.Schedule(8); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
439 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
440 else |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
441 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
442 reader_.Schedule(length); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
443 state_ = State_SequenceExplicitValue; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
444 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
445 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
446 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
447 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
448 void DicomStreamReader::HandleSequenceExplicitValue() |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
449 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
450 if (sequenceDepth_ == 0) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
451 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
452 throw OrthancException(ErrorCode_InternalError); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
453 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
454 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
455 sequenceDepth_ --; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
456 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
457 state_ = State_DatasetTag; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
458 reader_.Schedule(8); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
459 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
460 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
461 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
462 void DicomStreamReader::HandleDatasetValue(IVisitor& visitor, |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
463 const std::string& block) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
464 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
465 if (sequenceDepth_ == 0) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
466 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
467 bool c; |
4221
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
468 |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
469 if (IsNormalizationNeeded(block, danglingVR_)) |
4220
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
470 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
471 std::string s(block.begin(), block.end() - 1); |
4493
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
472 c = visitor.VisitDatasetTag(danglingTag_, danglingVR_, s, IsLittleEndian(), danglingOffset_); |
4220
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
473 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
474 else |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
475 { |
4493
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
476 c = visitor.VisitDatasetTag(danglingTag_, danglingVR_, block, IsLittleEndian(), danglingOffset_); |
4220
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
477 } |
4493
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
478 |
4220
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
479 if (!c) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
480 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
481 state_ = State_Done; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
482 return; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
483 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
484 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
485 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
486 reader_.Schedule(8); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
487 state_ = State_DatasetTag; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
488 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
489 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
490 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
491 DicomStreamReader::DicomStreamReader(std::istream& stream) : |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
492 reader_(stream), |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
493 state_(State_Preamble), |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
494 transferSyntax_(DicomTransferSyntax_LittleEndianImplicit), // Dummy |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
495 danglingTag_(0x0000, 0x0000), // Dummy |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
496 danglingVR_(ValueRepresentation_Unknown), // Dummy |
4493
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
497 danglingOffset_(0), // Dummy |
4220
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
498 sequenceDepth_(0) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
499 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
500 reader_.Schedule(128 /* empty header */ + |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
501 4 /* "DICM" magic value */ + |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
502 4 /* (0x0002, 0x0000) tag */ + |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
503 2 /* value representation of (0x0002, 0x0000) == "UL" */ + |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
504 2 /* length of "UL" value == 4 */ + |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
505 4 /* actual length of the meta-header */); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
506 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
507 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
508 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
509 void DicomStreamReader::Consume(IVisitor& visitor, |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
510 const DicomTag& untilTag) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
511 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
512 while (state_ != State_Done) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
513 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
514 std::string block; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
515 if (reader_.Read(block)) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
516 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
517 switch (state_) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
518 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
519 case State_Preamble: |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
520 HandlePreamble(visitor, block); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
521 break; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
522 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
523 case State_MetaHeader: |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
524 HandleMetaHeader(visitor, block); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
525 break; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
526 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
527 case State_DatasetTag: |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
528 HandleDatasetTag(block, untilTag); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
529 break; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
530 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
531 case State_DatasetExplicitLength: |
4493
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
532 HandleDatasetExplicitLength(visitor, block); |
4220
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
533 break; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
534 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
535 case State_SequenceExplicitLength: |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
536 HandleSequenceExplicitLength(block); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
537 break; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
538 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
539 case State_SequenceExplicitValue: |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
540 HandleSequenceExplicitValue(); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
541 break; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
542 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
543 case State_DatasetValue: |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
544 HandleDatasetValue(visitor, block); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
545 break; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
546 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
547 default: |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
548 throw OrthancException(ErrorCode_InternalError); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
549 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
550 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
551 else |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
552 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
553 return; // No more data in the stream |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
554 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
555 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
556 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
557 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
558 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
559 void DicomStreamReader::Consume(IVisitor& visitor) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
560 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
561 DicomTag untilTag(0xffff, 0xffff); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
562 Consume(visitor, untilTag); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
563 } |
4277
c5ca798b158a
CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4222
diff
changeset
|
564 |
c5ca798b158a
CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4222
diff
changeset
|
565 |
c5ca798b158a
CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4222
diff
changeset
|
566 bool DicomStreamReader::IsDone() const |
c5ca798b158a
CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4222
diff
changeset
|
567 { |
c5ca798b158a
CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4222
diff
changeset
|
568 return (state_ == State_Done); |
c5ca798b158a
CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4222
diff
changeset
|
569 } |
c5ca798b158a
CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4222
diff
changeset
|
570 |
c5ca798b158a
CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4222
diff
changeset
|
571 |
c5ca798b158a
CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4222
diff
changeset
|
572 uint64_t DicomStreamReader::GetProcessedBytes() const |
c5ca798b158a
CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4222
diff
changeset
|
573 { |
c5ca798b158a
CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4222
diff
changeset
|
574 return reader_.GetProcessedBytes(); |
c5ca798b158a
CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4222
diff
changeset
|
575 } |
4493
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
576 |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
577 |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
578 class DicomStreamReader::PixelDataVisitor : public DicomStreamReader::IVisitor |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
579 { |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
580 private: |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
581 bool hasPixelData_; |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
582 uint64_t pixelDataOffset_; |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
583 |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
584 public: |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
585 PixelDataVisitor() : |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
586 hasPixelData_(false), |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
587 pixelDataOffset_(0) |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
588 { |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
589 } |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
590 |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
591 virtual void VisitMetaHeaderTag(const DicomTag& tag, |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
592 const ValueRepresentation& vr, |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
593 const std::string& value) ORTHANC_OVERRIDE |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
594 { |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
595 } |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
596 |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
597 virtual void VisitTransferSyntax(DicomTransferSyntax transferSyntax) ORTHANC_OVERRIDE |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
598 { |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
599 } |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
600 |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
601 virtual bool VisitDatasetTag(const DicomTag& tag, |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
602 const ValueRepresentation& vr, |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
603 const std::string& value, |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
604 bool isLittleEndian, |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
605 uint64_t fileOffset) ORTHANC_OVERRIDE |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
606 { |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
607 if (tag == DICOM_TAG_PIXEL_DATA) |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
608 { |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
609 hasPixelData_ = true; |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
610 pixelDataOffset_ = fileOffset; |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
611 } |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
612 |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
613 // Stop processing once pixel data has been passed |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
614 return (tag < DICOM_TAG_PIXEL_DATA); |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
615 } |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
616 |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
617 bool HasPixelData() const |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
618 { |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
619 return hasPixelData_; |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
620 } |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
621 |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
622 uint64_t GetPixelDataOffset() const |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
623 { |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
624 return pixelDataOffset_; |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
625 } |
4494
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
626 |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
627 static bool LookupPixelDataOffset(uint64_t& offset, |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
628 std::istream& stream) |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
629 { |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
630 PixelDataVisitor visitor; |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
631 bool isLittleEndian; |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
632 |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
633 { |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
634 DicomStreamReader reader(stream); |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
635 |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
636 try |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
637 { |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
638 reader.Consume(visitor); |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
639 isLittleEndian = reader.IsLittleEndian(); |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
640 } |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
641 catch (OrthancException& e) |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
642 { |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
643 // Invalid DICOM file |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
644 return false; |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
645 } |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
646 } |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
647 |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
648 if (visitor.HasPixelData()) |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
649 { |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
650 // Sanity check if we face an unsupported DICOM file: Make |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
651 // sure that we can read DICOM_TAG_PIXEL_DATA at the reported |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
652 // position in the stream |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
653 stream.seekg(visitor.GetPixelDataOffset(), stream.beg); |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
654 |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
655 std::string s; |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
656 s.resize(4); |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
657 stream.read(&s[0], s.size()); |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
658 |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
659 if (!isLittleEndian) |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
660 { |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
661 // Byte swapping if reading a file whose transfer syntax is |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
662 // 1.2.840.10008.1.2.2 (big endian explicit) |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
663 std::swap(s[0], s[1]); |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
664 std::swap(s[2], s[3]); |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
665 } |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
666 |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
667 if (stream.gcount() == static_cast<std::streamsize>(s.size()) && |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
668 s[0] == char(0xe0) && |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
669 s[1] == char(0x7f) && |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
670 s[2] == char(0x10) && |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
671 s[3] == char(0x00)) |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
672 { |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
673 offset = visitor.GetPixelDataOffset(); |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
674 return true; |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
675 } |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
676 else |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
677 { |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
678 return false; |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
679 } |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
680 } |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
681 else |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
682 { |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
683 return false; |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
684 } |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
685 } |
4493
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
686 }; |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
687 |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
688 |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
689 bool DicomStreamReader::LookupPixelDataOffset(uint64_t& offset, |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
690 const std::string& dicom) |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
691 { |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
692 std::stringstream stream(dicom); |
4494
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
693 return PixelDataVisitor::LookupPixelDataOffset(offset, stream); |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
694 } |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
695 |
4493
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
696 |
4494
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
697 bool DicomStreamReader::LookupPixelDataOffset(uint64_t& offset, |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
698 const void* buffer, |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
699 size_t size) |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
700 { |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
701 boost::iostreams::array_source source(reinterpret_cast<const char*>(buffer), size); |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
702 boost::iostreams::stream<boost::iostreams::array_source> stream(source); |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
703 return PixelDataVisitor::LookupPixelDataOffset(offset, stream); |
4493
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
704 } |
4220
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
705 } |
4494
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
706 |