Skip to content

Commit 2fbffcb

Browse files
authored
major overhaul (#5)
* Update sicgl * fix build * setuptools and wrapper for c extension * Update README.md * update sicgl sources list * add compositors module * format * add functional module and pixel get fns * add a lot of docs and stuff * upates fix Py_None ownership error switch to color submodule format * pass all tests * compositors -> compostition * drastic overhaul * Update sequence.c * simplify scalar field * refactor * sorted * format * move interpolation * move core tests * Update color_sequence.h * idk * increase strictness * fix errors with mp_length * add scale utility * format * remove inconsistent leading underscores * update color sequence interpolation architecture * add sic logo
1 parent 79f2f74 commit 2fbffcb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+2564
-1578
lines changed

README.md

+53
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,58 @@
1+
![popsicgl](./docs/assets/popsicgl.WEBP)
2+
13
# pysicgl
24

35
pysicgl is a Python C extension interface for the [sicgl](https://github.com/oclyke/sicgl) graphics library.
46

57
both projects are young and would benefit from community involvement.
8+
9+
# getting started as a developer
10+
11+
**get submodules**
12+
13+
```bash
14+
git submodule update --init --recursive
15+
```
16+
17+
**set up the python environment**
18+
19+
* remove any existing virtual environment
20+
* create a new virtual environment
21+
* activate the virtual environment
22+
* install development dependencies
23+
24+
```bash
25+
rm -rf venv
26+
python3 -m venv venv # use your Python 3 interpreter
27+
source venv/bin/activate
28+
pip install -r requirements.dev.txt
29+
```
30+
31+
**build and develop pysicl**
32+
33+
```bash
34+
python setup.py build
35+
python setup.py develop
36+
```
37+
38+
**run tests and install**
39+
40+
```bash
41+
python -m pytest
42+
python setup.py test
43+
python setup.py install
44+
```
45+
46+
# formatting
47+
48+
```
49+
source venv/bin/activate
50+
./scripts/third-party/run-clang-format/run-clang-format.py -r include src
51+
black .
52+
```
53+
54+
# design choices
55+
56+
## color sequences
57+
58+
color sequences are immutable. side effects are not allowed.

docs/assets/popsicgl.WEBP

176 KB
Binary file not shown.

docs/assets/popsicle-bit-art.png

243 KB
Loading

examples/simple.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
display = pysicgl.Interface(display_screen, display_memory)
1616

1717
# create a orange-red color using a 4-tuple of RGBA components
18-
color = pysicgl.Color.from_rgba((255, 128, 3, 0))
18+
color = pysicgl.color.from_rgba((255, 128, 3, 0))
1919

2020
# draw a pixel directly to the interface origin
2121
# the coordinates are given in the interface-relative system

include/pysicgl.h

-13
This file was deleted.

include/pysicgl/color.h

-14
This file was deleted.

include/pysicgl/color_sequence.h

-24
This file was deleted.

include/pysicgl/drawing/blit.h

-7
This file was deleted.

include/pysicgl/drawing/compose.h

-7
This file was deleted.

include/pysicgl/drawing/field.h

-7
This file was deleted.

include/pysicgl/submodules/color.h

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#pragma once
2+
3+
#define PY_SSIZE_T_CLEAN
4+
#include <Python.h>
5+
// python includes first (clang-format)
6+
7+
PyMODINIT_FUNC PyInit_color(void);
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#pragma once
2+
3+
#define PY_SSIZE_T_CLEAN
4+
#include <Python.h>
5+
// python includes first (clang-format)
6+
7+
PyMODINIT_FUNC PyInit_composition(void);
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#pragma once
2+
3+
#define PY_SSIZE_T_CLEAN
4+
#include <Python.h>
5+
// python includes first (clang-format)
6+
7+
PyMODINIT_FUNC PyInit_functional(void);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#define PY_SSIZE_T_CLEAN
2+
#include <Python.h>
3+
// python includes first (clang-format)
4+
5+
PyObject* color_from_rgba(PyObject* self, PyObject* args);
6+
PyObject* color_to_rgba(PyObject* self, PyObject* args);
7+
PyObject* interpolate_color_sequence(
8+
PyObject* self_in, PyObject* args, PyObject* kwds);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#define PY_SSIZE_T_CLEAN
2+
#include <Python.h>
3+
// python includes first (clang-format)
4+
5+
PyObject* gamma_correct(PyObject* self, PyObject* args);

include/pysicgl/drawing/global.h include/pysicgl/submodules/functional/drawing/global.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#define PY_SSIZE_T_CLEAN
44
#include <Python.h>
5-
// python includes must come first
5+
// python includes first (clang-format)
66

77
PyObject* global_pixel(PyObject* self_in, PyObject* args);
88
PyObject* global_line(PyObject* self_in, PyObject* args);

include/pysicgl/drawing/interface.h include/pysicgl/submodules/functional/drawing/interface.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
#define PY_SSIZE_T_CLEAN
44
#include <Python.h>
5-
// python includes must come first
5+
// python includes first (clang-format)
6+
7+
PyObject* interface_compose(PyObject* self_in, PyObject* args);
8+
PyObject* interface_blit(PyObject* self_in, PyObject* args);
69

710
PyObject* interface_fill(PyObject* self_in, PyObject* args);
811
PyObject* interface_pixel(PyObject* self_in, PyObject* args);

include/pysicgl/drawing/screen.h include/pysicgl/submodules/functional/drawing/screen.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#define PY_SSIZE_T_CLEAN
44
#include <Python.h>
5-
// python includes must come first
5+
// python includes first (clang-format)
66

77
PyObject* screen_fill(PyObject* self_in, PyObject* args);
88
PyObject* screen_pixel(PyObject* self_in, PyObject* args);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#define PY_SSIZE_T_CLEAN
2+
#include <Python.h>
3+
// python includes first (clang-format)
4+
5+
PyObject* scalar_field(PyObject* self_in, PyObject* args, PyObject* kwds);
6+
PyObject* compose(PyObject* self_in, PyObject* args);
7+
PyObject* blit(PyObject* self_in, PyObject* args);
8+
PyObject* scale(PyObject* self_in, PyObject* args);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#pragma once
2+
3+
#define PY_SSIZE_T_CLEAN
4+
#include <Python.h>
5+
// python includes first (clang-format)
6+
7+
PyMODINIT_FUNC PyInit_interpolation(void);
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#pragma once
2+
3+
#define PY_SSIZE_T_CLEAN
4+
#include <Python.h>
5+
// python includes first (clang-format)
6+
7+
#include "pysicgl/types/color_sequence_interpolator.h"
8+
#include "sicgl/color_sequence.h"
9+
10+
// declare the type
11+
extern PyTypeObject ColorSequenceType;
12+
13+
typedef struct {
14+
PyObject_HEAD color_sequence_t sequence;
15+
ColorSequenceInterpolatorObject* interpolator;
16+
17+
// iterator state
18+
// protected by the GIL
19+
size_t iterator_index;
20+
} ColorSequenceObject;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#pragma once
2+
3+
#define PY_SSIZE_T_CLEAN
4+
#include <Python.h>
5+
// python includes first (clang-format)
6+
7+
#include "sicgl/color_sequence.h"
8+
9+
// declare the type
10+
extern PyTypeObject ColorSequenceInterpolatorType;
11+
12+
typedef struct {
13+
PyObject_HEAD sequence_map_fn fn;
14+
void* args;
15+
} ColorSequenceInterpolatorObject;
16+
17+
ColorSequenceInterpolatorObject* new_color_sequence_interpolator_object(
18+
sequence_map_fn fn, void* args);

include/pysicgl/types/compositor.h

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#pragma once
2+
3+
#define PY_SSIZE_T_CLEAN
4+
#include <Python.h>
5+
// python includes first (clang-format)
6+
7+
#include <stdbool.h>
8+
9+
#include "sicgl/compose.h"
10+
#include "sicgl/compositors.h"
11+
12+
// declare the type
13+
extern PyTypeObject CompositorType;
14+
15+
typedef struct {
16+
PyObject_HEAD
17+
/* Type-specific fields go here. */
18+
compositor_fn fn;
19+
void* args;
20+
} CompositorObject;
21+
22+
// public constructors
23+
CompositorObject* new_compositor_object(compositor_fn fn, void* args);

include/pysicgl/interface.h include/pysicgl/types/interface.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
#define PY_SSIZE_T_CLEAN
44
#include <Python.h>
5-
// python includes must come first
5+
// python includes first (clang-format)
66

7-
#include "pysicgl/screen.h"
7+
#include "pysicgl/types/screen.h"
88
#include "sicgl/interface.h"
99
#include "sicgl/screen.h"
1010

@@ -18,8 +18,8 @@ typedef struct {
1818

1919
// a ScreenObject which is linked to
2020
// the interface screen by reference
21-
ScreenObject* _screen;
21+
ScreenObject* screen;
2222

2323
// a buffer backs up the interface memory
24-
Py_buffer _memory_buffer;
24+
Py_buffer memory_buffer;
2525
} InterfaceObject;

include/pysicgl/field.h include/pysicgl/types/scalar_field.h

+3-5
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22

33
#define PY_SSIZE_T_CLEAN
44
#include <Python.h>
5-
// python includes must come first
5+
// python includes first (clang-format)
66

77
#include "sicgl/field.h"
88

99
// declare the type
1010
extern PyTypeObject ScalarFieldType;
1111

1212
typedef struct {
13-
PyObject_HEAD Py_buffer _scalars_buffer;
13+
PyObject_HEAD double* scalars;
14+
size_t length;
1415
} ScalarFieldObject;
15-
16-
int scalar_field_get_scalars(
17-
ScalarFieldObject* self, size_t* len, double** scalars);

include/pysicgl/screen.h include/pysicgl/types/screen.h

+2-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#define PY_SSIZE_T_CLEAN
44
#include <Python.h>
5-
// python includes must come first
5+
// python includes first (clang-format)
66

77
#include <stdbool.h>
88

@@ -18,8 +18,5 @@ typedef struct {
1818
screen_t _screen;
1919

2020
// a flag to explicitly indicate whether this is an object or reference
21-
bool _is_reference;
21+
bool is_reference;
2222
} ScreenObject;
23-
24-
// publicly accessible constructors
25-
ScreenObject* new_screen_object(screen_t* ref);

include/pysicgl/utilities.h

-9
This file was deleted.

packages/pysicgl/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from ._core import *

requirements.dev.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
black >= 22.12.0, < 23.0.0
22
pytest >= 7.2.1, < 8.0.0
3+
setuptools >= 67.0.0, < 68.0.0
34
sphinx >= 6.1.3, < 7.0.0

0 commit comments

Comments
 (0)