3 Example for including and mapping jpeg images to swf shapes
5 Part of the swftools package.
7 Copyright (c) 2000, 2001 Rainer Böhme <rfxswf@reflex-studio.de>
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
26 #include "../rfxswf.h"
35 int main( int argc
, char ** argv
)
50 memset(&swf
,0x00,sizeof(SWF
));
53 swf
.frameRate
= 0x1800;
54 swf
.movieSize
.xmax
= 20*WIDTH
;
55 swf
.movieSize
.ymax
= 20*HEIGHT
;
57 swf
.firstTag
= swf_InsertTag(NULL
,ST_SETBACKGROUNDCOLOR
);
65 t
= swf_InsertTag(t
,ST_DEFINEBITSJPEG2
);
67 swf_SetU16(t
,ID_BITS
);
68 // swf_SetJPEGBits(t,"test.jpg",QUALITY); <- use this to include an image from disk
70 // That's the way to use memory bitmaps (24bit,RGB)
72 jpeg
= swf_SetJPEGBitsStart(t
,WIDTH
,HEIGHT
,QUALITY
);
74 for (y
=0;y
<HEIGHT
;y
++)
75 { U8 scanline
[3*WIDTH
];
78 { scanline
[p
++] = x
; // R
79 scanline
[p
++] = y
; // G
80 scanline
[p
++] = 0x80; // B
82 swf_SetJPEGBitsLine(jpeg
,scanline
);
85 swf_SetJPEGBitsFinish(jpeg
);
87 // do some rotation animation
89 for (frame
=0;frame
<64;frame
++)
91 t
= swf_InsertTag(t
,ST_DEFINESHAPE
);
95 rgb
.b
= rgb
.g
= rgb
.r
= 0x00;
96 ls
= swf_ShapeAddLineStyle(s
,40,&rgb
);
98 swf_GetMatrix(NULL
,&m
);
100 m
.sy
= m
.sx
= (int)(cos(((float)(frame
))/32*3.141)*0x80000);
101 m
.r0
= (int)(sin(((float)(frame
))/32*3.141)*0x80000);
104 fs
= swf_ShapeAddBitmapFillStyle(s
,&m
,ID_BITS
,0);
106 swf_SetU16(t
,ID_SHAPE
+frame
); // ID
115 swf_SetShapeHeader(t
,s
);
117 swf_ShapeSetAll(t
,s
,0,0,ls
,fs
,0);
119 swf_ShapeSetLine(t
,s
,10*WIDTH
,0);
120 swf_ShapeSetLine(t
,s
,-10*WIDTH
,10*HEIGHT
);
121 // swf_ShapeSetLine(t,s,-10*WIDTH,-10*WIDTH);
122 swf_ShapeSetLine(t
,s
,0,-10*HEIGHT
);
128 { t
= swf_InsertTag(t
,ST_REMOVEOBJECT2
); swf_SetU16(t
,1);
129 t
= swf_InsertTag(t
,ST_REMOVEOBJECT2
); swf_SetU16(t
,2);
132 t
= swf_InsertTag(t
,ST_PLACEOBJECT2
);
133 swf_ObjectPlace(t
,ID_SHAPE
+frame
,1,NULL
,NULL
,NULL
);
135 t
= swf_InsertTag(t
,ST_PLACEOBJECT2
);
136 swf_GetMatrix(NULL
,&m
); // get default matrix with no transformation
138 m
.tx
= m
.ty
= 10*WIDTH
+frame
*10;
139 m
.sx
= m
.sy
= 0xfffeffff;
140 swf_ObjectPlace(t
,ID_SHAPE
+frame
,2,&m
,NULL
,NULL
);
143 t
= swf_InsertTag(t
,ST_SHOWFRAME
);
147 t
= swf_InsertTag(t
,ST_END
);
149 // swf_WriteCGI(&swf);
151 f
= open("jpegtest.swf",O_WRONLY
|O_CREAT
||O_BINARY
, 0644);
152 if FAILED(swf_WriteSWF(f
,&swf
)) fprintf(stderr
,"WriteSWF() failed.\n");
155 swf_FreeTags(&swf
); // cleanup