summaryrefslogtreecommitdiff
path: root/libavcodec/h264_cavlc.c
diff options
context:
space:
mode:
authorOskar Arvidsson <oskar@irock.se>2011-03-29 17:48:57 +0200
committerRonald S. Bultje <rsbultje@gmail.com>2011-05-10 07:24:33 -0400
commit6e3ef511d787ff632547059f8730396ff4498e70 (patch)
treebda396b13aaa01e8dccbd60d697a543eff7643db /libavcodec/h264_cavlc.c
parent44ca80df3445a59bc065924d8c6110fa10367d01 (diff)
Add the notion of pixel size in h264 related functions.
In high bit depth the pixels will not be stored in uint8_t like in the normal case, but in uint16_t. The pixel size is thus 1 in normal bit depth and 2 in high bit depth. Preparatory patch for high bit depth h264 decoding support. Signed-off-by: Ronald S. Bultje <rsbultje@gmail.com>
Diffstat (limited to 'libavcodec/h264_cavlc.c')
-rw-r--r--libavcodec/h264_cavlc.c84
1 files changed, 47 insertions, 37 deletions
diff --git a/libavcodec/h264_cavlc.c b/libavcodec/h264_cavlc.c
index 15d84ac32c..61b057176b 100644
--- a/libavcodec/h264_cavlc.c
+++ b/libavcodec/h264_cavlc.c
@@ -488,37 +488,44 @@ static int decode_residual(H264Context *h, GetBitContext *gb, DCTELEM *block, in
zeros_left= get_vlc2(gb, (total_zeros_vlc-1)[ total_coeff ].table, TOTAL_ZEROS_VLC_BITS, 1);
}
- scantable += zeros_left + total_coeff - 1;
- if(n >= LUMA_DC_BLOCK_INDEX){
- block[*scantable] = level[0];
- for(i=1;i<total_coeff && zeros_left > 0;i++) {
- if(zeros_left < 7)
- run_before= get_vlc2(gb, (run_vlc-1)[zeros_left].table, RUN_VLC_BITS, 1);
- else
- run_before= get_vlc2(gb, run7_vlc.table, RUN7_VLC_BITS, 2);
- zeros_left -= run_before;
- scantable -= 1 + run_before;
- block[*scantable]= level[i];
- }
- for(;i<total_coeff;i++) {
- scantable--;
- block[*scantable]= level[i];
- }
- }else{
- block[*scantable] = (level[0] * qmul[*scantable] + 32)>>6;
- for(i=1;i<total_coeff && zeros_left > 0;i++) {
- if(zeros_left < 7)
- run_before= get_vlc2(gb, (run_vlc-1)[zeros_left].table, RUN_VLC_BITS, 1);
- else
- run_before= get_vlc2(gb, run7_vlc.table, RUN7_VLC_BITS, 2);
- zeros_left -= run_before;
- scantable -= 1 + run_before;
- block[*scantable]= (level[i] * qmul[*scantable] + 32)>>6;
- }
- for(;i<total_coeff;i++) {
- scantable--;
- block[*scantable]= (level[i] * qmul[*scantable] + 32)>>6;
- }
+#define STORE_BLOCK(type) \
+ scantable += zeros_left + total_coeff - 1; \
+ if(n >= LUMA_DC_BLOCK_INDEX){ \
+ ((type*)block)[*scantable] = level[0]; \
+ for(i=1;i<total_coeff && zeros_left > 0;i++) { \
+ if(zeros_left < 7) \
+ run_before= get_vlc2(gb, (run_vlc-1)[zeros_left].table, RUN_VLC_BITS, 1); \
+ else \
+ run_before= get_vlc2(gb, run7_vlc.table, RUN7_VLC_BITS, 2); \
+ zeros_left -= run_before; \
+ scantable -= 1 + run_before; \
+ ((type*)block)[*scantable]= level[i]; \
+ } \
+ for(;i<total_coeff;i++) { \
+ scantable--; \
+ ((type*)block)[*scantable]= level[i]; \
+ } \
+ }else{ \
+ ((type*)block)[*scantable] = ((int)(level[0] * qmul[*scantable] + 32))>>6; \
+ for(i=1;i<total_coeff && zeros_left > 0;i++) { \
+ if(zeros_left < 7) \
+ run_before= get_vlc2(gb, (run_vlc-1)[zeros_left].table, RUN_VLC_BITS, 1); \
+ else \
+ run_before= get_vlc2(gb, run7_vlc.table, RUN7_VLC_BITS, 2); \
+ zeros_left -= run_before; \
+ scantable -= 1 + run_before; \
+ ((type*)block)[*scantable]= ((int)(level[i] * qmul[*scantable] + 32))>>6; \
+ } \
+ for(;i<total_coeff;i++) { \
+ scantable--; \
+ ((type*)block)[*scantable]= ((int)(level[i] * qmul[*scantable] + 32))>>6; \
+ } \
+ }
+
+ if (h->pixel_shift) {
+ STORE_BLOCK(int32_t)
+ } else {
+ STORE_BLOCK(int16_t)
}
if(zeros_left<0){
@@ -535,6 +542,7 @@ int ff_h264_decode_mb_cavlc(H264Context *h){
int partition_count;
unsigned int mb_type, cbp;
int dct8x8_allowed= h->pps.transform_8x8_mode;
+ const int pixel_shift = h->pixel_shift;
mb_xy = h->mb_xy = s->mb_x + s->mb_y*s->mb_stride;
@@ -605,7 +613,7 @@ decode_intra_mb:
align_get_bits(&s->gb);
// The pixels are stored in the same order as levels in h->mb array.
- for(x=0; x < (CHROMA ? 384 : 256); x++){
+ for(x=0; x < (CHROMA ? 384 : 256)*h->sps.bit_depth_luma/8; x++){
((uint8_t*)h->mb)[x]= get_bits(&s->gb, 8);
}
@@ -941,6 +949,8 @@ decode_intra_mb:
if(IS_INTRA16x16(mb_type)){
AV_ZERO128(h->mb_luma_dc+0);
AV_ZERO128(h->mb_luma_dc+8);
+ AV_ZERO128(h->mb_luma_dc+16);
+ AV_ZERO128(h->mb_luma_dc+24);
if( decode_residual(h, h->intra_gb_ptr, h->mb_luma_dc, LUMA_DC_BLOCK_INDEX, scan, h->dequant4_coeff[0][s->qscale], 16) < 0){
return -1; //FIXME continue if partitioned and other return -1 too
}
@@ -951,7 +961,7 @@ decode_intra_mb:
for(i8x8=0; i8x8<4; i8x8++){
for(i4x4=0; i4x4<4; i4x4++){
const int index= i4x4 + 4*i8x8;
- if( decode_residual(h, h->intra_gb_ptr, h->mb + 16*index, index, scan + 1, h->dequant4_coeff[0][s->qscale], 15) < 0 ){
+ if( decode_residual(h, h->intra_gb_ptr, h->mb + (16*index << pixel_shift), index, scan + 1, h->dequant4_coeff[0][s->qscale], 15) < 0 ){
return -1;
}
}
@@ -963,7 +973,7 @@ decode_intra_mb:
for(i8x8=0; i8x8<4; i8x8++){
if(cbp & (1<<i8x8)){
if(IS_8x8DCT(mb_type)){
- DCTELEM *buf = &h->mb[64*i8x8];
+ DCTELEM *buf = &h->mb[64*i8x8 << pixel_shift];
uint8_t *nnz;
for(i4x4=0; i4x4<4; i4x4++){
if( decode_residual(h, gb, buf, i4x4+4*i8x8, scan8x8+16*i4x4,
@@ -976,7 +986,7 @@ decode_intra_mb:
for(i4x4=0; i4x4<4; i4x4++){
const int index= i4x4 + 4*i8x8;
- if( decode_residual(h, gb, h->mb + 16*index, index, scan, h->dequant4_coeff[IS_INTRA( mb_type ) ? 0:3][s->qscale], 16) <0 ){
+ if( decode_residual(h, gb, h->mb + (16*index << pixel_shift), index, scan, h->dequant4_coeff[IS_INTRA( mb_type ) ? 0:3][s->qscale], 16) <0 ){
return -1;
}
}
@@ -990,7 +1000,7 @@ decode_intra_mb:
if(cbp&0x30){
for(chroma_idx=0; chroma_idx<2; chroma_idx++)
- if( decode_residual(h, gb, h->mb + 256 + 16*4*chroma_idx, CHROMA_DC_BLOCK_INDEX+chroma_idx, chroma_dc_scan, NULL, 4) < 0){
+ if( decode_residual(h, gb, h->mb + ((256 + 16*4*chroma_idx) << pixel_shift), CHROMA_DC_BLOCK_INDEX+chroma_idx, chroma_dc_scan, NULL, 4) < 0){
return -1;
}
}
@@ -1000,7 +1010,7 @@ decode_intra_mb:
const uint32_t *qmul = h->dequant4_coeff[chroma_idx+1+(IS_INTRA( mb_type ) ? 0:3)][h->chroma_qp[chroma_idx]];
for(i4x4=0; i4x4<4; i4x4++){
const int index= 16 + 4*chroma_idx + i4x4;
- if( decode_residual(h, gb, h->mb + 16*index, index, scan + 1, qmul, 15) < 0){
+ if( decode_residual(h, gb, h->mb + (16*index << pixel_shift), index, scan + 1, qmul, 15) < 0){
return -1;
}
}