Libraryless. Click here for Pure Java version (31578L/199K).
1 | // without types and proper AOT parsing |
2 | srecord noeq GazelleVScript(S text) { |
3 | LS tok; |
4 | |
5 | sS helpText = !include string #1033775; |
6 | |
7 | // A sequence is a sequence of runs, |
8 | // for example in an animation |
9 | class Sequence { |
10 | new MapSO vars; |
11 | } |
12 | |
13 | class Run is Steppable { |
14 | ListAndIndex<S> ptr; // where are we in the script |
15 | S token; |
16 | |
17 | new Stack stack; |
18 | |
19 | // main variables |
20 | settable IBWIntegralImage inputImage; |
21 | IBWIntegralImage integralImage; |
22 | settable BWImage bwImage; |
23 | |
24 | selfType setIntegralImage(IBWIntegralImage ii) { |
25 | push(integralImage = ii); |
26 | this; |
27 | } |
28 | |
29 | *() { |
30 | parse(); |
31 | ptr = ListAndIndex(tok, 1); |
32 | } |
33 | |
34 | void push(O o) { stack.add(o); } |
35 | |
36 | O value() { ret last(stack); } |
37 | |
38 | public bool step() { |
39 | token = ptr!; |
40 | if (token == null) false; |
41 | next(); |
42 | if (isInteger(token)) { |
43 | int i = parseInt(token); |
44 | token = tpp(); |
45 | if (is("p")) |
46 | scaleToHeight(i); |
47 | else if (is("c")) |
48 | posterize(i); |
49 | else if (is("w")) |
50 | scaleWidthOnly(i); |
51 | else |
52 | warn("Unknown token: " + token); |
53 | } else if (is("rasters")) |
54 | push(reproduceRasterBars(bwIntegralImage())); |
55 | else if (is("struct")) |
56 | push(struct(value())); |
57 | else if (is("niceStruct")) |
58 | push(sfuIndent(value())); |
59 | else if (is("className")) |
60 | push(className(value())); |
61 | else if (is("borderImage")) |
62 | push(bwImage = gazelle22_borderImage(bwImage)); |
63 | else if (is("gradientImage")) |
64 | push(bwImage = new Gazelle22_GradientImage(bwImage)!); |
65 | |
66 | else if (is("q1")) clip(0, .5, 0, .5); |
67 | else if (is("q2")) clip(.5, 1, 0, .5); |
68 | else if (is("q3")) clip(0, .5, .5, 1); |
69 | else if (is("q4")) clip(.5, 1, .5, 1); |
70 | |
71 | else if (is("original")) |
72 | push(toBufferedImage(inputImage)); |
73 | |
74 | else { |
75 | warn("Unknown token: " + token); |
76 | } |
77 | true; |
78 | } |
79 | |
80 | bool is(S t) { ret eqic(token, t); } |
81 | S tpp() { var token = ptr!; next(); ret token; } |
82 | void next { if (!ptr.atEnd()) ptr = ptr.plus(2); } |
83 | |
84 | // operations |
85 | |
86 | void scaleToHeight(int pixelRows) { |
87 | pixelRows = min(pixelRows, 512); |
88 | if (integralImage == null) |
89 | ret with warn("No integral image to scale down"); |
90 | push(bwImage = scaledBWImageFromBWIntegralImage_withMeta_height(pixelRows, integralImage)); |
91 | } |
92 | |
93 | void posterize(int colors) { |
94 | colors = clamp(colors, 2, 256); |
95 | if (bwImage == null) |
96 | ret with warn("No image to posterize"); |
97 | else |
98 | push(bwImage = posterizeBWImage_withMeta(colors, bwImage)); |
99 | } |
100 | |
101 | IBWIntegralImage bwIntegralImage() { |
102 | O val = value(); |
103 | if (val cast IBWIntegralImage) ret val; |
104 | if (val cast BWImage) { |
105 | var ii = main bwIntegralImage(val); |
106 | setIntegralImage(ii); |
107 | ret ii; |
108 | } |
109 | fail("Not an image on stack"); |
110 | } |
111 | |
112 | void scaleWidthOnly(int w) { |
113 | var ii = bwIntegralImage(); |
114 | push(bwImage = scaledBWImageFromBWIntegralImage_withMeta( |
115 | ii, w, ii.getHeight()); |
116 | } |
117 | |
118 | void clip(double x1, double x2, double y1, double y2) { |
119 | O val = value(); |
120 | if (val cast IBWIntegralImage) { |
121 | int w = val.getWidth(), h = val.getHeight(); |
122 | Rect r = toRect_round(scaleRect(w, h, |
123 | doubleRectFromPoints(x1, y1, x2, y2))); |
124 | setIntegralImage(new IIBWVirtualClip(val, r)); |
125 | } |
126 | else if (val cast BWImage) |
127 | todo(); |
128 | else fail("Not an image on stack"); |
129 | } |
130 | |
131 | // end of operations |
132 | |
133 | O result() { |
134 | ret last(stack); |
135 | } |
136 | |
137 | run { stepAll(this); } |
138 | } |
139 | |
140 | void parse() { |
141 | tok if null = javaTok(text); |
142 | } |
143 | } |
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1033717 |
Snippet name: | GazelleVScript - "Linear" script [v1] |
Eternal ID of this version: | #1033717/39 |
Text MD5: | 035e55d0cee5283ef6ab04e098f40b3b |
Transpilation MD5: | 4154db11b34e214882672e20fd02a827 |
Author: | stefan |
Category: | javax / gazelle v |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-03-08 07:41:34 |
Source code size: | 3894 bytes / 143 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 256 / 522 |
Version history: | 38 change(s) |
Referenced in: | [show references] |