add blend mode tests
[swfdec.git] / test / image / blend-mode.c
blobc302cc4818a84760b04dc42157bd397b00f9d853
1 /* gcc -Wall `pkg-config --libs --cflags libming glib-2.0` blend-mode.c -o blend-mode && ./blend-mode
2 */
4 #include <ming.h>
5 #include <glib.h>
7 #define SIZE 240
9 const char *modes[] = {
10 "0",
11 "normal",
12 "layer",
13 "multiply",
14 "screen",
15 "lighten",
16 "darken",
17 "difference",
18 "add",
19 "subtract",
20 "inverse",
21 "alpha",
22 "erase",
23 "overlay",
24 "hardlight",
25 "15"
28 SWFBitmap
29 create_yellow_image (guint w, guint h)
31 guint32 *data;
32 guint x, y;
33 SWFBitmap ret;
35 data = g_malloc (w * h * 4);
36 for (y = 0; y < h; y++) {
37 /* get 15 steps of 10 pixel high lines fading in yellow */
38 guint32 pixel = 255 / 15 * (y * 16 / h);
39 pixel *= 0x01010100;
40 for (x = 0; x < w; x++) {
41 data[y * w + x] = pixel;
44 ret = newSWFBitmap_fromData ((guint8 *) data, w, h, TRUE);
45 g_free (data);
46 return ret;
49 SWFBitmap
50 create_teal_image (guint w, guint h)
52 guint32 *data;
53 guint x, y;
54 SWFBitmap ret;
56 data = g_malloc (w * h * 4);
57 for (y = 0; y < h; y++) {
58 /* get 15 steps of 10 pixel high lines fading in yellow */
59 for (x = 0; x < w; x++) {
60 guint32 pixel = 255 / 15 * (x * 16 / w);
61 pixel *= 0x01000101;
62 data[y * w + x] = pixel;
65 ret = newSWFBitmap_fromData ((guint8 *) data, w, h, TRUE);
66 g_free (data);
67 return ret;
70 static SWFDisplayItem
71 add_images (SWFMovie movie, int blend_mode)
73 SWFBitmap bitmap;
74 SWFShape shape;
75 SWFMovieClip clip;
76 SWFDisplayItem item;
78 clip = newSWFMovieClip ();
80 bitmap = create_yellow_image (SIZE, SIZE);
81 shape = newSWFShapeFromBitmap (bitmap, SWFFILL_CLIPPED_BITMAP);
82 item = SWFMovieClip_add (clip, (SWFBlock) shape);
83 SWFDisplayItem_setDepth (item, 1);
85 bitmap = create_teal_image (SIZE, SIZE);
86 shape = newSWFShapeFromBitmap (bitmap, SWFFILL_CLIPPED_BITMAP);
87 item = SWFMovieClip_add (clip, (SWFBlock) shape);
88 SWFDisplayItem_setDepth (item, 2);
89 SWFDisplayItem_setBlendMode (item, blend_mode);
91 SWFMovieClip_nextFrame (clip);
93 item = SWFMovie_add (movie, (SWFBlock) clip);
94 SWFDisplayItem_setBlendMode (item, SWFBLEND_MODE_LAYER);
96 return item;
99 static void
100 do_movie (int version)
102 SWFMovie movie;
103 char *real_name;
104 int mode;
106 for (mode = 0; mode < G_N_ELEMENTS (modes); mode++) {
107 movie = newSWFMovieWithVersion (version);
108 movie = newSWFMovie();
109 SWFMovie_setRate (movie, 1);
110 SWFMovie_setDimension (movie, SIZE, SIZE);
111 SWFMovie_setBackground (movie, 0, 0, 0);
113 add_images (movie, mode);
114 SWFMovie_nextFrame (movie);
116 real_name = g_strdup_printf ("blend-mode-%s-%d.swf", modes[mode], version);
117 SWFMovie_save (movie, real_name);
118 g_free (real_name);
123 main (int argc, char **argv)
125 int i;
127 if (Ming_init ())
128 return 1;
130 for (i = 7; i < 9; i++)
131 do_movie (i);
133 return 0;