use environment variable SWFTOOLS_TMP instead of TEMP
[swftools.git] / lib / example / jpegtest.c
blob4e195d900bca87396277ac9d9775e4217242a9ab
1 /* jpegtest.c
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 */
23 #include <stdio.h>
24 #include <fcntl.h>
25 #include <math.h>
26 #include "../rfxswf.h"
28 #define WIDTH 256
29 #define HEIGHT 256
30 #define QUALITY 85
32 #define ID_BITS 1
33 #define ID_SHAPE 2
35 int main( int argc, char ** argv)
36 { SWF swf;
37 TAG* t;
38 RGBA rgb;
39 SHAPE* s;
40 MATRIX m;
41 SRECT r;
42 JPEGBITS* jpeg;
44 int f; // file handle
46 int ls; // line style
47 int fs; // fill style
48 int frame;
50 memset(&swf,0x00,sizeof(SWF));
52 swf.fileVersion = 4;
53 swf.frameRate = 0x1800;
54 swf.movieSize.xmax = 20*WIDTH;
55 swf.movieSize.ymax = 20*HEIGHT;
57 swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR);
58 t = swf.firstTag;
60 rgb.r = 0xff;
61 rgb.b = 0xff;
62 rgb.g = 0xff;
63 swf_SetRGB(t,&rgb);
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);
73 { int y;
74 for (y=0;y<HEIGHT;y++)
75 { U8 scanline[3*WIDTH];
76 int x,p = 0;
77 for (x=0;x<WIDTH;x++)
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);
93 swf_ShapeNew(&s);
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);
102 m.r1 = -m.r0;
104 fs = swf_ShapeAddBitmapFillStyle(s,&m,ID_BITS,0);
106 swf_SetU16(t,ID_SHAPE+frame); // ID
108 r.xmin = 0;
109 r.ymin = 0;
110 r.xmax = 10*WIDTH;
111 r.ymax = 10*HEIGHT;
113 swf_SetRect(t,&r);
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);
123 swf_ShapeSetEnd(t);
125 swf_ShapeFree(s);
127 if (frame)
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);
145 } // frame loop
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");
153 close(f);
155 swf_FreeTags(&swf); // cleanup
157 return 0;