1
/*********************************************************
2
* Copyright (C) 1998 VMware, Inc. All rights reserved.
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.
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.
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.
17
*********************************************************/
22
* Pixel conversion routines
30
#include "rasterConv.h"
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))))
38
#define CONVERT_SHORT_TO_LONG(pix, redMask, greenMask, blueMask, \
39
redShift1, redShift2, \
40
greenShift1, greenShift2, \
41
blueShift1, blueShift2) \
43
(((((pix) & (redMask)) >> (redShift1)) | \
44
(((pix) & (redMask)) >> (redShift2))) << 16)) | \
46
(((((pix) & (greenMask)) >> (greenShift1)) | \
47
(((pix) & (greenMask)) >> (greenShift2))) << 8)) | \
49
((((pix) & (blueMask)) << (blueShift1)) | \
50
(((pix) & (blueMask)) >> (blueShift2)))))
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))))
59
static const uint8 byte_masks_8bgr[9][3] = {
63
/*3*/ {REDMASK_BGR111, GREENMASK_BGR111, BLUEMASK_BGR111},
66
/*6*/ {REDMASK_RGB222, GREENMASK_RGB222, BLUEMASK_RGB222},
68
/*8*/ {REDMASK_BGR233, GREENMASK_BGR233, BLUEMASK_BGR233}
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])
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,
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,
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,
112
uint32 redShift, uint32 greenShift,
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,
124
uint32 redShift, uint32 greenShift,
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,
133
uint32 src_x, uint32 src_y,
134
uint32 x, uint32 y, uint32 w, uint32 h,
135
uint32 redMask, uint32 greenMask,
137
uint32 redShift, uint32 greenShift,
139
static void RasterConvertIndexto24(uint8 *tof, uint32 line_increment,
140
uint8 *src, uint32 src_increment,
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,
147
uint32 src_x, uint32 src_y,
148
uint32 x, uint32 y, uint32 w, uint32 h);
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);
179
*----------------------------------------------------------------------
181
* Raster_IsModeReasonable --
183
* Determine if a mode is something that Raster_Convert*
187
* TRUE if we like the mode.
192
*----------------------------------------------------------------------
196
Raster_IsModeReasonable(uint32 depth, uint32 bpp, Bool pseudocolor)
198
return (pseudocolor && bpp == 8) || (!pseudocolor &&
199
((bpp == 16 && (depth == 15 ||
201
(bpp == 24 && depth == 24) ||
202
(bpp == 32 && depth == 24)));
207
*----------------------------------------------------------------------
209
* Raster_GetBPPDepth --
211
* Converts separate depth and bpp values into one "bppdepth."
212
* See comment above Raster_ConvertPixels().
220
*----------------------------------------------------------------------
224
Raster_GetBPPDepth(uint32 depth, uint32 bpp)
226
if (depth == 24 && bpp == 32) {
235
*----------------------------------------------------------------------
237
* Raster_ConvertPixels --
239
* Convert pixels from one depth to another, while copying from
240
* source to destination.
242
* bppdepth is a unique number specifying the bpp/color-depth,
246
* -----------------------
253
* 32 24 32 * This is the only one that differs from depth
261
*----------------------------------------------------------------------
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)
271
int redShift,greenShift, blueShift;
274
if (src_bppdepth > 8) {
275
Warning("Raster convert pixels invalid depth for pseudo color %d\n",
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);
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);
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,
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,
311
RasterConvertIndexto24(tof, line_increment, src, src_increment,
312
pixels, src_x, src_y, x, y, w, h);
316
RasterConvertIndexto32(tof, line_increment, src, src_increment,
317
pixels, src_x, src_y, x, y, w, h);
321
Warning("Raster convert pixels invalid depth %d\n", bppdepth);
328
switch (src_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));
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);
345
Warning("Raster convert called when no conversion needed\n");
350
RasterConvert15to16(tof, line_increment, src, src_increment,
351
src_x, src_y, x, y, w, h);
355
RasterConvertShortTo24(tof, line_increment, src, src_increment,
356
src_x, src_y, x, y, w, h,
357
REDMASK_15, GREENMASK_15, BLUEMASK_15,
362
RasterConvertShortTo32(tof, line_increment, src, src_increment,
363
src_x, src_y, x, y, w, h,
364
REDMASK_15, GREENMASK_15, BLUEMASK_15,
369
Warning("Raster convert pixels invalid depth %d\n", 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));
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);
391
RasterConvert16to15(tof, line_increment, src, src_increment,
392
src_x, src_y, x, y, w, h);
396
Warning("Raster convert called when no conversion needed\n");
401
RasterConvertShortTo24(tof, line_increment, src, src_increment,
402
src_x, src_y, x, y, w, h,
403
REDMASK_16, GREENMASK_16, BLUEMASK_16,
408
RasterConvertShortTo32(tof, line_increment, src, src_increment,
409
src_x, src_y, x, y, w, h,
410
REDMASK_16, GREENMASK_16, BLUEMASK_16,
415
Warning("Raster convert pixels invalid depth %d\n", 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);
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);
438
RasterConvert24toShort(tof, line_increment, src, src_increment,
439
src_x, src_y, x, y, w, h,
440
REDMASK_15, GREENMASK_15, BLUEMASK_15,
445
RasterConvert24toShort(tof, line_increment, src, src_increment,
446
src_x, src_y, x, y, w, h,
447
REDMASK_16, GREENMASK_16, BLUEMASK_16,
452
Warning("Raster convert called when no conversion needed\n");
457
RasterConvert24to32(tof, line_increment, src, src_increment,
458
src_x, src_y, x, y, w, h);
462
Warning("Raster convert pixels invalid depth %d\n", 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);
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);
485
RasterConvert32toShort(tof, line_increment, src, src_increment,
486
src_x, src_y, x, y, w, h,
487
REDMASK_15, GREENMASK_15, BLUEMASK_15,
492
RasterConvert32toShort(tof, line_increment, src, src_increment,
493
src_x, src_y, x, y, w, h,
494
REDMASK_16, GREENMASK_16, BLUEMASK_16,
499
RasterConvert32to24(tof, line_increment, src, src_increment,
500
src_x, src_y, x, y, w, h);
504
Warning("Raster convert called when no conversion needed\n");
509
Warning("Raster convert pixels invalid depth %d\n", bppdepth);
516
Warning("Raster convert pixels invalid source depth %d\n", src_bppdepth);
517
NOT_IMPLEMENTED_BUG(10982);
524
*----------------------------------------------------------------------
526
* Raster_ConvertOnePixel --
528
* Convert the given pixel from its current depth to the specified
532
* The converted pixel
537
*----------------------------------------------------------------------
541
Raster_ConvertOnePixel(uint32 pix, int src_bppdepth, int bppdepth,
542
Bool pseudoColor, uint32 *pixels)
545
if (src_bppdepth != 8) {
546
Warning("Raster convert pixels invalid depth for pseudo color %d\n",
555
switch (src_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);
567
return ((pix & (REDMASK_15 | GREENMASK_15)) << 1) |
568
((pix & GREEN_HIBIT_15) >> GREEN_HILOSHIFT_15) |
573
return CONVERT_SHORT_TO_LONG(pix, REDMASK_15, GREENMASK_15,
574
BLUEMASK_15, 7, 12, 2, 7, 3, 2);
577
Warning("Raster convert one pixel invalid depth %d\n", 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);
590
return ((pix >> 1) & (REDMASK_15 | GREENMASK_15)) |
598
return CONVERT_SHORT_TO_LONG(pix, REDMASK_16, GREENMASK_16,
599
BLUEMASK_16, 8, 13, 3, 9, 3, 2);
602
Warning("Raster convert one pixel invalid depth %d\n", 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);
616
return CONVERT_LONG_TO_SHORT(pix, REDMASK_15, GREENMASK_15,
617
BLUEMASK_15, 9, 6, 3);
620
return CONVERT_LONG_TO_SHORT(pix, REDMASK_16, GREENMASK_16,
621
BLUEMASK_16, 8, 5, 3);
628
Warning("Raster convert one pixel invalid depth %d\n", bppdepth);
634
Warning("Raster convert one pixel invalid source depth %d\n",
645
*----------------------------------------------------------------------
647
* Raster_ConversionParameters --
649
* Get component masks that the conversion routines use for the
653
* Returns FALSE if depth not supported
658
*----------------------------------------------------------------------
662
Raster_ConversionParameters(int bppdepth, uint32 *redMask,
663
uint32 *greenMask, uint32 *blueMask)
667
*redMask = REDMASK_15;
668
*greenMask = GREENMASK_15;
669
*blueMask = BLUEMASK_15;
673
*redMask = REDMASK_16;
674
*greenMask = GREENMASK_16;
675
*blueMask = BLUEMASK_16;
679
*redMask = REDMASK_24;
680
*greenMask = GREENMASK_24;
681
*blueMask = BLUEMASK_24;
685
*redMask = REDMASK_32;
686
*greenMask = GREENMASK_32;
687
*blueMask = BLUEMASK_32;
699
*----------------------------------------------------------------------
701
* RasterConvert15to16 --
703
* Convert pixels from depth 15 to depth 16, while copying from
704
* source to destination.
712
*----------------------------------------------------------------------
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)
721
uint16 *srcptr, *dstptr;
725
srcptr = (uint16 *)src;
726
srcptr += (src_y * src_increment) + src_x;
728
line_increment >>= 1;
729
dstptr = (uint16 *)tof;
730
dstptr += (y * line_increment) + x;
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) |
739
srcptr += src_increment;
740
dstptr += line_increment;
746
*----------------------------------------------------------------------
748
* RasterConvertShortTo24 --
750
* Convert pixels from depth 15 or 16 to depth 24, while copying
751
* from source to destination.
759
*----------------------------------------------------------------------
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)
777
srcptr = (uint16 *)src;
778
srcptr += (src_y * src_increment) + src_x;
781
dstptr += (y * line_increment) + (x * 3);
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);
793
srcptr += src_increment;
794
dstptr += line_increment;
800
*----------------------------------------------------------------------
802
* RasterConvertShortTo32 --
804
* Convert pixels from depth 15 or 16 to depth 32, while copying
805
* from source to destination.
813
*----------------------------------------------------------------------
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)
831
srcptr = (uint16 *)src;
832
srcptr += (src_y * src_increment) + src_x;
834
line_increment >>= 2;
835
dstptr = (uint32 *)tof;
836
dstptr += (y * line_increment) + x;
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)) |
845
((((pix & greenMask) >> greenShift1) |
846
((pix & greenMask) >> greenShift2)) << 8)) |
848
(((pix & blueMask) << blueShift1) |
849
((pix & blueMask) >> blueShift2)));
851
srcptr += src_increment;
852
dstptr += line_increment;
858
*----------------------------------------------------------------------
860
* RasterConvert16to15 --
862
* Convert pixels from depth 16 to depth 15, while copying from
863
* source to destination.
871
*----------------------------------------------------------------------
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)
880
uint16 *srcptr, *dstptr;
884
srcptr = (uint16 *)src;
885
srcptr += (src_y * src_increment) + src_x;
887
line_increment >>= 1;
888
dstptr = (uint16 *)tof;
889
dstptr += (y * line_increment) + x;
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)) |
897
srcptr += src_increment;
898
dstptr += line_increment;
904
*----------------------------------------------------------------------
906
* RasterConvert24toShort --
908
* Convert pixels from depth 24 to depth 15 or 16, while copying
909
* from source to destination.
917
*----------------------------------------------------------------------
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)
933
srcptr += (src_y * src_increment) + (src_x * 3);
935
line_increment >>= 1;
936
dstptr = (uint16 *)tof;
937
dstptr += (y * line_increment) + x;
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);
948
srcptr += src_increment;
949
dstptr += line_increment;
955
*----------------------------------------------------------------------
957
* RasterConvert24to32 --
959
* Convert pixels from depth 24 to depth 32, while copying
960
* from source to destination.
968
*----------------------------------------------------------------------
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)
982
srcptr += (src_y * src_increment) + (src_x * 3);
984
line_increment >>= 2;
985
dstptr = (uint32 *)tof;
986
dstptr += (y * line_increment) + x;
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);
997
srcptr += src_increment;
998
dstptr += line_increment;
1004
*----------------------------------------------------------------------
1006
* RasterConvert32toShort --
1008
* Convert pixels from depth 32 to depth 15 or 16, while copying
1009
* from source to destination.
1017
*----------------------------------------------------------------------
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)
1032
src_increment >>= 2;
1033
srcptr = (uint32 *)src;
1034
srcptr += (src_y * src_increment) + src_x;
1036
line_increment >>= 1;
1037
dstptr = (uint16 *)tof;
1038
dstptr += (y * line_increment) + x;
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));
1047
srcptr += src_increment;
1048
dstptr += line_increment;
1054
*----------------------------------------------------------------------
1056
* RasterConvert32to24 --
1058
* Convert pixels from depth 32 to depth 24, while copying
1059
* from source to destination.
1067
*----------------------------------------------------------------------
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)
1080
src_increment >>= 2;
1081
srcptr = (uint32 *)src;
1082
srcptr += (src_y * src_increment) + src_x;
1085
dstptr += (y * line_increment) + (x * 3);
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;
1094
srcptr += src_increment;
1095
dstptr += line_increment;
1101
*----------------------------------------------------------------------
1103
* RasterConvertIndexto8 --
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
1115
*----------------------------------------------------------------------
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)
1131
srcptr += (src_y * src_increment) + src_x;
1133
dstptr = (uint8 *)tof;
1134
dstptr += (y * line_increment) + x;
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));
1143
srcptr += src_increment;
1144
dstptr += line_increment;
1150
*----------------------------------------------------------------------
1152
* RasterConvertIndextoShort --
1154
* Convert pixels from pseudo color values to depth 15 or 16, while
1155
* copying from source to destination.
1163
*----------------------------------------------------------------------
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)
1179
srcptr += (src_y * src_increment) + src_x;
1181
line_increment >>= 1;
1182
dstptr = (uint16 *)tof;
1183
dstptr += (y * line_increment) + x;
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));
1192
srcptr += src_increment;
1193
dstptr += line_increment;
1199
*----------------------------------------------------------------------
1201
* RasterConvertIndexto24 --
1203
* Convert pixels from pseudo color values to depth 24, while copying
1204
* from source to destination.
1212
*----------------------------------------------------------------------
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)
1226
srcptr += (src_y * src_increment) + src_x;
1229
dstptr += (y * line_increment) + (x * 3);
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;
1238
srcptr += src_increment;
1239
dstptr += line_increment;
1245
*----------------------------------------------------------------------
1247
* RasterConvertIndexto32 --
1249
* Convert pixels from pseudo color values to depth 32, while copying
1250
* from source to destination.
1258
*----------------------------------------------------------------------
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)
1272
srcptr += (src_y * src_increment) + src_x;
1274
line_increment >>= 2;
1275
dstptr = (uint32 *)tof;
1276
dstptr += (y * line_increment) + x;
1278
for (i=0; i<h; i++) {
1279
for (j=0; j<w; j++) {
1280
uint32 pix = pixels[srcptr[j]];
1283
srcptr += src_increment;
1284
dstptr += line_increment;
1290
*----------------------------------------------------------------------
1292
* RasterConvert32to8 --
1294
* Convert pixels from depth 32 to depth 8, while copying
1295
* from source to destination.
1296
* BGR233: redShift: 21 greenShift: 10 blueShift: 0
1304
*----------------------------------------------------------------------
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)
1319
src_increment >>= 2;
1320
srcptr = (uint32 *)src;
1321
srcptr += (src_y * src_increment) + src_x;
1323
dstptr = (uint8 *)tof;
1324
dstptr += (y * line_increment) + x;
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));
1333
srcptr += src_increment;
1334
dstptr += line_increment;
1340
*----------------------------------------------------------------------
1342
* RasterConvert24to8 --
1344
* Convert pixels from depth 24 to depth 8, while copying
1345
* from source to destination.
1346
* BGR233: redShift: 5 greenShift: 2 blueShift: 0
1354
*----------------------------------------------------------------------
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)
1370
srcptr += (src_y * src_increment) + (src_x * 3);
1372
dstptr = (uint8 *)tof;
1373
dstptr += (y * line_increment) + x;
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);
1384
srcptr += src_increment;
1385
dstptr += line_increment;
1391
*----------------------------------------------------------------------
1393
* RasterConvert16to8 --
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
1408
*----------------------------------------------------------------------
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)
1423
src_increment >>= 1;
1424
srcptr = (uint16 *)src;
1425
srcptr += (src_y * src_increment) + src_x;
1427
dstptr = (uint8 *)tof;
1428
dstptr += (y * line_increment) + x;
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));
1437
srcptr += src_increment;
1438
dstptr += line_increment;
1444
*----------------------------------------------------------------------
1446
* RasterGetShiftFromMask --
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
1459
*----------------------------------------------------------------------
1463
RasterGetShiftFromMask(uint32 start, uint32 mask)
1472
return (int)start - (int)num;
1477
*----------------------------------------------------------------------
1479
* RasterShiftPixel --
1481
* Shift the pixel. If the shift is negative, shift to left,
1482
* other, shift to right.
1490
*----------------------------------------------------------------------
1494
RasterShiftPixel(uint32 pixel, int shift)
1497
return pixel << -shift;
1499
return pixel >> shift;