~n-muench/ubuntu/oneiric/open-vm-tools/open-vm-tools.fix-836277

« back to all changes in this revision

Viewing changes to lib/raster/rasterConv.c

  • Committer: Bazaar Package Importer
  • Author(s): Devid Antonio Filoni
  • Date: 2008-08-15 21:21:40 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080815212140-05fhxj8wroosysmj
Tags: 2008.08.08-109361-1ubuntu1
* Merge from Debian unstable (LP: #258393), remaining Ubuntu change:
  - add ubuntu_toolchain_FTBFS.dpatch patch, fix FTBFS
* Update ubuntu_toolchain_FTBFS.dpatch patch for the new version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*********************************************************
 
2
 * Copyright (C) 1998 VMware, Inc. All rights reserved.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify it
 
5
 * under the terms of the GNU Lesser General Public License as published
 
6
 * by the Free Software Foundation version 2.1 and no later version.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful, but
 
9
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 
10
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the Lesser GNU General Public
 
11
 * License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU Lesser General Public License
 
14
 * along with this program; if not, write to the Free Software Foundation, Inc.,
 
15
 * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA.
 
16
 *
 
17
 *********************************************************/
 
18
 
 
19
/*
 
20
 * rasterConv.c --
 
21
 *
 
22
 *      Pixel conversion routines
 
23
 */
 
24
 
 
25
#include <stdlib.h>
 
26
#include <stdio.h>
 
27
#include <string.h>
 
28
 
 
29
#include "vmware.h"
 
30
#include "rasterConv.h"
 
31
 
 
32
#define CONVERT_LONG_TO_SHORT(pix, redMask, greenMask, blueMask,        \
 
33
                              redShift, greenShift, blueShift)          \
 
34
   (((redMask) & ((pix) >> (redShift))) |                               \
 
35
    ((greenMask) & ((pix) >> (greenShift))) |                           \
 
36
    ((blueMask) & ((pix) >> (blueShift))))
 
37
 
 
38
#define CONVERT_SHORT_TO_LONG(pix, redMask, greenMask, blueMask,        \
 
39
                              redShift1, redShift2,                     \
 
40
                              greenShift1, greenShift2,                 \
 
41
                              blueShift1, blueShift2)                   \
 
42
   ((REDMASK_32 &                                                       \
 
43
     (((((pix) & (redMask)) >> (redShift1)) |                           \
 
44
      (((pix) & (redMask)) >> (redShift2))) << 16)) |                   \
 
45
    (GREENMASK_32 &                                                     \
 
46
     (((((pix) & (greenMask)) >> (greenShift1)) |                       \
 
47
      (((pix) & (greenMask)) >> (greenShift2))) << 8)) |                \
 
48
    (BLUEMASK_32 &                                                      \
 
49
     ((((pix) & (blueMask)) << (blueShift1)) |                          \
 
50
      (((pix) & (blueMask)) >> (blueShift2)))))
 
51
 
 
52
#define CONVERT_LONG_TO_8BGR(pix, redMask, greenMask, blueMask, \
 
53
                              redShift, greenShift, blueShift)          \
 
54
   (((redMask) & ((pix) >> (redShift))) |                               \
 
55
    ((greenMask) & ((pix) >> (greenShift))) |                           \
 
56
    ((blueMask) & ((pix) << (blueShift))))
 
57
 
 
58
 
 
59
static const uint8 byte_masks_8bgr[9][3] = {
 
60
   /*0*/ {0,0,0},
 
61
   /*1*/ {0,0,0},
 
62
   /*2*/ {0,0,0},
 
63
   /*3*/ {REDMASK_BGR111, GREENMASK_BGR111, BLUEMASK_BGR111},
 
64
   /*4*/ {0,0,0},
 
65
   /*5*/ {0,0,0},
 
66
   /*6*/ {REDMASK_RGB222, GREENMASK_RGB222, BLUEMASK_RGB222},
 
67
   /*7*/ {0,0,0},
 
68
   /*8*/ {REDMASK_BGR233, GREENMASK_BGR233, BLUEMASK_BGR233}
 
69
};
 
70
 
 
71
#define REDMASK_8BPP(depth) (byte_masks_8bgr[depth][0])
 
72
#define GREENMASK_8BPP(depth) (byte_masks_8bgr[depth][1])
 
73
#define BLUEMASK_8BPP(depth) (byte_masks_8bgr[depth][2])
 
74
 
 
75
 
 
76
/*
 
77
 * Local functions
 
78
 */
 
79
 
 
80
static void RasterConvert15to16(uint8 *tof, uint32 line_increment,
 
81
                                uint8 *src, uint32 src_increment,
 
82
                                uint32 src_x, uint32 src_y,
 
83
                                uint32 x, uint32 y, uint32 w, uint32 h);
 
84
static void RasterConvertShortTo24(uint8 *tof, uint32 line_increment,
 
85
                                   uint8 *src, uint32 src_increment,
 
86
                                   uint32 src_x, uint32 src_y,
 
87
                                   uint32 x, uint32 y, uint32 w, uint32 h,
 
88
                                   uint32 redMask, uint32 greenMask,
 
89
                                   uint32 blueMask,
 
90
                                   uint32 redShift1, uint32 redShift2,
 
91
                                   uint32 greenShift1, uint32 greenShift2,
 
92
                                   uint32 blueShift1, uint32 blueShift2);
 
93
static void RasterConvertShortTo32(uint8 *tof, uint32 line_increment,
 
94
                                   uint8 *src, uint32 src_increment,
 
95
                                   uint32 src_x, uint32 src_y,
 
96
                                   uint32 x, uint32 y, uint32 w, uint32 h,
 
97
                                   uint32 redMask, uint32 greenMask,
 
98
                                   uint32 blueMask,
 
99
                                   uint32 redShift1, uint32 redShift2,
 
100
                                   uint32 greenShift1, uint32 greenShift2,
 
101
                                   uint32 blueShift1, uint32 blueShift2);
 
102
static void RasterConvert16to15(uint8 *tof, uint32 line_increment,
 
103
                                uint8 *src, uint32 src_increment,
 
104
                                uint32 src_x, uint32 src_y,
 
105
                                uint32 x, uint32 y, uint32 w, uint32 h);
 
106
static void RasterConvert24toShort(uint8 *tof, uint32 line_increment,
 
107
                                   uint8 *src, uint32 src_increment,
 
108
                                   uint32 src_x, uint32 src_y,
 
109
                                   uint32 x, uint32 y, uint32 w, uint32 h,
 
110
                                   uint32 redMask, uint32 greenMask,
 
111
                                   uint32 blueMask,
 
112
                                   uint32 redShift, uint32 greenShift,
 
113
                                   uint32 blueShift);
 
114
static void RasterConvert24to32(uint8 *tof, uint32 line_increment,
 
115
                                uint8 *src, uint32 src_increment,
 
116
                                uint32 src_x, uint32 src_y,
 
117
                                uint32 x, uint32 y, uint32 w, uint32 h);
 
118
static void RasterConvert32toShort(uint8 *tof, uint32 line_increment,
 
119
                                   uint8 *src, uint32 src_increment,
 
120
                                   uint32 src_x, uint32 src_y,
 
121
                                   uint32 x, uint32 y, uint32 w, uint32 h,
 
122
                                   uint32 redMask, uint32 greenMask,
 
123
                                   uint32 blueMask,
 
124
                                   uint32 redShift, uint32 greenShift,
 
125
                                   uint32 blueShift);
 
126
static void RasterConvert32to24(uint8 *tof, uint32 line_increment,
 
127
                                uint8 *src, uint32 src_increment,
 
128
                                uint32 src_x, uint32 src_y,
 
129
                                uint32 x, uint32 y, uint32 w, uint32 h);
 
130
static void RasterConvertIndextoShort(uint8 *tof, uint32 line_increment,
 
131
                                      uint8 *src, uint32 src_increment,
 
132
                                      uint32 *pixels,
 
133
                                      uint32 src_x, uint32 src_y,
 
134
                                      uint32 x, uint32 y, uint32 w, uint32 h,
 
135
                                      uint32 redMask, uint32 greenMask,
 
136
                                      uint32 blueMask,
 
137
                                      uint32 redShift, uint32 greenShift,
 
138
                                      uint32 blueShift);
 
