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
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,
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,
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,
112
uint32 redShift, uint32 greenShift,
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,
124
uint32 redShift, uint32 greenShift,
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,
137
uint32 redShift, uint32 greenShift,
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);
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);
180
*----------------------------------------------------------------------
182
* Raster_IsModeReasonable --
184
* Determine if a mode is something that Raster_Convert*
188
* TRUE if we like the mode.
193
*----------------------------------------------------------------------
197
Raster_IsModeReasonable(uint32 depth, uint32 bpp, Bool pseudocolor)
199
return (pseudocolor && bpp == 8) || (!pseudocolor &&
200
((bpp == 16 && (depth == 15 ||
202
(bpp == 24 && depth == 24) ||
203
(bpp == 32 && depth == 24)));
208
*----------------------------------------------------------------------
210
* Raster_GetBPPDepth --
212
* Converts separate depth and bpp values into one "bppdepth."
213
* See comment above Raster_ConvertPixels().
221
*----------------------------------------------------------------------
225
Raster_GetBPPDepth(uint32 depth, uint32 bpp)
227
if (depth == 24 && bpp == 32) {
236
*----------------------------------------------------------------------
238
* Raster_ConvertPixels --
240
* Convert pixels from one depth to another, while copying from
241
* source to destination.
243
* bppdepth is a unique number specifying the bpp/color-depth,
247
* -----------------------
254
* 32 24 32 * This is the only one that differs from depth
260
* If converting from a lower true-color depth to 32-bpp, fills the
261
* alpha values of the destination rectangle to 0xFF.
263
*----------------------------------------------------------------------
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)
273
int redShift, greenShift, blueShift;
276
if (src_bppdepth > 8) {
277
Warning("Raster convert pixels invalid depth for pseudo color %d\n",
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);
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);
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,
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,
313
RasterConvertIndexto24(tof, line_increment, src, src_increment,
314
pixels, src_x, src_y, x, y, w, h);
318
RasterConvertIndexto32(tof, line_increment, src, src_increment,
319
pixels, src_x, src_y, x, y, w, h);
323
Warning("Raster convert pixels invalid depth %d\n", bppdepth);
330
switch (src_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));
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);
347
Warning("Raster convert called when no conversion needed\n");
352
RasterConvert15to16(tof, line_increment, src, src_increment,
353
src_x, src_y, x, y, w, h);
357
RasterConvertShortTo24(tof, line_increment, src, src_increment,
358
src_x, src_y, x, y, w, h,
359
REDMASK_15, GREENMASK_15, BLUEMASK_15,
364
RasterConvertShortTo32(tof, line_increment, src, src_increment,
365
src_x, src_y, x, y, w, h,
366
REDMASK_15, GREENMASK_15, BLUEMASK_15,
371
Warning("Raster convert pixels invalid depth %d\n", 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));
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);
393
RasterConvert16to15(tof, line_increment, src, src_increment,
394
src_x, src_y, x, y, w, h);
398
Warning("Raster convert called when no conversion needed\n");
403
RasterConvertShortTo24(tof, line_increment, src, src_increment,
404
src_x, src_y, x, y, w, h,
405
REDMASK_16, GREENMASK_16, BLUEMASK_16,
410
RasterConvertShortTo32(tof, line_increment, src, src_increment,
411
src_x, src_y, x, y, w, h,
412
REDMASK_16, GREENMASK_16, BLUEMASK_16,
417
Warning("Raster convert pixels invalid depth %d\n", 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);
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);
440
RasterConvert24toShort(tof, line_increment, src, src_increment,
441
src_x, src_y, x, y, w, h,
442
REDMASK_15, GREENMASK_15, BLUEMASK_15,
447
RasterConvert24toShort(tof, line_increment, src, src_increment,
448
src_x, src_y, x, y, w, h,
449
REDMASK_16, GREENMASK_16, BLUEMASK_16,
454
Warning("Raster convert called when no conversion needed\n");
459
RasterConvert24to32(tof, line_increment, src, src_increment,
460
src_x, src_y, x, y, w, h);
464
Warning("Raster convert pixels invalid depth %d\n", 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);
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);
487
RasterConvert32toShort(tof, line_increment, src, src_increment,
488
src_x, src_y, x, y, w, h,
489
REDMASK_15, GREENMASK_15, BLUEMASK_15,
494
RasterConvert32toShort(tof, line_increment, src, src_increment,
495
src_x, src_y, x, y, w, h,
496
REDMASK_16, GREENMASK_16, BLUEMASK_16,
501
RasterConvert32to24(tof, line_increment, src, src_increment,
502
src_x, src_y, x, y, w, h);
506
Warning("Raster convert called when no conversion needed\n");
511
Warning("Raster convert pixels invalid depth %d\n", bppdepth);
518
Warning("Raster convert pixels invalid source depth %d\n", src_bppdepth);
519
NOT_IMPLEMENTED_BUG(10982);
526
*----------------------------------------------------------------------
528
* Raster_ConvertOnePixel --
530
* Convert the given pixel from its current depth to the specified
534
* The converted pixel
539
*----------------------------------------------------------------------
543
Raster_ConvertOnePixel(uint32 pix, int src_bppdepth, int bppdepth,
544
Bool pseudoColor, const uint32 *pixels)
547
if (src_bppdepth != 8) {
548
Warning("Raster convert pixels invalid depth for pseudo color %d\n",
557
switch (src_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);
569
return ((pix & (REDMASK_15 | GREENMASK_15)) << 1) |
570
((pix & GREEN_HIBIT_15) >> GREEN_HILOSHIFT_15) |
575
return CONVERT_SHORT_TO_LONG(pix, REDMASK_15, GREENMASK_15,
576
BLUEMASK_15, 7, 12, 2, 7, 3, 2);
579
Warning("Raster convert one pixel invalid depth %d\n", 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);
592
return ((pix >> 1) & (REDMASK_15 | GREENMASK_15)) |
600
return CONVERT_SHORT_TO_LONG(pix, REDMASK_16, GREENMASK_16,
601
BLUEMASK_16, 8, 13, 3, 9, 3, 2);
604
Warning("Raster convert one pixel invalid depth %d\n", 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);
618
return CONVERT_LONG_TO_SHORT(pix, REDMASK_15, GREENMASK_15,
619
BLUEMASK_15, 9, 6, 3);
622
return CONVERT_LONG_TO_SHORT(pix, REDMASK_16, GREENMASK_16,
623
BLUEMASK_16, 8, 5, 3);
630
Warning("Raster convert one pixel invalid depth %d\n", bppdepth);
636
Warning("Raster convert one pixel invalid source depth %d\n",
647
*----------------------------------------------------------------------
649
* Raster_ConversionParameters --
651
* Get component masks that the conversion routines use for the
655
* Returns FALSE if depth not supported
660
*----------------------------------------------------------------------
664
Raster_ConversionParameters(int bppdepth, // IN
665
uint32 *redMask, // OUT
666
uint32 *greenMask, // OUT
667
uint32 *blueMask) // OUT
671
*redMask = REDMASK_15;
672
*greenMask = GREENMASK_15;
673
*blueMask = BLUEMASK_15;
677
*redMask = REDMASK_16;
678
*greenMask = GREENMASK_16;
679
*blueMask = BLUEMASK_16;
683
*redMask = REDMASK_24;
684
*greenMask = GREENMASK_24;
685
*blueMask = BLUEMASK_24;
689
*redMask = REDMASK_32;
690
*greenMask = GREENMASK_32;
691
*blueMask = BLUEMASK_32;
703
*----------------------------------------------------------------------
705
* RasterConvert15to16 --
707
* Convert pixels from depth 15 to depth 16, while copying from
708
* source to destination.
716
*----------------------------------------------------------------------
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)
725
const uint16 *srcptr;
730
srcptr = (uint16 *)src;
731
srcptr += (src_y * src_increment) + src_x;
733
line_increment >>= 1;
734
dstptr = (uint16 *)tof;
735
dstptr += (y * line_increment) + x;
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) |
744
srcptr += src_increment;
745
dstptr += line_increment;
751
*----------------------------------------------------------------------
753
* RasterConvertShortTo24 --
755
* Convert pixels from depth 15 or 16 to depth 24, while copying
756
* from source to destination.
764
*----------------------------------------------------------------------
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)
777
const uint16 *srcptr;
782
srcptr = (uint16 *)src;
783
srcptr += (src_y * src_increment) + src_x;
786
dstptr += (y * line_increment) + (x * 3);
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);
798
srcptr += src_increment;
799
dstptr += line_increment;
805
*----------------------------------------------------------------------
807
* RasterConvertShortTo32 --
809
* Convert pixels from depth 15 or 16 to depth 32, while copying
810
* from source to destination.
816
* Fills the alpha values of the destination rectangle to 0xFF.
818
*----------------------------------------------------------------------
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)
831
const uint16 *srcptr;
836
srcptr = (uint16 *)src;
837
srcptr += (src_y * src_increment) + src_x;
839
line_increment >>= 2;
840
dstptr = (uint32 *)tof;
841
dstptr += (y * line_increment) + x;
843
for (i=0; i<h; i++) {
844
for (j=0; j<w; j++) {
845
uint32 pix = srcptr[j];
846
dstptr[j] = (0xFF << 24) |
848
((((pix & redMask) >> redShift1) |
849
((pix & redMask) >> redShift2)) << 16)) |
851
((((pix & greenMask) >> greenShift1) |
852
((pix & greenMask) >> greenShift2)) << 8)) |
854
(((pix & blueMask) << blueShift1) |
855
((pix & blueMask) >> blueShift2)));
857
srcptr += src_increment;
858
dstptr += line_increment;
864
*----------------------------------------------------------------------
866
* RasterConvert16to15 --
868
* Convert pixels from depth 16 to depth 15, while copying from
869
* source to destination.
877
*----------------------------------------------------------------------
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)
886
const uint16 *srcptr;
891
srcptr = (uint16 *)src;
892
srcptr += (src_y * src_increment) + src_x;
894
line_increment >>= 1;
895
dstptr = (uint16 *)tof;
896
dstptr += (y * line_increment) + x;
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)) |
904
srcptr += src_increment;
905
dstptr += line_increment;
911
*----------------------------------------------------------------------
913
* RasterConvert24toShort --
915
* Convert pixels from depth 24 to depth 15 or 16, while copying
916
* from source to destination.
924
*----------------------------------------------------------------------
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)
940
srcptr += (src_y * src_increment) + (src_x * 3);
942
line_increment >>= 1;
943
dstptr = (uint16 *)tof;
944
dstptr += (y * line_increment) + x;
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);
955
srcptr += src_increment;
956
dstptr += line_increment;
962
*----------------------------------------------------------------------
964
* RasterConvert24to32 --
966
* Convert pixels from depth 24 to depth 32, while copying
967
* from source to destination.
973
* Fills the alpha values of the destination rectangle to 0xFF.
975
*----------------------------------------------------------------------
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)
989
srcptr += (src_y * src_increment) + (src_x * 3);
991
line_increment >>= 2;
992
dstptr = (uint32 *)tof;
993
dstptr += (y * line_increment) + x;
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);
1005
srcptr += src_increment;
1006
dstptr += line_increment;
1012
*----------------------------------------------------------------------
1014
* RasterConvert32toShort --
1016
* Convert pixels from depth 32 to depth 15 or 16, while copying
1017
* from source to destination.
1025
*----------------------------------------------------------------------
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)
1036
const uint32 *srcptr;
1040
src_increment >>= 2;
1041
srcptr = (uint32 *)src;
1042
srcptr += (src_y * src_increment) + src_x;
1044
line_increment >>= 1;
1045
dstptr = (uint16 *)tof;
1046
dstptr += (y * line_increment) + x;
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));
1055
srcptr += src_increment;
1056
dstptr += line_increment;
1062
*----------------------------------------------------------------------
1064
* RasterConvert32to24 --
1066
* Convert pixels from depth 32 to depth 24, while copying
1067
* from source to destination.
1075
*----------------------------------------------------------------------
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)
1084
const uint32 *srcptr;
1088
src_increment >>= 2;
1089
srcptr = (uint32 *)src;
1090
srcptr += (src_y * src_increment) + src_x;
1093
dstptr += (y * line_increment) + (x * 3);
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;
1102
srcptr += src_increment;
1103
dstptr += line_increment;
1109
*----------------------------------------------------------------------
1111
* RasterConvertIndexto8 --
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
1123
*----------------------------------------------------------------------
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)
1134
const uint8 *srcptr;
1139
srcptr += (src_y * src_increment) + src_x;
1141
dstptr = (uint8 *)tof;
1142
dstptr += (y * line_increment) + x;
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));
1151
srcptr += src_increment;
1152
dstptr += line_increment;
1158
*----------------------------------------------------------------------
1160
* RasterConvertIndextoShort --
1162
* Convert pixels from pseudo color values to depth 15 or 16, while
1163
* copying from source to destination.
1171
*----------------------------------------------------------------------
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)
1182
const uint8 *srcptr;
1187
srcptr += (src_y * src_increment) + src_x;
1189
line_increment >>= 1;
1190
dstptr = (uint16 *)tof;
1191
dstptr += (y * line_increment) + x;
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));
1200
srcptr += src_increment;
1201
dstptr += line_increment;
1207
*----------------------------------------------------------------------
1209
* RasterConvertIndexto24 --
1211
* Convert pixels from pseudo color values to depth 24, while copying
1212
* from source to destination.
1220
*----------------------------------------------------------------------
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)
1229
const uint8 *srcptr;
1234
srcptr += (src_y * src_increment) + src_x;
1237
dstptr += (y * line_increment) + (x * 3);
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;
1246
srcptr += src_increment;
1247
dstptr += line_increment;
1253
*----------------------------------------------------------------------
1255
* RasterConvertIndexto32 --
1257
* Convert pixels from pseudo color values to depth 32, while copying
1258
* from source to destination.
1266
*----------------------------------------------------------------------
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)
1275
const uint8 *srcptr;
1280
srcptr += (src_y * src_increment) + src_x;
1282
line_increment >>= 2;
1283
dstptr = (uint32 *)tof;
1284
dstptr += (y * line_increment) + x;
1286
for (i=0; i<h; i++) {
1287
for (j=0; j<w; j++) {
1288
uint32 pix = pixels[srcptr[j]];
1291
srcptr += src_increment;
1292
dstptr += line_increment;
1298
*----------------------------------------------------------------------
1300
* RasterConvert32to8 --
1302
* Convert pixels from depth 32 to depth 8, while copying
1303
* from source to destination.
1304
* BGR233: redShift: 21 greenShift: 10 blueShift: 0
1312
*----------------------------------------------------------------------
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)
1323
const uint32 *srcptr;
1327
src_increment >>= 2;
1328
srcptr = (uint32 *)src;
1329
srcptr += (src_y * src_increment) + src_x;
1331
dstptr = (uint8 *)tof;
1332
dstptr += (y * line_increment) + x;
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));
1341
srcptr += src_increment;
1342
dstptr += line_increment;
1348
*----------------------------------------------------------------------
1350
* RasterConvert24to8 --
1352
* Convert pixels from depth 24 to depth 8, while copying
1353
* from source to destination.
1354
* BGR233: redShift: 5 greenShift: 2 blueShift: 0
1362
*----------------------------------------------------------------------
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)
1373
const uint8 *srcptr;
1378
srcptr += (src_y * src_increment) + (src_x * 3);
1380
dstptr = (uint8 *)tof;
1381
dstptr += (y * line_increment) + x;
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);
1392
srcptr += src_increment;
1393
dstptr += line_increment;
1399
*----------------------------------------------------------------------
1401
* RasterConvert16to8 --
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
1416
*----------------------------------------------------------------------
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)
1427
const uint16 *srcptr;
1431
src_increment >>= 1;
1432
srcptr = (uint16 *)src;
1433
srcptr += (src_y * src_increment) + src_x;
1435
dstptr = (uint8 *)tof;
1436
dstptr += (y * line_increment) + x;
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));
1445
srcptr += src_increment;
1446
dstptr += line_increment;
1452
*----------------------------------------------------------------------
1454
* RasterGetShiftFromMask --
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
1467
*----------------------------------------------------------------------
1471
RasterGetShiftFromMask(uint32 start, uint32 mask)
1480
return (int)start - (int)num;
1485
*----------------------------------------------------------------------
1487
* RasterShiftPixel --
1489
* Shift the pixel. If the shift is negative, shift to left,
1490
* other, shift to right.
1498
*----------------------------------------------------------------------
1502
RasterShiftPixel(uint32 pixel, int shift)
1505
return pixel << -shift;
1507
return pixel >> shift;