Subversion Repositories shark

Rev

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

Rev Author Line No. Line
2 pj 1
/*
2
 * Copyright (c) 1992 The Regents of the University of California.
3
 * All rights reserved.
4
 *
5
 * Permission to use, copy, modify, and distribute this software and its
6
 * documentation for any purpose, without fee, and without written agreement is
7
 * hereby granted, provided that the above copyright notice and the following
8
 * two paragraphs appear in all copies of this software.
9
 *
10
 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
11
 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
12
 * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
13
 * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
16
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
17
 * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
18
 * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
19
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
20
 */
21
 
22
/*
23
 * Portions of this software Copyright (c) 1995 Brown University.
24
 * All rights reserved.
25
 *
26
 * Permission to use, copy, modify, and distribute this software and its
27
 * documentation for any purpose, without fee, and without written agreement
28
 * is hereby granted, provided that the above copyright notice and the
29
 * following two paragraphs appear in all copies of this software.
30
 *
31
 * IN NO EVENT SHALL BROWN UNIVERSITY BE LIABLE TO ANY PARTY FOR DIRECT,
32
 * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
33
 * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF BROWN
34
 * UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35
 *
36
 * BROWN UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
37
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
38
 * PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"
39
 * BASIS, AND BROWN UNIVERSITY HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
40
 * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
41
 */
42
 
43
 
44
#include "video.h"
45
#include "dither.h"
46
#include "mpeg.h"               /* for ImageDesc */
47
 
48
#define NUM_COLORS 256          /* number of entries in colormap */
49
                                /* for gray-scale dithering */
50
 
51
/* Range values for lum, cr, cb. */
52
extern int LUM_RANGE;
53
extern int CR_RANGE;
54
extern int CB_RANGE;
55
 
56
/* Array that remaps color numbers to actual pixel values used by X server. */
57
 
58
extern unsigned char pixel[256];
59
 
60
/* Arrays holding quantized value ranged for lum, cr, and cb. */
61
 
62
extern int *lum_values;
63
extern int *cr_values;
64
extern int *cb_values;
65
 
66
 
67
/* ----------------------------- MNI Header -----------------------------------
68
@NAME       : InitColormap
69
@INPUT      : (none)
70
@OUTPUT     : *NumColors - number of entries in the newly-created colormap
71
              *Map - an array of colourmap entries; each one contains a
72
                     red, green, and blue byte-values (0 .. 255).  
73
                     *Map[i] gives the colour to display a pixel value i.
74
@RETURNS    : (none)
75
@DESCRIPTION: Creates a colour map used for most dithering methods
76
              (everything except full-colour, gray, and monochrome).
77
              The colour map itself is pretty self-explanatory -- a
78
              pixel with value i is to be displayed using the red, green
79
              and blue values in *Map[i] after InitColormap() is done.
80
@METHOD     :
81
@GLOBALS    :
82
@CALLS      :
83
@CREATED    : 95/3/4, Greg Ward: based on InitColorDisplay(), from gdith.c
84
                                 in the original Berkeley player
85
@MODIFIED   :
86
---------------------------------------------------------------------------- */
87
#ifndef DISABLE_DITHER
88
static void
89
InitColormap (int *NumColors, ColormapEntry **Map)
90
{
91
   int i, lum_num, cr_num, cb_num;
92
 
93
   *NumColors =  LUM_RANGE*CB_RANGE*CR_RANGE;
94
   *Map = (ColormapEntry *) malloc (*NumColors * sizeof (ColormapEntry));
95
 
96
   for (i = 0; i < *NumColors; i++)
97
   {
98
      lum_num = (i / (CR_RANGE*CB_RANGE))%LUM_RANGE;
99
      cr_num = (i / CB_RANGE)%CR_RANGE;
100
      cb_num = i % CB_RANGE;
101
 
102
/*      ConvertColor(lum_values[lum_num], cr_values[cr_num], cb_values[cb_num],
103
                   &(*Map)[i].red, &(*Map)[i].green, &(*Map)[i].blue);
104
*/
105
      pixel[i] = i;
106
   }
107
}
108
#endif
109
 
110
 
111
/* ----------------------------- MNI Header -----------------------------------
112
@NAME       : InitGrayColormap
113
@INPUT      : (none)
114
@OUTPUT     : *NumColors - number of entries in the newly-created colormap
115
              *Map - an array of colourmap entries
116
@RETURNS    : (none)
117
@DESCRIPTION: Creates a colour map used for gray-scale dithering, i.e.
118
              the red/green/blue values are the same for any given
119
              pixel value.
120
@METHOD     :
121
@GLOBALS    :
122
@CALLS      :
123
@CREATED    : 95/3/4, Greg Ward: based on InitGrayDisplay(), from gdith.c
124
                                 in the original Berkeley player
125
@MODIFIED   :
126
---------------------------------------------------------------------------- */
127
#ifndef DISABLE_DITHER
128
static void
129
InitGrayColormap (int *NumColors, ColormapEntry **Map)
130
{
131
   int  i;
132
 
133
//cprintf("InitGColor...\n");
134
   *NumColors =  NUM_COLORS;
135
   *Map = (ColormapEntry *) malloc (*NumColors * sizeof (ColormapEntry));
136
 
137
   for (i = 0; i < *NumColors; i++)
138
   {
139
      (*Map)[i].red = (*Map)[i].green = (*Map)[i].blue = i;
140
      pixel[i] = i;
141
   }
142
}
143
#endif
144
 
145
 
