* updated examples to new rfxswf name conventions
authorboehme <boehme>
Wed, 31 Oct 2001 15:03:57 +0000 (15:03 +0000)
committerboehme <boehme>
Wed, 31 Oct 2001 15:03:57 +0000 (15:03 +0000)
* added Makefile for all examples
* cleaned up examples: added some comments and removed deprecated stuff

lib/example/Makefile [new file with mode: 0644]
lib/example/README [deleted file]
lib/example/box.c
lib/example/jpegtest.c
lib/example/shape1.c
lib/example/texbox_ac.c [deleted file]
lib/example/transtest.c
lib/example/zlibtest.c

diff --git a/lib/example/Makefile b/lib/example/Makefile
new file mode 100644 (file)
index 0000000..e79ad35
--- /dev/null
@@ -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 (file)
index 09b8b15..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-These example may not compile because of recent major changes in rfxswf. 
-We will fix them soon.
index 5b10d4b..f4f3e72 100644 (file)
@@ -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 <rfxswf@reflex-studio.de>
+   This file is distributed under the GPL, see file COPYING for details 
+
+*/
 
 #include <stdio.h>
 #include <fcntl.h>
 #include <math.h>
 #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;
index 76eb1ea..5679ac7 100644 (file)
@@ -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 <rfxswf@reflex-studio.de>
+   This file is distributed under the GPL, see file COPYING for details 
+
+*/
 
 #include <stdio.h>
-#include <math.h>      
+#include <fcntl.h>
+#include <math.h>       
 #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<HEIGHT;y++)
       { U8 scanline[3*WIDTH];
@@ -54,71 +69,80 @@ int main ( int argc, char ** argv)
           scanline[p++] = y;    // G
           scanline[p++] = 0x80; // B          
         }
-        SetJPEGBitsLine(jpeg,scanline);
+        swf_SetJPEGBitsLine(jpeg,scanline);
       }
     }
-    SetJPEGBitsFinish(jpeg);
-*/
+    swf_SetJPEGBitsFinish(jpeg);
+
+// do some rotation animation
 