139
static void RasterConvertIndexto24(uint8 *tof, uint32 line_increment,
 
140
                                   uint8 *src, uint32 src_increment,
 
141
                                   uint32 *pixels,
 
142
                                   uint32 src_x, uint32 src_y,
 
143
                                   uint32 x, uint32 y, uint32 w, uint32 h);
 
144
static void RasterConvertIndexto32(uint8 *tof, uint32 line_increment,
 
145
                                   uint8 *src, uint32 src_increment,
 
146
                                   uint32 *pixels,
 
147
                                   uint32 src_x, uint32 src_y,
 
148
                                   uint32 x, uint32 y, uint32 w, uint32 h);
 
149
 
 
150
static void RasterConvert32to8(uint8 *tof, uint32 line_increment,
 
151
                               uint8 *src, uint32 src_increment,
 
152
                               uint32 src_x, uint32 src_y,
 
153
                               uint32 x, uint32 y, uint32 w, uint32 h,
 
154
                               uint32 redMask, uint32 greenMask, uint32 blueMask,
 
155
                               uint32 redShift, uint32 greenShift, uint32 blueShift);
 
156
static void RasterConvert24to8(uint8 *tof, uint32 line_increment,
 
157
                               uint8 *src, uint32 src_increment,
 
158
                               uint32 src_x, uint32 src_y,
 
159
                               uint32 x, uint32 y, uint32 w, uint32 h,
 
160
                               uint32 redMask, uint32 greenMask, uint32 blueMask,
 
161
                               uint32 redShift, uint32 greenShift, uint32 blueShift);
 
162
static void RasterConvert16to8(uint8 *tof, uint32 line_increment,
 
163
                               uint8 *src, uint32 src_increment,
 
164
                               uint32 src_x, uint32 src_y,
 
165
                               uint32 x, uint32 y, uint32 w, uint32 h,
 
166
                               uint32 redMask, uint32 greenMask, uint32 blueMask,
 
167
                               int redShift, int greenShift, int blueShift);
 
168
static void RasterConvertIndexto8(uint8 *tof, uint32 line_increment,
 
169
                                  uint8 *src, uint32 src_increment, uint32 *pixels,
 
170
                                  uint32 src_x, uint32 src_y,
 
171
                                  uint32 x, uint32 y, uint32 w, uint32 h,
 
172
                                  uint32 redMask, uint32 greenMask, uint32 blueMask,
 
173
                                  uint32 redShift, uint32 greenShift, uint32 blueShift);
 
174
static int RasterGetShiftFromMask(uint32 start, uint32 mask);
 
175
static INLINE uint32 RasterShiftPixel(uint32 pixel, int shift);
 
176
 
 
177
 
 
178
/*
 
179
 *----------------------------------------------------------------------
 
180
 *
 
181
 * Raster_IsModeReasonable --
 
182
 *
 
183
 *      Determine if a mode is something that Raster_Convert*
 
184
 *      can deal with.
 
185
 *
 
186
 * Results:
 
187
 *      TRUE if we like the mode.
 
188
 *
 
189
 * Side effects:
 
190
 *      None.
 
191
 *
 
192
 *----------------------------------------------------------------------
 
193
 */
 
194
 
 
195
Bool
 
196
Raster_IsModeReasonable(uint32 depth, uint32 bpp, Bool pseudocolor)
 
197
{
 
198
   return (pseudocolor && bpp == 8) || (!pseudocolor &&
 
199
                                        ((bpp == 16 && (depth == 15 ||
 
200
                                                        depth == 16)) ||
 
201
                                         (bpp == 24 && depth == 24) ||
 
202
                                         (bpp == 32 && depth == 24)));
 
203
}
 
204
 
 
205
 
 
206
/*
 
207
 *----------------------------------------------------------------------
 
208
 *
 
209
 * Raster_GetBPPDepth --
 
210
 *
 
211
 *      Converts separate depth and bpp values into one "bppdepth."
 
212
 *      See comment above Raster_ConvertPixels().
 
213
 *
 
214
 * Results:
 
215
 *      The bppdepth.
 
216
 *
 
217
 * Side effects:
 
218
 *      None.
 
219
 *
 
220
 *----------------------------------------------------------------------
 
221
 */
 
222
 
 
223
int
 
224
Raster_GetBPPDepth(uint32 depth, uint32 bpp)
 
225
{
 
226
   if (depth == 24 && bpp == 32) {
 
227
      return 32;
 
228
   } else {
 
229
      return depth;
 
230
   }
 
231
}
 
232
 
 
233
 
 
234
/*
 
235
 *----------------------------------------------------------------------
 
236
 *
 
237
 * Raster_ConvertPixels --
 
238
 *
 
239
 *      Convert pixels from one depth to another, while copying from
 
240
 *      source to destination.
 
241
 *
 
242
 *      bppdepth is a unique number specifying the bpp/color-depth,
 
243
 *      like so:
 
244
 *
 
245
 *      bpp   depth    bppdepth
 
246
 *      -----------------------
 
247
 *       8      3         3
 
248
 *       8      6         6
 
249
 *       8      8         8
 
250
 *      16     15        15
 
251
 *      16     16        16
 
252
 *      24     24        24
 
253
 *      32     24        32 * This is the only one that differs from depth
 
254
 *
 
255
 * Results:
 
256
 *      None
 
257
 *
 
258
 * Side effects:
 
259
 *      None
 
260
 *
 
261
 *----------------------------------------------------------------------
 
262
 */
 
263
 
 
264
void
 
265
Raster_ConvertPixels(uint8 *tof, int32 line_increment, int bppdepth,
 
266
                     uint8 *src, int32 src_increment, int src_bppdepth,
 
267
                     Bool pseudoColor, uint32 *pixels,
 
268
                     uint32 src_x, uint32 src_y,
 
269
                     uint32 x, uint32 y, uint32 w, uint32 h)
 
