X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Frfxswf.c;h=7049111478369dff390988892a001b21efad87cc;hb=8873581f76d2dee9c132d03ad0edf9d0d9f9cf18;hp=0e000060965b70e4302f4a2669aed417325bec83;hpb=469e1e998167801f48345b52b98d8bcb282b9f53;p=swftools.git diff --git a/lib/rfxswf.c b/lib/rfxswf.c index 0e00006..7049111 100644 --- a/lib/rfxswf.c +++ b/lib/rfxswf.c @@ -1,5 +1,4 @@ /* vi: set sts=2 sw=2 :*/ - /* rfxswf.c Library for creating and reading SWF files or parts of it. @@ -8,11 +7,22 @@ Part of the swftools package. - Copyright (c) 2000, 2001 Rainer Böhme - - This file is distributed under the GPL, see file COPYING for details + Copyright (c) 2000-2003 Rainer Böhme + Copyright (c) 2003 Matthias Kramm + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -*/ + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "rfxswf.h" @@ -250,7 +260,7 @@ int swf_SetRGB(TAG * t,RGBA * col) void swf_GetRGB(TAG * t, RGBA * col) { RGBA dummy; - if(!col); + if(!col) col = &dummy; col->r = swf_GetU8(t); col->g = swf_GetU8(t); @@ -299,22 +309,35 @@ void swf_GetGradient(TAG * tag, GRADIENT * gradient, char alpha) } } +int swf_CountUBits(U32 v,int nbits) +{ int n = 32; + U32 m = 0x80000000; + if(v == 0x00000000) n = 0; + else + while (!(v&m)) + { n--; + m>>=1; + } + return (n>nbits)?n:nbits; +} + int swf_CountBits(U32 v,int nbits) { int n = 33; U32 m = 0x80000000; - if (!v) n = 0; else if (v&m) - { while (v&m) + { if(v == 0xffffffff) n = 1; + else + while (v&m) { n--; m>>=1; - if (!m) break; } } else - { while (!(v&m)) + { if(v == 0x00000000) n = 0; + else + while (!(v&m)) { n--; m>>=1; - if (!m) break; } } return (n>nbits)?n:nbits; @@ -640,6 +663,30 @@ TAG * swf_InsertTag(TAG * after,U16 id) // updates frames, if nescessary return t; } +TAG * swf_InsertTagBefore(SWF* swf, TAG * before,U16 id) // updates frames, if nescessary +{ TAG * t; + + t = (TAG *)malloc(sizeof(TAG)); + if (t) + { memset(t,0x00,sizeof(TAG)); + t->id = id; + + if (before) + { t->frame = before->frame; + t->next = before; + t->prev = before->prev; + before->prev = t; + if (t->prev) t->prev->next = t; + + if (id==ST_SHOWFRAME) swf_UpdateFrame(t->next,+1); + } + } + if(swf && swf->firstTag == before) { + swf->firstTag = t; + } + return t; +} + void swf_ClearTag(TAG * t) { if (t->data) free(t->data); @@ -651,6 +698,12 @@ void swf_ClearTag(TAG * t) t->memsize = 0; } +void swf_ResetTag(TAG*tag, U16 id) +{ + tag->len = tag->pos = tag->readBit = tag->writeBit = 0; + tag->id = id; +} + int swf_DeleteTag(TAG * t) { if (!t) return -1; @@ -1113,29 +1166,37 @@ int swf_WriteSWF2(struct writer_t*writer, SWF * swf) // Writes SWF to file, swf_SetU16(&t2, swf->frameCount); l = swf_GetTagLen(&t2)+8; } + if(swf->compressed == 8) { + l -= 8; + } fileSize = l+len; if(len) {// don't touch headers without tags swf->fileSize = fileSize; swf->frameCount = frameCount; } - - if(swf->compressed) { - char*id = "CWS"; - writer->write(writer, id, 3); - } - else { - char*id = "FWS"; - writer->write(writer, id, 3); - } - writer->write(writer, &swf->fileVersion, 1); - PUT32(b4, swf->fileSize); - writer->write(writer, b4, 4); + if(swf->compressed != 8) { + /* compressed flag set to 8 means "skip first 8 + header bytes". This is necessary if the caller wants to + create compressed SWFs himself */ + if(swf->compressed) { + char*id = "CWS"; + writer->write(writer, id, 3); + } + else { + char*id = "FWS"; + writer->write(writer, id, 3); + } - if(swf->compressed) { - writer_init_zlibdeflate(&zwriter, writer); - writer = &zwriter; + writer->write(writer, &swf->fileVersion, 1); + PUT32(b4, swf->fileSize); + writer->write(writer, b4, 4); + + if(swf->compressed) { + writer_init_zlibdeflate(&zwriter, writer); + writer = &zwriter; + } } swf_SetRect(&t1,&swf->movieSize); @@ -1160,7 +1221,8 @@ int swf_WriteSWF2(struct writer_t*writer, SWF * swf) // Writes SWF to file, { if (swf_WriteTag2(writer, t)<0) return -1; t = swf_NextTag(t); } - writer->finish(writer); //e.g. flush zlib buffers + if(swf->compressed != 8) + writer->finish(writer); // flush zlib buffers - only if _we_ initialized that writer. } } return (int)fileSize; @@ -1170,8 +1232,10 @@ int swf_WriteSWF(int handle, SWF * swf) // Writes SWF to file, returns leng { struct writer_t writer; swf->compressed = 0; - if(handle<0) + if(handle<0) { + writer_init_nullwriter(&writer); return swf_WriteSWF2(&writer, swf); + } writer_init_filewriter(&writer, handle); return swf_WriteSWF2(&writer, swf); } @@ -1180,8 +1244,10 @@ int swf_WriteSWC(int handle, SWF * swf) // Writes SWF to file, returns leng { struct writer_t writer; swf->compressed = 1; - if(handle<0) + if(handle<0) { + writer_init_nullwriter(&writer); return swf_WriteSWF2(&writer, swf); + } writer_init_filewriter(&writer, handle); return swf_WriteSWF2(&writer, swf); }