Subversion Repositories shark

Rev

Rev 1624 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1624 giacomo 1
/* store.c, picture output routines                                         */
2
 
3
/* Copyright (C) 1996, MPEG Software Simulation Group. All Rights Reserved. */
4
 
5
/*
6
 * Disclaimer of Warranty
7
 *
8
 * These software programs are available to the user without any license fee or
9
 * royalty on an "as is" basis.  The MPEG Software Simulation Group disclaims
10
 * any and all warranties, whether express, implied, or statuary, including any
11
 * implied warranties or merchantability or of fitness for a particular
12
 * purpose.  In no event shall the copyright-holder be liable for any
13
 * incidental, punitive, or consequential damages of any kind whatsoever
14
 * arising from the use of these programs.
15
 *
16
 * This disclaimer of warranty extends to the user of these programs and user's
17
 * customers, employees, agents, transferees, successors, and assigns.
18
 *
19
 * The MPEG Software Simulation Group does not represent or warrant that the
20
 * programs furnished hereunder are free of infringement of any third-party
21
 * patents.
22
 *
23
 * Commercial implementations of MPEG-1 and MPEG-2 video, including shareware,
24
 * are subject to royalty fees to patent holders.  Many of these patents are
25
 * general enough such that they are unavoidable regardless of implementation
26
 * design.
27
 *
28
 */
29
 
30
#include <stdlib.h>
31
 
32
#include "drivers/glib.h"
33
 
34
#include "config.h"
35
#include "global.h"
36
 
37
extern DWORD flbaddr;
38
 
39
static void conv422to444 _ANSI_ARGS_((unsigned char *src, unsigned char *dst));
40
static void conv420to422 _ANSI_ARGS_((unsigned char *src, unsigned char *dst));
41
 
42
__inline__ WORD down32to16(unsigned char r, unsigned char g, unsigned char b)
43
{
44
    return ((b&0xf8)>>3)|((g&0xfc)<<3)|((r&0xf8)<<8);
45
}
46
 
47
void Write_Frame _ANSI_ARGS_((unsigned char *src[], int frame))
48
{
49
  int i, j;
50
  int y, u, v, r, g, b;
51
//  int rm=0,gm=0,bm=0;
52
  int crv, cbu, cgu, cgv;
53
  unsigned char *py, *pu, *pv;
54
  int height, width, incr;
55
  static unsigned char *u422, *v422, *u444, *v444;
56
 
57
  incr = width = Coded_Picture_Width ;
58
  height = Coded_Picture_Height;
59
 
60
  if (chroma_format==CHROMA444)
61
  {
62
    u444 = src[1];
63
    v444 = src[2];
64
  }
65
  else
66
  {
67
    if (!u444)
68
    {
69
      if (chroma_format==CHROMA420)
70
      {
71
        if (!(u422 = (unsigned char *)malloc((Coded_Picture_Width>>1)
72
                                             *Coded_Picture_Height)))
73
          Error("malloc failed");
74
        if (!(v422 = (unsigned char *)malloc((Coded_Picture_Width>>1)
75
                                             *Coded_Picture_Height)))
76
          Error("malloc failed");
77
      }
78
 
79
      if (!(u444 = (unsigned char *)malloc(Coded_Picture_Width
80
                                           *Coded_Picture_Height)))
81
        Error("malloc failed");
82
 
83
      if (!(v444 = (unsigned char *)malloc(Coded_Picture_Width
84
                                           *Coded_Picture_Height)))
85
        Error("malloc failed");
86
    }
87
 
88
    if (chroma_format==CHROMA420)
89
    {
90
      conv420to422(src[1],u422);
91
      conv420to422(src[2],v422);
92
      conv422to444(u422,u444);
93
      conv422to444(v422,v444);
94
    }
95
    else
96
    {
97
      conv422to444(src[1],u444);
98
      conv422to444(src[2],v444);
99
    }
100
  }
101
 
102
  /* matrix coefficients */
103
  crv = Inverse_Table_6_9[matrix_coefficients][0];
104
  cbu = Inverse_Table_6_9[matrix_coefficients][1];
105
  cgu = Inverse_Table_6_9[matrix_coefficients][2];
106
  cgv = Inverse_Table_6_9[matrix_coefficients][3];
107
 
108
  for (i=0; i<height; i++)
109
  {
110
    py = src[0] + incr*i;
111
    pu = u444 + incr*i;
112
    pv = v444 + incr*i;
113
 
114
    for (j=0; j<width; j++)
115
    {
116
      u = *pu++ - 128;
117
      v = *pv++ - 128;
118
      y = 76309 * (*py++ - 16); /* (255/219)*65536 */
119
 
120
      r = Clip[(y + crv*v + 32768)>>16];
121
      g = Clip[(y - cgu*u - cgv*v + 32768)>>16];
122
      b = Clip[(y + cbu*u + 32786)>>16];
123
 
124
      *(WORD *)(flbaddr+((i+ld->py)*800+(j+ld->px))*2) = down32to16(r,g,b);
125
 
126
    }
127
  }
128
 
129
}
130
 
