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
 * gray.c --
3
 *
4
 *      More procedures to dither grey-scale images.
5
 *
6
 */
7
 
8
/*
9
 * Copyright (c) 1995 The Regents of the University of California.
10
 * All rights reserved.
11
 *
12
 * Permission to use, copy, modify, and distribute this software and its
13
 * documentation for any purpose, without fee, and without written agreement is
14
 * hereby granted, provided that the above copyright notice and the following
15
 * two paragraphs appear in all copies of this software.
16
 *
17
 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
18
 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
19
 * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
20
 * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
21
 *
22
 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
23
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
24
 * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
25
 * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
26
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
27
 */
28
 
29
#include "video.h"
30
#include "proto.h"
31
#include "dither.h"
32
 
33
 
34
/*
35
 *--------------------------------------------------------------
36
 *
37
 * GrayDitherImage --
38
 *
39
 *      Dithers image into 128 gray scales. Simply maps luminance
40
 *      value into 1 of 128 gray scale colors (divide by two, essentially).
41
 *
42
 * Results:
43
 *      None.
44
 *
45
 * Side effects:
46
 *      None.
47
 *
48
 *--------------------------------------------------------------
49
 */
50
 
51
void
52
GrayDitherImage(lum, cr, cb, out, h, w)
53
    unsigned char *lum;
54
    unsigned char *cr;
55
    unsigned char *cb;
56
    unsigned char *out;
57
    int w, h;
58
{
59
 
60
  int i, max = w*h/16;
61
 
62
  for (i=0; i<max; i++) {
63
    out[0] = pixel[lum[0]];
64
    out[1] = pixel[lum[1]];
65
    out[2] = pixel[lum[2]];
66
    out[3] = pixel[lum[3]];
67
    out[4] = pixel[lum[4]];
68
    out[5] = pixel[lum[5]];
69
    out[6] = pixel[lum[6]];
70
    out[7] = pixel[lum[7]];
71
    out[8] = pixel[lum[8]];
72
    out[9] = pixel[lum[9]];
73
    out[10] = pixel[lum[10]];
74
    out[11] = pixel[lum[11]];
75
    out[12] = pixel[lum[12]];
76
    out[13] = pixel[lum[13]];
77
    out[14] = pixel[lum[14]];
78
    out[15] = pixel[lum[15]];
79
    out += 16;
80
    lum += 16;
81
  }
82
}
83
 
84
 
85
void
86
Gray16DitherImage(lum, cr, cb, p_out, h, w)
87
    unsigned char *lum;
88
    unsigned char *cr;
89
    unsigned char *cb;
90
    unsigned char *p_out;
91
    int w, h;
92
{
93
 
94
  unsigned short *out = (unsigned short *)p_out;
95
 
96
  int i, max = w*h/16;
97
 
98
  for (i=0; i<max; i++) {
99
    out[0] = wpixel[lum[0]];
100
    out[1] = wpixel[lum[1]];
101
    out[2] = wpixel[lum[2]];
102
    out[3] = wpixel[lum[3]];
103
    out[4] = wpixel[lum[4]];
104
    out[5] = wpixel[lum[5]];
105
    out[6] = wpixel[lum[6]];
106
    out[7] = wpixel[lum[7]];
107
    out[8] = wpixel[lum[8]];
108
    out[9] = wpixel[lum[9]];
109
    out[10] = wpixel[lum[10]];
110
    out[11] = wpixel[lum[11]];
111
    out[12] = wpixel[lum[12]];
112
    out[13] = wpixel[lum[13]];
113
    out[14] = wpixel[lum[14]];
114
    out[15] = wpixel[lum[15]];
115
    out += 16;
116
    lum += 16;
117
  }
118
}
119
 
120
void
121
Gray32DitherImage(lum, cr, cb, p_out, h, w)
122
    unsigned char *lum;
123
    unsigned char *cr;
124
    unsigned char *cb;
125
    unsigned char *p_out;
126
    int w, h;
