00001 #include "mpeg3private.h"
00002 #include "mpeg3protos.h"
00003 #include <stdio.h>
00004
00005
00006 static inline void rec(unsigned char *s, unsigned char *d, int lx2, int h)
00007 {
00008 int j;
00009 for(j = 0; j < h; j++, s += lx2, d += lx2)
00010 {
00011 d[0] = s[0]; d[1] = s[1]; d[2] = s[2]; d[3] = s[3];
00012 d[4] = s[4]; d[5] = s[5]; d[6] = s[6]; d[7] = s[7];
00013 d[8] = s[8]; d[9] = s[9]; d[10] = s[10]; d[11] = s[11];
00014 d[12] = s[12]; d[13] = s[13]; d[14] = s[14]; d[15] = s[15];
00015 }
00016 }
00017
00018
00019
00020 static inline void recc(unsigned char *s, unsigned char *d, int lx2, int h)
00021 {
00022 int j;
00023 for(j = 0; j < h; j++, s += lx2, d += lx2)
00024 {
00025 d[0] = s[0]; d[1] = s[1]; d[2] = s[2]; d[3] = s[3];
00026 d[4] = s[4]; d[5] = s[5]; d[6] = s[6]; d[7] = s[7];
00027 }
00028 }
00029
00030 static inline void reca(unsigned char *s, unsigned char *d, int lx2, int h)
00031 {
00032 int j;
00033 for(j = 0; j < h; j++, s +=lx2, d +=lx2)
00034 {
00035 d[0] = (unsigned int)(d[0] + s[0] + 1) >> 1;
00036 d[1] = (unsigned int)(d[1] + s[1] + 1) >> 1;
00037 d[2] = (unsigned int)(d[2] + s[2] + 1) >> 1;
00038 d[3] = (unsigned int)(d[3] + s[3] + 1) >> 1;
00039 d[4] = (unsigned int)(d[4] + s[4] + 1) >> 1;
00040 d[5] = (unsigned int)(d[5] + s[5] + 1) >> 1;
00041 d[6] = (unsigned int)(d[6] + s[6] + 1) >> 1;
00042 d[7] = (unsigned int)(d[7] + s[7] + 1) >> 1;
00043 d[8] = (unsigned int)(d[8] + s[8] + 1) >> 1;
00044 d[9] = (unsigned int)(d[9] + s[9] + 1) >> 1;
00045 d[10] = (unsigned int)(d[10] + s[10] + 1) >> 1;
00046 d[11] = (unsigned int)(d[11] + s[11] + 1) >> 1;
00047 d[12] = (unsigned int)(d[12] + s[12] + 1) >> 1;
00048 d[13] = (unsigned int)(d[13] + s[13] + 1) >> 1;
00049 d[14] = (unsigned int)(d[14] + s[14] + 1) >> 1;
00050 d[15] = (unsigned int)(d[15] + s[15] + 1) >> 1;
00051 }
00052 }
00053
00054 static inline void recac(unsigned char *s, unsigned char *d, int lx2, int h)
00055 {
00056 int j;
00057 for(j = 0; j < h; j++, s += lx2, d += lx2)
00058 {
00059 d[0] = (unsigned int)(d[0] + s[0] + 1)>>1;
00060 d[1] = (unsigned int)(d[1] + s[1] + 1)>>1;
00061 d[2] = (unsigned int)(d[2] + s[2] + 1)>>1;
00062 d[3] = (unsigned int)(d[3] + s[3] + 1)>>1;
00063 d[4] = (unsigned int)(d[4] + s[4] + 1)>>1;
00064 d[5] = (unsigned int)(d[5] + s[5] + 1)>>1;
00065 d[6] = (unsigned int)(d[6] + s[6] + 1)>>1;
00066 d[7] = (unsigned int)(d[7] + s[7] + 1)>>1;
00067 }
00068 }
00069
00070 static inline void recv(unsigned char *s, unsigned char *d, int lx, int lx2, int h)
00071 {
00072 unsigned char *dp,*sp,*sp2;
00073 int j;
00074 sp = s;
00075 sp2 = s + lx;
00076 dp = d;
00077 for(j = 0; j < h; j++)
00078 {
00079 dp[0] = (unsigned int)(sp[0] + sp2[0] + 1) >> 1;
00080 dp[1] = (unsigned int)(sp[1] + sp2[1] + 1) >> 1;
00081 dp[2] = (unsigned int)(sp[2] + sp2[2] + 1) >> 1;
00082 dp[3] = (unsigned int)(sp[3] + sp2[3] + 1) >> 1;
00083 dp[4] = (unsigned int)(sp[4] + sp2[4] + 1) >> 1;
00084 dp[5] = (unsigned int)(sp[5] + sp2[5] + 1) >> 1;
00085 dp[6] = (unsigned int)(sp[6] + sp2[6] + 1) >> 1;
00086 dp[7] = (unsigned int)(sp[7] + sp2[7] + 1) >> 1;
00087 dp[8] = (unsigned int)(sp[8] + sp2[8] + 1) >> 1;
00088 dp[9] = (unsigned int)(sp[9] + sp2[9] + 1) >> 1;
00089 dp[10] = (unsigned int)(sp[10] + sp2[10] + 1) >> 1;
00090 dp[11] = (unsigned int)(sp[11] + sp2[11] + 1) >> 1;
00091 dp[12] = (unsigned int)(sp[12] + sp2[12] + 1) >> 1;
00092 dp[13] = (unsigned int)(sp[13] + sp2[13] + 1) >> 1;
00093 dp[14] = (unsigned int)(sp[14] + sp2[14] + 1) >> 1;
00094 dp[15] = (unsigned int)(sp[15] + sp2[15] + 1) >> 1;
00095 sp+= lx2;
00096 sp2+= lx2;
00097 dp+= lx2;
00098 }
00099 }
00100
00101 static inline void recvc(unsigned char *s, unsigned char *d, int lx, int lx2, int h)
00102 {
00103 unsigned char *dp,*sp,*sp2;
00104 int j;
00105
00106 sp = s;
00107 sp2 = s+lx;
00108 dp = d;
00109 for(j = 0; j < h; j++)
00110 {
00111 dp[0] = (unsigned int)(sp[0]+sp2[0]+1)>>1;
00112 dp[1] = (unsigned int)(sp[1]+sp2[1]+1)>>1;
00113 dp[2] = (unsigned int)(sp[2]+sp2[2]+1)>>1;
00114 dp[3] = (unsigned int)(sp[3]+sp2[3]+1)>>1;
00115 dp[4] = (unsigned int)(sp[4]+sp2[4]+1)>>1;
00116 dp[5] = (unsigned int)(sp[5]+sp2[5]+1)>>1;
00117 dp[6] = (unsigned int)(sp[6]+sp2[6]+1)>>1;
00118 dp[7] = (unsigned int)(sp[7]+sp2[7]+1)>>1;
00119 sp+= lx2;
00120 sp2+= lx2;
00121 dp+= lx2;
00122 }
00123 }
00124
00125
00126 static inline void recva(unsigned char *s, unsigned char *d, int lx, int lx2, int h)
00127 {
00128 unsigned char *dp,*sp,*sp2;
00129 int j;
00130
00131 sp = s;
00132 sp2 = s+lx;
00133 dp = d;
00134 for (j=0; j<h; j++){
00135 dp[0] = (dp[0] + ((unsigned int)(sp[0]+sp2[0]+1)>>1) + 1)>>1;
00136 dp[1] = (dp[1] + ((unsigned int)(sp[1]+sp2[1]+1)>>1) + 1)>>1;
00137 dp[2] = (dp[2] + ((unsigned int)(sp[2]+sp2[2]+1)>>1) + 1)>>1;
00138 dp[3] = (dp[3] + ((unsigned int)(sp[3]+sp2[3]+1)>>1) + 1)>>1;
00139 dp[4] = (dp[4] + ((unsigned int)(sp[4]+sp2[4]+1)>>1) + 1)>>1;
00140 dp[5] = (dp[5] + ((unsigned int)(sp[5]+sp2[5]+1)>>1) + 1)>>1;
00141 dp[6] = (dp[6] + ((unsigned int)(sp[6]+sp2[6]+1)>>1) + 1)>>1;
00142 dp[7] = (dp[7] + ((unsigned int)(sp[7]+sp2[7]+1)>>1) + 1)>>1;
00143 dp[8] = (dp[8] + ((unsigned int)(sp[8]+sp2[8]+1)>>1) + 1)>>1;
00144 dp[9] = (dp[9] + ((unsigned int)(sp[9]+sp2[9]+1)>>1) + 1)>>1;
00145 dp[10] = (dp[10] + ((unsigned int)(sp[10]+sp2[10]+1)>>1) + 1)>>1;
00146 dp[11] = (dp[11] + ((unsigned int)(sp[11]+sp2[11]+1)>>1) + 1)>>1;
00147 dp[12] = (dp[12] + ((unsigned int)(sp[12]+sp2[12]+1)>>1) + 1)>>1;
00148 dp[13] = (dp[13] + ((unsigned int)(sp[13]+sp2[13]+1)>>1) + 1)>>1;
00149 dp[14] = (dp[14] + ((unsigned int)(sp[14]+sp2[14]+1)>>1) + 1)>>1;
00150 dp[15] = (dp[15] + ((unsigned int)(sp[15]+sp2[15]+1)>>1) + 1)>>1;
00151 sp+= lx2;
00152 sp2+= lx2;
00153 dp+= lx2;
00154 }
00155 }
00156
00157
00158 static inline void recvac(unsigned char *s, unsigned char *d, int lx,int lx2, int h){
00159 unsigned char *dp,*sp,*sp2;
00160 int j;
00161
00162 sp = s;
00163 sp2 = s+lx;
00164 dp = d;
00165 for (j=0; j<h; j++){
00166 dp[0] = (dp[0] + ((unsigned int)(sp[0]+sp2[0]+1)>>1) + 1)>>1;
00167 dp[1] = (dp[1] + ((unsigned int)(sp[1]+sp2[1]+1)>>1) + 1)>>1;
00168 dp[2] = (dp[2] + ((unsigned int)(sp[2]+sp2[2]+1)>>1) + 1)>>1;
00169 dp[3] = (dp[3] + ((unsigned int)(sp[3]+sp2[3]+1)>>1) + 1)>>1;
00170 dp[4] = (dp[4] + ((unsigned int)(sp[4]+sp2[4]+1)>>1) + 1)>>1;
00171 dp[5] = (dp[5] + ((unsigned int)(sp[5]+sp2[5]+1)>>1) + 1)>>1;
00172 dp[6] = (dp[6] + ((unsigned int)(sp[6]+sp2[6]+1)>>1) + 1)>>1;
00173 dp[7] = (dp[7] + ((unsigned int)(sp[7]+sp2[7]+1)>>1) + 1)>>1;
00174 sp+= lx2;
00175 sp2+= lx2;
00176 dp+= lx2;
00177 }
00178 }
00179
00180
00181 static inline void rech(unsigned char *s, unsigned char *d, int lx2, int h){
00182 unsigned char *dp,*sp;
00183 unsigned int s1,s2;
00184 int j;
00185
00186 sp = s;
00187 dp = d;
00188 for (j=0; j<h; j++){
00189 s1=sp[0];
00190 dp[0] = (unsigned int)(s1+(s2=sp[1])+1)>>1;
00191 dp[1] = (unsigned int)(s2+(s1=sp[2])+1)>>1;
00192 dp[2] = (unsigned int)(s1+(s2=sp[3])+1)>>1;
00193 dp[3] = (unsigned int)(s2+(s1=sp[4])+1)>>1;
00194 dp[4] = (unsigned int)(s1+(s2=sp[5])+1)>>1;
00195 dp[5] = (unsigned int)(s2+(s1=sp[6])+1)>>1;
00196 dp[6] = (unsigned int)(s1+(s2=sp[7])+1)>>1;
00197 dp[7] = (unsigned int)(s2+(s1=sp[8])+1)>>1;
00198 dp[8] = (unsigned int)(s1+(s2=sp[9])+1)>>1;
00199 dp[9] = (unsigned int)(s2+(s1=sp[10])+1)>>1;
00200 dp[10] = (unsigned int)(s1+(s2=sp[11])+1)>>1;
00201 dp[11] = (unsigned int)(s2+(s1=sp[12])+1)>>1;
00202 dp[12] = (unsigned int)(s1+(s2=sp[13])+1)>>1;
00203 dp[13] = (unsigned int)(s2+(s1=sp[14])+1)>>1;
00204 dp[14] = (unsigned int)(s1+(s2=sp[15])+1)>>1;
00205 dp[15] = (unsigned int)(s2+sp[16]+1)>>1;
00206 sp+= lx2;
00207 dp+= lx2;
00208 }
00209 }
00210
00211
00212 static inline void rechc(unsigned char *s,unsigned char *d, int lx2, int h){
00213 unsigned char *dp,*sp;
00214 unsigned int s1,s2;
00215 int j;
00216
00217 sp = s;
00218 dp = d;
00219 for (j=0; j<h; j++){
00220 s1=sp[0];
00221 dp[0] = (unsigned int)(s1+(s2=sp[1])+1)>>1;
00222 dp[1] = (unsigned int)(s2+(s1=sp[2])+1)>>1;
00223 dp[2] = (unsigned int)(s1+(s2=sp[3])+1)>>1;
00224 dp[3] = (unsigned int)(s2+(s1=sp[4])+1)>>1;
00225 dp[4] = (unsigned int)(s1+(s2=sp[5])+1)>>1;
00226 dp[5] = (unsigned int)(s2+(s1=sp[6])+1)>>1;
00227 dp[6] = (unsigned int)(s1+(s2=sp[7])+1)>>1;
00228 dp[7] = (unsigned int)(s2+sp[8]+1)>>1;
00229 sp+= lx2;
00230 dp+= lx2;
00231 }
00232 }
00233
00234 static inline void recha(unsigned char *s, unsigned char *d,int lx2, int h)
00235 {
00236 unsigned char *dp,*sp;
00237 unsigned int s1,s2;
00238 int j;
00239
00240 sp = s;
00241 dp = d;
00242 for (j = 0; j < h; j++)
00243 {
00244 s1 = sp[0];
00245 dp[0] = (dp[0] + ((unsigned int)(s1 + (s2 = sp[1]) + 1) >> 1) + 1) >> 1;
00246 dp[1] = (dp[1] + ((unsigned int)(s2 + (s1 = sp[2]) + 1) >> 1) + 1) >> 1;
00247 dp[2] = (dp[2] + ((unsigned int)(s1 + (s2 = sp[3]) + 1) >> 1) + 1) >> 1;
00248 dp[3] = (dp[3] + ((unsigned int)(s2 + (s1 = sp[4]) + 1) >> 1) + 1) >> 1;
00249 dp[4] = (dp[4] + ((unsigned int)(s1 + (s2 = sp[5]) + 1) >> 1) + 1) >> 1;
00250 dp[5] = (dp[5] + ((unsigned int)(s2 + (s1 = sp[6]) + 1) >> 1) + 1) >> 1;
00251 dp[6] = (dp[6] + ((unsigned int)(s1 + (s2 = sp[7]) + 1) >> 1) + 1) >> 1;
00252 dp[7] = (dp[7] + ((unsigned int)(s2 + (s1 = sp[8]) + 1) >> 1) + 1) >> 1;
00253 dp[8] = (dp[8] + ((unsigned int)(s1 + (s2 = sp[9]) + 1) >> 1) + 1) >> 1;
00254 dp[9] = (dp[9] + ((unsigned int)(s2 + (s1 = sp[10]) + 1) >> 1) + 1) >> 1;
00255 dp[10] = (dp[10] + ((unsigned int)(s1 + (s2 = sp[11]) + 1) >> 1) + 1) >> 1;
00256 dp[11] = (dp[11] + ((unsigned int)(s2 + (s1 = sp[12]) + 1) >> 1) + 1) >> 1;
00257 dp[12] = (dp[12] + ((unsigned int)(s1 + (s2 = sp[13]) + 1) >> 1) + 1) >> 1;
00258 dp[13] = (dp[13] + ((unsigned int)(s2 + (s1 = sp[14]) + 1) >> 1) + 1) >> 1;
00259 dp[14] = (dp[14] + ((unsigned int)(s1 + (s2 = sp[15]) + 1) >> 1) + 1) >> 1;
00260 dp[15] = (dp[15] + ((unsigned int)(s2 + sp[16] + 1) >> 1) + 1) >> 1;
00261 sp += lx2;
00262 dp += lx2;
00263 }
00264 }
00265
00266
00267 static inline void rechac(unsigned char *s,unsigned char *d, int lx2, int h)
00268 {
00269 unsigned char *dp,*sp;
00270 unsigned int s1,s2;
00271 int j;
00272
00273 sp = s;
00274 dp = d;
00275 for(j = 0; j < h; j++)
00276 {
00277 s1 = sp[0];
00278 dp[0] = (dp[0] + ((unsigned int)(s1 + (s2 = sp[1]) + 1) >> 1) + 1) >> 1;
00279 dp[1] = (dp[1] + ((unsigned int)(s2 + (s1 = sp[2]) + 1) >> 1) + 1) >> 1;
00280 dp[2] = (dp[2] + ((unsigned int)(s1 + (s2 = sp[3]) + 1) >> 1) + 1) >> 1;
00281 dp[3] = (dp[3] + ((unsigned int)(s2 + (s1 = sp[4]) + 1) >> 1) + 1) >> 1;
00282 dp[4] = (dp[4] + ((unsigned int)(s1 + (s2 = sp[5]) + 1) >> 1) + 1) >> 1;
00283 dp[5] = (dp[5] + ((unsigned int)(s2 + (s1 = sp[6]) + 1) >> 1) + 1) >> 1;
00284 dp[6] = (dp[6] + ((unsigned int)(s1 + (s2 = sp[7]) + 1) >> 1) + 1) >> 1;
00285 dp[7] = (dp[7] + ((unsigned int)(s2 + sp[8] + 1) >> 1) + 1) >> 1;
00286 sp += lx2;
00287 dp += lx2;
00288 }
00289 }
00290
00291
00292 static inline void rec4(unsigned char *s, unsigned char *d, int lx, int lx2, int h)
00293 {
00294 unsigned char *dp,*sp,*sp2;
00295 unsigned int s1,s2,s3,s4;
00296 int j;
00297
00298 sp = s;
00299 sp2 = s+lx;
00300 dp = d;
00301 for (j=0; j<h; j++){
00302 s1=sp[0]; s3=sp2[0];
00303 dp[0] = (unsigned int)(s1+(s2=sp[1])+s3+(s4=sp2[1])+2)>>2;
00304 dp[1] = (unsigned int)(s2+(s1=sp[2])+s4+(s3=sp2[2])+2)>>2;
00305 dp[2] = (unsigned int)(s1+(s2=sp[3])+s3+(s4=sp2[3])+2)>>2;
00306 dp[3] = (unsigned int)(s2+(s1=sp[4])+s4+(s3=sp2[4])+2)>>2;
00307 dp[4] = (unsigned int)(s1+(s2=sp[5])+s3+(s4=sp2[5])+2)>>2;
00308 dp[5] = (unsigned int)(s2+(s1=sp[6])+s4+(s3=sp2[6])+2)>>2;
00309 dp[6] = (unsigned int)(s1+(s2=sp[7])+s3+(s4=sp2[7])+2)>>2;
00310 dp[7] = (unsigned int)(s2+(s1=sp[8])+s4+(s3=sp2[8])+2)>>2;
00311 dp[8] = (unsigned int)(s1+(s2=sp[9])+s3+(s4=sp2[9])+2)>>2;
00312 dp[9] = (unsigned int)(s2+(s1=sp[10])+s4+(s3=sp2[10])+2)>>2;
00313 dp[10] = (unsigned int)(s1+(s2=sp[11])+s3+(s4=sp2[11])+2)>>2;
00314 dp[11] = (unsigned int)(s2+(s1=sp[12])+s4+(s3=sp2[12])+2)>>2;
00315 dp[12] = (unsigned int)(s1+(s2=sp[13])+s3+(s4=sp2[13])+2)>>2;
00316 dp[13] = (unsigned int)(s2+(s1=sp[14])+s4+(s3=sp2[14])+2)>>2;
00317 dp[14] = (unsigned int)(s1+(s2=sp[15])+s3+(s4=sp2[15])+2)>>2;
00318 dp[15] = (unsigned int)(s2+sp[16]+s4+sp2[16]+2)>>2;
00319 sp+= lx2;
00320 sp2+= lx2;
00321 dp+= lx2;
00322 }
00323 }
00324
00325
00326 static inline void rec4c(unsigned char *s,unsigned char *d, int lx, int lx2, int h)
00327 {
00328 unsigned char *dp,*sp,*sp2;
00329 unsigned int s1,s2,s3,s4;
00330 int j;
00331
00332 sp = s;
00333 sp2 = s+lx;
00334 dp = d;
00335 for (j=0; j<h; j++){
00336 s1=sp[0]; s3=sp2[0];
00337 dp[0] = (unsigned int)(s1+(s2=sp[1])+s3+(s4=sp2[1])+2)>>2;
00338 dp[1] = (unsigned int)(s2+(s1=sp[2])+s4+(s3=sp2[2])+2)>>2;
00339 dp[2] = (unsigned int)(s1+(s2=sp[3])+s3+(s4=sp2[3])+2)>>2;
00340 dp[3] = (unsigned int)(s2+(s1=sp[4])+s4+(s3=sp2[4])+2)>>2;
00341 dp[4] = (unsigned int)(s1+(s2=sp[5])+s3+(s4=sp2[5])+2)>>2;
00342 dp[5] = (unsigned int)(s2+(s1=sp[6])+s4+(s3=sp2[6])+2)>>2;
00343 dp[6] = (unsigned int)(s1+(s2=sp[7])+s3+(s4=sp2[7])+2)>>2;
00344 dp[7] = (unsigned int)(s2+sp[8]+s4+sp2[8]+2)>>2;
00345 sp+= lx2;
00346 sp2+= lx2;
00347 dp+= lx2;
00348 }
00349 }
00350
00351
00352 static inline void rec4a(unsigned char *s,unsigned char *d, int lx, int lx2, int h)
00353 {
00354 unsigned char *dp=d, *sp=s, *sp2=s+lx;
00355 unsigned int s1, s2, s3, s4;
00356 int j;
00357
00358
00359
00360
00361
00362
00363 for (j=0; j<h; j++){
00364 s1=sp[0]; s3=sp2[0];
00365 dp[0] = (dp[0] + ((unsigned int)(s1+(s2=sp[1])+s3+(s4=sp2[1])+2)>>2) + 1)>>1;
00366 dp[1] = (dp[1] + ((unsigned int)(s2+(s1=sp[2])+s4+(s3=sp2[2])+2)>>2) + 1)>>1;
00367 dp[2] = (dp[2] + ((unsigned int)(s1+(s2=sp[3])+s3+(s4=sp2[3])+2)>>2) + 1)>>1;
00368 dp[3] = (dp[3] + ((unsigned int)(s2+(s1=sp[4])+s4+(s3=sp2[4])+2)>>2) + 1)>>1;
00369 dp[4] = (dp[4] + ((unsigned int)(s1+(s2=sp[5])+s3+(s4=sp2[5])+2)>>2) + 1)>>1;
00370 dp[5] = (dp[5] + ((unsigned int)(s2+(s1=sp[6])+s4+(s3=sp2[6])+2)>>2) + 1)>>1;
00371 dp[6] = (dp[6] + ((unsigned int)(s1+(s2=sp[7])+s3+(s4=sp2[7])+2)>>2) + 1)>>1;
00372 dp[7] = (dp[7] + ((unsigned int)(s2+(s1=sp[8])+s4+(s3=sp2[8])+2)>>2) + 1)>>1;
00373 dp[8] = (dp[8] + ((unsigned int)(s1+(s2=sp[9])+s3+(s4=sp2[9])+2)>>2) + 1)>>1;
00374 dp[9] = (dp[9] + ((unsigned int)(s2+(s1=sp[10])+s4+(s3=sp2[10])+2)>>2) + 1)>>1;
00375 dp[10] = (dp[10] + ((unsigned int)(s1+(s2=sp[11])+s3+(s4=sp2[11])+2)>>2) + 1)>>1;
00376 dp[11] = (dp[11] + ((unsigned int)(s2+(s1=sp[12])+s4+(s3=sp2[12])+2)>>2) + 1)>>1;
00377 dp[12] = (dp[12] + ((unsigned int)(s1+(s2=sp[13])+s3+(s4=sp2[13])+2)>>2) + 1)>>1;
00378 dp[13] = (dp[13] + ((unsigned int)(s2+(s1=sp[14])+s4+(s3=sp2[14])+2)>>2) + 1)>>1;
00379 dp[14] = (dp[14] + ((unsigned int)(s1+(s2=sp[15])+s3+(s4=sp2[15])+2)>>2) + 1)>>1;
00380 dp[15] = (dp[15] + ((unsigned int)(s2+sp[16]+s4+sp2[16]+2)>>2) + 1)>>1;
00381 sp+= lx2;
00382 sp2+= lx2;
00383 dp+= lx2;
00384 }
00385 }
00386
00387
00388 static inline void rec4ac(unsigned char *s,unsigned char *d, int lx, int lx2, int h)
00389 {
00390 unsigned char *dp=d, *sp=s, *sp2=s+lx;
00391 unsigned int s1,s2,s3,s4;
00392 int j;
00393
00394
00395
00396
00397
00398
00399 for (j=0; j<h; j++)
00400 {
00401 s1=sp[0]; s3=sp2[0];
00402 dp[0] = (dp[0] + ((unsigned int)(s1+(s2=sp[1])+s3+(s4=sp2[1])+2)>>2) + 1)>>1;
00403 dp[1] = (dp[1] + ((unsigned int)(s2+(s1=sp[2])+s4+(s3=sp2[2])+2)>>2) + 1)>>1;
00404 dp[2] = (dp[2] + ((unsigned int)(s1+(s2=sp[3])+s3+(s4=sp2[3])+2)>>2) + 1)>>1;
00405 dp[3] = (dp[3] + ((unsigned int)(s2+(s1=sp[4])+s4+(s3=sp2[4])+2)>>2) + 1)>>1;
00406 dp[4] = (dp[4] + ((unsigned int)(s1+(s2=sp[5])+s3+(s4=sp2[5])+2)>>2) + 1)>>1;
00407 dp[5] = (dp[5] + ((unsigned int)(s2+(s1=sp[6])+s4+(s3=sp2[6])+2)>>2) + 1)>>1;
00408 dp[6] = (dp[6] + ((unsigned int)(s1+(s2=sp[7])+s3+(s4=sp2[7])+2)>>2) + 1)>>1;
00409 dp[7] = (dp[7] + ((unsigned int)(s2+sp[8]+s4+sp2[8]+2)>>2) + 1)>>1;
00410 sp+= lx2;
00411 sp2+= lx2;
00412 dp+= lx2;
00413 }
00414 }
00415
00416 static inline
00417 void recon_comp(mpeg3video_t *video,
00418 unsigned char *src,
00419 unsigned char *dst,
00420 int lx,
00421 int lx2,
00422 int w,
00423 int h,
00424 int x,
00425 int y,
00426 int dx,
00427 int dy,
00428 int addflag)
00429 {
00430 int switcher;
00431 unsigned char *s, *d;
00432
00433
00434 switcher = (dx & 1) << 3 | (dy & 1) << 2 | w;
00435 if(addflag) switcher |= 2;
00436
00437 s = src + lx * (y + (dy >> 1)) + x + (dx >> 1);
00438 d = dst + lx * y + x;
00439
00440
00441 switch(switcher)
00442 {
00443 case 0x3: reca(s, d, lx2, h); break;
00444 case 0x2: recac(s, d, lx2, h); break;
00445 case 0x1: rec(s, d, lx2, h); break;
00446 case 0x0: recc(s, d, lx2, h); break;
00447 case 0x7: recva(s, d, lx, lx2, h); break;
00448 case 0x6: recvac(s, d, lx, lx2, h); break;
00449 case 0x5: recv(s, d, lx, lx2, h); break;
00450 case 0x4: recvc(s, d, lx, lx2, h); break;
00451 case 0x9: rech(s, d, lx2, h); break;
00452 case 0x8: rechc(s, d, lx2, h); break;
00453 }
00454
00455
00456 switch(switcher)
00457 {
00458 case 0xb: recha(s, d, lx2, h); break;
00459 case 0xa: rechac(s, d, lx2, h); break;
00460 case 0xf: rec4a(s, d, lx, lx2, h); break;
00461 case 0xe: rec4ac(s, d, lx, lx2, h); break;
00462 case 0xd: rec4(s, d, lx, lx2, h); break;
00463 case 0xc: rec4c(s, d, lx, lx2, h); break;
00464 }
00465 }
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478 static void recon(mpeg3video_t *video,
00479 unsigned char *src[],
00480 int sfield,
00481 unsigned char *dst[],
00482 int dfield,
00483 int lx,
00484 int lx2,
00485 int w,
00486 int h,
00487 int x,
00488 int y,
00489 int dx,
00490 int dy,
00491 int addflag)
00492 {
00493
00494
00495 recon_comp(video, (src[0] + (sfield ? (lx2 >> 1) : 0)),
00496 dst[0] + (dfield ? (lx2 >> 1) : 0),
00497 lx, lx2, w, h, x, y, dx, dy, addflag);
00498
00499 if(video->chroma_format != CHROMA444)
00500 {
00501 lx >>= 1;
00502 dx /= 2;
00503 lx2 >>= 1;
00504 w = 0;
00505 x >>= 1;
00506 }
00507
00508 if(video->chroma_format == CHROMA420)
00509 {
00510 h >>= 1;
00511 dy /= 2;
00512 y >>= 1;
00513 }
00514
00515
00516 recon_comp(video, (src[1] + (sfield ? (lx2 >> 1) : 0)),
00517 dst[1] + (dfield ? (lx2 >> 1) : 0),
00518 lx, lx2, w, h, x, y, dx, dy, addflag);
00519
00520
00521 recon_comp(video, (src[2] + (sfield ? (lx2 >> 1) : 0)),
00522 dst[2] + (dfield ? (lx2 >> 1) : 0),
00523 lx, lx2, w, h, x, y, dx, dy, addflag);
00524 }
00525
00526 #define WIDTH 1
00527
00528 int mpeg3video_reconstruct(mpeg3video_t *video,
00529 int bx,
00530 int by,
00531 int mb_type,
00532 int motion_type,
00533 int PMV[2][2][2],
00534 int mv_field_sel[2][2],
00535 int dmvector[2],
00536 int stwtype)
00537 {
00538 int currentfield;
00539 unsigned char **predframe;
00540 int DMV[2][2];
00541 int stwtop, stwbot;
00542
00543 stwtop = stwtype % 3;
00544 stwbot = stwtype / 3;
00545
00546 if((mb_type & MB_FORWARD) || (video->pict_type == P_TYPE))
00547 {
00548 if(video->pict_struct == FRAME_PICTURE)
00549 {
00550 if((motion_type == MC_FRAME) || !(mb_type & MB_FORWARD))
00551 {
00552
00553 {
00554 if(stwtop < 2)
00555 recon(video, video->oldrefframe, 0, video->newframe, 0,
00556 video->coded_picture_width, video->coded_picture_width << 1, WIDTH, 8, bx, by,
00557 PMV[0][0][0], PMV[0][0][1], stwtop);
00558
00559 if(stwbot < 2)
00560 recon(video, video->oldrefframe, 1, video->newframe, 1,
00561 video->coded_picture_width, video->coded_picture_width << 1, WIDTH, 8, bx, by,
00562 PMV[0][0][0], PMV[0][0][1], stwbot);
00563 }
00564 }
00565 else if(motion_type == MC_FIELD)
00566 {
00567
00568 if(stwtop < 2)
00569 recon(video, video->oldrefframe, mv_field_sel[0][0], video->newframe, 0,
00570 video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 8, bx, by >> 1,
00571 PMV[0][0][0], PMV[0][0][1] >> 1, stwtop);
00572
00573
00574 if(stwbot < 2)
00575 recon(video, video->oldrefframe, mv_field_sel[1][0], video->newframe, 1,
00576 video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 8, bx, by >> 1,
00577 PMV[1][0][0], PMV[1][0][1] >> 1, stwbot);
00578 }
00579 else if(motion_type == MC_DMV)
00580 {
00581
00582
00583 mpeg3video_calc_dmv(video,
00584 DMV,
00585 dmvector,
00586 PMV[0][0][0],
00587 PMV[0][0][1] >> 1);
00588
00589 if(stwtop < 2)
00590 {
00591
00592 recon(video, video->oldrefframe, 0, video->newframe, 0,
00593 video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 8, bx, by>>1,
00594 PMV[0][0][0], PMV[0][0][1] >> 1, 0);
00595
00596
00597 recon(video, video->oldrefframe, 1, video->newframe, 0,
00598 video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 8, bx, by>>1,
00599 DMV[0][0], DMV[0][1], 1);
00600 }
00601
00602 if(stwbot < 2)
00603 {
00604
00605 recon(video, video->oldrefframe, 1, video->newframe, 1,
00606 video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 8, bx, by>>1,
00607 PMV[0][0][0], PMV[0][0][1]>>1, 0);
00608
00609
00610 recon(video, video->oldrefframe, 0, video->newframe, 1,
00611 video->coded_picture_width << 1, video->coded_picture_width<<1, WIDTH, 8, bx, by>>1,
00612 DMV[1][0], DMV[1][1], 1);
00613 }
00614 }
00615 else
00616
00617
00618 ;
00619 }
00620 else
00621 {
00622
00623
00624 currentfield = (video->pict_struct == BOTTOM_FIELD);
00625
00626
00627 if((video->pict_type == P_TYPE) && video->secondfield
00628 && (currentfield != mv_field_sel[0][0]))
00629 predframe = video->refframe;
00630 else
00631 predframe = video->oldrefframe;
00632
00633 if((motion_type == MC_FIELD) || !(mb_type & MB_FORWARD))
00634 {
00635
00636 if(stwtop < 2)
00637 recon(video, predframe,mv_field_sel[0][0],video->newframe,0,
00638 video->coded_picture_width << 1,video->coded_picture_width << 1,WIDTH,16,bx,by,
00639 PMV[0][0][0],PMV[0][0][1],stwtop);
00640 }
00641 else
00642 if(motion_type == MC_16X8)
00643 {
00644 if(stwtop < 2)
00645 {
00646 recon(video, predframe, mv_field_sel[0][0], video->newframe, 0,
00647 video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 8, bx, by,
00648 PMV[0][0][0], PMV[0][0][1], stwtop);
00649
00650
00651 if((video->pict_type==P_TYPE) && video->secondfield
00652 && (currentfield!=mv_field_sel[1][0]))
00653 predframe = video->refframe;
00654 else
00655 predframe = video->oldrefframe;
00656
00657 recon(video, predframe, mv_field_sel[1][0], video->newframe, 0,
00658 video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 8, bx, by+8,
00659 PMV[1][0][0], PMV[1][0][1], stwtop);
00660 }
00661 }
00662 else
00663 if(motion_type == MC_DMV)
00664 {
00665 if(video->secondfield)
00666 predframe = video->refframe;
00667 else
00668 predframe = video->oldrefframe;
00669
00670
00671 mpeg3video_calc_dmv(video,
00672 DMV,
00673 dmvector,
00674 PMV[0][0][0],
00675 PMV[0][0][1]);
00676
00677
00678 recon(video, video->oldrefframe, currentfield, video->newframe, 0,
00679 video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 16, bx, by,
00680 PMV[0][0][0], PMV[0][0][1], 0);
00681
00682
00683 recon(video, predframe, !currentfield, video->newframe, 0,
00684 video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 16, bx, by,
00685 DMV[0][0], DMV[0][1], 1);
00686 }
00687 else
00688
00689
00690 ;
00691 }
00692 stwtop = stwbot = 1;
00693 }
00694
00695 if(mb_type & MB_BACKWARD)
00696 {
00697 if(video->pict_struct == FRAME_PICTURE)
00698 {
00699 if(motion_type == MC_FRAME)
00700 {
00701
00702 if(stwtop < 2)
00703 recon(video, video->refframe, 0, video->newframe, 0,
00704 video->coded_picture_width, video->coded_picture_width << 1, WIDTH, 8, bx, by,
00705 PMV[0][1][0], PMV[0][1][1], stwtop);
00706
00707 if(stwbot < 2)
00708 recon(video, video->refframe, 1, video->newframe, 1,
00709 video->coded_picture_width, video->coded_picture_width << 1, WIDTH, 8, bx, by,
00710 PMV[0][1][0], PMV[0][1][1], stwbot);
00711 }
00712 else
00713 {
00714
00715
00716 if(stwtop < 2)
00717 {
00718 recon(video, video->refframe, mv_field_sel[0][1], video->newframe, 0,
00719 (video->coded_picture_width << 1), (video->coded_picture_width<<1), WIDTH, 8, bx, (by >> 1),
00720 PMV[0][1][0], (PMV[0][1][1] >> 1), stwtop);
00721 }
00722
00723
00724 if(stwbot < 2)
00725 {
00726 recon(video, video->refframe, mv_field_sel[1][1], video->newframe, 1, (video->coded_picture_width << 1),
00727 (video->coded_picture_width << 1), WIDTH, 8, bx, (by>>1),
00728 PMV[1][1][0], (PMV[1][1][1]>>1), stwbot);
00729 }
00730 }
00731 }
00732 else
00733 {
00734
00735
00736 if(motion_type == MC_FIELD)
00737 {
00738
00739 recon(video, video->refframe, mv_field_sel[0][1], video->newframe, 0,
00740 video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 16, bx, by,
00741 PMV[0][1][0], PMV[0][1][1], stwtop);
00742 }
00743 else if(motion_type==MC_16X8)
00744 {
00745 recon(video, video->refframe, mv_field_sel[0][1], video->newframe, 0,
00746 video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 8, bx, by,
00747 PMV[0][1][0], PMV[0][1][1], stwtop);
00748
00749 recon(video, video->refframe, mv_field_sel[1][1], video->newframe, 0,
00750 video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 8, bx, by+8,
00751 PMV[1][1][0], PMV[1][1][1], stwtop);
00752 }
00753 else
00754
00755
00756 ;
00757 }
00758 }
00759 return 0;
00760 }
00761
00762