/src/dcmtk/dcmdata/libsrc/dcistrma.cc
Line | Count | Source |
1 | | /* |
2 | | * |
3 | | * Copyright (C) 1994-2026, OFFIS e.V. |
4 | | * All rights reserved. See COPYRIGHT file for details. |
5 | | * |
6 | | * This software and supporting documentation were developed by |
7 | | * |
8 | | * OFFIS e.V. |
9 | | * R&D Division Health |
10 | | * Escherweg 2 |
11 | | * D-26121 Oldenburg, Germany |
12 | | * |
13 | | * |
14 | | * Module: dcmdata |
15 | | * |
16 | | * Author: Marco Eichelberg |
17 | | * |
18 | | * Purpose: base classes for input streams |
19 | | * |
20 | | */ |
21 | | |
22 | | #include "dcmtk/config/osconfig.h" |
23 | | #include "dcmtk/dcmdata/dcistrma.h" |
24 | | #include "dcmtk/dcmdata/dcistrmz.h" /* for DcmZLibInputFilter */ |
25 | | #include "dcmtk/dcmdata/dcerror.h" /* for EC_IllegalCall */ |
26 | | |
27 | | DcmInputStream::DcmInputStream(DcmProducer *initial) |
28 | 3.35k | : current_(initial) |
29 | 3.35k | , compressionFilter_(NULL) |
30 | 3.35k | , tell_(0) |
31 | 3.35k | , mark_(0) |
32 | 3.35k | , nestingDepth_(0) |
33 | 3.35k | , maxNestingDepth_(0) |
34 | 3.35k | { |
35 | 3.35k | } |
36 | | |
37 | | DcmInputStream::~DcmInputStream() |
38 | 3.35k | { |
39 | | // we cannot access the stream anymore at this point because the |
40 | | // producer has most probably already been deleted. |
41 | 3.35k | delete compressionFilter_; |
42 | 3.35k | } |
43 | | |
44 | | OFBool DcmInputStream::good() const |
45 | 57.8k | { |
46 | 57.8k | return current_->good(); |
47 | 57.8k | } |
48 | | |
49 | | OFCondition DcmInputStream::status() const |
50 | 82.9k | { |
51 | 82.9k | return current_->status(); |
52 | 82.9k | } |
53 | | |
54 | | OFBool DcmInputStream::eos() |
55 | 147k | { |
56 | 147k | return current_->eos(); |
57 | 147k | } |
58 | | |
59 | | offile_off_t DcmInputStream::avail() |
60 | 116k | { |
61 | 116k | return current_->avail(); |
62 | 116k | } |
63 | | |
64 | | offile_off_t DcmInputStream::read(void *buf, offile_off_t buflen) |
65 | 219k | { |
66 | 219k | offile_off_t result = current_->read(buf, buflen); |
67 | 219k | tell_ += result; |
68 | 219k | return result; |
69 | 219k | } |
70 | | |
71 | | offile_off_t DcmInputStream::skip(offile_off_t skiplen) |
72 | 3.35k | { |
73 | 3.35k | offile_off_t result = current_->skip(skiplen); |
74 | 3.35k | tell_ += result; |
75 | 3.35k | return result; |
76 | 3.35k | } |
77 | | |
78 | | offile_off_t DcmInputStream::tell() const |
79 | 77.4k | { |
80 | 77.4k | return tell_; |
81 | 77.4k | } |
82 | | |
83 | | void DcmInputStream::mark() |
84 | 69.4k | { |
85 | 69.4k | mark_ = tell_; |
86 | 69.4k | } |
87 | | |
88 | | void DcmInputStream::putback() |
89 | 13.8k | { |
90 | 13.8k | current_->putback(tell_ - mark_); |
91 | 13.8k | tell_ = mark_; |
92 | 13.8k | } |
93 | | |
94 | | const DcmProducer *DcmInputStream::currentProducer() const |
95 | 0 | { |
96 | 0 | return current_; |
97 | 0 | } |
98 | | |
99 | | Uint32 DcmInputStream::nestingDepth() const |
100 | 0 | { |
101 | 0 | return nestingDepth_; |
102 | 0 | } |
103 | | |
104 | | Uint32 DcmInputStream::incrementNestingDepth() |
105 | 4.21k | { |
106 | 4.21k | return ++nestingDepth_; |
107 | 4.21k | } |
108 | | |
109 | | void DcmInputStream::decrementNestingDepth() |
110 | 4.21k | { |
111 | 4.21k | if (nestingDepth_ > 0) |
112 | 4.21k | --nestingDepth_; |
113 | 4.21k | } |
114 | | |
115 | | Sint32 DcmInputStream::maxNestingDepth() const |
116 | 4.21k | { |
117 | 4.21k | return maxNestingDepth_; |
118 | 4.21k | } |
119 | | |
120 | | void DcmInputStream::setMaxNestingDepth(Sint32 maxDepth) |
121 | 0 | { |
122 | 0 | maxNestingDepth_ = maxDepth; |
123 | 0 | } |
124 | | |
125 | | OFCondition DcmInputStream::installCompressionFilter(E_StreamCompression filterType) |
126 | 129 | { |
127 | 129 | OFCondition result = EC_Normal; |
128 | 129 | if (compressionFilter_) result = EC_DoubleCompressionFilters; |
129 | 129 | else |
130 | 129 | { |
131 | 129 | switch (filterType) |
132 | 129 | { |
133 | 0 | #ifdef WITH_ZLIB |
134 | 129 | case ESC_zlib: |
135 | 129 | compressionFilter_ = new DcmZLibInputFilter(); |
136 | 129 | if (compressionFilter_) |
137 | 129 | { |
138 | 129 | compressionFilter_->append(*current_); |
139 | | // feed the compression engine with data from the producer |
140 | 129 | compressionFilter_->skip(0); |
141 | 129 | current_ = compressionFilter_; |
142 | 129 | } else result = EC_MemoryExhausted; |
143 | 129 | break; |
144 | 0 | #endif |
145 | 0 | case ESC_none: |
146 | 0 | case ESC_unsupported: |
147 | 0 | result = EC_UnsupportedEncoding; |
148 | 0 | break; |
149 | 129 | } |
150 | 129 | } |
151 | | |
152 | 129 | return result; |
153 | 129 | } |