From dcd54b8f52f1003b9723ea1aaeb6b1226e04e675 Mon Sep 17 00:00:00 2001 From: boehme Date: Wed, 31 Oct 2001 15:03:57 +0000 Subject: [PATCH] * updated examples to new rfxswf name conventions * added Makefile for all examples * cleaned up examples: added some comments and removed deprecated stuff --- lib/example/Makefile | 33 ++++ lib/example/README | 2 - lib/example/box.c | 249 +++++++++++++++--------------- lib/example/jpegtest.c | 160 +++++++++++--------- lib/example/shape1.c | 97 +++++++----- lib/example/texbox_ac.c | 374 --------------------------------------------- lib/example/transtest.c | 339 +++++++++-------------------------------- lib/example/zlibtest.c | 387 ++++++++++++++++++++++++----------------------- 8 files changed, 582 insertions(+), 1059 deletions(-) create mode 100644 lib/example/Makefile delete mode 100644 lib/example/README delete mode 100644 lib/example/texbox_ac.c diff --git a/lib/example/Makefile b/lib/example/Makefile new file mode 100644 index 0000000..e79ad35 --- /dev/null +++ b/lib/example/Makefile @@ -0,0 +1,33 @@ +# Makefile + +RFXSWF = ../rfxswf.o +LDLIBS = -ljpeg -lm -lz +CFLAGS = -funsigned-char +CC = gcc +DBFLAGS = -g2 + +.c.o: + $(CC) -c $(CFLAGS) $(DBFLAGS) -o $@ $< + +all: jpegtest box shape1 transtest zlibtest + +box: $(RFXSWF) box.o + $(CC) -o box box.o $(RFXSWF) $(LDLIBS) $(DBFLAGS) + +jpegtest: $(RFXSWF) jpegtest.o + $(CC) -o jpegtest jpegtest.o $(RFXSWF) $(LDLIBS) $(DBFLAGS) + +shape1: $(RFXSWF) shape1.o + $(CC) -o shape1 shape1.o $(RFXSWF) $(LDLIBS) $(DBFLAGS) + +transtest: $(RFXSWF) transtest.o + $(CC) -o transtest transtest.o $(RFXSWF) $(LDLIBS) $(DBFLAGS) + +zlibtest: $(RFXSWF) zlibtest.o + $(CC) -o zlibtest zlibtest.o $(RFXSWF) $(LDLIBS) $(DBFLAGS) + +clean: + rm -f jpegtest.o box.o shape1.o trastest.o zlibtest.o \ + jpegtest.swf box.swf shape1.swf trastest.swf zlibtest.swf + + diff --git a/lib/example/README b/lib/example/README deleted file mode 100644 index 09b8b15..0000000 --- a/lib/example/README +++ /dev/null @@ -1,2 +0,0 @@ -These example may not compile because of recent major changes in rfxswf. -We will fix them soon. diff --git a/lib/example/box.c b/lib/example/box.c index 5b10d4b..f4f3e72 100644 --- a/lib/example/box.c +++ b/lib/example/box.c @@ -1,18 +1,25 @@ +/* box.c -// linux/gcc: cc box.c ../rfxswf.c -funsigned-char -o box -lm; cp box /home/www/cgi-bin/box + Example for drawing 3D grind objects + + Part of the swftools package. + + Copyright (c) 2000, 2001 Rainer Böhme + + This file is distributed under the GPL, see file COPYING for details + +*/ #include #include #include #include "../rfxswf.h" -// Box - -#define BANNER_TEXT "reflex" -#define ID_FONT 2000 -#define ID_BANNER 2001 -#define ID_HIGHLIGHT 2002 -#define ID_BUTTON 2003 +#define BANNER_TEXT "reflex" // banner is disabled due to new font handling +#define ID_FONT 2000 +#define ID_BANNER 2001 +#define ID_HIGHLIGHT 2002 +#define ID_BUTTON 2003 #define a 200 int sX[] = { a,-a, a,-a, a,-a, a,-a}; @@ -40,15 +47,16 @@ void ShapeSquare(LPTAG t,LPSHAPE s,int p1,int p2,int p3,int p4,int dx,int dy) // Hidden-Line-Check if (((dX[p2]-dX[p1])*(dY[p3]-dY[p1])-(dX[p3]-dX[p1])*(dY[p2]-dY[p1]))<0) return; - ShapeSetMove(t,s,dX[p1]+dx,dY[p1]+dy); - ShapeSetLine(t,s,dX[p2]-dX[p1],dY[p2]-dY[p1]); - ShapeSetLine(t,s,dX[p3]-dX[p2],dY[p3]-dY[p2]); - ShapeSetLine(t,s,dX[p4]-dX[p3],dY[p4]-dY[p3]); - ShapeSetLine(t,s,dX[p1]-dX[p4],dY[p1]-dY[p4]); + swf_ShapeSetMove(t,s,dX[p1]+dx,dY[p1]+dy); + swf_ShapeSetLine(t,s,dX[p2]-dX[p1],dY[p2]-dY[p1]); + swf_ShapeSetLine(t,s,dX[p3]-dX[p2],dY[p3]-dY[p2]); + swf_ShapeSetLine(t,s,dX[p4]-dX[p3],dY[p4]-dY[p3]); + swf_ShapeSetLine(t,s,dX[p1]-dX[p4],dY[p1]-dY[p4]); } void mapBox(int xw,int yw,int zw) +// simple trigonometry without using transformation matrices { int i; int x1,y1,z1,x2,y2,z2,x3,y3,z3; int y,x,z; @@ -61,7 +69,7 @@ void mapBox(int xw,int yw,int zw) { x = sX[i]; y = sY[i]; z = sZ[i]; - + y1 = ( y*cos_[xw]- z*sin_[xw])>>8; z1 = ( y*sin_[xw]+ z*cos_[xw])>>8; x1 = x; @@ -75,7 +83,7 @@ void mapBox(int xw,int yw,int zw) dX[i] = x3*4000/(z3+950); dY[i] = y3*4000/(z3+950); - + } } @@ -87,8 +95,6 @@ int main (int argc,char ** argv) LPSHAPE s; S32 width = 800,height = 800; U8 gbits,abits; - LPSWFFONT font; - FONTUSAGE use; CXFORM cx1,cx2; MATRIX m; @@ -96,7 +102,7 @@ int main (int argc,char ** argv) /* f = open("Arial.efont",O_RDONLY); if (f>=0) - { if (FAILED(FontImport(f,&font))) + { if (FAILED(swf_FontImport(f,&font))) { fprintf(stderr,"Font import failed\n"); close(f); return -1; @@ -108,195 +114,194 @@ int main (int argc,char ** argv) } close(f); - FontSetID(font,ID_FONT); - FontInitUsage(&use); - FontUse(&use,BANNER_TEXT); - FontReduce(font,&use);*/ + swf_FontSetID(font,ID_FONT); + swf_FontInitUsage(&use); + swf_FontUse(&use,BANNER_TEXT); + swf_FontReduce(font,&use); +*/ calcTables(); memset(&swf,0x00,sizeof(SWF)); - swf.FileVersion = 4; - swf.FrameRate = 0x4000; - swf.MovieSize.xmax = 4*width; - swf.MovieSize.ymax = 4*height; + swf.fileVersion = 4; + swf.frameRate = 0x4000; + swf.movieSize.xmax = 4*width; + swf.movieSize.ymax = 4*height; - swf.FirstTag = InsertTag(NULL,ST_SETBACKGROUNDCOLOR); - t = swf.FirstTag; + swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR); + t = swf.firstTag; rgb.r = 0xff; rgb.g = 0xff; rgb.b = 0xff; - SetRGB(t,&rgb); + swf_SetRGB(t,&rgb); + +/* This part can't be used because of missing fonts. Nevertheless it shows, how + rfxswf handles fonts, fontusages (in order to include only the used glyphs + into the output swf) and how to make a simple button + - t = InsertTag(t,ST_DEFINEFONT); + t = swf_InsertTag(t,ST_DEFINEFONT); - FontSetDefine(t,font); + swf_FontSetDefine(t,font); - t = InsertTag(t,ST_DEFINEFONTINFO); + t = swf_InsertTag(t,ST_DEFINEFONTINFO); - FontSetInfo(t,font); + swf_FontSetInfo(t,font); - t = InsertTag(t,ST_DEFINETEXT); + t = swf_InsertTag(t,ST_DEFINETEXT); - SetU16(t,ID_BANNER); // ID + swf_SetU16(t,ID_BANNER); // ID r.xmin = 0; r.ymin = 0; r.xmax = 400; r.ymax = 400; - SetRect(t,&r); + + swf_SetRect(t,&r); - SetMatrix(t,NULL); + swf_SetMatrix(t,NULL); - TextCountBits(font,BANNER_TEXT,80,&gbits,&abits); + swf_TextCountBits(font,BANNER_TEXT,80,&gbits,&abits); - SetU8(t,gbits); - SetU8(t,abits); + swf_SetU8(t,gbits); + swf_SetU8(t,abits); rgb.r = 0xc0; rgb.g = 0xc0; rgb.b = 0xc0; - TextSetInfoRecord(t,font,height/4,&rgb,0,200); - TextSetCharRecord(t,font,BANNER_TEXT,80,gbits,abits); + swf_TextSetInfoRecord(t,font,height/4,&rgb,0,200); + swf_TextSetCharRecord(t,font,BANNER_TEXT,80,gbits,abits); - SetU8(t,0); + swf_SetU8(t,0); - t = InsertTag(t,ST_DEFINETEXT); + t = swf_InsertTag(t,ST_DEFINETEXT); - SetU16(t,ID_HIGHLIGHT); // ID + swf_SetU16(t,ID_HIGHLIGHT); // ID r.xmin = 0; r.ymin = 0; r.xmax = 800; r.ymax = 400; - SetRect(t,&r); + + swf_SetRect(t,&r); - SetMatrix(t,NULL); + swf_SetMatrix(t,NULL); - TextCountBits(font,BANNER_TEXT,80,&gbits,&abits); + swf_TextCountBits(font,BANNER_TEXT,80,&gbits,&abits); - SetU8(t,gbits); - SetU8(t,abits); + swf_SetU8(t,gbits); + swf_SetU8(t,abits); rgb.r = 0x20; rgb.g = 0x20; rgb.b = 0x20; - TextSetInfoRecord(t,font,height/4,&rgb,0,200); - TextSetCharRecord(t,font,BANNER_TEXT,80,gbits,abits); + swf_TextSetInfoRecord(t,font,height/4,&rgb,0,200); + swf_TextSetCharRecord(t,font,BANNER_TEXT,80,gbits,abits); - SetU8(t,0); - - t = InsertTag(t,ST_DEFINEBUTTON); + swf_SetU8(t,0); + + t = swf_InsertTag(t,ST_DEFINEBUTTON); - GetMatrix(NULL,&m); - - m.tx = 3*width; - m.ty = 7*height/2; + swf_GetMatrix(NULL,&m); + + m.tx = 3*width; + m.ty = 7*height/2; - SetU16(t,ID_BUTTON); // ID - ButtonSetRecord(t,BS_UP,ID_BANNER,1,&m,NULL); - ButtonSetRecord(t,BS_DOWN|BS_HIT|BS_OVER,ID_HIGHLIGHT,1,&m,NULL); - SetU8(t,0); // End of Button Records - SetU8(t,0); // End of Action Records + swf_SetU16(t,ID_BUTTON); // ID + swf_ButtonSetRecord(t,BS_UP,ID_BANNER,1,&m,NULL); + swf_ButtonSetRecord(t,BS_DOWN|BS_HIT|BS_OVER,ID_HIGHLIGHT,1,&m,NULL); + swf_SetU8(t,0); // End of Button Records + swf_SetU8(t,0); // End of Action Records - t = InsertTag(t,ST_PLACEOBJECT2); - - ObjectPlace(t,ID_BUTTON,1,NULL,NULL,NULL); - - GetCXForm(NULL,&cx1,1); - GetCXForm(NULL,&cx2,1); - -// cx1.a1 = -(0x40*1); -// cx2.a1 = -(0x40*2); - - cx1.r1 = cx1.g1 = 0x80; - cx2.r1 = cx2.g1 = 0xc0; - + t = swf_InsertTag(t,ST_PLACEOBJECT2); - + swf_ObjectPlace(t,ID_BUTTON,1,NULL,NULL,NULL); + +*/ + for (frame=0;frame<256;frame+=2) { int id = frame +1; - t = InsertTag(t,ST_DEFINESHAPE); + t = swf_InsertTag(t,ST_DEFINESHAPE); - NewShape(&s); + swf_ShapeNew(&s); rgb.r = rgb.g = 0x00; rgb.b = 0xff; - j = ShapeAddLineStyle(s,40,&rgb); + j = swf_ShapeAddLineStyle(s,40,&rgb); - SetU16(t,id); // ID + swf_SetU16(t,id); // ID r.xmin = 0; r.ymin = 0; r.xmax = 4*width; r.ymax = 4*height; - SetRect(t,&r); - - SetShapeStyles(t,s); - ShapeCountBits(s,NULL,NULL); - SetShapeBits(t,s); - - ShapeSetAll(t,s,0,0,j,0,0); - - mapBox(frame,frame,frame>>1); - - ShapeSquare(t,s,0,2,3,1,2*width,2*height); - ShapeSquare(t,s,4,5,7,6,2*width,2*height); - ShapeSquare(t,s,0,4,6,2,2*width,2*height); - ShapeSquare(t,s,1,3,7,5,2*width,2*height); - ShapeSquare(t,s,0,1,5,4,2*width,2*height); - ShapeSquare(t,s,2,6,7,3,2*width,2*height); - - ShapeSetEnd(t); + swf_SetRect(t,&r); + swf_SetShapeHeader(t,s); + swf_ShapeSetAll(t,s,0,0,j,0,0); + + mapBox(frame,frame,frame>>1); + + ShapeSquare(t,s,0,2,3,1,2*width,2*height); + ShapeSquare(t,s,4,5,7,6,2*width,2*height); + ShapeSquare(t,s,0,4,6,2,2*width,2*height); + ShapeSquare(t,s,1,3,7,5,2*width,2*height); + ShapeSquare(t,s,0,1,5,4,2*width,2*height); + ShapeSquare(t,s,2,6,7,3,2*width,2*height); + + swf_ShapeSetEnd(t); + swf_ShapeFree(s); } + swf_GetCXForm(NULL,&cx1,1); // get default ColorTransforms + swf_GetCXForm(NULL,&cx2,1); + + cx1.r1 = cx1.g1 = 0x80; // set alpha for blur effect + cx2.r1 = cx2.g1 = 0xc0; + for (frame=0;frame<256;frame+=2) { int id = frame +1; int id2 = ((frame-2)&255)+1; int id3 = ((frame-4)&255)+1; if (frame) - { t = InsertTag(t,ST_REMOVEOBJECT2); SetU16(t,2); // depth - t = InsertTag(t,ST_REMOVEOBJECT2); SetU16(t,3); // depth - t = InsertTag(t,ST_REMOVEOBJECT2); SetU16(t,4); // depth + { t = swf_InsertTag(t,ST_REMOVEOBJECT2); swf_SetU16(t,2); // depth + t = swf_InsertTag(t,ST_REMOVEOBJECT2); swf_SetU16(t,3); // depth + t = swf_InsertTag(t,ST_REMOVEOBJECT2); swf_SetU16(t,4); // depth } - t = InsertTag(t,ST_PLACEOBJECT2); + t = swf_InsertTag(t,ST_PLACEOBJECT2); - ObjectPlace(t,id,4,NULL,NULL,NULL); - - t = InsertTag(t,ST_PLACEOBJECT2); + swf_ObjectPlace(t,id,4,NULL,NULL,NULL); + + t = swf_InsertTag(t,ST_PLACEOBJECT2); - ObjectPlace(t,id2,3,NULL,&cx1,NULL); + swf_ObjectPlace(t,id2,3,NULL,&cx1,NULL); - t = InsertTag(t,ST_PLACEOBJECT2); + t = swf_InsertTag(t,ST_PLACEOBJECT2); - ObjectPlace(t,id3,2,NULL,&cx2,NULL); - - - t = InsertTag(t,ST_SHOWFRAME); - } + swf_ObjectPlace(t,id3,2,NULL,&cx2,NULL); + t = swf_InsertTag(t,ST_SHOWFRAME); + } - - t = InsertTag(t,ST_END); + t = swf_InsertTag(t,ST_END); + +// swf_WriteCGI(&swf); -// WriteCGI(&swf); - - f = open("shape1.swf",O_RDWR|O_CREAT|O_TRUNC); - if FAILED(WriteSWF(f,&swf)) fprintf(stderr,"WriteSWF() failed.\n"); + f = open("box.swf",O_RDWR|O_CREAT|O_TRUNC,0644); + if FAILED(swf_WriteSWF(f,&swf)) fprintf(stderr,"WriteSWF() failed.\n"); close(f); - FreeTags(&swf); + swf_FreeTags(&swf); #ifdef __NT__ - system("start ..\\shape1.swf"); + system("start ..\\box.swf"); #endif return 0; diff --git a/lib/example/jpegtest.c b/lib/example/jpegtest.c index 76eb1ea..5679ac7 100644 --- a/lib/example/jpegtest.c +++ b/lib/example/jpegtest.c @@ -1,17 +1,28 @@ -// linux/gcc cc jpegtest.c ../rfxswf.c -funsigned-char -o jpegtest -lm -ljpeg; cp jpegtest /home/www/cgi-bin/jpegtest +/* jpegtest.c + + Example for including and mapping jpeg images to swf shapes + + Part of the swftools package. + + Copyright (c) 2000, 2001 Rainer Böhme + + This file is distributed under the GPL, see file COPYING for details + +*/ #include -#include +#include +#include #include "../rfxswf.h" -#define WIDTH 256 -#define HEIGHT 256 -#define QUALITY 85 +#define WIDTH 256 +#define HEIGHT 256 +#define QUALITY 85 -#define ID_BITS 1 -#define ID_SHAPE 2 +#define ID_BITS 1 +#define ID_SHAPE 2 -int main ( int argc, char ** argv) +int main( int argc, char ** argv) { SWF swf; LPTAG t; RGBA rgb; @@ -19,6 +30,8 @@ int main ( int argc, char ** argv) MATRIX m; SRECT r; LPJPEGBITS jpeg; + + int f; // file handle int ls; // line style int fs; // fill style @@ -26,25 +39,27 @@ int main ( int argc, char ** argv) memset(&swf,0x00,sizeof(SWF)); - swf.FileVersion = 4; - swf.FrameRate = 0x1800; - swf.MovieSize.xmax = 20*WIDTH; - swf.MovieSize.ymax = 20*HEIGHT; + swf.fileVersion = 4; + swf.frameRate = 0x1800; + swf.movieSize.xmax = 20*WIDTH; + swf.movieSize.ymax = 20*HEIGHT; - swf.FirstTag = InsertTag(NULL,ST_SETBACKGROUNDCOLOR); - t = swf.FirstTag; + swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR); + t = swf.firstTag; rgb.r = 0xff; rgb.b = 0xff; rgb.g = 0xff; - SetRGB(t,&rgb); + swf_SetRGB(t,&rgb); - t = InsertTag(t,ST_DEFINEBITSJPEG2); + t = swf_InsertTag(t,ST_DEFINEBITSJPEG2); - SetU16(t,ID_BITS); - SetJPEGBits(t,"eye.jpg",QUALITY); + swf_SetU16(t,ID_BITS); +// swf_SetJPEGBits(t,"test.jpg",QUALITY); <- use this to include an image from disk -/* jpeg = SetJPEGBitsStart(t,WIDTH,HEIGHT,QUALITY); +// That's the way to use memory bitmaps (24bit,RGB) + + jpeg = swf_SetJPEGBitsStart(t,WIDTH,HEIGHT,QUALITY); { int y; for (y=0;y + + This file is distributed under the GPL, see file COPYING for details + +*/ + #include #include #include @@ -12,71 +24,82 @@ int main (int argc,char ** argv) LPSHAPE s; S32 width=300,height = 300; - int f,i,j; + int f,i,ls1,ls2; - memset(&swf,0x00,sizeof(SWF)); + memset(&swf,0x00,sizeof(SWF)); // set global movie parameters - swf.FileVersion = 4; - swf.FrameRate = 0x1900; - swf.MovieSize.xmax = 20*width; - swf.MovieSize.ymax = 20*height; + swf.fileVersion = 4; // make flash 4 compatible swf + swf.frameRate = 0x1900; // about 0x19 frames per second + + swf.movieSize.xmax = 20*width; // flash units: 1 pixel = 20 units + swf.movieSize.ymax = 20*height; + + swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR); - swf.FirstTag = InsertTag(NULL,ST_SETBACKGROUNDCOLOR); - t = swf.FirstTag; + // now create a tag list be connecting one after another + + t = swf.firstTag; rgb.r = 0xff; rgb.g = 0xff; rgb.b = 0xff; - SetRGB(t,&rgb); + swf_SetRGB(t,&rgb); - t = InsertTag(t,ST_DEFINESHAPE); + t = swf_InsertTag(t,ST_DEFINESHAPE); - NewShape(&s); - rgb.b = rgb.g = 0x00; - j = ShapeAddLineStyle(s,40,&rgb); + swf_ShapeNew(&s); // create new shape instance + + // add two different linestyles + rgb.b = rgb.g = 0x00; + ls1 = swf_ShapeAddLineStyle(s,40,&rgb); + rgb.r = 0; rgb.b = 0xff; - ShapeAddLineStyle(s,40,&rgb); + ls2 = swf_ShapeAddLineStyle(s,40,&rgb); - SetU16(t,1); // ID + swf_SetU16(t,1); // now set character ID r.xmin = 0; r.ymin = 0; - r.xmax = 4*width; - r.ymax = 4*height; + r.xmax = 20*width; + r.ymax = 20*height; - SetRect(t,&r); + swf_SetRect(t,&r); // set shape bounds + - SetShapeStyles(t,s); - ShapeCountBits(s,NULL,NULL); - SetShapeBits(t,s); + swf_SetShapeHeader(t,s); // write all styles to tag - ShapeSetAll(t,s,0,0,j,0,0); -// ShapeSetCurve(t,s,4*width,0,0,4*height); - ShapeSetLine(t,s,4*width,4*height); - ShapeSetStyle(t,s,2,0,0); + swf_ShapeSetAll(t,s,0,0,ls1,0,0); // move to (0,0), select linestyle ls1 and no fillstyle + + + swf_ShapeSetLine(t,s,10*width,10*height); // draw something + swf_ShapeSetStyle(t,s,ls2,0,0); // change to second linestyle + for (i=1;i<10;i++) - ShapeSetCircle(t,s,4*width,4*height,i*width/2,i*height/2); - ShapeSetEnd(t); + swf_ShapeSetCircle(t,s,10*width,10*height,i*width,i*height); + + swf_ShapeSetEnd(t); // finish drawing + + swf_ShapeFree(s); // clean shape structure (which isn't needed anymore after writing the tag) - t = InsertTag(t,ST_PLACEOBJECT2); + t = swf_InsertTag(t,ST_PLACEOBJECT2); // append tag to place your shape into the scene - ObjectPlace(t,1,1,NULL,NULL,NULL); + swf_ObjectPlace(t,1,1,NULL,NULL,NULL); // set character with id 1 (our shape) to depth 1 (upper most layer) - t = InsertTag(t,ST_SHOWFRAME); + t = swf_InsertTag(t,ST_SHOWFRAME); // finish current frame - t = InsertTag(t,ST_END); + t = swf_InsertTag(t,ST_END); // finish current movie (which has just one frame) -// WriteCGI(&swf); +// swf_WriteCGI(&swf); <- use this to create direct CGI output + // write movie to file - f = open("shape1.swf",O_WRONLY|O_CREAT, 0777); -// f = 1; - if FAILED(WriteSWF(f,&swf)) fprintf(stderr,"WriteSWF() failed.\n"); + f = open("shape1.swf",O_WRONLY|O_CREAT, 0644); + if FAILED(swf_WriteSWF(f,&swf)) fprintf(stderr,"WriteSWF() failed.\n"); close(f); - FreeTags(&swf); + swf_FreeTags(&swf); // cleanup -#ifdef __NT__ +#ifdef __NT__ // start flash player to show result on windows systems system("start ..\\shape1.swf"); #endif diff --git a/lib/example/texbox_ac.c b/lib/example/texbox_ac.c deleted file mode 100644 index c94ec36..0000000 --- a/lib/example/texbox_ac.c +++ /dev/null @@ -1,374 +0,0 @@ - -// linux/gcc: cc texbox_ac.c ../rfxswf.c -funsigned-char -o texbox -lmingac -lm -ljpeg; cp texbox /home/www/cgi-bin/texbox - -#include -#include -#include -#include "../rfxswf.h" -#include "../mingac.h" // Action Compiler of MING library - -// Box - -#define BANNER_TEXT "reflex" -#define QUALITY 80 -#define ID_FONT 2000 -#define ID_BANNER 2001 -#define ID_HIGHLIGHT 2002 -#define ID_BUTTON 2003 -#define ID_BITMAP 2004 -#define ID_SHAPE 2005 -#define ID_SHAPE2 2006 - -#define a 200 -int sX[] = { a,-a, a,-a, a,-a, a,-a}; -int sY[] = { a, a,-a,-a, a, a,-a,-a}; -int sZ[] = { a, a, a, a,-a,-a,-a,-a}; -#undef a - -#define PRECISION 16 - -int SHADE = 1; - -int dX[8]; -int dY[8]; -int square_visible[6] = {0,0,0,0,0,0}; -int square_depth[6][2] = {{2,3},{4,5},{6,7},{8,9},{10,11},{12,13}}; -int square_light[6] = {0,0,64,64,-64,-64}; - -int sin_[512],cos_[512]; - -void calcTables() -{ int i; - double d; - for (i=0;i<512;i++) - { d = ((double)i)/128*3.14159; - sin_[i] = (int)(sin(d)*(1<>PRECISION; - z1 = ( y*sin_[xw]+ z*cos_[xw])>>PRECISION; - x1 = x; - - x2 = (x1*cos_[yw]+z1*sin_[yw])>>PRECISION; - y2 = y1; - - x3 = (x2*cos_[zw]-y2*sin_[zw])>>PRECISION; - y3 = (x2*sin_[zw]+y2*cos_[zw])>>PRECISION; - z3 = (z1*cos_[yw]-x1*sin_[yw])>>PRECISION; - - dX[i] = x3*4000/(z3+950); - dY[i] = y3*4000/(z3+950); - - } -} - -void mapLights(int xw,int yw,int zw) -{ int i; - int x1,y1,z1,x2,y2,z2,x3,y3,z3; - - int y[] = {0,0,0,0,256,-256}; - int x[] = {0,0,256,-256,0,0}; - int z[] = {256,-256,0,0,0,0}; - - int lz = 256; // lightvector - int lx = 200, ly = 200; - - for (i=0;i<6;i++) - { y1 = (y[i]*cos_[xw]-z[i]*sin_[xw])>>PRECISION; - z1 = (y[i]*sin_[xw]+z[i]*cos_[xw])>>PRECISION; - x1 = x[i]; - - x2 = (x1*cos_[yw]+z1*sin_[yw])>>PRECISION; - y2 = y1; - z2 = (z1*cos_[yw]-x1*sin_[yw])>>PRECISION; - - x3 = (x2*cos_[zw]-y2*sin_[zw])>>PRECISION; - y3 = (x2*sin_[zw]+y2*cos_[zw])>>PRECISION; - z3 = z2; - - square_light[i] = -128-((x3*lx + y3*ly + z3*lz)>>9); - } -} - - -int main (int argc,char ** argv) -{ SWF swf; - LPTAG t; - RGBA rgb; - SRECT r; - LPSHAPE s; - S32 width = 800,height = 800; - U8 gbits,abits; - int fs,ls; // line & fillstyle - LPSWFFONT font; - FONTUSAGE use; - LPJPEGBITS jpeg; - MATRIX m; - - int f,i,j,frame; - - InitCompiler(AC_DEFAULT); - - f = open("Arial.efont",O_RDONLY); - if (f>=0) - { if (FAILED(FontImport(f,&font))) - { fprintf(stderr,"Font import failed\n"); - close(f); - return -1; - } - } - else - { fprintf(stderr,"Font not found\n"); - return -1; - } - close(f); - - FontSetID(font,ID_FONT); - FontInitUsage(&use); - FontUse(&use,BANNER_TEXT); - FontReduce(font,&use); - - calcTables(); - - memset(&swf,0x00,sizeof(SWF)); - - swf.FileVersion = 4; - swf.FrameRate = 0x4000; - swf.MovieSize.xmax = 4*width; - swf.MovieSize.ymax = 4*height; - - swf.FirstTag = InsertTag(NULL,ST_SETBACKGROUNDCOLOR); - t = swf.FirstTag; - - rgb.r = 0xff; - rgb.g = 0xff; - rgb.b = 0xff; - SetRGB(t,&rgb); - - t = InsertTag(t,ST_DEFINEFONT); - - FontSetDefine(t,font); - - t = InsertTag(t,ST_DEFINEFONTINFO); - - FontSetInfo(t,font); - - t = InsertTag(t,ST_DEFINETEXT); - - SetU16(t,ID_BANNER); // ID - - r.xmin = 0; - r.ymin = 0; - r.xmax = 400; - r.ymax = 400; - SetRect(t,&r); - - SetMatrix(t,NULL); - - TextCountBits(font,BANNER_TEXT,80,&gbits,&abits); - - SetU8(t,gbits); - SetU8(t,abits); - - rgb.r = 0xc0; - rgb.g = 0xc0; - rgb.b = 0xc0; - - TextSetInfoRecord(t,font,height/4,&rgb,0,200); - TextSetCharRecord(t,font,BANNER_TEXT,80,gbits,abits); - - SetU8(t,0); - - t = InsertTag(t,ST_DEFINETEXT); - - SetU16(t,ID_HIGHLIGHT); // ID - - r.xmin = 0; r.ymin = 0; r.xmax = 800; r.ymax = 400; - SetRect(t,&r); - - SetMatrix(t,NULL); - TextCountBits(font,BANNER_TEXT,80,&gbits,&abits); - - SetU8(t,gbits); - SetU8(t,abits); - - rgb.r = 0x20; - rgb.g = 0x20; - rgb.b = 0x20; - - TextSetInfoRecord(t,font,height/4,&rgb,0,200); - TextSetCharRecord(t,font,BANNER_TEXT,80,gbits,abits); - - SetU8(t,0); - - t = InsertTag(t,ST_DEFINEBUTTON); - - GetMatrix(NULL,&m); - - m.tx = 3*width; - m.ty = 7*height/2; - - SetU16(t,ID_BUTTON); // ID - ButtonSetRecord(t,BS_UP,ID_BANNER,1,&m,NULL); - ButtonSetRecord(t,BS_DOWN|BS_HIT|BS_OVER,ID_HIGHLIGHT,1,&m,NULL); - SetU8(t,0); // End of Button Records - - ActionCompile(t,"if (status==1) { status = 0; stop();} else { status=1; play();}"); - - - t = InsertTag(t,ST_PLACEOBJECT2); - - ObjectPlace(t,ID_BUTTON,1,NULL,NULL,NULL); - - t = InsertTag(t,ST_DEFINEBITSJPEG2); - - SetU16(t,ID_BITMAP); - SetJPEGBits(t,"eye.jpg",QUALITY); - - t = InsertTag(t,ST_DEFINESHAPE); - - NewShape(&s); - rgb.b = rgb.g = rgb.r = 0x00; - ls = ShapeAddLineStyle(s,10,&rgb); - rgb.b = 0xff; - - m.tx = m.ty = 0; - m.r0 = m.r1 = 0; - m.sx = m.sy = width<<8; - - fs = ShapeAddBitmapFillStyle(s,&m,ID_BITMAP,0); - - SetU16(t,ID_SHAPE); // ID - - r.xmin = 0; r.ymin = 0; - r.xmax = 2*width; r.ymax = 2*height; - SetRect(t,&r); - - SetShapeHeader(t,s); - ShapeSetAll(t,s,width,0,0,fs,0); - ShapeSetLine(t,s,-width,height); - ShapeSetStyle(t,s,ls,fs,0); - ShapeSetLine(t,s,0,-height); - ShapeSetLine(t,s,width,0); - ShapeSetEnd(t); - - ShapeFree(s); - - t = InsertTag(t,ST_DEFINESHAPE); - - NewShape(&s); - rgb.b = rgb.g = rgb.r = 0x00; - ls = ShapeAddLineStyle(s,10,&rgb); - rgb.b = 0xff; - - m.tx = m.ty = 0; - m.r0 = m.r1 = 0; - m.sx = m.sy = -(width<<8); - - fs = ShapeAddBitmapFillStyle(s,&m,ID_BITMAP,0); - - SetU16(t,ID_SHAPE2); // ID - - r.xmin = 0; r.ymin = 0; - r.xmax = 2*width; r.ymax = 2*height; - SetRect(t,&r); - - SetShapeHeader(t,s); - ShapeSetAll(t,s,width,0,0,fs,0); - ShapeSetLine(t,s,-width,height); - ShapeSetStyle(t,s,ls,fs,0); - ShapeSetLine(t,s,0,-height); - ShapeSetLine(t,s,width,0); - ShapeSetEnd(t); - - ShapeFree(s); - - for (frame=0;frame<256;frame++) - { int dc = 3; // whitespace correction - - mapBox(frame<<1,frame<<1,frame); - if (SHADE) mapLights(frame<<1,frame<<1,frame); - - t = MapSquare(t,width-dc,height-dc,0,2,3,1,2*width,2*height,0); - t = MapSquare(t,width-dc,height-dc,4,5,7,6,2*width,2*height,1); - t = MapSquare(t,width-dc,height-dc,0,4,6,2,2*width,2*height,2); - t = MapSquare(t,width-dc,height-dc,1,3,7,5,2*width,2*height,3); - t = MapSquare(t,width-dc,height-dc,0,1,5,4,2*width,2*height,4); - t = MapSquare(t,width-dc,height-dc,2,6,7,3,2*width,2*height,5); - - t = InsertTag(t,ST_SHOWFRAME); - } - /* - t = InsertTag(t,ST_DOACTION); - - ActionCompile(t,"stop();"); - */ - t = InsertTag(t,ST_END); - - WriteCGI(&swf); - FreeTags(&swf); - return 0; -} - - diff --git a/lib/example/transtest.c b/lib/example/transtest.c index 647a615..4746016 100644 --- a/lib/example/transtest.c +++ b/lib/example/transtest.c @@ -1,140 +1,25 @@ +/* transtest.c -// linux/gcc: cc transtest.c ../rfxswf.c -funsigned-char -o transtest -lm -ljpeg; cp transtest /home/www/cgi-bin/transtest + Example for transforming a textured triangle + + Part of the swftools package. + + Copyright (c) 2001 Rainer Böhme + + This file is distributed under the GPL, see file COPYING for details + +*/ #include #include #include #include "../rfxswf.h" -// Box - -#define BANNER_TEXT "reflex" -#define QUALITY 80 -#define ID_FONT 2000 -#define ID_BANNER 2001 -#define ID_HIGHLIGHT 2002 -#define ID_BUTTON 2003 -#define ID_BITMAP 2004 -#define ID_SHAPE 2005 - -#define a 200 -int sX[] = { a,-a, a,-a, a,-a, a,-a}; -int sY[] = { a, a,-a,-a, a, a,-a,-a}; -int sZ[] = { a, a, a, a,-a,-a,-a,-a}; -#undef a - -int dX[8]; -int dY[8]; - -int sin_[512],cos_[512]; - -void calcTables() -{ int i; - double d; - for (i=0;i<512;i++) - { d = ((double)i)/128*3.14159; - sin_[i] = (int)(sin(d)*256); - cos_[i] = (int)(cos(d)*256); - } -} - -void ShapeSquare(LPTAG t,LPSHAPE s,int p1,int p2,int p3,int p4,int dx,int dy) -{ - // Hidden-Line-Check - if (((dX[p2]-dX[p1])*(dY[p3]-dY[p1])-(dX[p3]-dX[p1])*(dY[p2]-dY[p1]))<0) return; - - ShapeSetMove(t,s,dX[p1]+dx,dY[p1]+dy); - ShapeSetLine(t,s,dX[p2]-dX[p1],dY[p2]-dY[p1]); - ShapeSetLine(t,s,dX[p3]-dX[p2],dY[p3]-dY[p2]); - ShapeSetLine(t,s,dX[p4]-dX[p3],dY[p4]-dY[p3]); - ShapeSetLine(t,s,dX[p1]-dX[p4],dY[p1]-dY[p4]); -} +#define QUALITY 80 +#define ID_BITMAP 2004 +#define ID_SHAPE 2005 - -void mapBox(int xw,int yw,int zw) -{ int i; - int x1,y1,z1,x2,y2,z2,x3,y3,z3; - int y,x,z; - xw &= 255; - yw &= 255; - zw &= 255; - - for (i=0;i<8;i++) - { x = sX[i]; - y = sY[i]; - z = sZ[i]; - - y1 = ( y*cos_[xw]- z*sin_[xw])>>8; - z1 = ( y*sin_[xw]+ z*cos_[xw])>>8; - x1 = x; - - x2 = (x1*cos_[yw]+z1*sin_[yw])>>8; - y2 = y1; - - x3 = (x2*cos_[zw]-y2*sin_[zw])>>8; - y3 = (x2*sin_[zw]+y2*cos_[zw])>>8; - z3 = (z1*cos_[yw]-x1*sin_[yw])>>8; - - dX[i] = x3*4000/(z3+950); - dY[i] = y3*4000/(z3+950); - - } -} - - -#define S64 long long -SFIXED SP(SFIXED a1,SFIXED a2,SFIXED b1,SFIXED b2) -{ S64 a; - a = (S64)a1*(S64)b1+(S64)a2*(S64)b2; - return (SFIXED)(a>>16); -} -SFIXED QFIX(int zaehler,int nenner) // bildet Quotient von zwei INTs in SFIXED -{ S64 z = zaehler<<16; - S64 a = z/(S64)nenner; - return (SFIXED)a; -} -#undef S64 - -LPMATRIX MatrixJoin(LPMATRIX d,LPMATRIX s1,LPMATRIX s2) -{ - if (!d) return NULL; - if (!s1) return (s2)?(LPMATRIX)memcpy(d,s2,sizeof(MATRIX)):NULL; - if (!s2) return (LPMATRIX)memcpy(d,s1,sizeof(MATRIX)); - - d->tx = s1->tx + s2->tx; - d->ty = s1->ty + s2->ty; - - d->sx = SP(s1->sx,s1->r1,s2->sx,s2->r0); - d->sy = SP(s1->r0,s1->sy,s2->r1,s2->sy); - d->r0 = SP(s1->r0,s1->sy,s2->sx,s2->r0); - d->r1 = SP(s1->sx,s1->r1,s2->r1,s2->sy); - - //DumpMatrix(NULL,d); - - return d; -} - -LPMATRIX MatrixMapTriangle(LPMATRIX m,int dx,int dy,int x0,int y0, - int x1,int y1,int x2,int y2) -{ int dx1 = x1 - x0; - int dy1 = y1 - y0; - int dx2 = x2 - x0; - int dy2 = y2 - y0; - - if (!m) return NULL; - if ((!dx)||(!dy)) return NULL; // check DIV by zero - - m->tx = x0; - m->ty = y0; - m->sx = QFIX(dx1,dx); - m->sy = QFIX(dy2,dy); - m->r0 = QFIX(dy1,dx); - m->r1 = QFIX(dx2,dy); - - return m; -} - int main (int argc,char ** argv) { SWF swf; LPTAG t; @@ -142,183 +27,95 @@ int main (int argc,char ** argv) SRECT r; LPSHAPE s; S32 width = 800,height = 800; - U8 gbits,abits; int fs,ls; // line & fillstyle - LPSWFFONT font; - FONTUSAGE use; LPJPEGBITS jpeg; MATRIX m; int f,i,j,frame; - f = open("Arial.efont",O_RDONLY); - if (f>=0) - { if (FAILED(FontImport(f,&font))) - { fprintf(stderr,"Font import failed\n"); - close(f); - return -1; - } - } - else - { fprintf(stderr,"Font not found\n"); - return -1; - } - close(f); - - FontSetID(font,ID_FONT); - FontInitUsage(&use); - FontUse(&use,BANNER_TEXT); - FontReduce(font,&use); - - calcTables(); - memset(&swf,0x00,sizeof(SWF)); - swf.FileVersion = 4; - swf.FrameRate = 0x4000; - swf.MovieSize.xmax = 4*width; - swf.MovieSize.ymax = 4*height; + swf.fileVersion = 4; + swf.frameRate = 0x4000; + swf.movieSize.xmax = 4*width; + swf.movieSize.ymax = 4*height; - swf.FirstTag = InsertTag(NULL,ST_SETBACKGROUNDCOLOR); - t = swf.FirstTag; + swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR); + t = swf.firstTag; rgb.r = 0xff; rgb.g = 0xff; rgb.b = 0xff; - SetRGB(t,&rgb); + swf_SetRGB(t,&rgb); - t = InsertTag(t,ST_DEFINEFONT); + t = swf_InsertTag(t,ST_DEFINEBITSJPEG2); - FontSetDefine(t,font); - - t = InsertTag(t,ST_DEFINEFONTINFO); - - FontSetInfo(t,font); - - t = InsertTag(t,ST_DEFINETEXT); - - SetU16(t,ID_BANNER); // ID - - r.xmin = 0; - r.ymin = 0; - r.xmax = 400; - r.ymax = 400; - SetRect(t,&r); - - SetMatrix(t,NULL); - - TextCountBits(font,BANNER_TEXT,80,&gbits,&abits); - - SetU8(t,gbits); - SetU8(t,abits); - - rgb.r = 0xc0; - rgb.g = 0xc0; - rgb.b = 0xc0; - - TextSetInfoRecord(t,font,height/4,&rgb,0,200); - TextSetCharRecord(t,font,BANNER_TEXT,80,gbits,abits); - - SetU8(t,0); - - t = InsertTag(t,ST_DEFINETEXT); - - SetU16(t,ID_HIGHLIGHT); // ID - - r.xmin = 0; - r.ymin = 0; - r.xmax = 800; - r.ymax = 400; - SetRect(t,&r); - - SetMatrix(t,NULL); - - TextCountBits(font,BANNER_TEXT,80,&gbits,&abits); - - SetU8(t,gbits); - SetU8(t,abits); - - rgb.r = 0x20; - rgb.g = 0x20; - rgb.b = 0x20; - - TextSetInfoRecord(t,font,height/4,&rgb,0,200); - TextSetCharRecord(t,font,BANNER_TEXT,80,gbits,abits); - - SetU8(t,0); - - t = InsertTag(t,ST_DEFINEBUTTON); - - GetMatrix(NULL,&m); - - m.tx = 3*width; - m.ty = 7*height/2; - - SetU16(t,ID_BUTTON); // ID - ButtonSetRecord(t,BS_UP,ID_BANNER,1,&m,NULL); - ButtonSetRecord(t,BS_DOWN|BS_HIT|BS_OVER,ID_HIGHLIGHT,1,&m,NULL); - SetU8(t,0); // End of Button Records - SetU8(t,0); // End of Action Records - - - t = InsertTag(t,ST_PLACEOBJECT2); - - ObjectPlace(t,ID_BUTTON,1,NULL,NULL,NULL); - - t = InsertTag(t,ST_DEFINEBITSJPEG2); - - SetU16(t,ID_BITMAP); - SetJPEGBits(t,"eye.jpg",QUALITY); + swf_SetU16(t,ID_BITMAP); + + if (FAILED(swf_SetJPEGBits(t,"texture.jpg",QUALITY))) + { fprintf(stderr,"Error: texture.jpg (256x256) not found in work directory.\n"); + exit(1); + } - t = InsertTag(t,ST_DEFINESHAPE); + t = swf_InsertTag(t,ST_DEFINESHAPE); - NewShape(&s); + swf_ShapeNew(&s); rgb.b = rgb.g = rgb.r = 0x00; - // ls = ShapeAddLineStyle(s,40,&rgb); ls = 0; rgb.b = 0xff; - fs = ShapeAddBitmapFillStyle(s,&m,ID_BITMAP,0); + fs = swf_ShapeAddBitmapFillStyle(s,NULL,ID_BITMAP,0); - SetU16(t,ID_SHAPE); // ID + swf_SetU16(t,ID_SHAPE); // ID r.xmin = 0; r.ymin = 0; r.xmax = 2*width; r.ymax = 2*height; - SetRect(t,&r); + swf_SetRect(t,&r); - SetShapeHeader(t,s); + swf_SetShapeHeader(t,s); - ShapeSetAll(t,s,0,0,ls,fs,0); - ShapeSetLine(t,s,width,0); - ShapeSetLine(t,s,-width,height); - ShapeSetLine(t,s,0,-height); - ShapeSetEnd(t); + swf_ShapeSetAll(t,s,0,0,ls,fs,0); + swf_ShapeSetLine(t,s,width,0); + swf_ShapeSetLine(t,s,-width,height); + swf_ShapeSetLine(t,s,0,-height); + swf_ShapeSetEnd(t); - ShapeFree(s); + swf_ShapeFree(s); - for (frame=0;frame<64;frame++) - { /*MATRIX m1,m2; + { + + /* Test procedure for swf_MatrixJoin + + MATRIX m1,m2; + + // set m1 to left rotation m1.sy = m1.sx = (int)(cos(((float)(frame))/32*3.141)*0x10000); m1.r0 = (int)(sin(((float)(frame))/32*3.141)*0x10000); m1.r1 = -m1.r0; m1.tx = width+frame*4; m1.ty = height; + // set m2 to right rotation + m2.sy = m2.sx = (int)(cos(((float)(64-frame))/32*3.141)*0x10000); m2.r0 = (int)(sin(((float)(64-frame))/32*3.141)*0x10000); m2.r1 = -m2.r0; m2.tx = width; m2.ty = height; - MatrixJoin(&m,&m1,&m2); */ + // joining m1 and m2 should lead to no transformation + + swf_MatrixJoin(&m,&m1,&m2); - int dx0 = width; // Konstanten der Shapes + */ + + int dx0 = width; // constants of shape int dy0 = width; - int px0 = 2*width; // Zielpunkte des Mappings + int px0 = 2*width; // destination of mapping int py0 = 2*width; int px1 = 3*width; @@ -327,23 +124,33 @@ int main (int argc,char ** argv) int px2 = 2*width-frame*8; int py2 = 3*width; - MatrixMapTriangle(&m,dx0,dy0,px0,py0,px1,py1,px2,py2); + swf_MatrixMapTriangle(&m,dx0,dy0,px0,py0,px1,py1,px2,py2); - t = InsertTag(t,ST_PLACEOBJECT2); + t = swf_InsertTag(t,ST_PLACEOBJECT2); if (!frame) - ObjectPlace(t,ID_SHAPE,1,&m,NULL,NULL); + swf_ObjectPlace(t,ID_SHAPE,1,&m,NULL,NULL); else - ObjectMove(t,1,&m,NULL); + swf_ObjectMove(t,1,&m,NULL); - t = InsertTag(t,ST_SHOWFRAME); + t = swf_InsertTag(t,ST_SHOWFRAME); } - t = InsertTag(t,ST_END); + t = swf_InsertTag(t,ST_END); + +// swf_WriteCGI(&swf); + + f = open("transtest.swf",O_RDWR|O_CREAT|O_TRUNC,0644); + if FAILED(swf_WriteSWF(f,&swf)) fprintf(stderr,"WriteSWF() failed.\n"); + close(f); + + swf_FreeTags(&swf); + +#ifdef __NT__ + system("start ..\\transtest.swf"); +#endif - WriteCGI(&swf); - FreeTags(&swf); return 0; } diff --git a/lib/example/zlibtest.c b/lib/example/zlibtest.c index 4608b6a..05126f2 100644 --- a/lib/example/zlibtest.c +++ b/lib/example/zlibtest.c @@ -1,190 +1,197 @@ -/* zlibtest.c - - Little example for rfxswf's lossless bitmap functions. - This program gives swf cgi output of three zlib compressed - images: 8 bit indexed, 16 and 32 bit - - Part of the swftools package. - - Copyright (c) 2001 Rainer Böhme - - This file is distributed under the GPL, see file COPYING for details - -*/ - -// There's no makefile so try to compile like this on linux/gcc: -// cc zlibtest.c ../rfxswf.c -funsigned-char -o zlibtest -lm -ljpeg -lz; cp zlibtest /home/www/cgi-bin/zlibtest - -#include -#include -#include -#include "../rfxswf.h" - -#define WIDTH 256 -#define HEIGHT 256 - -#define ID_BITS 1 -#define ID_SHAPE 16 - - -int main ( int argc, char ** argv) -{ SWF swf; - LPTAG t; - RGBA rgb; - LPSHAPE s; - MATRIX m; - SRECT r; - LPJPEGBITS jpeg; - int i; - - int ls; // line style - int fs; // fill style - - int dx = 256; // bitmap size - int dy = 256; - int bps8, bps16, bps32; // bytes per scanline - - U8 * bitmap8; - U16 * bitmap16; - RGBA * bitmap32; - RGBA * pal; - - // create test texture - - bps8 = BYTES_PER_SCANLINE(dx*sizeof(U8)); - bps16 = BYTES_PER_SCANLINE(dx*sizeof(U16)); - bps32 = BYTES_PER_SCANLINE(dx*sizeof(U32)); - - pal = malloc(256*sizeof(RGBA)); - - bitmap8 = malloc(bps8*dy); - bitmap16 = malloc(bps16*dy); - bitmap32 = malloc(bps32*dy); - - if ((bitmap8) && (pal) && (bitmap16)) - { int x,y; - for (y=0;y>1)+x] = ((x&0xf0)==(y&0xf0))?0xffff:(x&0x0f)<(y&0xf)?BM16_RED|BM16_GREEN:BM16_BLUE; - - for (y=0;y>2)+x].r = /*((x&0x10)==(y&0x10))?*/((x&4)==(y&4))?y:x; - bitmap32[y*(bps32>>2)+x].g = x; - bitmap32[y*(bps32>>2)+x].b = y; - } - - } - - // put texture into flash movie - - memset(&swf,0x00,sizeof(SWF)); - - swf.FileVersion = 4; - swf.FrameRate = 0x1800; - swf.MovieSize.xmax = 20*WIDTH; - swf.MovieSize.ymax = 20*HEIGHT; - - swf.FirstTag = InsertTag(NULL,ST_SETBACKGROUNDCOLOR); - t = swf.FirstTag; - - rgb.r = 0xff; - rgb.b = 0xff; - rgb.g = 0xff; - SetRGB(t,&rgb); - - t = InsertTag(t,ST_DEFINEBITSLOSSLESS); - - SetU16(t,ID_BITS); - SetLosslessBits(t,dx,dy,bitmap32,BMF_32BIT); - - t = InsertTag(t,ST_DEFINEBITSLOSSLESS2); - - /* be careful with ST_DEFINEBITSLOSSLESS2, because - the Flash player produces great bugs if you use too many - alpha colors in your palette. The only sensible result that - can be archeived is setting one color to r=0,b=0,g=0,a=0 to - make transparent parts in sprites. That's the cause why alpha - handling is implemented in lossless routines of rfxswf. - */ - - SetU16(t,ID_BITS+1); - SetLosslessBitsIndexed(t,dx,dy,bitmap8,pal,256); - - t = InsertTag(t,ST_DEFINEBITSLOSSLESS); - - SetU16(t,ID_BITS+2); - SetLosslessBits(t,dx,dy,bitmap16,BMF_16BIT); - - /* By the way: ST_DEFINELOSSLESS2 produces stange output on - 16 and 32 bits image data, too.... it seems that the - ming developers deal with the same problem. - */ - - for (i=0;i<9;i++) - { - t = InsertTag(t,ST_DEFINESHAPE); - - NewShape(&s); - rgb.b = rgb.g = rgb.r = 0x00; - ls = ShapeAddLineStyle(s,10,&rgb); - - GetMatrix(NULL,&m); - m.sx = (6*WIDTH/dx)<<16; - m.sy = (6*HEIGHT/dy)<<16; - - fs = ShapeAddBitmapFillStyle(s,&m,ID_BITS+((i+(i/3))%3),0); - - SetU16(t,ID_SHAPE+i); // ID - - r.xmin = 0; - r.ymin = 0; - r.xmax = 6*WIDTH; - r.ymax = 6*HEIGHT; - - SetRect(t,&r); - - SetShapeStyles(t,s); - ShapeCountBits(s,NULL,NULL); - SetShapeBits(t,s); - - ShapeSetAll(t,s,0,0,ls,fs,0); - - ShapeSetLine(t,s,6*WIDTH,0); - ShapeSetLine(t,s,0,6*HEIGHT); - ShapeSetLine(t,s,-6*WIDTH,0); - ShapeSetLine(t,s,0,-6*HEIGHT); - ShapeSetEnd(t); - - GetMatrix(NULL,&m); - m.tx = (i%3) * (6*WIDTH+60); - m.ty = (i/3) * (6*HEIGHT+60); - - t = InsertTag(t,ST_PLACEOBJECT2); - ObjectPlace(t,ID_SHAPE+i,1+i,&m,NULL,NULL); - } - - t = InsertTag(t,ST_SHOWFRAME); - - t = InsertTag(t,ST_END); - - WriteCGI(&swf); - FreeTags(&swf); - - free(pal); - free(bitmap8); - free(bitmap16); - free(bitmap32); - return 0; -} +/* zlibtest.c + + Little example for rfxswf's lossless bitmap functions. + This program creates a swf with three zlib compressed + images: 8 bit indexed, 16 and 32 bit + + Part of the swftools package. + + Copyright (c) 2001 Rainer Böhme + + This file is distributed under the GPL, see file COPYING for details + +*/ + +#include +#include +#include +#include +#include "../rfxswf.h" + +#define WIDTH 256 +#define HEIGHT 256 + +#define ID_BITS 1 +#define ID_SHAPE 16 + + +int main ( int argc, char ** argv) +{ SWF swf; + LPTAG t; + RGBA rgb; + LPSHAPE s; + MATRIX m; + SRECT r; + LPJPEGBITS jpeg; + int i,f; + + int ls; // line style + int fs; // fill style + + int dx = 256; // bitmap size + int dy = 256; + int bps8, bps16, bps32; // bytes per scanline + + U8 * bitmap8; + U16 * bitmap16; + RGBA * bitmap32; + RGBA * pal; + + // create test texture + + bps8 = BYTES_PER_SCANLINE(dx*sizeof(U8)); + bps16 = BYTES_PER_SCANLINE(dx*sizeof(U16)); + bps32 = BYTES_PER_SCANLINE(dx*sizeof(U32)); + + pal = malloc(256*sizeof(RGBA)); + + bitmap8 = malloc(bps8*dy); + bitmap16 = malloc(bps16*dy); + bitmap32 = malloc(bps32*dy); + + if ((bitmap8) && (pal) && (bitmap16)) + { int x,y; + for (y=0;y>1)+x] = ((x&0xf0)==(y&0xf0))?0xffff:(x&0x0f)<(y&0xf)?BM16_RED|BM16_GREEN:BM16_BLUE; + + for (y=0;y>2)+x].r = /*((x&0x10)==(y&0x10))?*/((x&4)==(y&4))?y:x; + bitmap32[y*(bps32>>2)+x].g = x; + bitmap32[y*(bps32>>2)+x].b = y; + } + + } + + // put texture into flash movie + + memset(&swf,0x00,sizeof(SWF)); + + swf.fileVersion = 4; + swf.frameRate = 0x1800; + swf.movieSize.xmax = 20*WIDTH; + swf.movieSize.ymax = 20*HEIGHT; + + swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR); + t = swf.firstTag; + + rgb.r = 0xff; + rgb.b = 0xff; + rgb.g = 0xff; + swf_SetRGB(t,&rgb); + + t = swf_InsertTag(t,ST_DEFINEBITSLOSSLESS); + + swf_SetU16(t,ID_BITS); + swf_SetLosslessBits(t,dx,dy,bitmap32,BMF_32BIT); + + t = swf_InsertTag(t,ST_DEFINEBITSLOSSLESS2); + + /* be careful with ST_DEFINEBITSLOSSLESS2, because + the Flash player produces great bugs if you use too many + alpha colors in your palette. The only sensible result that + can be archeived is setting one color to r=0,b=0,g=0,a=0 to + make transparent parts in sprites. That's the cause why alpha + handling is implemented in lossless routines of rfxswf. + */ + + swf_SetU16(t,ID_BITS+1); + swf_SetLosslessBitsIndexed(t,dx,dy,bitmap8,pal,256); + + t = swf_InsertTag(t,ST_DEFINEBITSLOSSLESS); + + swf_SetU16(t,ID_BITS+2); + swf_SetLosslessBits(t,dx,dy,bitmap16,BMF_16BIT); + + /* By the way: ST_DEFINELOSSLESS2 produces stange output on + 16 and 32 bits image data, too.... it seems that the + ming developers deal with the same problem. + */ + + for (i=0;i<9;i++) + { + t = swf_InsertTag(t,ST_DEFINESHAPE); + + swf_ShapeNew(&s); + rgb.b = rgb.g = rgb.r = 0x00; + ls = swf_ShapeAddLineStyle(s,10,&rgb); + + swf_GetMatrix(NULL,&m); + m.sx = (6*WIDTH/dx)<<16; + m.sy = (6*HEIGHT/dy)<<16; + + fs = swf_ShapeAddBitmapFillStyle(s,&m,ID_BITS+((i+(i/3))%3),0); + + swf_SetU16(t,ID_SHAPE+i); // ID + + r.xmin = 0; + r.ymin = 0; + r.xmax = 6*WIDTH; + r.ymax = 6*HEIGHT; + + swf_SetRect(t,&r); + + swf_SetShapeStyles(t,s); + swf_ShapeCountBits(s,NULL,NULL); + swf_SetShapeBits(t,s); + + swf_ShapeSetAll(t,s,0,0,ls,fs,0); + + swf_ShapeSetLine(t,s,6*WIDTH,0); + swf_ShapeSetLine(t,s,0,6*HEIGHT); + swf_ShapeSetLine(t,s,-6*WIDTH,0); + swf_ShapeSetLine(t,s,0,-6*HEIGHT); + swf_ShapeSetEnd(t); + + swf_GetMatrix(NULL,&m); + m.tx = (i%3) * (6*WIDTH+60); + m.ty = (i/3) * (6*HEIGHT+60); + + t = swf_InsertTag(t,ST_PLACEOBJECT2); + swf_ObjectPlace(t,ID_SHAPE+i,1+i,&m,NULL,NULL); + } + + t = swf_InsertTag(t,ST_SHOWFRAME); + + t = swf_InsertTag(t,ST_END); + +// swf_WriteCGI(&swf); + + f = open("zlibtest.swf",O_RDWR|O_CREAT|O_TRUNC,0644); + if FAILED(swf_WriteSWF(f,&swf)) fprintf(stderr,"WriteSWF() failed.\n"); + close(f); + + swf_FreeTags(&swf); + +#ifdef __NT__ + system("start ..\\zlibtest.swf"); +#endif + + free(pal); + free(bitmap8); + free(bitmap16); + free(bitmap32); + return 0; +} -- 1.7.10.4