Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1673 tullio 1
 
2
#include "config.h"
3
#include "global.h"
4
 
5
/* private prototypes */
6
static void Read_Lower_Layer_Component_Framewise _ANSI_ARGS_((int comp, int lw, int lh));
7
static void Read_Lower_Layer_Component_Fieldwise _ANSI_ARGS_((int comp, int lw, int lh));
8
static void Make_Spatial_Prediction_Frame _ANSI_ARGS_((int progressive_frame,
9
  int llprogressive_frame, unsigned char *fld0, unsigned char *fld1,
10
  short *tmp, unsigned char *dst, int llx0, int lly0, int llw, int llh,
11
  int horizontal_size, int vertical_size, int vm, int vn, int hm, int hn,
12
  int aperture));
13
static void Deinterlace _ANSI_ARGS_((unsigned char *fld0, unsigned char *fld1,
14
  int j0, int lx, int ly, int aperture));
15
static void Subsample_Vertical _ANSI_ARGS_((unsigned char *s, short *d,
16
  int lx, int lys, int lyd, int m, int n, int j0, int dj));
17
static void Subsample_Horizontal _ANSI_ARGS_((short *s, unsigned char *d,
18
  int x0, int lx, int lxs, int lxd, int ly, int m, int n));
19
 
20
 
21
 
22
/* get reference frame */
23
void Spatial_Prediction()
24
{
25
 
26
  if(Frame_Store_Flag)
27
  {
28
    Read_Lower_Layer_Component_Framewise(0,lower_layer_prediction_horizontal_size,
29
      lower_layer_prediction_vertical_size);      /* Y */
30
    Read_Lower_Layer_Component_Framewise(1,lower_layer_prediction_horizontal_size>>1,
31
      lower_layer_prediction_vertical_size>>1);   /* Cb ("U") */
32
    Read_Lower_Layer_Component_Framewise(2,lower_layer_prediction_horizontal_size>>1,
33
      lower_layer_prediction_vertical_size>>1);   /* Cr ("V") */
34
  }
35
  else
36
  {
37
    Read_Lower_Layer_Component_Fieldwise(0,lower_layer_prediction_horizontal_size,
38
      lower_layer_prediction_vertical_size);      /* Y */
39
    Read_Lower_Layer_Component_Fieldwise(1,lower_layer_prediction_horizontal_size>>1,
40
      lower_layer_prediction_vertical_size>>1);   /* Cb ("U") */
41
    Read_Lower_Layer_Component_Fieldwise(2,lower_layer_prediction_horizontal_size>>1,
42
      lower_layer_prediction_vertical_size>>1);   /* Cr ("V") */
43
  }
44
 
45
 
46
  Make_Spatial_Prediction_Frame  /* Y */
47
    (progressive_frame,lower_layer_progressive_frame,llframe0[0],llframe1[0],
48
     lltmp,current_frame[0],lower_layer_horizontal_offset,
49
     lower_layer_vertical_offset,
50
     lower_layer_prediction_horizontal_size,
51
     lower_layer_prediction_vertical_size,
52
     horizontal_size,vertical_size,vertical_subsampling_factor_m,
53
     vertical_subsampling_factor_n,horizontal_subsampling_factor_m,
54
     horizontal_subsampling_factor_n,
55
     picture_structure!=FRAME_PICTURE); /* this changed from CD to DIS */
56
 
57
  Make_Spatial_Prediction_Frame  /* Cb */
58
    (progressive_frame,lower_layer_progressive_frame,llframe0[1],llframe1[1],
59
     lltmp,current_frame[1],lower_layer_horizontal_offset/2,
60
     lower_layer_vertical_offset/2,
61
     lower_layer_prediction_horizontal_size>>1,
62
     lower_layer_prediction_vertical_size>>1,
63
     horizontal_size>>1,vertical_size>>1,vertical_subsampling_factor_m,
64
     vertical_subsampling_factor_n,horizontal_subsampling_factor_m,
65
     horizontal_subsampling_factor_n,1);
66
 
67
  Make_Spatial_Prediction_Frame  /* Cr */
68
    (progressive_frame,lower_layer_progressive_frame,llframe0[2],llframe1[2],
69
     lltmp,current_frame[2],lower_layer_horizontal_offset/2,
70
     lower_layer_vertical_offset/2,
71
     lower_layer_prediction_horizontal_size>>1,
72
     lower_layer_prediction_vertical_size>>1,
73
     horizontal_size>>1,vertical_size>>1,vertical_subsampling_factor_m,
74
     vertical_subsampling_factor_n,horizontal_subsampling_factor_m,
75
     horizontal_subsampling_factor_n,1);
76
 
77
}
78
 