-for (frame=0;frame<64;frame++)
-{
-  t = InsertTag(t,ST_DEFINESHAPE);
+    for (frame=0;frame<64;frame++)
+    {
+      t = swf_InsertTag(t,ST_DEFINESHAPE);
     
-    NewShape(&s);
-    rgb.b = rgb.g = rgb.r = 0x00;
-    ls = ShapeAddLineStyle(s,40,&rgb); 
-    rgb.b = 0xff;
-  //  fs = ShapeAddSolidFillStyle(s,&rgb);
-    //  
-    GetMatrix(NULL,&m);
-    m.sy = m.sx = (int)(cos(((float)(frame))/32*3.141)*0x80000);
-    m.r0 = (int)(sin(((float)(frame))/32*3.141)*0x80000);
-    m.r1 = -m.r0;
+          swf_ShapeNew(&s);
+          
+          rgb.b = rgb.g = rgb.r = 0x00;
+          ls = swf_ShapeAddLineStyle(s,40,&rgb);
+          
+          swf_GetMatrix(NULL,&m);
+          
+          m.sy = m.sx = (int)(cos(((float)(frame))/32*3.141)*0x80000);
+          m.r0 = (int)(sin(((float)(frame))/32*3.141)*0x80000);
+          m.r1 = -m.r0;
        
-    fs = ShapeAddBitmapFillStyle(s,&m,ID_BITS,0);
+          fs = swf_ShapeAddBitmapFillStyle(s,&m,ID_BITS,0);
     
-    SetU16(t,ID_SHAPE+frame);  // ID   
+          swf_SetU16(t,ID_SHAPE+frame);   // ID   
+
+          r.xmin = 0;
+          r.ymin = 0;
+          r.xmax = 10*WIDTH;
+          r.ymax = 10*HEIGHT;
 
-    r.xmin = 0;
-    r.ymin = 0;
-    r.xmax = 10*WIDTH;
-    r.ymax = 10*HEIGHT;
+          swf_SetRect(t,&r);
 
-    SetRect(t,&r);
+          swf_SetShapeHeader(t,s);
 
-    SetShapeStyles(t,s);
-    ShapeCountBits(s,NULL,NULL);
-    SetShapeBits(t,s);
+          swf_ShapeSetAll(t,s,0,0,ls,fs,0);
 
-    ShapeSetAll(t,s,0,0,ls,fs,0);
+          swf_ShapeSetLine(t,s,10*WIDTH,0);
+          swf_ShapeSetLine(t,s,-10*WIDTH,10*HEIGHT);
+//    swf_ShapeSetLine(t,s,-10*WIDTH,-10*WIDTH);
+          swf_ShapeSetLine(t,s,0,-10*HEIGHT);
+          swf_ShapeSetEnd(t);
 
-    ShapeSetLine(t,s,10*WIDTH,0);
-    ShapeSetLine(t,s,-10*WIDTH,10*HEIGHT);
-//    ShapeSetLine(t,s,-10*WIDTH,-10*WIDTH);
-    ShapeSetLine(t,s,0,-10*HEIGHT);
-    ShapeSetEnd(t);
+          swf_ShapeFree(s);
 
-  if (frame) 
-  { t = InsertTag(t,ST_REMOVEOBJECT2); SetU16(t,1);
-    t = InsertTag(t,ST_REMOVEOBJECT2); SetU16(t,2);
-  }
-        
-  t = InsertTag(t,ST_PLACEOBJECT2);
-    ObjectPlace(t,ID_SHAPE+frame,1,NULL,NULL,NULL); 
+      if (frame) 
+      { t = swf_InsertTag(t,ST_REMOVEOBJECT2); swf_SetU16(t,1);
+        t = swf_InsertTag(t,ST_REMOVEOBJECT2); swf_SetU16(t,2);
+      }
+         
+      t = swf_InsertTag(t,ST_PLACEOBJECT2);
+          swf_ObjectPlace(t,ID_SHAPE+frame,1,NULL,NULL,NULL); 
 
-  t = InsertTag(t,ST_PLACEOBJECT2);
-    GetMatrix(NULL,&m);
-    m.tx = m.ty = 10*WIDTH+frame*10;
-    m.sx = m.sy = 0xfffeffff;
-    ObjectPlace(t,ID_SHAPE+frame,2,&m,NULL,NULL);
+      t = swf_InsertTag(t,ST_PLACEOBJECT2);
+          swf_GetMatrix(NULL,&m); // get default matrix with no transformation
+          
+          m.tx = m.ty = 10*WIDTH+frame*10;
+          m.sx = m.sy = 0xfffeffff;
+          swf_ObjectPlace(t,ID_SHAPE+frame,2,&m,NULL,NULL);
 
 
-  t = InsertTag(t,ST_SHOWFRAME);
-}
+      t = swf_InsertTag(t,ST_SHOWFRAME);
+      
+    } // frame loop
 
-  t = InsertTag(t,ST_END);
+  t = swf_InsertTag(t,ST_END);
 
-  WriteCGI(&swf);
-  FreeTags(&swf);
+//  swf_WriteCGI(&swf);
+
+  f = open("jpegtest.swf",O_WRONLY|O_CREAT, 0644);
+  if FAILED(swf_WriteSWF(f,&swf)) fprintf(stderr,"WriteSWF() failed.\n");
+  close(f);
+  
+  swf_FreeTags(&swf); // cleanup
+  
   return 0;
 }
index 5a7da4e..e845ae9 100644 (file)
@@ -1,3 +1,15 @@
+/* shape1.c
+
+   Example implementation for drawing a shape with rfxswf
+   
+   Part of the swftools package.
+
+   Copyright (c) 2000, 2001 Rainer Böhme <rfxswf@reflex-studio.de>
+   This file is distributed under the GPL, see file COPYING for details 
+
+*/
+
 #include <stdio.h>
 #include <fcntl.h>
 #include <math.h>
