def _d_cb(cb): """Returns D(Cb) - Cb""" cb = float(cb) / 255 if cb <= .25: d = ((16 * cb - 12) * cb + 4) * cb else: d = math.sqrt(cb) return round((d - cb) * 255) LUT_1_2_x_cs = [util.clip(255 - 2 * i) for i in range(256)] LUT_cb_x_1_cb = [round(util.clip(i * (1 - i / 255))) for i in range(256)] LUT_2_x_cs_1 = [util.clip(2 * i - 255) for i in range(256)] LUT_d_cb = [_d_cb(i) for i in range(256)] def _soft_light(im1, im2): """The soft light blend mode. Arguments: im1: A backdrop image (RGB). im2: A source image (RGB). Returns: The output image. """
def test_clip_min_minus_1000(): assert util.clip(-1000, a_min=-1000) == -1000 assert util.clip(-1001, a_min=-1000) == -1000
def test_clip_max_1000(): assert util.clip(1000, a_max=1000) == 1000 assert util.clip(1001, a_max=1000) == 1000
def test_clip_256(): assert util.clip(256) == 255
def test_clip_255(): assert util.clip(255) == 255
def test_clip_0(): assert util.clip(0) == 0
def test_clip_minus_1(): assert util.clip(-1) == 0
# # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import numpy as np from PIL import Image, ImageChops from pilgram.css.blending.alpha import alpha_blend from pilgram import util LUT_2x = [util.clip(2 * i) for i in range(256)] LUT_2x_1 = [util.clip(2 * i - 255) for i in range(256)] def _hard_light(im1, im2): """The hard light blend mode. Arguments: im1: A backdrop image (RGB). im2: A source image (RGB). Returns: The output image. """ im2_multiply = util.apply_lut(im2, LUT_2x)