⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 spliter.c.svn-base

📁 A Flash Player with ActionScript support. Write in C and C++. It have two part, one is Player and an
💻 SVN-BASE
📖 第 1 页 / 共 5 页
字号:
#include <stdio.h>#include <stdlib.h>#include <string.h>#include "config.h"#include "spliter.h"#include "spliter_pub.h"#include "spliter_reader.h"#include "base_types.h"#include "bitmap_def.h"#include "button_def.h"#include "dynamic_text_def.h"#include "font_def.h"#include "morphing_def.h"#include "movie_clips_def.h"#include "shape_def.h"#include "static_text_def.h"#include "sound_def.h"#include "define.h"#include "swf_file_pub.h"#include <glib.h>#include <assert.h>#if WITH_DMALLOC#include <dmalloc.h>#endifint gg_error(void) {    printf("read file error!\n");    return -1;};int g_readdata(struct reader_t *reader,int len) {    void *p;    if (len == 0)        return 0;    p=(void *)malloc(len);    if (reader->read(reader, p, len) !=len )        return gg_error();    free((void *)p);    return 0;}SI32 reader_GetSBits(struct reader_t *reader, int nbits) {    UI32 res = reader_readbits(reader, nbits);    if (res&(1<<(nbits-1)))        res|=(0xffffffff<<nbits);    return (SI32)res;}UI32 reader_GetBits(struct reader_t *reader, int nbits) {    return reader_readbits(reader, nbits);}int reader_GetString(struct reader_t *reader,char **str) {    char tmpstr[1024];    int i=0;    char *cp;    char p;    do {        if ((reader->read(reader, &p, 1) != 1))            return gg_error();        tmpstr[i]=p;        i++;    } while(p);    cp=malloc(i);    memcpy(cp,tmpstr,i);    *str=cp;    return i;}int reader_GetStringWithLen(struct reader_t *reader,char **str,int len) {    char *cp;    cp=malloc(len+1);    if ((reader->read(reader, cp, len) != len))        return gg_error();    *str=cp;    cp+=len;    *cp=0;    return 0;}int reader_GetRgb(struct reader_t *reader,struct RGBA * r) {    UI8 p[3];    if (reader->read(reader, p, 3) != 3)        return gg_error();    r->Red=p[0];    r->Green=p[1];    r->Blue=p[2];    r->Alpha=255;    return 0;}int reader_GetRgba(struct reader_t *reader,struct RGBA * r) {    UI8 p[4];    if (reader->read(reader, p, 4) != 4)        return gg_error();    r->Red=p[0];    r->Green=p[1];    r->Blue=p[2];    r->Alpha=p[3];    return 0;}int reader_GetRect(struct reader_t *reader,struct RECT * r) {    int nbits;    struct RECT dummy;    reader->bitpos=8;    if (!r)        r = &dummy;    nbits = (int) reader_GetBits(reader,5);    r->Xmin = reader_GetSBits(reader,nbits);    r->Xmax = reader_GetSBits(reader,nbits);    r->Ymin = reader_GetSBits(reader,nbits);    r->Ymax = reader_GetSBits(reader,nbits);    return 0;}int reader_GetMatrix(struct reader_t *reader,struct Matrix *p) {    int nbits;    reader->bitpos=8;    p->HasScale=(UI8)reader_GetBits(reader,1);    if (p->HasScale) {        nbits=(int)reader_GetBits(reader,5);        p->ScaleX=(double)reader_GetSBits(reader,nbits)/(double)0x10000;        p->ScaleY=(double)reader_GetSBits(reader,nbits)/(double)0x10000;    } else {        p->ScaleX=1;        p->ScaleY=1;    }    p->HasRotate=(UI8)reader_GetBits(reader,1);    if (p->HasRotate) {        nbits=(int)reader_GetBits(reader,5);        p->RotateSkew1=(double)reader_GetSBits(reader,nbits)/(double)0x10000;        p->RotateSkew0=(double)reader_GetSBits(reader,nbits)/(double)0x10000;    }    nbits=(int)reader_GetBits(reader,5);    p->TranslateX=reader_GetSBits(reader,nbits);    p->TranslateY=reader_GetSBits(reader,nbits);    return 0;}int reader_GetCxFromWithAlpha(struct reader_t *reader,struct CxFormWithAlpha *p) {    int nbits;    reader->bitpos=8;    p->HasAddTerms=(UI8)reader_GetBits(reader,1);    p->HasMultTerms=(UI8)reader_GetBits(reader,1);    nbits=(int)reader_GetBits(reader,4);    if (p->HasMultTerms) {        p->RedMultTerm=(FB)reader_GetSBits(reader,nbits)/(FB)0x100;        p->GreenMultTerm=(FB)reader_GetSBits(reader,nbits)/(FB)0x100;        p->BlueMultTerm=(FB)reader_GetSBits(reader,nbits)/(FB)0x100;        p->AlphaMultTerm=(FB)reader_GetSBits(reader,nbits)/(FB)0x100;    } else {        p->RedMultTerm=1;        p->GreenMultTerm=1;        p->BlueMultTerm=1;        p->AlphaMultTerm=1;    }    if (p->HasAddTerms) {        p->RedAddTerm=reader_GetSBits(reader,nbits);        p->GreenAddTerm=reader_GetSBits(reader,nbits);        p->BlueAddTerm=reader_GetSBits(reader,nbits);        p->AlphaAddTerm=reader_GetSBits(reader,nbits);    }    return 0;}int reader_GetCxFrom(struct reader_t *reader,struct CxFormWithAlpha *p) {    int nbits;    reader->bitpos=8;    p->HasAddTerms=(UI8)reader_GetBits(reader,1);    p->HasMultTerms=(UI8)reader_GetBits(reader,1);    nbits=(int)reader_GetBits(reader,4);    if (p->HasMultTerms) {        p->RedMultTerm=(FB)reader_GetSBits(reader,nbits)/(FB)0x100;        p->GreenMultTerm=(FB)reader_GetSBits(reader,nbits)/(FB)0x100;        p->BlueMultTerm=(FB)reader_GetSBits(reader,nbits)/(FB)0x100;        p->AlphaMultTerm=0x100;    }    if (p->HasAddTerms) {        p->RedAddTerm=reader_GetSBits(reader,nbits);        p->GreenAddTerm=reader_GetSBits(reader,nbits);        p->BlueAddTerm=reader_GetSBits(reader,nbits);        p->AlphaAddTerm=0;    }    return 0;}int reader_GetGradient(struct reader_t *reader,struct Gradient **p,int type) {    struct Gradient *Grad;    UI8 Num;    int i;    if (reader->read(reader, &(Num), 1) !=1 )        return gg_error();    Grad=(struct Gradient *)malloc(sizeof(struct Gradient)+(sizeof(struct GradRecord)*(Num-1)));    bzero((void *)Grad,sizeof(struct Gradient)+(sizeof(struct GradRecord)*(Num-1)));    Grad->NumGradients=Num;    for (i=0;i<Num;i++) {        if (reader->read(reader, &(Grad->GradientRecords[i].Ratio), 1) !=1 )            return gg_error();        if (type==3) {            reader_GetRgba(reader,&(Grad->GradientRecords[i].Color));        } else {            reader_GetRgb(reader,&(Grad->GradientRecords[i].Color));        }    }    *p=Grad;    return 0;}int g_GetColor(struct reader_t*reader,struct RGB *color) {    UI8 p[3];    if (reader->read(reader, p, 3) != 3)        return gg_error();    color->Red=p[0];    color->Green=p[1];    color->Blue=p[2];    return 0;}int g_AddToDict(swf_file_t *swf_p,int id,struct DefineCharacter* char_p) {    if (swf_p->dict_p == NULL) {        swf_p->dict_p = g_new0(struct Dict,1);        swf_p->dict_p->count = 0;    };    if (swf_p->dict_p->count <= id) {        swf_p->dict_p->count = id + 50;        swf_p->dict_p = g_realloc(swf_p->dict_p,sizeof(struct Dict)+(swf_p->dict_p->count)*4);    };    swf_p->dict_p->dict[id] = char_p;    char_p->CharacterID = id;    switch (char_p->CharacterType) {    case CharBitsOne             :    case CharBitsJPEG            :    case CharBitsLosslessOne     :    case CharBitsLosslessTwo     :        bmp_makebmp(char_p,swf_p);        break;    case CharText:        stx_to_shape(swf_p,(struct DefineText*)char_p);        break;    };    return 0;}int g_GetDefSound(struct reader_t *reader,swf_file_t *swf_p,int sound_len) {    struct DefineSound *sound_p;    int i;    UI16        SoundId;    UI8		SoundFlags;    UI32        SoundSampleCount;    UI32	SoundLength;    if (reader->read(reader, &SoundId, 2) !=2 )        return gg_error();    SoundId=SWAP16(SoundId);    if (reader->read(reader, &SoundFlags, 1) !=1 )        return gg_error();    if (reader->read(reader, &SoundSampleCount, 4) !=4 )        return gg_error();    SoundSampleCount=SWAP32(SoundSampleCount);    SoundLength=sound_len-7;    i=sizeof(struct DefineSound)+sound_len-1;    sound_p=(struct DefineSound *)malloc(i);    sound_p->CharacterType=CharEventSound;    sound_p->SoundId=SoundId;    sound_p->SoundFlags=SoundFlags;    sound_p->SoundSampleCount=SoundSampleCount;    sound_p->SoundLength=SoundLength;    if (reader->read(reader, sound_p->SoundData, SoundLength) !=SoundLength )        return gg_error();    return g_AddToDict(swf_p,SoundId,(struct DefineCharacter*)sound_p);}//g_getExportAssets is not compileteint g_GetExportAssets(struct reader_t *reader,swf_file_t *swf_p,int len) {    UI16	count,id;    STRING	name_p;    int		i;    struct asset 	*asset_p,*a_p;    if (reader->read(reader, &count, 2) !=2 )        return gg_error();    count=SWAP16(count);    for (i = 0; i< count ; i++) {        if (reader->read(reader, &id, 2) !=2 )            return gg_error();        id=SWAP16(id);        reader_GetString(reader,&(name_p));        asset_p 	= g_new0(struct asset,1);        asset_p->id 	= id;        asset_p->name_p = name_p;        a_p = swf_p->dict_p->assets_p;        if (a_p) {            while (a_p->next_p)                a_p=a_p->next_p;            a_p->next_p=asset_p;        } else {            swf_p->dict_p->assets_p=asset_p;        }        printf("export %d name %s \n",id, name_p);    };    return 0;};int g_GetFillStyle(struct reader_t *reader,struct FillStyle *FillStyle_p,int type) {    struct FillStyle *p;    p=FillStyle_p;    if (reader->read(reader, &(p->FillStyleType), 1) !=1 )        return gg_error();    if (p->FillStyleType==0x00) {        if(type==3) {            reader_GetRgba(reader,&(p->Color));        } else {            reader_GetRgb(reader,(&(p->Color)));        }    }    if ((p->FillStyleType==0x10)||(p->FillStyleType==0x12)) {        reader_GetMatrix(reader,&(p->GradientMatrix));        reader_GetGradient(reader,&(p->GradientP),type);    }    if ((p->FillStyleType==0x41)||(p->FillStyleType==0x42)||(p->FillStyleType==0x43)||(p->FillStyleType==0x40)) {        if (reader->read(reader, &p->BitmapId, 2) !=2 )            return gg_error();        p->BitmapId=SWAP16(p->BitmapId);        reader_GetMatrix(reader,&(p->BitmapMatrix));    }    return 0;}int g_GetFillStyleArray(struct reader_t *reader,struct FillStyleArray **p,int type) {    UI8 count;    UI16 e_count;    int len;    int i;#if DEBUG    printf("begin GetFillStyleArray function\n");#endif    if (reader->read(reader, &count, 1) !=1 )        return gg_error();    len=count;    if (type!=1) {        if (count==0xff) {            if (reader->read(reader, &e_count, 2) !=2 )                return gg_error();            e_count=SWAP16(e_count);            len=e_count;        }    }#if DEBUG    printf("len:%d\n",len);#endif    *p=(struct FillStyleArray*)malloc(sizeof(struct FillStyleArray)+sizeof(struct FillStyle)*(len-1));    bzero((void *)*p,sizeof(struct FillStyleArray)+sizeof(struct FillStyle)*(len-1));    (*p)->count=len;    for(i=0;i<len;i++) {#if DEBUG        printf("get the %d FillStyles:%p\n",i,&((*p)->FillStyles[i]));#endif        g_GetFillStyle(reader,(struct FillStyle *)&((*p)->FillStyles[i]),type);    }#if DEBUG    printf("end GetFillStyleArray function\n");#endif    return 0;}int g_GetLineStyle(struct reader_t *reader,struct LineStyle *LineStyle_p,int type) {    struct LineStyle *p;    p=LineStyle_p;    bzero((void *)p,sizeof(struct LineStyle));    if (reader->read(reader, &(p->Width), 2) !=2 )        return gg_error();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -