Mercurial > hg > orthanc
annotate OrthancFramework/Sources/DicomFormat/DicomStreamReader.cpp @ 5657:dedbf019a707
Improved parsing of multiple numerical values in DICOM tags
author | Alain Mazy <am@orthanc.team> |
---|---|
date | Thu, 06 Jun 2024 17:55:13 +0200 |
parents | f7adfb22e20e |
children |
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 |
5640
f7adfb22e20e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
f7adfb22e20e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium |
5485
48b8dae6dc77
upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5324
diff
changeset
|
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
4220
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * This program is free software: you can redistribute it and/or |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 * 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
|
11 * as published by the Free Software Foundation, either version 3 of |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * the License, or (at your option) any later version. |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * 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
|
15 * WITHOUT ANY WARRANTY; without even the implied warranty of |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * Lesser General Public License for more details. |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 * |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 * 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
|
20 * License along with this program. If not, see |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 * <http://www.gnu.org/licenses/>. |
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 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 #include "../PrecompiledHeaders.h" |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 #include "DicomStreamReader.h" |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 #include "../OrthancException.h" |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 |
4304 | 30 #include <cassert> |
4493
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
31 #include <sstream> |
4494
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
32 #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
|
33 #include <boost/iostreams/stream.hpp> |
4493
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
34 |
4304 | 35 |
4494
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
36 #include <iostream> |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
37 |
4220
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 namespace Orthanc |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 { |
4221
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
40 static bool IsNormalizationNeeded(const std::string& source, |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
41 ValueRepresentation vr) |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
42 { |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
43 return (!source.empty() && |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
44 (source[source.size() - 1] == ' ' || |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
45 source[source.size() - 1] == '\0') && |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
46 // Normalization only applies to string-based VR |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
47 (vr == ValueRepresentation_ApplicationEntity || |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
48 vr == ValueRepresentation_AgeString || |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
49 vr == ValueRepresentation_CodeString || |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
50 vr == ValueRepresentation_DecimalString || |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
51 vr == ValueRepresentation_IntegerString || |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
52 vr == ValueRepresentation_LongString || |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
53 vr == ValueRepresentation_LongText || |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
54 vr == ValueRepresentation_PersonName || |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
55 vr == ValueRepresentation_ShortString || |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
56 vr == ValueRepresentation_ShortText || |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
57 vr == ValueRepresentation_UniqueIdentifier || |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
58 vr == ValueRepresentation_UnlimitedText)); |
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 |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
61 |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
62 static void NormalizeValue(std::string& inplace, |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
63 ValueRepresentation 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 if (IsNormalizationNeeded(inplace, vr)) |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
66 { |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
67 assert(!inplace.empty()); |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
68 inplace.resize(inplace.size() - 1); |
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 } |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
71 |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
72 |
4220
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
73 static uint16_t ReadUnsignedInteger16(const char* dicom, |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
74 bool littleEndian) |
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 const uint8_t* p = reinterpret_cast<const uint8_t*>(dicom); |
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 if (littleEndian) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
79 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
80 return (static_cast<uint16_t>(p[0]) | |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
81 (static_cast<uint16_t>(p[1]) << 8)); |
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 else |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
84 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
85 return (static_cast<uint16_t>(p[1]) | |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
86 (static_cast<uint16_t>(p[0]) << 8)); |
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 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
90 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
91 static uint32_t ReadUnsignedInteger32(const char* dicom, |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
92 bool littleEndian) |
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 const uint8_t* p = reinterpret_cast<const uint8_t*>(dicom); |
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 if (littleEndian) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
97 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
98 return (static_cast<uint32_t>(p[0]) | |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
99 (static_cast<uint32_t>(p[1]) << 8) | |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
100 (static_cast<uint32_t>(p[2]) << 16) | |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
101 (static_cast<uint32_t>(p[3]) << 24)); |
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 else |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
104 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
105 return (static_cast<uint32_t>(p[3]) | |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
106 (static_cast<uint32_t>(p[2]) << 8) | |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
107 (static_cast<uint32_t>(p[1]) << 16) | |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
108 (static_cast<uint32_t>(p[0]) << 24)); |
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 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
112 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
113 static DicomTag ReadTag(const char* dicom, |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
114 bool littleEndian) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
115 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
116 return DicomTag(ReadUnsignedInteger16(dicom, littleEndian), |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
117 ReadUnsignedInteger16(dicom + 2, littleEndian)); |
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 |
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 static bool IsShortExplicitTag(ValueRepresentation vr) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
122 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
123 /** |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
124 * 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
|
125 * 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
|
126 * LT, PN, SH, SL, SS, ST, TM, UI, UL and US" |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
127 * 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
|
128 **/ |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
129 return (vr == ValueRepresentation_ApplicationEntity /* AE */ || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
130 vr == ValueRepresentation_AgeString /* AS */ || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
131 vr == ValueRepresentation_AttributeTag /* AT */ || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
132 vr == ValueRepresentation_CodeString /* CS */ || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
133 vr == ValueRepresentation_Date /* DA */ || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
134 vr == ValueRepresentation_DecimalString /* DS */ || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
135 vr == ValueRepresentation_DateTime /* DT */ || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
136 vr == ValueRepresentation_FloatingPointSingle /* FL */ || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
137 vr == ValueRepresentation_FloatingPointDouble /* FD */ || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
138 vr == ValueRepresentation_IntegerString /* IS */ || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
139 vr == ValueRepresentation_LongString /* LO */ || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
140 vr == ValueRepresentation_LongText /* LT */ || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
141 vr == ValueRepresentation_PersonName /* PN */ || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
142 vr == ValueRepresentation_ShortString /* SH */ || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
143 vr == ValueRepresentation_SignedLong /* SL */ || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
144 vr == ValueRepresentation_SignedShort /* SS */ || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
145 vr == ValueRepresentation_ShortText /* ST */ || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
146 vr == ValueRepresentation_Time /* TM */ || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
147 vr == ValueRepresentation_UniqueIdentifier /* UI */ || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
148 vr == ValueRepresentation_UnsignedLong /* UL */ || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
149 vr == ValueRepresentation_UnsignedShort /* US */); |
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 |
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 bool DicomStreamReader::IsLittleEndian() const |
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 return (transferSyntax_ != DicomTransferSyntax_BigEndianExplicit); |
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 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
158 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
159 void DicomStreamReader::HandlePreamble(IVisitor& visitor, |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
160 const std::string& block) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
161 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
162 assert(block.size() == 144u); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
163 assert(reader_.GetProcessedBytes() == 144u); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
164 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
165 /** |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
166 * The "DICOM file meta information" is always encoded using |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
167 * "Explicit VR Little Endian Transfer Syntax" |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
168 * 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
|
169 **/ |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
170 if (block[128] != 'D' || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
171 block[129] != 'I' || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
172 block[130] != 'C' || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
173 block[131] != 'M' || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
174 ReadTag(block.c_str() + 132, true) != DicomTag(0x0002, 0x0000) || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
175 block[136] != 'U' || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
176 block[137] != 'L' || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
177 ReadUnsignedInteger16(block.c_str() + 138, true) != 4) |
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 throw OrthancException(ErrorCode_BadFileFormat); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
180 } |
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 uint32_t length = ReadUnsignedInteger32(block.c_str() + 140, true); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
183 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
184 reader_.Schedule(length); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
185 state_ = State_MetaHeader; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
186 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
187 |
4221
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
188 |
4220
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
189 void DicomStreamReader::HandleMetaHeader(IVisitor& visitor, |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
190 const std::string& block) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
191 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
192 size_t pos = 0; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
193 const char* p = block.c_str(); |
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 bool hasTransferSyntax = false; |
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 while (pos + 8 <= block.size()) |
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 DicomTag tag = ReadTag(p + pos, 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 ValueRepresentation vr = StringToValueRepresentation(std::string(p + pos + 4, 2), true); |
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 if (IsShortExplicitTag(vr)) |
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 uint16_t length = ReadUnsignedInteger16(p + pos + 6, true); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
206 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
207 std::string value; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
208 value.assign(p + pos + 8, length); |
4221
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
209 NormalizeValue(value, vr); |
4220
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 if (tag.GetGroup() == 0x0002) |
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 visitor.VisitMetaHeaderTag(tag, vr, value); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
214 } |
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 (tag == DICOM_TAG_TRANSFER_SYNTAX_UID) |
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 if (LookupTransferSyntax(transferSyntax_, value)) |
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 hasTransferSyntax = true; |
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 else |
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 throw OrthancException(ErrorCode_NotImplemented, "Unsupported transfer syntax: " + value); |
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 } |
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 pos += length + 8; |
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 else if (pos + 12 <= block.size()) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
231 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
232 uint16_t reserved = ReadUnsignedInteger16(p + pos + 6, true); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
233 if (reserved != 0) |
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 break; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
236 } |
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 uint32_t length = ReadUnsignedInteger32(p + pos + 8, true); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
239 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
240 if (tag.GetGroup() == 0x0002) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
241 { |
4221
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
242 std::string value; |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
243 value.assign(p + pos + 12, length); |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
244 NormalizeValue(value, vr); |
4220
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
245 visitor.VisitMetaHeaderTag(tag, vr, value); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
246 } |
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 pos += length + 12; |
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 } |
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 if (pos != block.size()) |
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 throw OrthancException(ErrorCode_BadFileFormat); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
255 } |
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 if (!hasTransferSyntax) |
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 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
|
260 } |
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 visitor.VisitTransferSyntax(transferSyntax_); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
263 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
264 reader_.Schedule(8); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
265 state_ = State_DatasetTag; |
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 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
268 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
269 void DicomStreamReader::HandleDatasetTag(const std::string& block, |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
270 const DicomTag& untilTag) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
271 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
272 static const DicomTag DICOM_TAG_SEQUENCE_ITEM(0xfffe, 0xe000); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
273 static const DicomTag DICOM_TAG_SEQUENCE_DELIMITATION_ITEM(0xfffe, 0xe00d); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
274 static const DicomTag DICOM_TAG_SEQUENCE_DELIMITATION_SEQUENCE(0xfffe, 0xe0dd); |
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 assert(block.size() == 8u); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
277 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
278 const bool littleEndian = IsLittleEndian(); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
279 DicomTag tag = ReadTag(block.c_str(), littleEndian); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
280 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
281 if (sequenceDepth_ == 0 && |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
282 tag >= untilTag) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
283 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
284 state_ = State_Done; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
285 return; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
286 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
287 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
288 if (tag == DICOM_TAG_SEQUENCE_ITEM || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
289 tag == DICOM_TAG_SEQUENCE_DELIMITATION_ITEM || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
290 tag == DICOM_TAG_SEQUENCE_DELIMITATION_SEQUENCE) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
291 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
292 // The special sequence items are encoded like "Implicit VR" |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
293 uint32_t length = ReadUnsignedInteger32(block.c_str() + 4, littleEndian); |
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 (tag == DICOM_TAG_SEQUENCE_ITEM) |
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 if (length == 0xffffffffu) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
298 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
299 // 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
|
300 reader_.Schedule(8); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
301 state_ = State_DatasetTag; |
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 else |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
304 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
305 // Explicit length: Can skip the full sequence at once |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
306 reader_.Schedule(length); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
307 state_ = State_DatasetValue; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
308 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
309 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
310 else if (tag == DICOM_TAG_SEQUENCE_DELIMITATION_ITEM || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
311 tag == DICOM_TAG_SEQUENCE_DELIMITATION_SEQUENCE) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
312 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
313 if (length != 0 || |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
314 sequenceDepth_ == 0) |
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 throw OrthancException(ErrorCode_BadFileFormat); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
317 } |
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 if (tag == DICOM_TAG_SEQUENCE_DELIMITATION_SEQUENCE) |
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 sequenceDepth_ --; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
322 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
323 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
324 reader_.Schedule(8); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
325 state_ = State_DatasetTag; |
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 else |
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 throw OrthancException(ErrorCode_InternalError); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
330 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
331 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
332 else |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
333 { |
4493
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
334 assert(reader_.GetProcessedBytes() >= block.size()); |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
335 const uint64_t tagOffset = reader_.GetProcessedBytes() - block.size(); |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
336 |
4220
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
337 ValueRepresentation vr = ValueRepresentation_Unknown; |
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 (transferSyntax_ == DicomTransferSyntax_LittleEndianImplicit) |
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 if (sequenceDepth_ == 0) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
342 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
343 danglingTag_ = tag; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
344 danglingVR_ = vr; |
4493
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
345 danglingOffset_ = tagOffset; |
4220
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
346 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
347 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
348 uint32_t length = ReadUnsignedInteger32(block.c_str() + 4, true /* little endian */); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
349 HandleDatasetExplicitLength(length); |
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 else |
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 // This in an explicit transfer syntax |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
354 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
355 vr = StringToValueRepresentation( |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
356 std::string(block.c_str() + 4, 2), false /* ignore unknown VR */); |
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 if (vr == ValueRepresentation_Sequence) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
359 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
360 sequenceDepth_ ++; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
361 reader_.Schedule(4); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
362 state_ = State_SequenceExplicitLength; |
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 else if (IsShortExplicitTag(vr)) |
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 uint16_t length = ReadUnsignedInteger16(block.c_str() + 6, littleEndian); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
367 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
368 reader_.Schedule(length); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
369 state_ = State_DatasetValue; |
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 else |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
372 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
373 uint16_t reserved = ReadUnsignedInteger16(block.c_str() + 6, littleEndian); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
374 if (reserved != 0) |
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 throw OrthancException(ErrorCode_BadFileFormat); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
377 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
378 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
379 reader_.Schedule(4); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
380 state_ = State_DatasetExplicitLength; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
381 } |
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 if (sequenceDepth_ == 0) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
384 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
385 danglingTag_ = tag; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
386 danglingVR_ = vr; |
4493
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
387 danglingOffset_ = tagOffset; |
4220
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 |
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 void DicomStreamReader::HandleDatasetExplicitLength(uint32_t length) |
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 if (length == 0xffffffffu) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
397 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
398 /** |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
399 * This is the case of pixel data with compressed transfer |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
400 * syntaxes. Schedule the reading of the first tag of the |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
401 * nested dataset. |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
402 * 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
|
403 **/ |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
404 state_ = State_DatasetTag; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
405 reader_.Schedule(8); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
406 sequenceDepth_ ++; |
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 else |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
409 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
410 reader_.Schedule(length); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
411 state_ = State_DatasetValue; |
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 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
414 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
415 |
4493
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
416 void DicomStreamReader::HandleDatasetExplicitLength(IVisitor& visitor, |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
417 const std::string& block) |
4220
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 assert(block.size() == 4); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
420 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
421 uint32_t length = ReadUnsignedInteger32(block.c_str(), IsLittleEndian()); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
422 HandleDatasetExplicitLength(length); |
4493
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
423 |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
424 std::string empty; |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
425 if (!visitor.VisitDatasetTag(danglingTag_, danglingVR_, empty, IsLittleEndian(), danglingOffset_)) |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
426 { |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
427 state_ = State_Done; |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
428 } |
4220
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 |
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 void DicomStreamReader::HandleSequenceExplicitLength(const std::string& block) |
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 assert(block.size() == 4); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
435 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
436 uint32_t length = ReadUnsignedInteger32(block.c_str(), IsLittleEndian()); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
437 if (length == 0xffffffffu) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
438 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
439 state_ = State_DatasetTag; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
440 reader_.Schedule(8); |
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 else |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
443 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
444 reader_.Schedule(length); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
445 state_ = State_SequenceExplicitValue; |
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 |
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 void DicomStreamReader::HandleSequenceExplicitValue() |
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 if (sequenceDepth_ == 0) |
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 throw OrthancException(ErrorCode_InternalError); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
455 } |
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 sequenceDepth_ --; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
458 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
459 state_ = State_DatasetTag; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
460 reader_.Schedule(8); |
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 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
463 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
464 void DicomStreamReader::HandleDatasetValue(IVisitor& visitor, |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
465 const std::string& block) |
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 if (sequenceDepth_ == 0) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
468 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
469 bool c; |
4221
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
470 |
e4c0218b6b23
better normalization in stream reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4220
diff
changeset
|
471 if (IsNormalizationNeeded(block, danglingVR_)) |
4220
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
472 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
473 std::string s(block.begin(), block.end() - 1); |
4493
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
474 c = visitor.VisitDatasetTag(danglingTag_, danglingVR_, s, IsLittleEndian(), danglingOffset_); |
4220
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
475 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
476 else |
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 c = visitor.VisitDatasetTag(danglingTag_, danglingVR_, block, IsLittleEndian(), danglingOffset_); |
4220
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
479 } |
4493
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
480 |
4220
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
481 if (!c) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
482 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
483 state_ = State_Done; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
484 return; |
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 } |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
487 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
488 reader_.Schedule(8); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
489 state_ = State_DatasetTag; |
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 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
492 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
493 DicomStreamReader::DicomStreamReader(std::istream& stream) : |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
494 reader_(stream), |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
495 state_(State_Preamble), |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
496 transferSyntax_(DicomTransferSyntax_LittleEndianImplicit), // Dummy |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
497 danglingTag_(0x0000, 0x0000), // Dummy |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
498 danglingVR_(ValueRepresentation_Unknown), // Dummy |
4493
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
499 danglingOffset_(0), // Dummy |
4220
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
500 sequenceDepth_(0) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
501 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
502 reader_.Schedule(128 /* empty header */ + |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
503 4 /* "DICM" magic value */ + |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
504 4 /* (0x0002, 0x0000) tag */ + |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
505 2 /* value representation of (0x0002, 0x0000) == "UL" */ + |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
506 2 /* length of "UL" value == 4 */ + |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
507 4 /* actual length of the meta-header */); |
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 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
510 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
511 void DicomStreamReader::Consume(IVisitor& visitor, |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
512 const DicomTag& untilTag) |
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 while (state_ != State_Done) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
515 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
516 std::string block; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
517 if (reader_.Read(block)) |
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 switch (state_) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
520 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
521 case State_Preamble: |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
522 HandlePreamble(visitor, block); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
523 break; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
524 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
525 case State_MetaHeader: |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
526 HandleMetaHeader(visitor, block); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
527 break; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
528 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
529 case State_DatasetTag: |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
530 HandleDatasetTag(block, untilTag); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
531 break; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
532 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
533 case State_DatasetExplicitLength: |
4493
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
534 HandleDatasetExplicitLength(visitor, block); |
4220
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
535 break; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
536 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
537 case State_SequenceExplicitLength: |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
538 HandleSequenceExplicitLength(block); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
539 break; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
540 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
541 case State_SequenceExplicitValue: |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
542 HandleSequenceExplicitValue(); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
543 break; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
544 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
545 case State_DatasetValue: |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
546 HandleDatasetValue(visitor, block); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
547 break; |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
548 |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
549 default: |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
550 throw OrthancException(ErrorCode_InternalError); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
551 } |
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 else |
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 return; // No more data in the stream |
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 |
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 void DicomStreamReader::Consume(IVisitor& visitor) |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
562 { |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
563 DicomTag untilTag(0xffff, 0xffff); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
564 Consume(visitor, untilTag); |
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
565 } |
4277
c5ca798b158a
CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4222
diff
changeset
|
566 |
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 bool DicomStreamReader::IsDone() const |
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 return (state_ == State_Done); |
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 |
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 uint64_t DicomStreamReader::GetProcessedBytes() const |
c5ca798b158a
CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4222
diff
changeset
|
575 { |
c5ca798b158a
CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4222
diff
changeset
|
576 return reader_.GetProcessedBytes(); |
c5ca798b158a
CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4222
diff
changeset
|
577 } |
4493
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
578 |
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 class DicomStreamReader::PixelDataVisitor : public DicomStreamReader::IVisitor |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
581 { |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
582 private: |
5316
03501a258d9e
added instance metadata "PixelDataVR"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
583 bool hasPixelData_; |
03501a258d9e
added instance metadata "PixelDataVR"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
584 uint64_t pixelDataOffset_; |
03501a258d9e
added instance metadata "PixelDataVR"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
585 ValueRepresentation pixelDataVR_; |
5324
e95caa87fed8
only store PixelDataVR metadata if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5316
diff
changeset
|
586 DicomTransferSyntax transferSyntax_; |
4493
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
587 |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
588 public: |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
589 PixelDataVisitor() : |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
590 hasPixelData_(false), |
5316
03501a258d9e
added instance metadata "PixelDataVR"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
591 pixelDataOffset_(0), |
5324
e95caa87fed8
only store PixelDataVR metadata if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5316
diff
changeset
|
592 pixelDataVR_(ValueRepresentation_Unknown), |
e95caa87fed8
only store PixelDataVR metadata if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5316
diff
changeset
|
593 transferSyntax_(DicomTransferSyntax_LittleEndianImplicit) // Default DICOM transfer syntax |
4493
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 VisitMetaHeaderTag(const DicomTag& tag, |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
598 const ValueRepresentation& vr, |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
599 const std::string& value) ORTHANC_OVERRIDE |
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 } |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
602 |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
603 virtual void VisitTransferSyntax(DicomTransferSyntax transferSyntax) ORTHANC_OVERRIDE |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
604 { |
5324
e95caa87fed8
only store PixelDataVR metadata if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5316
diff
changeset
|
605 transferSyntax_ = transferSyntax; |
4493
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 |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
608 virtual bool VisitDatasetTag(const DicomTag& tag, |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
609 const ValueRepresentation& vr, |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
610 const std::string& value, |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
611 bool isLittleEndian, |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
612 uint64_t fileOffset) ORTHANC_OVERRIDE |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
613 { |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
614 if (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 hasPixelData_ = true; |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
617 pixelDataOffset_ = fileOffset; |
5324
e95caa87fed8
only store PixelDataVR metadata if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5316
diff
changeset
|
618 |
e95caa87fed8
only store PixelDataVR metadata if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5316
diff
changeset
|
619 if (transferSyntax_ == DicomTransferSyntax_LittleEndianImplicit) |
e95caa87fed8
only store PixelDataVR metadata if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5316
diff
changeset
|
620 { |
e95caa87fed8
only store PixelDataVR metadata if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5316
diff
changeset
|
621 // Implicit Little Endian has always "OW" VR for pixel data |
e95caa87fed8
only store PixelDataVR metadata if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5316
diff
changeset
|
622 // https://dicom.nema.org/medical/dicom/current/output/chtml/part05/chapter_A.html |
e95caa87fed8
only store PixelDataVR metadata if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5316
diff
changeset
|
623 pixelDataVR_ = ValueRepresentation_OtherWord; |
e95caa87fed8
only store PixelDataVR metadata if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5316
diff
changeset
|
624 } |
e95caa87fed8
only store PixelDataVR metadata if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5316
diff
changeset
|
625 else if (transferSyntax_ == DicomTransferSyntax_LittleEndianExplicit || |
e95caa87fed8
only store PixelDataVR metadata if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5316
diff
changeset
|
626 transferSyntax_ == DicomTransferSyntax_BigEndianExplicit) |
e95caa87fed8
only store PixelDataVR metadata if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5316
diff
changeset
|
627 { |
e95caa87fed8
only store PixelDataVR metadata if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5316
diff
changeset
|
628 pixelDataVR_ = vr; |
e95caa87fed8
only store PixelDataVR metadata if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5316
diff
changeset
|
629 } |
e95caa87fed8
only store PixelDataVR metadata if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5316
diff
changeset
|
630 else |
e95caa87fed8
only store PixelDataVR metadata if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5316
diff
changeset
|
631 { |
e95caa87fed8
only store PixelDataVR metadata if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5316
diff
changeset
|
632 // Compressed transfer syntaxes must always be OB |
e95caa87fed8
only store PixelDataVR metadata if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5316
diff
changeset
|
633 pixelDataVR_ = ValueRepresentation_OtherByte; |
e95caa87fed8
only store PixelDataVR metadata if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5316
diff
changeset
|
634 } |
4493
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
635 } |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
636 |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
637 // Stop processing once pixel data has been passed |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
638 return (tag < DICOM_TAG_PIXEL_DATA); |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
639 } |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
640 |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
641 bool HasPixelData() const |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
642 { |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
643 return hasPixelData_; |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
644 } |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
645 |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
646 uint64_t GetPixelDataOffset() const |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
647 { |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
648 return pixelDataOffset_; |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
649 } |
4494
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
650 |
5316
03501a258d9e
added instance metadata "PixelDataVR"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
651 ValueRepresentation GetPixelDataVR() const |
03501a258d9e
added instance metadata "PixelDataVR"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
652 { |
03501a258d9e
added instance metadata "PixelDataVR"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
653 return pixelDataVR_; |
03501a258d9e
added instance metadata "PixelDataVR"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
654 } |
03501a258d9e
added instance metadata "PixelDataVR"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
655 |
4494
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
656 static bool LookupPixelDataOffset(uint64_t& offset, |
5316
03501a258d9e
added instance metadata "PixelDataVR"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
657 ValueRepresentation& vr, |
4494
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
658 std::istream& stream) |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
659 { |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
660 PixelDataVisitor visitor; |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
661 bool isLittleEndian; |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
662 |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
663 { |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
664 DicomStreamReader reader(stream); |
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 try |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
667 { |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
668 reader.Consume(visitor); |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
669 isLittleEndian = reader.IsLittleEndian(); |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
670 } |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
671 catch (OrthancException& e) |
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 // Invalid DICOM file |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
674 return false; |
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 } |
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 if (visitor.HasPixelData()) |
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 // 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
|
681 // 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
|
682 // position in the stream |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
683 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
|
684 |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
685 std::string s; |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
686 s.resize(4); |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
687 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
|
688 |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
689 if (!isLittleEndian) |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
690 { |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
691 // 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
|
692 // 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
|
693 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
|
694 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
|
695 } |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
696 |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
697 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
|
698 s[0] == char(0xe0) && |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
699 s[1] == char(0x7f) && |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
700 s[2] == char(0x10) && |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
701 s[3] == char(0x00)) |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
702 { |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
703 offset = visitor.GetPixelDataOffset(); |
5316
03501a258d9e
added instance metadata "PixelDataVR"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
704 vr = visitor.GetPixelDataVR(); |
4494
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
705 return true; |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
706 } |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
707 else |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
708 { |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
709 return false; |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
710 } |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
711 } |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
712 else |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
713 { |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
714 return false; |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
715 } |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
716 } |
4493
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
717 }; |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
718 |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
719 |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
720 bool DicomStreamReader::LookupPixelDataOffset(uint64_t& offset, |
5316
03501a258d9e
added instance metadata "PixelDataVR"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
721 ValueRepresentation& vr, |
4493
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
722 const std::string& dicom) |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
723 { |
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
724 std::stringstream stream(dicom); |
5316
03501a258d9e
added instance metadata "PixelDataVR"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
725 return PixelDataVisitor::LookupPixelDataOffset(offset, vr, stream); |
4494
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
726 } |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
727 |
4493
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
728 |
4494
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
729 bool DicomStreamReader::LookupPixelDataOffset(uint64_t& offset, |
5316
03501a258d9e
added instance metadata "PixelDataVR"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
730 ValueRepresentation& vr, |
4494
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
731 const void* buffer, |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
732 size_t size) |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
733 { |
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
734 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
|
735 boost::iostreams::stream<boost::iostreams::array_source> stream(source); |
5316
03501a258d9e
added instance metadata "PixelDataVR"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
736 return PixelDataVisitor::LookupPixelDataOffset(offset, vr, stream); |
4493
b57ca702a430
DicomStreamReader::LookupPixelDataOffset()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
737 } |
4220
92a21efa5c96
reorganization of DicomStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
738 } |
4494
39192eb9b43d
New metadata automatically computed at the instance level: "PixelDataOffset"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4493
diff
changeset
|
739 |