Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ blend2d/*.so
src/*.c
*.py[cd]
*.png

dist
2 changes: 1 addition & 1 deletion 3rdparty/asmjit
Submodule asmjit updated 221 files
2 changes: 1 addition & 1 deletion 3rdparty/blend2d
Submodule blend2d updated 496 files
22 changes: 19 additions & 3 deletions blend2d/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,23 @@
from __future__ import absolute_import

from ._capi import (
Array, ArrayType, CompOp, ConicalGradient, Context, ExtendMode, Font,
Format, Image, LinearGradient, Matrix2D, Path, Pattern, RadialGradient,
Rect, RectI, Region, StrokeCap, StrokeCapPosition, StrokeJoin
Array,
ArrayType,
CompOp,
ConicalGradient,
Context,
ExtendMode,
Font,
Format,
Image,
LinearGradient,
Matrix2D,
Path,
Pattern,
RadialGradient,
Rect,
RectI,
StrokeCap,
StrokeCapPosition,
StrokeJoin,
)
4 changes: 1 addition & 3 deletions blend2d/tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from __future__ import (
absolute_import, division, print_function, unicode_literals
)
from __future__ import absolute_import, division, print_function, unicode_literals

import unittest

Expand Down
56 changes: 25 additions & 31 deletions ci/edm_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@
import click

DEPENDENCIES = {
'cython',
'numpy',
"cython",
"numpy",
}
CONFIG_FILE = os.path.abspath(
os.path.join(os.path.dirname(__file__), '.edm.yaml')
)
CONFIG_FILE = os.path.abspath(os.path.join(os.path.dirname(__file__), ".edm.yaml"))


@click.group()
Expand All @@ -32,13 +30,12 @@ def cli():


@cli.command()
@click.option('--runtime', default='3.6')
@click.option('--environment', default=None)
@click.option("--runtime", default="3.6")
@click.option("--environment", default=None)
def install(runtime, environment):
""" Install project and dependencies into a clean EDM environment.
"""
"""Install project and dependencies into a clean EDM environment."""
parameters = get_parameters(runtime, environment)
parameters['packages'] = ' '.join(DEPENDENCIES)
parameters["packages"] = " ".join(DEPENDENCIES)
# edm commands to setup the development environment
commands = [
"{edm} environments create {environment} --force --version={runtime}",
Expand All @@ -48,56 +45,53 @@ def install(runtime, environment):
]
click.echo("Creating environment '{environment}'".format(**parameters))
execute(commands, parameters)
click.echo('Done install')
click.echo("Done install")


@cli.command()
@click.option('--runtime', default='3.6')
@click.option('--environment', default=None)
@click.option("--runtime", default="3.6")
@click.option("--environment", default=None)
def test(runtime, environment):
""" Run the test suite in a given environment with the specified toolkit.
"""
"""Run the test suite in a given environment with the specified toolkit."""
parameters = get_parameters(runtime, environment)
environ = {'PYTHONUNBUFFERED': '1'}
commands = [
"edm run -e {environment} -- python -m unittest discover blend2d"
]
environ = {"PYTHONUNBUFFERED": "1"}
commands = ["edm run -e {environment} -- python -m unittest discover blend2d"]

click.echo("Running tests in '{environment}'".format(**parameters))
os.environ.update(environ)
execute(commands, parameters)
click.echo('Done test')
click.echo("Done test")


@cli.command()
@click.option('--runtime', default='3.6')
@click.option('--environment', default=None)
@click.option("--runtime", default="3.6")
@click.option("--environment", default=None)
def cleanup(runtime, environment):
""" Remove a development environment.
"""
"""Remove a development environment."""
parameters = get_parameters(runtime, environment)
commands = [
"edm run -e {environment} -- python setup.py clean",
"edm environments remove {environment} --purge -y",
]
click.echo("Cleaning up environment '{environment}'".format(**parameters))
execute(commands, parameters)
click.echo('Done cleanup')
click.echo("Done cleanup")


# ----------------------------------------------------------------------------
# Utility routines
# ----------------------------------------------------------------------------


def get_parameters(runtime, environment):
""" Set up parameters dictionary for format() substitution """
"""Set up parameters dictionary for format() substitution"""
parameters = {
'runtime': runtime,
'environment': environment,
'edm': 'edm --config {}'.format(CONFIG_FILE),
"runtime": runtime,
"environment": environment,
"edm": "edm --config {}".format(CONFIG_FILE),
}
if environment is None:
parameters['environment'] = 'blend2d-{runtime}'.format(**parameters)
parameters["environment"] = "blend2d-{runtime}".format(**parameters)
return parameters


Expand All @@ -110,5 +104,5 @@ def execute(commands, parameters):
sys.exit(1)


if __name__ == '__main__':
if __name__ == "__main__":
cli()
8 changes: 4 additions & 4 deletions examples/gradient.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import numpy as np
from skimage.io import imsave

if __name__ == '__main__':
if __name__ == "__main__":
array = np.empty((256, 256, 4), dtype=np.uint8)
image = blend2d.Image(array)
context = blend2d.Context(image)
Expand All @@ -17,10 +17,10 @@
context.fill_all()

circle = blend2d.Path()
circle.ellipse(128, 128, 64, 64)
circle.add_ellipse(128, 128, 64, 64)

context.set_comp_op(blend2d.CompOp.EXCLUSION)
context.set_fill_style((0.0, 1.0, 1.0))
context.fill_path(circle)
context.fill_path((0, 0), circle)

imsave('gradient.png', array)
imsave("gradient.png", array)
10 changes: 5 additions & 5 deletions examples/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@ def random_lines(context, width, height):
path.reset()
path.move_to(x0, y0)
path.line_to(x1, y1)
context.stroke_path(path)
context.stroke_path((0, 0), path)


if __name__ == '__main__':
if __name__ == "__main__":
image_array = np.empty((256, 256, 4), dtype=np.uint8)
image = blend2d.Image(image_array)
image_context = blend2d.Context(image)
random_lines(image_context, 256, 256)

array = np.empty((512, 512, 4), dtype=np.uint8)
context = blend2d.Context(blend2d.Image(array))
context.clear()
context.clear_all()

src = blend2d.Rect(0, 0, *image_array.shape[:2])
dst = blend2d.Rect(0, 0, 100, 100)
context.blit_scaled_image(dst, image, src)

context.rotate(-np.pi/12)
context.rotate(-np.pi / 12)
context.blit_image((10.0, 100.0), image, src)

imsave('image.png', array)
imsave("image.png", array)
14 changes: 6 additions & 8 deletions examples/lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@
from skimage.color import hsv2rgb
from skimage.io import imsave

if __name__ == '__main__':
if __name__ == "__main__":
array = np.empty((500, 500, 4), dtype=np.uint8)
image = blend2d.Image(array)
canvas = blend2d.Context(image)

canvas.clear()
canvas.clear_all()
canvas.set_stroke_width(20.0)

path = blend2d.Path()
path.move_to(100, 0)
path.quadric_to(125, 25, 250, 0)
path.quadric_to(375, -25, 400, 0)
path.quadric_to(25, 25, 150, 0)
path.quadric_to(275, -25, 300, 0)

caps = {
blend2d.StrokeCap.CAP_BUTT,
Expand All @@ -30,7 +29,6 @@
color = hsv2rgb([[i / len(caps), 0.75, 0.75]])[0]
canvas.set_stroke_style(color)
canvas.set_stroke_caps(cap)
canvas.translate(0, (i + 1) * 75)
canvas.stroke_path(path)
canvas.stroke_path((100, (i + 1) * 75), path)

imsave('lines.png', array)
imsave("lines.png", array)
16 changes: 7 additions & 9 deletions examples/pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,28 @@ def random_lines(context, width, height):
path.reset()
path.move_to(x0, y0)
path.line_to(x1, y1)
context.stroke_path(path)
context.stroke_path((0, 0), path)


if __name__ == '__main__':
if __name__ == "__main__":
pattern_image = blend2d.Image(np.empty((256, 256, 4), dtype=np.uint8))
pattern_context = blend2d.Context(pattern_image)
random_lines(pattern_context, 256, 256)

array = np.empty((512, 512, 4), dtype=np.uint8)
image = blend2d.Image(array)
context = blend2d.Context(image)
context.clear()
context.clear_all()

area = blend2d.RectI(0, 0, 256, 256)
matrix = blend2d.Matrix2D()
matrix.rotate(128.0, 128.0, 45.0)
matrix.scale(0.25, 0.25)
pattern = blend2d.Pattern(
pattern_image, area, blend2d.ExtendMode.REPEAT, matrix
)
pattern = blend2d.Pattern(pattern_image, area, blend2d.ExtendMode.REPEAT, matrix)
context.set_fill_style(pattern)

circle = blend2d.Path()
circle.ellipse(256, 256, 200, 200)
context.fill_path(circle)
circle.add_ellipse(256, 256, 200, 200)
context.fill_path((0, 0), circle)

imsave('pattern.png', array)
imsave("pattern.png", array)
28 changes: 15 additions & 13 deletions examples/spiral.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ def spiral(size, hue, sat, val):
image = blend2d.Image(array)
canvas = blend2d.Context(image)
circle = blend2d.Path()
circle.ellipse(0, 0, CIRCLE_SIZE, CIRCLE_SIZE)
circle.add_ellipse(0, 0, CIRCLE_SIZE, CIRCLE_SIZE)

divisions = np.linspace(0, 2*np.pi, CIRCLE_COUNT, endpoint=False)
divisions = np.linspace(0, 2 * np.pi, CIRCLE_COUNT, endpoint=False)
centers = np.stack((np.cos(divisions), np.sin(divisions)), axis=1)
offsets = compute_offsets(np.sqrt(size[0]**2 + size[1]**2) / 2)
offsets = compute_offsets(np.sqrt(size[0] ** 2 + size[1] ** 2) / 2)
color_count = len(offsets)

hsv = np.ones((color_count, 1, 3))
Expand All @@ -45,7 +45,7 @@ def spiral(size, hue, sat, val):
hsv[:, 0, 2] = np.linspace(val[0], val[1], color_count, endpoint=False)
spectrum = hsv2rgb(hsv).reshape(color_count, 3)

canvas.clear() # fill with black
canvas.clear_all() # fill with black
for idx, offset in enumerate(offsets):
canvas.set_fill_style(spectrum[idx])
radius = np.pi * offset / CIRCLE_COUNT
Expand All @@ -54,22 +54,24 @@ def spiral(size, hue, sat, val):
if ((idx + i) % 2) == 0:
continue
canvas.reset_matrix()
canvas.translate(size[0]/2 + offset*centers[i, 0],
size[1]/2 + offset*centers[i, 1])
canvas.translate(
size[0] / 2 + offset * centers[i, 0],
size[1] / 2 + offset * centers[i, 1],
)
canvas.scale(scale, scale)
canvas.fill_path(circle)
canvas.fill_path((0, 0), circle)

# BGRA -> RGBA
array[:, :, [0, 1, 2]] = array[:, :, [2, 1, 0]]
imsave('spiral.png', array)
imsave("spiral.png", array)


if __name__ == '__main__':
if __name__ == "__main__":
p = argparse.ArgumentParser()
p.add_argument('-z', '--size', nargs=2, default=[1000, 1000])
p.add_argument('-u', '--hue', nargs=2, default=[0.0, 1.0])
p.add_argument('-s', '--sat', nargs=2, default=[0.95, 0.95])
p.add_argument('-v', '--val', nargs=2, default=[0.85, 0.85])
p.add_argument("-z", "--size", nargs=2, default=[1000, 1000])
p.add_argument("-u", "--hue", nargs=2, default=[0.0, 1.0])
p.add_argument("-s", "--sat", nargs=2, default=[0.95, 0.95])
p.add_argument("-v", "--val", nargs=2, default=[0.85, 0.85])
args = p.parse_args()
size = tuple(int(a) for a in args.size)
hue = tuple(float(a) for a in args.hue)
Expand Down
12 changes: 6 additions & 6 deletions examples/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
import numpy as np
from skimage.io import imsave

if __name__ == '__main__':
if __name__ == "__main__":
array = np.empty((500, 500, 4), dtype=np.uint8)
image = blend2d.Image(array)
canvas = blend2d.Context(image)

canvas.clear()
canvas.clear_all()
canvas.set_fill_style((1.0, 1.0, 1.0))

text = u'Hello World!'
font = blend2d.Font('/Library/Fonts/Skia.ttf', 50)
text = "Hello World!"
font = blend2d.Font("/Library/Fonts/Skia.ttf", 50)
canvas.fill_text((100, 100), font, text)

imsave('text.png', array)
array[:, :, 3] = 255
imsave("text.png", array)
Loading