2 * Copyright (C) 2007, 2009, 2010, 2011 Free Software Foundation, Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #include "ming_utils.h"
26 #define OUTPUT_VERSION 8
27 #define OUTPUT_FILENAME "LoadBitmapTest.swf"
29 const char* mediadir
=".";
32 /// The test shows the following:
34 /// The MovieClip itself is drawn with no transformation, i.e. identity matrix.
35 /// Any contained MovieClips keep their transformation.
36 /// BitmapData.draw draws on top of what's in the BitmapData already.
37 /// Dynamically loaded images are not drawn.
39 main(int argc
, char** argv
)
42 SWFMovieClip dejagnuclip
;
47 if (argc
> 1) mediadir
= argv
[1];
49 fprintf(stderr
, "Usage: %s <mediadir>\n", argv
[0]);
54 Ming_useSWFVersion (OUTPUT_VERSION
);
57 SWFMovie_setDimension(mo
, 800, 600);
59 SWFMovie_setRate(mo
, 12);
60 dejagnuclip
= get_dejagnu_clip(
61 (SWFBlock
)get_default_font(mediadir
), 10, 10, 150, 800, 600);
62 SWFMovie_add(mo
, (SWFBlock
)dejagnuclip
);
64 SWFMovie_nextFrame(mo
);
66 // Add a MovieClip with an image.
68 char file
[] = "/green.jpg";
69 if (strlen(mediadir
) > 1024) {
70 fprintf(stderr
, "Path to media dir too long! Fix the testcase");
72 char path
[1024 + sizeof file
];
73 strcpy(path
, mediadir
);
76 imgfile
= fopen(path
, "rb");
78 fprintf(stderr
, "Failed to open bitmap file");
82 // Note that recent ming version have the more convenient
83 // newSWFInput_filename() function, but we want to support
85 inp
= newSWFInput_file(imgfile
);
86 bp
= newSWFBitmap_fromInput(inp
);
90 SWFMovie_addExport(mo
, (SWFBlock
)bp
, "img1");
92 SWFMovie_writeExports(mo
);
94 // For some reason some values are very slightly different, even though
95 // the bytes should be taken directly from the embedded DefineBits tag.
96 // We'd better not worry about it too much; they're very close.
99 "near = function(bitmap, x, y, val) {"
101 " col = bitmap.getPixel(x, y);"
102 " col_r = (col & 0xff0000) >> 16;"
103 " col_g = (col & 0xff00) >> 8;"
104 " col_b = (col & 0xff);"
105 " val_r = (val & 0xff0000) >> 16;"
106 " val_g = (val & 0xff00) >> 8;"
107 " val_b = (val & 0xff);"
108 " if (Math.abs(col_r - val_r) > tol) return false;"
109 " if (Math.abs(col_b - val_b) > tol) return false;"
110 " if (Math.abs(col_g - val_g) > tol) return false;"
116 "f = flash.display.BitmapData.loadBitmap('img1');");
117 check_equals(mo
, "typeof(f)", "'object'");
118 check_equals(mo
, "f.__proto__", "flash.display.BitmapData.prototype");
119 check(mo
, "f.__proto__ === flash.display.BitmapData.prototype");
120 check_equals(mo
, "f.transparent", "false");
123 check(mo
, "near(f, 85, 10, 0x00ff00)");
124 check(mo
, "near(f, 85, 30, 0x008800)");
125 check(mo
, "near(f, 85, 50, 0x004400)");
126 check(mo
, "near(f, 85, 70, 0x002200)");
127 check(mo
, "near(f, 85, 85, 0x000000)");
129 // Now do weird things with the class to see what's called where.
132 // A static property of an object
134 "ASSetPropFlags(o, null, 0, 1);"
135 "o.func = flash.display.BitmapData.loadBitmap;"
138 "func = flash.display.BitmapData.loadBitmap;"
140 // Overwrite flash.display.BitmapData
141 "backup = flash.display.BitmapData;"
142 "_global.flash.display.BitmapData = 67;"
145 "c = o.func('img1');"
147 // Doesn't work. Not sure why; maybe because 'this' is a level.
150 "o.prototype = backup.prototype;"
151 "e = o.func('img1');"
153 "_root.attachBitmap(c, 67);"
157 check_equals(mo
, "typeof(c)", "'object'");
158 check_equals(mo
, "c.__proto__", "undefined");
159 xcheck_equals(mo
, "typeof(d)", "'undefined'");
161 // The __proto__ member is the prototype of the parent object.
162 check_equals(mo
, "typeof(e)", "'object'");
163 check_equals(mo
, "typeof(e.__proto__)", "'object'");
164 check_equals(mo
, "e.__proto__", "backup.prototype");
165 check_equals(mo
, "typeof(e.constructor)", "'function'");
166 check(mo
, "e.constructor != backup.constructor");
168 add_actions(mo
, "_global.flash.display.BitmapData = backup;");
170 add_actions(mo
, "stop();");
173 puts("Saving " OUTPUT_FILENAME
);
174 SWFMovie_save(mo
, OUTPUT_FILENAME
);