@@ -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 (file)
index c94ec36..0000000
+++ /dev/null
@@ -1,374 +0,0 @@
-\r
-// linux/gcc: cc texbox_ac.c ../rfxswf.c -funsigned-char -o texbox -lmingac -lm -ljpeg; cp texbox /home/www/cgi-bin/texbox\r
-\r
-#include <stdio.h>\r
-#include <fcntl.h>\r
-#include <math.h>\r
-#include "../rfxswf.h"\r
-#include "../mingac.h"  // Action Compiler of MING library\r
-\r
-// Box\r
-\r
-#define BANNER_TEXT     "reflex"\r
-#define QUALITY 80\r
-#define ID_FONT         2000\r
-#define ID_BANNER       2001\r
-#define ID_HIGHLIGHT    2002\r
-#define ID_BUTTON       2003\r
-#define ID_BITMAP       2004\r
-#define ID_SHAPE        2005\r
-#define ID_SHAPE2       2006\r
-\r
-#define a 200\r
-int sX[] = { a,-a, a,-a, a,-a, a,-a};\r
-int sY[] = { a, a,-a,-a, a, a,-a,-a};\r
-int sZ[] = { a, a, a, a,-a,-a,-a,-a};\r
-#undef a\r
-\r
-#define PRECISION 16\r
-\r
-int SHADE = 1;\r
-\r
-int dX[8];\r
-int dY[8];\r
-int square_visible[6]  = {0,0,0,0,0,0};\r
-int square_depth[6][2] = {{2,3},{4,5},{6,7},{8,9},{10,11},{12,13}};\r
-int square_light[6]    = {0,0,64,64,-64,-64};\r
-\r
-int sin_[512],cos_[512];\r
-\r
-void calcTables()       \r
-{ int i;\r
-  double d;\r
-  for (i=0;i<512;i++)\r
-  { d = ((double)i)/128*3.14159;\r
-    sin_[i] = (int)(sin(d)*(1<<PRECISION));\r
-    cos_[i] = (int)(cos(d)*(1<<PRECISION));\r
-  }\r
-}\r
-\r
-LPTAG MapSquare(LPTAG t,int dx0,int dy0,int p1,int p2,int p3,int p4,int dx,int dy,int square)\r
-{ MATRIX m;\r
-  CXFORM cx;\r
-\r
-  if (SHADE)\r
-  { GetCXForm(NULL,&cx,1);\r
-    cx.r1 = cx.b1 = cx.g1 = square_light[square];\r
-  }\r
-        \r
-  if (((dX[p2]-dX[p1])*(dY[p3]-dY[p1])-(dX[p3]-dX[p1])*(dY[p2]-dY[p1]))<0) \r
-  { if (square_visible[square])\r
-    { t = InsertTag(t,ST_REMOVEOBJECT2); SetU16(t,square_depth[square][0]);\r
-      t = InsertTag(t,ST_REMOVEOBJECT2); SetU16(t,square_depth[square][1]);\r
-    }\r
-    square_visible[square] = 0;\r
-    return t; \r
-  }\r
-\r
-  t = InsertTag(t,ST_PLACEOBJECT2);\r
-  \r
-  MatrixMapTriangle(&m,dx0,dy0,dX[p1]+dx,dY[p1]+dy,\r
-                        dX[p2]+dx,dY[p2]+dy,\r
-                 dX[p4]+dx,dY[p4]+dy);\r
-\r
-  if (!square_visible[square])\r
-    ObjectPlace(t,ID_SHAPE,square_depth[square][0],&m,SHADE?&cx:NULL,NULL);\r
-  else\r
-    ObjectMove(t,square_depth[square][0],&m,SHADE?&cx:NULL);\r
-\r
-  t = InsertTag(t,ST_PLACEOBJECT2);\r
-  \r
-  MatrixMapTriangle(&m,dx0,dy0,dX[p3]+dx,dY[p3]+dy,\r
-                        dX[p4]+dx,dY[p4]+dy,\r
-                 dX[p2]+dx,dY[p2]+dy);\r
-\r
-  if (!square_visible[square])\r
-    ObjectPlace(t,ID_SHAPE2,square_depth[square][1],&m,SHADE?&cx:NULL,NULL);\r
-  else\r
-    ObjectMove(t,square_depth[square][1],&m,SHADE?&cx:NULL);\r
-\r
-  square_visible[square] = 1;\r
\r
-  return t;\r
-}\r
-\r
-void mapBox(int xw,int yw,int zw)\r
-{ int i;\r
-  int x1,y1,z1,x2,y2,z2,x3,y3,z3;\r
-  int y,x,z;\r
-  \r
-  xw &= 255;\r
-  yw &= 255;\r
-  zw &= 255;\r
-\r
-  for (i=0;i<8;i++)\r
-  { x = sX[i];\r
-    y = sY[i];\r
-    z = sZ[i];\r
-                  \r
-    y1 = ( y*cos_[xw]- z*sin_[xw])>>PRECISION;\r
-    z1 = ( y*sin_[xw]+ z*cos_[xw])>>PRECISION;\r
-    x1 = x;\r
-\r
-    x2 = (x1*cos_[yw]+z1*sin_[yw])>>PRECISION;\r
-    y2 = y1;\r
-\r
-    x3 = (x2*cos_[zw]-y2*sin_[zw])>>PRECISION;\r
-    y3 = (x2*sin_[zw]+y2*cos_[zw])>>PRECISION;\r
-    z3 = (z1*cos_[yw]-x1*sin_[yw])>>PRECISION;\r
-\r
-    dX[i] = x3*4000/(z3+950);\r
-    dY[i] = y3*4000/(z3+950);\r
-        \r
-  }\r
-}\r
-\r
-void mapLights(int xw,int yw,int zw)\r
-{ int i;\r
-  int x1,y1,z1,x2,y2,z2,x3,y3,z3;\r
-\r
-  int y[] = {0,0,0,0,256,-256};\r
-  int x[] = {0,0,256,-256,0,0};\r
-  int z[] = {256,-256,0,0,0,0};\r
-\r
-  int lz = 256; // lightvector\r
-  int lx = 200, ly = 200;\r
-\r
-  for (i=0;i<6;i++)\r
-  { y1 = (y[i]*cos_[xw]-z[i]*sin_[xw])>>PRECISION;\r
-    z1 = (y[i]*sin_[xw]+z[i]*cos_[xw])>>PRECISION;\r
-    x1 = x[i];\r
-\r
-    x2 = (x1*cos_[yw]+z1*sin_[yw])>>PRECISION;\r
-    y2 = y1;\r
-    z2 = (z1*cos_[yw]-x1*sin_[yw])>>PRECISION;\r
-\r
-    x3 = (x2*cos_[zw]-y2*sin_[zw])>>PRECISION;\r
-    y3 = (x2*sin_[zw]+y2*cos_[zw])>>PRECISION;\r
-    z3 = z2;\r
-\r
-    square_light[i] = -128-((x3*lx + y3*ly + z3*lz)>>9);\r
-  }\r
-}\r
-\r
-\r
-int main (int argc,char ** argv)\r
-{ SWF swf;\r
-  LPTAG t;\r
-  RGBA rgb;\r
-  SRECT r;\r
-  LPSHAPE s;\r
-  S32 width = 800,height = 800;\r
-  U8 gbits,abits;\r
-  int fs,ls; // line & fillstyle\r
-  LPSWFFONT font;\r
-  FONTUSAGE use;\r
-  LPJPEGBITS jpeg;\r
-  MATRIX m;  \r
-  \r
-  int f,i,j,frame;\r
-  \r
-  InitCompiler(AC_DEFAULT);\r
-  \r
-  f = open("Arial.efont",O_RDONLY);\r
-  if (f>=0)\r
-  { if (FAILED(FontImport(f,&font)))\r
-    { fprintf(stderr,"Font import failed\n");\r
-      close(f);\r
-      return -1;\r
-    }\r
-  }\r
-  else\r
-  { fprintf(stderr,"Font not found\n");\r
-    return -1;\r
-  }\r
-  close(f);\r
-\r
-  FontSetID(font,ID_FONT);\r
-  FontInitUsage(&use);\r
-  FontUse(&use,BANNER_TEXT);\r
-  FontReduce(font,&use);\r
-  \r
-  calcTables();\r
-  \r
-  memset(&swf,0x00,sizeof(SWF));\r
-\r
-  swf.FileVersion    = 4;\r
-  swf.FrameRate      = 0x4000;\r
-  swf.MovieSize.xmax = 4*width;\r
-  swf.MovieSize.ymax = 4*height;\r
-\r
-  swf.FirstTag = InsertTag(NULL,ST_SETBACKGROUNDCOLOR);\r
-  t = swf.FirstTag;\r
-\r
-        rgb.r = 0xff;\r
-        rgb.g = 0xff;\r
-        rgb.b = 0xff;\r
-        SetRGB(t,&rgb);\r
-\r
-  t = InsertTag(t,ST_DEFINEFONT);\r
-\r
-        FontSetDefine(t,font);\r
-\r
-  t = InsertTag(t,ST_DEFINEFONTINFO);\r
-\r
-        FontSetInfo(t,font);\r
-\r
-  t = InsertTag(t,ST_DEFINETEXT);\r
-\r
-        SetU16(t,ID_BANNER);            // ID\r
-        \r
-        r.xmin = 0;\r
-        r.ymin = 0;\r
-        r.xmax = 400;\r
-        r.ymax = 400;\r
-        SetRect(t,&r);\r
-\r
-        SetMatrix(t,NULL);\r
-\r
-        TextCountBits(font,BANNER_TEXT,80,&gbits,&abits);\r
-        \r
-        SetU8(t,gbits);\r
-        SetU8(t,abits);\r
-\r
-        rgb.r = 0xc0;\r
-        rgb.g = 0xc0;\r
-        rgb.b = 0xc0;\r
-\r
-        TextSetInfoRecord(t,font,height/4,&rgb,0,200);\r
-        TextSetCharRecord(t,font,BANNER_TEXT,80,gbits,abits);\r
-\r
-        SetU8(t,0);\r
-        \r
-  t = InsertTag(t,ST_DEFINETEXT);\r
-\r
-        SetU16(t,ID_HIGHLIGHT);            // ID\r
-        \r
-        r.xmin = 0; r.ymin = 0; r.xmax = 800; r.ymax = 400;\r
-        SetRect(t,&r);\r
-\r
-        SetMatrix(t,NULL);\r
-        TextCountBits(font,BANNER_TEXT,80,&gbits,&abits);\r
-        \r
-        SetU8(t,gbits);\r
-        SetU8(t,abits);\r
-\r
-        rgb.r = 0x20;\r
-        rgb.g = 0x20;\r
-        rgb.b = 0x20;\r
-\r
-        TextSetInfoRecord(t,font,height/4,&rgb,0,200);\r
-        TextSetCharRecord(t,font,BANNER_TEXT,80,gbits,abits);\r
-\r
-        SetU8(t,0);\r
-        \r
-    t = InsertTag(t,ST_DEFINEBUTTON);\r
-    \r
-        GetMatrix(NULL,&m);\r
-        \r
-        m.tx = 3*width;\r
-        m.ty = 7*height/2;\r
-        \r
-        SetU16(t,ID_BUTTON); // ID\r
-        ButtonSetRecord(t,BS_UP,ID_BANNER,1,&m,NULL);\r
-        ButtonSetRecord(t,BS_DOWN|BS_HIT|BS_OVER,ID_HIGHLIGHT,1,&m,NULL);\r
-        SetU8(t,0); // End of Button Records\r
-        \r
-        ActionCompile(t,"if (status==1) { status = 0; stop();} else { status=1; play();}");\r
-    \r
-      \r
-    t = InsertTag(t,ST_PLACEOBJECT2);\r
-\r
-         ObjectPlace(t,ID_BUTTON,1,NULL,NULL,NULL);\r
-\r
-    t = InsertTag(t,ST_DEFINEBITSJPEG2);\r
-\r
-         SetU16(t,ID_BITMAP);\r
-         SetJPEGBits(t,"eye.jpg",QUALITY);\r
-         \r
-    t = InsertTag(t,ST_DEFINESHAPE);\r
-    \r
-         NewShape(&s);\r
-         rgb.b = rgb.g = rgb.r = 0x00;\r
-         ls = ShapeAddLineStyle(s,10,&rgb);     \r
-         rgb.b = 0xff;\r
-\r
-         m.tx = m.ty = 0;\r
-         m.r0 = m.r1 = 0;\r
-         m.sx = m.sy = width<<8;\r
-  \r
-         fs = ShapeAddBitmapFillStyle(s,&m,ID_BITMAP,0);\r
-    \r
-         SetU16(t,ID_SHAPE);    // ID   \r
-         \r
-         r.xmin = 0; r.ymin = 0;\r
-         r.xmax = 2*width; r.ymax = 2*height;\r
-         SetRect(t,&r);\r
-\r
-         SetShapeHeader(t,s);\r
-         ShapeSetAll(t,s,width,0,0,fs,0);\r
-         ShapeSetLine(t,s,-width,height);\r
-         ShapeSetStyle(t,s,ls,fs,0);\r
-         ShapeSetLine(t,s,0,-height);\r
-         ShapeSetLine(t,s,width,0);\r
-         ShapeSetEnd(t);\r
-\r
-         ShapeFree(s);\r
-         \r
-    t = InsertTag(t,ST_DEFINESHAPE);\r
-    \r
-         NewShape(&s);\r
-         rgb.b = rgb.g = rgb.r = 0x00;\r
-         ls = ShapeAddLineStyle(s,10,&rgb);     \r
-         rgb.b = 0xff;\r
-\r
-         m.tx = m.ty = 0;\r
-         m.r0 = m.r1 = 0;\r
-         m.sx = m.sy = -(width<<8);\r
-  \r
-         fs = ShapeAddBitmapFillStyle(s,&m,ID_BITMAP,0);\r
-    \r
-         SetU16(t,ID_SHAPE2);   // ID   \r
-         \r
-         r.xmin = 0; r.ymin = 0;\r
-         r.xmax = 2*width; r.ymax = 2*height;\r
-         SetRect(t,&r);\r
-\r
-         SetShapeHeader(t,s);\r
-         ShapeSetAll(t,s,width,0,0,fs,0);\r
-         ShapeSetLine(t,s,-width,height);\r
-         ShapeSetStyle(t,s,ls,fs,0);\r
-         ShapeSetLine(t,s,0,-height);\r
-         ShapeSetLine(t,s,width,0);\r
-         ShapeSetEnd(t);\r
-\r
-         ShapeFree(s);\r
-   \r
-  for (frame=0;frame<256;frame++)\r
-  { int dc = 3; // whitespace correction\r
-\r
-    mapBox(frame<<1,frame<<1,frame);\r
-    if (SHADE) mapLights(frame<<1,frame<<1,frame);\r
-    \r
-    t = MapSquare(t,width-dc,height-dc,0,2,3,1,2*width,2*height,0);\r
-    t = MapSquare(t,width-dc,height-dc,4,5,7,6,2*width,2*height,1);\r
-    t = MapSquare(t,width-dc,height-dc,0,4,6,2,2*width,2*height,2);\r
-    t = MapSquare(t,width-dc,height-dc,1,3,7,5,2*width,2*height,3);\r
-    t = MapSquare(t,width-dc,height-dc,0,1,5,4,2*width,2*height,4);\r
-    t = MapSquare(t,width-dc,height-dc,2,6,7,3,2*width,2*height,5);\r
-        \r
-    t = InsertTag(t,ST_SHOWFRAME);\r
-  }\r
-  /*\r
-    t = InsertTag(t,ST_DOACTION);\r
-\r
-      ActionCompile(t,"stop();");\r
-    */  \r
-    t = InsertTag(t,ST_END);\r
-  \r
-  WriteCGI(&swf);\r
-  FreeTags(&swf);\r
-  return 0;\r
-}\r
-\r
-\r
index 647a615..4746016 100644 (file)
+/* 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 <rfxswf@reflex-studio.de>
+   This file is distributed under the GPL, see file COPYING for details 
+
+*/
 
 #include <stdio.h>
 #include <fcntl.h>
 #include <math.h>
 #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;
 }
 
