mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-17 02:34:44 +03:00
Added fill decoder
This commit is contained in:
parent
b3bc4a7bb4
commit
290a662793
BIN
Tests/images/input_bw_fill.fpx
Normal file
BIN
Tests/images/input_bw_fill.fpx
Normal file
Binary file not shown.
|
@ -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"
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in New Issue
Block a user