Mercurial > libavcodec.hg
comparison mpeg12.c @ 1410:524c904a66b8 libavcodec
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
note: completly untested, no demuxer yet
author | michaelni |
---|---|
date | Fri, 22 Aug 2003 14:59:04 +0000 |
parents | 62ea3b7d00f0 |
children | c2e63cb94d06 |
comparison
equal
deleted
inserted
replaced
1409:62ea3b7d00f0 | 1410:524c904a66b8 |
---|---|
817 static VLC mbincr_vlc; | 817 static VLC mbincr_vlc; |
818 static VLC mb_ptype_vlc; | 818 static VLC mb_ptype_vlc; |
819 static VLC mb_btype_vlc; | 819 static VLC mb_btype_vlc; |
820 static VLC mb_pat_vlc; | 820 static VLC mb_pat_vlc; |
821 | 821 |
822 static void init_vlcs(MpegEncContext *s) | 822 static void init_vlcs() |
823 { | 823 { |
824 static int done = 0; | 824 static int done = 0; |
825 | 825 |
826 if (!done) { | 826 if (!done) { |
827 done = 1; | 827 done = 1; |
1225 l = 1 << (shift+4); | 1225 l = 1 << (shift+4); |
1226 val = ((val + l)&(l*2-1)) - l; | 1226 val = ((val + l)&(l*2-1)) - l; |
1227 return val; | 1227 return val; |
1228 } | 1228 } |
1229 | 1229 |
1230 static inline int decode_dc(MpegEncContext *s, int component) | 1230 static inline int decode_dc(GetBitContext *gb, int component) |
1231 { | 1231 { |
1232 int code, diff; | 1232 int code, diff; |
1233 | 1233 |
1234 if (component == 0) { | 1234 if (component == 0) { |
1235 code = get_vlc2(&s->gb, dc_lum_vlc.table, DC_VLC_BITS, 2); | 1235 code = get_vlc2(gb, dc_lum_vlc.table, DC_VLC_BITS, 2); |
1236 } else { | 1236 } else { |
1237 code = get_vlc2(&s->gb, dc_chroma_vlc.table, DC_VLC_BITS, 2); | 1237 code = get_vlc2(gb, dc_chroma_vlc.table, DC_VLC_BITS, 2); |
1238 } | 1238 } |
1239 if (code < 0){ | 1239 if (code < 0){ |
1240 fprintf(stderr, "invalid dc code at %d %d\n", s->mb_x, s->mb_y); | 1240 fprintf(stderr, "invalid dc code at\n"); |
1241 return 0xffff; | 1241 return 0xffff; |
1242 } | 1242 } |
1243 if (code == 0) { | 1243 if (code == 0) { |
1244 diff = 0; | 1244 diff = 0; |
1245 } else { | 1245 } else { |
1246 diff = get_xbits(&s->gb, code); | 1246 diff = get_xbits(gb, code); |
1247 } | 1247 } |
1248 return diff; | 1248 return diff; |
1249 } | 1249 } |
1250 | 1250 |
1251 static inline int mpeg1_decode_block_intra(MpegEncContext *s, | 1251 static inline int mpeg1_decode_block_intra(MpegEncContext *s, |
1259 const uint16_t *quant_matrix= s->intra_matrix; | 1259 const uint16_t *quant_matrix= s->intra_matrix; |
1260 const int qscale= s->qscale; | 1260 const int qscale= s->qscale; |
1261 | 1261 |
1262 /* DC coef */ | 1262 /* DC coef */ |
1263 component = (n <= 3 ? 0 : n - 4 + 1); | 1263 component = (n <= 3 ? 0 : n - 4 + 1); |
1264 diff = decode_dc(s, component); | 1264 diff = decode_dc(&s->gb, component); |
1265 if (diff >= 0xffff) | 1265 if (diff >= 0xffff) |
1266 return -1; | 1266 return -1; |
1267 dc = s->last_dc[component]; | 1267 dc = s->last_dc[component]; |
1268 dc += diff; | 1268 dc += diff; |
1269 s->last_dc[component] = dc; | 1269 s->last_dc[component] = dc; |
1496 component = 0; | 1496 component = 0; |
1497 }else{ | 1497 }else{ |
1498 quant_matrix = s->chroma_intra_matrix; | 1498 quant_matrix = s->chroma_intra_matrix; |
1499 component = n - 3; | 1499 component = n - 3; |
1500 } | 1500 } |
1501 diff = decode_dc(s, component); | 1501 diff = decode_dc(&s->gb, component); |
1502 if (diff >= 0xffff) | 1502 if (diff >= 0xffff) |
1503 return -1; | 1503 return -1; |
1504 dc = s->last_dc[component]; | 1504 dc = s->last_dc[component]; |
1505 dc += diff; | 1505 dc += diff; |
1506 s->last_dc[component] = dc; | 1506 s->last_dc[component] = dc; |
1568 { | 1568 { |
1569 Mpeg1Context *s = avctx->priv_data; | 1569 Mpeg1Context *s = avctx->priv_data; |
1570 | 1570 |
1571 s->mpeg_enc_ctx.flags= avctx->flags; | 1571 s->mpeg_enc_ctx.flags= avctx->flags; |
1572 common_init(&s->mpeg_enc_ctx); | 1572 common_init(&s->mpeg_enc_ctx); |
1573 init_vlcs(&s->mpeg_enc_ctx); | 1573 init_vlcs(); |
1574 | 1574 |
1575 s->mpeg_enc_ctx_allocated = 0; | 1575 s->mpeg_enc_ctx_allocated = 0; |
1576 s->mpeg_enc_ctx.picture_number = 0; | 1576 s->mpeg_enc_ctx.picture_number = 0; |
1577 s->repeat_field = 0; | 1577 s->repeat_field = 0; |
1578 s->mpeg_enc_ctx.codec_id= avctx->codec->id; | 1578 s->mpeg_enc_ctx.codec_id= avctx->codec->id; |
2475 mpeg_decode_frame, | 2475 mpeg_decode_frame, |
2476 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED, | 2476 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED, |
2477 }; | 2477 }; |
2478 | 2478 |
2479 #endif | 2479 #endif |
2480 | |
2481 /* this is ugly i know, but the alternative is too make | |
2482 hundreds of vars global and prefix them with ff_mpeg1_ | |
2483 which is far uglier. */ | |
2484 #include "mdec.c" |