X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=common%2Fcabac.h;h=9d0fddd2899038687f2882bc86e0f4332de111a5;hb=79704fa50d50a6ae756643ad69f0170e5af831fd;hp=9de99b330d39d2472d9ae9f7bc213c0bba84be39;hpb=9e7cfc35e955c3693b5690c233cc0049be222bce;p=x264 diff --git a/common/cabac.h b/common/cabac.h index 9de99b33..9d0fddd2 100644 --- a/common/cabac.h +++ b/common/cabac.h @@ -1,10 +1,10 @@ /***************************************************************************** * cabac.h: h264 encoder library ***************************************************************************** - * Copyright (C) 2003 Laurent Aimar - * $Id: cabac.h,v 1.1 2004/06/03 19:27:06 fenrir Exp $ + * Copyright (C) 2003-2008 x264 project * - * Authors: Laurent Aimar + * Authors: Loren Merritt + * Laurent Aimar * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,19 +18,14 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. *****************************************************************************/ -#ifndef _CABAC_H -#define _CABAC_H 1 +#ifndef X264_CABAC_H +#define X264_CABAC_H typedef struct { - /* context */ - DECLARE_ALIGNED_16( uint8_t state[460] ); - - int f8_bits_encoded; // only if using x264_cabac_size_decision() - /* state */ int i_low; int i_range; @@ -43,21 +38,35 @@ typedef struct uint8_t *p; uint8_t *p_end; + /* aligned for memcpy_aligned starting here */ + DECLARE_ALIGNED_16( int f8_bits_encoded ); // only if using x264_cabac_size_decision() + + /* context */ + uint8_t state[460]; } x264_cabac_t; -extern const uint8_t x264_cabac_transition[2][128]; -extern const uint16_t x264_cabac_entropy[2][128]; +extern const uint8_t x264_cabac_transition[128][2]; +extern const uint16_t x264_cabac_entropy[128][2]; /* init the contexts given i_slice_type, the quantif and the model */ void x264_cabac_context_init( x264_cabac_t *cb, int i_slice_type, int i_qp, int i_model ); /* encoder only: */ void x264_cabac_encode_init ( x264_cabac_t *cb, uint8_t *p_data, uint8_t *p_end ); -void x264_cabac_encode_decision( x264_cabac_t *cb, int i_ctx, int b ); +void x264_cabac_encode_decision_c( x264_cabac_t *cb, int i_ctx, int b ); +void x264_cabac_encode_decision_asm( x264_cabac_t *cb, int i_ctx, int b ); void x264_cabac_encode_bypass( x264_cabac_t *cb, int b ); +void x264_cabac_encode_ue_bypass( x264_cabac_t *cb, int exp_bits, int val ); void x264_cabac_encode_terminal( x264_cabac_t *cb ); void x264_cabac_encode_flush( x264_t *h, x264_cabac_t *cb ); +#ifdef HAVE_MMX +#define x264_cabac_encode_decision x264_cabac_encode_decision_asm +#else +#define x264_cabac_encode_decision x264_cabac_encode_decision_c +#endif +#define x264_cabac_encode_decision_noup x264_cabac_encode_decision + static inline int x264_cabac_pos( x264_cabac_t *cb ) { return (cb->p - cb->p_start + cb->i_bytes_outstanding) * 8 + cb->i_queue; @@ -68,20 +77,26 @@ static inline int x264_cabac_pos( x264_cabac_t *cb ) static inline void x264_cabac_size_decision( x264_cabac_t *cb, long i_ctx, long b ) { int i_state = cb->state[i_ctx]; - cb->state[i_ctx] = x264_cabac_transition[b][i_state]; - cb->f8_bits_encoded += x264_cabac_entropy[b][i_state]; + cb->state[i_ctx] = x264_cabac_transition[i_state][b]; + cb->f8_bits_encoded += x264_cabac_entropy[i_state][b]; } static inline int x264_cabac_size_decision2( uint8_t *state, long b ) { int i_state = *state; - *state = x264_cabac_transition[b][i_state]; - return x264_cabac_entropy[b][i_state]; + *state = x264_cabac_transition[i_state][b]; + return x264_cabac_entropy[i_state][b]; +} + +static inline void x264_cabac_size_decision_noup( x264_cabac_t *cb, long i_ctx, long b ) +{ + int i_state = cb->state[i_ctx]; + cb->f8_bits_encoded += x264_cabac_entropy[i_state][b]; } -static inline int x264_cabac_size_decision_noup( uint8_t *state, long b ) +static inline int x264_cabac_size_decision_noup2( uint8_t *state, long b ) { - return x264_cabac_entropy[b][*state]; + return x264_cabac_entropy[*state][b]; } #endif