예제 #1
0
파일: jpeg2swf.c 프로젝트: DJwa163/swftools
TAG *MovieStart(SWF * swf, float framerate, int dx, int dy)
{
    TAG *t;
    RGBA rgb;

    memset(swf, 0x00, sizeof(SWF));

    swf->fileVersion = global.version;
    swf->frameRate = (int)(256.0 * framerate);

    if(custom_clip) {
	swf->movieSize.xmin = clip_x1 * 20;
	swf->movieSize.ymin = clip_y1 * 20;
	swf->movieSize.xmax = clip_x2 * 20;
	swf->movieSize.ymax = clip_y2 * 20;
    } else {
	swf->movieSize.xmin = 0;
	swf->movieSize.ymin = 0;
	swf->movieSize.xmax = swf->movieSize.xmin + dx * 20;
	swf->movieSize.ymax = swf->movieSize.ymin + dy * 20;
    }

    t = swf->firstTag = swf_InsertTag(NULL, ST_SETBACKGROUNDCOLOR);

    rgb.r = rgb.g = rgb.b = rgb.a = 0x00;
    swf_SetRGB(t, &rgb);

    if (global.mx) {
	t = swf_InsertTag(t, ST_DEFINEVIDEOSTREAM);
	swf_SetU16(t, 0xf00d);
	swf_SetVideoStreamDefine(t, &stream, 65535, dx, dy);
    } else if (global.asset_name) {
	t = swf_InsertTag(t, ST_DEFINESPRITE);
	swf_SetU16(t, 1);
	swf_SetU16(t, global.next_id++);
    }

    return t;
}
예제 #2
0
int main (int argc,char ** argv)
{ SWF swf;
  TAG* t;
  RGBA rgb;
  SRECT r;
  SHAPE* s;
  S32 width = 800,height = 800;
  int fs,ls; // line & fillstyle
  JPEGBITS* jpeg;
  MATRIX m;  
  
  int f,i,j,frame;
  
  memset(&swf,0x00,sizeof(SWF));

  swf.fileVersion    = 4;
  swf.frameRate      = 0x4000;
  swf.movieSize.xmax = 4*width;
  swf.movieSize.ymax = 4*height;

  swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR);
  t = swf.firstTag;

        rgb.r = 0xff;
        rgb.g = 0xff;
        rgb.b = 0xff;
        swf_SetRGB(t,&rgb);

    t = swf_InsertTag(t,ST_DEFINEBITSJPEG2);

         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 = swf_InsertTag(t,ST_DEFINESHAPE);
    
         swf_ShapeNew(&s);
         rgb.b = rgb.g = rgb.r = 0x00;
         ls = 0;
         rgb.b = 0xff;
  
         fs = swf_ShapeAddBitmapFillStyle(s,NULL,ID_BITMAP,0);
    
         swf_SetU16(t,ID_SHAPE);    // ID   
         
         r.xmin = 0;
         r.ymin = 0;
         r.xmax = 2*width;
         r.ymax = 2*height;
         
         swf_SetRect(t,&r);

         swf_SetShapeHeader(t,s);
         
         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);

         swf_ShapeFree(s);
    
  for (frame=0;frame<64;frame++)
  {

    /* 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;

    // joining m1 and m2 should lead to no transformation

    swf_MatrixJoin(&m,&m1,&m2);

    */

    int dx0 = width;    // constants of shape 
    int dy0 = width;

    int px0 = 2*width;  // destination of mapping
    int py0 = 2*width;

    int px1 = 3*width;
    int py1 = 2*width-frame*4;

    int px2 = 2*width-frame*8;
    int py2 = 3*width;

    swf_MatrixMapTriangle(&m,dx0,dy0,px0,py0,px1,py1,px2,py2);

    t = swf_InsertTag(t,ST_PLACEOBJECT2);

        if (!frame)
         swf_ObjectPlace(t,ID_SHAPE,1,&m,NULL,NULL);
        else
          swf_ObjectMove(t,1,&m,NULL);
 
    t = swf_InsertTag(t,ST_SHOWFRAME);
  }
  
  
  t = swf_InsertTag(t,ST_END);
  
//  swf_WriteCGI(&swf);

  f = open("transtest.swf",O_RDWR|O_CREAT|O_TRUNC|O_BINARY,0644);
  if FAILED(swf_WriteSWF(f,&swf)) fprintf(stderr,"WriteSWF() failed.\n");
  close(f);

  swf_FreeTags(&swf);

#ifdef __NT__
  system("start ..\\transtest.swf");