index 4608b6a..05126f2 100644 (file)
-/* zlibtest.c\r
-\r
-   Little example for rfxswf's lossless bitmap functions.\r
-   This program gives swf cgi output of three zlib compressed\r
-   images: 8 bit indexed, 16 and 32 bit\r
-\r
-   Part of the swftools package.\r
-\r
-   Copyright (c) 2001 Rainer Böhme <rfxswf@reflex-studio.de>\r
\r
-   This file is distributed under the GPL, see file COPYING for details \r
-\r
-*/\r
-\r
-// There's no makefile so try to compile like this on linux/gcc:\r
-// cc zlibtest.c ../rfxswf.c -funsigned-char -o zlibtest -lm -ljpeg -lz; cp zlibtest /home/www/cgi-bin/zlibtest\r
-\r
-#include <stdio.h>\r
-#include <math.h>\r
-#include <zlib.h>     \r
-#include "../rfxswf.h"\r
-\r
-#define WIDTH           256\r
-#define HEIGHT          256\r
-\r
-#define ID_BITS         1\r
-#define ID_SHAPE        16\r
-\r
-\r
-int main ( int argc, char ** argv)\r
-{ SWF swf;\r
-  LPTAG t;\r
-  RGBA rgb;\r
-  LPSHAPE s;\r
-  MATRIX m;\r
-  SRECT r;\r
-  LPJPEGBITS jpeg;\r
-  int i;\r
-  \r
-  int ls; // line style\r
-  int fs; // fill style\r
-\r
-  int dx = 256; // bitmap size\r
-  int dy = 256;\r
-  int bps8, bps16, bps32;    // bytes per scanline\r
-\r
-  U8 * bitmap8;\r
-  U16 * bitmap16;\r
-  RGBA * bitmap32;\r
-  RGBA * pal;\r
-\r
-  // create test texture\r
-\r
-  bps8  = BYTES_PER_SCANLINE(dx*sizeof(U8));\r
-  bps16 = BYTES_PER_SCANLINE(dx*sizeof(U16));\r
-  bps32 = BYTES_PER_SCANLINE(dx*sizeof(U32));\r
-  \r
-  pal = malloc(256*sizeof(RGBA));\r
-\r
-  bitmap8 = malloc(bps8*dy);\r
-  bitmap16 = malloc(bps16*dy);\r
-  bitmap32 = malloc(bps32*dy);\r
-  \r
-  if ((bitmap8) && (pal) && (bitmap16))\r
-  { int x,y;\r
-    for (y=0;y<dy;y++)\r
-      for (x=0;x<dx;x++)\r
-        bitmap8[y*bps8+x] = (y/16)*16+(x/16);\r
-\r
-    for (x=0;x<256;x++)\r
-    { pal[x].r = (x&0xf)*16;\r
-      pal[x].g = (x*2)&0xff;\r
-      pal[x].b = x&0xf0;\r
-      pal[x].a = (x==0xff)?0:0xff;\r
-    }\r
-\r
-    for (y=0;y<dy;y++)\r
-      for (x=0;x<dx;x++)\r
-        bitmap16[y*(bps16>>1)+x] = ((x&0xf0)==(y&0xf0))?0xffff:(x&0x0f)<(y&0xf)?BM16_RED|BM16_GREEN:BM16_BLUE;\r
-\r
-    for (y=0;y<dy;y++)\r
-      for (x=0;x<dx;x++)\r
-        { bitmap32[y*(bps32>>2)+x].r = /*((x&0x10)==(y&0x10))?*/((x&4)==(y&4))?y:x;\r
-          bitmap32[y*(bps32>>2)+x].g = x;\r
-          bitmap32[y*(bps32>>2)+x].b = y;\r
-        }\r
-\r
-  } \r
-  \r
-  // put texture into flash movie\r
-\r
-  memset(&swf,0x00,sizeof(SWF));\r
-\r
-  swf.FileVersion       = 4;\r
-  swf.FrameRate         = 0x1800;\r
-  swf.MovieSize.xmax    = 20*WIDTH;\r
-  swf.MovieSize.ymax    = 20*HEIGHT;\r
-\r
-  swf.FirstTag = InsertTag(NULL,ST_SETBACKGROUNDCOLOR);\r
-  t = swf.FirstTag;\r
-\r
-    rgb.r = 0xff;\r
-    rgb.b = 0xff;\r
-    rgb.g = 0xff;\r
-    SetRGB(t,&rgb);\r
-\r
-  t = InsertTag(t,ST_DEFINEBITSLOSSLESS);\r
-\r
-    SetU16(t,ID_BITS);\r
-    SetLosslessBits(t,dx,dy,bitmap32,BMF_32BIT);\r
-    \r
-  t = InsertTag(t,ST_DEFINEBITSLOSSLESS2);\r
-\r
-    /* be careful with ST_DEFINEBITSLOSSLESS2, because\r
-       the Flash player produces great bugs if you use too many\r
-       alpha colors in your palette. The only sensible result that\r
-       can be archeived is setting one color to r=0,b=0,g=0,a=0 to\r
-       make transparent parts in sprites. That's the cause why alpha\r
-       handling is implemented in lossless routines of rfxswf.\r
-    */\r
-\r
-    SetU16(t,ID_BITS+1);\r
-    SetLosslessBitsIndexed(t,dx,dy,bitmap8,pal,256);\r
-    \r
-  t = InsertTag(t,ST_DEFINEBITSLOSSLESS);\r
-\r
-    SetU16(t,ID_BITS+2);\r
-    SetLosslessBits(t,dx,dy,bitmap16,BMF_16BIT);\r
-\r
-  /* By the way: ST_DEFINELOSSLESS2 produces stange output on\r
-     16 and 32 bits image data, too.... it seems that the\r
-     ming developers deal with the same problem.\r
-  */\r
-\r
-  for (i=0;i<9;i++)\r
-  {\r
-    t = InsertTag(t,ST_DEFINESHAPE);\r
-    \r
-    NewShape(&s);\r
-    rgb.b = rgb.g = rgb.r = 0x00;\r
-    ls = ShapeAddLineStyle(s,10,&rgb);  \r
-\r
-    GetMatrix(NULL,&m);\r
-    m.sx = (6*WIDTH/dx)<<16;\r
-    m.sy = (6*HEIGHT/dy)<<16;\r
-\r
-    fs = ShapeAddBitmapFillStyle(s,&m,ID_BITS+((i+(i/3))%3),0);\r
-    \r
-    SetU16(t,ID_SHAPE+i);   // ID   \r
-\r
-    r.xmin = 0;\r
-    r.ymin = 0;\r
-    r.xmax = 6*WIDTH;\r
-    r.ymax = 6*HEIGHT;\r
-\r
-    SetRect(t,&r);\r
-\r
-    SetShapeStyles(t,s);\r
-    ShapeCountBits(s,NULL,NULL);\r
-    SetShapeBits(t,s);\r
-\r
-    ShapeSetAll(t,s,0,0,ls,fs,0);\r
-\r
-    ShapeSetLine(t,s,6*WIDTH,0);\r
-    ShapeSetLine(t,s,0,6*HEIGHT);\r
-    ShapeSetLine(t,s,-6*WIDTH,0);\r
-    ShapeSetLine(t,s,0,-6*HEIGHT);\r
-    ShapeSetEnd(t);\r
-\r
-    GetMatrix(NULL,&m);\r
-    m.tx = (i%3) * (6*WIDTH+60);\r
-    m.ty = (i/3) * (6*HEIGHT+60);\r
-\r
-  t = InsertTag(t,ST_PLACEOBJECT2);\r
-    ObjectPlace(t,ID_SHAPE+i,1+i,&m,NULL,NULL);\r
-  }\r
-\r
-  t = InsertTag(t,ST_SHOWFRAME);\r
-\r
-  t = InsertTag(t,ST_END);\r
-\r
-  WriteCGI(&swf);\r
-  FreeTags(&swf);\r
-\r
-  free(pal);\r
-  free(bitmap8);\r
-  free(bitmap16);\r
-  free(bitmap32);  \r
-  return 0;\r
-}\r
+/* 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 <rfxswf@reflex-studio.de>
+   This file is distributed under the GPL, see file COPYING for details 
+
+*/
+
+#include <stdio.h>
+#include <fcntl.h>
+#include <math.h>
+#include <zlib.h>     
+#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<dy;y++)
+      for (x=0;x<dx;x++)
+        bitmap8[y*bps8+x] = (y/16)*16+(x/16);
+
+    for (x=0;x<256;x++)
+    { pal[x].r = (x&0xf)*16;
+      pal[x].g = (x*2)&0xff;
+      pal[x].b = x&0xf0;
+      pal[x].a = (x==0xff)?0:0xff;
+    }
+
+    for (y=0;y<dy;y++)
+      for (x=0;x<dx;x++)
+        bitmap16[y*(bps16>>1)+x] = ((x&0xf0)==(y&0xf0))?0xffff:(x&0x0f)<(y&0xf)?BM16_RED|BM16_GREEN:BM16_BLUE;
+
+    for (y=0;y<dy;y++)
+      for (x=0;x<dx;x++)
+        { bitmap32[y*(bps32>>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;
+}