| | 204 | static inline int mpeg1_decode_block_intra(MpegEncContext *s, |
| | 205 | DCTELEM *block, |
| | 206 | int n) |
| | 207 | { |
| | 208 | int level, dc, diff, i, j, run; |
| | 209 | int component; |
| | 210 | RLTable *rl = &ff_rl_mpeg1; |
| | 211 | uint8_t * const scantable= s->intra_scantable.permutated; |
| | 212 | const uint16_t *quant_matrix= s->intra_matrix; |
| | 213 | const int qscale= s->qscale; |
| | 215 | /* DC coefficient */ |
| | 216 | component = (n <= 3 ? 0 : n - 4 + 1); |
| | 217 | diff = decode_dc(&s->gb, component); |
| | 218 | if (diff >= 0xffff) |
| | 219 | return -1; |
| | 220 | dc = s->last_dc[component]; |
| | 221 | dc += diff; |
| | 222 | s->last_dc[component] = dc; |
| | 223 | block[0] = dc*quant_matrix[0]; |
| | 224 | dprintf(s->avctx, "dc=%d diff=%d\n", dc, diff); |
| | 225 | i = 0; |
| | 226 | { |
| | 227 | OPEN_READER(re, &s->gb); |
| | 228 | /* now quantify & encode AC coefficients */ |
| | 229 | for(;;) { |
| | 230 | UPDATE_CACHE(re, &s->gb); |
| | 231 | GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); |
| | 232 | |
| | 233 | if(level == 127){ |
| | 234 | break; |
| | 235 | } else if(level != 0) { |
| | 236 | i += run; |
| | 237 | j = scantable[i]; |
| | 238 | level= (level*qscale*quant_matrix[j])>>4; |
| | 239 | level= (level-1)|1; |
| | 240 | level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); |
| | 241 | LAST_SKIP_BITS(re, &s->gb, 1); |
| | 242 | } else { |
| | 243 | /* escape */ |
| | 244 | run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6); |
| | 245 | UPDATE_CACHE(re, &s->gb); |
| | 246 | level = SHOW_SBITS(re, &s->gb, 8); SKIP_BITS(re, &s->gb, 8); |
| | 247 | if (level == -128) { |
| | 248 | level = SHOW_UBITS(re, &s->gb, 8) - 256; LAST_SKIP_BITS(re, &s->gb, 8); |
| | 249 | } else if (level == 0) { |
| | 250 | level = SHOW_UBITS(re, &s->gb, 8) ; LAST_SKIP_BITS(re, &s->gb, 8); |
| | 251 | } |
| | 252 | i += run; |
| | 253 | j = scantable[i]; |
| | 254 | if(level<0){ |
| | 255 | level= -level; |
| | 256 | level= (level*qscale*quant_matrix[j])>>4; |
| | 257 | level= (level-1)|1; |
| | 258 | level= -level; |
| | 259 | }else{ |
| | 260 | level= (level*qscale*quant_matrix[j])>>4; |
| | 261 | level= (level-1)|1; |
| | 262 | } |
| | 263 | } |
| | 264 | if (i > 63){ |
| | 265 | av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y); |
| | 266 | return -1; |
| | 267 | } |
| | 268 | |
| | 269 | block[j] = level; |
| | 270 | } |
| | 271 | CLOSE_READER(re, &s->gb); |
| | 272 | } |
| | 273 | s->block_last_index[n] = i; |
| | 274 | return 0; |
| | 275 | } |
| | 276 | |
| 608 | | static inline int mpeg1_decode_block_intra(MpegEncContext *s, |
| 609 | | DCTELEM *block, |
| 610 | | int n) |
| 611 | | { |
| 612 | | int level, dc, diff, i, j, run; |
| 613 | | int component; |
| 614 | | RLTable *rl = &ff_rl_mpeg1; |
| 615 | | uint8_t * const scantable= s->intra_scantable.permutated; |
| 616 | | const uint16_t *quant_matrix= s->intra_matrix; |
| 617 | | const int qscale= s->qscale; |
| 619 | | /* DC coefficient */ |
| 620 | | component = (n <= 3 ? 0 : n - 4 + 1); |
| 621 | | diff = decode_dc(&s->gb, component); |
| 622 | | if (diff >= 0xffff) |
| 623 | | return -1; |
| 624 | | dc = s->last_dc[component]; |
| 625 | | dc += diff; |
| 626 | | s->last_dc[component] = dc; |
| 627 | | block[0] = dc*quant_matrix[0]; |
| 628 | | dprintf(s->avctx, "dc=%d diff=%d\n", dc, diff); |
| 629 | | i = 0; |
| 630 | | { |
| 631 | | OPEN_READER(re, &s->gb); |
| 632 | | /* now quantify & encode AC coefficients */ |
| 633 | | for(;;) { |
| 634 | | UPDATE_CACHE(re, &s->gb); |
| 635 | | GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); |
| 636 | | |
| 637 | | if(level == 127){ |
| 638 | | break; |
| 639 | | } else if(level != 0) { |
| 640 | | i += run; |
| 641 | | j = scantable[i]; |
| 642 | | level= (level*qscale*quant_matrix[j])>>4; |
| 643 | | level= (level-1)|1; |
| 644 | | level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); |
| 645 | | LAST_SKIP_BITS(re, &s->gb, 1); |
| 646 | | } else { |
| 647 | | /* escape */ |
| 648 | | run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6); |
| 649 | | UPDATE_CACHE(re, &s->gb); |
| 650 | | level = SHOW_SBITS(re, &s->gb, 8); SKIP_BITS(re, &s->gb, 8); |
| 651 | | if (level == -128) { |
| 652 | | level = SHOW_UBITS(re, &s->gb, 8) - 256; LAST_SKIP_BITS(re, &s->gb, 8); |
| 653 | | } else if (level == 0) { |
| 654 | | level = SHOW_UBITS(re, &s->gb, 8) ; LAST_SKIP_BITS(re, &s->gb, 8); |
| 655 | | } |
| 656 | | i += run; |
| 657 | | j = scantable[i]; |
| 658 | | if(level<0){ |
| 659 | | level= -level; |
| 660 | | level= (level*qscale*quant_matrix[j])>>4; |
| 661 | | level= (level-1)|1; |
| 662 | | level= -level; |
| 663 | | }else{ |
| 664 | | level= (level*qscale*quant_matrix[j])>>4; |
| 665 | | level= (level-1)|1; |
| 666 | | } |
| 667 | | } |
| 668 | | if (i > 63){ |
| 669 | | av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y); |
| 670 | | return -1; |
| 671 | | } |
| 672 | | |
| 673 | | block[j] = level; |
| 674 | | } |
| 675 | | CLOSE_READER(re, &s->gb); |
| 676 | | } |
| 677 | | s->block_last_index[n] = i; |
| 678 | | return 0; |
| 679 | | } |
| 680 | | |