def test_FlateDecode(predictor, s): """ Tests FlateDecode decode() and encode() methods. """ codec = FlateDecode() s = s.encode() encoded = codec.encode(s) assert codec.decode(encoded, {"/Predictor": predictor}) == s
def test_FlateDecode_unsupported_predictor(): """ Inputs an unsupported predictor (outside the [10, 15] range) checking that PdfReadError() is raised. Once this predictor support is updated in the future, this test case may be removed. """ codec = FlateDecode() predictors = (-10, -1, 0, 9, 16, 20, 100) for predictor, s in cartesian_product(predictors, filter_inputs): s = s.encode() with pytest.raises(PdfReadError): codec.decode(codec.encode(s), {"/Predictor": predictor})
def __init__(self, im): super().__init__() try: depth, colorspace = MODE_TO_COLORSPACE[im.mode] except KeyError: raise NotImplementedError('image mode %r not supported' % im.mode) w, h = im.size # always compress raw image data self._data = FlateDecode.encode(im.tobytes()) self[NameObject("/Filter")] = NameObject('/FlateDecode') self[NameObject('/Type')] = NameObject('/XObject') self[NameObject('/Subtype')] = NameObject('/Image') self[NameObject('/Width')] = NumberObject(w) self[NameObject('/Height')] = NumberObject(h) self[NameObject('/BitsPerComponent')] = NumberObject(depth) self[NameObject('/ColorSpace')] = NameObject(colorspace)
def test_FlateDecode_decompress_array_params(params): codec = FlateDecode() s = "" s = s.encode() encoded = codec.encode(s) assert codec.decode(encoded, params) == s