#endif
  
  return 0;
}
예제 #3
0
static void makestackmaster(SWF*swf)
{
    TAG*tag;
    int t;
    SRECT box;
    int fileversion = config.zlib?6:3;
    int frameRate = 256;
    U32 fileAttributes = 0;
    RGBA rgb;
    rgb.r=rgb.b=rgb.g=0;
    memset(&box, 0, sizeof(box));

    /* scan all slaves for bounding box */
    for(t=numslaves-1;t>=0;t--)
    {
	SWF head;
	int ret;
	int fi=open(slave_filename[t],O_RDONLY|O_BINARY);
	TAG*tag;
	if(fi<0 || swf_ReadSWF(fi, &head)<0) {
	    msg("<fatal> Couldn't open/read %s.", slave_filename[t]);
	    exit(1);
	}
	close(fi);
	swf_RemoveJPEGTables(&head);
        fileAttributes |= head.fileAttributes;
	removeCommonTags(&head);

	msg("<verbose> File %s has bounding box %d:%d:%d:%d\n",
		slave_filename[t], 
		head.movieSize.xmin, head.movieSize.ymin,
		head.movieSize.xmax, head.movieSize.ymax);

	tag = head.firstTag;
	while(tag) {
	    if(tag->id == ST_SETBACKGROUNDCOLOR && tag->len>=3) {
		rgb.r = tag->data[0];
		rgb.g = tag->data[1];
		rgb.b = tag->data[2];
	    }
	    tag=tag->next;
	}
	frameRate = head.frameRate;
	if(head.fileVersion > fileversion)
	    fileversion = head.fileVersion;
	if(!t)
	    box = head.movieSize;
	else {
	    if(head.movieSize.xmin < box.xmin)
		box.xmin = head.movieSize.xmin;
	    if(head.movieSize.ymin < box.ymin)
		box.ymin = head.movieSize.ymin;
	    if(head.movieSize.xmax > box.xmax)
		box.xmax = head.movieSize.xmax;
	    if(head.movieSize.ymax > box.ymax)
		box.ymax = head.movieSize.ymax;
	}
	msg("<verbose> New master bounding box is %d:%d:%d:%d\n",
		box.xmin, box.ymin,
		box.xmax, box.ymax);
	swf_FreeTags(&head);
    }

    memset(swf, 0, sizeof(SWF));
    swf->fileVersion = fileversion;
    swf->movieSize = box;
    swf->frameRate = frameRate;
    swf->fileAttributes = fileAttributes;

    swf->firstTag = swf_InsertTag(0, ST_SETBACKGROUNDCOLOR);
    tag = swf->firstTag;
    swf_SetRGB(tag, &rgb);
    
    for(t=0;t<numslaves;t++)
    {
	char buf[128];
	sprintf(buf, "Frame%02d", t);
	slave_name[t] = strdup(buf);

	tag = swf_InsertTag(tag, ST_DEFINESPRITE);
	swf_SetU16(tag, t+1);
	swf_SetU16(tag, 0);
	tag = swf_InsertTag(tag, ST_END);
	tag = swf_InsertTag(tag, ST_PLACEOBJECT2);
	swf_ObjectPlace(tag, t+1, 1+t,0,0, slave_name[t]);

	if(!config.stack1 || t == numslaves-1) {
	    tag = swf_InsertTag(tag, ST_SHOWFRAME);
	}
	if(!config.stack)
	if(t!=numslaves-1)
	{
	    tag = swf_InsertTag(tag, ST_REMOVEOBJECT2);
	    swf_SetU16(tag, 1+t);
	}
    }
    tag = swf_InsertTag(tag, ST_END);
    msg("<verbose> temporary SWF created");
}
예제 #4
0
int main (int argc,char ** argv)
{ SWF swf;
  RGBA rgb;
  SRECT r;
  SHAPE* s;
  MATRIX m;
  ActionTAG*a1,*a2,*a3;
  S32 width = 826, height = 1169;
  
  int f,i,ls1,fs1;
  int count;
  int t;

  memset(&swf,0x00,sizeof(SWF));        // set global movie parameters

  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);
  tag = swf.firstTag;
  rgb.r = 0xff;
  rgb.g = 0xff;
  rgb.b = 0xff;
  swf_SetRGB(tag,&rgb);

  tag = swf_InsertTag(tag,ST_DEFINESPRITE);
  swf_SetU16(tag, 1); //id
  swf_SetU16(tag, 0); //frames
  tag = swf_InsertTag(tag,ST_END);
  tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
  swf_ObjectPlace(tag, 1, 1, 0, 0, "loader");
  
  tag = swf_InsertTag(tag,ST_SHOWFRAME);

    a1 = action_PushFloat(0, 12.0);
    a1 = action_PushString(a1, "");
    a1 = action_GetProperty(a1);
    a1 = action_PushFloat(a1, 2.0);
    a1 = action_Less(a1);
    a1 = action_If(a1, 2);
    a1 = action_GotoFrame(a1, 1);
    a1 = action_End(a1);

    a2 = action_Stop(0);
    a2 = action_End(a2);

  tag = swf_InsertTag(tag,ST_DOACTION);
  swf_ActionSet(tag, a1);
  
  tag = swf_InsertTag(tag,ST_SHOWFRAME);
  
  tag = swf_InsertTag(tag,ST_DOACTION);
  swf_ActionSet(tag, a2);
  
  tag = swf_InsertTag(tag,ST_REMOVEOBJECT2);
  swf_SetU16(tag, 1);

  tag = swf_InsertTag(tag,ST_DEFINESPRITE);
  swf_SetU16(tag, 2); //id
  swf_SetU16(tag, 0); //frames
  tag = swf_InsertTag(tag,ST_END);
  tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
  swf_ObjectPlace(tag, 2, 2, 0, 0, "movie");
  
  tag = swf_InsertTag(tag,ST_SHOWFRAME);
  
  tag = swf_InsertTag(tag,ST_END);

  f = open("PreLoaderTemplate.swf",O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0644);
  if FAILED(swf_WriteSWF(f,&swf)) fprintf(stderr,"WriteSWF() failed.\n");
  close(f);

  swf_FreeTags(&swf);                       // cleanup

  swf_ActionFree(a1);
  swf_ActionFree(a2);

  return 0;
}
예제 #5
0
static void write_font(SWFFONT * font, char *filename)
{
    SWF swf;
    TAG *t;
    SRECT r;
    RGBA rgb;
    int f;
    int useDefineFont2 = 1;
    int storeGlyphNames = 1;
   
#define WRITEFONTID 8888
    font->id = WRITEFONTID;

    memset(&swf, 0x00, sizeof(SWF));

    swf.fileVersion = 9;
    swf.frameRate = 0x4000;

    t = swf_InsertTag(NULL, ST_SETBACKGROUNDCOLOR);
    swf.firstTag = t;
    rgb.r = 0xef;
    rgb.g = 0xef;
    rgb.b = 0xff;
    swf_SetRGB(t, &rgb);
    
    t = swf_InsertTag(t, ST_DEFINEFONT3);
    swf_FontSetDefine2(t, font);

    t = swf_InsertTag(t, ST_DEFINEFONTALIGNZONES);
    swf_SetU16(t, font->id);
    swf_SetU8(t, 0); //thin
    int i;
    for(i=0;i<256;i++) {
	swf_SetU8(t, 2);
	swf_SetF16(t, 82.0 / 1024.0);
	swf_SetF16(t, 82.0 / 1024.0);
	swf_SetF16(t, ((i%16/2)*82.0) / 1024.0);
	swf_SetF16(t, ((i/16/2)*82.0) / 1024.0);
	/*
	if(i<128 && (i&15)<8) {
	    swf_SetF16(t, 0.0);
	    swf_SetF16(t, 0.0);
	    swf_SetF16(t, 640.0 / 1024.0);
	    swf_SetF16(t, 640.0 / 1024.0);
	} else if(i<128 && (i&15)>=8) {
	    swf_SetF16(t, 0.0 / 1024.0);
	    swf_SetF16(t, 0.0   / 1024.0);
	    swf_SetF16(t, 330.0 / 1024.0);
	    swf_SetF16(t, 640.0 / 1024.0);
	} else if(i>=128 && (i&15)<8) {
	    swf_SetF16(t, 0.0   / 1024.0);
	    swf_SetF16(t, 0.0 / 1024.0);
	    swf_SetF16(t, 640.0 / 1024.0);
	    swf_SetF16(t, 330.0 / 1024.0);
	} else {
	    swf_SetF16(t, 0.0 / 1024.0);
	    swf_SetF16(t, 0.0 / 1024.0);
	    swf_SetF16(t, 330.0 / 1024.0);
	    swf_SetF16(t, 330.0 / 1024.0);
	}*/
	swf_SetU8(t, 3); // x and y
    }

    int s;
    int xmax = 0;
    int ymax = 0;
    int ypos = 1;
    U8 gbits, abits;
    int x, y, c;
    int range = font->maxascii;

    c = 0;
    range = 256;

    xmax = 1280;
    ymax = 1280*20;

    swf.movieSize.xmax = xmax * 20;
    swf.movieSize.ymax = ymax;

    t = swf_InsertTag(t, ST_DEFINETEXT);
    swf_SetU16(t, font->id + 1);	// ID
    r.xmin = 0;
    r.ymin = 0;
    r.xmax = swf.movieSize.xmax;
    r.ymax = swf.movieSize.ymax;
    swf_SetRect(t, &r);
    swf_SetMatrix(t, NULL);
    abits = swf_CountBits(xmax * 16, 0);
    gbits = 8;
    swf_SetU8(t, gbits);
    swf_SetU8(t, abits);

    rgb.r = 0x00;
    rgb.g = 0x00;
    rgb.b = 0x00;
    ypos = 2;
    
    int textscale = 1024;
    for (y = 0; y < ((range + 15) / 16); y++) {
	for (x = 0; x < 16; x++) {
	    //swf_TextSetInfoRecord(t, font, textscale, &rgb, x*64*20+64*20+10+(x+y)*20, y*64*20+128*20+10+(x^y)*20);
	    swf_TextSetInfoRecord(t, font, textscale, &rgb, x*64*20+64*20+10, y*64*20+128*20+10);
	    int g = y * 16 + x;
	    swf_SetU8(t, 1);
	    swf_SetBits(t, g, gbits);
	    swf_SetBits(t, 0, abits);
	    swf_ResetWriteBits(t);
	}
    }
    swf_SetU8(t, 0);
		 
    t = swf_InsertTag(t, ST_CSMTEXTSETTINGS);
    swf_SetU16(t, font->id + 1);
    swf_SetU8(t, (1<<3)//grid
	         |0x40//flashtype
		 );
    swf_SetU32(t, 0x20000);//thickness
    swf_SetU32(t, 0x800000);//sharpness
    swf_SetU8(t, 0);//reserved

    t = swf_InsertTag(t, ST_PLACEOBJECT2);
    swf_ObjectPlace(t, font->id + 1, 1, NULL, NULL, NULL);

    t = swf_InsertTag(t, ST_SHOWFRAME);
    t = swf_InsertTag(t, ST_END);

    f = open(filename, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0644);
    if FAILED
	(swf_WriteSWF(f, &swf)) fprintf(stderr, "WriteSWF() failed in writeFont().\n");
    close(f);

    swf_FreeTags(&swf);
}
예제 #6
0
파일: shape1.c 프로젝트: DJwa163/swftools
int main (int argc,char ** argv)
{ SWF swf;
  TAG* t;
  RGBA rgb;
  SRECT r;
  SHAPE* s;
  S32 width=300,height = 300;
  
  int f,i,ls1,ls2;

  memset(&swf,0x00,sizeof(SWF));        // set global movie parameters

  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);

                                        // now create a tag list be connecting one after another
  
  t = swf.firstTag;

        rgb.r = 0xff;
        rgb.g = 0xff;
        rgb.b = 0xff;
        swf_SetRGB(t,&rgb);

  t = swf_InsertTag(t,ST_DEFINESHAPE);

        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;
        ls2 = swf_ShapeAddLineStyle(s,40,&rgb);

        swf_SetU16(t,1);                // now set character ID

        r.xmin = 0;
        r.ymin = 0;
        r.xmax = 20*width;
        r.ymax = 20*height;
        
        swf_SetRect(t,&r);              // set shape bounds


        swf_SetShapeHeader(t,s);        // write all styles to tag

        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++)
          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 = swf_InsertTag(t,ST_PLACEOBJECT2);     // append tag to place your shape into the scene

        swf_ObjectPlace(t,1,1,NULL,NULL,NULL); // set character with id 1 (our shape) to depth 1 (upper most layer)

  t = swf_InsertTag(t,ST_SHOWFRAME);        // finish current frame

  t = swf_InsertTag(t,ST_END);              // finish current movie (which has just one frame)
  
//  swf_WriteCGI(&swf);    <- use this to create direct CGI output
  
                                            // write movie to file

  f = open("shape1.swf",O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0644);
  if FAILED(swf_WriteSWF(f,&swf)) fprintf(stderr,"WriteSWF() failed.\n");
  close(f);

  swf_FreeTags(&swf);                       // cleanup

#ifdef __NT__                               // start flash player to show result on windows systems
  system("start ..\\shape1.swf");
#endif
  
  return 0;
}