+void decode_block(TAG*tag, int pictype)
+{
+ int t;
+ int mb_type = -1, cbpc = -1;
+ int dbquant;
+ int cbpy_index, cbpy_value;
+ int intrablock = 0;
+ int type;
+ if(pictype == TYPE_INTER) /* non-intra pictures have a cod flag */
+ /* TODO: according to the flash spec, this field is always present */
+ {
+ int cod = swf_GetBits(tag, 1);
+ if(cod) {
+ printf(".");
+ return;
+ }
+ }
+ type = -1;
+
+ /* read mcbpc */
+
+ if(pictype == TYPE_INTRA) { /* I-frame */
+ type = gethuffvalue(tag, mcbpc_intra);
+ mb_type = mcbpc_intra_params[type].mb_type;
+ cbpc = mcbpc_intra_params[type].cbpc;
+ if(type == MCBPC_INTRA_STUFFING)
+ exit(1); //TODO: goto COD
+ }
+ else if(pictype == 1) { /* P-frame */
+ type = gethuffvalue(tag, mcbpc_inter);
+ mb_type = mcbpc_inter_params[type].mb_type;
+ cbpc = mcbpc_inter_params[type].cbpc;
+ if(type == MCBPC_INTER_STUFFING)
+ exit(1); //TODO: goto COD
+ }
+
+ if(mb_type == 3 || mb_type == 4)
+ {
+ intrablock = 1;
+ }
+
+ printf("%d", intrablock);
+
+ DEBUG printf("mcbpc type: %d mb_type:%d cbpc:%d\n", type, mb_type, cbpc);
+
+ /* read cbpy */
+
+ cbpy_index = gethuffvalue(tag, cbpy);
+ cbpy_value = cbpy_index;
+ if(!intrablock)
+ cbpy_value ^= 15;
+ DEBUG printf("cbpy value:%d (%d)\n", cbpy_value, cbpy_index);
+
+
+ /* I 0: 00 mcbpc/cbpy
+ P 0: 00 cod/mcbpc/cbpy/mvd
+ P 6: 10 cod/mcbpc/cbpy/dquant/mvd
+ P 8: 00 cod/mcbpc/cbpy/mvd/mvd24
+ */
+
+ /* quantizer */
+ if(has_quant[mb_type]) {
+ dbquant = swf_GetBits(tag, 2);
+ DEBUG printf("quantizer: %d\n", dbquant);
+ }
+
+ if(has_mvd[mb_type]&1) {
+ readMVD(tag); //horizontal
+ readMVD(tag); //vertical
+ }
+ if(has_mvd[mb_type]&2) {
+ /* only in advanced prediction mode */
+ readMVD(tag); //horizontal
+ readMVD(tag); //vertical
+ readMVD(tag); //horizontal
+ readMVD(tag); //vertical
+ readMVD(tag); //horizontal
+ readMVD(tag); //vertical
+ }
+
+ for(t=0;t<4;t++) {
+ int has_intradc = intrablock;
+ int has_tcoef = cbpy_value & (8>>t);
+ DEBUG printf("luminance%d ", t);
+ getCoefficient(tag, t, has_intradc, has_tcoef); /*luminance - affected by cbpy*/
+ DEBUG printf("\n");
+ }
+ for(t=0;t<2;t++) {
+ int has_intradc = intrablock;
+ int has_tcoef = cbpc & (2>>t);
+ DEBUG printf("chrominance%d ", t);
+ getCoefficient(tag, t, has_intradc, has_tcoef); /*chrominance - affected by mcbc*/
+ DEBUG printf("\n");
+ }
+}
+