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 file is distributed under the GPL, see file COPYING for details
16 #include "../rfxswf.h"
25 int main( int argc, char ** argv)
40 memset(&swf,0x00,sizeof(SWF));
43 swf.frameRate = 0x1800;
44 swf.movieSize.xmax = 20*WIDTH;
45 swf.movieSize.ymax = 20*HEIGHT;
47 swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR);
55 t = swf_InsertTag(t,ST_DEFINEBITSJPEG2);
57 swf_SetU16(t,ID_BITS);
58 // swf_SetJPEGBits(t,"test.jpg",QUALITY); <- use this to include an image from disk
60 // That's the way to use memory bitmaps (24bit,RGB)
62 jpeg = swf_SetJPEGBitsStart(t,WIDTH,HEIGHT,QUALITY);
64 for (y=0;y<HEIGHT;y++)
65 { U8 scanline[3*WIDTH];
68 { scanline[p++] = x; // R
69 scanline[p++] = y; // G
70 scanline[p++] = 0x80; // B
72 swf_SetJPEGBitsLine(jpeg,scanline);
75 swf_SetJPEGBitsFinish(jpeg);
77 // do some rotation animation
79 for (frame=0;frame<64;frame++)
81 t = swf_InsertTag(t,ST_DEFINESHAPE);
85 rgb.b = rgb.g = rgb.r = 0x00;
86 ls = swf_ShapeAddLineStyle(s,40,&rgb);
88 swf_GetMatrix(NULL,&m);
90 m.sy = m.sx = (int)(cos(((float)(frame))/32*3.141)*0x80000);
91 m.r0 = (int)(sin(((float)(frame))/32*3.141)*0x80000);
94 fs = swf_ShapeAddBitmapFillStyle(s,&m,ID_BITS,0);
96 swf_SetU16(t,ID_SHAPE+frame); // ID
105 swf_SetShapeHeader(t,s);
107 swf_ShapeSetAll(t,s,0,0,ls,fs,0);
109 swf_ShapeSetLine(t,s,10*WIDTH,0);
110 swf_ShapeSetLine(t,s,-10*WIDTH,10*HEIGHT);
111 // swf_ShapeSetLine(t,s,-10*WIDTH,-10*WIDTH);
112 swf_ShapeSetLine(t,s,0,-10*HEIGHT);
118 { t = swf_InsertTag(t,ST_REMOVEOBJECT2); swf_SetU16(t,1);
119 t = swf_InsertTag(t,ST_REMOVEOBJECT2); swf_SetU16(t,2);
122 t = swf_InsertTag(t,ST_PLACEOBJECT2);
123 swf_ObjectPlace(t,ID_SHAPE+frame,1,NULL,NULL,NULL);
125 t = swf_InsertTag(t,ST_PLACEOBJECT2);
126 swf_GetMatrix(NULL,&m); // get default matrix with no transformation
128 m.tx = m.ty = 10*WIDTH+frame*10;
129 m.sx = m.sy = 0xfffeffff;
130 swf_ObjectPlace(t,ID_SHAPE+frame,2,&m,NULL,NULL);
133 t = swf_InsertTag(t,ST_SHOWFRAME);
137 t = swf_InsertTag(t,ST_END);
139 // swf_WriteCGI(&swf);
141 f = open("jpegtest.swf",O_WRONLY|O_CREAT, 0644);
142 if FAILED(swf_WriteSWF(f,&swf)) fprintf(stderr,"WriteSWF() failed.\n");
145 swf_FreeTags(&swf); // cleanup