Skip to content

Commit 74eeb6a

Browse files
committed
rel 2025
1 parent ab2b35c commit 74eeb6a

File tree

5 files changed

+119
-118
lines changed

5 files changed

+119
-118
lines changed

.github/workflows/test-lint.yaml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ jobs:
2020
- '3.10'
2121
- '3.11'
2222
- '3.12'
23+
- '3.13'
2324

2425
steps:
2526
- name: Checkout code
@@ -30,16 +31,16 @@ jobs:
3031
with:
3132
python-version: ${{ matrix.python-version }}
3233

33-
- name: Install Poetry
34+
- name: Install UV
3435
run: |
35-
curl -sSL https://install.python-poetry.org | python3 -
36+
curl -LsSf https://astral.sh/uv/install.sh | sh
3637
3738
- name: Install dependencies
38-
run: poetry install
39+
run: uv sync
3940

4041
- name: Run pytest
41-
run: poetry run pytest
42+
run: uv run pytest
4243

4344
- name: Run ruff
44-
run: poetry run ruff check --output-format=github
45+
run: uv run ruff check --output-format=github
4546
continue-on-error: true

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
All major and minor version changes will be documented in this file. Details of
44
patch-level version changes can be found in [commit messages](../../commits/master).
55

6+
## 2025 - 2025/02/20
7+
8+
- optimise `_setLum` and `_setSat` functions
9+
- use uv instead of poetry
10+
611
## 2024.1.1 - 2024/03/17
712

813
- suppress warnings

blendmodes/blend.py

Lines changed: 48 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ def _setSat(originalColours: np.ndarray, newSaturation: np.ndarray) -> np.ndarra
239239
) / rangeColours[nonzeroMask]
240240
maxColours[nonzeroMask] = newSaturation[nonzeroMask]
241241

242-
# Zero out mid and max when rangeColours == 0
242+
# Zero out mid and max when rangeColours is 0
243243
midColours[~nonzeroMask] = 0
244244
maxColours[~nonzeroMask] = 0
245245

@@ -471,36 +471,30 @@ def blendLayers(
471471
opacity: float = 1.0,
472472
offsets: tuple[int, int] = (0, 0),
473473
) -> Image.Image:
474-
"""Blend two layers (background, and foreground).
475-
476-
Note if the background is smaller than the foreground then some of the foreground will be cut
477-
off
478-
479-
Args:
480-
----
481-
background (Image.Image): The background layer.
482-
foreground (Image.Image): The foreground layer (must be the same size as the background).
483-
blendType (BlendType): The blend type to be applied.
484-
opacity (float, optional): The opacity of the foreground image. Defaults to 1.0.
485-
offsets (Tuple[int, int], optional): Offsets for the foreground layer. Defaults to (0, 0).
486-
487-
Returns:
488-
-------
489-
Image.Image: The combined image.
490-
491-
Examples:
474+
"""Blend two layers (background and foreground), where the background may
475+
be cropped if smaller than the foreground.
476+
477+
:param Image.Image background: The background layer.
478+
:param Image.Image foreground: The foreground layer (must be the
479+
same size as the background).
480+
:param BlendType blendType: The blend type to be applied.
481+
:param float opacity: The opacity of the foreground image. Defaults to 1.0. (optional)
482+
:param tuple[int, int] offsets: Offsets for the foreground layer. Defaults to (0, 0). (optional)
483+
:return Image.Image: The combined image.
484+
485+
Examples
492486
--------
493-
# Blend two layers with default parameters
494-
combined_image = blendLayers(background_image, foreground_image, BlendType.NORMAL)
495-
496-
# Blend two layers with custom opacity and offsets
497-
combined_image = blendLayers(
498-
background_image,
499-
foreground_image,
500-
BlendType.MULTIPLY,
501-
opacity=0.7,
502-
offsets=(100, 50)
503-
)
487+
Blend two layers with default parameters
488+
>>> combined_image = blendLayers(background_image, foreground_image, BlendType.NORMAL)
489+
490+
Blend two layers with custom opacity and offsets
491+
>>> combined_image = blendLayers(
492+
... background_image,
493+
... foreground_image,
494+
... BlendType.MULTIPLY,
495+
... opacity=0.7,
496+
... offsets=(100, 50)
497+
...)
504498
505499
"""
506500
arr = blendLayersArray(
@@ -521,38 +515,33 @@ def blendLayersArray(
521515
opacity: float = 1.0,
522516
offsets: tuple[int, int] = (0, 0),
523517
) -> np.ndarray:
524-
"""Blend two layers (background, and foreground).
525-
526-
Note if the background is smaller than the foreground then some of the foreground will be cut
527-
off
528-
529-
Args:
530-
----
531-
background (np.ndarray | Image.Image): The background layer.
532-
foreground (np.ndarray | Image.Image): The foreground layer (must be the same size as the background).
533-
blendType (BlendType): The blend type to be applied.
534-
opacity (float, optional): The opacity of the foreground image. Defaults to 1.0.
535-
offsets (Tuple[int, int], optional): Offsets for the foreground layer. Defaults to (0, 0).
536-
537-
Returns:
538-
-------
539-
np.ndarray: The combined image.
540-
541-
Examples:
518+
"""Blend two layers (background and foreground), where the background may
519+
be cropped if smaller than the foreground.
520+
521+
:param np.ndarray | Image.Image background: The background layer.
522+
:param np.ndarray | Image.Image foreground: The foreground layer (must be the
523+
same size as the background).
524+
:param BlendType blendType: The blend type to be applied.
525+
:param float opacity: The opacity of the foreground image. Defaults to 1.0. (optional)
526+
:param tuple[int, int] offsets: Offsets for the foreground layer. Defaults to (0, 0). (optional)
527+
:return np.ndarray: The combined image.
528+
529+
Examples
542530
--------
543-
# Blend two layers with default parameters
544-
combined_image = blendLayers(background_image, foreground_image, BlendType.NORMAL)
545-
546-
# Blend two layers with custom opacity and offsets
547-
combined_image = blendLayers(
548-
background_image,
549-
foreground_image,
550-
BlendType.MULTIPLY,
551-
opacity=0.7,
552-
offsets=(100, 50)
553-
)
531+
Blend two layers with default parameters
532+
>>> combined_image = blendLayers(background_image, foreground_image, BlendType.NORMAL)
533+
534+
Blend two layers with custom opacity and offsets
535+
>>> combined_image = blendLayers(
536+
... background_image,
537+
... foreground_image,
538+
... BlendType.MULTIPLY,
539+
... opacity=0.7,
540+
... offsets=(100, 50)
541+
...)
554542
555543
"""
544+
556545
# Convert the Image.Image to a numpy array if required
557546
if isinstance(background, Image.Image):
558547
background = np.array(background.convert("RGBA"))

