Skip to content

Commit e46fc90

Browse files
committed
0.0.8
1 parent bc1fdb0 commit e46fc90

8 files changed

Lines changed: 90 additions & 2 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# PyImageCUDA 0.0.7
1+
# PyImageCUDA 0.0.8
22

33
[![PyPI version](https://img.shields.io/pypi/v/pyimagecuda.svg)](https://pypi.org/project/pyimagecuda/)
44
[![Build Status](https://github.com/offerrall/pyimagecuda/actions/workflows/build.yml/badge.svg)](https://github.com/offerrall/pyimagecuda/actions)

‎pyimagecuda/adjust.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ def brightness(image: Image, factor: float) -> None:
1919
2020
Docs & Examples: https://offerrall.github.io/pyimagecuda/adjust/#brightness
2121
"""
22+
if abs(factor) < 1e-6:
23+
return
24+
2225
adjust_brightness_f32(
2326
image._buffer._handle,
2427
image.width,
@@ -36,6 +39,9 @@ def contrast(image: Image, factor: float) -> None:
3639
3740
Docs & Examples: https://offerrall.github.io/pyimagecuda/adjust/#contrast
3841
"""
42+
if abs(factor - 1.0) < 1e-6:
43+
return
44+
3945
adjust_contrast_f32(
4046
image._buffer._handle,
4147
image.width,
@@ -54,6 +60,9 @@ def saturation(image: Image, factor: float) -> None:
5460
5561
Docs & Examples: https://offerrall.github.io/pyimagecuda/adjust/#saturation
5662
"""
63+
if abs(factor - 1.0) < 1e-6:
64+
return
65+
5766
adjust_saturation_f32(
5867
image._buffer._handle,
5968
image.width,
@@ -75,6 +84,9 @@ def gamma(image: Image, gamma: float) -> None:
7584
"""
7685
if gamma <= 0:
7786
raise ValueError("Gamma must be positive")
87+
88+
if abs(gamma - 1.0) < 1e-6:
89+
return
7890

7991
adjust_gamma_f32(
8092
image._buffer._handle,
@@ -92,6 +104,8 @@ def opacity(image: Image, factor: float) -> None:
92104
93105
Docs & Examples: https://offerrall.github.io/pyimagecuda/adjust/#opacity
94106
"""
107+
if abs(factor - 1.0) < 1e-6:
108+
return
95109

96110
adjust_opacity_f32(
97111
image._buffer._handle,

‎pyimagecuda/blend.py‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ def normal(
4545
4646
Docs & Examples: https://offerrall.github.io/pyimagecuda/blend/#normal
4747
"""
48+
if abs(opacity) < 1e-6:
49+
return
50+
4851
pos_x, pos_y = _calculate_position(
4952
base.width, base.height,
5053
overlay.width, overlay.height,
@@ -75,6 +78,9 @@ def multiply(
7578
7679
Docs & Examples: https://offerrall.github.io/pyimagecuda/blend/#multiply
7780
"""
81+
if abs(opacity) < 1e-6:
82+
return
83+
7884
pos_x, pos_y = _calculate_position(
7985
base.width, base.height,
8086
overlay.width, overlay.height,
@@ -105,6 +111,9 @@ def screen(
105111
106112
Docs & Examples: https://offerrall.github.io/pyimagecuda/blend/#screen
107113
"""
114+
if abs(opacity) < 1e-6:
115+
return
116+
108117
pos_x, pos_y = _calculate_position(
109118
base.width, base.height,
110119
overlay.width, overlay.height,
@@ -135,6 +144,9 @@ def add(
135144
136145
Docs & Examples: https://offerrall.github.io/pyimagecuda/blend/#add
137146
"""
147+
if abs(opacity) < 1e-6:
148+
return
149+
138150
pos_x, pos_y = _calculate_position(
139151
base.width, base.height,
140152
overlay.width, overlay.height,
@@ -165,6 +177,9 @@ def overlay(
165177
166178
Docs & Examples: https://offerrall.github.io/pyimagecuda/blend/#overlay
167179
"""
180+
if abs(opacity) < 1e-6:
181+
return
182+
168183
pos_x, pos_y = _calculate_position(
169184
base.width, base.height,
170185
overlay.width, overlay.height,
@@ -195,6 +210,9 @@ def soft_light(
195210
196211
Docs & Examples: https://offerrall.github.io/pyimagecuda/blend/#soft-light
197212
"""
213+
if abs(opacity) < 1e-6:
214+
return
215+
198216
pos_x, pos_y = _calculate_position(
199217
base.width, base.height,
200218
overlay.width, overlay.height,
@@ -225,6 +243,9 @@ def hard_light(
225243
226244
Docs & Examples: https://offerrall.github.io/pyimagecuda/blend/#hard-light
227245
"""
246+
if abs(opacity) < 1e-6:
247+
return
248+
228249
pos_x, pos_y = _calculate_position(
229250
base.width, base.height,
230251
overlay.width, overlay.height,

‎pyimagecuda/effect.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def rounded_corners(image: Image, radius: float) -> None:
2626
"""
2727
max_radius = min(image.width, image.height) / 2.0
2828
if radius < 0: raise ValueError("Radius must be non-negative")
29+
if radius == 0: return
2930
if radius > max_radius: radius = max_radius
3031

3132
rounded_corners_f32(image._buffer._handle, image.width, image.height, float(radius))

‎pyimagecuda/filter.py‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from .image import Image
22
from .utils import ensure_capacity
3+
from .io import copy
34
from .pyimagecuda_internal import (gaussian_blur_separable_f32, #type: ignore
45
sharpen_f32,
56
sepia_f32,
@@ -26,6 +27,15 @@ def gaussian_blur(
2627
Docs & Examples: https://offerrall.github.io/pyimagecuda/filter/#gaussian-blur
2728
"""
2829

30+
if radius == 0 or (sigma is not None and sigma <= 0.001):
31+
if dst_buffer is None:
32+
dst_buffer = Image(src.width, src.height)
33+
copy(dst_buffer, src)
34+
return dst_buffer
35+
else:
36+
copy(dst_buffer, src)
37+
return None
38+
2939
if sigma is None:
3040
sigma = radius / 3.0
3141

@@ -70,6 +80,15 @@ def sharpen(
7080
Docs & Examples: https://offerrall.github.io/pyimagecuda/filter/#sharpen
7181
"""
7282

83+
if abs(strength) < 1e-6:
84+
if dst_buffer is None:
85+
dst_buffer = Image(src.width, src.height)
86+
copy(dst_buffer, src)
87+
return dst_buffer
88+
else:
89+
copy(dst_buffer, src)
90+
return None
91+
7392
if dst_buffer is None:
7493
dst_buffer = Image(src.width, src.height)
7594
return_buffer = True
@@ -94,6 +113,8 @@ def sepia(image: Image, intensity: float = 1.0) -> None:
94113
95114
Docs & Examples: https://offerrall.github.io/pyimagecuda/filter/#sepia
96115
"""
116+
if abs(intensity) < 1e-6:
117+
return
97118

98119
sepia_f32(image._buffer._handle, image.width, image.height, float(intensity))
99120

@@ -153,6 +174,15 @@ def emboss(src: Image, strength: float = 1.0, dst_buffer: Image | None = None) -
153174
154175
Docs & Examples: https://offerrall.github.io/pyimagecuda/filter/#emboss
155176
"""
177+
if abs(strength) < 1e-6:
178+
if dst_buffer is None:
179+
dst_buffer = Image(src.width, src.height)
180+
copy(dst_buffer, src)
181+
return dst_buffer
182+
else:
183+
copy(dst_buffer, src)
184+
return None
185+
156186
if dst_buffer is None:
157187
dst_buffer = Image(src.width, src.height)
158188
return_buffer = True

‎pyimagecuda/resize.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from .image import Image
22
from .utils import ensure_capacity
33
from .pyimagecuda_internal import resize_f32 #type: ignore
4+
from .io import copy
45

56

67
def _resize_internal(
@@ -18,6 +19,17 @@ def _resize_internal(
1819
elif height is None:
1920
height = int(src.height * (width / src.width))
2021

22+
# No resize needed, just copy
23+
if width == src.width and height == src.height:
24+
if dst_buffer is None:
25+
dst_buffer = Image(width, height)
26+
copy(dst_buffer, src)
27+
return dst_buffer
28+
else:
29+
copy(dst_buffer, src)
30+
return None
31+
32+
# Resize normal
2133
if dst_buffer is None:
2234
dst_buffer = Image(width, height)
2335
return_buffer = True

‎pyimagecuda/transform.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from .image import Image
44
from .utils import ensure_capacity
55
from .fill import Fill
6+
from .io import copy
67
from .pyimagecuda_internal import ( #type: ignore
78
flip_f32, crop_f32, rotate_fixed_f32,
89
rotate_arbitrary_f32, copy_buffer
@@ -150,6 +151,15 @@ def crop(
150151
if width <= 0 or height <= 0:
151152
raise ValueError("Crop dimensions must be positive")
152153

154+
if x == 0 and y == 0 and width == image.width and height == image.height:
155+
if dst_buffer is None:
156+
dst_buffer = Image(width, height)
157+
copy(dst_buffer, image)
158+
return dst_buffer
159+
else:
160+
copy(dst_buffer, image)
161+
return None
162+
153163
if dst_buffer is None:
154164
dst_buffer = Image(width, height)
155165
return_buffer = True

‎pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "scikit_build_core.build"
44

55
[project]
66
name = "pyimagecuda"
7-
version = "0.0.7"
7+
version = "0.0.8"
88
description = "GPU-accelerated image processing library for Python"
99
readme = "README.md"
1010
requires-python = ">=3.10"

0 commit comments

Comments
 (0)