270
{
 
271
   int redShift,greenShift, blueShift;
 
272
 
 
273
   if (pseudoColor) {
 
274
      if (src_bppdepth > 8) {
 
275
         Warning("Raster convert pixels invalid depth for pseudo color %d\n",
 
276
                 src_bppdepth);
 
277
         NOT_IMPLEMENTED();
 
278
         return;
 
279
      }
 
280
 
 
281
      switch (bppdepth) {
 
282
         case 3: case 6: case 8:
 
283
            redShift = RasterGetShiftFromMask(24, REDMASK_8BPP(bppdepth));
 
284
            greenShift = RasterGetShiftFromMask(16, GREENMASK_8BPP(bppdepth));
 
285
            blueShift = RasterGetShiftFromMask(8, BLUEMASK_8BPP(bppdepth));
 
286
            ASSERT(redShift >= 0 && greenShift >= 0 && blueShift >= 0);
 
287
            
 
288
            RasterConvertIndexto8(tof, line_increment, src, src_increment,
 
289
                                  pixels, src_x, src_y, x, y, w, h,
 
290
                                  REDMASK_8BPP(bppdepth),
 
291
                                  GREENMASK_8BPP(bppdepth), 
 
292
                                  BLUEMASK_8BPP(bppdepth),
 
293
                                  redShift, greenShift, blueShift);
 
294
            break;
 
295
 
 
296
         case 15:
 
297
            RasterConvertIndextoShort(tof, line_increment, src, src_increment,
 
298
                                      pixels, src_x, src_y, x, y, w, h,
 
299
                                      REDMASK_15, GREENMASK_15, BLUEMASK_15,
 
300
                                      9, 6, 3);
 
301
            break;
 
302
 
 
303
         case 16:
 
304
            RasterConvertIndextoShort(tof, line_increment, src, src_increment,
 
305
                                      pixels, src_x, src_y, x, y, w, h,
 
306
                                      REDMASK_16, GREENMASK_16, BLUEMASK_16,
 
307
                                      8, 5, 3);
 
308
            break;
 
309
 
 
310
         case 24:
 
311
            RasterConvertIndexto24(tof, line_increment, src, src_increment,
 
312
                                   pixels, src_x, src_y, x, y, w, h);
 
313
            break;
 
314
 
 
315
         case 32:
 
316
            RasterConvertIndexto32(tof, line_increment, src, src_increment,
 
317
                                   pixels, src_x, src_y, x, y, w, h);
 
318
            break;
 
319
 
 
320
         default:
 
321
            Warning("Raster convert pixels invalid depth %d\n", bppdepth);
 
322
            NOT_IMPLEMENTED();
 
323
            break;
 
324
      }
 
325
      return;
 
326
   }
 
327
 
 
328
   switch (src_bppdepth) {
 
329
      case 15:
 
330
         switch (bppdepth) {
 
331
            case 3: case 6: case 8:
 
332
               redShift = RasterGetShiftFromMask(15, REDMASK_8BPP(bppdepth));
 
333
               greenShift = RasterGetShiftFromMask(10, GREENMASK_8BPP(bppdepth));
 
334
               blueShift = RasterGetShiftFromMask(5, BLUEMASK_8BPP(bppdepth));
 
335
 
 
336
               RasterConvert16to8(tof, line_increment, src, src_increment,
 
337
                                  src_x, src_y, x, y, w, h,
 
338
                                  REDMASK_8BPP(bppdepth),
 
339
                                  GREENMASK_8BPP(bppdepth), 
 
340
                                  BLUEMASK_8BPP(bppdepth),
 
341
                                  redShift, greenShift, blueShift);
 
342
               break; 
 
343
 
 
344
            case 15:
 
345
               Warning("Raster convert called when no conversion needed\n");
 
346
               NOT_IMPLEMENTED();
 
347
               break;
 
348
 
 
349
            case 16:
 
350
               RasterConvert15to16(tof, line_increment, src, src_increment,
 
351
                                   src_x, src_y, x, y, w, h);
 
352
               break;
 
353
 
 
354
            case 24:
 
355
               RasterConvertShortTo24(tof, line_increment, src, src_increment,
 
356
                                      src_x, src_y, x, y, w, h,
 
357
                                      REDMASK_15, GREENMASK_15, BLUEMASK_15,
 
358
                                      7, 12, 2, 7, 3, 2);
 
359
               break;
 
360
 
 
361
            case 32:
 
362
               RasterConvertShortTo32(tof, line_increment, src, src_increment,
 
363
                                      src_x, src_y, x, y, w, h,
 
364
                                      REDMASK_15, GREENMASK_15, BLUEMASK_15,
 
365
                                      7, 12, 2, 7, 3, 2);
 
366
               break;
 
367
 
 
368
            default:
 
369
               Warning("Raster convert pixels invalid depth %d\n", bppdepth);
 
370
               NOT_IMPLEMENTED();
 
371
               break;
 
372
         }
 
373
         break;
 
374
 
 
375
      case 16:
 
376
         switch (bppdepth) {
 
377
            case 3: case 6: case 8:
 
378
               redShift = RasterGetShiftFromMask(16, REDMASK_8BPP(bppdepth));
 
379
               greenShift = RasterGetShiftFromMask(11, GREENMASK_8BPP(bppdepth));
 
380
               blueShift = RasterGetShiftFromMask(5, BLUEMASK_8BPP(bppdepth));
 
381
 
 
382
               RasterConvert16to8(tof, line_increment, src, src_increment,
 
383
                                  src_x, src_y, x, y, w, h,
 
384
                                  REDMASK_8BPP(bppdepth),
 
385
                                  GREENMASK_8BPP(bppdepth), 
 
386
                                  BLUEMASK_8BPP(bppdepth),
 
387
                                  redShift, greenShift, blueShift);
 
388
               break;
 
389
 
 
390
            case 15:
 
391
               RasterConvert16to15(tof, line_increment, src, src_increment,
 
392
                                   src_x, src_y, x, y, w, h);
 
393
               break;
 
394
 
 
395
            case 16:
 
396
               Warning("Raster convert called when no conversion needed\n");
 
397
               NOT_IMPLEMENTED();
 
398
               break;
 
399
 
 
400
            case 24:
 
401
               RasterConvertShortTo24(tof, line_increment, src, src_increment,
 
402
                                      src_x, src_y, x, y, w, h,
 
403
                                      REDMASK_16, GREENMASK_16, BLUEMASK_16,
 
404
                                      8, 13, 3, 9, 3, 2);
 
405
               break;
 
406
 
 
407
            case 32:
 
408
               RasterConvertShortTo32(tof, line_increment, src, src_increment,
 
409
                                      src_x, src_y, x, y, w, h,
 
410
                                      REDMASK_16, GREENMASK_16, BLUEMASK_16,
 
411
                                      8, 13, 3, 9, 3, 2);
 
412
               break;
 
413
 
 
414
            default:
 
415
               Warning("Raster convert pixels invalid depth %d\n", bppdepth);
 
416
               NOT_IMPLEMENTED();
 
417
               break;
 
418
         }
 
419
         break;
 
420
 
 
421
      case 24:
 
422
         switch (bppdepth) {
 
423
            case 3: case 6: case 8:
 
424
               redShift = RasterGetShiftFromMask(8, REDMASK_8BPP(bppdepth));
 
425
               greenShift = RasterGetShiftFromMask(8, GREENMASK_8BPP(bppdepth));
 
426
               blueShift = RasterGetShiftFromMask(8, BLUEMASK_8BPP(bppdepth));
 
427
               ASSERT(redShift >= 0 && greenShift >= 0 && blueShift >= 0);
 
428
 
 
429
               RasterConvert24to8(tof, line_increment, src, src_increment,
 
430
                                  src_x, src_y, x, y, w, h,
 
431
                                  REDMASK_8BPP(bppdepth),
 
432
                                  GREENMASK_8BPP(bppdepth), 
 
433
                                  BLUEMASK_8BPP(bppdepth),
 
434
                                  redShift, greenShift, blueShift);
 
435
               break;
 
436
 
 
437
            case 15:
 
438
               RasterConvert24toShort(tof, line_increment, src, src_increment,
 
439
                                      src_x, src_y, x, y, w, h,
 
440
                                      REDMASK_15, GREENMASK_15, BLUEMASK_15,
 
441
                                      7, 2, 3);
 
442
               break;
 
443
 
 
444
            case 16:
 
445
               RasterConvert24toShort(tof, line_increment, src, src_increment,
 
446
                                      src_x, src_y, x, y, w, h,
 
447
                                      REDMASK_16, GREENMASK_16, BLUEMASK_16,
 
448
                                      8, 3, 3);
 
449
               break;
 
450
 
 
451
            case 24:
 
452
               Warning("Raster convert called when no conversion needed\n");
 
453
               NOT_IMPLEMENTED();
 
454
               break;
 
455
 
 
456
            case 32:
 
457
               RasterConvert24to32(tof, line_increment, src, src_increment,
 
458
                                   src_x, src_y, x, y, w, h);
 
459
               break;
 
460
 
 
461
            default:
 
462
               Warning("Raster convert pixels invalid depth %d\n", bppdepth);
 
463
               NOT_IMPLEMENTED();
 
464
               break;
 
465
         }
 
466
         break;
 
467
 
 
468
      case 32:
 
469
         switch (bppdepth) {
 
470
            case 3: case 6: case 8:
 
471
               redShift = RasterGetShiftFromMask(24, REDMASK_8BPP(bppdepth));
 
472
               greenShift = RasterGetShiftFromMask(16, GREENMASK_8BPP(bppdepth));
 
473
               blueShift = RasterGetShiftFromMask(8, BLUEMASK_8BPP(bppdepth));
 
474
               ASSERT(redShift >= 0 && greenShift >= 0 && blueShift >= 0);
 
475
 
 
476
               RasterConvert32to8(tof, line_increment, src, src_increment,
 
477
                                  src_x, src_y, x, y, w, h,
 
478
                                  REDMASK_8BPP(bppdepth),
 
479
                                  GREENMASK_8BPP(bppdepth), 
 
480
                                  BLUEMASK_8BPP(bppdepth),
 
481
                                  redShift, greenShift, blueShift);
 
482
               break;
 
483
 
 
484
            case 15:
 
485
               RasterConvert32toShort(tof, line_increment, src, src_increment,
 
486
                                      src_x, src_y, x, y, w, h,
 
487
                                      REDMASK_15, GREENMASK_15, BLUEMASK_15,
 
488
                                      9, 6, 3);
 
489
               break;
 
490
 
 
491
            case 16:
 
492
               RasterConvert32toShort(tof, line_increment, src, src_increment,
 
493
                                      src_x, src_y, x, y, w, h,
 
494
                                      REDMASK_16, GREENMASK_16, BLUEMASK_16,
 
495
                                      8, 5, 3);
 
496
               break;
 
497
 
 
498
            case 24:
 
499
               RasterConvert32to24(tof, line_increment, src, src_increment,
 
500
                                   src_x, src_y, x, y, w, h);
 
501
               break;
 
502
 
 
503
            case 32:
 
504
               Warning("Raster convert called when no conversion needed\n");
 
505
               NOT_IMPLEMENTED();
 
506
               break;
 
507
 
 
508
            default:
 
509
               Warning("Raster convert pixels invalid depth %d\n", bppdepth);
 
510
               NOT_IMPLEMENTED();
 
511
               break;
 
512
         }
 
513
         break;
 
514
 
 
515
      default:
 
516
         Warning("Raster convert pixels invalid source depth %d\n", src_bppdepth);
 
517
         NOT_IMPLEMENTED_BUG(10982);
 
518
         break;
 
519
   }
 
520
}
 
