big merge from master, fix rpm creation, drop fetching swfdec
[gnash.git] / testsuite / misc-ming.all / GradientFillTest.as
blobeb1dc3df40f6341342bed380b0507625f68999bc
1 //
2 // Some tests for the Drawing API
3 // Build with:
4 // makeswf -o DrawingApi.swf DrawingApi.as
5 // Run with:
6 // firefox DrawingApi.swf
7 // Or:
8 // gnash DrawingApi.swf
9 //
11 // Click the mouse button to turn the cursor shape into a mask and back.
12 // Press a number on the keyboard to switch between "pages" of the drawing.
13 // We currently have pages 1, 2, 3, 4.
14 // All pages are tested automatically.
16 // '-' and '+' decrement and increment _alpha
17 // 'h' toggles _visible
21 #include "../actionscript.all/check.as"
23 // This tests the gradients found in DrawingApiTest for version 8, where
24 // some extra arguments were added.
26 // Make Matrix visible for easier gradient tests.
27 ASSetPropFlags(_global, "flash", 0, 5248);
29 draw100x100Box = function(x, y, mc) {
30 s = 90;
31 with (mc) {
32 moveTo(x, y);
33 lineTo(x + s, y);
34 lineTo(x + s, y + s);
35 lineTo(x, y + s);
36 lineTo(x, y);
37 endFill();
41 createEmptyMovieClip("grad", 150);
43 // Test gradients.
44 // The beginGradientFill function works with fake Matrices, but there is no
45 // point making more work for ourselves as that testing is already done for
46 // the Matrix class.
47 // Only the "box" matrixType gets special handling.
49 with(grad) {
51 // Linear gradients
52 fillType = "linear";
54 x = 0;
55 y = 0;
57 // shape 1
58 colors = [0x0000ff, 0xffffff];
59 alphas = [100, 100];
60 ratios = [0, 0xff];
61 matrix = new flash.geom.Matrix();
62 beginGradientFill(fillType, colors, alphas, ratios, matrix);
63 draw100x100Box(x, y, grad);
65 // shape 2
66 x += 100;
67 colors = [0x0000ff, 0xffffff];
68 alphas = [100, 100];
69 ratios = [0, 0xff];
70 matrix.createGradientBox(90, 90, 0, x, y);
71 beginGradientFill(fillType, colors, alphas, ratios, matrix);
72 draw100x100Box(x, y, grad);
74 // shape 3
75 x += 100;
76 colors = [0x0000ff, 0xffffff, 0xff00ff];
77 alphas = [100, 100, 100];
78 ratios = [0, 0xff / 2, 0xff];
79 matrix.createGradientBox(90, 90, Math.PI / 4, x, y);
80 beginGradientFill(fillType, colors, alphas, ratios, matrix);
81 draw100x100Box(x, y, grad);
83 // shape 4
84 x += 100;
85 colors = [0x0000ff, 0xffffff, 0xff00ff];
86 alphas = [100, 100, 100];
87 ratios = [0, 0xff / 2, 0xff];
88 matrix.createGradientBox(180, 180, Math.PI / 4, x, y);
89 beginGradientFill(fillType, colors, alphas, ratios, matrix);
90 draw100x100Box(x, y, grad);
92 // shape 5
93 x += 100;
94 colors = [0x0000ff, 0xffffff, 0x00ff00];
95 alphas = [100, 100, 100];
96 ratios = [0, 0xff / 2, 0xff];
97 matrix.createGradientBox(180, 180, Math.PI / 4 * 3, x - 90, y - 90);
98 beginGradientFill(fillType, colors, alphas, ratios, matrix);
99 draw100x100Box(x, y, grad);
101 // shape 6
102 x += 100;
103 colors = [0x0000ff, 0xffffff, 0x00ff00, 0xff00ff, 0x00ffff, 0xffff00 ];
104 alphas = [100, 100, 100, 50, 25, 100];
105 ratios = [0, 0xff / 5, 0xff / 5 * 2, 0xff / 5 * 3, 0xff / 5 * 4, 0xff];
106 matrix.createGradientBox(90, 90, Math.PI / 2, x, y);
107 beginGradientFill(fillType, colors, alphas, ratios, matrix);
108 draw100x100Box(x, y, grad);
110 // Radial gradients
111 fillType = "radial";
113 x = 0;
114 y += 100;
116 // shape 7
117 colors = [0x0000ff, 0xffffff];
118 alphas = [100, 100];
119 ratios = [0, 0xff];
120 matrix = new flash.geom.Matrix();
121 beginGradientFill(fillType, colors, alphas, ratios, matrix);
122 draw100x100Box(x, y, grad);
124 // shape 8
125 x += 100;
126 colors = [0x0000ff, 0xffffff];
127 alphas = [100, 100];
128 ratios = [0, 0xff];
129 matrix.createGradientBox(90, 90, 0, x, y);
130 beginGradientFill(fillType, colors, alphas, ratios, matrix);
131 draw100x100Box(x, y, grad);
133 // shape 9
134 x += 100;
135 colors = [0x0000ff, 0xffffff, 0xff00ff];
136 alphas = [100, 100, 100];
137 ratios = [0, 0xff / 2, 0xff];
138 matrix.createGradientBox(90, 90, Math.PI / 4, x, y);
139 beginGradientFill(fillType, colors, alphas, ratios, matrix);
140 draw100x100Box(x, y, grad);
142 // shape 10
143 x += 100;
144 colors = [0x0000ff, 0xffffff, 0xff00ff];
145 alphas = [100, 100, 100];
146 ratios = [0, 0xff / 2, 0xff];
147 matrix.createGradientBox(180, 180, Math.PI / 4, x, y);
148 beginGradientFill(fillType, colors, alphas, ratios, matrix);
149 draw100x100Box(x, y, grad);
151 // shape 11
152 x += 100;
153 colors = [0x0000ff, 0xffffff, 0x00ff00];
154 alphas = [100, 100, 100];
155 ratios = [0, 0xff / 2, 0xff];
156 matrix.createGradientBox(180, 180, Math.PI / 4 * 3, x - 90, y - 90);
157 beginGradientFill(fillType, colors, alphas, ratios, matrix);
158 draw100x100Box(x, y, grad);
160 // shape 12
161 x += 100;
162 colors = [0x0000ff, 0xffffff, 0x00ff00, 0xff00ff, 0x00ffff, 0xffff00 ];
163 alphas = [100, 100, 100, 50, 25, 100];
164 ratios = [0, 0xff / 5, 0xff / 5 * 2, 0xff / 5 * 3, 0xff / 5 * 4, 0xff];
165 matrix.createGradientBox(90, 90, Math.PI / 2, x, y);
166 beginGradientFill(fillType, colors, alphas, ratios, matrix);
167 draw100x100Box(x, y, grad);
169 y += 100;
170 x = 0;
172 // Shape 13
174 // Check that ratios are adjusted if they do not get successively larger.
175 fillType = "linear";
176 colors = [0x0000ff, 0xffffff, 0x00ff00];
177 alphas = [100, 100, 100];
178 ratios = [0, 0x10, 0x05];
179 matrix.createGradientBox(90, 90, 0, x, y);
180 beginGradientFill(fillType, colors, alphas, ratios, matrix);
181 draw100x100Box(x, y, grad);
184 // Shape 14
185 x += 100;
187 // Test a linear gradient with one stop
188 fillType = "linear";
189 colors = [0xff0000];
190 alphas = [100];
191 ratios = [0];
192 matrix.createGradientBox(90, 90, 0, x, y);
193 beginGradientFill(fillType, colors, alphas, ratios, matrix);
194 draw100x100Box(x, y, grad);
197 // Shape 15
198 x += 100;
200 // Test a linear gradient with one stop
201 fillType = "radial";
202 colors = [0x00ff00];
203 alphas = [100];
204 ratios = [0];
205 matrix.createGradientBox(90, 90, 0, x, y);
206 beginGradientFill(fillType, colors, alphas, ratios, matrix);
207 draw100x100Box(x, y, grad);
209 // Shape 15
210 x += 100;
212 // Test a radial gradient with SWF8 args
213 fillType = "radial";
214 colors = [0xffff00, 0x0000ff, 0x00ffff];
215 alphas = [100, 100, 100];
216 ratios = [0, 0xa0, 0xff];
217 matrix.createGradientBox(90, 90, 0, x, y);
218 beginGradientFill(fillType, colors, alphas, ratios, matrix, "pad");
219 draw100x100Box(x, y, grad);
221 // Shape 16
222 x += 100;
224 // Test a radial gradient with SWF8 args
225 fillType = "radial";
226 colors = [0xffff00, 0x0000ff, 0x00ffff];
227 alphas = [100, 100, 100];
228 ratios = [0, 0xa0, 0xff];
229 matrix.createGradientBox(90, 90, 0, x, y);
230 beginGradientFill(fillType, colors, alphas, ratios, matrix, "reflect");
231 draw100x100Box(x, y, grad);
233 // Shape 17
234 x += 100;
236 // Test a radial gradient with SWF8 args
237 fillType = "radial";
238 colors = [0xffff00, 0x0000ff, 0x00ffff];
239 alphas = [100, 100, 100];
240 ratios = [0, 0xa0, 0xff];
241 matrix.createGradientBox(90, 90, 0, x, y);
242 beginGradientFill(fillType, colors, alphas, ratios, matrix, "repeat");
243 draw100x100Box(x, y, grad);
245 x = 0;
246 y += 100;
248 // Shape 18
250 // Test a radial gradient with SWF8 args
251 fillType = "radial";
252 colors = [0xffff00, 0x0000ff, 0x00ffff];
253 alphas = [100, 100, 100];
254 ratios = [0, 0xa0, 0xff];
255 matrix.createGradientBox(90, 90, 0, x, y);
256 beginGradientFill(fillType, colors, alphas, ratios, matrix, "");
257 draw100x100Box(x, y, grad);
259 // Shape 19
260 x += 100;
262 // Test a radial gradient with SWF8 args
263 fillType = "radial";
264 colors = [0xffff00, 0x0000ff, 0x00ffff];
265 alphas = [100, 100, 100];
266 ratios = [0, 0xa0, 0xff];
267 matrix.createGradientBox(90, 90, 0, x, y);
268 beginGradientFill(fillType, colors, alphas, ratios, matrix, "pad",
269 "RGB");
270 draw100x100Box(x, y, grad);
273 // Shape 20
274 x += 100;
276 // Test a radial gradient with SWF8 args
277 fillType = "radial";
278 colors = [0xffff00, 0x0000ff, 0x00ffff];
279 alphas = [100, 100, 100];
280 ratios = [0, 0xa0, 0xff];
281 matrix.createGradientBox(90, 90, 0, x, y);
282 beginGradientFill(fillType, colors, alphas, ratios, matrix, "pad",
283 "linearRGB");
284 draw100x100Box(x, y, grad);
286 // Shape 21
287 x += 100;
289 // Test a radial gradient with SWF8 args
290 fillType = "radial";
291 colors = [0xffff00, 0x0000ff, 0x00ffff];
292 alphas = [100, 100, 100];
293 ratios = [0, 0xa0, 0xff];
294 matrix.createGradientBox(90, 90, 0, x, y);
295 beginGradientFill(fillType, colors, alphas, ratios, matrix, "pad",
296 "");
297 draw100x100Box(x, y, grad);
299 // Shape 22
300 x += 100;
302 fillType = "radial";
303 colors = [0xffff00, 0x0000ff, 0x00ffff];
304 alphas = [100, 100, 100];
305 ratios = [0, 0xa0, 0xff];
306 matrix.createGradientBox(90, 90, 0, x, y);
307 beginGradientFill(fillType, colors, alphas, ratios, matrix, "pad",
308 "rgb", 3.5);
309 draw100x100Box(x, y, grad);
311 // Shape 23
312 x += 100;
314 fillType = "linear";
315 colors = [0xff0000, 0x00ff00];
316 alphas = [100, 100];
317 ratios = [0, 0xff];
318 matrix.createGradientBox(90, 90, 0, x, y);
319 beginGradientFill(fillType, colors, alphas, ratios, matrix, "pad",
320 "linearRGB", 3.5);
321 draw100x100Box(x, y, grad);
323 // Shape 24
324 x = 0;
325 y += 100;
327 fillType = "linear";
328 colors = [0xff0000, 0x00ff00];
329 alphas = [100, 0];
330 ratios = [0, 0xff];
331 matrix.createGradientBox(90, 90, 0, x, y);
332 beginGradientFill(fillType, colors, alphas, ratios, matrix, "pad",
333 "linearRGB", 3.5);
334 draw100x100Box(x, y, grad);
337 grad.onRollOver = function() {};
339 testbmp = new flash.display.BitmapData(1000, 1000, false);
340 testbmp.draw(grad);
342 searchArray = function(ar, el) {
343 for (var i in ar) {
344 if (ar[i] == el) return true;
346 return false;
349 nearColor = function(a, b, exfail) {
350 tolerance = 32;
351 ra = (a & 0xff0000) >> 16;
352 ba = (a & 0xff00) >> 8;
353 ga = (a & 0xff);
354 rb = (b & 0xff0000) >> 16;
355 bb = (b & 0xff00) >> 8;
356 gb = (b & 0xff);
357 dist = Math.sqrt(Math.pow(ra - rb, 2) + Math.pow(ba - bb, 2) + Math.pow(ga - gb, 2));
358 if (dist > tolerance) {
359 str = "Expected: 0x" + b.toString(16) + ", got: 0x" + a.toString(16);
360 str += " (Allowed tolerance: " + tolerance + ", distance: " + dist + ")";
361 if (exfail) xfail_check(str);
362 else fail_check(str);
363 return;
365 str = "0x" + b.toString(16) + " is near to 0x" + a.toString(16);
366 if (exfail) xpass_check(str);
367 else pass_check(str);
370 // Array is:
371 // 0: top left
372 // 1: top centre
373 // 2: top right
374 // 3: centre left
375 // 4: centre centre
376 // 5: centre right
377 // 6: bottom left
378 // 7: bottom centre
379 // 8: bottom right
381 // Passes is an optional array of the index of the tests that
382 // fail.
383 checkSquare = function(x, y, ar, bmp, fails) {
384 trace("Checking square at " + x + "x" + y);
385 size = 90;
386 low = 4;
387 high = size - low;
388 mid = size / 2;
389 #if 1
390 t = [
391 "0x" + testbmp.getPixel(x + low, y + low).toString(16),
392 "0x" + testbmp.getPixel(x + low, y + mid).toString(16),
393 "0x" + testbmp.getPixel(x + low, y + high).toString(16),
394 "0x" + testbmp.getPixel(x + mid, y + low).toString(16),
395 "0x" + testbmp.getPixel(x + mid, y + mid).toString(16),
396 "0x" + testbmp.getPixel(x + mid, y + high).toString(16),
397 "0x" + testbmp.getPixel(x + high, y + low).toString(16),
398 "0x" + testbmp.getPixel(x + high, y + mid).toString(16),
399 "0x" + testbmp.getPixel(x + high, y + high).toString(16)
401 trace(t);
402 #endif
403 nearColor(testbmp.getPixel(x + low, y + low), ar[0], searchArray(fails, 0));
404 nearColor(testbmp.getPixel(x + low, y + mid), ar[1], searchArray(fails, 1));
405 nearColor(testbmp.getPixel(x + low, y + high), ar[2], searchArray(fails, 2));
406 nearColor(testbmp.getPixel(x + mid, y + low), ar[3], searchArray(fails, 3));
407 nearColor(testbmp.getPixel(x + mid, y + mid), ar[4], searchArray(fails, 4));
408 nearColor(testbmp.getPixel(x + mid, y + high), ar[5], searchArray(fails, 5));
409 nearColor(testbmp.getPixel(x + high, y + low), ar[6], searchArray(fails, 6));
410 nearColor(testbmp.getPixel(x + high, y + mid), ar[7], searchArray(fails, 7));
411 nearColor(testbmp.getPixel(x + high, y + high), ar[8], searchArray(fails, 8));
414 checkSquare(0, 0, [0x8080ff,0x8080ff,0x8080ff,0x8787ff,0x8787ff,0x8787ff,0x8d8dff,0x8d8dff,0x8d8dff], bmp);
415 checkSquare(100, 0, [0xb0bff,0xb0bff,0xb0bff,0x7f7fff,0x7f7fff,0x7f7fff,0xf4f4ff,0xf4f4ff,0xf4f4ff], bmp);
416 checkSquare(200, 0, [0xff,0x5a5aff,0xfffdff,0x5a5aff,0xffffff,0xff59ff,0xffffff,0xff59ff,0xff00ff], bmp);
417 checkSquare(300, 0, [0xff,0xff,0x4a4aff,0xff,0x4a4aff,0x9c9cff,0x4a4aff,0x9c9cff,0xeeeeff], bmp);
418 checkSquare(400, 0, [0xffffff,0xabffab,0x59ff59,0xacacff,0xffffff,0xabffab,0x5a5aff,0xacacff,0xffffff], bmp);
419 checkSquare(500, 0, [0x3737ff,0xa29ea2,0xd1ff57,0x3737ff,0xa29ea2,0xd1ff57,0x3737ff,0xa29ea2,0xd1ff57], bmp);
421 checkSquare(0, 100, [0x2020ff,0x2d2dff,0x3a3aff,0x2323ff,0x2f2fff,0x3b3bff,0x2a2aff,0x3434ff,0x4040ff], bmp);
422 checkSquare(100, 100, [0xffffff,0xe9e9ff,0xffffff,0xe9e9ff,0xff,0xe9e9ff,0xffffff,0xe9e9ff,0xffffff], bmp);
423 checkSquare(200, 100, [0xff00ff,0xff2bff,0xff00ff,0xff2bff,0xff,0xff2bff,0xff00ff,0xff2bff,0xff00ff], bmp);
424 checkSquare(300, 100, [0xff00ff,0xff00ff,0xff15ff,0xff00ff,0xff93ff,0xfffdff,0xff15ff,0xfffdff,0x2020ff], bmp);
425 checkSquare(400, 100, [0x2020ff,0xfdfffd,0x15ff15,0xfdfffd,0x93ff93,0xff00,0x15ff15,0xff00,0xff00], bmp);
426 checkSquare(500, 100, [0xffff00,0xb4ff9d,0xffff00,0xb4ff9d,0xff,0xb4ff9d,0xffff00,0xb4ff9d,0xffff00], bmp);
428 checkSquare(0, 200, [0xafafff,0xafafff,0xafafff,0xff00,0xff00,0xff00,0xff00,0xff00,0xff00], bmp);
429 checkSquare(100, 200, [0xff0000,0xff0000,0xff0000,0xff0000,0xff0000,0xff0000,0xff0000,0xff0000,0xff0000], bmp);
430 checkSquare(200, 200, [0xff00,0xff00,0xff00,0xff00,0xff00,0xff00,0xff00,0xff00,0xff00], bmp);
431 checkSquare(300, 200, [0xffff,0xc3ff,0xffff,0xc3ff,0xffff00,0xc3ff,0xffff,0xc3ff,0xffff], bmp);
432 checkSquare(400, 200, [0x55ff,0xa9ff,0x43ff,0xb6ff,0xeded11,0xd1ff,0x30ff,0xdeff,0x1dff], bmp);
433 checkSquare(500, 200, [0x9d9d61,0xa3ff,0x91916d,0xb6ff,0xeaea14,0xd1ff,0x82827c,0xe4ff,0x757589], bmp, [7]);
435 checkSquare(0, 300, [0xffff,0xc3ff,0xffff,0xc3ff,0xffff00,0xc3ff,0xffff,0xc3ff,0xffff], bmp);
436 checkSquare(100, 300, [0xffff,0xc3ff,0xffff,0xc3ff,0xffff00,0xc3ff,0xffff,0xc3ff,0xffff], bmp);
437 checkSquare(200, 300, [0xfefe,0xe2fe,0xfefe,0xe2fe,0xfefe00,0xe2fe,0xfefe,0xe2fe,0xfefe], bmp, [4]);
438 checkSquare(300, 300, [0xffff,0xc3ff,0xffff,0xc3ff,0xffff00,0xc3ff,0xffff,0xc3ff,0xffff], bmp);
439 checkSquare(400, 300, [0xffff,0xe1ff,0xffff,0xc6ff,0x3636c8,0xc6ff,0xffff,0xf2f20c,0xffff], bmp);
440 checkSquare(500, 300, [0xfa3a00,0xfa3a00,0xfa3a00,0xbbbb00,0xbbbb00,0xbbbb00,0x3afa00,0x3afa00,0x3afa00], bmp);
442 checkSquare(0, 400, [0xfa420b,0xfa420b,0xfa420b,0xdddd7f,0xdddd7f,0xdddd7f,0xf6fff4,0xf6fff4,0xf6fff4], bmp);
443 totals();
445 stop();