X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fh.263%2Fswfvideo.c;h=c928a3fa44b0570ef6687e0fc92c49b009e8e42a;hb=d71ba2887f2fd86de49a1b456fd91febcb145786;hp=6e2149429d9c88dcd181dda5918e1ab732421d53;hpb=675cc23f423cc699b0ad29e61adf185fdfbfc25f;p=swftools.git diff --git a/lib/h.263/swfvideo.c b/lib/h.263/swfvideo.c index 6e21494..c928a3f 100644 --- a/lib/h.263/swfvideo.c +++ b/lib/h.263/swfvideo.c @@ -816,6 +816,9 @@ static void predictmvd(VIDEOSTREAM*s, int bx, int by, int*px, int*py) static inline int mvd2index(int px, int py, int x, int y, int xy) { + + if((x<-32 && x>31) || (y<-32 && y>31)) + fprintf(stderr, "(%d,%d)\n", x,y); assert((x>=-32 && x<=31) && (y>=-32 && y<=31)); //assert((x&1)==0 && (y&1)==0);//for now //assert((x&2)==0 && (y&2)==0);//for now(2) @@ -1055,9 +1058,9 @@ void prepareMVDBlock(VIDEOSTREAM*s, mvdblockdata_t*data, int bx, int by, block_t int writeMVDBlock(VIDEOSTREAM*s, TAG*tag, mvdblockdata_t*data) { int c = 0, y = 0; - /* mvd (0,0) block (mode=0) */ int t; int has_dc=0; // mvd w/o mvd24 + /* mvd (0,0) block (mode=0) */ int mode = 0; int bx = data->bx; int by = data->by; @@ -1265,12 +1268,13 @@ void swf_SetVideoStreamPFrame(TAG*tag, VIDEOSTREAM*s, RGBA*pic, int quant) #endif } -void swf_SetVideoStreamMover(TAG*tag, VIDEOSTREAM*s, signed char* movex, signed char* movey, int quant) +void swf_SetVideoStreamMover(TAG*tag, VIDEOSTREAM*s, signed char* movex, signed char* movey, void**picture, int quant) { int bx, by; if(quant<1) quant=1; if(quant>31) quant=31; + s->quant = quant; writeHeader(tag, s->width, s->height, s->frame, quant, TYPE_PFRAME); @@ -1281,29 +1285,63 @@ void swf_SetVideoStreamMover(TAG*tag, VIDEOSTREAM*s, signed char* movex, signed { for(bx=0;bxbbx;bx++) { - if(!(by==31)) { - /* mvd (0,0) block (mode=0) */ - int t; - int mode = 0; - int has_dc = 0; - int cbpybits=0,cbpcbits=0; - int predictmvdx, predictmvdy; - int mvx=movex[by*s->bbx+bx]; - int mvy=movey[by*s->bbx+bx]; + int predictmvdx=0, predictmvdy=0; + int mvx=movex[by*s->bbx+bx]; + int mvy=movey[by*s->bbx+bx]; + + if(mvx<-32) mvx=-32; + if(mvx>31) mvx=31; + if(mvy<-32) mvy=-32; + if(mvy>31) mvy=31; + if(mvx == 0 && mvy == 0 && picture == 0) { + swf_SetBits(tag,1,1); // COD skip + } else { + int mode = 0; + int has_dc=0; + int y=0,c=0; + block_t b; + block_t b2; + swf_SetBits(tag,0,1); // COD - codehuffman(tag, mcbpc_inter, mode*4+cbpcbits); - codehuffman(tag, cbpy, cbpybits^15); - - /* vector */ - predictmvd(s,bx,by,&predictmvdx,&predictmvdy); - codehuffman(tag, mvd, mvd2index(predictmvdx, predictmvdy, mvx, mvy, 0)); - codehuffman(tag, mvd, mvd2index(predictmvdx, predictmvdy, mvx, mvy, 1)); - s->mvdx[by*s->bbx+bx] = mvx; - s->mvdy[by*s->bbx+bx] = mvy; + + if(mvx==0 && mvy==0) { // only picture + mode = 3; + has_dc = 1; + } + + if(picture) { + /* todo: store picture in b */ + dodctandquant(&b, &b2, 1, s->quant); + getblockpatterns(&b2, &y, &c, 1); + } else { + y=0;c=0; + } + + codehuffman(tag, mcbpc_inter, mode*4+c); + codehuffman(tag, cbpy, y^15); + + if(mode < 3) { + /* has motion vector */ + predictmvd(s,bx,by,&predictmvdx,&predictmvdy); + codehuffman(tag, mvd, mvd2index(predictmvdx, predictmvdy, mvx, mvy, 0)); + codehuffman(tag, mvd, mvd2index(predictmvdx, predictmvdy, mvx, mvy, 1)); + s->mvdx[by*s->bbx+bx] = mvx; + s->mvdy[by*s->bbx+bx] = mvy; + } + + if(picture) { + encode8x8(tag, b2.y1, has_dc, y&8); + encode8x8(tag, b2.y2, has_dc, y&4); + encode8x8(tag, b2.y3, has_dc, y&2); + encode8x8(tag, b2.y4, has_dc, y&1); + encode8x8(tag, b2.u, has_dc, c&2); + encode8x8(tag, b2.v, has_dc, c&1); + } } } } + s->frame++; } #define TESTS @@ -1352,6 +1390,81 @@ void test_copy_diff() #ifdef MAIN #include "png.h" + +int compileSWFActionCode(const char *script, int version, void**data, int*len) {return 0;} + +void mkblack() +{ + SWF swf; + SWFPLACEOBJECT obj; + int frames = 88; + int width = 160; + int height = 112; + int x,y; + TAG*tag = 0; + RGBA rgb; + RGBA* pic = 0; + VIDEOSTREAM stream; + + pic = malloc(width*height*4); + memset(pic, 0, width*height*4); + + memset(&swf,0,sizeof(SWF)); + memset(&obj,0,sizeof(obj)); + + swf.fileVersion = 6; + swf.frameRate = 15*256; + swf.movieSize.xmax = 20*width; + swf.movieSize.ymax = 20*height; + + swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR); + tag = swf.firstTag; + rgb.r = 0x00;rgb.g = 0x30;rgb.b = 0xff; + swf_SetRGB(tag,&rgb); + + tag = swf_InsertTag(tag, ST_DEFINEVIDEOSTREAM); + swf_SetU16(tag, 1); + swf_SetVideoStreamDefine(tag, &stream, frames, width, height); + stream.do_motion = 0; + + for(y=0;y