MCPcopy Index your code
hub / github.com/clips/pattern / decode

Method decode

pattern/web/pdf/pdftypes.py:196–252  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

194 return [ filters ]
195
196 def decode(self):
197 assert self.data is None and self.rawdata != None
198 data = self.rawdata
199 if self.decipher:
200 # Handle encryption
201 data = self.decipher(self.objid, self.genno, data)
202 filters = self.get_filters()
203 if not filters:
204 self.data = data
205 self.rawdata = None
206 return
207 for f in filters:
208 if f in LITERALS_FLATE_DECODE:
209 # will get errors if the document is encrypted.
210 try:
211 data = zlib.decompress(data)
212 except zlib.error, e:
213 if STRICT:
214 raise PDFException('Invalid zlib bytes: %r, %r' % (e, data))
215 data = ''
216 elif f in LITERALS_LZW_DECODE:
217 data = lzwdecode(data)
218 elif f in LITERALS_ASCII85_DECODE:
219 data = ascii85decode(data)
220 elif f in LITERALS_ASCIIHEX_DECODE:
221 data = asciihexdecode(data)
222 elif f in LITERALS_RUNLENGTH_DECODE:
223 data = rldecode(data)
224 elif f in LITERALS_CCITTFAX_DECODE:
225 #data = ccittfaxdecode(data)
226 raise PDFNotImplementedError('Unsupported filter: %r' % f)
227 elif f == LITERAL_CRYPT:
228 # not yet..
229 raise PDFNotImplementedError('/Crypt filter is unsupported')
230 else:
231 raise PDFNotImplementedError('Unsupported filter: %r' % f)
232 # apply predictors
233 params = self.get_any(('DP', 'DecodeParms', 'FDecodeParms'), {})
234 if 'Predictor' in params and 'Columns' in params:
235 pred = int_value(params['Predictor'])
236 columns = int_value(params['Columns'])
237 if pred:
238 if pred != 12:
239 raise PDFNotImplementedError('Unsupported predictor: %r' % pred)
240 buf = ''
241 ent0 = '\x00' * columns
242 for i in xrange(0, len(data), columns+1):
243 pred = data[i]
244 ent1 = data[i+1:i+1+columns]
245 if pred == '\x02':
246 ent1 = ''.join( chr((ord(a)+ord(b)) & 255) for (a,b) in zip(ent0,ent1) )
247 buf += ent1
248 ent0 = ent1
249 data = buf
250 self.data = data
251 self.rawdata = None
252 return
253

Callers 1

get_dataMethod · 0.95

Calls 11

get_filtersMethod · 0.95
get_anyMethod · 0.95
lzwdecodeFunction · 0.90
ascii85decodeFunction · 0.90
asciihexdecodeFunction · 0.90
rldecodeFunction · 0.90
PDFExceptionClass · 0.85
int_valueFunction · 0.85
lenFunction · 0.85
zipFunction · 0.85

Tested by

no test coverage detected