39
39
40
40
logger = logging .getLogger (__name__ )
41
41
42
+ # An inline image should be used only for small images (4096 bytes or less),
43
+ # but allow twice this for cases where this has been exceeded.
42
44
BUFFER_SIZE = 8192
43
45
44
46
45
47
def extract_inline_AHx (stream : StreamType ) -> bytes :
46
48
"""
47
- Extract HexEncoded Stream from Inline Image .
48
- the stream will be moved onto the EI
49
+ Extract HexEncoded stream from inline image .
50
+ The stream will be moved onto the EI.
49
51
"""
50
52
data_out : bytes = b""
51
- # Read data until delimiter > and EI as backup
52
- # ignoring backup.
53
+ # Read data until delimiter > and EI as backup.
53
54
while True :
54
55
data_buffered = read_non_whitespace (stream ) + stream .read (BUFFER_SIZE )
55
56
if not data_buffered :
@@ -86,12 +87,11 @@ def extract_inline_AHx(stream: StreamType) -> bytes:
86
87
87
88
def extract_inline_A85 (stream : StreamType ) -> bytes :
88
89
"""
89
- Extract A85 Stream from Inline Image .
90
- the stream will be moved onto the EI
90
+ Extract A85 stream from inline image .
91
+ The stream will be moved onto the EI.
91
92
"""
92
93
data_out : bytes = b""
93
- # Read data up to delimiter ~>
94
- # see §3.3.2 from PDF ref 1.7
94
+ # Read data until delimiter ~>
95
95
while True :
96
96
data_buffered = read_non_whitespace (stream ) + stream .read (BUFFER_SIZE )
97
97
if not data_buffered :
@@ -119,12 +119,11 @@ def extract_inline_A85(stream: StreamType) -> bytes:
119
119
120
120
def extract_inline_RL (stream : StreamType ) -> bytes :
121
121
"""
122
- Extract RL (RunLengthDecode) Stream from Inline Image .
123
- The stream will be moved onto the EI
122
+ Extract RL (RunLengthDecode) stream from inline image .
123
+ The stream will be moved onto the EI.
124
124
"""
125
125
data_out : bytes = b""
126
- # Read data up to delimiter ~>
127
- # see §3.3.4 from PDF ref 1.7
126
+ # Read data until delimiter 128
128
127
while True :
129
128
data_buffered = stream .read (BUFFER_SIZE )
130
129
if not data_buffered :
@@ -146,12 +145,12 @@ def extract_inline_RL(stream: StreamType) -> bytes:
146
145
147
146
def extract_inline_DCT (stream : StreamType ) -> bytes :
148
147
"""
149
- Extract DCT (JPEG) Stream from Inline Image .
150
- The stream will be moved onto the EI
148
+ Extract DCT (JPEG) stream from inline image .
149
+ The stream will be moved onto the EI.
151
150
"""
152
151
data_out : bytes = b""
153
152
# Read Blocks of data (ID/Size/data) up to ID=FF/D9
154
- # see https://www.digicamsoft.com/itu/itu-t81-36.html
153
+ # https://www.digicamsoft.com/itu/itu-t81-36.html
155
154
notfirst = False
156
155
while True :
157
156
c = stream .read (1 )
@@ -196,15 +195,15 @@ def extract_inline_default(stream: StreamType) -> bytes:
196
195
raise PdfReadError ("Unexpected end of stream" )
197
196
pos_ei = data_buffered .find (
198
197
b"E"
199
- ) # we can not look straight for "EI" because it may not have been loaded in the buffer
198
+ ) # We can not look straight for "EI" because it may not have been loaded in the buffer
200
199
201
200
if pos_ei == - 1 :
202
201
stream_out .write (data_buffered )
203
202
else :
204
- # Write out everything including E (the one from EI to be removed).
203
+ # Write out everything including E (the one from EI to be removed)
205
204
stream_out .write (data_buffered [0 : pos_ei + 1 ])
206
205
sav_pos_ei = stream_out .tell () - 1
207
- # Seek back in the stream to read the E next.
206
+ # Seek back in the stream to read the E next
208
207
stream .seek (pos_ei + 1 - len (data_buffered ), 1 )
209
208
saved_pos = stream .tell ()
210
209
# Check for End Image
0 commit comments