79
static void Read_Lower_Layer_Component_Framewise(comp,lw,lh)
80
     int comp;
81
     int lw, lh;
82
{
83
        cprintf("Read_Lower_Layer_Component_Framewise\n");
84
}
85
 
86
 
87
static void Read_Lower_Layer_Component_Fieldwise(comp,lw,lh)
88
     int comp;
89
     int lw, lh;
90
{
91
        cprintf("Read_Lower_Layer_Component_Fieldwise\n");
92
}
93
 
94
 
95
/* form spatial prediction */
96
static void Make_Spatial_Prediction_Frame(progressive_frame,
97
  llprogressive_frame,fld0,fld1,tmp,dst,llx0,lly0,llw,llh,horizontal_size,
98
  vertical_size,vm,vn,hm,hn,aperture)
99
int progressive_frame,llprogressive_frame;
100
unsigned char *fld0,*fld1;
101
short *tmp;
102
unsigned char *dst;
103
int llx0,lly0,llw,llh,horizontal_size,vertical_size,vm,vn,hm,hn,aperture;
104
{
105
  int w, h, x0, llw2, llh2;
106
 
107
  llw2 = (llw*hn)/hm;
108
  llh2 = (llh*vn)/vm;
109
 
110
  if (llprogressive_frame)
111
  {
112
    /* progressive -> progressive / interlaced */
113
    Subsample_Vertical(fld0,tmp,llw,llh,llh2,vm,vn,0,1);
114
  }
115
  else if (progressive_frame)
116
  {
117
    /* interlaced -> progressive */
118
    if (lower_layer_deinterlaced_field_select)
119
    {
120
      Deinterlace(fld1,fld0,0,llw,llh,aperture);
121
      Subsample_Vertical(fld1,tmp,llw,llh,llh2,vm,vn,0,1);
122
    }
123
    else
124
    {
125
      Deinterlace(fld0,fld1,1,llw,llh,aperture);
126
      Subsample_Vertical(fld0,tmp,llw,llh,llh2,vm,vn,0,1);
127
    }
128
  }
129
  else
130
  {
131
    /* interlaced -> interlaced */
132
    Deinterlace(fld0,fld1,1,llw,llh,aperture);
133
    Deinterlace(fld1,fld0,0,llw,llh,aperture);
134
    Subsample_Vertical(fld0,tmp,llw,llh,llh2,vm,vn,0,2);
135
    Subsample_Vertical(fld1,tmp,llw,llh,llh2,vm,vn,1,2);
136
  }
137
 
138
    /* vertical limits */
139
    if (lly0<0)
140
    {
141
      tmp-= llw*lly0;
142
      llh2+= lly0;
143
      if (llh2<0)
144
        llh2 = 0;
145
      h = (vertical_size<llh2) ? vertical_size : llh2;
146
    }
147
    else
148
    {
149
      dst+= horizontal_size*lly0;
150
      h= vertical_size - lly0;
151
      if (h>llh2)
152
        h = llh2;
153
    }
154
 
155
    /* horizontal limits */
156
    if (llx0<0)
157
    {
158
      x0 = -llx0;
159
      llw2+= llx0;
160
      if (llw2<0)
161
        llw2 = 0;
162
      w = (horizontal_size<llw2) ? horizontal_size : llw2;
163
    }
164
    else
165
    {
166
      dst+= llx0;
167
      x0 = 0;
168
      w = horizontal_size - llx0;
169
      if (w>llw2)
170
        w = llw2;
171
    }
172
 
173
  Subsample_Horizontal(tmp,dst,x0,w,llw,horizontal_size,h,hm,hn);
174
}
175
 