131
/*
132
void Display_Image(Dithered_Image)
133
unsigned char *Dithered_Image;
134
{
135
  / * display dithered image */
136
//}
137
 
138
 
139
/* horizontal 1:2 interpolation filter */
140
static void conv422to444(src,dst)
141
unsigned char *src,*dst;
142
{
143
  int i, i2, w, j, im3, im2, im1, ip1, ip2, ip3;
144
 
145
  w = Coded_Picture_Width>>1;
146
 
147
  if (base.MPEG2_Flag)
148
  {
149
    for (j=0; j<Coded_Picture_Height; j++)
150
    {
151
      for (i=0; i<w; i++)
152
      {
153
        i2 = i<<1;
154
        im2 = (i<2) ? 0 : i-2;
155
        im1 = (i<1) ? 0 : i-1;
156
        ip1 = (i<w-1) ? i+1 : w-1;
157
        ip2 = (i<w-2) ? i+2 : w-1;
158
        ip3 = (i<w-3) ? i+3 : w-1;
159
 
160
        /* FIR filter coefficients (*256): 21 0 -52 0 159 256 159 0 -52 0 21 */
161
        /* even samples (0 0 256 0 0) */
162
        dst[i2] = src[i];
163
 
164
        /* odd samples (21 -52 159 159 -52 21) */
165
        dst[i2+1] = Clip[(int)(21*(src[im2]+src[ip3])
166
                        -52*(src[im1]+src[ip2])
167
                       +159*(src[i]+src[ip1])+128)>>8];
168
      }
169
      src+= w;
170
      dst+= Coded_Picture_Width;
171
    }
172
  }
173
  else
174
  {
175
    for (j=0; j<Coded_Picture_Height; j++)
176
    {
177
      for (i=0; i<w; i++)
178
      {
179
 
180
        i2 = i<<1;
181
        im3 = (i<3) ? 0 : i-3;
182
        im2 = (i<2) ? 0 : i-2;
183
        im1 = (i<1) ? 0 : i-1;
184
        ip1 = (i<w-1) ? i+1 : w-1;
185
        ip2 = (i<w-2) ? i+2 : w-1;
186
        ip3 = (i<w-3) ? i+3 : w-1;
187
 
188
        /* FIR filter coefficients (*256): 5 -21 70 228 -37 11 */
189
        dst[i2] =   Clip[(int)(  5*src[im3]
190
                         -21*src[im2]
191
                         +70*src[im1]
192
                        +228*src[i]
193
                         -37*src[ip1]
194
                         +11*src[ip2]+128)>>8];
195
 
196
       dst[i2+1] = Clip[(int)(  5*src[ip3]
197
                         -21*src[ip2]
198
                         +70*src[ip1]
199
                        +228*src[i]
200
                         -37*src[im1]
201
                         +11*src[im2]+128)>>8];
202
      }
203
      src+= w;
204
      dst+= Coded_Picture_Width;
205
    }
206
  }
207
}
208
 
