FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pixie-python/src/pixie/pixie.py at master · treeform/pixie-python · GitHub
treeform
/
pixie-python
Public
Notifications
You must be signed in to change notification settings
Fork
2
Star
112
Code
Issues
7
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
pixie-python
/
src
/
pixie
/
pixie.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
2683 lines (2088 loc) · 82.6 KB
Breadcrumbs
pixie-python
/
src
/
pixie
/
pixie.py
Copy path
File metadata and controls
2683 lines (2088 loc) · 82.6 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from
ctypes
import
*
import
os
,
sys
dir
=
os
.
path
.
dirname
(
sys
.
modules
[
"pixie"
].
__file__
)
if
sys
.
platform
==
"win32"
:
libName
=
"pixie.dll"
elif
sys
.
platform
==
"darwin"
:
libName
=
"libpixie.dylib"
else
:
libName
=
"libpixie.so"
dll
=
cdll
.
LoadLibrary
(
os
.
path
.
join
(
dir
,
libName
))
class
PixieError
(
Exception
):
pass
class
SeqIterator
(
object
):
def
__init__
(
self
,
seq
):
self
.
idx
=
0
self
.
seq
=
seq
def
__iter__
(
self
):
return
self
def
__next__
(
self
):
if
self
.
idx
<
len
(
self
.
seq
):
self
.
idx
+=
1
return
self
.
seq
[
self
.
idx
-
1
]
else
:
self
.
idx
=
0
raise
StopIteration
DEFAULT_MITER_LIMIT
=
4.0
AUTO_LINE_HEIGHT
=
-
1.0
FileFormat
=
c_byte
PNG_FORMAT
=
0
BMP_FORMAT
=
1
JPEG_FORMAT
=
2
GIF_FORMAT
=
3
QOI_FORMAT
=
4
PPM_FORMAT
=
5
BlendMode
=
c_byte
NORMAL_BLEND
=
0
DARKEN_BLEND
=
1
MULTIPLY_BLEND
=
2
COLOR_BURN_BLEND
=
3
LIGHTEN_BLEND
=
4
SCREEN_BLEND
=
5
COLOR_DODGE_BLEND
=
6
OVERLAY_BLEND
=
7
SOFT_LIGHT_BLEND
=
8
HARD_LIGHT_BLEND
=
9
DIFFERENCE_BLEND
=
10
EXCLUSION_BLEND
=
11
HUE_BLEND
=
12
SATURATION_BLEND
=
13
COLOR_BLEND
=
14
LUMINOSITY_BLEND
=
15
MASK_BLEND
=
16
OVERWRITE_BLEND
=
17
SUBTRACT_MASK_BLEND
=
18
EXCLUDE_MASK_BLEND
=
19
PaintKind
=
c_byte
SOLID_PAINT
=
0
IMAGE_PAINT
=
1
TILED_IMAGE_PAINT
=
2
LINEAR_GRADIENT_PAINT
=
3
RADIAL_GRADIENT_PAINT
=
4
ANGULAR_GRADIENT_PAINT
=
5
WindingRule
=
c_byte
NON_ZERO
=
0
EVEN_ODD
=
1
LineCap
=
c_byte
BUTT_CAP
=
0
ROUND_CAP
=
1
SQUARE_CAP
=
2
LineJoin
=
c_byte
MITER_JOIN
=
0
ROUND_JOIN
=
1
BEVEL_JOIN
=
2
HorizontalAlignment
=
c_byte
LEFT_ALIGN
=
0
CENTER_ALIGN
=
1
RIGHT_ALIGN
=
2
VerticalAlignment
=
c_byte
TOP_ALIGN
=
0
MIDDLE_ALIGN
=
1
BOTTOM_ALIGN
=
2
TextCase
=
c_byte
NORMAL_CASE
=
0
UPPER_CASE
=
1
LOWER_CASE
=
2
TITLE_CASE
=
3
def
check_error
():
result
=
dll
.
pixie_check_error
()
return
result
def
take_error
():
result
=
dll
.
pixie_take_error
().
decode
(
"utf8"
)
return
result
class
Vector2
(
Structure
):
_fields_
=
[
(
"x"
,
c_float
),
(
"y"
,
c_float
)
]
def
__init__
(
self
,
x
,
y
):
self
.
x
=
x
self
.
y
=
y
def
__eq__
(
self
,
obj
):
return
self
.
x
==
obj
.
x
and
self
.
y
==
obj
.
y
class
Matrix3
(
Structure
):
_fields_
=
[
(
"values"
,
c_float
*
9
)
]
def
__init__
(
self
):
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_matrix3_mul
(
self
,
b
)
return
result
class
Rect
(
Structure
):
_fields_
=
[
(
"x"
,
c_float
),
(
"y"
,
c_float
),
(
"w"
,
c_float
),
(
"h"
,
c_float
)
]
def
__init__
(
self
,
x
,
y
,
w
,
h
):
self
.
x
=
x
self
.
y
=
y
self
.
w
=
w
self
.
h
=
h
def
__eq__
(
self
,
obj
):
return
self
.
x
==
obj
.
x
and
self
.
y
==
obj
.
y
and
self
.
w
==
obj
.
w
and
self
.
h
==
obj
.
h
class
Color
(
Structure
):
_fields_
=
[
(
"r"
,
c_float
),
(
"g"
,
c_float
),
(
"b"
,
c_float
),
(
"a"
,
c_float
)
]
def
__init__
(
self
,
r
,
g
,
b
,
a
):
self
.
r
=
r
self
.
g
=
g
self
.
b
=
b
self
.
a
=
a
def
__eq__
(
self
,
obj
):
return
self
.
r
==
obj
.
r
and
self
.
g
==
obj
.
g
and
self
.
b
==
obj
.
b
and
self
.
a
==
obj
.
a
class
ColorStop
(
Structure
):
_fields_
=
[
(
"color"
,
Color
),
(
"position"
,
c_float
)
]
def
__init__
(
self
,
color
,
position
):
self
.
color
=
color
self
.
position
=
position
def
__eq__
(
self
,
obj
):
return
self
.
color
==
obj
.
color
and
self
.
position
==
obj
.
position
class
TextMetrics
(
Structure
):
_fields_
=
[
(
"width"
,
c_float
)
]
def
__init__
(
self
,
width
):
self
.
width
=
width
def
__eq__
(
self
,
obj
):
return
self
.
width
==
obj
.
width
class
SeqFloat32
(
Structure
):
_fields_
=
[(
"ref"
,
c_ulonglong
)]
def
__bool__
(
self
):
return
self
.
ref
!=
None
def
__eq__
(
self
,
obj
):
return
self
.
ref
==
obj
.
ref
def
__del__
(
self
):
dll
.
pixie_seq_float32_unref
(
self
)
def
__init__
(
self
):
self
.
ref
=
dll
.
pixie_new_seq_float32
()
def
__len__
(
self
):
return
dll
.
pixie_seq_float32_len
(
self
)
def
__getitem__
(
self
,
index
):
return
dll
.
pixie_seq_float32_get
(
self
,
index
)
def
__setitem__
(
self
,
index
,
value
):
dll
.
pixie_seq_float32_set
(
self
,
index
,
value
)
def
__delitem__
(
self
,
index
):
dll
.
pixie_seq_float32_delete
(
self
,
index
)
def
append
(
self
,
value
):
dll
.
pixie_seq_float32_add
(
self
,
value
)
def
clear
(
self
):
dll
.
pixie_seq_float32_clear
(
self
)
def
__iter__
(
self
):
return
SeqIterator
(
self
)
class
SeqSpan
(
Structure
):
_fields_
=
[(
"ref"
,
c_ulonglong
)]
def
__bool__
(
self
):
return
self
.
ref
!=
None
def
__eq__
(
self
,
obj
):
return
self
.
ref
==
obj
.
ref
def
__del__
(
self
):
dll
.
pixie_seq_span_unref
(
self
)
def
__init__
(
self
):
self
.
ref
=
dll
.
pixie_new_seq_span
()
def
__len__
(
self
):
return
dll
.
pixie_seq_span_len
(
self
)
def
__getitem__
(
self
,
index
):
return
dll
.
pixie_seq_span_get
(
self
,
index
)
def
__setitem__
(
self
,
index
,
value
):
dll
.
pixie_seq_span_set
(
self
,
index
,
value
)
def
__delitem__
(
self
,
index
):
dll
.
pixie_seq_span_delete
(
self
,
index
)
def
append
(
self
,
value
):
dll
.
pixie_seq_span_add
(
self
,
value
)
def
clear
(
self
):
dll
.
pixie_seq_span_clear
(
self
)
def
__iter__
(
self
):
return
SeqIterator
(
self
)
def
typeset
(
self
,
bounds
=
None
,
h_align
=
LEFT_ALIGN
,
v_align
=
TOP_ALIGN
,
wrap
=
True
):
"""
Lays out the character glyphs and returns the arrangement.
Optional parameters:
bounds: width determines wrapping and hAlign, height for vAlign
hAlign: horizontal alignment of the text
vAlign: vertical alignment of the text
wrap: enable/disable text wrapping
"""
if
bounds
is
None
:
bounds
=
Vector2
(
0
,
0
)
result
=
dll
.
pixie_seq_span_typeset
(
self
,
bounds
,
h_align
,
v_align
,
wrap
)
return
result
def
layout_bounds
(
self
):
"""
Computes the width and height of the spans in pixels.
"""
result
=
dll
.
pixie_seq_span_layout_bounds
(
self
)
return
result
class
Image
(
Structure
):
_fields_
=
[(
"ref"
,
c_ulonglong
)]
def
__bool__
(
self
):
return
self
.
ref
!=
None
def
__eq__
(
self
,
obj
):
return
self
.
ref
==
obj
.
ref
def
__del__
(
self
):
dll
.
pixie_image_unref
(
self
)
def
__init__
(
self
,
width
,
height
):
result
=
dll
.
pixie_new_image
(
width
,
height
)
if
check_error
():
raise
PixieError
(
take_error
())
self
.
ref
=
result
@
property
def
width
(
self
):
return
dll
.
pixie_image_get_width
(
self
)
@
width
.
setter
def
width
(
self
,
width
):
dll
.
pixie_image_set_width
(
self
,
width
)
@
property
def
height
(
self
):
return
dll
.
pixie_image_get_height
(
self
)
@
height
.
setter
def
height
(
self
,
height
):
dll
.
pixie_image_set_height
(
self
,
height
)
def
write_file
(
self
,
file_path
):
"""
Writes an image to a file.
"""
dll
.
pixie_image_write_file
(
self
,
file_path
.
encode
(
"utf8"
))
if
check_error
():
raise
PixieError
(
take_error
())
def
copy
(
self
):
"""
Copies the image data into a new image.
"""
result
=
dll
.
pixie_image_copy
(
self
)
if
check_error
():
raise
PixieError
(
take_error
())
return
result
def
get_color
(
self
,
x
,
y
):
"""
Gets a color at (x, y) or returns transparent black if outside of bounds.
"""
result
=
dll
.
pixie_image_get_color
(
self
,
x
,
y
)
return
result
def
set_color
(
self
,
x
,
y
,
color
):
"""
Sets a color at (x, y) or does nothing if outside of bounds.
"""
dll
.
pixie_image_set_color
(
self
,
x
,
y
,
color
)
def
fill
(
self
,
color
):
"""
Fills the image with the color.
"""
dll
.
pixie_image_fill
(
self
,
color
)
def
flip_horizontal
(
self
):
"""
Flips the image around the Y axis.
"""
dll
.
pixie_image_flip_horizontal
(
self
)
def
flip_vertical
(
self
):
"""
Flips the image around the X axis.
"""
dll
.
pixie_image_flip_vertical
(
self
)
def
sub_image
(
self
,
x
,
y
,
w
,
h
):
"""
Gets a sub image from this image.
"""
result
=
dll
.
pixie_image_sub_image
(
self
,
x
,
y
,
w
,
h
)
if
check_error
():
raise
PixieError
(
take_error
())
return
result
def
minify_by2
(
self
,
power
=
1
):
"""
Scales the image down by an integer scale.
"""
result
=
dll
.
pixie_image_minify_by2
(
self
,
power
)
if
check_error
():
raise
PixieError
(
take_error
())
return
result
def
magnify_by2
(
self
,
power
=
1
):
"""
Scales image up by 2 ^ power.
"""
result
=
dll
.
pixie_image_magnify_by2
(
self
,
power
)
if
check_error
():
raise
PixieError
(
take_error
())
return
result
def
apply_opacity
(
self
,
opacity
):
"""
Multiplies alpha of the image by opacity.
"""
dll
.
pixie_image_apply_opacity
(
self
,
opacity
)
def
invert
(
self
):
"""
Inverts all of the colors and alpha.
"""
dll
.
pixie_image_invert
(
self
)
def
blur
(
self
,
radius
,
out_of_bounds
=
None
):
"""
Applies Gaussian blur to the image given a radius.
"""
if
out_of_bounds
is
None
:
out_of_bounds
=
Color
(
0
,
0
,
0
,
0
)
dll
.
pixie_image_blur
(
self
,
radius
,
out_of_bounds
)
if
check_error
():
raise
PixieError
(
take_error
())
def
new_mask
(
self
):
"""
Returns a new mask using the alpha values of the image.
"""
result
=
dll
.
pixie_image_new_mask
(
self
)
if
check_error
():
raise
PixieError
(
take_error
())
return
result
def
resize
(
self
,
width
,
height
):
"""
Resize an image to a given height and width.
"""
result
=
dll
.
pixie_image_resize
(
self
,
width
,
height
)
if
check_error
():
raise
PixieError
(
take_error
())
return
result
def
shadow
(
self
,
offset
,
spread
,
blur
,
color
):
"""
Create a shadow of the image with the offset, spread and blur.
"""
result
=
dll
.
pixie_image_shadow
(
self
,
offset
,
spread
,
blur
,
color
)
if
check_error
():
raise
PixieError
(
take_error
())
return
result
def
super_image
(
self
,
x
,
y
,
w
,
h
):
"""
Either cuts a sub image or returns a super image with padded transparency.
"""
result
=
dll
.
pixie_image_super_image
(
self
,
x
,
y
,
w
,
h
)
if
check_error
():
raise
PixieError
(
take_error
())
return
result
def
draw
(
self
,
b
,
transform
=
None
,
blend_mode
=
NORMAL_BLEND
):
"""
Draws one image onto another using matrix with color blending.
"""
if
transform
is
None
:
transform
=
Matrix3
()
dll
.
pixie_image_draw
(
self
,
b
,
transform
,
blend_mode
)
if
check_error
():
raise
PixieError
(
take_error
())
def
mask_draw
(
self
,
mask
,
transform
=
None
,
blend_mode
=
MASK_BLEND
):
"""
Draws a mask onto an image using a matrix with color blending.
"""
if
transform
is
None
:
transform
=
Matrix3
()
dll
.
pixie_image_mask_draw
(
self
,
mask
,
transform
,
blend_mode
)
if
check_error
():
raise
PixieError
(
take_error
())
def
fill_gradient
(
self
,
paint
):
"""
Fills with the Paint gradient.
"""
dll
.
pixie_image_fill_gradient
(
self
,
paint
)
if
check_error
():
raise
PixieError
(
take_error
())
def
fill_text
(
self
,
font
,
text
,
transform
=
None
,
bounds
=
None
,
h_align
=
LEFT_ALIGN
,
v_align
=
TOP_ALIGN
):
"""
Typesets and fills the text. Optional parameters:
transform: translation or matrix to apply
bounds: width determines wrapping and hAlign, height for vAlign
hAlign: horizontal alignment of the text
vAlign: vertical alignment of the text
"""
if
transform
is
None
:
transform
=
Matrix3
()
if
bounds
is
None
:
bounds
=
Vector2
(
0
,
0
)
dll
.
pixie_image_fill_text
(
self
,
font
,
text
.
encode
(
"utf8"
),
transform
,
bounds
,
h_align
,
v_align
)
if
check_error
():
raise
PixieError
(
take_error
())
def
arrangement_fill_text
(
self
,
arrangement
,
transform
=
None
):
"""
Fills the text arrangement.
"""
if
transform
is
None
:
transform
=
Matrix3
()
dll
.
pixie_image_arrangement_fill_text
(
self
,
arrangement
,
transform
)
if
check_error
():
raise
PixieError
(
take_error
())
def
stroke_text
(
self
,
font
,
text
,
transform
=
None
,
stroke_width
=
1.0
,
bounds
=
None
,
h_align
=
LEFT_ALIGN
,
v_align
=
TOP_ALIGN
,
line_cap
=
BUTT_CAP
,
line_join
=
MITER_JOIN
,
miter_limit
=
DEFAULT_MITER_LIMIT
,
dashes
=
None
):
"""
Typesets and strokes the text. Optional parameters:
transform: translation or matrix to apply
bounds: width determines wrapping and hAlign, height for vAlign
hAlign: horizontal alignment of the text
vAlign: vertical alignment of the text
lineCap: stroke line cap shape
lineJoin: stroke line join shape
"""
if
transform
is
None
:
transform
=
Matrix3
()
if
bounds
is
None
:
bounds
=
Vector2
(
0
,
0
)
if
dashes
is
None
:
dashes
=
SeqFloat32
()
dll
.
pixie_image_stroke_text
(
self
,
font
,
text
.
encode
(
"utf8"
),
transform
,
stroke_width
,
bounds
,
h_align
,
v_align
,
line_cap
,
line_join
,
miter_limit
,
dashes
)
if
check_error
():
raise
PixieError
(
take_error
())
def
arrangement_stroke_text
(
self
,
arrangement
,
transform
=
None
,
stroke_width
=
1.0
,
line_cap
=
BUTT_CAP
,
line_join
=
MITER_JOIN
,
miter_limit
=
DEFAULT_MITER_LIMIT
,
dashes
=
None
):
"""
Strokes the text arrangement.
"""
if
transform
is
None
:
transform
=
Matrix3
()
if
dashes
is
None
:
dashes
=
SeqFloat32
()
dll
.
pixie_image_arrangement_stroke_text
(
self
,
arrangement
,
transform
,
stroke_width
,
line_cap
,
line_join
,
miter_limit
,
dashes
)
if
check_error
():
raise
PixieError
(
take_error
())
def
fill_path
(
self
,
path
,
paint
,
transform
=
None
,
winding_rule
=
NON_ZERO
):
"""
Fills a path.
"""
if
transform
is
None
:
transform
=
Matrix3
()
dll
.
pixie_image_fill_path
(
self
,
path
,
paint
,
transform
,
winding_rule
)
if
check_error
():
raise
PixieError
(
take_error
())
def
stroke_path
(
self
,
path
,
paint
,
transform
=
None
,
stroke_width
=
1.0
,
line_cap
=
BUTT_CAP
,
line_join
=
MITER_JOIN
,
miter_limit
=
DEFAULT_MITER_LIMIT
,
dashes
=
None
):
"""
Strokes a path.
"""
if
transform
is
None
:
transform
=
Matrix3
()
if
dashes
is
None
:
dashes
=
SeqFloat32
()
dll
.
pixie_image_stroke_path
(
self
,
path
,
paint
,
transform
,
stroke_width
,
line_cap
,
line_join
,
miter_limit
,
dashes
)
if
check_error
():
raise
PixieError
(
take_error
())
def
new_context
(
self
):
"""
Create a new Context that will draw to the parameter image.
"""
result
=
dll
.
pixie_image_new_context
(
self
)
return
result
class
Mask
(
Structure
):
_fields_
=
[(
"ref"
,
c_ulonglong
)]
def
__bool__
(
self
):
return
self
.
ref
!=
None
def
__eq__
(
self
,
obj
):
return
self
.
ref
==
obj
.
ref
def
__del__
(
self
):
dll
.
pixie_mask_unref
(
self
)
def
__init__
(
self
,
width
,
height
):
result
=
dll
.
pixie_new_mask
(
width
,
height
)
if
check_error
():
raise
PixieError
(
take_error
())
self
.
ref
=
result
@
property
def
width
(
self
):
return
dll
.
pixie_mask_get_width
(
self
)
@
width
.
setter
def
width
(
self
,
width
):
dll
.
pixie_mask_set_width
(
self
,
width
)
@
property
def
height
(
self
):
return
dll
.
pixie_mask_get_height
(
self
)
@
height
.
setter
def
height
(
self
,
height
):
dll
.
pixie_mask_set_height
(
self
,
height
)
def
write_file
(
self
,
file_path
):
"""
Writes a mask to a file.
"""
dll
.
pixie_mask_write_file
(
self
,
file_path
.
encode
(
"utf8"
))
if
check_error
():
raise
PixieError
(
take_error
())
def
copy
(
self
):
"""
Copies the image data into a new image.
"""
result
=
dll
.
pixie_mask_copy
(
self
)
if
check_error
():
raise
PixieError
(
take_error
())
return
result
def
get_value
(
self
,
x
,
y
):
"""
Gets a value at (x, y) or returns transparent black if outside of bounds.
"""
result
=
dll
.
pixie_mask_get_value
(
self
,
x
,
y
)
return
result
def
set_value
(
self
,
x
,
y
,
value
):
"""
Sets a value at (x, y) or does nothing if outside of bounds.
"""
dll
.
pixie_mask_set_value
(
self
,
x
,
y
,
value
)
def
fill
(
self
,
value
):
"""
Fills the mask with the value.
"""
dll
.
pixie_mask_fill
(
self
,
value
)
def
minify_by2
(
self
,
power
=
1
):
"""
Scales the mask down by an integer scale.
"""
result
=
dll
.
pixie_mask_minify_by2
(
self
,
power
)
if
check_error
():
raise
PixieError
(
take_error
())
return
result
def
magnify_by2
(
self
,
power
=
1
):
"""
Scales mask up by 2 ^ power.
"""
result
=
dll
.
pixie_mask_magnify_by2
(
self
,
power
)
if
check_error
():
raise
PixieError
(
take_error
())
return
result
def
spread
(
self
,
spread
):
"""
Grows the mask by spread.
"""
dll
.
pixie_mask_spread
(
self
,
spread
)
if
check_error
():
raise
PixieError
(
take_error
())
def
ceil
(
self
):
"""
A value of 0 stays 0. Anything else turns into 255.
"""
dll
.
pixie_mask_ceil
(
self
)
def
new_image
(
self
):
result
=
dll
.
pixie_mask_new_image
(
self
)
if
check_error
():
raise
PixieError
(
take_error
())
return
result
def
apply_opacity
(
self
,
opacity
):
"""
Multiplies alpha of the image by opacity.
"""
dll
.
pixie_mask_apply_opacity
(
self
,
opacity
)
def
invert
(
self
):
"""
Inverts all of the values - creates a negative of the mask.
"""
dll
.
pixie_mask_invert
(
self
)
def
blur
(
self
,
radius
,
out_of_bounds
=
0
):
"""
Applies Gaussian blur to the image given a radius.
"""
dll
.
pixie_mask_blur
(
self
,
radius
,
out_of_bounds
)
if
check_error
():
raise
PixieError
(
take_error
())
def
draw
(
self
,
b
,
transform
=
None
,
blend_mode
=
MASK_BLEND
):
"""
Draws a mask onto a mask using a matrix with color blending.
"""
if
transform
is
None
:
transform
=
Matrix3
()
dll
.
pixie_mask_draw
(
self
,
b
,
transform
,
blend_mode
)
if
check_error
():
raise
PixieError
(
take_error
())
def
image_draw
(
self
,
image
,
transform
=
None
,
blend_mode
=
MASK_BLEND
):
"""
Draws a image onto a mask using a matrix with color blending.
"""
if
transform
is
None
:
transform
=
Matrix3
()
dll
.
pixie_mask_image_draw
(
self
,
image
,
transform
,
blend_mode
)
if
check_error
():
raise
PixieError
(
take_error
())
def
fill_text
(
self
,
font
,
text
,
transform
=
None
,
bounds
=
None
,
h_align
=
LEFT_ALIGN
,
v_align
=
TOP_ALIGN
):
"""
Typesets and fills the text. Optional parameters:
transform: translation or matrix to apply
bounds: width determines wrapping and hAlign, height for vAlign
hAlign: horizontal alignment of the text
vAlign: vertical alignment of the text
"""
if
transform
is
None
:
transform
=
Matrix3
()
if
bounds
is
None
:
bounds
=
Vector2
(
0
,
0
)
dll
.
pixie_mask_fill_text
(
self
,
font
,
text
.
encode
(
"utf8"
),
transform
,
bounds
,
h_align
,
v_align
)
if
check_error
():
raise
PixieError
(
take_error
())
def
arrangement_fill_text
(
self
,
arrangement
,
transform
=
None
):
"""
Fills the text arrangement.
"""
if
transform
is
None
:
transform
=
Matrix3
()
dll
.
pixie_mask_arrangement_fill_text
(
self
,
arrangement
,
transform
)
if
check_error
():
raise
PixieError
(
take_error
())
def
stroke_text
(
self
,
font
,
text
,
transform
=
None
,
stroke_width
=
1.0
,
bounds
=
None
,
h_align
=
LEFT_ALIGN
,
v_align
=
TOP_ALIGN
,
line_cap
=
BUTT_CAP
,
line_join
=
MITER_JOIN
,
miter_limit
=
DEFAULT_MITER_LIMIT
,
dashes
=
None
):
"""
Typesets and strokes the text. Optional parameters:
transform: translation or matrix to apply
bounds: width determines wrapping and hAlign, height for vAlign
hAlign: horizontal alignment of the text
vAlign: vertical alignment of the text
lineCap: stroke line cap shape
lineJoin: stroke line join shape
"""
if
transform
is
None
:
transform
=
Matrix3
()
if
bounds
is
None
:
bounds
=
Vector2
(
0
,
0
)
if
dashes
is
None
:
dashes
=
SeqFloat32
()
dll
.
pixie_mask_stroke_text
(
self
,
font
,
text
.
encode
(
"utf8"
),
transform
,
stroke_width
,
bounds
,
h_align
,
v_align
,
line_cap
,
line_join
,
miter_limit
,
dashes
)
if
check_error
():
raise
PixieError
(
take_error
())
def
arrangement_stroke_text
(
self
,
arrangement
,
transform
=
None
,
stroke_width
=
1.0
,
line_cap
=
BUTT_CAP
,
line_join
=
MITER_JOIN
,
miter_limit
=
DEFAULT_MITER_LIMIT
,
dashes
=
None
):
"""
Strokes the text arrangement.
"""
if
transform
is
None
:
transform
=
Matrix3
()
if
dashes
is
None
:
dashes
=
SeqFloat32
()
dll
.
pixie_mask_arrangement_stroke_text
(
self
,
arrangement
,
transform
,
stroke_width
,
line_cap
,
line_join
,
miter_limit
,
dashes
)
if
check_error
():
raise
PixieError
(
take_error
())
def
fill_path
(
self
,
path
,
transform
=
None
,
winding_rule
=
NON_ZERO
,
blend_mode
=
NORMAL_BLEND
):
"""
Fills a path.
"""
if
transform
is
None
:
transform
=
Matrix3
()
dll
.
pixie_mask_fill_path
(
self
,
path
,
transform
,
winding_rule
,
blend_mode
)
if
check_error
():
raise
PixieError
(
take_error
())
def
stroke_path
(
self
,
path
,
transform
=
None
,
stroke_width
=
1.0
,
line_cap
=
BUTT_CAP
,
line_join
=
MITER_JOIN
,
miter_limit
=
DEFAULT_MITER_LIMIT
,
dashes
=
None
,
blend_mode
=
NORMAL_BLEND
):
"""
Strokes a path.
"""
if
transform
is
None
:
transform
=
Matrix3
()
if
dashes
is
None
:
dashes
=
SeqFloat32
()
dll
.
pixie_mask_stroke_path
(
self
,
path
,
transform
,
stroke_width
,
line_cap
,
line_join
,
miter_limit
,
dashes
,
blend_mode
)
if
check_error
():
raise
PixieError
(
take_error
())
class
Paint
(
Structure
):
_fields_
=
[(
"ref"
,
c_ulonglong
)]
def
__bool__
(
self
):
return
self
.
ref
!=
None
def
__eq__
(
self
,
obj
):
return
self
.
ref
==
obj
.
ref
def
__del__
(
self
):
dll
.
pixie_paint_unref
(
self
)
def
__init__
(
self
,
kind
):
result
=
dll
.
pixie_new_paint
(
kind
)
self
.
ref
=
result
@
property
def
kind
(
self
):
return
dll
.
pixie_paint_get_kind
(
self
)
@
kind
.
setter
def
kind
(
self
,
kind
):
dll
.
pixie_paint_set_kind
(
self
,
kind
)
@
property
def
blend_mode
(
self
):
return
dll
.
pixie_paint_get_blend_mode
(
self
)
@
blend_mode
.
setter
def
blend_mode
(
self
,
blend_mode
):
dll
.
pixie_paint_set_blend_mode
(
self
,
blend_mode
)
@
property
def
opacity
(
self
):
return
dll
.
pixie_paint_get_opacity
(
self
)
@
opacity
.
setter
def
opacity
(
self
,
opacity
):
dll
.
pixie_paint_set_opacity
(
self
,
opacity
)
@
property
def
color
(
self
):
return
dll
.
pixie_paint_get_color
(
self
)
@
color
.
setter
def
color
(
self
,
color
):
dll
.
pixie_paint_set_color
(
self
,
color
)
@
property
def
image
(
self
):
return
dll
.
pixie_paint_get_image
(
self
)
@
image
.
setter
def
image
(
self
,
image
):
dll
.
pixie_paint_set_image
(
self
,
image
)
@
property
def
image_mat
(
self
):
return
dll
.
pixie_paint_get_image_mat
(
self
)
@
image_mat
.
setter
def
image_mat
(
self
,
image_mat
):
dll
.
pixie_paint_set_image_mat
(
self
,
image_mat
)
class
PaintGradientHandlePositions
:
def
__init__
(
self
,
paint
):
self
.
paint
=
paint
def
__len__
(
self
):
return
dll
.
pixie_paint_gradient_handle_positions_len
(
self
.
paint
)
def
__getitem__
(
self
,
index
):
return
dll
.
pixie_paint_gradient_handle_positions_get
(
self
.
paint
,
index
)
def
__setitem__
(
self
,
index
,
value
):
dll
.
pixie_paint_gradient_handle_positions_set
(
self
.
paint
,
index
,
value
)
def
__delitem__
(
self
,
index
):
dll
.
pixie_paint_gradient_handle_positions_delete
(
self
.
paint
,
index
)
def
append
(
self
,
value
):
dll
.
pixie_paint_gradient_handle_positions_add
(
self
.
paint
,
value
)
def
clear
(
self
):
dll
.
pixie_paint_gradient_handle_positions_clear
(
self
.
paint
)
def
__iter__
(
self
):
return
SeqIterator
(
self
)
@
property
def
gradient_handle_positions
(
self
):
return
self
.
PaintGradientHandlePositions
(
self
)
class
PaintGradientStops
:
def
__init__
(
self
,
paint
):
self
.
paint
=
paint
def
__len__
(
self
):
return
dll
.
pixie_paint_gradient_stops_len
(
self
.
paint
)
def
__getitem__
(
self
,
index
):
return
dll
.
pixie_paint_gradient_stops_get
(
self
.
paint
,
index
)
def
__setitem__
(
self
,
index
,
value
):
dll
.
pixie_paint_gradient_stops_set
(
self
.
paint
,
index
,
value
)
def
__delitem__
(
self
,
index
):
dll
.
pixie_paint_gradient_stops_delete
(
self
.
paint
,
index
)
def
append
(
self
,
value
):
dll
.
pixie_paint_gradient_stops_add
(
self
.
paint
,
value
)
def
clear
(
self
):
dll
.
pixie_paint_gradient_stops_clear
(
self
.
paint
)
def
__iter__
(
self
):
return
SeqIterator
(
self
)
@
property
def
gradient_stops
(
self
):
return
self
.
PaintGradientStops
(
self
)
def
new_paint
(
self
):
"""
Create a new Paint with the same properties.
"""
result
=
dll
.
pixie_paint_new_paint
(
self
)
return
result
class
Path
(
Structure
):
_fields_
=
[(
"ref"
,
c_ulonglong
)]
def
__bool__
(
self
):
return
self
.
ref
!=
None
def
__eq__
(
self
,
obj
):
return
self
.
ref
==
obj
.
ref
def
__del__
(
self
):
dll
.
pixie_path_unref
(
self
)
def
__init__
(
self
):
result
=
dll
.
pixie_new_path
()
self
.
ref
=
result
def
transform
(
self
,
mat
):
"""
Apply a matrix transform to a path.
"""
dll
.
pixie_path_transform
(
self
,
mat
)
def
add_path
(
self
,
other
):
"""
Adds a path to the current path.
"""
dll
.
pixie_path_add_path
(
self
,
other
)
def
close_path
(
self
):
"""
Attempts to add a straight line from the current point to the start of
the current sub-path. If the shape has already been closed or has only
one point, this function does nothing.
"""
dll
.
pixie_path_close_path
(
self
)
def
compute_bounds
(
self
,
transform
=
None
):
"""
Compute the bounds of the path.
"""
if
transform
is
None
:
transform
=
Matrix3
()
result
=
dll
.
pixie_path_compute_bounds
(
self
,
transform
)
if
check_error
():
raise
PixieError
(
take_error
())
return
result
def
fill_overlaps
(
self
,
test
,
transform
=
None
,
winding_rule
=
NON_ZERO
):
"""
Returns whether or not the specified point is contained in the current path.
"""
if
transform
is
None
:
transform
=
Matrix3
()
result
=
dll
.
pixie_path_fill_overlaps
(
self
,
test
,
transform
,
winding_rule
)
if
check_error
():
raise
PixieError
(
take_error
())
return
result
def
stroke_overlaps
(
self
,
test
,
transform
=
None
,
stroke_width
=
1.0
,
line_cap
=
BUTT_CAP
,
line_join
=
MITER_JOIN
,
miter_limit
=
DEFAULT_MITER_LIMIT
,
dashes
=
None
):
"""
Returns whether or not the specified point is inside the area contained
by the stroking of a path.
"""
if
transform
is
None
:
transform
=
Matrix3
()
if
dashes
is
None
:
dashes
=
SeqFloat32
()
result
=
dll
.
pixie_path_stroke_overlaps
(
self
,
test
,
transform
,
stroke_width
,
line_cap
,
line_join
,
miter_limit
,
dashes
)
if
check_error
():
raise
PixieError
(
take_error
())
View remainder of file in raw view
Back
|
FazBrowse Home
|
New Git URL