127
{
128
 
129
  unsigned int *out = (unsigned int *)p_out;
130
  int i, max = w*h/16;
131
 
132
  for (i=0; i<max; i++) {
133
    out[0] = wpixel[lum[0]];
134
    out[1] = wpixel[lum[1]];
135
    out[2] = wpixel[lum[2]];
136
    out[3] = wpixel[lum[3]];
137
    out[4] = wpixel[lum[4]];
138
    out[5] = wpixel[lum[5]];
139
    out[6] = wpixel[lum[6]];
140
    out[7] = wpixel[lum[7]];
141
    out[8] = wpixel[lum[8]];
142
    out[9] = wpixel[lum[9]];
143
    out[10] = wpixel[lum[10]];
144
    out[11] = wpixel[lum[11]];
145
    out[12] = wpixel[lum[12]];
146
    out[13] = wpixel[lum[13]];
147
    out[14] = wpixel[lum[14]];
148
    out[15] = wpixel[lum[15]];
149
    out += 16;
150
    lum += 16;
151
  }
152
}
153
 
154
 
155
/*
156
 *--------------------------------------------------------------
157
 *
158
 * Gray2DitherImage --
159
 *
160
 *      Dithers image into 128 gray scales. Simply maps luminance
161
 *      value into 1 of 128 gray scale colors (divide by two, essentially).
162
 *
163
 * Results:
164
 *      None.
165
 *
166
 * Side effects:
167
 *      None.
168
 *
169
 *--------------------------------------------------------------
170
 */
171
 
172
void
173
Gray2DitherImage(lum, cr, cb, p_out, h, w)
174
    unsigned char *lum;
175
    unsigned char *cr;
176
    unsigned char *cb;
177
    unsigned char *p_out;
178
    int w, h;
179
{
180
 
181
  int x, y;
182
  unsigned short *out = (unsigned short *)p_out;
183
  unsigned short *out2 = out + w;
184
 
185
  for (y=0; y<h; y++) {
186
    for (x=0; x<w; x+=16) {
187
      out[0] = out2[0] = wpixel[lum[0]];
188
      out[1] = out2[1] = wpixel[lum[1]];
189
      out[2] = out2[2] = wpixel[lum[2]];
190
      out[3] = out2[3] = wpixel[lum[3]];
191
      out[4] = out2[4] = wpixel[lum[4]];
192
      out[5] = out2[5] = wpixel[lum[5]];
193
      out[6] = out2[6] = wpixel[lum[6]];
194
      out[7] = out2[7] = wpixel[lum[7]];
195
      out[8] = out2[8] = wpixel[lum[8]];
196
      out[9] = out2[9] = wpixel[lum[9]];
197
      out[10] = out2[10] = wpixel[lum[10]];
198
      out[11] = out2[11] = wpixel[lum[11]];
199
      out[12] = out2[12] = wpixel[lum[12]];
200
      out[13] = out2[13] = wpixel[lum[13]];
201
      out[14] = out2[14] = wpixel[lum[14]];
202
      out[15] = out2[15] = wpixel[lum[15]];
203
      out += 16;
204
      out2 += 16;
205
      lum += 16;
206
    }
207
  out += w;
208
  out2 += w;
209
  }
210
}
211
 
212
void
213
Gray216DitherImage(lum, cr, cb, p_out, h, w)
214
    unsigned char *lum;
215
    unsigned char *cr;
216
    unsigned char *cb;
217
    unsigned char *p_out;
218
    int w, h;
219
{
220
 
221
  int x, y;
222
  unsigned int *out = (unsigned int *)p_out;
223
  unsigned int *out2 = out + w;
224
 
225
  for (y=0; y<h; y++) {
226
    for (x=0; x<w; x+=16) {
227
      out[0] = out2[0] = wpixel[lum[0]];
228
      out[1] = out2[1] = wpixel[lum[1]];
229
      out[2] = out2[2] = wpixel[lum[2]];
230
      out[3] = out2[3] = wpixel[lum[3]];
231
      out[4] = out2[4] = wpixel[lum[4]];
232
      out[5] = out2[5] = wpixel[lum[5]];
233
      out[6] = out2[6] = wpixel[lum[6]];
234
      out[7] = out2[7] = wpixel[lum[7]];
235
      out[8] = out2[8] = wpixel[lum[8]];
236
      out[9] = out2[9] = wpixel[lum[9]];
237
      out[10] = out2[10] = wpixel[lum[10]];
238
      out[11] = out2[11] = wpixel[lum[11]];
239
      out[12] = out2[12] = wpixel[lum[12]];
240
      out[13] = out2[13] = wpixel[lum[13]];
241
      out[14] = out2[14] = wpixel[lum[14]];
242
      out[15] = out2[15] = wpixel[lum[15]];
243
      out += 16;
244
      out2 += 16;
245
      lum += 16;
246
    }
247
  out += w;
248
  out2 += w;
249
  }
250
}
251
 