521
 
 
522
 
 
523
/*
 
524
 *----------------------------------------------------------------------
 
525
 *
 
526
 * Raster_ConvertOnePixel --
 
527
 *
 
528
 *      Convert the given pixel from its current depth to the specified
 
529
 *      depth.
 
530
 *
 
531
 * Results:
 
532
 *      The converted pixel
 
533
 *
 
534
 * Side effects:
 
535
 *      None
 
536
 *
 
537
 *----------------------------------------------------------------------
 
538
 */
 
539
 
 
540
uint32
 
541
Raster_ConvertOnePixel(uint32 pix, int src_bppdepth, int bppdepth,
 
542
                       Bool pseudoColor, uint32 *pixels)
 
543
{
 
544
   if (pseudoColor) {
 
545
      if (src_bppdepth != 8) {
 
546
         Warning("Raster convert pixels invalid depth for pseudo color %d\n",
 
547
                 src_bppdepth);
 
548
         NOT_IMPLEMENTED();
 
549
         return 0;
 
550
      }
 
551
      pix = pixels[pix];
 
552
      src_bppdepth = 32;
 
553
   }
 
554
 
 
555
   switch (src_bppdepth) {
 
556
      case 15:
 
557
         switch (bppdepth) {
 
558
            case 3: case 6: case 8:
 
559
               return CONVERT_LONG_TO_8BGR(pix, REDMASK_8BPP(bppdepth), 
 
560
                                           GREENMASK_8BPP(bppdepth),
 
561
                                           BLUEMASK_8BPP(bppdepth), 12, 4, 3);
 
562
 
 
563
            case 15:
 
564
               return pix;
 
565
 
 
566
            case 16:
 
567
               return ((pix & (REDMASK_15 | GREENMASK_15)) << 1) |
 
568
                      ((pix & GREEN_HIBIT_15) >> GREEN_HILOSHIFT_15) |
 
569
                      (pix & BLUEMASK_16);
 
570
 
 
571
            case 24:
 
572
            case 32:
 
573
               return CONVERT_SHORT_TO_LONG(pix, REDMASK_15, GREENMASK_15,
 
574
                                            BLUEMASK_15, 7, 12, 2, 7, 3, 2);
 
575
 
 
576
            default:
 
577
               Warning("Raster convert one pixel invalid depth %d\n", bppdepth);
 
578
               NOT_IMPLEMENTED();
 
579
               return 0;
 
580
         }
 
581
 
 
582
      case 16:
 
583
         switch (bppdepth) {
 
584
            case 3: case 6: case 8:
 
585
               return CONVERT_LONG_TO_8BGR(pix, REDMASK_8BPP(bppdepth), 
 
586
                                           GREENMASK_8BPP(bppdepth),
 
587
                                           BLUEMASK_8BPP(bppdepth), 13, 5, 3);
 
588
 
 
589
            case 15:
 
590
               return ((pix >> 1) & (REDMASK_15 | GREENMASK_15)) |
 
591
                      (pix & BLUEMASK_15);
 
592
 
 
593
            case 16:
 
594
               return pix;
 
595
 
 
596
            case 24:
 
597
            case 32:
 
598
               return CONVERT_SHORT_TO_LONG(pix, REDMASK_16, GREENMASK_16,
 
599
                                            BLUEMASK_16, 8, 13, 3, 9, 3, 2);
 
600
 
 
601
            default:
 
602
               Warning("Raster convert one pixel invalid depth %d\n", bppdepth);
 
603
               NOT_IMPLEMENTED();
 
604
               return 0;
 
605
         }
 
606
 
 
607
      case 24:
 
608
      case 32:
 
609
         switch (bppdepth) {
 
610
            case 3: case 6: case 8:
 
611
               return CONVERT_LONG_TO_8BGR(pix, REDMASK_8BPP(bppdepth), 
 
612
                                           GREENMASK_8BPP(bppdepth),
 
613
                                           BLUEMASK_8BPP(bppdepth), 21, 10, 0);
 
614
 
 
615
            case 15:
 
616
               return CONVERT_LONG_TO_SHORT(pix, REDMASK_15, GREENMASK_15,
 
617
                                            BLUEMASK_15, 9, 6, 3);
 
618
 
 
619
            case 16:
 
620
               return CONVERT_LONG_TO_SHORT(pix, REDMASK_16, GREENMASK_16,
 
621
                                            BLUEMASK_16, 8, 5, 3);
 
622
 
 
623
            case 24:
 
624
            case 32:
 
625
               return pix;
 
626
 
 
627
            default:
 
628
               Warning("Raster convert one pixel invalid depth %d\n", bppdepth);
 
629
               NOT_IMPLEMENTED();
 
630
               return 0;
 
631
         }
 
632
 
 
633
      default:
 
634
         Warning("Raster convert one pixel invalid source depth %d\n",
 
635
                 src_bppdepth);
 
636
         NOT_IMPLEMENTED();
 
637
         return 0;
 
638
   }
 
639
 
 
640
   return pix;
 
641
}
 
642
 
 
643
 
 
644
/*
 
645
 *----------------------------------------------------------------------
 
646
 *
 
647
 * Raster_ConversionParameters --
 
648
 *
 
649
 *      Get component masks that the conversion routines use for the
 
650
 *      supported depths
 
651
 *
 
652
 * Results:
 
653
 *      Returns FALSE if depth not supported
 
654
 *
 
655
 * Side effects:
 
656
 *      None
 
657
 *
 
658
 *----------------------------------------------------------------------
 
659
 */
 
660
 
 
661
Bool
 
662
Raster_ConversionParameters(int bppdepth, uint32 *redMask,
 
663
                            uint32 *greenMask, uint32 *blueMask)
 
664
{
 
665
   switch (bppdepth) {
 
666
      case 15:
 
667
         *redMask = REDMASK_15;
 
668
         *greenMask = GREENMASK_15;
 
669
         *blueMask = BLUEMASK_15;
 
670
         break;
 
671
 
 
672
      case 16:
 
673
         *redMask = REDMASK_16;
 
674
         *greenMask = GREENMASK_16;
 
675
         *blueMask = BLUEMASK_16;
 
676
         break;
 
677
 
 
678
      case 24:
 
679
         *redMask = REDMASK_24;
 
680
         *greenMask = GREENMASK_24;
 
681
         *blueMask = BLUEMASK_24;
 
682
         break;
 
683
 
 
684
      case 32:
 
685
         *redMask = REDMASK_32;
 
686
         *greenMask = GREENMASK_32;
 
687
         *blueMask = BLUEMASK_32;
 
688
         break;
 
689
 
 
690
      default:
 
691
         return FALSE;
 
692
   }
 
693
 
 
694
   return TRUE;
 
695
}
 
