spriteworkflow 0.1.0__tar.gz
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.
- spriteworkflow-0.1.0/LICENSE +21 -0
- spriteworkflow-0.1.0/PKG-INFO +236 -0
- spriteworkflow-0.1.0/README.md +215 -0
- spriteworkflow-0.1.0/pyproject.toml +39 -0
- spriteworkflow-0.1.0/setup.cfg +4 -0
- spriteworkflow-0.1.0/spriteworkflow/__init__.py +23 -0
- spriteworkflow-0.1.0/spriteworkflow/cli.py +202 -0
- spriteworkflow-0.1.0/spriteworkflow/extractor.py +64 -0
- spriteworkflow-0.1.0/spriteworkflow/ffmpeg_manager.py +9 -0
- spriteworkflow-0.1.0/spriteworkflow/matte.py +152 -0
- spriteworkflow-0.1.0/spriteworkflow/report.py +142 -0
- spriteworkflow-0.1.0/spriteworkflow/spritesheet_grid.py +132 -0
- spriteworkflow-0.1.0/spriteworkflow/spritesheet_lineal.py +68 -0
- spriteworkflow-0.1.0/spriteworkflow.egg-info/PKG-INFO +236 -0
- spriteworkflow-0.1.0/spriteworkflow.egg-info/SOURCES.txt +17 -0
- spriteworkflow-0.1.0/spriteworkflow.egg-info/dependency_links.txt +1 -0
- spriteworkflow-0.1.0/spriteworkflow.egg-info/entry_points.txt +2 -0
- spriteworkflow-0.1.0/spriteworkflow.egg-info/requires.txt +9 -0
- spriteworkflow-0.1.0/spriteworkflow.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 jhonvillanueva-hash
|
|
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 all
|
|
13
|
+
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 THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: spriteworkflow
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Simple video to spritesheet workflow library.
|
|
5
|
+
Author-email: jhonvillanueva-hash <jhon.villanueva.lozano.v@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/jhonvillanueva-hash/spriteworkflow
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.10
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Requires-Dist: opencv-python>=4.8.0
|
|
14
|
+
Requires-Dist: pillow>=10.0.0
|
|
15
|
+
Requires-Dist: imageio-ffmpeg>=0.6.0
|
|
16
|
+
Provides-Extra: test
|
|
17
|
+
Requires-Dist: pytest>=7.0; extra == "test"
|
|
18
|
+
Provides-Extra: dev
|
|
19
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
|
|
22
|
+
# SpriteWorkflow
|
|
23
|
+
|
|
24
|
+
Biblioteca Python para convertir videos en spritesheets (hojas de sprites).
|
|
25
|
+
Extrae fotogramas de un video, opcionalmente remueve el fondo por chroma-key,
|
|
26
|
+
y los ensambla en un spritesheet lineal (horizontal) o en cuadrícula (grid).
|
|
27
|
+
Incluye un reporte de validación en formato JSON.
|
|
28
|
+
|
|
29
|
+
## Instalación
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install spriteworkflow
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Requiere **Python ≥ 3.10** y dependencias: `opencv-python`, `pillow`, `imageio-ffmpeg`.
|
|
36
|
+
|
|
37
|
+
### Dependencias de sistema
|
|
38
|
+
|
|
39
|
+
- **FFmpeg**: necesario para la extracción de fotogramas. La biblioteca lo
|
|
40
|
+
localiza automáticamente con `imageio-ffmpeg`, pero si no está disponible
|
|
41
|
+
puedes instalarlo manualmente:
|
|
42
|
+
- Windows: `winget install ffmpeg`
|
|
43
|
+
- macOS: `brew install ffmpeg`
|
|
44
|
+
- Linux: `sudo apt install ffmpeg`
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## Funciones de la biblioteca
|
|
49
|
+
|
|
50
|
+
### `extract_frames(video_name, output_dir="temp")`
|
|
51
|
+
|
|
52
|
+
Extrae fotogramas de un video en archivos PNG numerados.
|
|
53
|
+
|
|
54
|
+
| Parámetro | Tipo | Default | Descripción |
|
|
55
|
+
|----------------|-------------------|-----------|------------------------------------------|
|
|
56
|
+
| `video_name` | `str` o `Path` | — | Ruta al archivo de video |
|
|
57
|
+
| `output_dir` | `str` o `Path` | `"temp"` | Directorio de salida (se crea si no existe) |
|
|
58
|
+
|
|
59
|
+
- **Retorna**: `list[Path]` — rutas a los PNG extraídos, ordenados.
|
|
60
|
+
- **Excepciones**: `FileNotFoundError` (video no existe),
|
|
61
|
+
`ValueError` (archivo inválido o vacío), `PermissionError` (sin permiso),
|
|
62
|
+
`RuntimeError` (FFmpeg falla o no se extrajeron fotogramas).
|
|
63
|
+
|
|
64
|
+
### `remove_background(frames=None, frames_dir=None, bg_color=None, tolerance=30, feather=0, output_dir="matted")`
|
|
65
|
+
|
|
66
|
+
Elimina el fondo de fotogramas mediante chroma-key (distancia euclidiana en RGB).
|
|
67
|
+
|
|
68
|
+
| Parámetro | Tipo | Default | Descripción |
|
|
69
|
+
|---------------|-------------------|-------------|------------------------------------------------|
|
|
70
|
+
| `frames` | `list[Path]` | `None` | Lista de rutas a los fotogramas PNG |
|
|
71
|
+
| `frames_dir` | `str` o `Path` | `None` | Directorio con PNG (alternativa a `frames`) |
|
|
72
|
+
| `bg_color` | `tuple[int,int,int]` | `None` | RGB del chroma-key; auto-detectado si es `None`|
|
|
73
|
+
| `tolerance` | `int` | `30` | Distancia euclídea máxima del color de fondo |
|
|
74
|
+
| `feather` | `int` | `0` | Ancho del difuminado lineal alrededor de `tolerance`|
|
|
75
|
+
| `output_dir` | `str` o `Path` | `"matted"` | Directorio para los PNG con canal alpha |
|
|
76
|
+
|
|
77
|
+
- **Retorna**: `list[Path]` — rutas a los PNG procesados (RGBA), ordenados.
|
|
78
|
+
- **Excepciones**: `ValueError` (parámetros inválidos),
|
|
79
|
+
`FileNotFoundError` (`frames_dir` no existe),
|
|
80
|
+
`NotADirectoryError` (`frames_dir` no es directorio).
|
|
81
|
+
|
|
82
|
+
### `create_spritesheet_lineal(frames=None, frames_dir=None, output_file="spritesheet.png")`
|
|
83
|
+
|
|
84
|
+
Ensambla fotogramas en un spritesheet horizontal (una fila).
|
|
85
|
+
|
|
86
|
+
| Parámetro | Tipo | Default | Descripción |
|
|
87
|
+
|----------------|-------------------|----------------------|------------------------------------------|
|
|
88
|
+
| `frames` | `list[Path]` | `None` | Lista de rutas a los fotogramas PNG |
|
|
89
|
+
| `frames_dir` | `str` o `Path` | `None` | Directorio con PNG (alternativa a `frames`)|
|
|
90
|
+
| `output_file` | `str` o `Path` | `"spritesheet.png"` | Ruta del spritesheet generado |
|
|
91
|
+
|
|
92
|
+
- **Retorna**: `Path` — ruta al archivo generado.
|
|
93
|
+
- **Excepciones**: `ValueError`, `FileNotFoundError`, `NotADirectoryError`.
|
|
94
|
+
|
|
95
|
+
### `create_spritesheet_grid(frames=None, frames_dir=None, columns=None, padding=0, background=(0,0,0,0), output_file="spritesheet_grid.png")`
|
|
96
|
+
|
|
97
|
+
Ensambla fotogramas en un spritesheet en cuadrícula (filas × columnas).
|
|
98
|
+
|
|
99
|
+
| Parámetro | Tipo | Default | Descripción |
|
|
100
|
+
|----------------|--------------------|----------------------------|------------------------------------------|
|
|
101
|
+
| `frames` | `list[Path]` | `None` | Lista de rutas a los fotogramas PNG |
|
|
102
|
+
| `frames_dir` | `str` o `Path` | `None` | Directorio con PNG (alternativa a `frames`)|
|
|
103
|
+
| `columns` | `int` o `None` | `None` | N° de columnas; `None` = `ceil(sqrt(N))`|
|
|
104
|
+
| `padding` | `int` | `0` | Píxeles de espacio entre celdas |
|
|
105
|
+
| `background` | `tuple[int,int,int,int]` | `(0,0,0,0)` | RGBA de relleno para celdas vacías |
|
|
106
|
+
| `output_file` | `str` o `Path` | `"spritesheet_grid.png"` | Ruta del spritesheet generado |
|
|
107
|
+
|
|
108
|
+
- **Retorna**: `Path` — ruta al archivo generado.
|
|
109
|
+
- **Excepciones**: `ValueError`, `FileNotFoundError`, `NotADirectoryError`.
|
|
110
|
+
|
|
111
|
+
### `generate_report(frames=None, frames_dir=None, spritesheet_path=None, output_file="report.json")`
|
|
112
|
+
|
|
113
|
+
Inspecciona fotogramas y produce un reporte de validación JSON.
|
|
114
|
+
|
|
115
|
+
| Parámetro | Tipo | Default | Descripción |
|
|
116
|
+
|--------------------|-------------------|----------------|------------------------------------------|
|
|
117
|
+
| `frames` | `list[Path]` | `None` | Lista de rutas a los fotogramas PNG |
|
|
118
|
+
| `frames_dir` | `str` o `Path` | `None` | Directorio con PNG (alternativa) |
|
|
119
|
+
| `spritesheet_path` | `str` o `Path` | `None` | Ruta al spritesheet (opcional) |
|
|
120
|
+
| `output_file` | `str` o `Path` | `"report.json"`| Ruta del archivo JSON generado |
|
|
121
|
+
|
|
122
|
+
- **Retorna**: `Path` — ruta al archivo JSON.
|
|
123
|
+
- **Excepciones**: `ValueError`, `FileNotFoundError`, `NotADirectoryError`.
|
|
124
|
+
|
|
125
|
+
El reporte incluye: `total_frames`, `frames[]` (archivo, ancho, alto),
|
|
126
|
+
`consistent_dimensions`, `reference_size`, `mismatched_frames`,
|
|
127
|
+
`spritesheet_path`, `spritesheet_size`, y `generated_at`.
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## Ejemplo de uso (como biblioteca)
|
|
132
|
+
|
|
133
|
+
```python
|
|
134
|
+
from spriteworkflow import extract_frames, remove_background
|
|
135
|
+
from spriteworkflow import create_spritesheet_grid, generate_report
|
|
136
|
+
|
|
137
|
+
# 1. Extraer fotogramas de un video
|
|
138
|
+
frames = extract_frames("gameplay.mp4", output_dir="temp")
|
|
139
|
+
print(f"Extraídos {len(frames)} fotogramas")
|
|
140
|
+
|
|
141
|
+
# 2. Remover fondo verde (chroma-key)
|
|
142
|
+
frames_matted = remove_background(
|
|
143
|
+
frames=frames,
|
|
144
|
+
bg_color=(0, 255, 0),
|
|
145
|
+
tolerance=40,
|
|
146
|
+
output_dir="matted",
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
# 3. Crear spritesheet en grilla (3 columnas)
|
|
150
|
+
sheet = create_spritesheet_grid(
|
|
151
|
+
frames=frames_matted,
|
|
152
|
+
columns=3,
|
|
153
|
+
padding=2,
|
|
154
|
+
background=(0, 0, 0, 0),
|
|
155
|
+
output_file="hoja_sprites.png",
|
|
156
|
+
)
|
|
157
|
+
print(f"Spritesheet guardado: {sheet}")
|
|
158
|
+
|
|
159
|
+
# 4. Generar reporte de validación
|
|
160
|
+
report = generate_report(
|
|
161
|
+
frames=frames_matted,
|
|
162
|
+
spritesheet_path=sheet,
|
|
163
|
+
output_file="reporte.json",
|
|
164
|
+
)
|
|
165
|
+
print(f"Reporte guardado: {report}")
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
## Uso desde CLI
|
|
171
|
+
|
|
172
|
+
El paquete instala el comando `spriteworkflow` con un subcomando `build` que
|
|
173
|
+
encadena el pipeline completo:
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
spriteworkflow build <video> [opciones]
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### Argumentos
|
|
180
|
+
|
|
181
|
+
| Argumento / Flag | Descripción | Default |
|
|
182
|
+
|-------------------------|-----------------------------------------------|-------------------------|
|
|
183
|
+
| `video` | Ruta al video de entrada (requerido) | — |
|
|
184
|
+
| `--output`, `-o` | Ruta del spritesheet generado | `spritesheet.png` |
|
|
185
|
+
| `--layout` | Lineal o grid (`lineal`, `grid`) | `lineal` |
|
|
186
|
+
| `--columns` | Columnas para grilla (auto si no se indica) | auto `ceil(sqrt(N))` |
|
|
187
|
+
| `--padding` | Píxeles de separación entre celdas | `0` |
|
|
188
|
+
| `--matte` | Activa remoción de fondo por chroma-key | desactivado |
|
|
189
|
+
| `--bg-color` | RGB para chroma-key, ej: `--bg-color 0 255 0`| auto-detectado |
|
|
190
|
+
| `--tolerance` | Tolerancia euclídea de chroma-key | `30` |
|
|
191
|
+
| `--feather` | Difuminado del borde del chroma-key | `0` |
|
|
192
|
+
| `--report-file` | Ruta del reporte JSON de validación | no se genera |
|
|
193
|
+
| `--temp-dir` | Directorio temporal para fotogramas extraídos | `temp` |
|
|
194
|
+
|
|
195
|
+
### Ejemplos
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
# Pipeline mínimo: extraer y ensamblar spritesheet lineal
|
|
199
|
+
spriteworkflow build partida.mp4
|
|
200
|
+
|
|
201
|
+
# Especificar ruta de salida
|
|
202
|
+
spriteworkflow build partida.mp4 -o assets/hoja.png
|
|
203
|
+
|
|
204
|
+
# Spritesheet en grilla de 4 columnas con padding
|
|
205
|
+
spriteworkflow build partida.mp4 --layout grid --columns 4 --padding 2
|
|
206
|
+
|
|
207
|
+
# Remover chroma-key verde, luego ensamblar spritesheet
|
|
208
|
+
spriteworkflow build partida.mp4 --matte --bg-color 0 255 0
|
|
209
|
+
|
|
210
|
+
# Pipeline completo con reporte
|
|
211
|
+
spriteworkflow build partida.mp4 \
|
|
212
|
+
--layout grid --columns 4 --padding 2 \
|
|
213
|
+
--matte --tolerance 40 \
|
|
214
|
+
--report-file reporte.json
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## Ejecutar pruebas
|
|
218
|
+
|
|
219
|
+
El proyecto usa `pytest`. Para ejecutar la suite completa:
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
pip install -e ".[test]"
|
|
223
|
+
pytest -v
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
Para ejecutar un archivo de pruebas específico:
|
|
227
|
+
|
|
228
|
+
```bash
|
|
229
|
+
pytest tests/cli_test.py -v
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
---
|
|
233
|
+
|
|
234
|
+
## Licencia
|
|
235
|
+
|
|
236
|
+
MIT
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
# SpriteWorkflow
|
|
2
|
+
|
|
3
|
+
Biblioteca Python para convertir videos en spritesheets (hojas de sprites).
|
|
4
|
+
Extrae fotogramas de un video, opcionalmente remueve el fondo por chroma-key,
|
|
5
|
+
y los ensambla en un spritesheet lineal (horizontal) o en cuadrícula (grid).
|
|
6
|
+
Incluye un reporte de validación en formato JSON.
|
|
7
|
+
|
|
8
|
+
## Instalación
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
pip install spriteworkflow
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Requiere **Python ≥ 3.10** y dependencias: `opencv-python`, `pillow`, `imageio-ffmpeg`.
|
|
15
|
+
|
|
16
|
+
### Dependencias de sistema
|
|
17
|
+
|
|
18
|
+
- **FFmpeg**: necesario para la extracción de fotogramas. La biblioteca lo
|
|
19
|
+
localiza automáticamente con `imageio-ffmpeg`, pero si no está disponible
|
|
20
|
+
puedes instalarlo manualmente:
|
|
21
|
+
- Windows: `winget install ffmpeg`
|
|
22
|
+
- macOS: `brew install ffmpeg`
|
|
23
|
+
- Linux: `sudo apt install ffmpeg`
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## Funciones de la biblioteca
|
|
28
|
+
|
|
29
|
+
### `extract_frames(video_name, output_dir="temp")`
|
|
30
|
+
|
|
31
|
+
Extrae fotogramas de un video en archivos PNG numerados.
|
|
32
|
+
|
|
33
|
+
| Parámetro | Tipo | Default | Descripción |
|
|
34
|
+
|----------------|-------------------|-----------|------------------------------------------|
|
|
35
|
+
| `video_name` | `str` o `Path` | — | Ruta al archivo de video |
|
|
36
|
+
| `output_dir` | `str` o `Path` | `"temp"` | Directorio de salida (se crea si no existe) |
|
|
37
|
+
|
|
38
|
+
- **Retorna**: `list[Path]` — rutas a los PNG extraídos, ordenados.
|
|
39
|
+
- **Excepciones**: `FileNotFoundError` (video no existe),
|
|
40
|
+
`ValueError` (archivo inválido o vacío), `PermissionError` (sin permiso),
|
|
41
|
+
`RuntimeError` (FFmpeg falla o no se extrajeron fotogramas).
|
|
42
|
+
|
|
43
|
+
### `remove_background(frames=None, frames_dir=None, bg_color=None, tolerance=30, feather=0, output_dir="matted")`
|
|
44
|
+
|
|
45
|
+
Elimina el fondo de fotogramas mediante chroma-key (distancia euclidiana en RGB).
|
|
46
|
+
|
|
47
|
+
| Parámetro | Tipo | Default | Descripción |
|
|
48
|
+
|---------------|-------------------|-------------|------------------------------------------------|
|
|
49
|
+
| `frames` | `list[Path]` | `None` | Lista de rutas a los fotogramas PNG |
|
|
50
|
+
| `frames_dir` | `str` o `Path` | `None` | Directorio con PNG (alternativa a `frames`) |
|
|
51
|
+
| `bg_color` | `tuple[int,int,int]` | `None` | RGB del chroma-key; auto-detectado si es `None`|
|
|
52
|
+
| `tolerance` | `int` | `30` | Distancia euclídea máxima del color de fondo |
|
|
53
|
+
| `feather` | `int` | `0` | Ancho del difuminado lineal alrededor de `tolerance`|
|
|
54
|
+
| `output_dir` | `str` o `Path` | `"matted"` | Directorio para los PNG con canal alpha |
|
|
55
|
+
|
|
56
|
+
- **Retorna**: `list[Path]` — rutas a los PNG procesados (RGBA), ordenados.
|
|
57
|
+
- **Excepciones**: `ValueError` (parámetros inválidos),
|
|
58
|
+
`FileNotFoundError` (`frames_dir` no existe),
|
|
59
|
+
`NotADirectoryError` (`frames_dir` no es directorio).
|
|
60
|
+
|
|
61
|
+
### `create_spritesheet_lineal(frames=None, frames_dir=None, output_file="spritesheet.png")`
|
|
62
|
+
|
|
63
|
+
Ensambla fotogramas en un spritesheet horizontal (una fila).
|
|
64
|
+
|
|
65
|
+
| Parámetro | Tipo | Default | Descripción |
|
|
66
|
+
|----------------|-------------------|----------------------|------------------------------------------|
|
|
67
|
+
| `frames` | `list[Path]` | `None` | Lista de rutas a los fotogramas PNG |
|
|
68
|
+
| `frames_dir` | `str` o `Path` | `None` | Directorio con PNG (alternativa a `frames`)|
|
|
69
|
+
| `output_file` | `str` o `Path` | `"spritesheet.png"` | Ruta del spritesheet generado |
|
|
70
|
+
|
|
71
|
+
- **Retorna**: `Path` — ruta al archivo generado.
|
|
72
|
+
- **Excepciones**: `ValueError`, `FileNotFoundError`, `NotADirectoryError`.
|
|
73
|
+
|
|
74
|
+
### `create_spritesheet_grid(frames=None, frames_dir=None, columns=None, padding=0, background=(0,0,0,0), output_file="spritesheet_grid.png")`
|
|
75
|
+
|
|
76
|
+
Ensambla fotogramas en un spritesheet en cuadrícula (filas × columnas).
|
|
77
|
+
|
|
78
|
+
| Parámetro | Tipo | Default | Descripción |
|
|
79
|
+
|----------------|--------------------|----------------------------|------------------------------------------|
|
|
80
|
+
| `frames` | `list[Path]` | `None` | Lista de rutas a los fotogramas PNG |
|
|
81
|
+
| `frames_dir` | `str` o `Path` | `None` | Directorio con PNG (alternativa a `frames`)|
|
|
82
|
+
| `columns` | `int` o `None` | `None` | N° de columnas; `None` = `ceil(sqrt(N))`|
|
|
83
|
+
| `padding` | `int` | `0` | Píxeles de espacio entre celdas |
|
|
84
|
+
| `background` | `tuple[int,int,int,int]` | `(0,0,0,0)` | RGBA de relleno para celdas vacías |
|
|
85
|
+
| `output_file` | `str` o `Path` | `"spritesheet_grid.png"` | Ruta del spritesheet generado |
|
|
86
|
+
|
|
87
|
+
- **Retorna**: `Path` — ruta al archivo generado.
|
|
88
|
+
- **Excepciones**: `ValueError`, `FileNotFoundError`, `NotADirectoryError`.
|
|
89
|
+
|
|
90
|
+
### `generate_report(frames=None, frames_dir=None, spritesheet_path=None, output_file="report.json")`
|
|
91
|
+
|
|
92
|
+
Inspecciona fotogramas y produce un reporte de validación JSON.
|
|
93
|
+
|
|
94
|
+
| Parámetro | Tipo | Default | Descripción |
|
|
95
|
+
|--------------------|-------------------|----------------|------------------------------------------|
|
|
96
|
+
| `frames` | `list[Path]` | `None` | Lista de rutas a los fotogramas PNG |
|
|
97
|
+
| `frames_dir` | `str` o `Path` | `None` | Directorio con PNG (alternativa) |
|
|
98
|
+
| `spritesheet_path` | `str` o `Path` | `None` | Ruta al spritesheet (opcional) |
|
|
99
|
+
| `output_file` | `str` o `Path` | `"report.json"`| Ruta del archivo JSON generado |
|
|
100
|
+
|
|
101
|
+
- **Retorna**: `Path` — ruta al archivo JSON.
|
|
102
|
+
- **Excepciones**: `ValueError`, `FileNotFoundError`, `NotADirectoryError`.
|
|
103
|
+
|
|
104
|
+
El reporte incluye: `total_frames`, `frames[]` (archivo, ancho, alto),
|
|
105
|
+
`consistent_dimensions`, `reference_size`, `mismatched_frames`,
|
|
106
|
+
`spritesheet_path`, `spritesheet_size`, y `generated_at`.
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
## Ejemplo de uso (como biblioteca)
|
|
111
|
+
|
|
112
|
+
```python
|
|
113
|
+
from spriteworkflow import extract_frames, remove_background
|
|
114
|
+
from spriteworkflow import create_spritesheet_grid, generate_report
|
|
115
|
+
|
|
116
|
+
# 1. Extraer fotogramas de un video
|
|
117
|
+
frames = extract_frames("gameplay.mp4", output_dir="temp")
|
|
118
|
+
print(f"Extraídos {len(frames)} fotogramas")
|
|
119
|
+
|
|
120
|
+
# 2. Remover fondo verde (chroma-key)
|
|
121
|
+
frames_matted = remove_background(
|
|
122
|
+
frames=frames,
|
|
123
|
+
bg_color=(0, 255, 0),
|
|
124
|
+
tolerance=40,
|
|
125
|
+
output_dir="matted",
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
# 3. Crear spritesheet en grilla (3 columnas)
|
|
129
|
+
sheet = create_spritesheet_grid(
|
|
130
|
+
frames=frames_matted,
|
|
131
|
+
columns=3,
|
|
132
|
+
padding=2,
|
|
133
|
+
background=(0, 0, 0, 0),
|
|
134
|
+
output_file="hoja_sprites.png",
|
|
135
|
+
)
|
|
136
|
+
print(f"Spritesheet guardado: {sheet}")
|
|
137
|
+
|
|
138
|
+
# 4. Generar reporte de validación
|
|
139
|
+
report = generate_report(
|
|
140
|
+
frames=frames_matted,
|
|
141
|
+
spritesheet_path=sheet,
|
|
142
|
+
output_file="reporte.json",
|
|
143
|
+
)
|
|
144
|
+
print(f"Reporte guardado: {report}")
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
## Uso desde CLI
|
|
150
|
+
|
|
151
|
+
El paquete instala el comando `spriteworkflow` con un subcomando `build` que
|
|
152
|
+
encadena el pipeline completo:
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
spriteworkflow build <video> [opciones]
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### Argumentos
|
|
159
|
+
|
|
160
|
+
| Argumento / Flag | Descripción | Default |
|
|
161
|
+
|-------------------------|-----------------------------------------------|-------------------------|
|
|
162
|
+
| `video` | Ruta al video de entrada (requerido) | — |
|
|
163
|
+
| `--output`, `-o` | Ruta del spritesheet generado | `spritesheet.png` |
|
|
164
|
+
| `--layout` | Lineal o grid (`lineal`, `grid`) | `lineal` |
|
|
165
|
+
| `--columns` | Columnas para grilla (auto si no se indica) | auto `ceil(sqrt(N))` |
|
|
166
|
+
| `--padding` | Píxeles de separación entre celdas | `0` |
|
|
167
|
+
| `--matte` | Activa remoción de fondo por chroma-key | desactivado |
|
|
168
|
+
| `--bg-color` | RGB para chroma-key, ej: `--bg-color 0 255 0`| auto-detectado |
|
|
169
|
+
| `--tolerance` | Tolerancia euclídea de chroma-key | `30` |
|
|
170
|
+
| `--feather` | Difuminado del borde del chroma-key | `0` |
|
|
171
|
+
| `--report-file` | Ruta del reporte JSON de validación | no se genera |
|
|
172
|
+
| `--temp-dir` | Directorio temporal para fotogramas extraídos | `temp` |
|
|
173
|
+
|
|
174
|
+
### Ejemplos
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
# Pipeline mínimo: extraer y ensamblar spritesheet lineal
|
|
178
|
+
spriteworkflow build partida.mp4
|
|
179
|
+
|
|
180
|
+
# Especificar ruta de salida
|
|
181
|
+
spriteworkflow build partida.mp4 -o assets/hoja.png
|
|
182
|
+
|
|
183
|
+
# Spritesheet en grilla de 4 columnas con padding
|
|
184
|
+
spriteworkflow build partida.mp4 --layout grid --columns 4 --padding 2
|
|
185
|
+
|
|
186
|
+
# Remover chroma-key verde, luego ensamblar spritesheet
|
|
187
|
+
spriteworkflow build partida.mp4 --matte --bg-color 0 255 0
|
|
188
|
+
|
|
189
|
+
# Pipeline completo con reporte
|
|
190
|
+
spriteworkflow build partida.mp4 \
|
|
191
|
+
--layout grid --columns 4 --padding 2 \
|
|
192
|
+
--matte --tolerance 40 \
|
|
193
|
+
--report-file reporte.json
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## Ejecutar pruebas
|
|
197
|
+
|
|
198
|
+
El proyecto usa `pytest`. Para ejecutar la suite completa:
|
|
199
|
+
|
|
200
|
+
```bash
|
|
201
|
+
pip install -e ".[test]"
|
|
202
|
+
pytest -v
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
Para ejecutar un archivo de pruebas específico:
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
pytest tests/cli_test.py -v
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
213
|
+
## Licencia
|
|
214
|
+
|
|
215
|
+
MIT
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "spriteworkflow"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Simple video to spritesheet workflow library."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Programming Language :: Python :: 3",
|
|
15
|
+
"Operating System :: OS Independent",
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
authors = [
|
|
19
|
+
{ name = "jhonvillanueva-hash", email = "jhon.villanueva.lozano.v@gmail.com" }
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
dependencies = [
|
|
23
|
+
"opencv-python>=4.8.0",
|
|
24
|
+
"pillow>=10.0.0",
|
|
25
|
+
"imageio-ffmpeg>=0.6.0"
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
[project.optional-dependencies]
|
|
29
|
+
test = ["pytest>=7.0"]
|
|
30
|
+
dev = ["pytest>=7.0"]
|
|
31
|
+
|
|
32
|
+
[project.urls]
|
|
33
|
+
Homepage = "https://github.com/jhonvillanueva-hash/spriteworkflow"
|
|
34
|
+
|
|
35
|
+
[project.scripts]
|
|
36
|
+
spriteworkflow = "spriteworkflow.cli:main"
|
|
37
|
+
|
|
38
|
+
[tool.setuptools.packages.find]
|
|
39
|
+
include = ["spriteworkflow"]
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""SpriteWorkflow — convert video frames into linear spritesheets.
|
|
2
|
+
|
|
3
|
+
Provides :func:`extract_frames` (extract frames from video via FFmpeg),
|
|
4
|
+
:func:`create_spritesheet_lineal` (stitch frames into a horizontal
|
|
5
|
+
spritesheet), :func:`remove_background` (chroma-key background removal
|
|
6
|
+
on frames), :func:`create_spritesheet_grid` (arrange frames in a
|
|
7
|
+
rows × columns grid), and :func:`generate_report` (inspect frames and
|
|
8
|
+
produce a JSON validation report).
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from .extractor import extract_frames
|
|
12
|
+
from .spritesheet_lineal import create_spritesheet_lineal
|
|
13
|
+
from .matte import remove_background
|
|
14
|
+
from .spritesheet_grid import create_spritesheet_grid
|
|
15
|
+
from .report import generate_report
|
|
16
|
+
|
|
17
|
+
__all__ = [
|
|
18
|
+
"extract_frames",
|
|
19
|
+
"create_spritesheet_lineal",
|
|
20
|
+
"remove_background",
|
|
21
|
+
"create_spritesheet_grid",
|
|
22
|
+
"generate_report",
|
|
23
|
+
]
|