1 /********************************************************************
3 * THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. *
4 * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
5 * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
6 * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
8 * THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2007 *
9 * by the Xiph.Org Foundation http://www.xiph.org/ *
11 ********************************************************************
14 last mod: $Id: fragment.c 14348 2008-01-04 18:17:00Z tterribe $
16 ********************************************************************/
18 #include "../internal.h"
20 void oc_frag_recon_intra(const oc_theora_state
*_state
,unsigned char *_dst
,
21 int _dst_ystride
,const ogg_int16_t
*_residue
){
22 _state
->opt_vtable
.frag_recon_intra(_dst
,_dst_ystride
,_residue
);
25 void oc_frag_recon_intra_c(unsigned char *_dst
,int _dst_ystride
,
26 const ogg_int16_t
*_residue
){
33 _dst
[j
]=OC_CLAMP255(res
+128);
39 void oc_frag_recon_inter(const oc_theora_state
*_state
,unsigned char *_dst
,
40 int _dst_ystride
,const unsigned char *_src
,int _src_ystride
,
41 const ogg_int16_t
*_residue
){
42 _state
->opt_vtable
.frag_recon_inter(_dst
,_dst_ystride
,_src
,_src_ystride
,
46 void oc_frag_recon_inter_c(unsigned char *_dst
,int _dst_ystride
,
47 const unsigned char *_src
,int _src_ystride
,const ogg_int16_t
*_residue
){
54 _dst
[j
]=OC_CLAMP255(res
+_src
[j
]);
61 void oc_frag_recon_inter2(const oc_theora_state
*_state
,unsigned char *_dst
,
62 int _dst_ystride
,const unsigned char *_src1
,int _src1_ystride
,
63 const unsigned char *_src2
,int _src2_ystride
,const ogg_int16_t
*_residue
){
64 _state
->opt_vtable
.frag_recon_inter2(_dst
,_dst_ystride
,_src1
,_src1_ystride
,
65 _src2
,_src2_ystride
,_residue
);
68 void oc_frag_recon_inter2_c(unsigned char *_dst
,int _dst_ystride
,
69 const unsigned char *_src1
,int _src1_ystride
,const unsigned char *_src2
,
70 int _src2_ystride
,const ogg_int16_t
*_residue
){
77 _dst
[j
]=OC_CLAMP255(res
+((int)_src1
[j
]+_src2
[j
]>>1));
85 /*Computes the predicted DC value for the given fragment.
86 This requires that the fully decoded DC values be available for the left,
87 upper-left, upper, and upper-right fragments (if they exist).
88 _frag: The fragment to predict the DC value for.
89 _fplane: The fragment plane the fragment belongs to.
90 _x: The x-coordinate of the fragment.
91 _y: The y-coordinate of the fragment.
92 _pred_last: The last fully-decoded DC value for each predictor frame
93 (OC_FRAME_GOLD, OC_FRAME_PREV and OC_FRAME_SELF).
94 This should be initialized to 0's for the first fragment in each
96 Return: The predicted DC value for this fragment.*/
97 int oc_frag_pred_dc(const oc_fragment
*_frag
,
98 const oc_fragment_plane
*_fplane
,int _x
,int _y
,int _pred_last
[3]){
99 static const int PRED_SCALE
[16][4]={
114 /*OC_PL|OC_PUL|PC_PU*/
122 /*OC_PL|OC_PUL|OC_PUR*/
126 /*OC_PL|OC_PU|OC_PUR*/
128 /*OC_PUL|OC_PU|OC_PUR*/
130 /*OC_PL|OC_PUL|OC_PU|OC_PUR*/
133 static const int PRED_SHIFT
[16]={0,0,0,0,0,1,0,5,0,7,1,7,0,7,4,5};
134 static const int PRED_RMASK
[16]={0,0,0,0,0,1,0,31,0,127,1,127,0,127,15,31};
135 static const int BC_MASK
[8]={
136 /*No boundary condition.*/
137 OC_PL
|OC_PUL
|OC_PU
|OC_PUR
,
142 /*Top row, left column.*/
146 /*Right and left column.*/
148 /*Top row, right column.*/
150 /*Top row, right and left column.*/
153 /*Predictor fragments, left, up-left, up, up-right.*/
154 const oc_fragment
*predfr
[4];
155 /*The frame used for prediction for this fragment.*/
157 /*The boundary condition flags.*/
159 /*DC predictor values: left, up-left, up, up-right, missing values
164 /*Which predictor constants to use.*/
166 /*The predicted DC value.*/
169 pred_frame
=OC_FRAME_FOR_MODE
[_frag
->mbmode
];
170 bc
=(_x
==0)+((_y
==0)<<1)+((_x
+1==_fplane
->nhfrags
)<<2);
172 predfr
[1]=_frag
-_fplane
->nhfrags
-1;
173 predfr
[2]=predfr
[1]+1;
174 predfr
[3]=predfr
[2]+1;
180 if((BC_MASK
[bc
]&pflag
)&&predfr
[i
]->coded
&&
181 OC_FRAME_FOR_MODE
[predfr
[i
]->mbmode
]==pred_frame
){
182 p
[np
++]=predfr
[i
]->dc
;
186 if(pflags
==0)return _pred_last
[pred_frame
];
188 ret
=PRED_SCALE
[pflags
][0]*p
[0];
190 for(i
=1;i
<np
;i
++)ret
+=PRED_SCALE
[pflags
][i
]*p
[i
];
191 ret
=OC_DIV_POW2(ret
,PRED_SHIFT
[pflags
],PRED_RMASK
[pflags
]);
193 if((pflags
&(OC_PL
|OC_PUL
|OC_PU
))==(OC_PL
|OC_PUL
|OC_PU
)){
194 if(abs(ret
-p
[2])>128)ret
=p
[2];
195 else if(abs(ret
-p
[0])>128)ret
=p
[0];
196 else if(abs(ret
-p
[1])>128)ret
=p
[1];