pyimagecuda 0.1.0__cp311-cp311-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.
@@ -0,0 +1,275 @@
1
+ import math
2
+ from typing import Literal
3
+ from .image import Image
4
+ from .fill import Fill
5
+ from .io import copy
6
+ from .pyimagecuda_internal import ( #type: ignore
7
+ flip_f32, crop_f32, rotate_fixed_f32,
8
+ rotate_arbitrary_f32, copy_buffer, zoom_f32
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
+ dst_buffer.resize(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
+ interpolation: Literal['nearest', 'bilinear', 'bicubic', 'lanczos'] = 'bilinear',
59
+ dst_buffer: Image | None = None
60
+ ) -> Image | None:
61
+ """
62
+ Rotates the image by any angle in degrees (Clockwise).
63
+
64
+ Docs & Examples: https://offerrall.github.io/pyimagecuda/transform/#rotate
65
+ """
66
+
67
+ interp_map = {
68
+ 'nearest': 0,
69
+ 'bilinear': 1,
70
+ 'bicubic': 2,
71
+ 'lanczos': 3
72
+ }
73
+
74
+ interp_method = interp_map.get(interpolation)
75
+ if interp_method is None:
76
+ raise ValueError(f"Invalid interpolation: {interpolation}. Must be {list(interp_map.keys())}")
77
+
78
+ norm_angle = angle % 360
79
+ if norm_angle < 0:
80
+ norm_angle += 360
81
+
82
+ is_fixed = False
83
+ fixed_mode = 0
84
+
85
+ if abs(norm_angle - 0) < 0.01:
86
+ if dst_buffer is None:
87
+ dst_buffer = Image(image.width, image.height)
88
+ return_buffer = True
89
+ else:
90
+ dst_buffer.resize(image.width, image.height)
91
+ return_buffer = False
92
+
93
+ copy_buffer(dst_buffer._buffer._handle, image._buffer._handle, image.width, image.height)
94
+ return dst_buffer if return_buffer else None
95
+
96
+ elif abs(norm_angle - 90) < 0.01:
97
+ is_fixed = True
98
+ fixed_mode = 0
99
+ elif abs(norm_angle - 180) < 0.01:
100
+ is_fixed = True
101
+ fixed_mode = 1
102
+ elif abs(norm_angle - 270) < 0.01:
103
+ is_fixed = True
104
+ fixed_mode = 2
105
+
106
+ if is_fixed:
107
+ if fixed_mode == 1:
108
+ rot_w = image.width
109
+ rot_h = image.height
110
+ else:
111
+ rot_w = image.height
112
+ rot_h = image.width
113
+ else:
114
+ rads = math.radians(angle)
115
+ sin_a = abs(math.sin(rads))
116
+ cos_a = abs(math.cos(rads))
117
+ rot_w = int(image.width * cos_a + image.height * sin_a)
118
+ rot_h = int(image.width * sin_a + image.height * cos_a)
119
+
120
+ if expand:
121
+ final_w = rot_w
122
+ final_h = rot_h
123
+ offset_x = 0
124
+ offset_y = 0
125
+ else:
126
+ final_w = image.width
127
+ final_h = image.height
128
+ offset_x = (final_w - rot_w) // 2
129
+ offset_y = (final_h - rot_h) // 2
130
+
131
+ if dst_buffer is None:
132
+ dst_buffer = Image(final_w, final_h)
133
+ return_buffer = True
134
+ else:
135
+ dst_buffer.resize(final_w, final_h)
136
+ return_buffer = False
137
+
138
+ if is_fixed:
139
+ rotate_fixed_f32(
140
+ image._buffer._handle,
141
+ dst_buffer._buffer._handle,
142
+ image.width, image.height,
143
+ final_w, final_h,
144
+ fixed_mode, offset_x, offset_y
145
+ )
146
+ else:
147
+ rotate_arbitrary_f32(
148
+ image._buffer._handle,
149
+ dst_buffer._buffer._handle,
150
+ image.width, image.height,
151
+ final_w, final_h,
152
+ float(angle),
153
+ interp_method
154
+ )
155
+
156
+ return dst_buffer if return_buffer else None
157
+
158
+ @staticmethod
159
+ def crop(
160
+ image: Image,
161
+ x: int,
162
+ y: int,
163
+ width: int,
164
+ height: int,
165
+ dst_buffer: Image | None = None
166
+ ) -> Image | None:
167
+ """
168
+ Crops a rectangular region (returns new image or writes to buffer).
169
+
170
+ Docs & Examples: https://offerrall.github.io/pyimagecuda/transform/#crop
171
+ """
172
+ if width <= 0 or height <= 0:
173
+ raise ValueError("Crop dimensions must be positive")
174
+
175
+ if x == 0 and y == 0 and width == image.width and height == image.height:
176
+ if dst_buffer is None:
177
+ dst_buffer = Image(width, height)
178
+ copy(dst_buffer, image)
179
+ return dst_buffer
180
+ else:
181
+ copy(dst_buffer, image)
182
+ return None
183
+
184
+ if dst_buffer is None:
185
+ dst_buffer = Image(width, height)
186
+ return_buffer = True
187
+ else:
188
+ dst_buffer.resize(width, height)
189
+ return_buffer = False
190
+
191
+ Fill.color(dst_buffer, (0.0, 0.0, 0.0, 0.0))
192
+
193
+ crop_left = x
194
+ crop_top = y
195
+ crop_right = x + width
196
+ crop_bottom = y + height
197
+ img_right = image.width
198
+ img_bottom = image.height
199
+
200
+ intersect_left = max(crop_left, 0)
201
+ intersect_top = max(crop_top, 0)
202
+ intersect_right = min(crop_right, img_right)
203
+ intersect_bottom = min(crop_bottom, img_bottom)
204
+
205
+ copy_w = intersect_right - intersect_left
206
+ copy_h = intersect_bottom - intersect_top
207
+
208
+ if copy_w > 0 and copy_h > 0:
209
+ crop_f32(
210
+ image._buffer._handle,
211
+ dst_buffer._buffer._handle,
212
+ image.width, dst_buffer.width,
213
+ intersect_left, intersect_top,
214
+ intersect_left - crop_left, intersect_top - crop_top,
215
+ copy_w, copy_h
216
+ )
217
+
218
+ return dst_buffer if return_buffer else None
219
+
220
+ @staticmethod
221
+ def zoom(
222
+ image: Image,
223
+ zoom_factor: float = 2.0,
224
+ center_x: float | None = None,
225
+ center_y: float | None = None,
226
+ interpolation: Literal['nearest', 'bilinear', 'bicubic', 'lanczos'] = 'bilinear',
227
+ dst_buffer: Image | None = None
228
+ ) -> Image | None:
229
+ """
230
+ Zoom into an image by a specified factor, centered at (center_x, center_y).
231
+
232
+ Docs & Examples: https://offerrall.github.io/pyimagecuda/transform/#zoom
233
+ """
234
+ if zoom_factor <= 0:
235
+ raise ValueError("Zoom factor must be positive")
236
+
237
+ if center_x is None:
238
+ center_x = image.width / 2.0
239
+ if center_y is None:
240
+ center_y = image.height / 2.0
241
+
242
+ center_x = max(0.0, min(float(image.width - 1), float(center_x)))
243
+ center_y = max(0.0, min(float(image.height - 1), float(center_y)))
244
+
245
+ interp_map = {
246
+ 'nearest': 0,
247
+ 'bilinear': 1,
248
+ 'bicubic': 2,
249
+ 'lanczos': 3
250
+ }
251
+
252
+ interp_method = interp_map.get(interpolation)
253
+ if interp_method is None:
254
+ raise ValueError(f"Invalid interpolation: {interpolation}. Must be {list(interp_map.keys())}")
255
+
256
+ if dst_buffer is None:
257
+ dst_buffer = Image(image.width, image.height)
258
+ return_buffer = True
259
+ else:
260
+ return_buffer = False
261
+
262
+ zoom_f32(
263
+ image._buffer._handle,
264
+ dst_buffer._buffer._handle,
265
+ image.width,
266
+ image.height,
267
+ dst_buffer.width,
268
+ dst_buffer.height,
269
+ float(zoom_factor),
270
+ float(center_x),
271
+ float(center_y),
272
+ interp_method
273
+ )
274
+
275
+ return dst_buffer if return_buffer else None
@@ -0,0 +1,150 @@
1
+ Metadata-Version: 2.2
2
+ Name: pyimagecuda
3
+ Version: 0.1.0
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.1.0
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
+ ![Platform](https://img.shields.io/badge/platform-Windows%20%7C%20Linux-brightgreen)
16
+ ![Tests](https://img.shields.io/badge/tests-85%20passed-brightgreen)
17
+ [![NVIDIA](https://img.shields.io/badge/NVIDIA-CUDA-76B900?style=flat&logo=nvidia&logoColor=white)](https://developer.nvidia.com/cuda-zone)
18
+
19
+ **GPU-accelerated image compositing for Python.**
20
+
21
+ > PyImageCUDA is built for image composition, not computer vision. It provides GPU tools to create, modify, and blend images, rather than analyze or recognize objects within them.
22
+
23
+ ## Quick Example
24
+
25
+ <img src="https://offerrall.github.io/pyimagecuda/images/quick.png" alt="Demo" width="400">
26
+
27
+ ```python
28
+ from pyimagecuda import Image, Fill, Effect, Blend, Transform, save
29
+
30
+ with Image(1024, 1024) as bg:
31
+ Fill.color(bg, (0, 1, 0.8, 1))
32
+ with Image(512, 512) as card:
33
+ Fill.gradient(card, (1, 0, 0, 1), (0, 0, 1, 1), 'radial')
34
+ Effect.rounded_corners(card, 50)
35
+
36
+ with Effect.stroke(card, 10, (1, 1, 1, 1)) as stroked:
37
+ with Effect.drop_shadow(stroked, blur=50, color=(0, 0, 0, 1)) as shadowed:
38
+ with Transform.rotate(shadowed, 45) as rotated:
39
+ Blend.normal(bg, rotated, anchor='center')
40
+
41
+ save(bg, 'output.png')
42
+ ```
43
+
44
+ ## Key Features
45
+
46
+ * ✅ **Zero Dependencies:** No CUDA Toolkit, Visual Studio, or complex compilers needed. Is Plug & Play on both Windows and Linux.
47
+ * ✅ **Ultra-lightweight:** library weighs **~1 MB**.
48
+ * ✅ **Studio Quality:** 32-bit floating-point precision (float32) to prevent color banding.
49
+ * ✅ **Advanced Memory Control:** Reuse GPU buffers across operations and resize without reallocation—critical for video processing and batch workflows.
50
+ * ✅ **OpenGL Integration:** Direct GPU-to-GPU display for real-time preview widgets.
51
+ * ✅ **API Simplicity:** Intuitive, Pythonic API designed for ease of use.
52
+
53
+ ## Use Cases
54
+
55
+ * **Generative Art:** Create thousands of unique variations in seconds.
56
+ * **Motion Graphics:** Process video frames or generate effects in real-time.
57
+ * **Image Compositing:** Complex multi-layer designs with GPU-accelerated effects.
58
+ * **Node Editors & Real-time Tools:** Build responsive image editors with instant preview.
59
+ * **Game Development:** Procedural UI assets, icons, and sprite generation.
60
+ * **Marketing Automation:** Mass-produce personalized graphics from templates.
61
+ * **Data Augmentation:** High-speed batch transformations for ML datasets.
62
+
63
+ ## PyImageCUDA Ecosystem
64
+
65
+ This library is the foundation. For visual workflows:
66
+
67
+ **[PyImageCUDA Studio](https://github.com/offerrall/pyimagecuda-studio)**
68
+ - Node-based image compositor with real-time preview
69
+ - Design templates visually, automate with Python
70
+ - 40+ nodes: generators, effects, filters, transforms
71
+ - Headless batch processing API
72
+ ```bash
73
+ pip install pyimagecuda-studio
74
+ ```
75
+
76
+ ---
77
+
78
+ ## Installation
79
+
80
+ ## Installation
81
+ ```bash
82
+ pip install pyimagecuda
83
+ ```
84
+
85
+ **Note:** `pyvips` is the only mandatory dependency (installed automatically). It is used strictly for robust file I/O (JPG, PNG, WEBP...) and high-quality Text rendering on the CPU.
86
+
87
+ ## Documentation
88
+
89
+ ### Core Concepts
90
+ * [Getting Started Guide](https://offerrall.github.io/pyimagecuda/)
91
+ * [Image & Memory](https://offerrall.github.io/pyimagecuda/image/) (Buffer management)
92
+ * [IO](https://offerrall.github.io/pyimagecuda/io/) (Loading and Saving)
93
+ * [OpenGL Integration](https://offerrall.github.io/pyimagecuda/opengl/) (Real-time preview, zero-copy display)
94
+
95
+ ### Operations
96
+ * [Fill](https://offerrall.github.io/pyimagecuda/fill/) (Solid colors, Gradients, Checkerboard, Grid, Stripes, Dots, Circle, Ngon, Noise, Perlin)
97
+ * [Text](https://offerrall.github.io/pyimagecuda/text/) (Rich typography, system fonts, HTML-like markup, letter spacing...)
98
+ * [Blend](https://offerrall.github.io/pyimagecuda/blend/) (Normal, Multiply, Screen, Add, Overlay, Soft Light, Hard Light, Mask)
99
+ * [Resize](https://offerrall.github.io/pyimagecuda/resize/) (Nearest, Bilinear, Bicubic, Lanczos)
100
+ * [Adjust](https://offerrall.github.io/pyimagecuda/adjust/) (Brightness, Contrast, Saturation, Gamma, Opacity)
101
+ * [Transform](https://offerrall.github.io/pyimagecuda/transform/) (Flip, Rotate, Crop, Zoom)
102
+ * [Filter](https://offerrall.github.io/pyimagecuda/filter/) (Gaussian Blur, Sharpen, Sepia, Invert, Threshold, Solarize, Sobel, Emboss)
103
+ * [Effect](https://offerrall.github.io/pyimagecuda/effect/) (Drop Shadow, Rounded Corners, Stroke, Vignette)
104
+
105
+ ## Performance
106
+
107
+ PyImageCUDA shows significant speedups for GPU-friendly operations like blending, filtering, and transformations. Performance varies by operation complexity and workflow:
108
+
109
+ - Complex operations (blur, blend, rotate) see **10-260x improvements**
110
+ - Simple operations (flip, crop) see **3-20x improvements**
111
+ - Real-world pipelines with file I/O typically see **1.5-2.5x speedups**
112
+
113
+ Results depend on your hardware, batch size, and whether you reuse GPU buffers.
114
+
115
+ **[→ View Detailed Benchmarks](https://offerrall.github.io/pyimagecuda/benchmarks/)**
116
+
117
+ ## Requirements
118
+
119
+ * **OS:**
120
+ - Windows 10 or 11 (64-bit).
121
+ - Linux: Any modern distribution (Ubuntu, Fedora, Debian, Arch, WSL2, etc.).
122
+ * **GPU:** NVIDIA GPU (Maxwell architecture / GTX 900 series or newer).
123
+ * **Drivers:** Standard NVIDIA Drivers installed.
124
+
125
+ **NOT REQUIRED:** Visual Studio, CUDA Toolkit, or Conda.
126
+
127
+ ## Linux Compatibility & Troubleshooting
128
+
129
+ PyImageCUDA is currently tested primarily on **Ubuntu LTS** releases with up-to-date NVIDIA drivers.
130
+
131
+ If you encounter the following error on Linux:
132
+
133
+ ```text
134
+ RuntimeError: Kernel launch failed: the provided PTX was compiled with an unsupported toolchain.
135
+ ```
136
+
137
+ Solution: This indicates your installed NVIDIA drivers are too old to execute the kernels included in the library. Please update your NVIDIA drivers to the latest version available for your distribution (Proprietary drivers recommended).
138
+
139
+ We are actively investigating ways to broaden compatibility for older drivers and legacy Linux distributions in future releases.
140
+
141
+ ## Tests
142
+ ```bash
143
+ pytest tests/tests.py
144
+ ```
145
+
146
+ ## Contributing
147
+ Contributions welcome! Open issues or submit PRs
148
+
149
+ ## License
150
+ MIT License. See [LICENSE](LICENSE) for details.
@@ -0,0 +1,17 @@
1
+ pyimagecuda/__init__.py,sha256=A94o-xcZCZAKunZEK_z8pXSlwsNuLX00AcLBOrcAsZM,2219
2
+ pyimagecuda/adjust.py,sha256=xGSgifVWaFkaXyL718PUcYqwtZJAlnvMHNLQHiUS40M,3231
3
+ pyimagecuda/blend.py,sha256=sPupoAh9Mnz16dAsv6C3ynZvDHmV-0MR-A32KpEcE6Q,9132
4
+ pyimagecuda/effect.py,sha256=XTt7q7xr9T6TMqGkF00G8PgO04f70MMQuMxCl2hB2yM,6812
5
+ pyimagecuda/fill.py,sha256=7ybr-wkyr5_ziLL_6bvrLAW_Ixe1nMz36Lrj6jJAiOI,8934
6
+ pyimagecuda/filter.py,sha256=wOGh791djvkzPiwAz3kUABldaPOWVEO6Rqetgkw--N0,6306
7
+ pyimagecuda/gl_interop.py,sha256=x3P9MbjOSgwEMIdhkTE4lshAjn7YqXBM0JsKv2NsFUI,2654
8
+ pyimagecuda/image.py,sha256=UJaaxWctNSZ1lX45vzDhLXHjbhBlSPT54bB4MLyH3JE,3958
9
+ pyimagecuda/io.py,sha256=d8ODBO50bx43yNYUH5IjXxvrDW991W5-qJ2ex8DlNok,8616
10
+ pyimagecuda/pyimagecuda_internal.cp311-win_amd64.pyd,sha256=XW2cG1iUYGXUQkrs2I1zFkGTcPOD87NyK46pF8vdqMw,1309184
11
+ pyimagecuda/resize.py,sha256=iw3wRiOfQYHJygkbUvDEiC-gtnX9gX6gpXAsAdjduOc,3244
12
+ pyimagecuda/text.py,sha256=QTiecJkpLb7RyIpl8D7aEj3yGaLWW4uQ-J82UKBMCjY,3502
13
+ pyimagecuda/transform.py,sha256=fp5_9tlA5TKZWSroViyK48u9yNGDr0ujBLyXckqgvRk,8902
14
+ pyimagecuda-0.1.0.dist-info/METADATA,sha256=2ojkw061PrlE6lY-4Ji2dxoSZP1_ZaIRbt-rzUiNBIY,6737
15
+ pyimagecuda-0.1.0.dist-info/WHEEL,sha256=oXhHG6ewLm-FNdEna2zwgy-K0KEl4claZ1ztR4VTx0I,106
16
+ pyimagecuda-0.1.0.dist-info/licenses/LICENSE,sha256=xfNh_pr4FPV8klv9rbs9GFflEfqf7vSFzcXK6BetRN0,1114
17
+ pyimagecuda-0.1.0.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: cp311-cp311-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.