Coverage for /pythoncovmergedfiles/medio/medio/src/pdfminer.six/pdfminer/runlength.py: 6%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1#
2# RunLength decoder (Adobe version) implementation based on PDF Reference
3# version 1.4 section 3.3.4.
4#
5# * public domain *
6#
9def rldecode(data: bytes) -> bytes:
10 """RunLength decoder (Adobe version) implementation based on PDF Reference
11 version 1.4 section 3.3.4:
12 The RunLengthDecode filter decodes data that has been encoded in a
13 simple byte-oriented format based on run length. The encoded data
14 is a sequence of runs, where each run consists of a length byte
15 followed by 1 to 128 bytes of data. If the length byte is in the
16 range 0 to 127, the following length + 1 (1 to 128) bytes are
17 copied literally during decompression. If length is in the range
18 129 to 255, the following single byte is to be copied 257 - length
19 (2 to 128) times during decompression. A length value of 128
20 denotes EOD.
21 """
22 decoded = b""
23 i = 0
24 while i < len(data):
25 length = data[i]
26 if length == 128:
27 break
29 if length >= 0 and length < 128:
30 for j in range(i + 1, (i + 1) + (length + 1)):
31 decoded += bytes((data[j],))
32 i = (i + 1) + (length + 1)
34 if length > 128:
35 run = bytes((data[i + 1],)) * (257 - length)
36 decoded += run
37 i = (i + 1) + 1
39 return decoded