int SWFInput_readBits(SWFInput input, int number) { int ret = input->buffer; if ( number == input->bufbits ) { input->bufbits = 0; input->buffer = 0; return ret; } if ( number > input->bufbits ) { number -= input->bufbits; while( number > 8 ) { ret <<= 8; ret += SWFInput_getChar(input); number -= 8; } input->buffer = SWFInput_getChar(input); if ( number > 0 ) { ret <<= number; input->bufbits = 8-number; ret += input->buffer >> (8-number); input->buffer &= (1<<input->bufbits)-1; }
static void write_mp3(SWFSoundStreamBlock streamblock, SWFByteOutputMethod method, void *data) { SWFInput input = streamblock->stream->source.mp3.input; int l = streamblock->length; for ( ; l>0; --l ) method((unsigned char)SWFInput_getChar(input), data); }
static void writeSWFDBLBitmapToMethod(SWFBlock block, SWFByteOutputMethod method, void *data) { SWFDBLBitmap dbl = (SWFDBLBitmap)block; int i; methodWriteUInt16(CHARACTERID(dbl), method, data); /* just dump the rest of the file */ for ( i=block->length-2; i>0; --i ) method((unsigned char)SWFInput_getChar(dbl->input), data); }
static void write_flv(SWFSoundStreamBlock streamblock, SWFByteOutputMethod method, void *data) { SWFInput input; FLVStream *flv = streamblock->stream->source.flv.stream; FLVTag *tag = &streamblock->stream->source.flv.tag; int tagOffset = streamblock->stream->source.flv.tagOffset; int l = streamblock->length; int ret; if(tagOffset < 0) { ret = FLVStream_nextTagType(flv, tag, NULL, FLV_AUDIOTAG); if(ret < 0) return; } input = FLVTag_getPayloadInput(tag); if(input == NULL) return; if(tagOffset > 0) SWFInput_seek(input, tagOffset, SEEK_SET); while( l>0 ) { int ichar = SWFInput_getChar(input); if(ichar != EOF) { method(ichar, data); l--; continue; } ret = FLVStream_nextTagType(flv, tag, tag, FLV_AUDIOTAG); if(ret < 0) return; input = FLVTag_getPayloadInput(tag); if(input == NULL) return; } streamblock->stream->source.flv.tag = *tag; streamblock->stream->source.flv.tagOffset = SWFInput_tell(input); }
SWFDBLBitmap newSWFDBLBitmap_fromInput(SWFInput input) { SWFDBLBitmap dbl; int version; int width, height; dbl = (SWFDBLBitmap)malloc(sizeof(struct SWFDBLBitmap_s)); SWFCharacterInit((SWFCharacter)dbl); CHARACTERID(dbl) = ++SWF_gNumCharacters; BLOCK(dbl)->writeBlock = writeSWFDBLBitmapToMethod; BLOCK(dbl)->complete = completeSWFDBLBitmap; BLOCK(dbl)->dtor = (destroySWFBlockMethod) destroySWFCharacter; dbl->input = input; if ( SWFInput_getChar(input) != 'D' || SWFInput_getChar(input) != 'B' ) { SWF_error("File is not a DBL file!"); } version = SWFInput_getChar(input); if ( version != 'L' && version != 'l' ) SWF_error("File is not a DBL file!"); switch ( SWFInput_getChar(input) ) { case 1: BLOCK(dbl)->type = SWF_DEFINELOSSLESS; break; case 2: BLOCK(dbl)->type = SWF_DEFINELOSSLESS2; break; default: SWF_error("Unexpected DBL type byte!"); } if ( version == 'l' ) { BLOCK(dbl)->length = SWFInput_getUInt32_BE(input); BLOCK(dbl)->length += 2; /* character id */ } else { /* first version used a 2-byte file length.. brilliant, eh? */ BLOCK(dbl)->length = SWFInput_getUInt16_BE(input); BLOCK(dbl)->length += 2; /* character id */ } SWFInput_getChar(input); /* format */ width = SWFInput_getUInt16(input); height = SWFInput_getUInt16(input); /* roll back to beginning of dbl data */ SWFInput_seek(input, -5, SEEK_CUR); CHARACTER(dbl)->bounds = newSWFRect(0, width, 0, height); return dbl; }