146
/* ----------------------------- MNI Header -----------------------------------
147
@NAME       : InitDither
148
@INPUT      : Image - pointer to the image descriptor for the current MPEG
149
@OUTPUT     : Image->ColormapSize, Image->Colormap - the colour map for
150
              this movie, as initialized by either InitColormap or
151
              InitGrayColormap (unless the current dithering scheme
152
              is full colour, in which case there is no colour map)
153
@RETURNS    : (none)
154
@DESCRIPTION: Does all initialization particular to the type of dithering
155
              being used.  Basically, sets up the internal data structures
156
              needed by the dithering code, and then sets up a colour map
157
              needed to display the pixels output by the ditherers.
158
@METHOD     :
159
@GLOBALS    :
160
@CALLS      : InitColor     (for most dithering methods)
161
              InitColormap  (for most dithering methods)
162
              InitGrayColormap (for gray-scale dithering)
163
              Init(..)Dither  (.. = the current dithering method)
164
@CREATED    : 95/3/3, Greg Ward: taken mostly from main() in the original
165
                                 Berkeley player
166
@MODIFIED   :
167
---------------------------------------------------------------------------- */
168
void
169
InitDither (ImageDesc *Image)
170
{
171
   LUM_RANGE = 8;
172
   CR_RANGE = 4;
173
   CB_RANGE = 4;
174
 
175
//cprintf("InitDitherin'...\n");
176
   switch (Image->vid_stream->ditherType)
177
   {
178
#ifndef DISABLE_DITHER
179
      case HYBRID_DITHER:
180
         InitColor ();
181
         InitHybridDither ();
182
         InitColormap (&Image->ColormapSize, &Image->Colormap);
183
         break;
184
 
185
      case HYBRID2_DITHER:
186
         InitColor ();
187
         InitHybridErrorDither ();
188
         InitColormap (&Image->ColormapSize, &Image->Colormap);
189
         break;
190
 
191
      case FS4_DITHER:
192
         InitColor ();
193
         InitFS4Dither ();
194
         InitColormap (&Image->ColormapSize, &Image->Colormap);
195
         break;
196
 
197
      case FS2_DITHER:
198
         InitColor ();
199
         InitFS2Dither ();
200
         InitColormap (&Image->ColormapSize, &Image->Colormap);
201
         break;
202
 
203
      case FS2FAST_DITHER:
204
         InitColor ();
205
         InitFS2FastDither ();
206
         InitColormap (&Image->ColormapSize, &Image->Colormap);
207
         break;
208
 
209
      case Twox2_DITHER:
210
         InitColor ();
211
         Init2x2Dither ();
212
         InitColormap (&Image->ColormapSize, &Image->Colormap);
213
         PostInit2x2Dither ();
214
         break;
215
 
216
      case GRAY_DITHER:
217
//cprintf("InitGray\n");
218
         InitGrayColormap (&Image->ColormapSize, &Image->Colormap);
219
         break;
220
#endif
221
      case FULL_COLOR_DITHER:
222
         wpixel[0] = 0xff;
223
         wpixel[1] = 0xff00;
224
         wpixel[2] = 0xff0000;
225
         Image->vid_stream->matched_depth=24;
226
         InitColorDither(1);
227
         Image->ColormapSize = -1;
228
         Image->Colormap = NULL;
229
         break;
230
 
231
#ifndef DISABLE_DITHER
232
 
233
      // MG      
234
      case HALF_COLOR_DITHER:
235
         wpixel[2] = 0x001f;
236
         wpixel[1] = 0x07e0;
237
         wpixel[0] = 0xf800;
238
         Image->vid_stream->matched_depth=16;
239
         InitColorDither(1);
240
         Image->ColormapSize = -1;
241
         Image->Colormap = NULL;
242
         break;
243
 
244
     case NO_DITHER:
245
         break;
246
 
247
      case ORDERED_DITHER:
248
         InitColor ();
249
         InitOrderedDither ();
250
         InitColormap (&Image->ColormapSize, &Image->Colormap);
251
         break;
252
 
253
      case MONO_DITHER:
254
      case MONO_THRESHOLD:
255
         break;
256
 
257
      case ORDERED2_DITHER:
258
         InitColor ();
259
         InitColormap (&Image->ColormapSize, &Image->Colormap);
260
         InitOrdered2Dither ();
261
         break;
262
 
263
      case MBORDERED_DITHER:
264
         InitColor ();
265
         InitColormap (&Image->ColormapSize, &Image->Colormap);
266
         InitMBOrderedDither ();
267
         break;
268
 
269
      case PPM_DITHER:
270
         Image->ColormapSize = -1;
271
         Image->Colormap = NULL;
272
         wpixel[0] = 0xff;
273
         wpixel[1] = 0xff00;
274
         wpixel[2] = 0xff0000;
275
         Image->vid_stream->matched_depth=24;
276
         InitColorDither(TRUE);
277
         break;
278
#endif
279
   }
280
}  
281
 
282
 
283
void ExecuteDisplay(VidStream *vid_stream, XInfo *xinfo)
284
{
285
  char dummy;
286
  int depth, result;
287
  static int rate_deal = -1;
288
  static int one_frame_time;
289
  register int usec, sec;
290
 
291
 
292
  vid_stream->totNumFrames++;
293
 
294
  if (partialFlag) {
295
    if ((endFrame != -1) && (vid_stream->totNumFrames > endFrame)) {
296
 
297
      vid_stream->film_has_ended=TRUE;
298
      if (loopFlag) {
299
              clear_data_stream(vid_stream);
300
      } else DestroyVidStream(vid_stream, xinfo);
301
      return;
302
    }
303
    if (vid_stream->totNumFrames < startFrame) {
304
      return;
305
    }
306
  }
307
}
308