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);
78 { pal[x].r = (x&0xf)*16;
79 pal[x].g = (x*2)&0xff;
81 pal[x].a = (x==0xff)?0:0xff;
86 bitmap16[y*(bps16>>1)+x] = ((x&0xf0)==(y&0xf0))?0xffff:(x&0x0f)<(y&0xf)?BM16_RED|BM16_GREEN:BM16_BLUE;
90 { bitmap32[y*(bps32>>2)+x].r = /*((x&0x10)==(y&0x10))?*/((x&4)==(y&4))?y:x;
91 bitmap32[y*(bps32>>2)+x].g = x;
92 bitmap32[y*(bps32>>2)+x].b = y;
97 // put texture into flash movie
99 memset(&swf,0x00,sizeof(SWF));
102 swf.frameRate = 0x1800;
103 swf.movieSize.xmax = 20*WIDTH;
104 swf.movieSize.ymax = 20*HEIGHT;
106 swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR);
114 t = swf_InsertTag(t,ST_DEFINEBITSLOSSLESS);
116 swf_SetU16(t,ID_BITS);
117 swf_SetLosslessBits(t,dx,dy,bitmap32,BMF_32BIT);
119 t = swf_InsertTag(t,ST_DEFINEBITSLOSSLESS2);
121 /* be careful with ST_DEFINEBITSLOSSLESS2, because
122 the Flash player produces great bugs if you use too many
123 alpha colors in your palette. The only sensible result that
124 can be archeived is setting one color to r=0,b=0,g=0,a=0 to
125 make transparent parts in sprites. That's the cause why alpha
126 handling is implemented in lossless routines of rfxswf.
129 swf_SetU16(t,ID_BITS+1);
130 swf_SetLosslessBitsIndexed(t,dx,dy,bitmap8,pal,256);
132 t = swf_InsertTag(t,ST_DEFINEBITSLOSSLESS);
134 swf_SetU16(t,ID_BITS+2);
135 swf_SetLosslessBits(t,dx,dy,bitmap16,BMF_16BIT);
137 /* By the way: ST_DEFINELOSSLESS2 produces stange output on
138 16 and 32 bits image data, too.... it seems that the
139 ming developers deal with the same problem.
144 t = swf_InsertTag(t,ST_DEFINESHAPE);
147 rgb.b = rgb.g = rgb.r = 0x00;
148 ls = swf_ShapeAddLineStyle(s,10,&rgb);
150 swf_GetMatrix(NULL,&m);
151 m.sx = (6*WIDTH/dx)<<16;
152 m.sy = (6*HEIGHT/dy)<<16;
154 fs = swf_ShapeAddBitmapFillStyle(s,&m,ID_BITS+((i+(i/3))%3),0);
156 swf_SetU16(t,ID_SHAPE+i); // ID
165 swf_SetShapeStyles(t,s);
166 swf_ShapeCountBits(s,NULL,NULL);
167 swf_SetShapeBits(t,s);
169 swf_ShapeSetAll(t,s,0,0,ls,fs,0);
171 swf_ShapeSetLine(t,s,6*WIDTH,0);
172 swf_ShapeSetLine(t,s,0,6*HEIGHT);
173 swf_ShapeSetLine(t,s,-6*WIDTH,0);
174 swf_ShapeSetLine(t,s,0,-6*HEIGHT);
177 swf_GetMatrix(NULL,&m);
178 m.tx = (i%3) * (6*WIDTH+60);
179 m.ty = (i/3) * (6*HEIGHT+60);
181 t = swf_InsertTag(t,ST_PLACEOBJECT2);
182 swf_ObjectPlace(t,ID_SHAPE+i,1+i,&m,NULL,NULL);
185 t = swf_InsertTag(t,ST_SHOWFRAME);
187 t = swf_InsertTag(t,ST_END);
189 // swf_WriteCGI(&swf);
191 f = open("zlibtest.swf",O_RDWR|O_CREAT|O_TRUNC,0644);
192 if FAILED(swf_WriteSWF(f,&swf)) fprintf(stderr,"WriteSWF() failed.\n");
198 system("start ..\\zlibtest.swf");