176
/* deinterlace one field (interpolate opposite parity samples)
177
 *
178
 * deinterlacing is done in-place: if j0=1, fld0 contains the input field in
179
 * its even lines and the odd lines are interpolated by this routine
180
 * if j0=0, the input field is in the odd lines and the even lines are
181
 * interpolated
182
 *
183
 * fld0: field to be deinterlaced
184
 * fld1: other field (referenced by the two field aperture filter)
185
 * j0:   0: interpolate even (top) lines, 1: interpolate odd (bottom) lines
186
 * lx:   width of fld0 and fld1
187
 * ly:   height of the deinterlaced field (has to be even)
188
 * aperture: 1: use one field aperture filter (two field otherwise)
189
 */
190
static void Deinterlace(fld0,fld1,j0,lx,ly,aperture)
191
unsigned char *fld0,*fld1;
192
int j0,lx,ly; /* ly has to be even */
193
int aperture;
194
{
195
  int i,j,v;
196
  unsigned char *p0, *p0m1, *p0p1, *p1, *p1m2, *p1p2;
197
 
198
  /* deinterlace one field */
199
  for (j=j0; j<ly; j+=2)
200
  {
201
    p0 = fld0+lx*j;
202
    p0m1 = (j==0)    ? p0+lx : p0-lx;
203
    p0p1 = (j==ly-1) ? p0-lx : p0+lx;
204
 
205
    if (aperture)
206
      for (i=0; i<lx; i++)
207
        p0[i] = (unsigned int)(p0m1[i] + p0p1[i] + 1)>>1;
208
    else
209
    {
210
      p1 = fld1 + lx*j;
211
      p1m2 = (j<2)     ? p1 : p1-2*lx;
212
      p1p2 = (j>=ly-2) ? p1 : p1+2*lx;
213
      for (i=0; i<lx; i++)
214
      {
215
        v = 8*(p0m1[i]+p0p1[i]) + 2*p1[i] - p1m2[i] - p1p2[i];
216
        p0[i] = Clip[(v + ((v>=0) ? 8 : 7))>>4];
217
      }
218
    }
219
  }
220
}
221
 
222
/* vertical resampling */
223
static void Subsample_Vertical(s,d,lx,lys,lyd,m,n,j0,dj)
224
unsigned char *s;
225
short *d;
226
int lx, lys, lyd, m, n, j0, dj;
227
{
228
  int i, j, c1, c2, jd;
229
  unsigned char *s1, *s2;
230
  short *d1;
231
 
232
  for (j=j0; j<lyd; j+=dj)
233
  {
234
    d1 = d + lx*j;
235
    jd = (j*m)/n;
236
    s1 = s + lx*jd;
237
    s2 = (jd<lys-1)? s1+lx : s1;
238
    c2 = (16*((j*m)%n) + (n>>1))/n;
239
    c1 = 16 - c2;
240
    for (i=0; i<lx; i++)
241
      d1[i] = c1*s1[i] + c2*s2[i];
242
  }
243
}
244
 
245
/* horizontal resampling */
246
static void Subsample_Horizontal(s,d,x0,lx,lxs,lxd,ly,m,n)
247
short *s;
248
unsigned char *d;
249
int x0, lx, lxs, lxd, ly, m, n;
250
{
251
  int i, i1, j, id, c1, c2, v;
252
  short *s1, *s2;
253
  unsigned char *d1;
254
 
255
  for (i1=0; i1<lx; i1++)
256
  {
257
    d1 = d + i1;
258
    i = x0 + i1;
259
    id = (i*m)/n;
260
    s1 = s+id;
261
    s2 = (id<lxs-1) ? s1+1 : s1;
262
    c2 = (16*((i*m)%n) + (n>>1))/n;
263
    c1 = 16 - c2;
264
    for (j=0; j<ly; j++)
265
    {
266
      v = c1*(*s1) + c2*(*s2);
267
      *d1 = (v + ((v>=0) ? 128 : 127))>>8;
268
      d1+= lxd;
269
      s1+= lxs;
270
      s2+= lxs;
271
    }
272
  }
273
}
274
 
275