mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 01:46:18 +03:00
Fixed generated palettes
This commit is contained in:
parent
d0a30ec369
commit
a9372d5cf0
BIN
Tests/images/palette_negative.png
Normal file
BIN
Tests/images/palette_negative.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 17 KiB |
BIN
Tests/images/palette_sepia.png
Normal file
BIN
Tests/images/palette_sepia.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 20 KiB |
BIN
Tests/images/palette_wedge.png
Normal file
BIN
Tests/images/palette_wedge.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 17 KiB |
|
@ -2,7 +2,7 @@ import pytest
|
|||
|
||||
from PIL import Image, ImagePalette
|
||||
|
||||
from .helper import assert_image_equal, hopper
|
||||
from .helper import assert_image_equal, assert_image_equal_tofile, hopper
|
||||
|
||||
|
||||
def test_putpalette():
|
||||
|
@ -36,9 +36,15 @@ def test_putpalette():
|
|||
def test_imagepalette():
|
||||
im = hopper("P")
|
||||
im.putpalette(ImagePalette.negative())
|
||||
assert_image_equal_tofile(im.convert("RGB"), "Tests/images/palette_negative.png")
|
||||
|
||||
im.putpalette(ImagePalette.random())
|
||||
|
||||
im.putpalette(ImagePalette.sepia())
|
||||
assert_image_equal_tofile(im.convert("RGB"), "Tests/images/palette_sepia.png")
|
||||
|
||||
im.putpalette(ImagePalette.wedge())
|
||||
assert_image_equal_tofile(im.convert("RGB"), "Tests/images/palette_wedge.png")
|
||||
|
||||
|
||||
def test_putpalette_with_alpha_values():
|
||||
|
|
|
@ -204,9 +204,9 @@ def make_gamma_lut(exp):
|
|||
|
||||
|
||||
def negative(mode="RGB"):
|
||||
palette = list(range(256))
|
||||
palette = list(range(256 * len(mode)))
|
||||
palette.reverse()
|
||||
return ImagePalette(mode, palette * len(mode))
|
||||
return ImagePalette(mode, [i // len(mode) for i in palette])
|
||||
|
||||
|
||||
def random(mode="RGB"):
|
||||
|
@ -219,15 +219,13 @@ def random(mode="RGB"):
|
|||
|
||||
|
||||
def sepia(white="#fff0c0"):
|
||||
r, g, b = ImageColor.getrgb(white)
|
||||
r = make_linear_lut(0, r)
|
||||
g = make_linear_lut(0, g)
|
||||
b = make_linear_lut(0, b)
|
||||
return ImagePalette("RGB", r + g + b)
|
||||
bands = [make_linear_lut(0, band) for band in ImageColor.getrgb(white)]
|
||||
return ImagePalette("RGB", [bands[i % 3][i // 3] for i in range(256 * 3)])
|
||||
|
||||
|
||||
def wedge(mode="RGB"):
|
||||
return ImagePalette(mode, list(range(256)) * len(mode))
|
||||
palette = list(range(256 * len(mode)))
|
||||
return ImagePalette(mode, [i // len(mode) for i in palette])
|
||||
|
||||
|
||||
def load(filename):
|
||||
|
|
Loading…
Reference in New Issue
Block a user