696
 
 
697
 
 
698
/*
 
699
 *----------------------------------------------------------------------
 
700
 *
 
701
 * RasterConvert15to16 --
 
702
 *
 
703
 *      Convert pixels from depth 15 to depth 16, while copying from
 
704
 *      source to destination.
 
705
 *
 
706
 * Results:
 
707
 *      None
 
708
 *
 
709
 * Side effects:
 
710
 *      None
 
711
 *
 
712
 *----------------------------------------------------------------------
 
713
 */
 
714
 
 
715
static void
 
716
RasterConvert15to16(uint8 *tof, uint32 line_increment,
 
717
                    uint8 *src, uint32 src_increment,
 
718
                    uint32 src_x, uint32 src_y,
 
719
                    uint32 x, uint32 y, uint32 w, uint32 h)
 
720
{
 
721
   uint16 *srcptr, *dstptr;
 
722
   int i, j;
 
723
 
 
724
   src_increment >>= 1;
 
725
   srcptr = (uint16 *)src;
 
726
   srcptr += (src_y * src_increment) + src_x;
 
727
 
 
728
   line_increment >>= 1;
 
729
   dstptr = (uint16 *)tof;
 
730
   dstptr += (y * line_increment) + x;
 
731
 
 
732
   for (i=0; i<h; i++) {
 
733
      for (j=0; j<w; j++) {
 
734
         uint32 pix = srcptr[j];
 
735
         dstptr[j] = ((pix & (REDMASK_15 | GREENMASK_15)) << 1) |
 
736
                     ((pix & GREEN_HIBIT_15) >> GREEN_HILOSHIFT_15) |
 
737
                     (pix & BLUEMASK_16);
 
738
      }
 
739
      srcptr += src_increment;
 
740
      dstptr += line_increment;
 
741
   }
 
742
}
 
743
 
 
744
 
 
745
/*
 
746
 *----------------------------------------------------------------------
 
747
 *
 
748
 * RasterConvertShortTo24 --
 
749
 *
 
750
 *      Convert pixels from depth 15 or 16 to depth 24, while copying
 
751
 *      from source to destination.
 
752
 *
 
753
 * Results:
 
754
 *      None
 
755
 *
 
756
 * Side effects:
 
757
 *      None
 
758
 *
 
759
 *----------------------------------------------------------------------
 
760
 */
 
761
 
 
762
static void
 
763
RasterConvertShortTo24(uint8 *tof, uint32 line_increment,
 
764
                       uint8 *src, uint32 src_increment,
 
765
                       uint32 src_x, uint32 src_y,
 
766
                       uint32 x, uint32 y, uint32 w, uint32 h,
 
767
                       uint32 redMask, uint32 greenMask, uint32 blueMask,
 
768
                       uint32 redShift1, uint32 redShift2,
 
769
                       uint32 greenShift1, uint32 greenShift2,
 
770
                       uint32 blueShift1, uint32 blueShift2)
 
771
{
 
772
   uint16 *srcptr;
 
773
   uint8 *dstptr;
 
774
   int i, j, k;
 
775
 
 
776
   src_increment >>= 1;
 
777
   srcptr = (uint16 *)src;
 
778
   srcptr += (src_y * src_increment) + src_x;
 
779
 
 
780
   dstptr = tof;
 
781
   dstptr += (y * line_increment) + (x * 3);
 
782
 
 
783
   for (i=0; i<h; i++) {
 
784
      for (j=0, k=0; j<w; j++) {
 
785
         uint32 pix = srcptr[j];
 
786
         dstptr[k++] = ((pix & blueMask) << blueShift1) |
 
787
                       ((pix & blueMask) >> blueShift2);
 
788
         dstptr[k++] = ((pix & greenMask) >> greenShift1) |
 
789
                       ((pix & greenMask) >> greenShift2);
 
790
         dstptr[k++] = ((pix & redMask) >> redShift1) |
 
791
                       ((pix & redMask) >> redShift2);
 
792
      }
 
793
      srcptr += src_increment;
 
794
      dstptr += line_increment;
 
795
   }
 
796
}
 
797
 
 
798
 
 
799
/*
 
800
 *----------------------------------------------------------------------
 
801
 *
 
802
 * RasterConvertShortTo32 --
 
803
 *
 
804
 *      Convert pixels from depth 15 or 16 to depth 32, while copying
 
805
 *      from source to destination.
 
806
 *
 
807
 * Results:
 
808
 *      None
 
809
 *
 
810
 * Side effects:
 
811
 *      None
 
812
 *
 
813
 *----------------------------------------------------------------------
 
814
 */
 
815
 
 
816
static void
 
817
RasterConvertShortTo32(uint8 *tof, uint32 line_increment,
 
818
                       uint8 *src, uint32 src_increment,
 
819
                       uint32 src_x, uint32 src_y,
 
820
                       uint32 x, uint32 y, uint32 w, uint32 h,
 
821
                       uint32 redMask, uint32 greenMask, uint32 blueMask,
 
822
                       uint32 redShift1, uint32 redShift2,
 
823
                       uint32 greenShift1, uint32 greenShift2,
 
824
                       uint32 blueShift1, uint32 blueShift2)
 
825
{
 
826
   uint16 *srcptr;
 
827
   uint32 *dstptr;
 
828
   int i, j;
 
829
 
 
830
   src_increment >>= 1;
 
831
   srcptr = (uint16 *)src;
 
832
   srcptr += (src_y * src_increment) + src_x;
 
833
 
 
834
   line_increment >>= 2;
 
835
   dstptr = (uint32 *)tof;
 
836
   dstptr += (y * line_increment) + x;
 
837
 
 
838
   for (i=0; i<h; i++) {
 
839
      for (j=0; j<w; j++) {
 
840
         uint32 pix = srcptr[j];
 
841
         dstptr[j] = (REDMASK_32 &
 
842
                      ((((pix & redMask) >> redShift1) |
 
843
                        ((pix & redMask) >> redShift2)) << 16)) |
 
844
                     (GREENMASK_32 &
 
845
                      ((((pix & greenMask) >> greenShift1) |
 
846
                        ((pix & greenMask) >> greenShift2)) << 8)) |
 
847
                     (BLUEMASK_32 &
 
848
                      (((pix & blueMask) << blueShift1) |
 
849
                       ((pix & blueMask) >> blueShift2)));
 
850
      }
 
851
      srcptr += src_increment;
 
852
      dstptr += line_increment;
 
853
   }
 
854
}
 
855
 
 
856
 
 
857
/*
 
858
 *----------------------------------------------------------------------
 
859
 *
 
860
 * RasterConvert16to15 --
 
861
 *
 
862
 *      Convert pixels from depth 16 to depth 15, while copying from
 
863
 *      source to destination.
 
864
 *
 
865
 * Results:
 
866
 *      None
 
867
 *
 
868
 * Side effects:
 
869
 *      None
 
870
 *
 
871
 *----------------------------------------------------------------------
 
872
 */
 
873
 
 
874
static void
 
875
RasterConvert16to15(uint8 *tof, uint32 line_increment,
 
876
                    uint8 *src, uint32 src_increment,
 
877
                    uint32 src_x, uint32 src_y,
 
878
                    uint32 x, uint32 y, uint32 w, uint32 h)
 
879
{
 
880
   uint16 *srcptr, *dstptr;
 
881
   int i, j;
 
882
 
 
883
   src_increment >>= 1;
 
884
   srcptr = (uint16 *)src;
 
885
   srcptr += (src_y * src_increment) + src_x;
 
886
 
 
887
   line_increment >>= 1;
 
888
   dstptr = (uint16 *)tof;
 
889
   dstptr += (y * line_increment) + x;
 
890
 
 
891
   for (i=0; i<h; i++) {
 
892
      for (j=0; j<w; j++) {
 
893
         uint32 pix = srcptr[j];
 
894
         dstptr[j] = ((pix >> 1) & (REDMASK_15 | GREENMASK_15)) |
 
895
                     (pix & BLUEMASK_15);
 
896
      }
 
897
      srcptr += src_increment;
 
898
      dstptr += line_increment;
 
899
   }
 
900
}
 
