Skip to content

Commit

Permalink
major overhaul (#5)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
oclyke authored Nov 29, 2023
1 parent 79f2f74 commit 2fbffcb
Show file tree
Hide file tree
Showing 64 changed files with 2,564 additions and 1,578 deletions.
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,58 @@
![popsicgl](./docs/assets/popsicgl.WEBP)

# pysicgl

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

both projects are young and would benefit from community involvement.

# getting started as a developer

**get submodules**

```bash
git submodule update --init --recursive
```

**set up the python environment**

* remove any existing virtual environment
* create a new virtual environment
* activate the virtual environment
* install development dependencies

```bash
rm -rf venv
python3 -m venv venv # use your Python 3 interpreter
source venv/bin/activate
pip install -r requirements.dev.txt
```

**build and develop pysicl**

```bash
python setup.py build
python setup.py develop
```

**run tests and install**

```bash
python -m pytest
python setup.py test
python setup.py install
```

# formatting

```
source venv/bin/activate
./scripts/third-party/run-clang-format/run-clang-format.py -r include src
black .
```

# design choices

## color sequences

color sequences are immutable. side effects are not allowed.
Binary file added docs/assets/popsicgl.WEBP
Binary file not shown.
Binary file added docs/assets/popsicle-bit-art.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion examples/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
display = pysicgl.Interface(display_screen, display_memory)

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

# draw a pixel directly to the interface origin
# the coordinates are given in the interface-relative system
Expand Down
13 changes: 0 additions & 13 deletions include/pysicgl.h

This file was deleted.

14 changes: 0 additions & 14 deletions include/pysicgl/color.h

This file was deleted.

24 changes: 0 additions & 24 deletions include/pysicgl/color_sequence.h

This file was deleted.

7 changes: 0 additions & 7 deletions include/pysicgl/drawing/blit.h

This file was deleted.

7 changes: 0 additions & 7 deletions include/pysicgl/drawing/compose.h

This file was deleted.

7 changes: 0 additions & 7 deletions include/pysicgl/drawing/field.h

This file was deleted.

7 changes: 7 additions & 0 deletions include/pysicgl/submodules/color.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

#define PY_SSIZE_T_CLEAN
#include <Python.h>
// python includes first (clang-format)

PyMODINIT_FUNC PyInit_color(void);
7 changes: 7 additions & 0 deletions include/pysicgl/submodules/composition.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

#define PY_SSIZE_T_CLEAN
#include <Python.h>
// python includes first (clang-format)

PyMODINIT_FUNC PyInit_composition(void);
7 changes: 7 additions & 0 deletions include/pysicgl/submodules/functional.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

#define PY_SSIZE_T_CLEAN
#include <Python.h>
// python includes first (clang-format)

PyMODINIT_FUNC PyInit_functional(void);
8 changes: 8 additions & 0 deletions include/pysicgl/submodules/functional/color.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#define PY_SSIZE_T_CLEAN
#include <Python.h>
// python includes first (clang-format)

PyObject* color_from_rgba(PyObject* self, PyObject* args);
PyObject* color_to_rgba(PyObject* self, PyObject* args);
PyObject* interpolate_color_sequence(
PyObject* self_in, PyObject* args, PyObject* kwds);
5 changes: 5 additions & 0 deletions include/pysicgl/submodules/functional/color_correction.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#define PY_SSIZE_T_CLEAN
#include <Python.h>
// python includes first (clang-format)

PyObject* gamma_correct(PyObject* self, PyObject* args);
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

PyObject* global_pixel(PyObject* self_in, PyObject* args);
PyObject* global_line(PyObject* self_in, PyObject* args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

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

PyObject* interface_compose(PyObject* self_in, PyObject* args);
PyObject* interface_blit(PyObject* self_in, PyObject* args);

PyObject* interface_fill(PyObject* self_in, PyObject* args);
PyObject* interface_pixel(PyObject* self_in, PyObject* args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

PyObject* screen_fill(PyObject* self_in, PyObject* args);
PyObject* screen_pixel(PyObject* self_in, PyObject* args);
Expand Down
8 changes: 8 additions & 0 deletions include/pysicgl/submodules/functional/operations.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#define PY_SSIZE_T_CLEAN
#include <Python.h>
// python includes first (clang-format)

PyObject* scalar_field(PyObject* self_in, PyObject* args, PyObject* kwds);
PyObject* compose(PyObject* self_in, PyObject* args);
PyObject* blit(PyObject* self_in, PyObject* args);
PyObject* scale(PyObject* self_in, PyObject* args);
7 changes: 7 additions & 0 deletions include/pysicgl/submodules/interpolation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

#define PY_SSIZE_T_CLEAN
#include <Python.h>
// python includes first (clang-format)

PyMODINIT_FUNC PyInit_interpolation(void);
20 changes: 20 additions & 0 deletions include/pysicgl/types/color_sequence.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

#define PY_SSIZE_T_CLEAN
#include <Python.h>
// python includes first (clang-format)

#include "pysicgl/types/color_sequence_interpolator.h"
#include "sicgl/color_sequence.h"

// declare the type
extern PyTypeObject ColorSequenceType;

typedef struct {
PyObject_HEAD color_sequence_t sequence;
ColorSequenceInterpolatorObject* interpolator;

// iterator state
// protected by the GIL
size_t iterator_index;
} ColorSequenceObject;
18 changes: 18 additions & 0 deletions include/pysicgl/types/color_sequence_interpolator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#define PY_SSIZE_T_CLEAN
#include <Python.h>
// python includes first (clang-format)

#include "sicgl/color_sequence.h"

// declare the type
extern PyTypeObject ColorSequenceInterpolatorType;

typedef struct {
PyObject_HEAD sequence_map_fn fn;
void* args;
} ColorSequenceInterpolatorObject;

ColorSequenceInterpolatorObject* new_color_sequence_interpolator_object(
sequence_map_fn fn, void* args);
23 changes: 23 additions & 0 deletions include/pysicgl/types/compositor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

#define PY_SSIZE_T_CLEAN
#include <Python.h>
// python includes first (clang-format)

#include <stdbool.h>

#include "sicgl/compose.h"
#include "sicgl/compositors.h"

// declare the type
extern PyTypeObject CompositorType;

typedef struct {
PyObject_HEAD
/* Type-specific fields go here. */
compositor_fn fn;
void* args;
} CompositorObject;

// public constructors
CompositorObject* new_compositor_object(compositor_fn fn, void* args);
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

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

#include "pysicgl/screen.h"
#include "pysicgl/types/screen.h"
#include "sicgl/interface.h"
#include "sicgl/screen.h"

Expand All @@ -18,8 +18,8 @@ typedef struct {

// a ScreenObject which is linked to
// the interface screen by reference
ScreenObject* _screen;
ScreenObject* screen;

// a buffer backs up the interface memory
Py_buffer _memory_buffer;
Py_buffer memory_buffer;
} InterfaceObject;
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@

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

#include "sicgl/field.h"

// declare the type
extern PyTypeObject ScalarFieldType;

typedef struct {
PyObject_HEAD Py_buffer _scalars_buffer;
PyObject_HEAD double* scalars;
size_t length;
} ScalarFieldObject;

int scalar_field_get_scalars(
ScalarFieldObject* self, size_t* len, double** scalars);
7 changes: 2 additions & 5 deletions include/pysicgl/screen.h → include/pysicgl/types/screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

#include <stdbool.h>

Expand All @@ -18,8 +18,5 @@ typedef struct {
screen_t _screen;

// a flag to explicitly indicate whether this is an object or reference
bool _is_reference;
bool is_reference;
} ScreenObject;

// publicly accessible constructors
ScreenObject* new_screen_object(screen_t* ref);
9 changes: 0 additions & 9 deletions include/pysicgl/utilities.h

This file was deleted.

1 change: 1 addition & 0 deletions packages/pysicgl/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from ._core import *
1 change: 1 addition & 0 deletions requirements.dev.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
black >= 22.12.0, < 23.0.0
pytest >= 7.2.1, < 8.0.0
setuptools >= 67.0.0, < 68.0.0
sphinx >= 6.1.3, < 7.0.0
Loading

0 comments on commit 2fbffcb

Please sign in to comment.