annotate OrthancFramework/Sources/DicomFormat/DicomStreamReader.cpp @ 5342:65d55cc86a41

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