901
 
 
902
 
 
903
/*
 
904
 *----------------------------------------------------------------------
 
905
 *
 
906
 * RasterConvert24toShort --
 
907
 *
 
908
 *      Convert pixels from depth 24 to depth 15 or 16, while copying
 
909
 *      from source to destination.
 
910
 *
 
911
 * Results:
 
912
 *      None
 
913
 *
 
914
 * Side effects:
 
915
 *      None
 
916
 *
 
917
 *----------------------------------------------------------------------
 
918
 */
 
919
 
 
920
static void
 
921
RasterConvert24toShort(uint8 *tof, uint32 line_increment,
 
922
                       uint8 *src, uint32 src_increment,
 
923
                       uint32 src_x, uint32 src_y,
 
924
                       uint32 x, uint32 y, uint32 w, uint32 h,
 
925
                       uint32 redMask, uint32 greenMask, uint32 blueMask,
 
926
                       uint32 redShift, uint32 greenShift, uint32 blueShift)
 
927
{
 
928
   uint8 *srcptr;
 
929
   uint16 *dstptr;
 
930
   int i, j, k;
 
931
 
 
932
   srcptr = src;
 
933
   srcptr += (src_y * src_increment) + (src_x * 3);
 
934
 
 
935
   line_increment >>= 1;
 
936
   dstptr = (uint16 *)tof;
 
937
   dstptr += (y * line_increment) + x;
 
938
 
 
939
   for (i=0; i<h; i++) {
 
940
      for (j=0, k=0; j<w; j++) {
 
941
         uint8 blue = srcptr[k++];
 
942
         uint8 green = srcptr[k++];
 
943
         uint8 red = srcptr[k++];
 
944
         dstptr[j] = ((red << redShift) & redMask) |
 
945
                     ((green << greenShift) & greenMask) |
 
946
                     ((blue >> blueShift) & blueMask);
 
947
      }
 
948
      srcptr += src_increment;
 
949
      dstptr += line_increment;
 
950
   }
 
951
}
 
952
 
 
953
 
 
954
/*
 
955
 *----------------------------------------------------------------------
 
956
 *
 
957
 * RasterConvert24to32 --
 
958
 *
 
959
 *      Convert pixels from depth 24 to depth 32, while copying
 
960
 *      from source to destination.
 
961
 *
 
962
 * Results:
 
963
 *      None
 
964
 *
 
965
 * Side effects:
 
966
 *      None
 
967
 *
 
968
 *----------------------------------------------------------------------
 
969
 */
 
970
 
 
971
static void
 
972
RasterConvert24to32(uint8 *tof, uint32 line_increment,
 
973
                    uint8 *src, uint32 src_increment,
 
974
                    uint32 src_x, uint32 src_y,
 
975
                    uint32 x, uint32 y, uint32 w, uint32 h)
 
976
{
 
977
   uint8 *srcptr;
 
978
   uint32 *dstptr;
 
979
   int i, j, k;
 
980
 
 
981
   srcptr = src;
 
982
   srcptr += (src_y * src_increment) + (src_x * 3);
 
983
 
 
984
   line_increment >>= 2;
 
985
   dstptr = (uint32 *)tof;
 
986
   dstptr += (y * line_increment) + x;
 
987
 
 
988
   for (i=0; i<h; i++) {
 
989
      for (j=0, k=0; j<w; j++) {
 
990
         uint8 blue = srcptr[k++];
 
991
         uint8 green = srcptr[k++];
 
992
         uint8 red = srcptr[k++];
 
993
         dstptr[j] = ((red << 16) & REDMASK_32) |
 
994
                     ((green << 8) & GREENMASK_32) |
 
995
                     (blue & BLUEMASK_32);
 
996
      }
 
997
      srcptr += src_increment;
 
998
      dstptr += line_increment;
 
999
   }
 
1000
}
 
1001
 
 
1002
 
 
1003
/*
 
1004
 *----------------------------------------------------------------------
 
1005
 *
 
1006
 * RasterConvert32toShort --
 
1007
 *
 
1008
 *      Convert pixels from depth 32 to depth 15 or 16, while copying
 
1009
 *      from source to destination.
 
1010
 *
 
1011
 * Results:
 
1012
 *      None
 
1013
 *
 
1014
 * Side effects:
 
1015
 *      None
 
1016
 *
 
1017
 *----------------------------------------------------------------------
 
1018
 */
 
1019
 
 
1020
static void
 
1021
RasterConvert32toShort(uint8 *tof, uint32 line_increment,
 
1022
                       uint8 *src, uint32 src_increment,
 
1023
                       uint32 src_x, uint32 src_y,
 
1024
                       uint32 x, uint32 y, uint32 w, uint32 h,
 
1025
                       uint32 redMask, uint32 greenMask, uint32 blueMask,
 
1026
                       uint32 redShift, uint32 greenShift, uint32 blueShift)
 
1027
{
 
1028
   uint32 *srcptr;
 
1029
   uint16 *dstptr;
 
1030
   int i, j;
 
1031
 
 
1032
   src_increment >>= 2;
 
1033
   srcptr = (uint32 *)src;
 
1034
   srcptr += (src_y * src_increment) + src_x;
 
1035
 
 
1036
   line_increment >>= 1;
 
1037
   dstptr = (uint16 *)tof;
 
1038
   dstptr += (y * line_increment) + x;
 
1039
 
 
1040
   for (i=0; i<h; i++) {
 
1041
      for (j=0; j<w; j++) {
 
1042
         uint32 pix = srcptr[j];
 
1043
         dstptr[j] = (redMask & (pix >> redShift)) |
 
1044
                     (greenMask & (pix >> greenShift)) |
 
1045
                     (blueMask & (pix >> blueShift));
 
1046
      }
 
1047
      srcptr += src_increment;
 
1048
      dstptr += line_increment;
 
1049
   }
 
1050
}
 
1051
 
 
1052
 
 
1053
/*
 
1054
 *----------------------------------------------------------------------
 
1055
 *
 
1056
 * RasterConvert32to24 --
 
1057
 *
 
1058
 *      Convert pixels from depth 32 to depth 24, while copying
 
1059
 *      from source to destination.
 
1060
 *
 
1061
 * Results:
 
1062
 *      None
 
1063
 *
 
1064
 * Side effects:
 
1065
 *      None
 
1066
 *
 
1067
 *----------------------------------------------------------------------
 
1068
 */
 
1069
 
 
1070
static void
 
1071
RasterConvert32to24(uint8 *tof, uint32 line_increment,
 
1072
                    uint8 *src, uint32 src_increment,
 
1073
                    uint32 src_x, uint32 src_y,
 
1074
                    uint32 x, uint32 y, uint32 w, uint32 h)
 
1075
{
 
1076
   uint32 *srcptr;
 
1077
   uint8 *dstptr;
 
1078
   int i, j, k;
 
1079
 
 
1080
   src_increment >>= 2;
 
1081
   srcptr = (uint32 *)src;
 
1082
   srcptr += (src_y * src_increment) + src_x;
 
1083
 
 
1084
   dstptr = tof;
 
1085
   dstptr += (y * line_increment) + (x * 3);
 
1086
 
 
1087
   for (i=0; i<h; i++) {
 
1088
      for (j=0, k=0; j<w; j++) {
 
1089
         uint32 pix = srcptr[j];
 
1090
         dstptr[k++] = pix & BLUEMASK_32;
 
1091
         dstptr[k++] = (pix & GREENMASK_32) >> 8;
 
1092
         dstptr[k++] = (pix & REDMASK_32) >> 16;
 
1093
      }
 
1094
      srcptr += src_increment;
 
1095
      dstptr += line_increment;
 
1096
   }
 
1097
}
 