209
/* vertical 1:2 interpolation filter */
210
static void conv420to422(src,dst)
211
unsigned char *src,*dst;
212
{
213
  int w, h, i, j, j2;
214
  int jm6, jm5, jm4, jm3, jm2, jm1, jp1, jp2, jp3, jp4, jp5, jp6, jp7;
215
 
216
  w = Coded_Picture_Width>>1;
217
  h = Coded_Picture_Height>>1;
218
 
219
  if (progressive_frame)
220
  {
221
    /* intra frame */
222
    for (i=0; i<w; i++)
223
    {
224
      for (j=0; j<h; j++)
225
      {
226
        j2 = j<<1;
227
        jm3 = (j<3) ? 0 : j-3;
228
        jm2 = (j<2) ? 0 : j-2;
229
        jm1 = (j<1) ? 0 : j-1;
230
        jp1 = (j<h-1) ? j+1 : h-1;
231
        jp2 = (j<h-2) ? j+2 : h-1;
232
        jp3 = (j<h-3) ? j+3 : h-1;
233
 
234
        /* FIR filter coefficients (*256): 5 -21 70 228 -37 11 */
235
        /* New FIR filter coefficients (*256): 3 -16 67 227 -32 7 */
236
        dst[w*j2] =     Clip[(int)(  3*src[w*jm3]
237
                             -16*src[w*jm2]
238
                             +67*src[w*jm1]
239
                            +227*src[w*j]
240
                             -32*src[w*jp1]
241
                             +7*src[w*jp2]+128)>>8];
242
 
243
        dst[w*(j2+1)] = Clip[(int)(  3*src[w*jp3]
244
                             -16*src[w*jp2]
245
                             +67*src[w*jp1]
246
                            +227*src[w*j]
247
                             -32*src[w*jm1]
248
                             +7*src[w*jm2]+128)>>8];
249
      }
250
      src++;
251
      dst++;
252
    }
253
  }
254
  else
255
  {
256
    /* intra field */
257
    for (i=0; i<w; i++)
258
    {
259
      for (j=0; j<h; j+=2)
260
      {
261
        j2 = j<<1;
262
 
263
        /* top field */
264
        jm6 = (j<6) ? 0 : j-6;
265
        jm4 = (j<4) ? 0 : j-4;
266
        jm2 = (j<2) ? 0 : j-2;
267
        jp2 = (j<h-2) ? j+2 : h-2;
268
        jp4 = (j<h-4) ? j+4 : h-2;
269
        jp6 = (j<h-6) ? j+6 : h-2;
270
 
271
        /* Polyphase FIR filter coefficients (*256): 2 -10 35 242 -18 5 */
272
        /* New polyphase FIR filter coefficients (*256): 1 -7 30 248 -21 5 */
273
        dst[w*j2] = Clip[(int)(  1*src[w*jm6]
274
                         -7*src[w*jm4]
275
                         +30*src[w*jm2]
276
                        +248*src[w*j]
277
                         -21*src[w*jp2]
278
                          +5*src[w*jp4]+128)>>8];
279
 
280
        /* Polyphase FIR filter coefficients (*256): 11 -38 192 113 -30 8 */
281
        /* New polyphase FIR filter coefficients (*256):7 -35 194 110 -24 4 */
282
        dst[w*(j2+2)] = Clip[(int)( 7*src[w*jm4]
283
                             -35*src[w*jm2]
284
                            +194*src[w*j]
285
                            +110*src[w*jp2]
286
                             -24*src[w*jp4]
287
                              +4*src[w*jp6]+128)>>8];
288
 
289
        /* bottom field */
290
        jm5 = (j<5) ? 1 : j-5;
291
        jm3 = (j<3) ? 1 : j-3;
292
        jm1 = (j<1) ? 1 : j-1;
293
        jp1 = (j<h-1) ? j+1 : h-1;
294
        jp3 = (j<h-3) ? j+3 : h-1;
295
        jp5 = (j<h-5) ? j+5 : h-1;
296
        jp7 = (j<h-7) ? j+7 : h-1;
297
 
298
        /* Polyphase FIR filter coefficients (*256): 11 -38 192 113 -30 8 */
299
        /* New polyphase FIR filter coefficients (*256):7 -35 194 110 -24 4 */
300
        dst[w*(j2+1)] = Clip[(int)( 7*src[w*jp5]
301
                             -35*src[w*jp3]
302
                            +194*src[w*jp1]
303
                            +110*src[w*jm1]
304
                             -24*src[w*jm3]
305
                              +4*src[w*jm5]+128)>>8];
306
 
307
        dst[w*(j2+3)] = Clip[(int)(  1*src[w*jp7]
308
                             -7*src[w*jp5]
309
                             +30*src[w*jp3]
310
                            +248*src[w*jp1]
311
                             -21*src[w*jm1]
312
                              +5*src[w*jm3]+128)>>8];
313
      }
314
      src++;
315
      dst++;
316
    }
317
  }
318
}
319