- 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);
+
+ if(mvx==0 && mvy==0 && picture) { // only picture
+ mode = 3;
+ has_dc = 1;
+ }
+
+ if(picture) {
+ RGBA* picblock = (RGBA*)picture;
+ rgb2yuv(pic, picblock,16,16,16,16);
+ /* TODO: if has_dc!=1, subtract 128 from rgb values */
+ getregion(&b, pic, 0,0,16);
+ 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, mode==3?y: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(has_dc||y||c) {
+ 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);
+ }