1098
 
 
1099
 
 
1100
/*
 
1101
 *----------------------------------------------------------------------
 
1102
 *
 
1103
 * RasterConvertIndexto8 --
 
1104
 *
 
1105
 *      Convert pixels from pseudo color values to depth 8 true color while
 
1106
 *      copying from source to destination.
 
1107
 *      BGR233: redShift: 21    greenShift: 10   blueShift: 0   
 
1108
 *
 
1109
 * Results:
 
1110
 *      None
 
1111
 *
 
1112
 * Side effects:
 
1113
 *      None
 
1114
 *
 
1115
 *----------------------------------------------------------------------
 
1116
 */
 
1117
 
 
1118
static void
 
1119
RasterConvertIndexto8(uint8 *tof, uint32 line_increment,
 
1120
                          uint8 *src, uint32 src_increment, uint32 *pixels,
 
1121
                          uint32 src_x, uint32 src_y,
 
1122
                          uint32 x, uint32 y, uint32 w, uint32 h,
 
1123
                          uint32 redMask, uint32 greenMask, uint32 blueMask,
 
1124
                          uint32 redShift, uint32 greenShift, uint32 blueShift)
 
1125
{
 
1126
   uint8 *srcptr;
 
1127
   uint8 *dstptr;
 
1128
   int i, j;
 
1129
 
 
1130
   srcptr = src;
 
1131
   srcptr += (src_y * src_increment) + src_x;
 
1132
 
 
1133
   dstptr = (uint8 *)tof;
 
1134
   dstptr += (y * line_increment) + x;
 
1135
 
 
1136
   for (i=0; i<h; i++) {
 
1137
      for (j=0; j<w; j++) {
 
1138
         uint32 pix = pixels[srcptr[j]];
 
1139
         dstptr[j] = (redMask & (pix >> redShift)) |
 
1140
                     (greenMask & (pix >> greenShift)) |
 
1141
                     (blueMask & (pix >> blueShift));
 
1142
      }
 
1143
      srcptr += src_increment;
 
1144
      dstptr += line_increment;
 
1145
   }
 
1146
}
 
1147
 
 
1148
 
 
1149
/*
 
1150
 *----------------------------------------------------------------------
 
1151
 *
 
1152
 * RasterConvertIndextoShort --
 
1153
 *
 
1154
 *      Convert pixels from pseudo color values to depth 15 or 16, while
 
1155
 *      copying from source to destination.
 
1156
 *
 
1157
 * Results:
 
1158
 *      None
 
1159
 *
 
1160
 * Side effects:
 
1161
 *      None
 
1162
 *
 
1163
 *----------------------------------------------------------------------
 
1164
 */
 
1165
 
 
1166
static void
 
1167
RasterConvertIndextoShort(uint8 *tof, uint32 line_increment,
 
1168
                          uint8 *src, uint32 src_increment, uint32 *pixels,
 
1169
                          uint32 src_x, uint32 src_y,
 
1170
                          uint32 x, uint32 y, uint32 w, uint32 h,
 
1171
                          uint32 redMask, uint32 greenMask, uint32 blueMask,
 
1172
                          uint32 redShift, uint32 greenShift, uint32 blueShift)
 
1173
{
 
1174
   uint8 *srcptr;
 
1175
   uint16 *dstptr;
 
1176
   int i, j;
 
1177
 
 
1178
   srcptr = src;
 
1179
   srcptr += (src_y * src_increment) + src_x;
 
1180
 
 
1181
   line_increment >>= 1;
 
1182
   dstptr = (uint16 *)tof;
 
1183
   dstptr += (y * line_increment) + x;
 
1184
 
 
1185
   for (i=0; i<h; i++) {
 
1186
      for (j=0; j<w; j++) {
 
1187
         uint32 pix = pixels[srcptr[j]];
 
1188
         dstptr[j] = (redMask & (pix >> redShift)) |
 
1189
                     (greenMask & (pix >> greenShift)) |
 
1190
                     (blueMask & (pix >> blueShift));
 
1191
      }
 
1192
      srcptr += src_increment;
 
1193
      dstptr += line_increment;
 
1194
   }
 
1195
}
 
1196
 
 
1197
 
 
1198
/*
 
1199
 *----------------------------------------------------------------------
 
1200
 *
 
1201
 * RasterConvertIndexto24 --
 
1202
 *
 
1203
 *      Convert pixels from pseudo color values to depth 24, while copying
 
1204
 *      from source to destination.
 
1205
 *
 
1206
 * Results:
 
1207
 *      None
 
1208
 *
 
1209
 * Side effects:
 
1210
 *      None
 
1211
 *
 
1212
 *----------------------------------------------------------------------
 
1213
 */
 
1214
 
 
1215
static void
 
1216
RasterConvertIndexto24(uint8 *tof, uint32 line_increment,
 
1217
                       uint8 *src, uint32 src_increment, uint32 *pixels,
 
1218
                       uint32 src_x, uint32 src_y,
 
1219
                       uint32 x, uint32 y, uint32 w, uint32 h)
 
1220
{
 
1221
   uint8 *srcptr;
 
1222
   uint8 *dstptr;
 
1223
   int i, j, k;
 
1224
 
 
1225
   srcptr = src;
 
1226
   srcptr += (src_y * src_increment) + src_x;
 
1227
 
 
1228
   dstptr = tof;
 
1229
   dstptr += (y * line_increment) + (x * 3);
 
1230
 
 
1231
   for (i=0; i<h; i++) {
 
1232
      for (j=0, k=0; j<w; j++) {
 
1233
         uint32 pix = pixels[srcptr[j]];
 
1234
         dstptr[k++] = pix & BLUEMASK_32;
 
1235
         dstptr[k++] = (pix & GREENMASK_32) >> 8;
 
1236
         dstptr[k++] = (pix & REDMASK_32) >> 16;
 
1237
      }
 
1238
      srcptr += src_increment;
 
1239
      dstptr += line_increment;
 
1240
   }
 
1241
}
 
1242
 
 
1243
 
 
1244
/*
 
1245
 *----------------------------------------------------------------------
 
1246
 *
 
1247
 * RasterConvertIndexto32 --
 
1248
 *
 
1249
 *      Convert pixels from pseudo color values to depth 32, while copying
 
1250
 *      from source to destination.
 
1251
 *
 
1252
 * Results:
 
1253
 *      None
 
1254
 *
 
1255
 * Side effects:
 
1256
 *      None
 
1257
 *
 
1258
 *----------------------------------------------------------------------
 
1259
 */
 
1260
 
 
1261
static void
 
1262
RasterConvertIndexto32(uint8 *tof, uint32 line_increment,
 
1263
                       uint8 *src, uint32 src_increment, uint32 *pixels,
 
1264
                       uint32 src_x, uint32 src_y,
 
1265
                       uint32 x, uint32 y, uint32 w, uint32 h)
 
1266
{
 
1267
   uint8 *srcptr;
 
1268
   uint32 *dstptr;
 
1269
   int i, j;
 
1270
 
 
1271
   srcptr = src;
 
1272
   srcptr += (src_y * src_increment) + src_x;
 
1273
 
 
1274
   line_increment >>= 2;
 
1275
   dstptr = (uint32 *)tof;
 
1276
   dstptr += (y * line_increment) + x;
 
1277
 
 
1278
   for (i=0; i<h; i++) {
 
1279
      for (j=0; j<w; j++) {
 
1280
         uint32 pix = pixels[srcptr[j]];
 
1281
         dstptr[j] = pix;
 
1282
      }
 
1283
      srcptr += src_increment;
 
1284
      dstptr += line_increment;
 
1285
   }
 
1286
}
 
1287
 
 
1288
 
 
1289
/*
 
1290
 *----------------------------------------------------------------------
 
1291
 *
 
1292
 * RasterConvert32to8 --
 
1293
 *
 
1294
 *      Convert pixels from depth 32 to depth 8, while copying
 
1295
 *      from source to destination. 
 
1296
 *      BGR233: redShift: 21    greenShift: 10   blueShift: 0 
 
1297
 *
 
1298
 * Results:
 
1299
 *      None
 
1300
 *
 
1301
 * Side effects:
 
1302
 *      None
 
1303
 *
 
1304
 *----------------------------------------------------------------------
 
1305
 */
 
