Skip to content
Open
Show file tree
Hide file tree
Changes from 8 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
2 changes: 1 addition & 1 deletion blend2d/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@
from ._capi import (
Array, ArrayType, CompOp, ConicalGradient, Context, ExtendMode, Font,
Format, Image, LinearGradient, Matrix2D, Path, Pattern, RadialGradient,
Rect, RectI, Region, StrokeCap, StrokeCapPosition, StrokeJoin
Rect, RectI, StrokeCap, StrokeCapPosition, StrokeJoin
)
8 changes: 4 additions & 4 deletions examples/gradient.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import blend2d
import numpy as np
from skimage.io import imsave
import matplotlib.pyplot as plt

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)

imsave('gradient.png', array)
plt.imshow(array)
10 changes: 5 additions & 5 deletions examples/image.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import blend2d
import numpy as np
from skimage.io import imsave
import matplotlib.pyplot as plt


def random_lines(context, width, height):
Expand All @@ -20,21 +20,21 @@ def random_lines(context, width, height):
context.stroke_path(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)
plt.imshow(array)
12 changes: 6 additions & 6 deletions examples/lines.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import blend2d
import numpy as np
from skimage.color import hsv2rgb
from skimage.io import imsave
import matplotlib.pyplot as plt
from matplotlib.colors import hsv_to_rgb

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()
Expand All @@ -27,10 +27,10 @@

for i, cap in enumerate(caps):
with canvas:
color = hsv2rgb([[i / len(caps), 0.75, 0.75]])[0]
color = hsv_to_rgb([[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)

imsave('lines.png', array)
plt.imshow(array)
10 changes: 5 additions & 5 deletions examples/pattern.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import blend2d
import numpy as np
from skimage.io import imsave
import matplotlib.pyplot as plt


def random_lines(context, width, height):
Expand All @@ -20,15 +20,15 @@ def random_lines(context, width, height):
context.stroke_path(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()
Expand All @@ -40,7 +40,7 @@ def random_lines(context, width, height):
context.set_fill_style(pattern)

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

imsave('pattern.png', array)
plt.imshow(array)
32 changes: 17 additions & 15 deletions examples/spiral.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import argparse

import numpy as np
from skimage.color import hsv2rgb
from skimage.io import imsave
from matplotlib.colors import hsv_to_rgb
import matplotlib.pyplot as plt

import blend2d

Expand Down Expand Up @@ -32,20 +32,20 @@ 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))
hsv[:, 0, 0] = np.linspace(hue[0], hue[1], color_count, endpoint=False)
hsv[:, 0, 1] = np.linspace(sat[0], sat[1], color_count, endpoint=False)
hsv[:, 0, 2] = np.linspace(val[0], val[1], color_count, endpoint=False)
spectrum = hsv2rgb(hsv).reshape(color_count, 3)
spectrum = hsv_to_rgb(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)

# BGRA -> RGBA
array[:, :, [0, 1, 2]] = array[:, :, [2, 1, 0]]
imsave('spiral.png', array)
plt.imshow(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
18 changes: 9 additions & 9 deletions examples/text.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import blend2d
import numpy as np
from skimage.io import imsave
import matplotlib.pyplot as plt

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.set_fill_style((1.0, 1.0, 1.0))
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)
canvas.fill_text((100, 100), font, text)

imsave('text.png', array)
text = "Hello World!"
# font = blend2d.Font("/Library/Fonts/Skia.ttf", 50)
# canvas.fill_text((100, 100), font, text)
array[:, :, 3] = 255
plt.imshow(array)
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from setuptools.command.build_ext import build_ext

# Set to 'Release' when building a release
BUILD_TYPE = 'Debug'
BUILD_TYPE = 'Release'


class CMakeExtension(Extension):
Expand Down Expand Up @@ -69,7 +69,7 @@ def build_extensions(self):
# Config and build the extension
cmd = ['cmake', ext.cmake_lists_dir] + cmake_args
subprocess.check_call(cmd, cwd=tmpdir)
cmd = ['cmake', '--build', '.', '--config', BUILD_TYPE]
cmd = ['cmake', '--build', '.','--parallel','8', '--config', BUILD_TYPE]
subprocess.check_call(cmd, cwd=tmpdir)


Expand Down
Loading