diff --git a/setup.py b/setup.py index 7dc924f..2856f69 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name = "pixie-python", - version = "3.0.2", + version = "3.1.4", author = "Andre von Houck", author_email = "starplant@gmail.com", description = "Python bindings for Pixie, a full-featured 2D graphics library", diff --git a/src/pixie/libpixie.dylib b/src/pixie/libpixie.dylib index 2381c89..1723e7d 100755 Binary files a/src/pixie/libpixie.dylib and b/src/pixie/libpixie.dylib differ diff --git a/src/pixie/libpixie.so b/src/pixie/libpixie.so index 384fdaa..3f9ac1b 100755 Binary files a/src/pixie/libpixie.so and b/src/pixie/libpixie.so differ diff --git a/src/pixie/pixie.dll b/src/pixie/pixie.dll index 3789c5a..d61e2da 100644 Binary files a/src/pixie/pixie.dll and b/src/pixie/pixie.dll differ diff --git a/src/pixie/pixie.py b/src/pixie/pixie.py index 7ee1ce4..cdce515 100644 --- a/src/pixie/pixie.py +++ b/src/pixie/pixie.py @@ -22,6 +22,8 @@ class PixieError(Exception): FF_BMP = 1 FF_JPG = 2 FF_GIF = 3 +FF_QOI = 4 +FF_PPM = 5 BlendMode = c_byte BM_NORMAL = 0 @@ -110,14 +112,14 @@ class Matrix3(Structure): ] def __init__(self): - tmp = dll.pixie_matrix_3() + tmp = dll.pixie_matrix3() self.values = tmp.values def __eq__(self, obj): return self.values[0] == obj.values[0] and self.values[1] == obj.values[1] and self.values[2] == obj.values[2] and self.values[3] == obj.values[3] and self.values[4] == obj.values[4] and self.values[5] == obj.values[5] and self.values[6] == obj.values[6] and self.values[7] == obj.values[7] and self.values[8] == obj.values[8] def __mul__(self, b): - result = dll.pixie_matrix_3_mul(self, b) + result = dll.pixie_matrix3_mul(self, b) return result class Rect(Structure): @@ -188,28 +190,28 @@ def __eq__(self, obj): return self.ref == obj.ref def __del__(self): - dll.pixie_seq_float_32_unref(self) + dll.pixie_seq_float32_unref(self) def __init__(self): - self.ref = dll.pixie_new_seq_float_32() + self.ref = dll.pixie_new_seq_float32() def __len__(self): - return dll.pixie_seq_float_32_len(self) + return dll.pixie_seq_float32_len(self) def __getitem__(self, index): - return dll.pixie_seq_float_32_get(self, index) + return dll.pixie_seq_float32_get(self, index) def __setitem__(self, index, value): - dll.pixie_seq_float_32_set(self, index, value) + dll.pixie_seq_float32_set(self, index, value) def __delitem__(self, index): - dll.pixie_seq_float_32_delete(self, index) + dll.pixie_seq_float32_delete(self, index) def append(self, value): - dll.pixie_seq_float_32_add(self, value) + dll.pixie_seq_float32_add(self, value) def clear(self): - dll.pixie_seq_float_32_clear(self) + dll.pixie_seq_float32_clear(self) class SeqSpan(Structure): _fields_ = [("ref", c_ulonglong)] @@ -331,7 +333,7 @@ def set_color(self, x, y, color): def fill(self, color): """ - Fills the image with the parameter color. + Fills the image with the color. """ dll.pixie_image_fill(self, color) @@ -356,20 +358,20 @@ def sub_image(self, x, y, w, h): raise PixieError(take_error()) return result - def minify_by_2(self, power = 1): + def minify_by2(self, power = 1): """ Scales the image down by an integer scale. """ - result = dll.pixie_image_minify_by_2(self, power) + result = dll.pixie_image_minify_by2(self, power) if check_error(): raise PixieError(take_error()) return result - def magnify_by_2(self, power = 1): + def magnify_by2(self, power = 1): """ Scales image up by 2 ^ power. """ - result = dll.pixie_image_magnify_by_2(self, power) + result = dll.pixie_image_magnify_by2(self, power) if check_error(): raise PixieError(take_error()) return result @@ -398,7 +400,7 @@ def blur(self, radius, out_of_bounds = None): def new_mask(self): """ - Returns a new mask using the alpha values of the parameter image. + Returns a new mask using the alpha values of the image. """ result = dll.pixie_image_new_mask(self) if check_error(): @@ -613,24 +615,24 @@ def set_value(self, x, y, value): def fill(self, value): """ - Fills the mask with the parameter value. + Fills the mask with the value. """ dll.pixie_mask_fill(self, value) - def minify_by_2(self, power = 1): + def minify_by2(self, power = 1): """ Scales the mask down by an integer scale. """ - result = dll.pixie_mask_minify_by_2(self, power) + result = dll.pixie_mask_minify_by2(self, power) if check_error(): raise PixieError(take_error()) return result - def magnify_by_2(self, power = 1): + def magnify_by2(self, power = 1): """ Scales mask up by 2 ^ power. """ - result = dll.pixie_mask_magnify_by_2(self, power) + result = dll.pixie_mask_magnify_by2(self, power) if check_error(): raise PixieError(take_error()) return result @@ -985,16 +987,16 @@ def line_to(self, x, y): """ dll.pixie_path_line_to(self, x, y) - def bezier_curve_to(self, x_1, y_1, x_2, y_2, x_3, y_3): + def bezier_curve_to(self, x1, y1, x2, y2, x3, y3): """ Adds a cubic Bézier curve to the current sub-path. It requires three points: the first two are control points and the third one is the end point. The starting point is the latest point in the current path, which can be changed using moveTo() before creating the Bézier curve. """ - dll.pixie_path_bezier_curve_to(self, x_1, y_1, x_2, y_2, x_3, y_3) + dll.pixie_path_bezier_curve_to(self, x1, y1, x2, y2, x3, y3) - def quadratic_curve_to(self, x_1, y_1, x_2, y_2): + def quadratic_curve_to(self, x1, y1, x2, y2): """ Adds a quadratic Bézier curve to the current sub-path. It requires two points: the first one is a control point and the second one is the end @@ -1002,7 +1004,7 @@ def quadratic_curve_to(self, x_1, y_1, x_2, y_2): which can be changed using moveTo() before creating the quadratic Bézier curve. """ - dll.pixie_path_quadratic_curve_to(self, x_1, y_1, x_2, y_2) + dll.pixie_path_quadratic_curve_to(self, x1, y1, x2, y2) def elliptical_arc_to(self, rx, ry, x_axis_rotation, large_arc_flag, sweep_flag, x, y): """ @@ -1011,20 +1013,20 @@ def elliptical_arc_to(self, rx, ry, x_axis_rotation, large_arc_flag, sweep_flag, """ dll.pixie_path_elliptical_arc_to(self, rx, ry, x_axis_rotation, large_arc_flag, sweep_flag, x, y) - def arc(self, x, y, r, a_0, a_1, ccw = False): + def arc(self, x, y, r, a0, a1, ccw = False): """ Adds a circular arc to the current sub-path. """ - dll.pixie_path_arc(self, x, y, r, a_0, a_1, ccw) + dll.pixie_path_arc(self, x, y, r, a0, a1, ccw) if check_error(): raise PixieError(take_error()) - def arc_to(self, x_1, y_1, x_2, y_2, r): + def arc_to(self, x1, y1, x2, y2, r): """ Adds a circular arc using the given control points and radius. Commonly used for making rounded corners. """ - dll.pixie_path_arc_to(self, x_1, y_1, x_2, y_2, r) + dll.pixie_path_arc_to(self, x1, y1, x2, y2, r) if check_error(): raise PixieError(take_error()) @@ -1570,6 +1572,13 @@ def reset_transform(self): """ dll.pixie_context_reset_transform(self) + def get_line_dash(self): + result = dll.pixie_context_get_line_dash(self) + return result + + def set_line_dash(self, line_dash): + dll.pixie_context_set_line_dash(self, line_dash) + def draw_image(self, image, dx, dy): """ Draws a source image onto the destination image. @@ -1578,13 +1587,13 @@ def draw_image(self, image, dx, dy): if check_error(): raise PixieError(take_error()) - def draw_image_2(self, image, dx, dy, d_width, d_height): - dll.pixie_context_draw_image_2(self, image, dx, dy, d_width, d_height) + def draw_image2(self, image, dx, dy, d_width, d_height): + dll.pixie_context_draw_image2(self, image, dx, dy, d_width, d_height) if check_error(): raise PixieError(take_error()) - def draw_image_3(self, image, sx, sy, s_width, s_height, dx, dy, d_width, d_height): - dll.pixie_context_draw_image_3(self, image, sx, sy, s_width, s_height, dx, dy, d_width, d_height) + def draw_image3(self, image, sx, sy, s_width, s_height, dx, dy, d_width, d_height): + dll.pixie_context_draw_image3(self, image, sx, sy, s_width, s_height, dx, dy, d_width, d_height) if check_error(): raise PixieError(take_error()) @@ -1601,14 +1610,14 @@ def line_to(self, x, y): """ dll.pixie_context_line_to(self, x, y) - def bezier_curve_to(self, cp_1x, cp_1y, cp_2x, cp_2y, x, y): + def bezier_curve_to(self, cp1x, cp1y, cp2x, cp2y, x, y): """ Adds a cubic Bézier curve to the current sub-path. It requires three points: the first two are control points and the third one is the end point. The starting point is the latest point in the current path, which can be changed using moveTo() before creating the Bézier curve. """ - dll.pixie_context_bezier_curve_to(self, cp_1x, cp_1y, cp_2x, cp_2y, x, y) + dll.pixie_context_bezier_curve_to(self, cp1x, cp1y, cp2x, cp2y, x, y) def quadratic_curve_to(self, cpx, cpy, x, y): """ @@ -1620,19 +1629,19 @@ def quadratic_curve_to(self, cpx, cpy, x, y): """ dll.pixie_context_quadratic_curve_to(self, cpx, cpy, x, y) - def arc(self, x, y, r, a_0, a_1, ccw = False): + def arc(self, x, y, r, a0, a1, ccw = False): """ Draws a circular arc. """ - dll.pixie_context_arc(self, x, y, r, a_0, a_1, ccw) + dll.pixie_context_arc(self, x, y, r, a0, a1, ccw) if check_error(): raise PixieError(take_error()) - def arc_to(self, x_1, y_1, x_2, y_2, radius): + def arc_to(self, x1, y1, x2, y2, radius): """ Draws a circular arc using the given control points and radius. """ - dll.pixie_context_arc_to(self, x_1, y_1, x_2, y_2, radius) + dll.pixie_context_arc_to(self, x1, y1, x2, y2, radius) if check_error(): raise PixieError(take_error()) @@ -1862,35 +1871,35 @@ def inverse(m): dll.pixie_take_error.argtypes = [] dll.pixie_take_error.restype = c_char_p -dll.pixie_matrix_3.argtypes = [] -dll.pixie_matrix_3.restype = Matrix3 +dll.pixie_matrix3.argtypes = [] +dll.pixie_matrix3.restype = Matrix3 -dll.pixie_matrix_3_mul.argtypes = [Matrix3, Matrix3] -dll.pixie_matrix_3_mul.restype = Matrix3 +dll.pixie_matrix3_mul.argtypes = [Matrix3, Matrix3] +dll.pixie_matrix3_mul.restype = Matrix3 -dll.pixie_seq_float_32_unref.argtypes = [SeqFloat32] -dll.pixie_seq_float_32_unref.restype = None +dll.pixie_seq_float32_unref.argtypes = [SeqFloat32] +dll.pixie_seq_float32_unref.restype = None -dll.pixie_new_seq_float_32.argtypes = [] -dll.pixie_new_seq_float_32.restype = c_ulonglong +dll.pixie_new_seq_float32.argtypes = [] +dll.pixie_new_seq_float32.restype = c_ulonglong -dll.pixie_seq_float_32_len.argtypes = [SeqFloat32] -dll.pixie_seq_float_32_len.restype = c_longlong +dll.pixie_seq_float32_len.argtypes = [SeqFloat32] +dll.pixie_seq_float32_len.restype = c_longlong -dll.pixie_seq_float_32_get.argtypes = [SeqFloat32, c_longlong] -dll.pixie_seq_float_32_get.restype = c_float +dll.pixie_seq_float32_get.argtypes = [SeqFloat32, c_longlong] +dll.pixie_seq_float32_get.restype = c_float -dll.pixie_seq_float_32_set.argtypes = [SeqFloat32, c_longlong, c_float] -dll.pixie_seq_float_32_set.restype = None +dll.pixie_seq_float32_set.argtypes = [SeqFloat32, c_longlong, c_float] +dll.pixie_seq_float32_set.restype = None -dll.pixie_seq_float_32_delete.argtypes = [SeqFloat32, c_longlong] -dll.pixie_seq_float_32_delete.restype = None +dll.pixie_seq_float32_delete.argtypes = [SeqFloat32, c_longlong] +dll.pixie_seq_float32_delete.restype = None -dll.pixie_seq_float_32_add.argtypes = [SeqFloat32, c_float] -dll.pixie_seq_float_32_add.restype = None +dll.pixie_seq_float32_add.argtypes = [SeqFloat32, c_float] +dll.pixie_seq_float32_add.restype = None -dll.pixie_seq_float_32_clear.argtypes = [SeqFloat32] -dll.pixie_seq_float_32_clear.restype = None +dll.pixie_seq_float32_clear.argtypes = [SeqFloat32] +dll.pixie_seq_float32_clear.restype = None dll.pixie_seq_span_unref.argtypes = [SeqSpan] dll.pixie_seq_span_unref.restype = None @@ -1964,11 +1973,11 @@ def inverse(m): dll.pixie_image_sub_image.argtypes = [Image, c_longlong, c_longlong, c_longlong, c_longlong] dll.pixie_image_sub_image.restype = Image -dll.pixie_image_minify_by_2.argtypes = [Image, c_longlong] -dll.pixie_image_minify_by_2.restype = Image +dll.pixie_image_minify_by2.argtypes = [Image, c_longlong] +dll.pixie_image_minify_by2.restype = Image -dll.pixie_image_magnify_by_2.argtypes = [Image, c_longlong] -dll.pixie_image_magnify_by_2.restype = Image +dll.pixie_image_magnify_by2.argtypes = [Image, c_longlong] +dll.pixie_image_magnify_by2.restype = Image dll.pixie_image_apply_opacity.argtypes = [Image, c_float] dll.pixie_image_apply_opacity.restype = None @@ -2054,11 +2063,11 @@ def inverse(m): dll.pixie_mask_fill.argtypes = [Mask, c_ubyte] dll.pixie_mask_fill.restype = None -dll.pixie_mask_minify_by_2.argtypes = [Mask, c_longlong] -dll.pixie_mask_minify_by_2.restype = Mask +dll.pixie_mask_minify_by2.argtypes = [Mask, c_longlong] +dll.pixie_mask_minify_by2.restype = Mask -dll.pixie_mask_magnify_by_2.argtypes = [Mask, c_longlong] -dll.pixie_mask_magnify_by_2.restype = Mask +dll.pixie_mask_magnify_by2.argtypes = [Mask, c_longlong] +dll.pixie_mask_magnify_by2.restype = Mask dll.pixie_mask_spread.argtypes = [Mask, c_float] dll.pixie_mask_spread.restype = None @@ -2504,14 +2513,20 @@ def inverse(m): dll.pixie_context_reset_transform.argtypes = [Context] dll.pixie_context_reset_transform.restype = None +dll.pixie_context_get_line_dash.argtypes = [Context] +dll.pixie_context_get_line_dash.restype = SeqFloat32 + +dll.pixie_context_set_line_dash.argtypes = [Context, SeqFloat32] +dll.pixie_context_set_line_dash.restype = None + dll.pixie_context_draw_image.argtypes = [Context, Image, c_float, c_float] dll.pixie_context_draw_image.restype = None -dll.pixie_context_draw_image_2.argtypes = [Context, Image, c_float, c_float, c_float, c_float] -dll.pixie_context_draw_image_2.restype = None +dll.pixie_context_draw_image2.argtypes = [Context, Image, c_float, c_float, c_float, c_float] +dll.pixie_context_draw_image2.restype = None -dll.pixie_context_draw_image_3.argtypes = [Context, Image, c_float, c_float, c_float, c_float, c_float, c_float, c_float, c_float] -dll.pixie_context_draw_image_3.restype = None +dll.pixie_context_draw_image3.argtypes = [Context, Image, c_float, c_float, c_float, c_float, c_float, c_float, c_float, c_float] +dll.pixie_context_draw_image3.restype = None dll.pixie_context_move_to.argtypes = [Context, c_float, c_float] dll.pixie_context_move_to.restype = None diff --git a/tests/images/blur.png b/tests/images/blur.png index 3c4fc1b..a2cc8ad 100644 Binary files a/tests/images/blur.png and b/tests/images/blur.png differ diff --git a/tests/images/draw.png b/tests/images/draw.png index ab06f44..b463fbd 100644 Binary files a/tests/images/draw.png and b/tests/images/draw.png differ diff --git a/tests/images/fill1.png b/tests/images/fill1.png index d4bb232..6800861 100644 Binary files a/tests/images/fill1.png and b/tests/images/fill1.png differ diff --git a/tests/images/fill_gradient.png b/tests/images/fill_gradient.png index 3088ed8..199d240 100644 Binary files a/tests/images/fill_gradient.png and b/tests/images/fill_gradient.png differ diff --git a/tests/images/fill_text.png b/tests/images/fill_text.png index 3a3d326..951d7ff 100644 Binary files a/tests/images/fill_text.png and b/tests/images/fill_text.png differ diff --git a/tests/images/flip_horizontal.png b/tests/images/flip_horizontal.png index abcbd13..37de54d 100644 Binary files a/tests/images/flip_horizontal.png and b/tests/images/flip_horizontal.png differ diff --git a/tests/images/flip_vertical.png b/tests/images/flip_vertical.png index 249c1a3..67e3563 100644 Binary files a/tests/images/flip_vertical.png and b/tests/images/flip_vertical.png differ diff --git a/tests/images/mask_draw.png b/tests/images/mask_draw.png index 9d279a5..c9d772f 100644 Binary files a/tests/images/mask_draw.png and b/tests/images/mask_draw.png differ diff --git a/tests/images/red.png b/tests/images/red.png index baa7f02..65e644c 100644 Binary files a/tests/images/red.png and b/tests/images/red.png differ diff --git a/tests/images/shadow.png b/tests/images/shadow.png index 0318e65..5a62aa6 100644 Binary files a/tests/images/shadow.png and b/tests/images/shadow.png differ diff --git a/tests/images/stroke1.png b/tests/images/stroke1.png index 4311b4c..03bafe5 100644 Binary files a/tests/images/stroke1.png and b/tests/images/stroke1.png differ diff --git a/tests/images/stroke_text.png b/tests/images/stroke_text.png index f673e89..43665e0 100644 Binary files a/tests/images/stroke_text.png and b/tests/images/stroke_text.png differ diff --git a/tests/images/sub_image.png b/tests/images/sub_image.png index 1f02f5e..4601858 100644 Binary files a/tests/images/sub_image.png and b/tests/images/sub_image.png differ diff --git a/tests/images/super_image.png b/tests/images/super_image.png index ecba2e3..06083bb 100644 Binary files a/tests/images/super_image.png and b/tests/images/super_image.png differ diff --git a/tests/masks/127.png b/tests/masks/127.png index 5707df5..6f74fdd 100644 Binary files a/tests/masks/127.png and b/tests/masks/127.png differ diff --git a/tests/masks/255.png b/tests/masks/255.png index 9661e8e..df7ed2e 100644 Binary files a/tests/masks/255.png and b/tests/masks/255.png differ diff --git a/tests/masks/blur.png b/tests/masks/blur.png index a9fc6df..ef456db 100644 Binary files a/tests/masks/blur.png and b/tests/masks/blur.png differ diff --git a/tests/masks/draw.png b/tests/masks/draw.png index 18024bb..198450b 100644 Binary files a/tests/masks/draw.png and b/tests/masks/draw.png differ diff --git a/tests/masks/fill1.png b/tests/masks/fill1.png index 19aba64..28245fd 100644 Binary files a/tests/masks/fill1.png and b/tests/masks/fill1.png differ diff --git a/tests/masks/fill_text.png b/tests/masks/fill_text.png index 820da96..f804933 100644 Binary files a/tests/masks/fill_text.png and b/tests/masks/fill_text.png differ diff --git a/tests/masks/image_draw.png b/tests/masks/image_draw.png index e01b1f1..7bbed57 100644 Binary files a/tests/masks/image_draw.png and b/tests/masks/image_draw.png differ diff --git a/tests/masks/minified.png b/tests/masks/minified.png index 9661e8e..df7ed2e 100644 Binary files a/tests/masks/minified.png and b/tests/masks/minified.png differ diff --git a/tests/masks/spread.png b/tests/masks/spread.png index 58a6ac8..9ca414a 100644 Binary files a/tests/masks/spread.png and b/tests/masks/spread.png differ diff --git a/tests/masks/stroke1.png b/tests/masks/stroke1.png index aca3e82..ab9c5ce 100644 Binary files a/tests/masks/stroke1.png and b/tests/masks/stroke1.png differ diff --git a/tests/masks/stroke_text.png b/tests/masks/stroke_text.png index 4116003..6a200cd 100644 Binary files a/tests/masks/stroke_text.png and b/tests/masks/stroke_text.png differ diff --git a/tests/test_context.py b/tests/test_context.py index dc5f6e1..5d892c6 100644 --- a/tests/test_context.py +++ b/tests/test_context.py @@ -127,3 +127,17 @@ def test_text(): context.fill_text("test", 0, 0) context.stroke_text("text", 0, 0) + +def test_line_dash(): + context = pixie.Context(100, 100) + line_dash = pixie.SeqFloat32() + line_dash.append(1) + line_dash.append(0) + line_dash.append(2) + line_dash.append(3) + context.set_line_dash(line_dash) + retrieved_line_dash = context.get_line_dash() + assert len(line_dash) == len(retrieved_line_dash) + for i in range(0, len(line_dash)): + print(line_dash[i]) + assert line_dash[i] == retrieved_line_dash[i] diff --git a/tests/test_image.py b/tests/test_image.py index ab59036..ad557c2 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -45,16 +45,16 @@ def test_subsuper(): image.sub_image(0, 0, 20, 20).write_file("tests/images/sub_image.png") image.super_image(-10, -10, 120, 120).write_file("tests/images/super_image.png") -def test_minify_by_2(): +def test_minify_by2(): image = pixie.Image(400, 400) image.fill(pixie.Color(0, 0, 1, 1)) - image = image.minify_by_2(2) + image = image.minify_by2(2) image.write_file("tests/images/minified.png") -def test_magnify_by_2(): +def test_magnify_by2(): image = pixie.Image(25, 25) image.fill(pixie.Color(0, 1, 0, 1)) - image = image.magnify_by_2(2) + image = image.magnify_by2(2) image.write_file("tests/images/magnified.png") def test_paths(): diff --git a/tests/test_mask.py b/tests/test_mask.py index 750ff29..4685dc1 100644 --- a/tests/test_mask.py +++ b/tests/test_mask.py @@ -23,7 +23,7 @@ def test_basic(): def test_minify_by_2(): mask = pixie.Mask(400, 400) mask.fill(255) - mask = mask.minify_by_2(2) + mask = mask.minify_by2(2) mask.write_file("tests/masks/minified.png") def test_paths():