3 Little example for rfxswf's lossless bitmap functions.
4 This program creates a swf with three zlib compressed
5 images: 8 bit indexed, 16 and 32 bit
7 Part of the swftools package.
9 Copyright (c) 2001 Rainer Böhme <rfxswf@reflex-studio.de>
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
28 #include "../rfxswf.h"
37 int main ( int argc, char ** argv)
50 int dx = 256; // bitmap size
52 int bps8, bps16, bps32; // bytes per scanline
59 // create test texture
61 bps8 = BYTES_PER_SCANLINE(dx*sizeof(U8));
62 bps16 = BYTES_PER_SCANLINE(dx*sizeof(U16));
63 bps32 = BYTES_PER_SCANLINE(dx*sizeof(U32));
65 pal = malloc(256*sizeof(RGBA));
67 bitmap8 = malloc(bps8*dy);
68 bitmap16 = malloc(bps16*dy);
69 bitmap32 = malloc(bps32*dy);
71 if ((bitmap8) && (pal) && (bitmap16))
75 bitmap8[y*bps8+x] = (y/16)*16+(x/16);
83 pal[x].r = (pal[x].r*pal[x].a)/255;
84 pal[x].g = (pal[x].g*pal[x].a)/255;
85 pal[x].b = (pal[x].b*pal[x].a)/255;
93 bitmap16[y*(bps16>>1)+x] = ((green/0x40)&0x03)|
96 ((green/0x08)&0x07)<<13;
101 { bitmap32[y*(bps32>>2)+x].r = /*((x&0x10)==(y&0x10))?*/((x&4)==(y&4))?y:x;
102 bitmap32[y*(bps32>>2)+x].g = x;
103 bitmap32[y*(bps32>>2)+x].b = y;
108 // put texture into flash movie
110 memset(&swf,0x00,sizeof(SWF));
113 swf.frameRate = 0x1800;
114 swf.movieSize.xmax = 20*WIDTH;
115 swf.movieSize.ymax = 20*HEIGHT;
117 swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR);
125 t = swf_InsertTag(t,ST_DEFINEBITSLOSSLESS);
127 swf_SetU16(t,ID_BITS);
128 swf_SetLosslessBits(t,dx,dy,bitmap32,BMF_32BIT);
130 t = swf_InsertTag(t,ST_DEFINEBITSLOSSLESS2);
132 /* be careful with ST_DEFINEBITSLOSSLESS2, because
133 the Flash player produces great bugs if you use too many
134 alpha colors in your palette. The only sensible result that
135 can be archeived is setting one color to r=0,b=0,g=0,a=0 to
136 make transparent parts in sprites. That's the cause why alpha
137 handling is implemented in lossless routines of rfxswf.
140 swf_SetU16(t,ID_BITS+1);
141 swf_SetLosslessBitsIndexed(t,dx,dy,bitmap8,pal,256);
143 t = swf_InsertTag(t,ST_DEFINEBITSLOSSLESS);
145 swf_SetU16(t,ID_BITS+2);
146 swf_SetLosslessBits(t,dx,dy,bitmap16,BMF_16BIT);
148 /* By the way: ST_DEFINELOSSLESS2 produces stange output on
149 16 and 32 bits image data, too.... it seems that the
150 ming developers deal with the same problem.
155 t = swf_InsertTag(t,ST_DEFINESHAPE);
158 rgb.b = rgb.g = rgb.r = 0x00;
159 ls = swf_ShapeAddLineStyle(s,10,&rgb);
161 swf_GetMatrix(NULL,&m);
162 m.sx = (6*WIDTH/dx)<<16;
163 m.sy = (6*HEIGHT/dy)<<16;
165 fs = swf_ShapeAddBitmapFillStyle(s,&m,ID_BITS+((i+(i/3))%3),0);
167 swf_SetU16(t,ID_SHAPE+i); // ID
176 swf_SetShapeStyles(t,s);
177 swf_ShapeCountBits(s,NULL,NULL);
178 swf_SetShapeBits(t,s);
180 swf_ShapeSetAll(t,s,0,0,ls,fs,0);
182 swf_ShapeSetLine(t,s,6*WIDTH,0);
183 swf_ShapeSetLine(t,s,0,6*HEIGHT);
184 swf_ShapeSetLine(t,s,-6*WIDTH,0);
185 swf_ShapeSetLine(t,s,0,-6*HEIGHT);
188 swf_GetMatrix(NULL,&m);
189 m.tx = (i%3) * (6*WIDTH+60);
190 m.ty = (i/3) * (6*HEIGHT+60);
192 t = swf_InsertTag(t,ST_PLACEOBJECT2);
193 swf_ObjectPlace(t,ID_SHAPE+i,1+i,&m,NULL,NULL);
196 t = swf_InsertTag(t,ST_SHOWFRAME);
198 t = swf_InsertTag(t,ST_END);
200 // swf_WriteCGI(&swf);
202 f = open("zlibtest.swf",O_RDWR|O_CREAT|O_TRUNC|O_BINARY,0644);
203 if FAILED(swf_WriteSWF(f,&swf)) fprintf(stderr,"WriteSWF() failed.\n");
209 system("start ..\\zlibtest.swf");