2 * DIB Engine pixel Primitives
4 * Copyright 2009 Massimo Del Fedele
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/port.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(dibdrv
);
29 /* ------------------------------------------------------------*/
30 /* BITFIELD HELPERS */
31 static DWORD
GetField32 (DWORD pixel
, int shift
, int len
)
33 pixel
= pixel
& (((1 << (len
)) - 1) << shift
);
34 pixel
= pixel
<< (32 - (shift
+ len
)) >> 24;
38 static WORD
GetField16 (WORD pixel
, int shift
, int len
)
46 /* ------------------------------------------------------------*/
47 /* PIXEL POINTER READING */
48 void *_DIBDRV_GetPixelPointer32(const DIBDRVBITMAP
*dib
, int x
, int y
)
50 BYTE
*ptr
= dib
->bits
;
52 ptr
+= (y
* dib
->stride
);
58 void *_DIBDRV_GetPixelPointer24(const DIBDRVBITMAP
*dib
, int x
, int y
)
60 BYTE
*ptr
= dib
->bits
;
62 ptr
+= (y
* dib
->stride
);
68 void *_DIBDRV_GetPixelPointer16(const DIBDRVBITMAP
*dib
, int x
, int y
)
70 BYTE
*ptr
= dib
->bits
;
72 ptr
+= (y
* dib
->stride
);
78 void *_DIBDRV_GetPixelPointer8(const DIBDRVBITMAP
*dib
, int x
, int y
)
80 BYTE
*ptr
= dib
->bits
;
82 ptr
+= (y
* dib
->stride
);
88 void *_DIBDRV_GetPixelPointer4(const DIBDRVBITMAP
*dib
, int x
, int y
)
90 BYTE
*ptr
= dib
->bits
;
92 ptr
+= (y
* dib
->stride
);
98 void *_DIBDRV_GetPixelPointer1(const DIBDRVBITMAP
*dib
, int x
, int y
)
100 BYTE
*ptr
= dib
->bits
;
102 ptr
+= (y
* dib
->stride
);
108 /* ------------------------------------------------------------*/
110 void _DIBDRV_SetPixel32(DIBDRVBITMAP
*dib
, int x
, int y
, DWORD
and, DWORD
xor)
112 DWORD
*ptr
= dib
->funcs
->GetPixelPointer(dib
, x
, y
);
113 _DIBDRV_rop32(ptr
, and, xor);
116 void _DIBDRV_SetPixel24(DIBDRVBITMAP
*dib
, int x
, int y
, DWORD
and, DWORD
xor)
118 BYTE
*ptr
= dib
->funcs
->GetPixelPointer(dib
, x
, y
);
119 _DIBDRV_rop8(ptr
, and & 0xff, xor & 0xff);
120 _DIBDRV_rop8(ptr
+ 1, (and >> 8) & 0xff, (xor >> 8) & 0xff);
121 _DIBDRV_rop8(ptr
+ 2, (and >> 16) & 0xff, (xor >> 16) & 0xff);
124 void _DIBDRV_SetPixel16(DIBDRVBITMAP
*dib
, int x
, int y
, DWORD
and, DWORD
xor)
126 WORD
*ptr
= dib
->funcs
->GetPixelPointer(dib
, x
, y
);
127 _DIBDRV_rop16(ptr
, and, xor);
130 void _DIBDRV_SetPixel8(DIBDRVBITMAP
*dib
, int x
, int y
, DWORD
and, DWORD
xor)
132 BYTE
*ptr
= dib
->funcs
->GetPixelPointer(dib
, x
, y
);
133 _DIBDRV_rop8(ptr
, and, xor);
136 void _DIBDRV_SetPixel4(DIBDRVBITMAP
*dib
, int x
, int y
, DWORD
and, DWORD
xor)
138 BYTE
*ptr
= dib
->funcs
->GetPixelPointer(dib
, x
, y
);
139 BYTE byte_and
, byte_xor
;
141 if(x
& 1) /* upper nibble untouched */
143 byte_and
= (and & 0xf) | 0xf0;
144 byte_xor
= (xor & 0xf);
148 byte_and
= ((and << 4) & 0xf0) | 0x0f;
149 byte_xor
= ((xor << 4) & 0xf0);
152 _DIBDRV_rop8(ptr
, byte_and
, byte_xor
);
155 void _DIBDRV_SetPixel1(DIBDRVBITMAP
*dib
, int x
, int y
, DWORD
and, DWORD
xor)
158 BYTE byte_and
= 0, byte_xor
= 0, mask
;
160 if(and & 1) byte_and
= 0xff;
161 if(xor & 1) byte_xor
= 0xff;
163 mask
= 1 << (7 - (x
& 7));
168 ptr
= dib
->funcs
->GetPixelPointer(dib
, x
, y
);
170 _DIBDRV_rop8(ptr
, byte_and
, byte_xor
);
173 /* ------------------------------------------------------------*/
175 DWORD
_DIBDRV_GetPixel32_RGB(const DIBDRVBITMAP
*dib
, int x
, int y
)
177 DWORD
*ptr
= dib
->funcs
->GetPixelPointer(dib
, x
, y
);
181 DWORD
_DIBDRV_GetPixel32_BITFIELDS(const DIBDRVBITMAP
*dib
, int x
, int y
)
183 DWORD
*ptr
= dib
->funcs
->GetPixelPointer(dib
, x
, y
);
185 return GetField32(*ptr
, dib
->redShift
, dib
->redLen
) << 16 |
186 GetField32(*ptr
, dib
->greenShift
, dib
->greenLen
) << 8 |
187 GetField32(*ptr
, dib
->blueShift
, dib
->blueLen
);
190 DWORD
_DIBDRV_GetPixel24(const DIBDRVBITMAP
*dib
, int x
, int y
)
192 BYTE
*ptr
= dib
->funcs
->GetPixelPointer(dib
, x
, y
);
193 return (ptr
[0] << 16) | (ptr
[1] << 8) | ptr
[2];
196 DWORD
_DIBDRV_GetPixel16_RGB(const DIBDRVBITMAP
*dib
, int x
, int y
)
198 WORD
*ptr
= dib
->funcs
->GetPixelPointer(dib
, x
, y
);
199 return ((*ptr
& 0x7c00) << 9) | ((*ptr
& 0x03e0) << 6) | ((*ptr
& 0x001f) << 3);
202 DWORD
_DIBDRV_GetPixel16_BITFIELDS(const DIBDRVBITMAP
*dib
, int x
, int y
)
204 WORD
*ptr
= dib
->funcs
->GetPixelPointer(dib
, x
, y
);
206 return GetField16(*ptr
, dib
->redShift
, dib
->redLen
) << 16 |
207 GetField16(*ptr
, dib
->greenShift
, dib
->greenLen
) << 8 |
208 GetField16(*ptr
, dib
->blueShift
, dib
->blueLen
);
211 DWORD
_DIBDRV_GetPixel8(const DIBDRVBITMAP
*dib
, int x
, int y
)
213 BYTE
*ptr
= dib
->funcs
->GetPixelPointer(dib
, x
, y
);
214 RGBQUAD
*color
= dib
->colorTable
+ *ptr
;
215 return (color
->rgbRed
<< 16) | (color
->rgbGreen
<< 8) | color
->rgbBlue
;
218 DWORD
_DIBDRV_GetPixel4(const DIBDRVBITMAP
*dib
, int x
, int y
)
220 BYTE
*ptr
= dib
->funcs
->GetPixelPointer(dib
, x
, y
), pix
;
228 color
= dib
->colorTable
+ pix
;
229 return (color
->rgbRed
<< 16) | (color
->rgbGreen
<< 8) | color
->rgbBlue
;
232 DWORD
_DIBDRV_GetPixel1(const DIBDRVBITMAP
*dib
, int x
, int y
)
234 BYTE
*ptr
= dib
->funcs
->GetPixelPointer(dib
, x
, y
), pix
;
239 pix
>>= (7 - (x
& 7));
242 color
= dib
->colorTable
+ pix
;
243 return (color
->rgbRed
<< 16) | (color
->rgbGreen
<< 8) | color
->rgbBlue
;