Skip to content

Commit 77238e0

Browse files
authored
MAINT: Change inline image comments (#3288)
For RunLengthDecode, a length value of 128 shall denote EOD.
1 parent d59164b commit 77238e0

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

pypdf/generic/_image_inline.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,18 @@
3939

4040
logger = logging.getLogger(__name__)
4141

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.
4244
BUFFER_SIZE = 8192
4345

4446

4547
def extract_inline_AHx(stream: StreamType) -> bytes:
4648
"""
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.
4951
"""
5052
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.
5354
while True:
5455
data_buffered = read_non_whitespace(stream) + stream.read(BUFFER_SIZE)
5556
if not data_buffered:
@@ -86,12 +87,11 @@ def extract_inline_AHx(stream: StreamType) -> bytes:
8687

8788
def extract_inline_A85(stream: StreamType) -> bytes:
8889
"""
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.
9192
"""
9293
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 ~>
9595
while True:
9696
data_buffered = read_non_whitespace(stream) + stream.read(BUFFER_SIZE)
9797
if not data_buffered:
@@ -119,12 +119,11 @@ def extract_inline_A85(stream: StreamType) -> bytes:
119119

120120
def extract_inline_RL(stream: StreamType) -> bytes:
121121
"""
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.
124124
"""
125125
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
128127
while True:
129128
data_buffered = stream.read(BUFFER_SIZE)
130129
if not data_buffered:
@@ -146,12 +145,12 @@ def extract_inline_RL(stream: StreamType) -> bytes:
146145

147146
def extract_inline_DCT(stream: StreamType) -> bytes:
148147
"""
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.
151150
"""
152151
data_out: bytes = b""
153152
# 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
155154
notfirst = False
156155
while True:
157156
c = stream.read(1)
@@ -196,15 +195,15 @@ def extract_inline_default(stream: StreamType) -> bytes:
196195
raise PdfReadError("Unexpected end of stream")
197196
pos_ei = data_buffered.find(
198197
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
200199

201200
if pos_ei == -1:
202201
stream_out.write(data_buffered)
203202
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)
205204
stream_out.write(data_buffered[0 : pos_ei + 1])
206205
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
208207
stream.seek(pos_ei + 1 - len(data_buffered), 1)
209208
saved_pos = stream.tell()
210209
# Check for End Image

0 commit comments

Comments
 (0)