DIB Engine: implement most engine functions
[wine/hacks.git] / dlls / winedib.drv / primitives_pixel.c
blobca68cf16a464188e89f2c0daccf8ef51891a6eba
1 /*
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
21 #include "config.h"
22 #include "wine/port.h"
24 #include "dibdrv.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;
35 return pixel;
38 static WORD GetField16 (WORD pixel, int shift, int len)
40 FIXME("TODO\n");
41 return 0;
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);
54 ptr += x * 4;
55 return ptr;
58 void *_DIBDRV_GetPixelPointer24(const DIBDRVBITMAP *dib, int x, int y)
60 BYTE *ptr = dib->bits;
62 ptr += (y * dib->stride);
64 ptr += x * 3;
65 return ptr;
68 void *_DIBDRV_GetPixelPointer16(const DIBDRVBITMAP *dib, int x, int y)
70 BYTE *ptr = dib->bits;
72 ptr += (y * dib->stride);
74 ptr += x * 2;
75 return ptr;
78 void *_DIBDRV_GetPixelPointer8(const DIBDRVBITMAP *dib, int x, int y)
80 BYTE *ptr = dib->bits;
82 ptr += (y * dib->stride);
84 ptr += x;
85 return ptr;
88 void *_DIBDRV_GetPixelPointer4(const DIBDRVBITMAP *dib, int x, int y)
90 BYTE *ptr = dib->bits;
92 ptr += (y * dib->stride);
94 ptr += x / 2;
95 return ptr;
98 void *_DIBDRV_GetPixelPointer1(const DIBDRVBITMAP *dib, int x, int y)
100 BYTE *ptr = dib->bits;
102 ptr += (y * dib->stride);
104 ptr += x / 8;
105 return ptr;
108 /* ------------------------------------------------------------*/
109 /* PIXEL WRITING */
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);
146 else
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)
157 BYTE *ptr;
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));
165 byte_and |= ~mask;
166 byte_xor &= mask;
168 ptr = dib->funcs->GetPixelPointer(dib, x, y);
170 _DIBDRV_rop8(ptr, byte_and, byte_xor);
173 /* ------------------------------------------------------------*/
174 /* PIXEL READING */
175 DWORD _DIBDRV_GetPixel32_RGB(const DIBDRVBITMAP *dib, int x, int y)
177 DWORD *ptr = dib->funcs->GetPixelPointer(dib, x, y);
178 return *ptr;
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;
221 RGBQUAD *color;
223 if(x & 1)
224 pix = *ptr & 0x0f;
225 else
226 pix = *ptr >> 4;
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;
235 RGBQUAD *color;
237 pix = *ptr;
239 pix >>= (7 - (x & 7));
240 pix &= 1;
242 color = dib->colorTable + pix;
243 return (color->rgbRed << 16) | (color->rgbGreen << 8) | color->rgbBlue;