Follow-on fix for bug 457825. Use sheet principal for agent and user sheets. r=dbaron...
[wine-gecko.git] / media / libtheora / lib / dec / fragment.c
blobbf95400b2c903a065f88a5498c1365dc233551d8
1 /********************************************************************
2 * *
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. *
7 * *
8 * THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2007 *
9 * by the Xiph.Org Foundation http://www.xiph.org/ *
10 * *
11 ********************************************************************
13 function:
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){
27 int i;
28 for(i=0;i<8;i++){
29 int j;
30 for(j=0;j<8;j++){
31 int res;
32 res=*_residue++;
33 _dst[j]=OC_CLAMP255(res+128);
35 _dst+=_dst_ystride;
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,
43 _residue);
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){
48 int i;
49 for(i=0;i<8;i++){
50 int j;
51 for(j=0;j<8;j++){
52 int res;
53 res=*_residue++;
54 _dst[j]=OC_CLAMP255(res+_src[j]);
56 _dst+=_dst_ystride;
57 _src+=_src_ystride;
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){
71 int i;
72 for(i=0;i<8;i++){
73 int j;
74 for(j=0;j<8;j++){
75 int res;
76 res=*_residue++;
77 _dst[j]=OC_CLAMP255(res+((int)_src1[j]+_src2[j]>>1));
79 _dst+=_dst_ystride;
80 _src1+=_src1_ystride;
81 _src2+=_src2_ystride;
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
95 color plane.
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]={
100 /*0*/
101 {0,0,0,0},
102 /*OC_PL*/
103 {1,0,0,0},
104 /*OC_PUL*/
105 {1,0,0,0},
106 /*OC_PL|OC_PUL*/
107 {1,0,0,0},
108 /*OC_PU*/
109 {1,0,0,0},
110 /*OC_PL|OC_PU*/
111 {1,1,0,0},
112 /*OC_PUL|OC_PU*/
113 {0,1,0,0},
114 /*OC_PL|OC_PUL|PC_PU*/
115 {29,-26,29,0},
116 /*OC_PUR*/
117 {1,0,0,0},
118 /*OC_PL|OC_PUR*/
119 {75,53,0,0},
120 /*OC_PUL|OC_PUR*/
121 {1,1,0,0},
122 /*OC_PL|OC_PUL|OC_PUR*/
123 {75,0,53,0},
124 /*OC_PU|OC_PUR*/
125 {1,0,0,0},
126 /*OC_PL|OC_PU|OC_PUR*/
127 {75,0,53,0},
128 /*OC_PUL|OC_PU|OC_PUR*/
129 {3,10,3,0},
130 /*OC_PL|OC_PUL|OC_PU|OC_PUR*/
131 {29,-26,29,0}
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,
138 /*Left column.*/
139 OC_PU|OC_PUR,
140 /*Top row.*/
141 OC_PL,
142 /*Top row, left column.*/
144 /*Right column.*/
145 OC_PL|OC_PUL|OC_PU,
146 /*Right and left column.*/
147 OC_PU,
148 /*Top row, right column.*/
149 OC_PL,
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.*/
156 int pred_frame;
157 /*The boundary condition flags.*/
158 int bc;
159 /*DC predictor values: left, up-left, up, up-right, missing values
160 skipped.*/
161 int p[4];
162 /*Predictor count.*/
163 int np;
164 /*Which predictor constants to use.*/
165 int pflags;
166 /*The predicted DC value.*/
167 int ret;
168 int i;
169 pred_frame=OC_FRAME_FOR_MODE[_frag->mbmode];
170 bc=(_x==0)+((_y==0)<<1)+((_x+1==_fplane->nhfrags)<<2);
171 predfr[0]=_frag-1;
172 predfr[1]=_frag-_fplane->nhfrags-1;
173 predfr[2]=predfr[1]+1;
174 predfr[3]=predfr[2]+1;
175 np=0;
176 pflags=0;
177 for(i=0;i<4;i++){
178 int pflag;
179 pflag=1<<i;
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;
183 pflags|=pflag;
186 if(pflags==0)return _pred_last[pred_frame];
187 else{
188 ret=PRED_SCALE[pflags][0]*p[0];
189 /*LOOP VECTORIZES.*/
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];
198 return ret;