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 file is distributed under the GPL, see file COPYING for details
18 #include "../rfxswf.h"
27 int main ( int argc, char ** argv)
40 int dx = 256; // bitmap size
42 int bps8, bps16, bps32; // bytes per scanline
49 // create test texture
51 bps8 = BYTES_PER_SCANLINE(dx*sizeof(U8));
52 bps16 = BYTES_PER_SCANLINE(dx*sizeof(U16));
53 bps32 = BYTES_PER_SCANLINE(dx*sizeof(U32));
55 pal = malloc(256*sizeof(RGBA));
57 bitmap8 = malloc(bps8*dy);
58 bitmap16 = malloc(bps16*dy);
59 bitmap32 = malloc(bps32*dy);
61 if ((bitmap8) && (pal) && (bitmap16))
65 bitmap8[y*bps8+x] = (y/16)*16+(x/16);
68 { pal[x].r = (x&0xf)*16;
69 pal[x].g = (x*2)&0xff;
71 pal[x].a = (x==0xff)?0:0xff;
76 bitmap16[y*(bps16>>1)+x] = ((x&0xf0)==(y&0xf0))?0xffff:(x&0x0f)<(y&0xf)?BM16_RED|BM16_GREEN:BM16_BLUE;
80 { bitmap32[y*(bps32>>2)+x].r = /*((x&0x10)==(y&0x10))?*/((x&4)==(y&4))?y:x;
81 bitmap32[y*(bps32>>2)+x].g = x;
82 bitmap32[y*(bps32>>2)+x].b = y;
87 // put texture into flash movie
89 memset(&swf,0x00,sizeof(SWF));
92 swf.frameRate = 0x1800;
93 swf.movieSize.xmax = 20*WIDTH;
94 swf.movieSize.ymax = 20*HEIGHT;
96 swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR);
104 t = swf_InsertTag(t,ST_DEFINEBITSLOSSLESS);
106 swf_SetU16(t,ID_BITS);
107 swf_SetLosslessBits(t,dx,dy,bitmap32,BMF_32BIT);
109 t = swf_InsertTag(t,ST_DEFINEBITSLOSSLESS2);
111 /* be careful with ST_DEFINEBITSLOSSLESS2, because
112 the Flash player produces great bugs if you use too many
113 alpha colors in your palette. The only sensible result that
114 can be archeived is setting one color to r=0,b=0,g=0,a=0 to
115 make transparent parts in sprites. That's the cause why alpha
116 handling is implemented in lossless routines of rfxswf.
119 swf_SetU16(t,ID_BITS+1);
120 swf_SetLosslessBitsIndexed(t,dx,dy,bitmap8,pal,256);
122 t = swf_InsertTag(t,ST_DEFINEBITSLOSSLESS);
124 swf_SetU16(t,ID_BITS+2);
125 swf_SetLosslessBits(t,dx,dy,bitmap16,BMF_16BIT);
127 /* By the way: ST_DEFINELOSSLESS2 produces stange output on
128 16 and 32 bits image data, too.... it seems that the
129 ming developers deal with the same problem.
134 t = swf_InsertTag(t,ST_DEFINESHAPE);
137 rgb.b = rgb.g = rgb.r = 0x00;
138 ls = swf_ShapeAddLineStyle(s,10,&rgb);
140 swf_GetMatrix(NULL,&m);
141 m.sx = (6*WIDTH/dx)<<16;
142 m.sy = (6*HEIGHT/dy)<<16;
144 fs = swf_ShapeAddBitmapFillStyle(s,&m,ID_BITS+((i+(i/3))%3),0);
146 swf_SetU16(t,ID_SHAPE+i); // ID
155 swf_SetShapeStyles(t,s);
156 swf_ShapeCountBits(s,NULL,NULL);
157 swf_SetShapeBits(t,s);
159 swf_ShapeSetAll(t,s,0,0,ls,fs,0);
161 swf_ShapeSetLine(t,s,6*WIDTH,0);
162 swf_ShapeSetLine(t,s,0,6*HEIGHT);
163 swf_ShapeSetLine(t,s,-6*WIDTH,0);
164 swf_ShapeSetLine(t,s,0,-6*HEIGHT);
167 swf_GetMatrix(NULL,&m);
168 m.tx = (i%3) * (6*WIDTH+60);
169 m.ty = (i/3) * (6*HEIGHT+60);
171 t = swf_InsertTag(t,ST_PLACEOBJECT2);
172 swf_ObjectPlace(t,ID_SHAPE+i,1+i,&m,NULL,NULL);
175 t = swf_InsertTag(t,ST_SHOWFRAME);
177 t = swf_InsertTag(t,ST_END);
179 // swf_WriteCGI(&swf);
181 f = open("zlibtest.swf",O_RDWR|O_CREAT|O_TRUNC,0644);
182 if FAILED(swf_WriteSWF(f,&swf)) fprintf(stderr,"WriteSWF() failed.\n");
188 system("start ..\\zlibtest.swf");