add blend mode tests
[swfdec.git] / test / image / mask-and-clip.c
blob3b825d9af43a70a71c7bfa68ccbd07eac7e32a2c
1 /* gcc `pkg-config --libs --cflags libming` mask-and-clip.c -o mask-and-clip && ./mask-and-clip
2 */
4 #include <ming.h>
6 enum {
7 FIRST_MOVIE_CLIP_ALL,
8 SECOND_MOVIE_CLIP_ALL,
9 THIRD_MOVIE_SWAP_DEPTH,
10 THIRD_MOVIE_MASK,
11 N_FLAGS
13 #define FLAG_SET(var, flag) ((var) & (1 << (flag)))
15 static SWFBlock
16 get_rectangle (int r, int g, int b)
18 SWFMovieClip clip;
19 SWFShape shape;
20 SWFFillStyle fill;
22 clip = newSWFMovieClip ();
23 shape = newSWFShape ();
24 fill = SWFShape_addSolidFillStyle (shape, r, g, b, 255);
25 SWFShape_setRightFillStyle (shape, fill);
26 SWFShape_drawLineTo (shape, 100, 0);
27 SWFShape_drawLineTo (shape, 100, 100);
28 SWFShape_drawLineTo (shape, 0, 100);
29 SWFShape_drawLineTo (shape, 0, 0);
31 SWFMovieClip_add (clip, (SWFBlock) shape);
32 SWFMovieClip_nextFrame (clip);
33 return (SWFBlock) clip;
36 static void
37 do_movie (int version, unsigned int flags)
39 char name[100];
40 SWFMovie movie;
41 SWFDisplayItem item, item1, item2;
43 movie = newSWFMovieWithVersion (version);
44 SWFMovie_setRate (movie, 1);
45 SWFMovie_setDimension (movie, 200, 150);
47 item1 = item = SWFMovie_add (movie, get_rectangle (255, 0, 0));
48 SWFDisplayItem_setDepth (item, 0);
49 SWFDisplayItem_setName (item, "a");
50 if (FLAG_SET (flags, FIRST_MOVIE_CLIP_ALL)) {
51 SWFDisplayItem_setMaskLevel (item, 3);
52 } else {
53 SWFDisplayItem_setMaskLevel (item, 1);
56 item2 = item = SWFMovie_add (movie, get_rectangle (0, 255, 0));
57 SWFDisplayItem_moveTo (item, 50, 25);
58 SWFDisplayItem_setDepth (item, 1);
59 SWFDisplayItem_setName (item, "b");
60 if (FLAG_SET (flags, SECOND_MOVIE_CLIP_ALL)) {
61 SWFDisplayItem_setMaskLevel (item, 3);
62 } else {
63 SWFDisplayItem_setMaskLevel (item, 2);
66 item = SWFMovie_add (movie, get_rectangle (0, 0, 255));
67 SWFDisplayItem_moveTo (item, 25, 50);
68 SWFDisplayItem_setDepth (item, 3);
69 SWFDisplayItem_setName (item, "c");
71 if (FLAG_SET (flags, THIRD_MOVIE_SWAP_DEPTH)) {
72 SWFMovie_add (movie, (SWFBlock) newSWFAction ("c.swapDepths (100);"));
74 if (FLAG_SET (flags, THIRD_MOVIE_MASK)) {
75 SWFDisplayItem mask = SWFMovie_add (movie, get_rectangle (128, 128, 128));
76 SWFDisplayItem_moveTo (mask, 50, 50);
77 SWFDisplayItem_setDepth (mask, 50);
78 SWFDisplayItem_setName (mask, "mask");
79 SWFMovie_add (movie, (SWFBlock) newSWFAction (
80 "c.setMask (mask);"
81 ));
83 SWFMovie_nextFrame (movie);
85 sprintf (name, "mask-and-clip-%u-%d.swf", flags, version);
86 SWFMovie_save (movie, name);
89 int
90 main (int argc, char **argv)
92 int i, j;
94 if (Ming_init ())
95 return 1;
97 for (i = 8; i <= 8; i++) {
98 for (j = 0; j < (1 << N_FLAGS); j++) {
99 do_movie (i, j);
103 return 0;