diff --git a/Tests/images/input_bw_fill.fpx b/Tests/images/input_bw_fill.fpx new file mode 100644 index 000000000..440ef444e Binary files /dev/null and b/Tests/images/input_bw_fill.fpx differ diff --git a/Tests/test_file_fpx.py b/Tests/test_file_fpx.py index fa22e90f6..45880d618 100644 --- a/Tests/test_file_fpx.py +++ b/Tests/test_file_fpx.py @@ -2,7 +2,7 @@ import pytest from PIL import Image -from .helper import assert_image_equal_tofile +from .helper import assert_image_equal, assert_image_equal_tofile FpxImagePlugin = pytest.importorskip( "PIL.FpxImagePlugin", reason="olefile not installed" @@ -18,6 +18,20 @@ def test_sanity(): assert_image_equal_tofile(im, "Tests/images/input_bw_one_band.png") +def test_fill(): + with Image.open("Tests/images/input_bw_fill.fpx") as im: + # The first tile has been hexedited to fill with white + compression, (x, y, x1, y1) = im.tile[0][:2] + assert compression == "fpx_fill" + assert (x, y, x1, y1) == (0, 0, 64, 46) + + with Image.open("Tests/images/input_bw_one_band.png") as im2: + for x in range(x1): + for y in range(y1): + im2.putpixel((x, y), 255) + assert_image_equal(im, im2) + + def test_invalid_file(): # Test an invalid OLE file invalid_file = "Tests/images/flower.jpg" diff --git a/src/PIL/FpxImagePlugin.py b/src/PIL/FpxImagePlugin.py index a55376d0e..884392d41 100644 --- a/src/PIL/FpxImagePlugin.py +++ b/src/PIL/FpxImagePlugin.py @@ -171,10 +171,9 @@ class FpxImageFile(ImageFile.ImageFile): elif compression == 1: - # FIXME: the fill decoder is not implemented self.tile.append( ( - "fill", + "fpx_fill", (x, y, x1, y1), i32(s, i) + 28, (self.rawmode, s[12:16]), @@ -236,10 +235,23 @@ class FpxImageFile(ImageFile.ImageFile): return ImageFile.ImageFile.load(self) +class FpxFillDecoder(ImageFile.PyDecoder): + _pulls_fd = True + + def decode(self, buffer): + rawmode, color = self.args + bands = Image.getmodebands(rawmode) + data = color[:bands] * self.state.xsize * self.state.ysize + self.set_as_raw(data, rawmode) + return -1, 0 + + # # -------------------------------------------------------------------- Image.register_open(FpxImageFile.format, FpxImageFile, _accept) +Image.register_decoder("fpx_fill", FpxFillDecoder) + Image.register_extension(FpxImageFile.format, ".fpx")