documentation/reference/blendmodes/blend.md

Lines changed: 57 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
- [alpha_comp_shell](#alpha_comp_shell)
1414
- [blend](#blend)
1515
- [blendLayers](#blendlayers)
16-
- [Blend two layers with custom opacity and offsets](#blend-two-layers-with-custom-opacity-and-offsets)
1716
- [blendLayersArray](#blendlayersarray)
18-
- [Blend two layers with custom opacity and offsets](#blend-two-layers-with-custom-opacity-and-offsets-1)
1917
- [colour](#colour)
2018
- [colourburn](#colourburn)
2119
- [colourdodge](#colourdodge)
@@ -136,7 +134,7 @@ def additive(background: np.ndarray, foreground: np.ndarray) -> np.ndarray: ...
136134

137135
## alpha_comp_shell
138136

139-
[Show source in blend.py:638](../../../blendmodes/blend.py#L638)
137+
[Show source in blend.py:627](../../../blendmodes/blend.py#L627)
140138

141139
Implement common transformations occurring in any blend or composite mode.
142140

@@ -211,39 +209,43 @@ def blend(
211209

212210
[Show source in blend.py:467](../../../blendmodes/blend.py#L467)
213211

214-
Blend two layers (background, and foreground).
212+
Blend two layers (background and foreground), where the background may
213+
be cropped if smaller than the foreground.
215214

216-
Note if the background is smaller than the foreground then some of the foreground will be cut
217-
off
215+
:param Image.Image background: The background layer.
216+
:param Image.Image foreground: The foreground layer (must be the
217+
same size as the background).
218218

219219
#### Arguments
220220

221-
----
222-
- `background` *Image.Image* - The background layer.
223-
- `foreground` *Image.Image* - The foreground layer (must be the same size as the background).
224-
- `blendType` *BlendType* - The blend type to be applied.
225-
- `opacity` *float, optional* - The opacity of the foreground image. Defaults to 1.0.
226-
offsets (Tuple[int, int], optional): Offsets for the foreground layer. Defaults to (0, 0).
221+
- `blendType` *BlendType* - The blend type to be applied.
222+
- `opacity` *float* - The opacity of the foreground image. Defaults to 1.0. (optional)
223+
:param tuple[int, int] offsets: Offsets for the foreground layer. Defaults to (0, 0). (optional)
227224

228225
#### Returns
229226

230-
-------
231-
- `Image.Image` - The combined image.
232-
233-
#### Examples
227+
Type: *Image.Image*
228+
The combined image.
234229

230+
Examples
235231
--------
236-
# Blend two layers with default parameters
237-
combined_image = blendLayers(background_image, foreground_image, BlendType.NORMAL)
232+
Blend two layers with default parameters
233+
234+
```python
235+
>>> combined_image = blendLayers(background_image, foreground_image, BlendType.NORMAL)
236+
```
238237

239-
# Blend two layers with custom opacity and offsets
240-
combined_image = blendLayers(
241-
background_image,
242-
foreground_image,
243-
BlendType.MULTIPLY,
244-
opacity=0.7,
245-
offsets=(100, 50)
246-
)
238+
Blend two layers with custom opacity and offsets
239+
240+
```python
241+
>>> combined_image = blendLayers(
242+
... background_image,
243+
... foreground_image,
244+
... BlendType.MULTIPLY,
245+
... opacity=0.7,
246+
... offsets=(100, 50)
247+
...)
248+
```
247249

248250
#### Signature
249251

@@ -261,41 +263,45 @@ def blendLayers(
261263

262264
## blendLayersArray
263265

264-
[Show source in blend.py:517](../../../blendmodes/blend.py#L517)
266+
[Show source in blend.py:511](../../../blendmodes/blend.py#L511)
265267

266-
Blend two layers (background, and foreground).
268+
Blend two layers (background and foreground), where the background may
269+
be cropped if smaller than the foreground.
267270

268-
Note if the background is smaller than the foreground then some of the foreground will be cut
269-
off
271+
:param np.ndarray | Image.Image background: The background layer.
272+
:param np.ndarray | Image.Image foreground: The foreground layer (must be the
273+
same size as the background).
270274

271275
#### Arguments
272276

273-
----
274-
background (np.ndarray | Image.Image): The background layer.
275-
foreground (np.ndarray | Image.Image): The foreground layer (must be the same size as the background).
276-
- `blendType` *BlendType* - The blend type to be applied.
277-
- `opacity` *float, optional* - The opacity of the foreground image. Defaults to 1.0.
278-
offsets (Tuple[int, int], optional): Offsets for the foreground layer. Defaults to (0, 0).
277+
- `blendType` *BlendType* - The blend type to be applied.
278+
- `opacity` *float* - The opacity of the foreground image. Defaults to 1.0. (optional)
279+
:param tuple[int, int] offsets: Offsets for the foreground layer. Defaults to (0, 0). (optional)
279280

280281
#### Returns
281282

282-
-------
283-
- `np.ndarray` - The combined image.
284-
285-
#### Examples
283+
Type: *np.ndarray*
284+
The combined image.
286285

286+
Examples
287287
--------
288-
# Blend two layers with default parameters
289-
combined_image = blendLayers(background_image, foreground_image, BlendType.NORMAL)
290-
291-
# Blend two layers with custom opacity and offsets
292-
combined_image = blendLayers(
293-
background_image,
294-
foreground_image,
295-
BlendType.MULTIPLY,
296-
opacity=0.7,
297-
offsets=(100, 50)
298-
)
288+
Blend two layers with default parameters
289+
290+
```python
291+
>>> combined_image = blendLayers(background_image, foreground_image, BlendType.NORMAL)
292+
```
293+
294+
Blend two layers with custom opacity and offsets
295+
296+
```python
297+
>>> combined_image = blendLayers(
298+
... background_image,
299+
... foreground_image,
300+
... BlendType.MULTIPLY,
301+
... opacity=0.7,
302+
... offsets=(100, 50)
303+
...)
304+
```
299305

300306
#### Signature
301307

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
[project]
22
name = "blendmodes"
3-
version = "2024.1.1"
3+
version = "2025"
44
description = "Use this module to apply a number of blending modes to a background and foreground image"
55
authors = [{ name = "FredHappyface" }]
6-
requires-python = ">=3.9,<4.0"
6+
requires-python = ">=3.9"
77
readme = "README.md"
88
license = "mit"
99
classifiers = [
@@ -58,7 +58,7 @@ ignore = [
5858
fixable = ["ALL"]
5959

6060
[tool.ruff.lint.per-file-ignores]
61-
"**/{tests,docs,tools}/*" = ["D", "S101", "E402"]
61+
"**/{tests,docs,tools}/*" = ["D", "S101", "E402", "S311"]
6262

6363
[tool.ruff.lint.flake8-tidy-imports]
6464
ban-relative-imports = "all" # Disallow all relative imports.

0 commit comments

Comments
 (0)