252
#ifndef SIXTYFOUR_BIT
253
 
254
void
255
Gray232DitherImage(lum, cr, cb, p_out, h, w)
256
    unsigned char *lum;
257
    unsigned char *cr;
258
    unsigned char *cb;
259
    unsigned char *p_out;
260
    int w, h;
261
{
262
 
263
  int x, y;
264
  unsigned int *out = (unsigned int *)p_out;
265
  unsigned int *out2 = out + w * 2;
266
 
267
  for (y=0; y<h; y++) {
268
    for (x=0; x<w; x+=16) {
269
      out[0] = out2[0] = out[1] = out2[1] = wpixel[lum[0]];
270
      out[2] = out2[2] = out[3] = out2[3] = wpixel[lum[1]];
271
      out[4] = out2[4] = out[5] = out2[5] = wpixel[lum[2]];
272
      out[6] = out2[6] = out[7] = out2[7] = wpixel[lum[3]];
273
      out[8] = out2[8] = out[9] = out2[9] = wpixel[lum[4]];
274
      out[10] = out2[10] = out[11] = out2[11] = wpixel[lum[5]];
275
      out[12] = out2[12] = out[13] = out2[13] = wpixel[lum[6]];
276
      out[14] = out2[14] = out[15] = out2[15] = wpixel[lum[7]];
277
      out[16] = out2[16] = out[17] = out2[17] = wpixel[lum[8]];
278
      out[18] = out2[18] = out[19] = out2[19] = wpixel[lum[9]];
279
      out[20] = out2[20] = out[21] = out2[21] = wpixel[lum[10]];
280
      out[22] = out2[22] = out[23] = out2[23] = wpixel[lum[11]];
281
      out[24] = out2[24] = out[25] = out2[25] = wpixel[lum[12]];
282
      out[26] = out2[26] = out[27] = out2[27] = wpixel[lum[13]];
283
      out[28] = out2[28] = out[29] = out2[29] = wpixel[lum[14]];
284
      out[30] = out2[30] = out[31] = out2[31] = wpixel[lum[15]];
285
      out += 32;
286
      out2 += 32;
287
      lum += 16;
288
    }
289
  out += w * 2;
290
  out2 += w * 2;
291
  }
292
}
293
 
294
#else /* def SIXTYFOUR_BIT */
295
 
296
void
297
Gray232DitherImage(lum, cr, cb, p_out, h, w)
298
    unsigned char *lum;
299
    unsigned char *cr;
300
    unsigned char *cb;
301
    unsigned char *p_out;
302
    int w, h;
303
{
304
 
305
  int x, y;
306
  unsigned long *out = (unsigned long *)p_out;
307
  unsigned long *out2 = out + w;
308
 
309
  for (y=0; y<h; y++) {
310
    for (x=0; x<w; x+=16) {
311
      out[0] = out2[0]   = wpixel[lum[0]];
312
      out[2] = out2[2]   = wpixel[lum[1]];
313
      out[4] = out2[4]   = wpixel[lum[2]];
314
      out[6] = out2[6]   = wpixel[lum[3]];
315
      out[8] = out2[8]   = wpixel[lum[4]];
316
      out[10] = out2[10] = wpixel[lum[5]];
317
      out[12] = out2[12] = wpixel[lum[6]];
318
      out[14] = out2[14] = wpixel[lum[7]];
319
      out[16] = out2[16] = wpixel[lum[8]];
320
      out[18] = out2[18] = wpixel[lum[9]];
321
      out[20] = out2[20] = wpixel[lum[10]];
322
      out[22] = out2[22] = wpixel[lum[11]];
323
      out[24] = out2[24] = wpixel[lum[12]];
324
      out[26] = out2[26] = wpixel[lum[13]];
325
      out[28] = out2[28] = wpixel[lum[14]];
326
      out[30] = out2[30] = wpixel[lum[15]];
327
      out += 16;
328
      out2 += 16;
329
      lum += 16;
330
    }
331
  out += w;
332
  out2 += w;
333
  }
334
}
335
 
336
#endif /* def SIXTYFOUR_BIT */