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
19 #include "../rfxswf.h"
28 int main ( int argc, char ** argv)
41 int dx = 256; // bitmap size
43 int bps8, bps16, bps32; // bytes per scanline
50 // create test texture
52 bps8 = BYTES_PER_SCANLINE(dx*sizeof(U8));
53 bps16 = BYTES_PER_SCANLINE(dx*sizeof(U16));
54 bps32 = BYTES_PER_SCANLINE(dx*sizeof(U32));
56 pal = malloc(256*sizeof(RGBA));
58 bitmap8 = malloc(bps8*dy);
59 bitmap16 = malloc(bps16*dy);
60 bitmap32 = malloc(bps32*dy);
62 if ((bitmap8) && (pal) && (bitmap16))
66 bitmap8[y*bps8+x] = (y/16)*16+(x/16);
69 { pal[x].r = (x&0xf)*16;
70 pal[x].g = (x*2)&0xff;
72 pal[x].a = (x==0xff)?0:0xff;
77 bitmap16[y*(bps16>>1)+x] = ((x&0xf0)==(y&0xf0))?0xffff:(x&0x0f)<(y&0xf)?BM16_RED|BM16_GREEN:BM16_BLUE;
81 { bitmap32[y*(bps32>>2)+x].r = /*((x&0x10)==(y&0x10))?*/((x&4)==(y&4))?y:x;
82 bitmap32[y*(bps32>>2)+x].g = x;
83 bitmap32[y*(bps32>>2)+x].b = y;
88 // put texture into flash movie
90 memset(&swf,0x00,sizeof(SWF));
93 swf.frameRate = 0x1800;
94 swf.movieSize.xmax = 20*WIDTH;
95 swf.movieSize.ymax = 20*HEIGHT;
97 swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR);
105 t = swf_InsertTag(t,ST_DEFINEBITSLOSSLESS);
107 swf_SetU16(t,ID_BITS);
108 swf_SetLosslessBits(t,dx,dy,bitmap32,BMF_32BIT);
110 t = swf_InsertTag(t,ST_DEFINEBITSLOSSLESS2);
112 /* be careful with ST_DEFINEBITSLOSSLESS2, because
113 the Flash player produces great bugs if you use too many
114 alpha colors in your palette. The only sensible result that
115 can be archeived is setting one color to r=0,b=0,g=0,a=0 to
116 make transparent parts in sprites. That's the cause why alpha
117 handling is implemented in lossless routines of rfxswf.
120 swf_SetU16(t,ID_BITS+1);
121 swf_SetLosslessBitsIndexed(t,dx,dy,bitmap8,pal,256);
123 t = swf_InsertTag(t,ST_DEFINEBITSLOSSLESS);
125 swf_SetU16(t,ID_BITS+2);
126 swf_SetLosslessBits(t,dx,dy,bitmap16,BMF_16BIT);
128 /* By the way: ST_DEFINELOSSLESS2 produces stange output on
129 16 and 32 bits image data, too.... it seems that the
130 ming developers deal with the same problem.
135 t = swf_InsertTag(t,ST_DEFINESHAPE);
138 rgb.b = rgb.g = rgb.r = 0x00;
139 ls = swf_ShapeAddLineStyle(s,10,&rgb);
141 swf_GetMatrix(NULL,&m);
142 m.sx = (6*WIDTH/dx)<<16;
143 m.sy = (6*HEIGHT/dy)<<16;
145 fs = swf_ShapeAddBitmapFillStyle(s,&m,ID_BITS+((i+(i/3))%3),0);
147 swf_SetU16(t,ID_SHAPE+i); // ID
156 swf_SetShapeStyles(t,s);
157 swf_ShapeCountBits(s,NULL,NULL);
158 swf_SetShapeBits(t,s);
160 swf_ShapeSetAll(t,s,0,0,ls,fs,0);
162 swf_ShapeSetLine(t,s,6*WIDTH,0);
163 swf_ShapeSetLine(t,s,0,6*HEIGHT);
164 swf_ShapeSetLine(t,s,-6*WIDTH,0);
165 swf_ShapeSetLine(t,s,0,-6*HEIGHT);
168 swf_GetMatrix(NULL,&m);
169 m.tx = (i%3) * (6*WIDTH+60);
170 m.ty = (i/3) * (6*HEIGHT+60);
172 t = swf_InsertTag(t,ST_PLACEOBJECT2);
173 swf_ObjectPlace(t,ID_SHAPE+i,1+i,&m,NULL,NULL);
176 t = swf_InsertTag(t,ST_SHOWFRAME);
178 t = swf_InsertTag(t,ST_END);
180 // swf_WriteCGI(&swf);
182 f = open("zlibtest.swf",O_RDWR|O_CREAT|O_TRUNC,0644);
183 if FAILED(swf_WriteSWF(f,&swf)) fprintf(stderr,"WriteSWF() failed.\n");
189 system("start ..\\zlibtest.swf");