~n-muench/ubuntu/precise/open-vm-tools/open-vm-tools.raring-precise.backport

« back to all changes in this revision

Viewing changes to lib/raster/rasterConv.c

  • Committer: Package Import Robot
  • Author(s): Nate Muench
  • Date: 2012-01-23 16:09:45 UTC
  • mfrom: (1.4.6) (2.4.26 sid)
  • Revision ID: package-import@ubuntu.com-20120123160945-b6s0r1vkcovucpf3
Tags: 2011.12.20-562307-0ubuntu1
* Merge latest upstream git tag. Fixes building on Precise
  (LP: #898289, LP: #905612)

* Items merged from Debian unstable:
  - debian/control:
    + open-vm-tools recommends open-vm-dkms. (LP: #598933)
    + open-vm-tools now suggests open-vm-toolbox. (LP: #604998)
  (From 2011.08.21-471295-1 release)
  - Updating maintainer and uploaders fields.
  - Removing vcs fields.
  - Removing references to Daniel's old email address.
  - Updating years in copyright file.
  - Updating to standards version 3.9.2.
  - Updating to debhelper version 8.
  - Switching to source format 3.0 (quilt).
  - Removing manual chrpath setting.
  - Removing exclusion from plugins from debhelper shlibs.
  - Rediffing kvers.patch.
  (From 2011.09.23-491607-1 release)
  - Marking binary architecture-dependend packages as linux and kfreebsd
  only.
  - Removing liburiparser-dev from build-depends as upstream dropped
  unity support.
  - Building with libproc-dev on amd64 again.
  - Dropping disabling of dnet support.
  (From 2011.09.23-491607-2 release)
  - Adding doxygen to build-depends for api documentation.
  - Adding libcunit1-dev to build-depends for test suites.
  - Minimizing rules file.
  - Adding open-vm-tools-dev package, containing only the api
    documentation for now.
  (From 2011.09.23-491607-3 release)
  - Sorting overrides in rules alphabetically.
  - Compacting copyright file.
  - Adding udev rule to set timeout for vmware scsi devices
  (From 2011.12.20-562307-1 release)
  - Adding patch to correct typo in upstreams dkms configuration

* Remaining Changes:
  - Remove Stable part of version numbering.
  - debian folder:
    + Re-added open-vm-dkms.postinst & open-vm-dkms.prerm.
      * Allows dkms modules to compile upon installation.
  - debian/control:
    + Re-add open-vm-source and make into a transitional package
      for open-vm-toolbox.
    + Return dependancies that were moved to open-vm-tools back to
      open-vm-toolbox.
  - debian/rules and debian/open-vm-toolbox.lintian-overrides:
    + Make vmware-user-suid-wrapper suid-root
  - debian/rules:
    + Added CFLAGS field with -Wno-deprecated-declarations
      * Will suppress issues with glib 2.31 or later.
    + Add line to copy vmware-xdg-detect-de into place.
    + Install vmware-user.desktop through toolbox package.
  - debian/open-vm-tools.init:
    + Re-add 'modprobe [-r] vmblock'.
    + Add 'modprobe [-r] vmxnet'.
      * Incase it's not loaded during boot.
    + Remove and re-add pcnet32 module
      * Will be done before (remove) and after (readd) vmxnet module
        is added.
      * If vmxnet doesn't exist (aka modules fail to build), pcnet32 can be
        still used for network connectivity.
      * Workaround until a better fix can be done.
  - Re-add gnome-session to debian/local/xautostart.conf
  - Manpages removed (from debian/manpages):
    + vmmemctl.9
    + vmxnet3.9
    + Remove references to manpages that have been removed.

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