X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fh.263%2Fswfvideo.c;h=a4c8df5b76b9f2b49b3cc9dfe745e1c5df06a8d9;hb=f7e02fdcc5f94e3129124abb157037d7b54553e9;hp=13f9de4d0077982e2b24adec1000eedc42c131d9;hpb=d7654648690a00456effd8c9067ef0d9eb2b6bd0;p=swftools.git diff --git a/lib/h.263/swfvideo.c b/lib/h.263/swfvideo.c index 13f9de4..a4c8df5 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) @@ -1265,8 +1268,7 @@ void swf_SetVideoStreamPFrame(TAG*tag, VIDEOSTREAM*s, RGBA*pic, int quant) #endif } -static int uline[64],vline[64],yline[64]; -void swf_SetVideoStreamMover(TAG*tag, VIDEOSTREAM*s, int quant) +void swf_SetVideoStreamMover(TAG*tag, VIDEOSTREAM*s, signed char* movex, signed char* movey, int quant) { int bx, by; @@ -1282,58 +1284,36 @@ void swf_SetVideoStreamMover(TAG*tag, VIDEOSTREAM*s, int quant) { for(bx=0;bxbbx;bx++) { - //if((lrand48()&255) || !(bx>8 && bx<24 && by>8 && by<24)) { - if(!(by==31)) { - /* mvd (0,0) block (mode=0) */ - int t; - int mode = 0; // mvd w/o mvd24 - int has_dc = 0; - int cbpybits=0,cbpcbits=0; - int predictmvdx, predictmvdy; - //int mvx=-1+(2*(s->frame&1)); - //int mvy=-1+((s->frame&2)); - int mvx=0;//(lrand48()%4)-2; - int mvy=3; + /* mvd (0,0) block (mode=0) */ + int mode = 0; + int has_dc = 0; + int cbpybits=0,cbpcbits=0; + 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) { + swf_SetBits(tag,1,1); // COD skip + } else { 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; - } else { - /* i block (mode=3) */ - int mode = 3; - int has_dc = 1; - int cbpybits,cbpcbits; - int t; - block_t b; - memset(&b, 0, sizeof(block_t)); - b.y1[0] = b.y2[0] = b.y3[0] = b.y4[0] = yline[bx]; - b.u[0] = uline[bx]; - b.v[0] = vline[bx]; - - getblockpatterns(&b, &cbpybits, &cbpcbits, has_dc); - swf_SetBits(tag,0,1); // COD - codehuffman(tag, mcbpc_inter, mode*4+cbpcbits); - codehuffman(tag, cbpy, cbpybits); - - /* luminance */ - encode8x8(tag, b.y1, has_dc, cbpybits&8); - encode8x8(tag, b.y2, has_dc, cbpybits&4); - encode8x8(tag, b.y3, has_dc, cbpybits&2); - encode8x8(tag, b.y4, has_dc, cbpybits&1); - - /* chrominance */ - encode8x8(tag, b.u, has_dc, cbpcbits&2); - encode8x8(tag, b.v, has_dc, cbpcbits&1); } } } + s->frame++; } #define TESTS @@ -1395,7 +1375,8 @@ int main(int argn, char*argv[]) int frames = 10; int framerate = 29; unsigned char*data; - char* fname = "/home/kramm/pics/peppers.png"; + char* fname = "/home/kramm/pics/peppers_fromjpg.png"; + //char* fname = "/home/kramm/pics/baboon.png"; VIDEOSTREAM stream; double d = 1.0; @@ -1419,11 +1400,11 @@ int main(int argn, char*argv[]) swf.fileVersion = 6; swf.frameRate = framerate*256; swf.movieSize.xmax = 20*width*2; - swf.movieSize.ymax = 20*height-20*64; + swf.movieSize.ymax = 20*height; swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR); tag = swf.firstTag; - rgb.r = 0x00;rgb.g = 0x00;rgb.b = 0x00; + rgb.r = 0x00;rgb.g = 0x30;rgb.b = 0xff; swf_SetRGB(tag,&rgb); tag = swf_InsertTag(tag, ST_DEFINEVIDEOSTREAM); @@ -1431,6 +1412,8 @@ int main(int argn, char*argv[]) swf_SetVideoStreamDefine(tag, &stream, frames, width, height); stream.do_motion = 0; + srand48(time(0)); + for(t=0;t