1
/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/vmware/bits2pixels.c,v 1.2 2002/12/11 17:07:58 dawes Exp $ */
2
/* **********************************************************
3
* Copyright (C) 1999-2001 VMware, Inc.
5
* **********************************************************/
7
char rcsId_bits2pixels[] = "Id: bits2pixels.c,v 1.6 2001/01/26 23:32:15 yoel Exp $";
9
#define FILECODE "F(814)"
15
* Emulation routines to convert bitmaps to pixmaps
18
#include "vm_basic_types.h"
19
#include "bits2pixels.h"
26
static void RasterBitsToPixels8(uint8 *bits, uint32 bits_increment,
27
uint8 *pix, uint32 pix_increment,
28
uint32 width, uint32 height, uint32 fg, uint32 bg);
30
static void RasterBitsToPixels16(uint8 *bits, uint32 bits_increment,
31
uint8 *pix, uint32 pix_increment,
32
uint32 width, uint32 height, uint32 fg, uint32 bg);
34
static void RasterBitsToPixels24(uint8 *bits, uint32 bits_increment,
35
uint8 *pix, uint32 pix_increment,
36
uint32 width, uint32 height, uint32 fg, uint32 bg);
38
static void RasterBitsToPixels32(uint8 *bits, uint32 bits_increment,
39
uint8 *pix, uint32 pix_increment,
40
uint32 width, uint32 height, uint32 fg, uint32 bg);
44
*----------------------------------------------------------------------
46
* vmwareRaster_BitsToPixels --
48
* Convert a bitmap to a pixmap, converting 1 bits to the foreground
49
* color (fg) and 0 bits to the background color (bg).
52
* Pixmap filled with pixels
57
*----------------------------------------------------------------------
61
vmwareRaster_BitsToPixels(uint8 *bits, uint32 bits_increment,
62
uint8 *pix, uint32 pix_increment, int bytes_per_pixel,
63
uint32 width, uint32 height, uint32 fg, uint32 bg)
65
switch (bytes_per_pixel) {
67
RasterBitsToPixels8(bits, bits_increment, pix, pix_increment,
68
width, height, fg, bg);
72
RasterBitsToPixels16(bits, bits_increment, pix, pix_increment,
73
width, height, fg, bg);
77
RasterBitsToPixels24(bits, bits_increment, pix, pix_increment,
78
width, height, fg, bg);
82
RasterBitsToPixels32(bits, bits_increment, pix, pix_increment,
83
width, height, fg, bg);
90
*----------------------------------------------------------------------
92
* RasterBitsToPixels8 --
94
* Convert a bitmap to a pixmap, converting 1 bits to the foreground
95
* color (fg) and 0 bits to the background color (bg), for an 8-bit
99
* Pixmap filled with pixels
104
*----------------------------------------------------------------------
108
RasterBitsToPixels8(uint8 *bits, uint32 bits_increment,
109
uint8 *pix, uint32 pix_increment,
110
uint32 width, uint32 height, uint32 fg, uint32 bg)
114
uint32 expbits = 0; /* Bits to be expanded */
116
for (i=0; i<height; i++) {
119
for (j = width ; j > 0; j -= 4) {
120
expbits = (*lbits >> 4) & 0x0f;
224
expbits = *lbits & 0x0f;
333
*lpix++ = (expbits & 0x08) ? fg : bg;
336
*lpix++ = (expbits & 0x04) ? fg : bg;
339
*lpix++ = (expbits & 0x02) ? fg : bg;
345
pix += pix_increment;
346
bits += bits_increment;
353
*----------------------------------------------------------------------
355
* RasterBitsToPixels16 --
357
* Convert a bitmap to a pixmap, converting 1 bits to the foreground
358
* color (fg) and 0 bits to the background color (bg), for a 16-bit
362
* Pixmap filled with pixels
367
*----------------------------------------------------------------------
371
RasterBitsToPixels16(uint8 *bits, uint32 bits_increment,
372
uint8 *pix, uint32 pix_increment,
373
uint32 width, uint32 height, uint32 fg, uint32 bg)
378
uint32 expbits = 0; /* Bits to be expanded */
380
for (i=0; i<height; i++) {
381
lpix = (uint16 *)pix;
383
for (j = width; j > 0; j -= 4) {
384
expbits = (*lbits >> 4) & 0x0f;
488
expbits = *lbits & 0x0f;
597
*lpix++ = (expbits & 0x08) ? fg : bg;
600
*lpix++ = (expbits & 0x04) ? fg : bg;
603
*lpix++ = (expbits & 0x02) ? fg : bg;
609
pix += pix_increment;
610
bits += bits_increment;
618
*----------------------------------------------------------------------
620
* RasterBitsToPixels24 --
622
* Convert a bitmap to a pixmap, converting 1 bits to the foreground
623
* color (fg) and 0 bits to the background color (bg), for a 24-bit
627
* Pixmap filled with pixels
632
*----------------------------------------------------------------------
636
RasterBitsToPixels24(uint8 *bits, uint32 bits_increment,
637
uint8 *pix, uint32 pix_increment,
638
uint32 width, uint32 height, uint32 fg, uint32 bg)
641
uint32 fgColor1, fgColor2, fgColor3;
642
uint32 bgColor1, bgColor2, bgColor3;
645
uint32 expbits = 0; /* Bits to be expanded */
647
fgColor1 = fg & 0x000000ff;
648
fgColor2 = (fg >> 8) & 0x000000ff;
649
fgColor3 = (fg >> 16) & 0x000000ff;
651
bgColor1 = bg & 0x000000ff;
652
bgColor2 = (bg >> 8) & 0x000000ff;
653
bgColor3 = (bg >> 16) & 0x000000ff;
655
for (i=0; i<height; i++) {
658
for (j = width; j > 0; j -= 4) {
659
expbits = (*lbits >> 4) & 0x0f;
891
expbits = *lbits & 0x0f;
1128
*lpix++ = (expbits & 0x08) ? fgColor1 : bgColor1;
1129
*lpix++ = (expbits & 0x08) ? fgColor2 : bgColor2;
1130
*lpix++ = (expbits & 0x08) ? fgColor3 : bgColor3;
1133
*lpix++ = (expbits & 0x04) ? fgColor1 : bgColor1;
1134
*lpix++ = (expbits & 0x04) ? fgColor2 : bgColor2;
1135
*lpix++ = (expbits & 0x04) ? fgColor3 : bgColor3;
1138
*lpix++ = (expbits & 0x02) ? fgColor1 : bgColor1;
1139
*lpix++ = (expbits & 0x02) ? fgColor2 : bgColor2;
1140
*lpix++ = (expbits & 0x02) ? fgColor3 : bgColor3;
1146
pix += pix_increment;
1147
bits += bits_increment;
1155
*----------------------------------------------------------------------
1157
* RasterBitsToPixels32 --
1159
* Convert a bitmap to a pixmap, converting 1 bits to the foreground
1160
* color (fg) and 0 bits to the background color (bg), for a 32-bit
1164
* Pixmap filled with pixels
1169
*----------------------------------------------------------------------
1173
RasterBitsToPixels32(uint8 *bits, uint32 bits_increment,
1174
uint8 *pix, uint32 pix_increment,
1175
uint32 width, uint32 height, uint32 fg, uint32 bg)
1180
uint32 expbits = 0; /* Bits to be expanded */
1182
for (i=0; i<height; i++) {
1183
lpix = (uint32 *)pix;
1185
for (j = width; j > 0; j -= 4) {
1186
expbits = (*lbits >> 4) & 0x0f;
1290
expbits = *lbits & 0x0f;
1399
*lpix++ = (expbits & 0x08) ? fg : bg;
1402
*lpix++ = (expbits & 0x04) ? fg : bg;
1405
*lpix++ = (expbits & 0x02) ? fg : bg;
1411
pix += pix_increment;
1412
bits += bits_increment;