[xiph-commits] r14344 - in trunk: theora/lib theora/lib/dec
theora/lib/dec/x86 theora-exp/lib theora-exp/lib/x86
tterribe at svn.xiph.org
tterribe at svn.xiph.org
Fri Jan 4 10:00:30 PST 2008
Author: tterribe
Date: 2008-01-04 10:00:14 -0800 (Fri, 04 Jan 2008)
New Revision: 14344
Modified:
trunk/theora-exp/lib/encode.c
trunk/theora-exp/lib/internal.h
trunk/theora-exp/lib/mcenc.c
trunk/theora-exp/lib/state.c
trunk/theora-exp/lib/x86/mmxstate.c
trunk/theora/lib/dec/state.c
trunk/theora/lib/dec/x86/mmxstate.c
trunk/theora/lib/internal.h
Log:
Drastically simplify oc_state_get_mv_offsets().
Modified: trunk/theora/lib/dec/state.c
===================================================================
--- trunk/theora/lib/dec/state.c 2008-01-04 17:45:14 UTC (rev 14343)
+++ trunk/theora/lib/dec/state.c 2008-01-04 18:00:14 UTC (rev 14344)
@@ -713,22 +713,19 @@
/*Determines the offsets in an image buffer to use for motion compensation.
_state: The Theora state the offsets are to be computed with.
- _offset0: Returns the offset for the first buffer.
- _offset1: Returns the offset for the second buffer, if the motion vector
- has non-zero fractional components.
+ _offsets: Returns the offset for the buffer(s).
+ _offsets[0] is always set.
+ _offsets[1] is set if the motion vector has non-zero fractional
+ components.
_dx: The X component of the motion vector.
_dy: The Y component of the motion vector.
_ystride: The Y stride in the buffer the motion vector points into.
_pli: The color plane index.
Return: The number of offsets returned: 1 or 2.*/
-int oc_state_get_mv_offsets(oc_theora_state *_state,int *_offset0,
- int *_offset1,int _dx,int _dy,int _ystride,int _pli){
- int offset0;
- int offset1;
+int oc_state_get_mv_offsets(oc_theora_state *_state,int _offsets[2],
+ int _dx,int _dy,int _ystride,int _pli){
int xprec;
int yprec;
- int xsign;
- int ysign;
int xfrac;
int yfrac;
/*Here is a brief description of how Theora handles motion vectors:
@@ -749,55 +746,32 @@
precision in each component.*/
xprec=1+(!(_state->info.pixel_fmt&1)&!!_pli);
yprec=1+(!(_state->info.pixel_fmt&2)&!!_pli);
- /*These two variables are either 0 for a non-negative vector or all 1's for
- a negative one.*/
- xsign=-(_dx<0);
- ysign=-(_dy<0);
/*These two variables are either 0 if all the fractional bits are 0 or 1 if
any of them are non-zero.*/
xfrac=!!(_dx&(1<<xprec)-1);
yfrac=!!(_dy&(1<<yprec)-1);
- /*This branchless code is equivalent to:
- if(_dx<0){
- if(_dy<0){
- offset0=-(-_dx>>xprec)-(-_dy>>yprec)*_ystride;
- }
- else{
- offset0=-(-_dx>>xprec)+(_dy>>yprec)*_ystride;
- }
- }
- else{
- if(_dy<0){
- offset0=(_dx>>xprec)-(-_dy>>yprec)*_ystride;
- }
- else{
- offset0=(_dx>>xprec)+(_dy>>yprec)*_ystride;
- }
- }*/
- *_offset0=offset0=(_dx>>xprec)+(xfrac&xsign)+
- ((_dy>>yprec)+(yfrac&ysign))*_ystride;
+ _offsets[0]=(_dx>>xprec)+(_dy>>yprec)*_ystride;
if(xfrac||yfrac){
- int o[2];
/*This branchless code is equivalent to:
+ if(_dx<0)_offests[0]=-(-_dx>>xprec);
+ else _offsets[0]=(_dx>>xprec);
+ if(_dy<0)_offsets[0]-=(-_dy>>yprec)*_ystride;
+ else _offsets[0]+=(_dy>>yprec)*_ystride;
+ _offsets[1]=_offsets[0];
if(xfrac){
- if(_dx<0)offset1=offset0-1;
- else offset1=offset0+1;
+ if(_dx<0)_offsets[1]++;
+ else _offsets[1]--;
}
- else offset1=offset0;*/
- o[0]=offset0;
- o[1]=offset0+(xsign|1);
- offset1=o[xfrac];
- /*This branchless code is equivalent to:
if(yfrac){
- if(_dy<0)offset1-=ref_stride;
- else offset1+=ref_stride;
+ if(_dy<0)_offsets[1]+=_ystride;
+ else _offsets[1]-=_ystride;
}*/
- o[0]=offset1;
- o[1]=offset1+(_ystride&~ysign)-(_ystride&ysign);
- *_offset1=o[yfrac];
+ _offsets[1]=_offsets[0];
+ _offsets[_dx>=0]+=xfrac;
+ _offsets[_dy>=0]+=_ystride&-yfrac;
return 2;
}
- return 1;
+ else return 1;
}
void oc_state_frag_recon(oc_theora_state *_state, oc_fragment *_frag,
@@ -927,19 +901,18 @@
else{
int ref_framei;
int ref_ystride;
- int mvoffset0;
- int mvoffset1;
+ int mvoffsets[2];
ref_framei=_state->ref_frame_idx[OC_FRAME_FOR_MODE[_frag->mbmode]];
ref_ystride=_state->ref_frame_bufs[ref_framei][_pli].ystride;
- if(oc_state_get_mv_offsets(_state,&mvoffset0,&mvoffset1,_frag->mv[0],
- _frag->mv[1],ref_ystride,_pli)>1){
+ if(oc_state_get_mv_offsets(_state,mvoffsets,_frag->mv[0],_frag->mv[1],
+ ref_ystride,_pli)>1){
oc_frag_recon_inter2(_state,_frag->buffer[dst_framei],dst_ystride,
- _frag->buffer[ref_framei]+mvoffset0,ref_ystride,
- _frag->buffer[ref_framei]+mvoffset1,ref_ystride,res_buf);
+ _frag->buffer[ref_framei]+mvoffsets[0],ref_ystride,
+ _frag->buffer[ref_framei]+mvoffsets[1],ref_ystride,res_buf);
}
else{
oc_frag_recon_inter(_state,_frag->buffer[dst_framei],dst_ystride,
- _frag->buffer[ref_framei]+mvoffset0,ref_ystride,res_buf);
+ _frag->buffer[ref_framei]+mvoffsets[0],ref_ystride,res_buf);
}
}
oc_restore_fpu(_state);
Modified: trunk/theora/lib/dec/x86/mmxstate.c
===================================================================
--- trunk/theora/lib/dec/x86/mmxstate.c 2008-01-04 17:45:14 UTC (rev 14343)
+++ trunk/theora/lib/dec/x86/mmxstate.c 2008-01-04 18:00:14 UTC (rev 14344)
@@ -153,19 +153,18 @@
else{
int ref_framei;
int ref_ystride;
- int mvoffset0;
- int mvoffset1;
+ int mvoffsets[2];
ref_framei=_state->ref_frame_idx[OC_FRAME_FOR_MODE[_frag->mbmode]];
ref_ystride=_state->ref_frame_bufs[ref_framei][_pli].ystride;
- if(oc_state_get_mv_offsets(_state,&mvoffset0,&mvoffset1,_frag->mv[0],
- _frag->mv[1],ref_ystride,_pli)>1){
+ if(oc_state_get_mv_offsets(_state,mvoffsets,_frag->mv[0],_frag->mv[1],
+ ref_ystride,_pli)>1){
oc_frag_recon_inter2(_state,_frag->buffer[dst_framei],dst_ystride,
- _frag->buffer[ref_framei]+mvoffset0,ref_ystride,
- _frag->buffer[ref_framei]+mvoffset1,ref_ystride,res_buf);
+ _frag->buffer[ref_framei]+mvoffsets[0],ref_ystride,
+ _frag->buffer[ref_framei]+mvoffsets[1],ref_ystride,res_buf);
}
else{
oc_frag_recon_inter(_state,_frag->buffer[dst_framei],dst_ystride,
- _frag->buffer[ref_framei]+mvoffset0,ref_ystride,res_buf);
+ _frag->buffer[ref_framei]+mvoffsets[0],ref_ystride,res_buf);
}
}
oc_restore_fpu(_state);
Modified: trunk/theora/lib/internal.h
===================================================================
--- trunk/theora/lib/internal.h 2008-01-04 17:45:14 UTC (rev 14343)
+++ trunk/theora/lib/internal.h 2008-01-04 18:00:14 UTC (rev 14344)
@@ -427,8 +427,8 @@
void oc_state_fill_buffer_ptrs(oc_theora_state *_state,int _buf_idx,
th_ycbcr_buffer _img);
int oc_state_mbi_for_pos(oc_theora_state *_state,int _mbx,int _mby);
-int oc_state_get_mv_offsets(oc_theora_state *_state,int *_offset0,
- int *_offset1,int _dx,int _dy,int _ystride,int _pli);
+int oc_state_get_mv_offsets(oc_theora_state *_state,int *_offsets,
+ int _dx,int _dy,int _ystride,int _pli);
int oc_state_loop_filter_init(oc_theora_state *_state,int *_bv);
void oc_state_loop_filter(oc_theora_state *_state,int _frame);
Modified: trunk/theora-exp/lib/encode.c
===================================================================
--- trunk/theora-exp/lib/encode.c 2008-01-04 17:45:14 UTC (rev 14343)
+++ trunk/theora-exp/lib/encode.c 2008-01-04 18:00:14 UTC (rev 14344)
@@ -453,18 +453,17 @@
int src_ystride;
int ref_ystride;
int ref_framei;
- int mvoffset0;
- int mvoffset1;
+ int mvoffsets[2];
int y;
int x;
src_ystride=_enc->state.input[_pli].ystride;
ref_framei=_enc->state.ref_frame_idx[OC_FRAME_FOR_MODE[_frag->mbmode]];
ref_ystride=_enc->state.ref_frame_bufs[ref_framei][_pli].ystride;
src=_frag->buffer[OC_FRAME_IO];
- if(oc_state_get_mv_offsets(&_enc->state,&mvoffset0,&mvoffset1,
+ if(oc_state_get_mv_offsets(&_enc->state,mvoffsets,
_frag->mv[0],_frag->mv[1],ref_ystride,_pli)>1){
- ref0=_frag->buffer[ref_framei]+mvoffset0;
- ref1=_frag->buffer[ref_framei]+mvoffset1;
+ ref0=_frag->buffer[ref_framei]+mvoffsets[0];
+ ref1=_frag->buffer[ref_framei]+mvoffsets[1];
if(_frag->border!=NULL){
ogg_int64_t mask;
mask=_frag->border->mask;
@@ -493,7 +492,7 @@
}
}
else{
- ref0=_frag->buffer[ref_framei]+mvoffset0;
+ ref0=_frag->buffer[ref_framei]+mvoffsets[0];
if(_frag->border!=NULL){
ogg_int64_t mask;
mask=_frag->border->mask;
@@ -1136,32 +1135,31 @@
int cur_ystride;
int ref_ystride;
int ref_framei;
- int mvoffset0;
- int mvoffset1;
+ int mvoffsets[2];
cur_ystride=_enc->state.input[_pli].ystride;
ref_framei=_enc->state.ref_frame_idx[_frame];
ref_ystride=_enc->state.ref_frame_bufs[ref_framei][_pli].ystride;
- if(oc_state_get_mv_offsets(&_enc->state,&mvoffset0,&mvoffset1,_dx,_dy,
+ if(oc_state_get_mv_offsets(&_enc->state,mvoffsets,_dx,_dy,
ref_ystride,_pli)>1){
if(_frag->border==NULL){
return oc_sad8_halfpel(_frag->buffer[OC_FRAME_IO],cur_ystride,
- _frag->buffer[ref_framei]+mvoffset0,
- _frag->buffer[ref_framei]+mvoffset1,ref_ystride);
+ _frag->buffer[ref_framei]+mvoffsets[0],
+ _frag->buffer[ref_framei]+mvoffsets[1],ref_ystride);
}
else{
return oc_sad8_halfpel_border(_frag->buffer[OC_FRAME_IO],cur_ystride,
- _frag->buffer[ref_framei]+mvoffset0,
- _frag->buffer[ref_framei]+mvoffset1,ref_ystride,_frag->border->mask);
+ _frag->buffer[ref_framei]+mvoffsets[0],
+ _frag->buffer[ref_framei]+mvoffsets[1],ref_ystride,_frag->border->mask);
}
}
else{
if(_frag->border==NULL){
return oc_sad8_fullpel(_frag->buffer[OC_FRAME_IO],cur_ystride,
- _frag->buffer[ref_framei]+mvoffset0,ref_ystride);
+ _frag->buffer[ref_framei]+mvoffsets[0],ref_ystride);
}
else{
return oc_sad8_fullpel_border(_frag->buffer[OC_FRAME_IO],
- cur_ystride,_frag->buffer[ref_framei]+mvoffset0,ref_ystride,
+ cur_ystride,_frag->buffer[ref_framei]+mvoffsets[0],ref_ystride,
_frag->border->mask);
}
}
Modified: trunk/theora-exp/lib/internal.h
===================================================================
--- trunk/theora-exp/lib/internal.h 2008-01-04 17:45:14 UTC (rev 14343)
+++ trunk/theora-exp/lib/internal.h 2008-01-04 18:00:14 UTC (rev 14344)
@@ -391,8 +391,8 @@
void oc_state_fill_buffer_ptrs(oc_theora_state *_state,int _buf_idx,
th_ycbcr_buffer _img);
int oc_state_mbi_for_pos(oc_theora_state *_state,int _mbx,int _mby);
-int oc_state_get_mv_offsets(oc_theora_state *_state,int *_offset0,
- int *_offset1,int _dx,int _dy,int _ystride,int _pli);
+int oc_state_get_mv_offsets(oc_theora_state *_state,int _offsets[2],
+ int _dx,int _dy,int _ystride,int _pli);
int oc_state_loop_filter_init(oc_theora_state *_state,int *_bv);
void oc_state_loop_filter(oc_theora_state *_state,int _frame);
Modified: trunk/theora-exp/lib/mcenc.c
===================================================================
--- trunk/theora-exp/lib/mcenc.c 2008-01-04 17:45:14 UTC (rev 14343)
+++ trunk/theora-exp/lib/mcenc.c 2008-01-04 18:00:14 UTC (rev 14344)
@@ -254,8 +254,8 @@
(_vec[0]<<1)+dx,(_vec[1]<<1)+dy,ref_ystride,0);
However, it should also be much faster, as it involves no multiplies and
doesn't have to handle chroma vectors.*/
- xmask=((_vec[0]<<1)+OC_SQUARE_DX[site]>>6)^(dx>>1);
- ymask=((_vec[1]<<1)+OC_SQUARE_DY[site]>>6)^(dy>>1);
+ xmask=-((((_vec[0]<<1)+dx)^dx)<0);
+ ymask=-((((_vec[1]<<1)+dy)^dy)<0);
mvoffset0=mvoffset_base+(dx&xmask)+(offset_y[site]&ymask);
mvoffset1=mvoffset_base+(dx&~xmask)+(offset_y[site]&~ymask);
err=oc_sad16_halfpel(frags,mb_map,cur_ystride,ref_ystride,mvoffset0,
@@ -308,8 +308,8 @@
(_vec[0]<<1)+dx,(_vec[1]<<1)+dy,ref_ystride,0);
However, it should also be much faster, as it involves no multiplies and
doesn't have to handle chroma vectors.*/
- xmask=((_vec[0]<<1)+OC_SQUARE_DX[site]>>6)^(dx>>1);
- ymask=((_vec[1]<<1)+OC_SQUARE_DY[site]>>6)^(dy>>1);
+ xmask=-((((_vec[0]<<1)+dx)^dx)<0);
+ ymask=-((((_vec[1]<<1)+dy)^dy)<0);
mvoffset0=mvoffset_base+(dx&xmask)+(offset_y[site]&ymask);
mvoffset1=mvoffset_base+(dx&~xmask)+(offset_y[site]&~ymask);
if(frag->border==NULL){
Modified: trunk/theora-exp/lib/state.c
===================================================================
--- trunk/theora-exp/lib/state.c 2008-01-04 17:45:14 UTC (rev 14343)
+++ trunk/theora-exp/lib/state.c 2008-01-04 18:00:14 UTC (rev 14344)
@@ -685,24 +685,19 @@
/*Determines the offsets in an image buffer to use for motion compensation.
_state: The Theora state the offsets are to be computed with.
- _offset0: Returns the offset for the first buffer.
- _offset1: Returns the offset for the second buffer, if the motion vector
- has non-zero fractional components.
+ _offsets: Returns the offset for the buffer(s).
+ _offsets[0] is always set.
+ _offsets[1] is set if the motion vector has non-zero fractional
+ components.
_dx: The X component of the motion vector.
_dy: The Y component of the motion vector.
_ystride: The Y stride in the buffer the motion vector points into.
_pli: The color plane index.
Return: The number of offsets returned: 1 or 2.*/
-int oc_state_get_mv_offsets(oc_theora_state *_state,int *_offset0,
- int *_offset1,int _dx,int _dy,int _ystride,int _pli){
- static const int MV_SHIFT[6]={1,2};
- static const int MV_MASK[6]={1,3};
- int offset0;
- int offset1;
- int xtype;
- int ytype;
- int xsign;
- int ysign;
+int oc_state_get_mv_offsets(oc_theora_state *_state,int _offsets[2],
+ int _dx,int _dy,int _ystride,int _pli){
+ int xprec;
+ int yprec;
int xfrac;
int yfrac;
/*Here is a brief description of how Theora handles motion vectors:
@@ -721,57 +716,34 @@
appropriate amount, always truncating _away_ from zero.*/
/*These two variables decide whether we are in half- or quarter-pixel
precision in each component.*/
- xtype=!(_state->info.pixel_fmt&1)&!!_pli;
- ytype=!(_state->info.pixel_fmt&2)&!!_pli;
- /*These two variables are either 0 for a non-negative vector or all 1's for
- a negative one.*/
- xsign=_dx>>6;
- ysign=_dy>>6;
+ xprec=1+(!(_state->info.pixel_fmt&1)&!!_pli);
+ yprec=1+(!(_state->info.pixel_fmt&2)&!!_pli);
/*These two variables are either 0 if all the fractional bits are 0 or 1 if
any of them are non-zero.*/
- xfrac=!!(_dx&MV_MASK[xtype]);
- yfrac=!!(_dy&MV_MASK[ytype]);
- /*This branchless code is equivalent to:
- if(_dx<0){
- if(_dy<0){
- offset0=-(-_dx>>MV_SHIFT[xtype])-(-_dy>>MV_SHIFT[ytype])*_ystride;
- }
- else{
- offset0=-(-_dx>>MV_SHIFT[xtype])+(_dy>>MV_SHIFT[ytype])*_ystride;
- }
- }
- else{
- if(_dy<0){
- offset0=(_dx>>MV_SHIFT[xtype])-(-_dy>>MV_SHIFT[ytype])*_ystride;
- }
- else{
- offset0=(_dx>>MV_SHIFT[xtype])+(_dy>>MV_SHIFT[ytype])*_ystride;
- }
- }*/
- *_offset0=offset0=(_dx>>MV_SHIFT[xtype])+(xfrac&xsign)+
- ((_dy>>MV_SHIFT[ytype])+(yfrac&ysign))*_ystride;
+ xfrac=!!(_dx&(1<<xprec)-1);
+ yfrac=!!(_dy&(1<<yprec)-1);
+ _offsets[0]=(_dx>>xprec)+(_dy>>yprec)*_ystride;
if(xfrac||yfrac){
- int o[2];
/*This branchless code is equivalent to:
+ if(_dx<0)_offests[0]=-(-_dx>>xprec);
+ else _offsets[0]=(_dx>>xprec);
+ if(_dy<0)_offsets[0]-=(-_dy>>yprec)*_ystride;
+ else _offsets[0]+=(_dy>>yprec)*_ystride;
+ _offsets[1]=_offsets[0];
if(xfrac){
- if(_dx<0)offset1=offset0-1;
- else offset1=offset0+1;
+ if(_dx<0)_offsets[1]++;
+ else _offsets[1]--;
}
- else offset1=offset0;*/
- o[0]=offset0;
- o[1]=offset0+(xsign|1);
- offset1=o[xfrac];
- /*This branchless code is equivalent to:
if(yfrac){
- if(_dy<0)offset1-=ref_stride;
- else offset1+=ref_stride;
+ if(_dy<0)_offsets[1]+=_ystride;
+ else _offsets[1]-=_ystride;
}*/
- o[0]=offset1;
- o[1]=offset1+(_ystride&~ysign)-(_ystride&ysign);
- *_offset1=o[yfrac];
+ _offsets[1]=_offsets[0];
+ _offsets[_dx>=0]+=xfrac;
+ _offsets[_dy>=0]+=_ystride&-yfrac;
return 2;
}
- return 1;
+ else return 1;
}
void oc_state_frag_recon(oc_theora_state *_state,const oc_fragment *_frag,
@@ -851,19 +823,18 @@
else{
int ref_framei;
int ref_ystride;
- int mvoffset0;
- int mvoffset1;
+ int mvoffsets[2];
ref_framei=_state->ref_frame_idx[OC_FRAME_FOR_MODE[_frag->mbmode]];
ref_ystride=_state->ref_frame_bufs[ref_framei][_pli].ystride;
- if(oc_state_get_mv_offsets(_state,&mvoffset0,&mvoffset1,_frag->mv[0],
- _frag->mv[1],ref_ystride,_pli)>1){
+ if(oc_state_get_mv_offsets(_state,mvoffsets,_frag->mv[0],_frag->mv[1],
+ ref_ystride,_pli)>1){
oc_frag_recon_inter2(_state,_frag->buffer[dst_framei],dst_ystride,
- _frag->buffer[ref_framei]+mvoffset0,ref_ystride,
- _frag->buffer[ref_framei]+mvoffset1,ref_ystride,res_buf);
+ _frag->buffer[ref_framei]+mvoffsets[0],ref_ystride,
+ _frag->buffer[ref_framei]+mvoffsets[1],ref_ystride,res_buf);
}
else{
oc_frag_recon_inter(_state,_frag->buffer[dst_framei],dst_ystride,
- _frag->buffer[ref_framei]+mvoffset0,ref_ystride,res_buf);
+ _frag->buffer[ref_framei]+mvoffsets[0],ref_ystride,res_buf);
}
}
oc_restore_fpu(_state);
Modified: trunk/theora-exp/lib/x86/mmxstate.c
===================================================================
--- trunk/theora-exp/lib/x86/mmxstate.c 2008-01-04 17:45:14 UTC (rev 14343)
+++ trunk/theora-exp/lib/x86/mmxstate.c 2008-01-04 18:00:14 UTC (rev 14344)
@@ -148,19 +148,18 @@
else{
int ref_framei;
int ref_ystride;
- int mvoffset0;
- int mvoffset1;
+ int mvoffsets[2];
ref_framei=_state->ref_frame_idx[OC_FRAME_FOR_MODE[_frag->mbmode]];
ref_ystride=_state->ref_frame_bufs[ref_framei][_pli].ystride;
- if(oc_state_get_mv_offsets(_state,&mvoffset0,&mvoffset1,_frag->mv[0],
- _frag->mv[1],ref_ystride,_pli)>1){
+ if(oc_state_get_mv_offsets(_state,mvoffsets,_frag->mv[0],_frag->mv[1],
+ ref_ystride,_pli)>1){
oc_frag_recon_inter2(_state,_frag->buffer[dst_framei],dst_ystride,
- _frag->buffer[ref_framei]+mvoffset0,ref_ystride,
- _frag->buffer[ref_framei]+mvoffset1,ref_ystride,res_buf);
+ _frag->buffer[ref_framei]+mvoffsets[0],ref_ystride,
+ _frag->buffer[ref_framei]+mvoffsets[1],ref_ystride,res_buf);
}
else{
oc_frag_recon_inter(_state,_frag->buffer[dst_framei],dst_ystride,
- _frag->buffer[ref_framei]+mvoffset0,ref_ystride,res_buf);
+ _frag->buffer[ref_framei]+mvoffsets[0],ref_ystride,res_buf);
}
}
oc_restore_fpu(_state);
More information about the commits
mailing list