pyimagecuda 0.0.4__cp312-cp312-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
pyimagecuda/resize.py ADDED
@@ -0,0 +1,97 @@
1
+ from .image import Image
2
+ from .utils import ensure_capacity
3
+ from .pyimagecuda_internal import resize_f32 #type: ignore
4
+
5
+
6
+ def _resize_internal(
7
+ src: Image,
8
+ width: int | None,
9
+ height: int | None,
10
+ method: int,
11
+ dst_buffer: Image | None = None
12
+ ) -> Image | None:
13
+
14
+ if width is None and height is None:
15
+ raise ValueError("At least one of width or height must be specified")
16
+ elif width is None:
17
+ width = int(src.width * (height / src.height))
18
+ elif height is None:
19
+ height = int(src.height * (width / src.width))
20
+
21
+ if dst_buffer is None:
22
+ dst_buffer = Image(width, height)
23
+ return_buffer = True
24
+ else:
25
+ ensure_capacity(dst_buffer, width, height)
26
+ return_buffer = False
27
+
28
+ resize_f32(
29
+ src._buffer._handle,
30
+ dst_buffer._buffer._handle,
31
+ src.width,
32
+ src.height,
33
+ width,
34
+ height,
35
+ method
36
+ )
37
+
38
+ return dst_buffer if return_buffer else None
39
+
40
+
41
+ class Resize:
42
+ @staticmethod
43
+ def nearest(
44
+ src: Image,
45
+ width: int | None = None,
46
+ height: int | None = None,
47
+ dst_buffer: Image | None = None
48
+ ) -> Image | None:
49
+ """
50
+ Resizes the image using nearest neighbor interpolation (returns new image or writes to buffer).
51
+
52
+ Docs & Examples: https://offerrall.github.io/pyimagecuda/resize/#nearest
53
+ """
54
+ return _resize_internal(src, width, height, 0, dst_buffer)
55
+
56
+ @staticmethod
57
+ def bilinear(
58
+ src: Image,
59
+ width: int | None = None,
60
+ height: int | None = None,
61
+ dst_buffer: Image | None = None
62
+ ) -> Image | None:
63
+ """
64
+ Resizes the image using bilinear interpolation (returns new image or writes to buffer).
65
+
66
+ Docs & Examples: https://offerrall.github.io/pyimagecuda/resize/#bilinear
67
+ """
68
+
69
+ return _resize_internal(src, width, height, 1, dst_buffer)
70
+
71
+ @staticmethod
72
+ def bicubic(
73
+ src: Image,
74
+ width: int | None = None,
75
+ height: int | None = None,
76
+ dst_buffer: Image | None = None
77
+ ) -> Image | None:
78
+ """
79
+ Resizes the image using bicubic interpolation (returns new image or writes to buffer).
80
+
81
+ Docs & Examples: https://offerrall.github.io/pyimagecuda/resize/#bicubic
82
+ """
83
+ return _resize_internal(src, width, height, 2, dst_buffer)
84
+
85
+ @staticmethod
86
+ def lanczos(
87
+ src: Image,
88
+ width: int | None = None,
89
+ height: int | None = None,
90
+ dst_buffer: Image | None = None
91
+ ) -> Image | None:
92
+ """
93
+ Resizes the image using Lanczos interpolation (returns new image or writes to buffer).
94
+
95
+ Docs & Examples: https://offerrall.github.io/pyimagecuda/resize/#lanczos
96
+ """
97
+ return _resize_internal(src, width, height, 3, dst_buffer)
@@ -0,0 +1,186 @@
1
+ import math
2
+ from typing import Literal
3
+ from .image import Image
4
+ from .utils import ensure_capacity
5
+ from .fill import Fill
6
+ from .pyimagecuda_internal import ( #type: ignore
7
+ flip_f32, crop_f32, rotate_fixed_f32,
8
+ rotate_arbitrary_f32, copy_buffer
9
+ )
10
+
11
+
12
+ class Transform:
13
+
14
+ @staticmethod
15
+ def flip(
16
+ image: Image,
17
+ direction: Literal['horizontal', 'vertical', 'both'] = 'horizontal',
18
+ dst_buffer: Image | None = None
19
+ ) -> Image | None:
20
+ """
21
+ Flips the image across the specified axis (returns new image or writes to buffer).
22
+
23
+ Docs & Examples: https://offerrall.github.io/pyimagecuda/transform/#flip
24
+ """
25
+
26
+ direction_map = {
27
+ 'horizontal': 0,
28
+ 'vertical': 1,
29
+ 'both': 2
30
+ }
31
+
32
+ mode = direction_map.get(direction)
33
+ if mode is None:
34
+ raise ValueError(f"Invalid direction: {direction}. Must be {list(direction_map.keys())}")
35
+
36
+ if dst_buffer is None:
37
+ dst_buffer = Image(image.width, image.height)
38
+ return_buffer = True
39
+ else:
40
+ ensure_capacity(dst_buffer, image.width, image.height)
41
+ return_buffer = False
42
+
43
+ flip_f32(
44
+ image._buffer._handle,
45
+ dst_buffer._buffer._handle,
46
+ image.width,
47
+ image.height,
48
+ mode
49
+ )
50
+
51
+ return dst_buffer if return_buffer else None
52
+
53
+ @staticmethod
54
+ def rotate(
55
+ image: Image,
56
+ angle: float,
57
+ expand: bool = True,
58
+ dst_buffer: Image | None = None
59
+ ) -> Image | None:
60
+ """
61
+ Rotates the image by any angle in degrees (Clockwise).
62
+
63
+ Docs & Examples: https://offerrall.github.io/pyimagecuda/transform/#rotate
64
+ """
65
+
66
+ norm_angle = angle % 360
67
+ if norm_angle < 0: norm_angle += 360
68
+
69
+ is_fixed = False
70
+ fixed_mode = 0
71
+
72
+ if abs(norm_angle - 0) < 0.01:
73
+ if dst_buffer is None:
74
+ dst_buffer = Image(image.width, image.height)
75
+ return_buffer = True
76
+ else:
77
+ ensure_capacity(dst_buffer, image.width, image.height)
78
+ return_buffer = False
79
+
80
+ copy_buffer(dst_buffer._buffer._handle, image._buffer._handle, image.width, image.height)
81
+ return dst_buffer if return_buffer else None
82
+
83
+ elif abs(norm_angle - 90) < 0.01: is_fixed = True; fixed_mode = 0
84
+ elif abs(norm_angle - 180) < 0.01: is_fixed = True; fixed_mode = 1
85
+ elif abs(norm_angle - 270) < 0.01: is_fixed = True; fixed_mode = 2
86
+
87
+ if is_fixed:
88
+ if fixed_mode == 1:
89
+ rot_w, rot_h = image.width, image.height
90
+ else:
91
+ rot_w, rot_h = image.height, image.width
92
+ else:
93
+ rads = math.radians(angle)
94
+ sin_a = abs(math.sin(rads))
95
+ cos_a = abs(math.cos(rads))
96
+ rot_w = int(image.width * cos_a + image.height * sin_a)
97
+ rot_h = int(image.width * sin_a + image.height * cos_a)
98
+
99
+ if expand:
100
+ final_w = rot_w
101
+ final_h = rot_h
102
+ offset_x = 0
103
+ offset_y = 0
104
+ else:
105
+ final_w = image.width
106
+ final_h = image.height
107
+ offset_x = (final_w - rot_w) // 2
108
+ offset_y = (final_h - rot_h) // 2
109
+
110
+ if dst_buffer is None:
111
+ dst_buffer = Image(final_w, final_h)
112
+ return_buffer = True
113
+ else:
114
+ ensure_capacity(dst_buffer, final_w, final_h)
115
+ return_buffer = False
116
+
117
+ if is_fixed:
118
+ rotate_fixed_f32(
119
+ image._buffer._handle,
120
+ dst_buffer._buffer._handle,
121
+ image.width, image.height,
122
+ final_w, final_h,
123
+ fixed_mode, offset_x, offset_y
124
+ )
125
+ else:
126
+ rotate_arbitrary_f32(
127
+ image._buffer._handle,
128
+ dst_buffer._buffer._handle,
129
+ image.width, image.height,
130
+ final_w, final_h,
131
+ float(angle)
132
+ )
133
+
134
+ return dst_buffer if return_buffer else None
135
+
136
+ @staticmethod
137
+ def crop(
138
+ image: Image,
139
+ x: int,
140
+ y: int,
141
+ width: int,
142
+ height: int,
143
+ dst_buffer: Image | None = None
144
+ ) -> Image | None:
145
+ """
146
+ Crops a rectangular region (returns new image or writes to buffer).
147
+
148
+ Docs & Examples: https://offerrall.github.io/pyimagecuda/transform/#crop
149
+ """
150
+ if width <= 0 or height <= 0:
151
+ raise ValueError("Crop dimensions must be positive")
152
+
153
+ if dst_buffer is None:
154
+ dst_buffer = Image(width, height)
155
+ return_buffer = True
156
+ else:
157
+ ensure_capacity(dst_buffer, width, height)
158
+ return_buffer = False
159
+
160
+ Fill.color(dst_buffer, (0.0, 0.0, 0.0, 0.0))
161
+
162
+ crop_left = x
163
+ crop_top = y
164
+ crop_right = x + width
165
+ crop_bottom = y + height
166
+ img_right, img_bottom = image.width, image.height
167
+
168
+ intersect_left = max(crop_left, 0)
169
+ intersect_top = max(crop_top, 0)
170
+ intersect_right = min(crop_right, img_right)
171
+ intersect_bottom = min(crop_bottom, img_bottom)
172
+
173
+ copy_w = intersect_right - intersect_left
174
+ copy_h = intersect_bottom - intersect_top
175
+
176
+ if copy_w > 0 and copy_h > 0:
177
+ crop_f32(
178
+ image._buffer._handle,
179
+ dst_buffer._buffer._handle,
180
+ image.width, dst_buffer.width,
181
+ intersect_left, intersect_top,
182
+ intersect_left - crop_left, intersect_top - crop_top,
183
+ copy_w, copy_h
184
+ )
185
+
186
+ return dst_buffer if return_buffer else None
pyimagecuda/utils.py ADDED
@@ -0,0 +1,17 @@
1
+ from .image import ImageBase
2
+
3
+ def ensure_capacity(buffer: ImageBase, required_width: int, required_height: int) -> None:
4
+ """
5
+ Checks if the buffer has enough capacity and updates its logical dimensions.
6
+ Raises ValueError if capacity is insufficient.
7
+ """
8
+ max_w, max_h = buffer.get_max_capacity()
9
+
10
+ if required_width > max_w or required_height > max_h:
11
+ raise ValueError(
12
+ f"Buffer capacity too small: need {required_width}×{required_height}, "
13
+ f"got capacity {max_w}×{max_h}"
14
+ )
15
+
16
+ buffer.width = required_width
17
+ buffer.height = required_height
@@ -0,0 +1,95 @@
1
+ Metadata-Version: 2.2
2
+ Name: pyimagecuda
3
+ Version: 0.0.4
4
+ Summary: GPU-accelerated image processing library for Python
5
+ Author: Beltrán Offerrall
6
+ Requires-Python: >=3.10
7
+ Requires-Dist: pyvips[binary]
8
+ Description-Content-Type: text/markdown
9
+
10
+ # PyImageCUDA 0.0.4
11
+
12
+ [![PyPI version](https://img.shields.io/pypi/v/pyimagecuda.svg)](https://pypi.org/project/pyimagecuda/)
13
+ [![Build Status](https://github.com/offerrall/pyimagecuda/actions/workflows/build.yml/badge.svg)](https://github.com/offerrall/pyimagecuda/actions)
14
+ ![Python](https://img.shields.io/badge/python-3.10%20|%203.11%20|%203.12%20|%203.13-blue)
15
+
16
+ **GPU-accelerated image compositing for Python.**
17
+
18
+ > PyImageCUDA focuses on creative image generation rather than computer vision. Expect GPU-accelerated effects for design workflows—blending modes, shadows, gradients, filters... not edge detection or object recognition.
19
+
20
+ ## Quick Example
21
+
22
+ <img src="https://offerrall.github.io/pyimagecuda/images/quick.png" alt="Demo" width="400">
23
+
24
+ ```python
25
+ from pyimagecuda import Image, Fill, Effect, Blend, Transform, save
26
+
27
+ with Image(1024, 1024) as bg:
28
+ Fill.color(bg, (0, 1, 0.8, 1))
29
+ with Image(512, 512) as card:
30
+ Fill.gradient(card, (1, 0, 0, 1), (0, 0, 1, 1), 'radial')
31
+ Effect.rounded_corners(card, 50)
32
+
33
+ with Effect.stroke(card, 10, (1, 1, 1, 1)) as stroked:
34
+ with Effect.drop_shadow(stroked, blur=50, color=(0, 0, 0, 1)) as shadowed:
35
+ with Transform.rotate(shadowed, 45) as rotated:
36
+ Blend.normal(bg, rotated, anchor='center')
37
+
38
+ save(bg, 'output.png')
39
+ ```
40
+
41
+ ## Key Features
42
+
43
+ * ✅ **Zero Dependencies:** No CUDA Toolkit, Visual Studio, or complex compilers needed. Is Plug & Play.
44
+ * ✅ **Ultra-lightweight:** library weighs **<0.5 MB**.
45
+ * ✅ **Studio Quality:** 32-bit floating-point precision (float32) to prevent color banding.
46
+ * ✅ **Advanced Memory Control:** Reuse GPU buffers across operations and resize without reallocation—critical for video processing and batch workflows.
47
+ * ✅ **API Simplicity:** Intuitive, Pythonic API designed for ease of use.
48
+
49
+ ## Use Cases
50
+
51
+ * **Generative Art:** Create thousands of unique variations in seconds.
52
+ * **Motion Graphics:** Process video frames or generate effects in real-time.
53
+ * **Image Compositing:** Complex multi-layer designs with GPU-accelerated effects.
54
+ * **Game Development:** Procedural UI assets, icons, and sprite generation.
55
+ * **Marketing Automation:** Mass-produce personalized graphics from templates.
56
+ * **Data Augmentation:** High-speed batch transformations for ML datasets.
57
+
58
+ ## Installation
59
+ ```bash
60
+ pip install pyimagecuda
61
+ ```
62
+
63
+ **Note:** Automatically installs `pyvips` binary dependencies for robust image format support (JPG, PNG, WEBP, HEIC).
64
+
65
+ ## Documentation
66
+
67
+ **⚠️ Alpha Release:** Many more features are planned and under development. If you have specific needs or bug reports, please open an issue on GitHub.
68
+
69
+ ### Core Concepts
70
+ * [Getting Started Guide](https://offerrall.github.io/pyimagecuda/)
71
+ * [Image & Memory](https://offerrall.github.io/pyimagecuda/image/) (Buffer management)
72
+ * [IO](https://offerrall.github.io/pyimagecuda/io/) (Loading and Saving)
73
+
74
+ ### Operations
75
+ * [Adjust](https://offerrall.github.io/pyimagecuda/adjust/) (Brightness, Contrast, Saturation, Gamma, Opacity)
76
+ * [Transform](https://offerrall.github.io/pyimagecuda/transform/) (Flip, Rotate, Crop)
77
+ * [Blend](https://offerrall.github.io/pyimagecuda/blend/) (Normal, Multiply, Screen, Add, Overlay, Soft Light, Hard Light, Mask)
78
+ * [Resize](https://offerrall.github.io/pyimagecuda/resize/) (Nearest, Bilinear, Bicubic, Lanczos)
79
+ * [Filter](https://offerrall.github.io/pyimagecuda/filter/) (Gaussian Blur, Sharpen, Sepia, Invert, Threshold, Solarize, Sobel, Emboss)
80
+ * [Effect](https://offerrall.github.io/pyimagecuda/effect/) (Drop Shadow, Rounded Corners, Stroke, Vignette)
81
+ * [Fill](https://offerrall.github.io/pyimagecuda/fill/) (Solid colors, Gradients, Checkerboard, Grid, Stripes, Dots, Circle, Ngon, Noise, Perlin)
82
+
83
+ ## Requirements
84
+
85
+ * **OS:** Windows 10 or 11 (64-bit). *Linux support coming soon.*
86
+ * **GPU:** NVIDIA GPU (Maxwell architecture / GTX 900 series or newer).
87
+ * **Drivers:** Standard NVIDIA Drivers installed.
88
+
89
+ **NOT REQUIRED:** Visual Studio, CUDA Toolkit, or Conda.
90
+
91
+ ## Contributing
92
+ Contributions welcome! Open issues or submit PRs
93
+
94
+ ## License
95
+ MIT License. See [LICENSE](LICENSE) for details.
@@ -0,0 +1,16 @@
1
+ pyimagecuda/__init__.py,sha256=NUbXSns16c8fs0VqqeuMQ19zNMK9deU7Hd7eCZia1gA,2044
2
+ pyimagecuda/adjust.py,sha256=d2R7LFKqGQVNFwq6KXToDuOfRafvx3qiAXCPKB_Sp7A,2908
3
+ pyimagecuda/blend.py,sha256=EQgUz7dqfJbjUof1mMRy8OUX84D_eOuzh4n2y-comJY,8691
4
+ pyimagecuda/effect.py,sha256=W861V0xkzIMuJk6rZxfRtlK_H78IIPIvxHaXRZ5qduQ,6199
5
+ pyimagecuda/fill.py,sha256=7ybr-wkyr5_ziLL_6bvrLAW_Ixe1nMz36Lrj6jJAiOI,8934
6
+ pyimagecuda/filter.py,sha256=puUsGBaaWhPnByHytqeaH5Uu1PPVBzhW-sQVQIxtq2Y,5615
7
+ pyimagecuda/image.py,sha256=VRDHUOF2VClwdj3Q5YSQsmy9lpirwQvbC1P8avE3PdI,2864
8
+ pyimagecuda/io.py,sha256=aee7rAeMesONzafQcF28QwQ9FqfKFSqAvEPN7zKY2i0,5182
9
+ pyimagecuda/pyimagecuda_internal.cp312-win_amd64.pyd,sha256=zqfxoT2QjPIYvVTQnBqvM4AUSzUazi0FTdqpjsXdKRk,582656
10
+ pyimagecuda/resize.py,sha256=-I4dqMu0-5OBHh_qMkBdOxrHXqfkrpvYaULsDOqproo,2934
11
+ pyimagecuda/transform.py,sha256=n_fftpugw2SJscvwS4JzFjZ2m-lITAlHK0delnCScq8,6091
12
+ pyimagecuda/utils.py,sha256=8IZ35y783AVJVuoQmcStPVAyx5WK_PDhkWqLo51PbTo,633
13
+ pyimagecuda-0.0.4.dist-info/METADATA,sha256=sILv6k_PrXlJIFRexbNiNrniErLqBODvjm9nhSUieYg,4383
14
+ pyimagecuda-0.0.4.dist-info/WHEEL,sha256=chqeLhPBtPdrOoreR34YMcofSk3yWDQhkrsDJ2n48LU,106
15
+ pyimagecuda-0.0.4.dist-info/licenses/LICENSE,sha256=xfNh_pr4FPV8klv9rbs9GFflEfqf7vSFzcXK6BetRN0,1114
16
+ pyimagecuda-0.0.4.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: scikit-build-core 0.11.6
3
+ Root-Is-Purelib: false
4
+ Tag: cp312-cp312-win_amd64
5
+
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2011-2025 The Bootstrap Authors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.