1306
 
 
1307
static void
 
1308
RasterConvert32to8(uint8 *tof, uint32 line_increment,
 
1309
                   uint8 *src, uint32 src_increment,
 
1310
                   uint32 src_x, uint32 src_y,
 
1311
                   uint32 x, uint32 y, uint32 w, uint32 h,
 
1312
                   uint32 redMask, uint32 greenMask, uint32 blueMask,
 
1313
                   uint32 redShift, uint32 greenShift, uint32 blueShift)
 
1314
{
 
1315
   uint32 *srcptr;
 
1316
   uint8 *dstptr;
 
1317
   int i, j;
 
1318
 
 
1319
   src_increment >>= 2;
 
1320
   srcptr = (uint32 *)src;
 
1321
   srcptr += (src_y * src_increment) + src_x;
 
1322
 
 
1323
   dstptr = (uint8 *)tof;
 
1324
   dstptr += (y * line_increment) + x;
 
1325
 
 
1326
   for (i=0; i<h; i++) {
 
1327
      for (j=0; j<w; j++) {
 
1328
         uint32 pix = srcptr[j];
 
1329
         dstptr[j] = (redMask & (pix >> redShift)) |
 
1330
                     (greenMask & (pix >> greenShift)) |
 
1331
                     (blueMask & (pix >> blueShift));
 
1332
      }
 
1333
      srcptr += src_increment;
 
1334
      dstptr += line_increment;
 
1335
   }
 
1336
}
 
1337
 
 
1338
 
 
1339
/*
 
1340
 *----------------------------------------------------------------------
 
1341
 *
 
1342
 * RasterConvert24to8 --
 
1343
 *
 
1344
 *      Convert pixels from depth 24 to depth 8, while copying
 
1345
 *      from source to destination.
 
1346
 *      BGR233: redShift: 5     greenShift: 2    blueShift: 0 
 
1347
 *
 
1348
 * Results:
 
1349
 *      None
 
1350
 *
 
1351
 * Side effects:
 
1352
 *      None
 
1353
 *
 
1354
 *----------------------------------------------------------------------
 
1355
 */
 
1356
 
 
1357
static void
 
1358
RasterConvert24to8(uint8 *tof, uint32 line_increment,
 
1359
                   uint8 *src, uint32 src_increment,
 
1360
                   uint32 src_x, uint32 src_y,
 
1361
                   uint32 x, uint32 y, uint32 w, uint32 h,
 
1362
                   uint32 redMask, uint32 greenMask, uint32 blueMask,
 
1363
                   uint32 redShift, uint32 greenShift, uint32 blueShift)
 
1364
{
 
1365
   uint8 *srcptr;
 
1366
   uint8 *dstptr;
 
1367
   int i, j, k;
 
1368
 
 
1369
   srcptr = src;
 
1370
   srcptr += (src_y * src_increment) + (src_x * 3);
 
1371
 
 
1372
   dstptr = (uint8 *)tof;
 
1373
   dstptr += (y * line_increment) + x;
 
1374
 
 
1375
   for (i=0; i<h; i++) {
 
1376
      for (j=0, k=0; j<w; j++) {
 
1377
         uint8 blue = srcptr[k++];
 
1378
         uint8 green = srcptr[k++];
 
1379
         uint8 red = srcptr[k++];
 
1380
         dstptr[j] = ((red >> redShift) & redMask) |
 
1381
                     ((green >> greenShift) & greenMask) |
 
1382
                     ((blue >> blueShift) & blueMask);
 
1383
      }
 
1384
      srcptr += src_increment;
 
1385
      dstptr += line_increment;
 
1386
   }
 
1387
}
 
1388
 
 
1389
 
 
1390
/*
 
1391
 *----------------------------------------------------------------------
 
1392
 *
 
1393
 * RasterConvert16to8 --
 
1394
 *
 
1395
 *      Convert pixels from depth 16/15 to depth 8 BGR, while copying from
 
1396
 *      source to destination.
 
1397
 *      For BGR233 and depth 16: redShift:13 greenShift:5 
 
1398
 *                               blueShift:3 Shift left 
 
1399
 *      For BGR233 and depth 15: redShift:12 greenShift:4 
 
1400
 *                               blueShift:3 Shift left 
 
1401
 *
 
1402
 * Results:
 
1403
 *      None
 
1404
 *
 
1405
 * Side effects:
 
1406
 *      None
 
1407
 *
 
1408
 *----------------------------------------------------------------------
 
1409
 */
 
1410
 
 
1411
static void
 
1412
RasterConvert16to8(uint8 *tof, uint32 line_increment,
 
1413
                   uint8 *src, uint32 src_increment,
 
1414
                   uint32 src_x, uint32 src_y,
 
1415
                   uint32 x, uint32 y, uint32 w, uint32 h,
 
1416
                   uint32 redMask, uint32 greenMask, uint32 blueMask,
 
1417
                   int redShift, int greenShift, int blueShift)
 
1418
{
 
1419
   uint16 *srcptr;
 
1420
   uint8 *dstptr;
 
1421
   int i, j;
 
1422
 
 
1423
   src_increment >>= 1;
 
1424
   srcptr = (uint16 *)src;
 
1425
   srcptr += (src_y * src_increment) + src_x;
 
1426
 
 
1427
   dstptr = (uint8 *)tof;
 
1428
   dstptr += (y * line_increment) + x;
 
1429
 
 
1430
   for (i=0; i<h; i++) {
 
1431
      for (j=0; j<w; j++) {
 
1432
         uint16 pix = srcptr[j];
 
1433
         dstptr[j] = (redMask & RasterShiftPixel(pix, redShift)) |
 
1434
                     (greenMask & RasterShiftPixel(pix, greenShift)) |
 
1435
                     (blueMask & RasterShiftPixel(pix, blueShift));
 
1436
      }
 
1437
      srcptr += src_increment;
 
1438
      dstptr += line_increment;
 
1439
   }
 
1440
}
 
1441
 
 
1442
 
 
1443
/*
 
1444
 *----------------------------------------------------------------------
 
1445
 *
 
1446
 * RasterGetShiftFromMask --
 
1447
 *
 
1448
 *      Caculate the shift from the mask. For example, if we want to
 
1449
 *      convert from 24 bpp to BGR233, then for greenShift, the green mask 
 
1450
 *      is 11100, green bits in 24 bpp starts from bit 16, the green bits in
 
1451
 *      BGR233 starts from bit 6, then the shift is 16 - 6 = 10
 
1452
 *
 
1453
 * Results:
 
1454
 *      The shift
 
1455
 *
 
1456
 * Side effects:
 
1457
 *      None
 
1458
 *
 
1459
 *----------------------------------------------------------------------
 
1460
 */
 
1461
 
 
1462
static int
 
1463
RasterGetShiftFromMask(uint32 start, uint32 mask)
 
1464
{
 
1465
   uint32 num = 0;
 
1466
 
 
1467
   while (mask) {
 
1468
      mask = mask >> 1;
 
1469
      num++;
 
1470
   }
 
1471
 
 
1472
   return (int)start - (int)num; 
 
1473
}
 
1474
 
 
1475
 
 
1476
/*
 
1477
 *----------------------------------------------------------------------
 
1478
 *
 
1479
 * RasterShiftPixel --
 
1480
 *
 
1481
 *     Shift the pixel. If the shift is negative, shift to left,
 
1482
 *     other, shift to right.
 
1483
 *
 
1484
 * Results:
 
1485
 *      The shifted data
 
1486
 *
 
1487
 * Side effects:
 
1488
 *      None
 
1489
 *
 
1490
 *----------------------------------------------------------------------
 
1491
 */
 
1492
 
 
1493
uint32
 
1494
RasterShiftPixel(uint32 pixel, int shift)
 
1495
{
 
1496
   if (shift < 0) {
 
1497
      return pixel << -shift;
 
1498
   } else {
 
1499
      return pixel >> shift;
 
1500
   }
 
1501
}