mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-11-04 01:47:47 +03:00 
			
		
		
		
	Removed unused import and restored existing checks (#1)
* Removed unused import * Restored existing checks * Restored coerce_e, _E and data property * Deprecated coerce_e Co-authored-by: Andrew Murray <radarhere@users.noreply.github.com>
This commit is contained in:
		
							parent
							
								
									4e12ccc63e
								
							
						
					
					
						commit
						46802d5def
					
				| 
						 | 
				
			
			@ -1,5 +1,7 @@
 | 
			
		|||
import pytest
 | 
			
		||||
 | 
			
		||||
from PIL import Image
 | 
			
		||||
 | 
			
		||||
from .helper import assert_image_equal, hopper
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -17,6 +19,7 @@ def test_sanity():
 | 
			
		|||
        im.point(list(range(256)))
 | 
			
		||||
    im.point(lambda x: x * 1)
 | 
			
		||||
    im.point(lambda x: x + 1)
 | 
			
		||||
    im.point(lambda x: x - 1)
 | 
			
		||||
    im.point(lambda x: x * 1 + 1)
 | 
			
		||||
    im.point(lambda x: 0.1 + 0.2 * x)
 | 
			
		||||
    im.point(lambda x: -x)
 | 
			
		||||
| 
						 | 
				
			
			@ -24,6 +27,7 @@ def test_sanity():
 | 
			
		|||
    im.point(lambda x: 1 - x / 2)
 | 
			
		||||
    im.point(lambda x: (2 + x) / 3)
 | 
			
		||||
    im.point(lambda x: 0.5)
 | 
			
		||||
    im.point(lambda x: x / 1)
 | 
			
		||||
    with pytest.raises(TypeError):
 | 
			
		||||
        im.point(lambda x: x * x)
 | 
			
		||||
    with pytest.raises(TypeError):
 | 
			
		||||
| 
						 | 
				
			
			@ -55,3 +59,8 @@ def test_f_mode():
 | 
			
		|||
    im = hopper("F")
 | 
			
		||||
    with pytest.raises(ValueError):
 | 
			
		||||
        im.point(None)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_coerce_e_deprecation():
 | 
			
		||||
    with pytest.warns(DeprecationWarning):
 | 
			
		||||
        assert Image.coerce_e(2).data == 2
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -29,7 +29,6 @@ import builtins
 | 
			
		|||
import io
 | 
			
		||||
import logging
 | 
			
		||||
import math
 | 
			
		||||
import numbers
 | 
			
		||||
import os
 | 
			
		||||
import re
 | 
			
		||||
import struct
 | 
			
		||||
| 
						 | 
				
			
			@ -431,19 +430,23 @@ def _getencoder(mode, encoder_name, args, extra=()):
 | 
			
		|||
# Simple expression analyzer
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# _Affine(m, b) represents the polynomial m x + b
 | 
			
		||||
class _Affine:
 | 
			
		||||
    def __init__(self, m, b):
 | 
			
		||||
        self.m = m
 | 
			
		||||
        self.b = b
 | 
			
		||||
def coerce_e(value):
 | 
			
		||||
    deprecate("coerce_e", 10)
 | 
			
		||||
    return value if isinstance(value, _E) else _E(1, value)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class _E:
 | 
			
		||||
    def __init__(self, scale, data):
 | 
			
		||||
        self.scale = scale
 | 
			
		||||
        self.data = data
 | 
			
		||||
 | 
			
		||||
    def __neg__(self):
 | 
			
		||||
        return _Affine(-self.m, -self.b)
 | 
			
		||||
        return _E(-self.scale, -self.data)
 | 
			
		||||
 | 
			
		||||
    def __add__(self, other):
 | 
			
		||||
        if isinstance(other, _Affine):
 | 
			
		||||
            return _Affine(self.m + other.m, self.b + other.b)
 | 
			
		||||
        return _Affine(self.m, self.b + other)
 | 
			
		||||
        if isinstance(other, _E):
 | 
			
		||||
            return _E(self.scale + other.scale, self.data + other.data)
 | 
			
		||||
        return _E(self.scale, self.data + other)
 | 
			
		||||
 | 
			
		||||
    __radd__ = __add__
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -454,21 +457,21 @@ class _Affine:
 | 
			
		|||
        return other + -self
 | 
			
		||||
 | 
			
		||||
    def __mul__(self, other):
 | 
			
		||||
        if isinstance(other, _Affine):
 | 
			
		||||
        if isinstance(other, _E):
 | 
			
		||||
            return NotImplemented
 | 
			
		||||
        return _Affine(self.m * other, self.b * other)
 | 
			
		||||
        return _E(self.scale * other, self.data * other)
 | 
			
		||||
 | 
			
		||||
    __rmul__ = __mul__
 | 
			
		||||
 | 
			
		||||
    def __truediv__(self, other):
 | 
			
		||||
        if isinstance(other, _Affine):
 | 
			
		||||
        if isinstance(other, _E):
 | 
			
		||||
            return NotImplemented
 | 
			
		||||
        return _Affine(self.m / other, self.b / other)
 | 
			
		||||
        return _E(self.scale / other, self.data / other)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def _getscaleoffset(expr):
 | 
			
		||||
    a = expr(_Affine(1.0, 0.0))
 | 
			
		||||
    return (a.m, a.b) if isinstance(a, _Affine) else (0.0, a)
 | 
			
		||||
    a = expr(_E(1, 0))
 | 
			
		||||
    return (a.scale, a.data) if isinstance(a, _E) else (0, a)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# --------------------------------------------------------------------
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user