texplay 0.4.3 → 0.4.4.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG +225 -222
- data/README.markdown +48 -48
- data/Rakefile +16 -16
- data/examples/common.rb +18 -18
- data/examples/example_alpha_blend.rb +29 -29
- data/examples/example_bezier.rb +41 -41
- data/examples/example_blank.rb +37 -37
- data/examples/example_cache.rb +21 -21
- data/examples/example_color_control.rb +69 -69
- data/examples/example_color_transform.rb +62 -62
- data/examples/example_color_transform_circle.rb +34 -34
- data/examples/example_darken.rb +24 -24
- data/examples/example_dup.rb +73 -73
- data/examples/example_each.rb +39 -39
- data/examples/example_effect.rb +34 -34
- data/examples/example_fill.rb +43 -43
- data/examples/example_fill_old.rb +48 -48
- data/examples/example_fluent.rb +29 -29
- data/examples/example_font.rb +31 -31
- data/examples/example_hash_arguments.rb +46 -46
- data/examples/example_ippa.rb +23 -23
- data/examples/example_light.rb +75 -75
- data/examples/example_light_multiply.rb +18 -18
- data/examples/example_lsystem.rb +61 -61
- data/examples/example_melt.rb +25 -25
- data/examples/example_meyet.rb +62 -62
- data/examples/example_polyline.rb +42 -42
- data/examples/example_scale.rb +27 -27
- data/examples/example_select.rb +36 -36
- data/examples/example_select2.rb +25 -25
- data/examples/example_simple.rb +46 -46
- data/examples/example_splice.rb +26 -26
- data/examples/example_sync.rb +59 -59
- data/examples/example_tiles.rb +41 -41
- data/examples/example_trace.rb +22 -22
- data/examples/example_transparent.rb +28 -28
- data/examples/example_transparent2.rb +24 -24
- data/examples/example_transparent3.rb +20 -20
- data/examples/example_turtle.rb +39 -39
- data/examples/example_weird.rb +22 -22
- data/examples/example_window_render_to_image.rb +41 -41
- data/examples/example_window_to_blob.rb +35 -35
- data/examples/media/maria.png +0 -0
- data/examples/media/rose.bmp +0 -0
- data/ext/texplay/actions.c +1011 -1006
- data/ext/texplay/actions.h +60 -60
- data/ext/texplay/bindings.c +1130 -1125
- data/ext/texplay/bindings.h +46 -46
- data/ext/texplay/cache.c +123 -118
- data/ext/texplay/cache.h +24 -24
- data/ext/texplay/compat.h +21 -27
- data/ext/texplay/extconf.rb +38 -38
- data/ext/texplay/graphics_utils.c +1318 -1313
- data/ext/texplay/graphics_utils.h +22 -22
- data/ext/texplay/texplay.c +206 -201
- data/ext/texplay/texplay.h +153 -153
- data/ext/texplay/utils.c +896 -891
- data/ext/texplay/utils.h +153 -153
- data/lib/texplay-contrib.rb +147 -147
- data/lib/texplay.rb +347 -347
- data/lib/texplay/alone.rb +20 -20
- data/lib/texplay/c_function_docs.rb +178 -178
- data/lib/texplay/live.rb +84 -84
- data/lib/texplay/version.rb +3 -3
- data/live/live.rb +85 -85
- data/test/image_spec.rb +45 -45
- data/test/texplay_spec.rb +144 -144
- metadata +42 -52
- data/lib/texplay/1.8/texplay.so +0 -0
- data/lib/texplay/1.9/texplay.so +0 -0
@@ -1,1313 +1,1318 @@
|
|
1
|
-
#include "texplay.h"
|
2
|
-
#include "utils.h"
|
3
|
-
#include "graphics_utils.h"
|
4
|
-
#include "cache.h"
|
5
|
-
|
6
|
-
#ifdef __APPLE__
|
7
|
-
#include <
|
8
|
-
#
|
9
|
-
#include <
|
10
|
-
#
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
static void
|
20
|
-
static void
|
21
|
-
static
|
22
|
-
static
|
23
|
-
static
|
24
|
-
|
25
|
-
static
|
26
|
-
static rgba
|
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
|
-
cur->
|
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
|
-
/* sync
|
113
|
-
case
|
114
|
-
|
115
|
-
break;
|
116
|
-
|
117
|
-
/* sync
|
118
|
-
case
|
119
|
-
|
120
|
-
break;
|
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
|
-
tex_data
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
if (payload->pen.
|
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
|
-
/* for
|
221
|
-
if(payload->pen.
|
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
|
-
offset
|
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
|
-
cur->
|
346
|
-
cur->
|
347
|
-
|
348
|
-
|
349
|
-
cur->pen.
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
cur->pen.
|
355
|
-
|
356
|
-
|
357
|
-
cur->pen.
|
358
|
-
cur->pen.
|
359
|
-
cur->pen.
|
360
|
-
cur->pen.
|
361
|
-
|
362
|
-
|
363
|
-
cur->pen.
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
cur->pen.
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
cur->pen.
|
377
|
-
cur->pen.
|
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
|
-
cur->pen.
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
cur->pen.
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
cur->pen.
|
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
|
-
cur->pen.
|
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
|
-
else if(draw_mode == string2sym("
|
588
|
-
cur->pen.drawing_mode =
|
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
|
-
case 1:
|
670
|
-
|
671
|
-
|
672
|
-
break;
|
673
|
-
|
674
|
-
case
|
675
|
-
new_color = convert_rb_color_to_rgba(rb_funcall(proc, rb_intern("call"), arity,
|
676
|
-
convert_rgba_to_rb_color(&old_color)
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
convert_rgba_to_rb_color(&
|
683
|
-
|
684
|
-
|
685
|
-
case
|
686
|
-
new_color = convert_rb_color_to_rgba(rb_funcall(proc, rb_intern("call"), arity,
|
687
|
-
convert_rgba_to_rb_color(&old_color),
|
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
|
-
try_color
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
try_color
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
try_color
|
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
|
-
source_pixel_char.
|
933
|
-
source_pixel_char.
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
source_pixel_char.
|
939
|
-
source_pixel_char.
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
~(source_pixel_char.
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
source_pixel_char.
|
960
|
-
|
961
|
-
|
962
|
-
|
963
|
-
|
964
|
-
|
965
|
-
|
966
|
-
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
|
975
|
-
|
976
|
-
|
977
|
-
|
978
|
-
|
979
|
-
~source_pixel_char.
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
|
992
|
-
|
993
|
-
|
994
|
-
|
995
|
-
|
996
|
-
|
997
|
-
|
998
|
-
|
999
|
-
|
1000
|
-
|
1001
|
-
|
1002
|
-
|
1003
|
-
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
1007
|
-
|
1008
|
-
|
1009
|
-
|
1010
|
-
|
1011
|
-
|
1012
|
-
|
1013
|
-
|
1014
|
-
|
1015
|
-
|
1016
|
-
|
1017
|
-
|
1018
|
-
|
1019
|
-
|
1020
|
-
|
1021
|
-
|
1022
|
-
|
1023
|
-
|
1024
|
-
|
1025
|
-
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
1030
|
-
|
1031
|
-
|
1032
|
-
|
1033
|
-
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
1037
|
-
|
1038
|
-
|
1039
|
-
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1044
|
-
|
1045
|
-
dest_pixel.
|
1046
|
-
dest_pixel.
|
1047
|
-
|
1048
|
-
|
1049
|
-
|
1050
|
-
|
1051
|
-
|
1052
|
-
}
|
1053
|
-
|
1054
|
-
|
1055
|
-
|
1056
|
-
|
1057
|
-
|
1058
|
-
|
1059
|
-
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1063
|
-
|
1064
|
-
|
1065
|
-
|
1066
|
-
|
1067
|
-
|
1068
|
-
|
1069
|
-
|
1070
|
-
|
1071
|
-
|
1072
|
-
|
1073
|
-
|
1074
|
-
|
1075
|
-
|
1076
|
-
|
1077
|
-
|
1078
|
-
|
1079
|
-
|
1080
|
-
|
1081
|
-
|
1082
|
-
|
1083
|
-
|
1084
|
-
|
1085
|
-
|
1086
|
-
|
1087
|
-
|
1088
|
-
|
1089
|
-
|
1090
|
-
transformed_color
|
1091
|
-
|
1092
|
-
transformed_color
|
1093
|
-
|
1094
|
-
transformed_color.red
|
1095
|
-
transformed_color.green
|
1096
|
-
transformed_color.blue
|
1097
|
-
transformed_color.alpha
|
1098
|
-
|
1099
|
-
|
1100
|
-
|
1101
|
-
|
1102
|
-
|
1103
|
-
|
1104
|
-
|
1105
|
-
|
1106
|
-
|
1107
|
-
|
1108
|
-
|
1109
|
-
|
1110
|
-
|
1111
|
-
|
1112
|
-
|
1113
|
-
|
1114
|
-
|
1115
|
-
|
1116
|
-
|
1117
|
-
|
1118
|
-
|
1119
|
-
|
1120
|
-
|
1121
|
-
|
1122
|
-
|
1123
|
-
|
1124
|
-
|
1125
|
-
|
1126
|
-
|
1127
|
-
|
1128
|
-
|
1129
|
-
|
1130
|
-
|
1131
|
-
|
1132
|
-
|
1133
|
-
|
1134
|
-
|
1135
|
-
}
|
1136
|
-
|
1137
|
-
|
1138
|
-
|
1139
|
-
|
1140
|
-
|
1141
|
-
|
1142
|
-
|
1143
|
-
|
1144
|
-
|
1145
|
-
|
1146
|
-
|
1147
|
-
|
1148
|
-
|
1149
|
-
|
1150
|
-
|
1151
|
-
|
1152
|
-
|
1153
|
-
|
1154
|
-
|
1155
|
-
|
1156
|
-
|
1157
|
-
}
|
1158
|
-
|
1159
|
-
|
1160
|
-
|
1161
|
-
|
1162
|
-
|
1163
|
-
|
1164
|
-
|
1165
|
-
|
1166
|
-
|
1167
|
-
|
1168
|
-
|
1169
|
-
|
1170
|
-
|
1171
|
-
|
1172
|
-
|
1173
|
-
|
1174
|
-
|
1175
|
-
|
1176
|
-
|
1177
|
-
|
1178
|
-
|
1179
|
-
|
1180
|
-
|
1181
|
-
|
1182
|
-
|
1183
|
-
|
1184
|
-
|
1185
|
-
|
1186
|
-
|
1187
|
-
|
1188
|
-
|
1189
|
-
|
1190
|
-
|
1191
|
-
|
1192
|
-
|
1193
|
-
|
1194
|
-
|
1195
|
-
|
1196
|
-
|
1197
|
-
|
1198
|
-
|
1199
|
-
|
1200
|
-
|
1201
|
-
|
1202
|
-
|
1203
|
-
|
1204
|
-
|
1205
|
-
|
1206
|
-
|
1207
|
-
|
1208
|
-
tex->
|
1209
|
-
|
1210
|
-
|
1211
|
-
|
1212
|
-
|
1213
|
-
|
1214
|
-
|
1215
|
-
|
1216
|
-
|
1217
|
-
|
1218
|
-
|
1219
|
-
|
1220
|
-
|
1221
|
-
|
1222
|
-
|
1223
|
-
|
1224
|
-
|
1225
|
-
|
1226
|
-
|
1227
|
-
|
1228
|
-
|
1229
|
-
|
1230
|
-
|
1231
|
-
|
1232
|
-
|
1233
|
-
|
1234
|
-
|
1235
|
-
|
1236
|
-
|
1237
|
-
|
1238
|
-
|
1239
|
-
|
1240
|
-
|
1241
|
-
|
1242
|
-
|
1243
|
-
|
1244
|
-
|
1245
|
-
|
1246
|
-
|
1247
|
-
|
1248
|
-
|
1249
|
-
|
1250
|
-
|
1251
|
-
|
1252
|
-
|
1253
|
-
|
1254
|
-
|
1255
|
-
|
1256
|
-
|
1257
|
-
|
1258
|
-
|
1259
|
-
|
1260
|
-
|
1261
|
-
|
1262
|
-
|
1263
|
-
|
1264
|
-
|
1265
|
-
|
1266
|
-
|
1267
|
-
|
1268
|
-
|
1269
|
-
|
1270
|
-
|
1271
|
-
|
1272
|
-
|
1273
|
-
|
1274
|
-
|
1275
|
-
|
1276
|
-
|
1277
|
-
/*
|
1278
|
-
|
1279
|
-
|
1280
|
-
|
1281
|
-
|
1282
|
-
|
1283
|
-
|
1284
|
-
|
1285
|
-
|
1286
|
-
|
1287
|
-
|
1288
|
-
|
1289
|
-
|
1290
|
-
|
1291
|
-
|
1292
|
-
|
1293
|
-
|
1294
|
-
|
1295
|
-
|
1296
|
-
|
1297
|
-
|
1298
|
-
|
1299
|
-
|
1300
|
-
|
1301
|
-
|
1302
|
-
|
1303
|
-
|
1304
|
-
|
1305
|
-
|
1306
|
-
|
1307
|
-
|
1308
|
-
|
1309
|
-
|
1310
|
-
|
1311
|
-
|
1312
|
-
|
1313
|
-
|
1
|
+
#include "texplay.h"
|
2
|
+
#include "utils.h"
|
3
|
+
#include "graphics_utils.h"
|
4
|
+
#include "cache.h"
|
5
|
+
|
6
|
+
#ifdef __APPLE__
|
7
|
+
# include <AvailabilityMacros.h>
|
8
|
+
#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_9
|
9
|
+
# include <GLUT/glut.h>
|
10
|
+
#else
|
11
|
+
# include <GL/glut.h>
|
12
|
+
#endif
|
13
|
+
#else
|
14
|
+
# include <GL/glut.h>
|
15
|
+
#endif
|
16
|
+
|
17
|
+
|
18
|
+
/* small helper functions */
|
19
|
+
static void initialize_action_struct(action_struct * cur, VALUE hash_arg, sync_ sync_mode);
|
20
|
+
static void process_common_hash_args(action_struct * cur, VALUE * hash_arg, sync_ sync_mode, bool primary);
|
21
|
+
static void prepare_drawing_mode(action_struct * cur);
|
22
|
+
static void prepare_alpha_blend(action_struct * cur);
|
23
|
+
static void prepare_fill_texture(action_struct * cur);
|
24
|
+
static void prepare_color_control(action_struct * cur);
|
25
|
+
static void prepare_color_select(action_struct * cur);
|
26
|
+
static rgba apply_lerp(action_struct * payload, texture_info * tex, int x, int y);
|
27
|
+
static rgba apply_alpha_blend(action_struct * payload, texture_info * tex, int x, int y, rgba blended_pixel);
|
28
|
+
static rgba apply_drawing_mode(action_struct * payload, texture_info * tex, int x, int y, rgba blended_pixel);
|
29
|
+
|
30
|
+
static rgba apply_color_control_transform(action_struct * payload, texture_info * tex, int x, int y);
|
31
|
+
static rgba exec_color_control_proc(action_struct * cur, texture_info * tex, int x, int y, rgba blended_pixel);
|
32
|
+
/* end helpers */
|
33
|
+
|
34
|
+
|
35
|
+
void
|
36
|
+
update_lazy_bounds(action_struct * cur, texture_info * tex)
|
37
|
+
{
|
38
|
+
|
39
|
+
/* only update global bounds if we're doing a lazy_sync */
|
40
|
+
if (cur->sync_mode != lazy_sync)
|
41
|
+
return;
|
42
|
+
|
43
|
+
VALUE lazy_bounds;
|
44
|
+
int xmin, ymin, xmax, ymax;
|
45
|
+
|
46
|
+
lazy_bounds = get_image_local(tex->image, LAZY_BOUNDS);
|
47
|
+
|
48
|
+
xmin = INT2FIX(MIN(cur->xmin, FIX2INT(get_from_array(lazy_bounds, 0))));
|
49
|
+
ymin = INT2FIX(MIN(cur->ymin, FIX2INT(get_from_array(lazy_bounds, 1))));
|
50
|
+
xmax = INT2FIX(MAX(cur->xmax, FIX2INT(get_from_array(lazy_bounds, 2))));
|
51
|
+
ymax = INT2FIX(MAX(cur->ymax, FIX2INT(get_from_array(lazy_bounds, 3))));
|
52
|
+
|
53
|
+
set_array_value(lazy_bounds, 0, xmin);
|
54
|
+
set_array_value(lazy_bounds, 1, ymin);
|
55
|
+
set_array_value(lazy_bounds, 2, xmax);
|
56
|
+
set_array_value(lazy_bounds, 3, ymax);
|
57
|
+
}
|
58
|
+
|
59
|
+
void
|
60
|
+
update_bounds(action_struct * cur, int xmin, int ymin, int xmax, int ymax)
|
61
|
+
{
|
62
|
+
if(xmin > xmax) SWAP(xmin, xmax);
|
63
|
+
if(ymin > ymax) SWAP(ymin, ymax);
|
64
|
+
|
65
|
+
cur->xmin = MIN(cur->xmin, xmin);
|
66
|
+
cur->ymin = MIN(cur->ymin, ymin);
|
67
|
+
cur->xmax = MAX(cur->xmax, xmax);
|
68
|
+
cur->ymax = MAX(cur->ymax, ymax);
|
69
|
+
}
|
70
|
+
|
71
|
+
void
|
72
|
+
set_local_bounds(action_struct * cur, int xmin, int ymin, int xmax, int ymax, texture_info * tex)
|
73
|
+
{
|
74
|
+
|
75
|
+
/* local bounds used by both eager_sync and lazy_sync: */
|
76
|
+
if(cur->sync_mode == no_sync)
|
77
|
+
return;
|
78
|
+
|
79
|
+
/* eager sync: to demarcate precise area to sync to opengl */
|
80
|
+
/* lazy sync: to update global bounds */
|
81
|
+
cur->xmin = xmin;
|
82
|
+
cur->ymin = ymin;
|
83
|
+
cur->xmax = xmax;
|
84
|
+
cur->ymax = ymax;
|
85
|
+
}
|
86
|
+
|
87
|
+
void
|
88
|
+
draw_prologue(action_struct * cur, texture_info * tex, int xmin, int ymin, int xmax, int ymax,
|
89
|
+
VALUE * hash_arg, sync_ sync_mode, bool primary, action_struct ** payload_ptr)
|
90
|
+
{
|
91
|
+
if(!primary) return;
|
92
|
+
|
93
|
+
/* set the payload pointer */
|
94
|
+
*payload_ptr = cur;
|
95
|
+
|
96
|
+
/* not too happy about having this here, look at texplay.h for why */
|
97
|
+
cur->tex = tex;
|
98
|
+
|
99
|
+
process_common_hash_args(cur, hash_arg, sync_mode, primary);
|
100
|
+
|
101
|
+
set_local_bounds(cur, xmin, ymin, xmax, ymax, tex);
|
102
|
+
}
|
103
|
+
|
104
|
+
void
|
105
|
+
draw_epilogue(action_struct * cur, texture_info * tex, bool primary)
|
106
|
+
{
|
107
|
+
/* only primary actions get sync'd */
|
108
|
+
if(!primary) return;
|
109
|
+
|
110
|
+
switch(cur->sync_mode) {
|
111
|
+
|
112
|
+
/* do not sync */
|
113
|
+
case no_sync:
|
114
|
+
return;
|
115
|
+
break;
|
116
|
+
|
117
|
+
/* sync immediately */
|
118
|
+
case eager_sync:
|
119
|
+
create_subtexture_and_sync_to_gl(IMAGE_BOUNDS(cur), tex);
|
120
|
+
break;
|
121
|
+
|
122
|
+
/* sync later (at end of paint block?) */
|
123
|
+
case lazy_sync:
|
124
|
+
update_lazy_bounds(cur, tex);
|
125
|
+
break;
|
126
|
+
|
127
|
+
default:
|
128
|
+
rb_raise(rb_eRuntimeError,
|
129
|
+
"sync_mode may only be: lazy_sync, eager_sync, no_sync. got %d\n", cur->sync_mode);
|
130
|
+
}
|
131
|
+
}
|
132
|
+
|
133
|
+
/* set the pixel color at (x, y) */
|
134
|
+
void
|
135
|
+
set_pixel_color(rgba * pixel_color, texture_info * tex, int x, int y)
|
136
|
+
{
|
137
|
+
float * tex_data;
|
138
|
+
|
139
|
+
/* should pixel be drawn ? */
|
140
|
+
if (x > (tex->width - 1) || x < 0 || y > (tex->height - 1) || y < 0)
|
141
|
+
return;
|
142
|
+
|
143
|
+
/* if not a color then do not draw */
|
144
|
+
if(not_a_color(*pixel_color))
|
145
|
+
return;
|
146
|
+
|
147
|
+
tex_data = get_pixel_data(tex, x, y);
|
148
|
+
|
149
|
+
/* set the pixel color */
|
150
|
+
tex_data[red] = pixel_color->red;
|
151
|
+
tex_data[green] = pixel_color->green;
|
152
|
+
tex_data[blue] = pixel_color->blue;
|
153
|
+
tex_data[alpha] = pixel_color->alpha;
|
154
|
+
}
|
155
|
+
|
156
|
+
/* utility func to manage both kinds of color comparions */
|
157
|
+
static bool
|
158
|
+
cmp_color_with_or_without_tolerance(rgba c1, rgba c2, action_struct * payload)
|
159
|
+
{
|
160
|
+
return payload->pen.has_tolerance ? cmp_color_with_tolerance(c1, c2, payload->pen.tolerance) : cmp_color(c1, c2);
|
161
|
+
}
|
162
|
+
|
163
|
+
static bool
|
164
|
+
skip_pixel(rgba source_color, action_struct * payload, texture_info * tex, int x, int y)
|
165
|
+
{
|
166
|
+
|
167
|
+
if (!payload->pen.has_color_select) return false;
|
168
|
+
|
169
|
+
rgba dest_color = get_pixel_color(tex, x, y);
|
170
|
+
bool color_match = false;
|
171
|
+
|
172
|
+
if (payload->pen.source_select.size > 0) {
|
173
|
+
for (int i = 0; i < payload->pen.source_select.size; i++) {
|
174
|
+
if (cmp_color_with_or_without_tolerance(source_color, payload->pen.source_select.colors[i], payload)) {
|
175
|
+
color_match = true;
|
176
|
+
break;
|
177
|
+
}
|
178
|
+
if (!color_match) return true;
|
179
|
+
}
|
180
|
+
}
|
181
|
+
|
182
|
+
if (payload->pen.source_ignore.size > 0) {
|
183
|
+
for (int i = 0; i < payload->pen.source_ignore.size; i++) {
|
184
|
+
if (cmp_color_with_or_without_tolerance(source_color, payload->pen.source_ignore.colors[i], payload))
|
185
|
+
return true;
|
186
|
+
}
|
187
|
+
}
|
188
|
+
|
189
|
+
color_match = false;
|
190
|
+
if (payload->pen.dest_select.size > 0) {
|
191
|
+
for (int i = 0; i < payload->pen.dest_select.size; i++) {
|
192
|
+
if (cmp_color_with_or_without_tolerance(dest_color, payload->pen.dest_select.colors[i], payload)) {
|
193
|
+
color_match = true;
|
194
|
+
break;
|
195
|
+
}
|
196
|
+
}
|
197
|
+
if (!color_match) return true;
|
198
|
+
}
|
199
|
+
|
200
|
+
if (payload->pen.dest_ignore.size > 0) {
|
201
|
+
for (int i = 0; i < payload->pen.dest_ignore.size; i++) {
|
202
|
+
if (cmp_color_with_or_without_tolerance(dest_color, payload->pen.dest_ignore.colors[i], payload))
|
203
|
+
return true;
|
204
|
+
}
|
205
|
+
}
|
206
|
+
|
207
|
+
return false;
|
208
|
+
}
|
209
|
+
|
210
|
+
|
211
|
+
void
|
212
|
+
set_pixel_color_with_style(action_struct * payload, texture_info * tex, int x, int y)
|
213
|
+
{
|
214
|
+
|
215
|
+
rgba blended_pixel;
|
216
|
+
|
217
|
+
blended_pixel = payload->color;
|
218
|
+
|
219
|
+
|
220
|
+
/* for linear interpolation */
|
221
|
+
if(payload->pen.has_lerp) {
|
222
|
+
blended_pixel = apply_lerp(payload, tex, x, y);
|
223
|
+
}
|
224
|
+
|
225
|
+
/* for color_control transform */
|
226
|
+
if(payload->pen.has_color_control_transform)
|
227
|
+
blended_pixel = apply_color_control_transform(payload, tex, x, y);
|
228
|
+
|
229
|
+
/* for texture fill */
|
230
|
+
if(payload->pen.has_source_texture)
|
231
|
+
blended_pixel = get_pixel_color(&payload->pen.source_tex,
|
232
|
+
x % payload->pen.source_tex.width,
|
233
|
+
y % payload->pen.source_tex.height);
|
234
|
+
|
235
|
+
/* for color_control proc */
|
236
|
+
if(payload->pen.has_color_control_proc)
|
237
|
+
blended_pixel = exec_color_control_proc(payload, tex, x, y, blended_pixel);
|
238
|
+
|
239
|
+
/* should skip this pixel? color selection */
|
240
|
+
if (skip_pixel(blended_pixel, payload, tex, x, y))
|
241
|
+
return;
|
242
|
+
|
243
|
+
/* drawing modes */
|
244
|
+
if(payload->pen.has_drawing_mode) {
|
245
|
+
blended_pixel = apply_drawing_mode(payload, tex, x, y, blended_pixel);
|
246
|
+
}
|
247
|
+
|
248
|
+
/* TO DO: refactor into its own helper function
|
249
|
+
& rewrite using sse2 */
|
250
|
+
if(payload->pen.alpha_blend)
|
251
|
+
blended_pixel = apply_alpha_blend(payload, tex, x, y, blended_pixel);
|
252
|
+
|
253
|
+
|
254
|
+
set_pixel_color(&blended_pixel, tex, x, y);
|
255
|
+
}
|
256
|
+
|
257
|
+
|
258
|
+
rgba
|
259
|
+
get_pixel_color_from_chunk(float * chunk, int width, int height, int x, int y)
|
260
|
+
{
|
261
|
+
rgba my_color;
|
262
|
+
|
263
|
+
int offset;
|
264
|
+
|
265
|
+
if (x > (width - 1) || x < 0 || y > (height - 1) || y < 0)
|
266
|
+
return not_a_color_v;
|
267
|
+
|
268
|
+
offset = 4 * (x + y * width);
|
269
|
+
|
270
|
+
my_color.red = chunk[offset + red];
|
271
|
+
my_color.green = chunk[offset + green];
|
272
|
+
my_color.blue = chunk[offset + blue];
|
273
|
+
my_color.alpha = chunk[offset + alpha];
|
274
|
+
|
275
|
+
return my_color;
|
276
|
+
}
|
277
|
+
|
278
|
+
|
279
|
+
rgba
|
280
|
+
get_pixel_color(texture_info * tex, int x, int y)
|
281
|
+
{
|
282
|
+
rgba my_color;
|
283
|
+
|
284
|
+
int offset;
|
285
|
+
|
286
|
+
/* if pixel location is out of range return not_a_color_v */
|
287
|
+
if (x > (tex->width - 1) || x < 0 || y > (tex->height - 1) || y < 0)
|
288
|
+
return not_a_color_v;
|
289
|
+
|
290
|
+
offset = calc_pixel_offset(tex, x, y);
|
291
|
+
|
292
|
+
my_color.red = tex->td_array[offset + red];
|
293
|
+
my_color.green = tex->td_array[offset + green];
|
294
|
+
my_color.blue = tex->td_array[offset + blue];
|
295
|
+
my_color.alpha = tex->td_array[offset + alpha];
|
296
|
+
|
297
|
+
return my_color;
|
298
|
+
}
|
299
|
+
|
300
|
+
/* return the array where pixel data is stored */
|
301
|
+
float*
|
302
|
+
get_pixel_data(texture_info * tex, int x, int y)
|
303
|
+
{
|
304
|
+
int offset = calc_pixel_offset(tex, x, y);
|
305
|
+
|
306
|
+
return &tex->td_array[offset];
|
307
|
+
}
|
308
|
+
|
309
|
+
/* if 2nd param is Qnil, then create a blank image with 'width' and 'height
|
310
|
+
otherwise, try to use the 2nd param (dup) to create a duplicate image
|
311
|
+
*/
|
312
|
+
VALUE
|
313
|
+
create_image(VALUE window, int width, int height)
|
314
|
+
{
|
315
|
+
static VALUE empty_image_stub = 0;
|
316
|
+
static VALUE image = 0;
|
317
|
+
|
318
|
+
if (empty_image_stub == 0) {
|
319
|
+
VALUE gosu = rb_const_get(rb_cObject, rb_intern("Gosu"));
|
320
|
+
VALUE tp = rb_const_get(rb_cObject, rb_intern("TexPlay"));
|
321
|
+
empty_image_stub = rb_const_get(tp, rb_intern("EmptyImageStub"));
|
322
|
+
image = rb_const_get(gosu, rb_intern("Image"));
|
323
|
+
}
|
324
|
+
|
325
|
+
VALUE rmagick_img;
|
326
|
+
VALUE new_image;
|
327
|
+
VALUE options = rb_hash_new();
|
328
|
+
|
329
|
+
set_hash_value(options, "caching", Qfalse);
|
330
|
+
|
331
|
+
rmagick_img = rb_funcall(empty_image_stub, rb_intern("new"), 2, INT2FIX(width), INT2FIX(height));
|
332
|
+
|
333
|
+
new_image = rb_funcall(image, rb_intern("new"), 3, window, rmagick_img, options);
|
334
|
+
|
335
|
+
return new_image;
|
336
|
+
}
|
337
|
+
|
338
|
+
|
339
|
+
|
340
|
+
/* static functions */
|
341
|
+
static void
|
342
|
+
initialize_action_struct(action_struct * cur, VALUE hash_arg, sync_ sync_mode)
|
343
|
+
{
|
344
|
+
/* initialize action-struct to default values */
|
345
|
+
cur->sync_mode = sync_mode;
|
346
|
+
cur->hash_arg = hash_arg;
|
347
|
+
|
348
|
+
cur->color = convert_image_local_color_to_rgba(cur->tex->image);
|
349
|
+
cur->pen.has_color_control_proc = false;
|
350
|
+
cur->pen.has_color_control_transform = false;
|
351
|
+
cur->pen.has_source_texture = false;
|
352
|
+
|
353
|
+
/* alpha blending */
|
354
|
+
cur->pen.alpha_blend = false;
|
355
|
+
|
356
|
+
/* set static color control transformations to defaults */
|
357
|
+
cur->pen.color_mult.red = 1.0;
|
358
|
+
cur->pen.color_mult.green = 1.0;
|
359
|
+
cur->pen.color_mult.blue = 1.0;
|
360
|
+
cur->pen.color_mult.alpha = 1.0;
|
361
|
+
|
362
|
+
cur->pen.color_add.red = 0.0;
|
363
|
+
cur->pen.color_add.green = 0.0;
|
364
|
+
cur->pen.color_add.blue = 0.0;
|
365
|
+
cur->pen.color_add.alpha = 0.0;
|
366
|
+
|
367
|
+
/* lerp is off by default */
|
368
|
+
cur->pen.has_lerp = false;
|
369
|
+
|
370
|
+
/* drawing mode is off by deafult */
|
371
|
+
cur->pen.has_drawing_mode = false;
|
372
|
+
|
373
|
+
/* color selection */
|
374
|
+
cur->pen.has_color_select = false;
|
375
|
+
cur->pen.source_select.size = 0;
|
376
|
+
cur->pen.source_ignore.size = 0;
|
377
|
+
cur->pen.dest_select.size = 0;
|
378
|
+
cur->pen.dest_ignore.size = 0;
|
379
|
+
|
380
|
+
/* tolerance */
|
381
|
+
cur->pen.has_tolerance = false;
|
382
|
+
cur->pen.tolerance = 0.0;
|
383
|
+
}
|
384
|
+
|
385
|
+
/* TODO: fix this function below, it's too ugly and bulky and weird **/
|
386
|
+
static void
|
387
|
+
process_common_hash_args(action_struct * cur, VALUE * hash_arg, sync_ sync_mode, bool primary)
|
388
|
+
{
|
389
|
+
|
390
|
+
VALUE user_defaults;
|
391
|
+
VALUE hash_blend;
|
392
|
+
|
393
|
+
|
394
|
+
/* if a hash doesn't exist then create one */
|
395
|
+
if(!is_a_hash(*hash_arg))
|
396
|
+
*hash_arg = rb_hash_new();
|
397
|
+
|
398
|
+
/* init the action to default values */
|
399
|
+
initialize_action_struct(cur, *hash_arg, sync_mode);
|
400
|
+
|
401
|
+
/* get the user default options & merge with given options */
|
402
|
+
user_defaults = get_image_local(cur->tex->image, USER_DEFAULTS);
|
403
|
+
hash_blend = rb_funcall(user_defaults, rb_intern("merge"), 1, *hash_arg);
|
404
|
+
rb_funcall(*hash_arg, rb_intern("merge!"), 1, hash_blend);
|
405
|
+
|
406
|
+
if(has_optional_hash_arg(*hash_arg, "color")) {
|
407
|
+
VALUE c = get_from_hash(*hash_arg, "color");
|
408
|
+
cur->color = convert_rb_color_to_rgba(c);
|
409
|
+
if(c == string2sym("random")) {
|
410
|
+
set_hash_value(*hash_arg, "color", convert_rgba_to_rb_color(&cur->color));
|
411
|
+
}
|
412
|
+
}
|
413
|
+
|
414
|
+
/* shadows */
|
415
|
+
if(RTEST(get_from_hash(*hash_arg, "shadow"))) {
|
416
|
+
cur->pen.color_mult.red = 0.66;
|
417
|
+
cur->pen.color_mult.green = 0.66;
|
418
|
+
cur->pen.color_mult.blue = 0.66;
|
419
|
+
cur->pen.color_mult.alpha = 1;
|
420
|
+
|
421
|
+
cur->pen.has_color_control_transform = true;
|
422
|
+
}
|
423
|
+
|
424
|
+
/* tolerance */
|
425
|
+
if(RTEST(get_from_hash(*hash_arg, "tolerance"))) {
|
426
|
+
cur->pen.tolerance = NUM2DBL(get_from_hash(*hash_arg, "tolerance"));
|
427
|
+
|
428
|
+
/* maximum length of hypotonese extended in 4-space (color space) is sqrt(4) */
|
429
|
+
if (cur->pen.tolerance >= 2)
|
430
|
+
cur->pen.tolerance = 2;
|
431
|
+
|
432
|
+
if (cur->pen.tolerance < 0)
|
433
|
+
cur->pen.tolerance = 0;
|
434
|
+
|
435
|
+
cur->pen.has_tolerance = true;
|
436
|
+
}
|
437
|
+
|
438
|
+
/* lerp */
|
439
|
+
if(RTEST(get_from_hash(*hash_arg, "lerp"))) {
|
440
|
+
cur->pen.lerp = NUM2DBL(get_from_hash(*hash_arg, "lerp"));
|
441
|
+
|
442
|
+
/* bounds */
|
443
|
+
if(cur->pen.lerp > 1.0) cur->pen.lerp = 1.0;
|
444
|
+
if(cur->pen.lerp < 0.0) cur->pen.lerp = 0.0;
|
445
|
+
cur->pen.has_lerp = true;
|
446
|
+
}
|
447
|
+
|
448
|
+
/* sync mode */
|
449
|
+
if(has_optional_hash_arg(*hash_arg, "sync_mode")) {
|
450
|
+
VALUE user_sync_mode = get_from_hash(*hash_arg, "sync_mode");
|
451
|
+
|
452
|
+
Check_Type(user_sync_mode, T_SYMBOL);
|
453
|
+
|
454
|
+
if(user_sync_mode == string2sym("lazy_sync"))
|
455
|
+
cur->sync_mode = lazy_sync;
|
456
|
+
else if(user_sync_mode == string2sym("eager_sync"))
|
457
|
+
cur->sync_mode = eager_sync;
|
458
|
+
else if(user_sync_mode == string2sym("no_sync"))
|
459
|
+
cur->sync_mode = no_sync;
|
460
|
+
else
|
461
|
+
rb_raise(rb_eArgError, "unrecognized sync mode: %s\n. Allowable modes are "
|
462
|
+
":lazy_sync, :eager_sync, :no_sync.",
|
463
|
+
sym2string(user_sync_mode));
|
464
|
+
|
465
|
+
delete_from_hash(*hash_arg, "sync_mode");
|
466
|
+
|
467
|
+
}
|
468
|
+
|
469
|
+
/* prepare color selection */
|
470
|
+
prepare_color_select(cur);
|
471
|
+
|
472
|
+
/* process drawing mode */
|
473
|
+
prepare_drawing_mode(cur);
|
474
|
+
|
475
|
+
/* process the color_control block or transform (if there is one) */
|
476
|
+
prepare_color_control(cur);
|
477
|
+
|
478
|
+
/* process the filling texture (if there is one) */
|
479
|
+
prepare_fill_texture(cur);
|
480
|
+
|
481
|
+
/* does the user want to blend alpha values ? */
|
482
|
+
prepare_alpha_blend(cur);
|
483
|
+
}
|
484
|
+
|
485
|
+
static void
|
486
|
+
prepare_alpha_blend(action_struct * cur)
|
487
|
+
{
|
488
|
+
if(has_optional_hash_arg(cur->hash_arg, "alpha_blend")) {
|
489
|
+
|
490
|
+
VALUE blend_mode = get_from_hash(cur->hash_arg, "alpha_blend");
|
491
|
+
|
492
|
+
/* true is equivalent to default blend mode, 'source' */
|
493
|
+
if(blend_mode == Qtrue)
|
494
|
+
blend_mode = string2sym("source");
|
495
|
+
|
496
|
+
/* where false or nil is passed */
|
497
|
+
if(!RTEST(blend_mode)) {
|
498
|
+
cur->pen.alpha_blend = false;
|
499
|
+
return;
|
500
|
+
}
|
501
|
+
|
502
|
+
cur->pen.alpha_blend = true;
|
503
|
+
|
504
|
+
Check_Type(blend_mode, T_SYMBOL);
|
505
|
+
|
506
|
+
if(blend_mode == string2sym("source")) {
|
507
|
+
cur->pen.alpha_blend_mode = source;
|
508
|
+
}
|
509
|
+
else if(blend_mode == string2sym("dest")) {
|
510
|
+
cur->pen.alpha_blend_mode = dest;
|
511
|
+
}
|
512
|
+
else if(blend_mode == string2sym("source_with_fixed_alpha")) {
|
513
|
+
cur->pen.alpha_blend_mode = source_with_fixed_alpha;
|
514
|
+
}
|
515
|
+
else if(blend_mode == string2sym("dest_with_fixed_alpha")) {
|
516
|
+
cur->pen.alpha_blend_mode = dest_with_fixed_alpha;
|
517
|
+
}
|
518
|
+
else
|
519
|
+
rb_raise(rb_eArgError, "unrecognized blend mode: %s\n.",
|
520
|
+
sym2string(blend_mode));
|
521
|
+
|
522
|
+
}
|
523
|
+
|
524
|
+
|
525
|
+
}
|
526
|
+
|
527
|
+
static void
|
528
|
+
prepare_drawing_mode(action_struct * cur)
|
529
|
+
{
|
530
|
+
if(is_a_hash(cur->hash_arg)) {
|
531
|
+
/* drawing mode */
|
532
|
+
if(has_optional_hash_arg(cur->hash_arg, "mode")) {
|
533
|
+
cur->pen.has_drawing_mode = true;
|
534
|
+
|
535
|
+
VALUE draw_mode = get_from_hash(cur->hash_arg, "mode");
|
536
|
+
|
537
|
+
|
538
|
+
Check_Type(draw_mode, T_SYMBOL);
|
539
|
+
|
540
|
+
if(draw_mode == string2sym("default")) {
|
541
|
+
cur->pen.has_drawing_mode = false;
|
542
|
+
|
543
|
+
return;
|
544
|
+
}
|
545
|
+
else if(draw_mode == string2sym("clear"))
|
546
|
+
cur->pen.drawing_mode = clear;
|
547
|
+
|
548
|
+
else if(draw_mode == string2sym("copy"))
|
549
|
+
cur->pen.drawing_mode = copy;
|
550
|
+
|
551
|
+
else if(draw_mode == string2sym("noop"))
|
552
|
+
cur->pen.drawing_mode = noop;
|
553
|
+
|
554
|
+
else if(draw_mode == string2sym("set"))
|
555
|
+
cur->pen.drawing_mode = set;
|
556
|
+
|
557
|
+
else if(draw_mode == string2sym("copy_inverted"))
|
558
|
+
cur->pen.drawing_mode = copy_inverted;
|
559
|
+
|
560
|
+
else if(draw_mode == string2sym("invert"))
|
561
|
+
cur->pen.drawing_mode = invert;
|
562
|
+
|
563
|
+
else if(draw_mode == string2sym("and_reverse"))
|
564
|
+
cur->pen.drawing_mode = and_reverse;
|
565
|
+
|
566
|
+
else if(draw_mode == string2sym("and"))
|
567
|
+
cur->pen.drawing_mode = and;
|
568
|
+
|
569
|
+
else if(draw_mode == string2sym("or"))
|
570
|
+
cur->pen.drawing_mode = or;
|
571
|
+
|
572
|
+
else if(draw_mode == string2sym("nand"))
|
573
|
+
cur->pen.drawing_mode = nand;
|
574
|
+
|
575
|
+
else if(draw_mode == string2sym("nor"))
|
576
|
+
cur->pen.drawing_mode = nor;
|
577
|
+
|
578
|
+
else if(draw_mode == string2sym("xor"))
|
579
|
+
cur->pen.drawing_mode = xor;
|
580
|
+
|
581
|
+
else if(draw_mode == string2sym("equiv"))
|
582
|
+
cur->pen.drawing_mode = equiv;
|
583
|
+
|
584
|
+
else if(draw_mode == string2sym("and_inverted"))
|
585
|
+
cur->pen.drawing_mode = and_inverted;
|
586
|
+
|
587
|
+
else if(draw_mode == string2sym("or_inverted"))
|
588
|
+
cur->pen.drawing_mode = or_inverted;
|
589
|
+
|
590
|
+
else if(draw_mode == string2sym("additive"))
|
591
|
+
cur->pen.drawing_mode = additive;
|
592
|
+
else if(draw_mode == string2sym("multiply"))
|
593
|
+
cur->pen.drawing_mode = multiply;
|
594
|
+
else if(draw_mode == string2sym("screen"))
|
595
|
+
cur->pen.drawing_mode = screen;
|
596
|
+
else if(draw_mode == string2sym("overlay"))
|
597
|
+
cur->pen.drawing_mode = overlay;
|
598
|
+
else if(draw_mode == string2sym("darken"))
|
599
|
+
cur->pen.drawing_mode = darken;
|
600
|
+
else if(draw_mode == string2sym("lighten"))
|
601
|
+
cur->pen.drawing_mode = lighten;
|
602
|
+
else if(draw_mode == string2sym("color_dodge"))
|
603
|
+
cur->pen.drawing_mode = color_dodge;
|
604
|
+
else if(draw_mode == string2sym("color_burn"))
|
605
|
+
cur->pen.drawing_mode = color_burn;
|
606
|
+
else if(draw_mode == string2sym("hard_light"))
|
607
|
+
cur->pen.drawing_mode = hard_light;
|
608
|
+
else if(draw_mode == string2sym("soft_light"))
|
609
|
+
cur->pen.drawing_mode = soft_light;
|
610
|
+
else if(draw_mode == string2sym("difference"))
|
611
|
+
cur->pen.drawing_mode = difference;
|
612
|
+
else if(draw_mode == string2sym("exclusion"))
|
613
|
+
cur->pen.drawing_mode = exclusion;
|
614
|
+
else
|
615
|
+
rb_raise(rb_eArgError, "unrecognized drawing mode: %s\n.",
|
616
|
+
sym2string(draw_mode));
|
617
|
+
}
|
618
|
+
}
|
619
|
+
}
|
620
|
+
|
621
|
+
|
622
|
+
/* set action color to return value of color_control proc */
|
623
|
+
static void
|
624
|
+
prepare_color_control(action_struct * cur)
|
625
|
+
{
|
626
|
+
|
627
|
+
if(is_a_hash(cur->hash_arg)) {
|
628
|
+
VALUE try_val = get_from_hash(cur->hash_arg, "color_control");
|
629
|
+
|
630
|
+
if(rb_respond_to(try_val, rb_intern("call"))) {
|
631
|
+
cur->pen.color_control_proc = try_val;
|
632
|
+
cur->pen.color_control_arity = FIX2INT(rb_funcall(try_val, rb_intern("arity"), 0));
|
633
|
+
cur->pen.has_color_control_proc = true;
|
634
|
+
}
|
635
|
+
else if(is_a_hash(try_val)) {
|
636
|
+
VALUE try_add = get_from_hash(try_val, "add");
|
637
|
+
VALUE try_mult = get_from_hash(try_val, "mult");
|
638
|
+
|
639
|
+
if(is_an_array(try_add)) {
|
640
|
+
|
641
|
+
cur->pen.color_add = convert_rb_color_to_rgba(try_add);
|
642
|
+
|
643
|
+
cur->pen.has_color_control_transform = true;
|
644
|
+
}
|
645
|
+
if(is_an_array(try_mult)) {
|
646
|
+
|
647
|
+
cur->pen.color_mult = convert_rb_color_to_rgba(try_mult);
|
648
|
+
|
649
|
+
cur->pen.has_color_control_transform = true;
|
650
|
+
}
|
651
|
+
|
652
|
+
}
|
653
|
+
}
|
654
|
+
}
|
655
|
+
|
656
|
+
static rgba
|
657
|
+
exec_color_control_proc(action_struct * cur, texture_info * tex, int x, int y, rgba blended_pixel)
|
658
|
+
{
|
659
|
+
int arity = cur->pen.color_control_arity;
|
660
|
+
VALUE proc = cur->pen.color_control_proc;
|
661
|
+
rgba old_color = get_pixel_color(tex, x, y);
|
662
|
+
rgba current_color = blended_pixel;
|
663
|
+
rgba new_color;
|
664
|
+
|
665
|
+
if(!cur->pen.has_color_control_proc)
|
666
|
+
rb_raise(rb_eRuntimeError, "needs a proc");
|
667
|
+
|
668
|
+
switch(arity) {
|
669
|
+
case -1:
|
670
|
+
case 0:
|
671
|
+
new_color = convert_rb_color_to_rgba(rb_funcall(proc, rb_intern("call"), 0));
|
672
|
+
break;
|
673
|
+
|
674
|
+
case 1:
|
675
|
+
new_color = convert_rb_color_to_rgba(rb_funcall(proc, rb_intern("call"), arity,
|
676
|
+
convert_rgba_to_rb_color(&old_color)));
|
677
|
+
break;
|
678
|
+
|
679
|
+
case 2:
|
680
|
+
new_color = convert_rb_color_to_rgba(rb_funcall(proc, rb_intern("call"), arity,
|
681
|
+
convert_rgba_to_rb_color(&old_color),
|
682
|
+
convert_rgba_to_rb_color(¤t_color)));
|
683
|
+
break;
|
684
|
+
|
685
|
+
case 3:
|
686
|
+
new_color = convert_rb_color_to_rgba(rb_funcall(proc, rb_intern("call"), arity,
|
687
|
+
convert_rgba_to_rb_color(&old_color),
|
688
|
+
INT2FIX(x), INT2FIX(y)));
|
689
|
+
break;
|
690
|
+
case 4:
|
691
|
+
new_color = convert_rb_color_to_rgba(rb_funcall(proc, rb_intern("call"), arity,
|
692
|
+
convert_rgba_to_rb_color(&old_color),
|
693
|
+
convert_rgba_to_rb_color(¤t_color),
|
694
|
+
INT2FIX(x), INT2FIX(y)));
|
695
|
+
break;
|
696
|
+
default:
|
697
|
+
rb_raise(rb_eArgError, "permissible arities for color_control proc are 1, 2, 3 and 4. Got %d\n",
|
698
|
+
arity);
|
699
|
+
}
|
700
|
+
|
701
|
+
/* update the action color */
|
702
|
+
return new_color;
|
703
|
+
}
|
704
|
+
|
705
|
+
static void
|
706
|
+
prepare_fill_texture(action_struct * payload)
|
707
|
+
{
|
708
|
+
if(is_a_hash(payload->hash_arg)) {
|
709
|
+
VALUE try_image = get_from_hash(payload->hash_arg, "texture");
|
710
|
+
if(is_gosu_image(try_image)) {
|
711
|
+
|
712
|
+
get_texture_info(try_image, &payload->pen.source_tex);
|
713
|
+
payload->pen.has_source_texture = true;
|
714
|
+
}
|
715
|
+
}
|
716
|
+
}
|
717
|
+
|
718
|
+
static void
|
719
|
+
process_select_color_list(rgba_list * clist, VALUE try_color)
|
720
|
+
{
|
721
|
+
/* is a general array of colors? i.e [:red, Gosu::Color::RED, [1,1,1,1] ] */
|
722
|
+
if (TYPE(try_color) == T_ARRAY && not_rb_raw_color(try_color)) {
|
723
|
+
int num_colors = RARRAY_LEN(try_color);
|
724
|
+
|
725
|
+
if (num_colors > RGBA_LIST_SIZE)
|
726
|
+
rb_raise(rb_eArgError, "Too many colors given in array. Maximum is %d\n. Got %d\n",
|
727
|
+
RGBA_LIST_SIZE, num_colors);
|
728
|
+
|
729
|
+
for (int i = 0; i < RARRAY_LEN(try_color); ++i) {
|
730
|
+
clist->colors[i] = convert_rb_color_to_rgba(get_from_array(try_color, i));
|
731
|
+
}
|
732
|
+
|
733
|
+
clist->size = num_colors;
|
734
|
+
}
|
735
|
+
|
736
|
+
/* is a single color value? i.e :red, [1,1,1,1], Gosu::Color::GREEN */
|
737
|
+
else {
|
738
|
+
clist->colors[0] = convert_rb_color_to_rgba(try_color);
|
739
|
+
clist->size = 1;
|
740
|
+
}
|
741
|
+
}
|
742
|
+
|
743
|
+
|
744
|
+
static void
|
745
|
+
prepare_color_select(action_struct * payload)
|
746
|
+
{
|
747
|
+
VALUE try_color = get_from_hash(payload->hash_arg,
|
748
|
+
"source_select");
|
749
|
+
if (!NIL_P(try_color)) {
|
750
|
+
process_select_color_list(&payload->pen.source_select, try_color);
|
751
|
+
payload->pen.has_color_select = true;
|
752
|
+
}
|
753
|
+
|
754
|
+
try_color = get_from_hash(payload->hash_arg,
|
755
|
+
"source_ignore");
|
756
|
+
if (!NIL_P(try_color)) {
|
757
|
+
process_select_color_list(&payload->pen.source_ignore, try_color);
|
758
|
+
payload->pen.has_color_select = true;
|
759
|
+
}
|
760
|
+
|
761
|
+
try_color = get_from_hash(payload->hash_arg,
|
762
|
+
"dest_select");
|
763
|
+
if (!NIL_P(try_color)) {
|
764
|
+
process_select_color_list(&payload->pen.dest_select, try_color);
|
765
|
+
payload->pen.has_color_select = true;
|
766
|
+
}
|
767
|
+
|
768
|
+
try_color = get_from_hash(payload->hash_arg,
|
769
|
+
"dest_ignore");
|
770
|
+
if (!NIL_P(try_color)) {
|
771
|
+
process_select_color_list(&payload->pen.dest_ignore, try_color);
|
772
|
+
payload->pen.has_color_select = true;
|
773
|
+
}
|
774
|
+
|
775
|
+
}
|
776
|
+
|
777
|
+
/***********************************/
|
778
|
+
/**** drawing mode related code ****/
|
779
|
+
/***********************************/
|
780
|
+
|
781
|
+
typedef struct {
|
782
|
+
unsigned char red, green, blue, alpha;
|
783
|
+
} rgba_char;
|
784
|
+
|
785
|
+
static inline rgba_char
|
786
|
+
color_float_to_int_format(rgba c)
|
787
|
+
{
|
788
|
+
return (rgba_char) { c.red * 255,
|
789
|
+
c.green * 255,
|
790
|
+
c.blue * 255,
|
791
|
+
c.alpha * 255
|
792
|
+
};
|
793
|
+
}
|
794
|
+
|
795
|
+
static inline rgba
|
796
|
+
color_int_vals_to_float_format(unsigned char r, unsigned char g, unsigned char b,
|
797
|
+
unsigned char a)
|
798
|
+
{
|
799
|
+
return (rgba) { r / 255.0,
|
800
|
+
g / 255.0,
|
801
|
+
b / 255.0,
|
802
|
+
a / 255.0
|
803
|
+
};
|
804
|
+
}
|
805
|
+
|
806
|
+
/* using terminology from photoshop PDF. b=background, s=source */
|
807
|
+
static inline rgba
|
808
|
+
mode_multiply(rgba b, rgba s)
|
809
|
+
{
|
810
|
+
return (rgba) { b.red * s.red,
|
811
|
+
b.green * s.green,
|
812
|
+
b.blue * s.blue,
|
813
|
+
b.alpha * s.alpha };
|
814
|
+
}
|
815
|
+
|
816
|
+
static inline rgba
|
817
|
+
mode_screen(rgba b, rgba s)
|
818
|
+
{
|
819
|
+
return (rgba) { b.red + s.red - (b.red * s.red),
|
820
|
+
b.green + s.green - (b.green * s.green),
|
821
|
+
b.blue + s.blue - (b.blue * s.blue),
|
822
|
+
b.alpha + s.alpha - (b.alpha * s.alpha) };
|
823
|
+
}
|
824
|
+
|
825
|
+
static inline float
|
826
|
+
mode_hardlight_channel(float b, float s)
|
827
|
+
{
|
828
|
+
if (s <= 0.5)
|
829
|
+
return 2 * b * s;
|
830
|
+
|
831
|
+
else
|
832
|
+
return b + s - (b * s);
|
833
|
+
}
|
834
|
+
|
835
|
+
static inline rgba
|
836
|
+
mode_hardlight(rgba b, rgba s)
|
837
|
+
{
|
838
|
+
return (rgba) { mode_hardlight_channel(b.red, s.red),
|
839
|
+
mode_hardlight_channel(b.green, s.green),
|
840
|
+
mode_hardlight_channel(b.blue, s.blue),
|
841
|
+
mode_hardlight_channel(b.alpha, s.alpha) };
|
842
|
+
}
|
843
|
+
|
844
|
+
/* function from the photoshop PDF to implement soft lighting */
|
845
|
+
static inline float
|
846
|
+
D(float x)
|
847
|
+
{
|
848
|
+
if (x <= 0.25)
|
849
|
+
return ((16 * x - 12) * x + 4) * x;
|
850
|
+
else
|
851
|
+
return sqrt(x);
|
852
|
+
}
|
853
|
+
|
854
|
+
static inline float
|
855
|
+
mode_softlight_channel(float b, float s)
|
856
|
+
{
|
857
|
+
if (s <= 0.5)
|
858
|
+
return b - (1 - 2 * s) * b * (1 - b);
|
859
|
+
else
|
860
|
+
return b + (2 * s - 1) * (D(b) - b);
|
861
|
+
}
|
862
|
+
|
863
|
+
static inline rgba
|
864
|
+
mode_softlight(rgba b, rgba s)
|
865
|
+
{
|
866
|
+
return (rgba) { mode_softlight_channel(b.red, s.red),
|
867
|
+
mode_softlight_channel(b.green, s.green),
|
868
|
+
mode_softlight_channel(b.blue, s.blue),
|
869
|
+
mode_softlight_channel(b.alpha, s.alpha) };
|
870
|
+
}
|
871
|
+
|
872
|
+
static inline float
|
873
|
+
mode_colordodge_channel(float b, float s)
|
874
|
+
{
|
875
|
+
if (s < 1)
|
876
|
+
return MIN(1, b / (1 - s));
|
877
|
+
else
|
878
|
+
return 1;
|
879
|
+
}
|
880
|
+
|
881
|
+
static inline float
|
882
|
+
mode_colorburn_channel(float b, float s)
|
883
|
+
{
|
884
|
+
if (s > 0)
|
885
|
+
return 1 - MIN(1, (1 - b) / s);
|
886
|
+
else
|
887
|
+
return 0;
|
888
|
+
}
|
889
|
+
|
890
|
+
static rgba
|
891
|
+
apply_drawing_mode(action_struct * payload, texture_info * tex, int x, int y, rgba source_pixel)
|
892
|
+
{
|
893
|
+
rgba finished_pixel;
|
894
|
+
|
895
|
+
rgba dest_pixel = get_pixel_color(tex, x, y);
|
896
|
+
|
897
|
+
rgba_char dest_pixel_char = color_float_to_int_format(dest_pixel);
|
898
|
+
rgba_char source_pixel_char = color_float_to_int_format(source_pixel);
|
899
|
+
|
900
|
+
switch(payload->pen.drawing_mode)
|
901
|
+
{
|
902
|
+
|
903
|
+
/* bitwise blending functions */
|
904
|
+
case clear:
|
905
|
+
finished_pixel = (rgba) { 0, 0, 0, 0 };
|
906
|
+
break;
|
907
|
+
case copy:
|
908
|
+
finished_pixel = source_pixel;
|
909
|
+
break;
|
910
|
+
case noop:
|
911
|
+
finished_pixel = dest_pixel;
|
912
|
+
break;
|
913
|
+
case set:
|
914
|
+
finished_pixel = (rgba) { 1, 1, 1, 1 };
|
915
|
+
break;
|
916
|
+
case copy_inverted:
|
917
|
+
finished_pixel = color_int_vals_to_float_format(~source_pixel_char.red,
|
918
|
+
~source_pixel_char.green,
|
919
|
+
~source_pixel_char.blue,
|
920
|
+
source_pixel_char.alpha);
|
921
|
+
break;
|
922
|
+
case invert:
|
923
|
+
finished_pixel = color_int_vals_to_float_format(~dest_pixel_char.red,
|
924
|
+
~dest_pixel_char.green,
|
925
|
+
~dest_pixel_char.blue,
|
926
|
+
dest_pixel_char.alpha);
|
927
|
+
|
928
|
+
break;
|
929
|
+
case and_reverse:
|
930
|
+
finished_pixel = color_int_vals_to_float_format(source_pixel_char.red | ~dest_pixel_char.red,
|
931
|
+
source_pixel_char.green | ~dest_pixel_char.green,
|
932
|
+
source_pixel_char.blue | ~dest_pixel_char.blue,
|
933
|
+
source_pixel_char.alpha);
|
934
|
+
break;
|
935
|
+
case and:
|
936
|
+
finished_pixel = color_int_vals_to_float_format(source_pixel_char.red & dest_pixel_char.red,
|
937
|
+
source_pixel_char.green & dest_pixel_char.green,
|
938
|
+
source_pixel_char.blue & dest_pixel_char.blue,
|
939
|
+
source_pixel_char.alpha);
|
940
|
+
break;
|
941
|
+
case or:
|
942
|
+
finished_pixel = color_int_vals_to_float_format(source_pixel_char.red | dest_pixel_char.red,
|
943
|
+
source_pixel_char.green | dest_pixel_char.green,
|
944
|
+
source_pixel_char.blue | dest_pixel_char.blue,
|
945
|
+
source_pixel_char.alpha);
|
946
|
+
|
947
|
+
break;
|
948
|
+
case nand:
|
949
|
+
finished_pixel = color_int_vals_to_float_format(~(source_pixel_char.red & dest_pixel_char.red),
|
950
|
+
~(source_pixel_char.green & dest_pixel_char.green),
|
951
|
+
~(source_pixel_char.blue & dest_pixel_char.blue),
|
952
|
+
~(source_pixel_char.alpha & dest_pixel_char.alpha));
|
953
|
+
|
954
|
+
break;
|
955
|
+
case nor:
|
956
|
+
finished_pixel = color_int_vals_to_float_format(~(source_pixel_char.red | dest_pixel_char.red),
|
957
|
+
~(source_pixel_char.green | dest_pixel_char.green),
|
958
|
+
~(source_pixel_char.blue | dest_pixel_char.blue),
|
959
|
+
source_pixel_char.alpha);
|
960
|
+
|
961
|
+
break;
|
962
|
+
case xor:
|
963
|
+
finished_pixel = color_int_vals_to_float_format(source_pixel_char.red ^ dest_pixel_char.red,
|
964
|
+
source_pixel_char.green ^ dest_pixel_char.green,
|
965
|
+
source_pixel_char.blue ^ dest_pixel_char.blue,
|
966
|
+
source_pixel_char.alpha);
|
967
|
+
|
968
|
+
break;
|
969
|
+
case equiv:
|
970
|
+
finished_pixel = color_int_vals_to_float_format(~(source_pixel_char.red ^ dest_pixel_char.red),
|
971
|
+
~(source_pixel_char.green ^ dest_pixel_char.green),
|
972
|
+
~(source_pixel_char.blue ^ dest_pixel_char.blue),
|
973
|
+
source_pixel_char.alpha);
|
974
|
+
|
975
|
+
break;
|
976
|
+
case and_inverted:
|
977
|
+
finished_pixel = color_int_vals_to_float_format(~source_pixel_char.red & dest_pixel_char.red,
|
978
|
+
~source_pixel_char.green & dest_pixel_char.green,
|
979
|
+
~source_pixel_char.blue & dest_pixel_char.blue,
|
980
|
+
source_pixel_char.alpha);
|
981
|
+
break;
|
982
|
+
case or_inverted:
|
983
|
+
finished_pixel = color_int_vals_to_float_format(~source_pixel_char.red | dest_pixel_char.red,
|
984
|
+
~source_pixel_char.green | dest_pixel_char.green,
|
985
|
+
~source_pixel_char.blue | dest_pixel_char.blue,
|
986
|
+
source_pixel_char.alpha);
|
987
|
+
|
988
|
+
break;
|
989
|
+
|
990
|
+
/* photoshop style blending functions */
|
991
|
+
case additive:
|
992
|
+
finished_pixel = (rgba) { MIN(source_pixel.red + dest_pixel.red, 1),
|
993
|
+
MIN(source_pixel.green + dest_pixel.green, 1),
|
994
|
+
MIN(source_pixel.blue + dest_pixel.blue, 1),
|
995
|
+
MIN(source_pixel.alpha + dest_pixel.alpha, 1) };
|
996
|
+
break;
|
997
|
+
case multiply:
|
998
|
+
finished_pixel = mode_multiply(dest_pixel, source_pixel);
|
999
|
+
|
1000
|
+
break;
|
1001
|
+
case screen:
|
1002
|
+
finished_pixel = mode_screen(dest_pixel, source_pixel);
|
1003
|
+
|
1004
|
+
break;
|
1005
|
+
case overlay:
|
1006
|
+
finished_pixel = mode_hardlight(source_pixel, dest_pixel);
|
1007
|
+
|
1008
|
+
break;
|
1009
|
+
case darken:
|
1010
|
+
finished_pixel = (rgba) { MIN(source_pixel.red, dest_pixel.red),
|
1011
|
+
MIN(source_pixel.green, dest_pixel.green),
|
1012
|
+
MIN(source_pixel.blue, dest_pixel.blue),
|
1013
|
+
MIN(source_pixel.alpha, dest_pixel.alpha) };
|
1014
|
+
break;
|
1015
|
+
case lighten:
|
1016
|
+
finished_pixel = (rgba) { MAX(source_pixel.red, dest_pixel.red),
|
1017
|
+
MAX(source_pixel.green, dest_pixel.green),
|
1018
|
+
MAX(source_pixel.blue, dest_pixel.blue),
|
1019
|
+
MAX(source_pixel.alpha, dest_pixel.alpha) };
|
1020
|
+
break;
|
1021
|
+
case color_dodge:
|
1022
|
+
finished_pixel = (rgba) { mode_colordodge_channel(dest_pixel.red, source_pixel.red),
|
1023
|
+
mode_colordodge_channel(dest_pixel.green, source_pixel.green),
|
1024
|
+
mode_colordodge_channel(dest_pixel.blue, source_pixel.blue),
|
1025
|
+
mode_colordodge_channel(dest_pixel.alpha, source_pixel.alpha) };
|
1026
|
+
|
1027
|
+
break;
|
1028
|
+
case color_burn:
|
1029
|
+
finished_pixel = (rgba) { mode_colorburn_channel(dest_pixel.red, source_pixel.red),
|
1030
|
+
mode_colorburn_channel(dest_pixel.green, source_pixel.green),
|
1031
|
+
mode_colorburn_channel(dest_pixel.blue, source_pixel.blue),
|
1032
|
+
mode_colorburn_channel(dest_pixel.alpha, source_pixel.alpha) };
|
1033
|
+
break;
|
1034
|
+
case hard_light:
|
1035
|
+
finished_pixel = mode_hardlight(dest_pixel, source_pixel);
|
1036
|
+
|
1037
|
+
break;
|
1038
|
+
case soft_light:
|
1039
|
+
finished_pixel = mode_softlight(dest_pixel, source_pixel);
|
1040
|
+
|
1041
|
+
break;
|
1042
|
+
case difference:
|
1043
|
+
finished_pixel = (rgba) { ABS(dest_pixel.red - source_pixel.red),
|
1044
|
+
ABS(dest_pixel.green - source_pixel.green),
|
1045
|
+
ABS(dest_pixel.blue - source_pixel.blue),
|
1046
|
+
ABS(dest_pixel.alpha - source_pixel.alpha) };
|
1047
|
+
break;
|
1048
|
+
case exclusion:
|
1049
|
+
finished_pixel = (rgba) { dest_pixel.red + source_pixel.red - (2 * dest_pixel.red * source_pixel.red),
|
1050
|
+
dest_pixel.green + source_pixel.green - (2 * dest_pixel.green * source_pixel.green),
|
1051
|
+
dest_pixel.blue + source_pixel.blue - (2 * dest_pixel.blue * source_pixel.blue),
|
1052
|
+
dest_pixel.alpha + source_pixel.alpha - (2 * dest_pixel.alpha * source_pixel.alpha) };
|
1053
|
+
break;
|
1054
|
+
}
|
1055
|
+
|
1056
|
+
return finished_pixel;
|
1057
|
+
}
|
1058
|
+
/***************************************/
|
1059
|
+
/**** end drawing mode related code ****/
|
1060
|
+
/***************************************/
|
1061
|
+
|
1062
|
+
|
1063
|
+
static rgba
|
1064
|
+
apply_lerp(action_struct * payload, texture_info * tex, int x, int y)
|
1065
|
+
{
|
1066
|
+
rgba finished_pixel;
|
1067
|
+
rgba dest_pixel = get_pixel_color(tex, x, y);
|
1068
|
+
|
1069
|
+
finished_pixel.red = payload->pen.lerp * payload->color.red +
|
1070
|
+
(1 - payload->pen.lerp) * dest_pixel.red;
|
1071
|
+
|
1072
|
+
finished_pixel.green = payload->pen.lerp * payload->color.green +
|
1073
|
+
(1 - payload->pen.lerp) * dest_pixel.green;
|
1074
|
+
|
1075
|
+
finished_pixel.blue = payload->pen.lerp * payload->color.blue +
|
1076
|
+
(1 - payload->pen.lerp) * dest_pixel.blue;
|
1077
|
+
|
1078
|
+
finished_pixel.alpha = payload->pen.lerp * payload->color.alpha +
|
1079
|
+
(1 - payload->pen.lerp) * dest_pixel.alpha;
|
1080
|
+
|
1081
|
+
return finished_pixel;
|
1082
|
+
}
|
1083
|
+
|
1084
|
+
|
1085
|
+
/* TODO: reimplement using SSE2 */
|
1086
|
+
static rgba
|
1087
|
+
apply_color_control_transform(action_struct * payload, texture_info * tex, int x, int y)
|
1088
|
+
|
1089
|
+
{
|
1090
|
+
rgba transformed_color;
|
1091
|
+
|
1092
|
+
transformed_color = get_pixel_color(tex, x, y);
|
1093
|
+
|
1094
|
+
transformed_color.red += payload->pen.color_add.red;
|
1095
|
+
transformed_color.green += payload->pen.color_add.green;
|
1096
|
+
transformed_color.blue += payload->pen.color_add.blue;
|
1097
|
+
transformed_color.alpha += payload->pen.color_add.alpha;
|
1098
|
+
|
1099
|
+
transformed_color.red *= payload->pen.color_mult.red;
|
1100
|
+
transformed_color.green *= payload->pen.color_mult.green;
|
1101
|
+
transformed_color.blue *= payload->pen.color_mult.blue;
|
1102
|
+
transformed_color.alpha *= payload->pen.color_mult.alpha;
|
1103
|
+
|
1104
|
+
return transformed_color;
|
1105
|
+
}
|
1106
|
+
|
1107
|
+
static rgba
|
1108
|
+
apply_alpha_blend(action_struct * payload, texture_info * tex, int x, int y, rgba blended_pixel)
|
1109
|
+
{
|
1110
|
+
rgba dest_pixel = get_pixel_color(tex, x, y);
|
1111
|
+
rgba finished_pixel;
|
1112
|
+
|
1113
|
+
if (not_a_color(blended_pixel))
|
1114
|
+
return blended_pixel;
|
1115
|
+
|
1116
|
+
alpha_blend_mode_t blend_mode = payload->pen.alpha_blend_mode;
|
1117
|
+
|
1118
|
+
switch(blend_mode)
|
1119
|
+
{
|
1120
|
+
case source:
|
1121
|
+
case source_with_fixed_alpha:
|
1122
|
+
/** TO DO: rewrite this using sse2 instructions **/
|
1123
|
+
finished_pixel.red = blended_pixel.alpha * blended_pixel.red + (1 - blended_pixel.alpha)
|
1124
|
+
* dest_pixel.red;
|
1125
|
+
|
1126
|
+
finished_pixel.green = blended_pixel.alpha * blended_pixel.green + (1 - blended_pixel.alpha)
|
1127
|
+
* dest_pixel.green;
|
1128
|
+
|
1129
|
+
finished_pixel.blue = blended_pixel.alpha * blended_pixel.blue + (1 - blended_pixel.alpha)
|
1130
|
+
* dest_pixel.blue;
|
1131
|
+
|
1132
|
+
if(blend_mode == source) {
|
1133
|
+
finished_pixel.alpha = blended_pixel.alpha * blended_pixel.alpha + (1 - blended_pixel.alpha)
|
1134
|
+
* dest_pixel.alpha;
|
1135
|
+
}
|
1136
|
+
else {
|
1137
|
+
|
1138
|
+
// fixed alpha
|
1139
|
+
finished_pixel.alpha = dest_pixel.alpha;
|
1140
|
+
}
|
1141
|
+
|
1142
|
+
break;
|
1143
|
+
case dest:
|
1144
|
+
case dest_with_fixed_alpha:
|
1145
|
+
finished_pixel.red = dest_pixel.alpha * blended_pixel.red + (1 - dest_pixel.alpha)
|
1146
|
+
* dest_pixel.red;
|
1147
|
+
|
1148
|
+
finished_pixel.green = dest_pixel.alpha * blended_pixel.green + (1 - dest_pixel.alpha)
|
1149
|
+
* dest_pixel.green;
|
1150
|
+
|
1151
|
+
finished_pixel.blue = dest_pixel.alpha * blended_pixel.blue + (1 - dest_pixel.alpha)
|
1152
|
+
* dest_pixel.blue;
|
1153
|
+
|
1154
|
+
if(blend_mode == dest) {
|
1155
|
+
finished_pixel.alpha = dest_pixel.alpha * blended_pixel.alpha + (1 - dest_pixel.alpha)
|
1156
|
+
* dest_pixel.alpha;
|
1157
|
+
}
|
1158
|
+
else {
|
1159
|
+
|
1160
|
+
// fixed alpha
|
1161
|
+
finished_pixel.alpha = dest_pixel.alpha;
|
1162
|
+
}
|
1163
|
+
|
1164
|
+
break;
|
1165
|
+
default:
|
1166
|
+
rb_raise(rb_eRuntimeError,
|
1167
|
+
"apply_alpha_blend() impossible error. got %d\n", blend_mode);
|
1168
|
+
|
1169
|
+
}
|
1170
|
+
|
1171
|
+
return finished_pixel;
|
1172
|
+
}
|
1173
|
+
|
1174
|
+
/* NEW from utils.c */
|
1175
|
+
float *
|
1176
|
+
allocate_texture(int width, int height)
|
1177
|
+
{
|
1178
|
+
float * new_texture;
|
1179
|
+
int mval;
|
1180
|
+
|
1181
|
+
mval = 4 * width * height * sizeof(float);
|
1182
|
+
|
1183
|
+
new_texture = malloc(mval);
|
1184
|
+
|
1185
|
+
return new_texture;
|
1186
|
+
}
|
1187
|
+
|
1188
|
+
/* get information from texture */
|
1189
|
+
void
|
1190
|
+
get_texture_info(VALUE image, texture_info * tex)
|
1191
|
+
{
|
1192
|
+
VALUE info, gc_state_off;
|
1193
|
+
int toppos, leftpos;
|
1194
|
+
float top, left;
|
1195
|
+
cache_entry * entry;
|
1196
|
+
|
1197
|
+
/* hack to prevent segfault */
|
1198
|
+
gc_state_off = rb_gc_disable();
|
1199
|
+
|
1200
|
+
tex->width = FIX2INT(rb_funcall(image, rb_intern("width"), 0));
|
1201
|
+
tex->height = FIX2INT(rb_funcall(image, rb_intern("height"), 0));
|
1202
|
+
|
1203
|
+
/* ensure gl_tex_info returns non nil */
|
1204
|
+
info = check_for_texture_info(image);
|
1205
|
+
|
1206
|
+
top = NUM2DBL(rb_funcall(info, rb_intern("top"), 0));
|
1207
|
+
left = NUM2DBL(rb_funcall(info, rb_intern("left"), 0));
|
1208
|
+
tex->tname = FIX2INT(rb_funcall(info ,rb_intern("tex_name"),0));
|
1209
|
+
|
1210
|
+
/* search for texture in cache (& create if not extant) */
|
1211
|
+
entry = find_or_create_cache_entry(tex->tname);
|
1212
|
+
|
1213
|
+
tex->td_array = entry->tdata;
|
1214
|
+
tex->yincr = entry->sidelength;
|
1215
|
+
|
1216
|
+
/* scratch variables */
|
1217
|
+
toppos = ROUND(top * entry->sidelength * entry->sidelength);
|
1218
|
+
leftpos = ROUND(left * entry->sidelength);
|
1219
|
+
|
1220
|
+
/* find the first pixel for the image */
|
1221
|
+
tex->firstpixel = (int)(toppos + leftpos);
|
1222
|
+
|
1223
|
+
tex->x_offset = ROUND(left * tex->yincr);
|
1224
|
+
tex->y_offset = ROUND(top * tex->yincr);
|
1225
|
+
|
1226
|
+
/* save the associated Gosu::Image */
|
1227
|
+
tex->image = image;
|
1228
|
+
|
1229
|
+
/* only enable gc if was enabled on function entry */
|
1230
|
+
if(!gc_state_off) rb_gc_enable();
|
1231
|
+
}
|
1232
|
+
|
1233
|
+
/* ensure gl_tex_info returns non nil */
|
1234
|
+
VALUE
|
1235
|
+
check_for_texture_info(VALUE image)
|
1236
|
+
{
|
1237
|
+
VALUE info;
|
1238
|
+
|
1239
|
+
info = rb_funcall(image, rb_intern("gl_tex_info"), 0);
|
1240
|
+
|
1241
|
+
if(NIL_P(info)) {
|
1242
|
+
VALUE image_name = rb_inspect(image);
|
1243
|
+
int width = FIX2INT(rb_funcall(image, rb_intern("width"), 0));
|
1244
|
+
int height = FIX2INT(rb_funcall(image, rb_intern("height"), 0));
|
1245
|
+
|
1246
|
+
rb_raise(rb_eException, "Error: gl_tex_info returns nil for %s (%i x %i). Could be caused by "
|
1247
|
+
"very large image or Gosu bug. Try updating Gosu or use a smaller image. Note: TexPlay should"
|
1248
|
+
" be able to work with %i x %i images.",
|
1249
|
+
StringValuePtr(image_name), width, height, max_quad_size() - 2, max_quad_size() - 2);
|
1250
|
+
}
|
1251
|
+
|
1252
|
+
return info;
|
1253
|
+
}
|
1254
|
+
|
1255
|
+
/* responsible for syncing a subimage to gl */
|
1256
|
+
void
|
1257
|
+
sync_to_gl(int tex_name, int x_offset, int y_offset, int width, int height, void * sub)
|
1258
|
+
{
|
1259
|
+
/* set the opengl texture context */
|
1260
|
+
glEnable(GL_TEXTURE_2D);
|
1261
|
+
glBindTexture(GL_TEXTURE_2D, tex_name);
|
1262
|
+
|
1263
|
+
/* sync subtexture */
|
1264
|
+
glTexSubImage2D(GL_TEXTURE_2D, 0, x_offset, y_offset, width, height,
|
1265
|
+
GL_RGBA, GL_FLOAT, sub);
|
1266
|
+
|
1267
|
+
glDisable(GL_TEXTURE_2D);
|
1268
|
+
}
|
1269
|
+
|
1270
|
+
void
|
1271
|
+
create_subtexture_and_sync_to_gl(image_bounds * img_bounds, texture_info * tex)
|
1272
|
+
{
|
1273
|
+
/* image vars */
|
1274
|
+
int xbound, ybound;
|
1275
|
+
float * sub = NULL;
|
1276
|
+
|
1277
|
+
/* make the current action's boundaries sane; left until this point because we only
|
1278
|
+
know height/width here */
|
1279
|
+
constrain_boundaries(&img_bounds->xmin, &img_bounds->ymin, &img_bounds->xmax, &img_bounds->ymax,
|
1280
|
+
tex->width, tex->height);
|
1281
|
+
|
1282
|
+
/* helper variables */
|
1283
|
+
ybound = img_bounds->ymax - img_bounds->ymin + 1;
|
1284
|
+
xbound = img_bounds->xmax - img_bounds->xmin + 1;
|
1285
|
+
|
1286
|
+
sub = get_image_chunk(tex, img_bounds->xmin, img_bounds->ymin, img_bounds->xmax, img_bounds->ymax);
|
1287
|
+
|
1288
|
+
sync_to_gl(tex->tname, tex->x_offset + img_bounds->xmin, tex->y_offset + img_bounds->ymin, xbound,
|
1289
|
+
ybound, (void*)sub);
|
1290
|
+
|
1291
|
+
free(sub);
|
1292
|
+
}
|
1293
|
+
|
1294
|
+
float *
|
1295
|
+
get_image_chunk(texture_info * tex, int xmin, int ymin, int xmax, int ymax)
|
1296
|
+
{
|
1297
|
+
int xbound;
|
1298
|
+
int ybound;
|
1299
|
+
float * image_buf = NULL;
|
1300
|
+
|
1301
|
+
constrain_boundaries(&xmin, &ymin, &xmax, &ymax, tex->width, tex->height);
|
1302
|
+
|
1303
|
+
xbound = xmax - xmin + 1;
|
1304
|
+
ybound = ymax - ymin + 1;
|
1305
|
+
|
1306
|
+
image_buf = allocate_texture(xbound, ybound);
|
1307
|
+
|
1308
|
+
for(int y = 0; y < ybound; y++)
|
1309
|
+
for(int x = 0; x < xbound; x++) {
|
1310
|
+
int buf_index = 4 * (x + y * xbound);
|
1311
|
+
|
1312
|
+
int offset = calc_pixel_offset(tex, x + xmin, y + ymin);
|
1313
|
+
|
1314
|
+
color_copy(tex->td_array + offset, image_buf + buf_index);
|
1315
|
+
}
|
1316
|
+
|
1317
|
+
return image_buf;
|
1318
|
+
}
|