2 * ReactOS W32 Subsystem
3 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 /* $Id: dib24bpp.c,v 1.20 2004/04/06 21:53:48 weiden Exp $ */
20 #undef WIN32_LEAN_AND_MEAN
23 #include <win32k/bitmaps.h>
24 #include <win32k/brush.h>
25 #include <win32k/debug.h>
27 #include <include/object.h>
28 #include <ddk/winddi.h>
29 #include "../eng/objects.h"
33 DIB_24BPP_PutPixel(PSURFOBJ SurfObj
, LONG x
, LONG y
, ULONG c
)
35 PBYTE addr
= SurfObj
->pvScan0
+ (y
* SurfObj
->lDelta
) + (x
<< 1) + x
;
36 *(PUSHORT
)(addr
) = c
& 0xFFFF;
37 *(addr
+ 2) = (c
>> 16) & 0xFF;
41 DIB_24BPP_GetPixel(PSURFOBJ SurfObj
, LONG x
, LONG y
)
43 PBYTE addr
= SurfObj
->pvScan0
+ y
* SurfObj
->lDelta
+ (x
<< 1) + x
;
44 return *(PUSHORT
)(addr
) + (*(addr
+ 2) << 16);
48 DIB_24BPP_HLine(PSURFOBJ SurfObj
, LONG x1
, LONG x2
, LONG y
, ULONG c
)
50 PBYTE addr
= SurfObj
->pvScan0
+ y
* SurfObj
->lDelta
+ (x1
<< 1) + x1
;
55 *(PUSHORT
)(addr
) = c
& 0xFFFF;
64 DIB_24BPP_VLine(PSURFOBJ SurfObj
, LONG x
, LONG y1
, LONG y2
, ULONG c
)
66 PBYTE addr
= SurfObj
->pvScan0
+ y1
* SurfObj
->lDelta
+ (x
<< 1) + x
;
67 LONG lDelta
= SurfObj
->lDelta
;
71 *(PUSHORT
)(addr
) = c
& 0xFFFF;
72 *(addr
+ 2) = c
>> 16;
79 DIB_24BPP_BitBltSrcCopy( SURFOBJ
*DestSurf
, SURFOBJ
*SourceSurf
,
80 SURFGDI
*DestGDI
, SURFGDI
*SourceGDI
,
81 PRECTL DestRect
, POINTL
*SourcePoint
,
82 XLATEOBJ
*ColorTranslation
)
84 LONG i
, j
, sx
, sy
, xColor
, f1
;
85 PBYTE SourceBits
, DestBits
, SourceLine
, DestLine
;
86 PBYTE SourceBits_4BPP
, SourceLine_4BPP
;
87 PWORD SourceBits_16BPP
, SourceLine_16BPP
;
89 DestBits
= DestSurf
->pvScan0
+ (DestRect
->top
* DestSurf
->lDelta
) + DestRect
->left
* 3;
91 switch(SourceGDI
->BitsPerPixel
)
97 for (j
=DestRect
->top
; j
<DestRect
->bottom
; j
++)
100 for (i
=DestRect
->left
; i
<DestRect
->right
; i
++)
102 if(DIB_1BPP_GetPixel(SourceSurf
, sx
, sy
) == 0)
104 DIB_24BPP_PutPixel(DestSurf
, i
, j
, XLATEOBJ_iXlate(ColorTranslation
, 0));
106 DIB_24BPP_PutPixel(DestSurf
, i
, j
, XLATEOBJ_iXlate(ColorTranslation
, 1));
115 SourceBits_4BPP
= SourceSurf
->pvScan0
+ (SourcePoint
->y
* SourceSurf
->lDelta
) + (SourcePoint
->x
>> 1);
117 for (j
=DestRect
->top
; j
<DestRect
->bottom
; j
++)
119 SourceLine_4BPP
= SourceBits_4BPP
;
124 for (i
=DestRect
->left
; i
<DestRect
->right
; i
++)
126 xColor
= XLATEOBJ_iXlate(ColorTranslation
,
127 (*SourceLine_4BPP
& altnotmask
[f1
]) >> (4 * (1 - f1
)));
128 *DestLine
++ = xColor
& 0xff;
129 *(PWORD
)DestLine
= xColor
>> 8;
131 if(f1
== 1) { SourceLine_4BPP
++; f1
= 0; } else { f1
= 1; }
135 SourceBits_4BPP
+= SourceSurf
->lDelta
;
136 DestBits
+= DestSurf
->lDelta
;
141 SourceLine
= SourceSurf
->pvScan0
+ (SourcePoint
->y
* SourceSurf
->lDelta
) + SourcePoint
->x
;
144 for (j
= DestRect
->top
; j
< DestRect
->bottom
; j
++)
146 SourceBits
= SourceLine
;
149 for (i
= DestRect
->left
; i
< DestRect
->right
; i
++)
151 xColor
= XLATEOBJ_iXlate(ColorTranslation
, *SourceBits
);
152 *DestBits
= xColor
& 0xff;
153 *(PWORD
)(DestBits
+ 1) = xColor
>> 8;
158 SourceLine
+= SourceSurf
->lDelta
;
159 DestLine
+= DestSurf
->lDelta
;
164 SourceBits_16BPP
= SourceSurf
->pvScan0
+ (SourcePoint
->y
* SourceSurf
->lDelta
) + 2 * SourcePoint
->x
;
166 for (j
=DestRect
->top
; j
<DestRect
->bottom
; j
++)
168 SourceLine_16BPP
= SourceBits_16BPP
;
171 for (i
=DestRect
->left
; i
<DestRect
->right
; i
++)
173 xColor
= XLATEOBJ_iXlate(ColorTranslation
, *SourceLine_16BPP
);
174 *DestLine
++ = xColor
& 0xff;
175 *(PWORD
)DestLine
= xColor
>> 8;
180 SourceBits_16BPP
= (PWORD
)((PBYTE
)SourceBits_16BPP
+ SourceSurf
->lDelta
);
181 DestBits
+= DestSurf
->lDelta
;
186 if (NULL
== ColorTranslation
|| 0 != (ColorTranslation
->flXlate
& XO_TRIVIAL
))
188 if (DestRect
->top
< SourcePoint
->y
)
190 SourceBits
= SourceSurf
->pvScan0
+ (SourcePoint
->y
* SourceSurf
->lDelta
) + 3 * SourcePoint
->x
;
191 for (j
= DestRect
->top
; j
< DestRect
->bottom
; j
++)
193 RtlMoveMemory(DestBits
, SourceBits
, 3 * (DestRect
->right
- DestRect
->left
));
194 SourceBits
+= SourceSurf
->lDelta
;
195 DestBits
+= DestSurf
->lDelta
;
200 SourceBits
= SourceSurf
->pvScan0
+ ((SourcePoint
->y
+ DestRect
->bottom
- DestRect
->top
- 1) * SourceSurf
->lDelta
) + 3 * SourcePoint
->x
;
201 DestBits
= DestSurf
->pvScan0
+ ((DestRect
->bottom
- 1) * DestSurf
->lDelta
) + 3 * DestRect
->left
;
202 for (j
= DestRect
->bottom
- 1; DestRect
->top
<= j
; j
--)
204 RtlMoveMemory(DestBits
, SourceBits
, 3 * (DestRect
->right
- DestRect
->left
));
205 SourceBits
-= SourceSurf
->lDelta
;
206 DestBits
-= DestSurf
->lDelta
;
213 DPRINT1("DIB_24BPP_Bitblt: Unhandled ColorTranslation for 16 -> 16 copy");
219 SourceLine
= SourceSurf
->pvScan0
+ (SourcePoint
->y
* SourceSurf
->lDelta
) + 4 * SourcePoint
->x
;
222 for (j
= DestRect
->top
; j
< DestRect
->bottom
; j
++)
224 SourceBits
= SourceLine
;
227 for (i
= DestRect
->left
; i
< DestRect
->right
; i
++)
229 xColor
= XLATEOBJ_iXlate(ColorTranslation
, *((PDWORD
) SourceBits
));
230 *DestBits
= xColor
& 0xff;
231 *(PWORD
)(DestBits
+ 1) = xColor
>> 8;
236 SourceLine
+= SourceSurf
->lDelta
;
237 DestLine
+= DestSurf
->lDelta
;
242 DbgPrint("DIB_24BPP_Bitblt: Unhandled Source BPP: %u\n", SourceGDI
->BitsPerPixel
);
250 DIB_24BPP_BitBlt(SURFOBJ
*DestSurf
, SURFOBJ
*SourceSurf
,
251 SURFGDI
*DestGDI
, SURFGDI
*SourceGDI
,
252 PRECTL DestRect
, POINTL
*SourcePoint
,
253 PBRUSHOBJ Brush
, PPOINTL BrushOrigin
,
254 XLATEOBJ
*ColorTranslation
, ULONG Rop4
)
257 ULONG SourceX
, SourceY
;
258 ULONG Dest
, Source
, Pattern
;
262 /* Pattern brushes */
263 PGDIBRUSHOBJ GdiBrush
;
264 HBITMAP PatternSurface
= NULL
;
266 ULONG PatternWidth
, PatternHeight
;
270 return DIB_24BPP_BitBltSrcCopy(
280 UsesSource
= ((Rop4
& 0xCC0000) >> 2) != (Rop4
& 0x330000);
281 UsesPattern
= ((Rop4
& 0xF00000) >> 4) != (Rop4
& 0x0F0000);
289 if (Brush
->iSolidColor
== 0xFFFFFFFF)
291 PBITMAPOBJ PatternBitmap
;
293 GdiBrush
= CONTAINING_RECORD(
298 PatternBitmap
= BITMAPOBJ_LockBitmap(GdiBrush
->hbmPattern
);
299 PatternSurface
= BitmapToSurf(PatternBitmap
, NULL
);
300 BITMAPOBJ_UnlockBitmap(GdiBrush
->hbmPattern
);
302 PatternObj
= (PSURFOBJ
)AccessUserObject((ULONG
)PatternSurface
);
303 PatternWidth
= PatternObj
->sizlBitmap
.cx
;
304 PatternHeight
= PatternObj
->sizlBitmap
.cy
;
308 SourceY
= SourcePoint
->y
;
311 (DestRect
->left
<< 1) + DestRect
->left
+
312 DestRect
->top
* DestSurf
->lDelta
);
314 for (Y
= DestRect
->top
; Y
< DestRect
->bottom
; Y
++)
316 SourceX
= SourcePoint
->x
;
317 for (X
= DestRect
->left
; X
< DestRect
->right
; X
++, DestBits
+= 3, SourceX
++)
319 Dest
= *((PUSHORT
)DestBits
) + (*(DestBits
+ 2) << 16);
323 Source
= DIB_GetSource(SourceSurf
, SourceGDI
, SourceX
, SourceY
, ColorTranslation
);
328 if (Brush
->iSolidColor
== 0xFFFFFFFF)
330 Pattern
= DIB_1BPP_GetPixel(PatternObj
, X
% PatternWidth
, Y
% PatternHeight
) ? GdiBrush
->crFore
: GdiBrush
->crBack
;
334 Pattern
= Brush
->iSolidColor
;
338 Dest
= DIB_DoRop(Rop4
, Dest
, Source
, Pattern
) & 0xFFFFFF;
339 *(PUSHORT
)(DestBits
) = Dest
& 0xFFFF;
340 *(DestBits
+ 2) = Dest
>> 16;
344 DestBits
-= (DestRect
->right
- DestRect
->left
) * 3;
345 DestBits
+= DestSurf
->lDelta
;
348 if (PatternSurface
!= NULL
)
349 EngDeleteSurface(PatternSurface
);
354 BOOLEAN
DIB_24BPP_StretchBlt(SURFOBJ
*DestSurf
, SURFOBJ
*SourceSurf
,
355 SURFGDI
*DestGDI
, SURFGDI
*SourceGDI
,
356 RECTL
* DestRect
, RECTL
*SourceRect
,
357 POINTL
* MaskOrigin
, POINTL
* BrushOrigin
,
358 XLATEOBJ
*ColorTranslation
, ULONG Mode
)
360 DbgPrint("DIB_24BPP_StretchBlt: Source BPP: %u\n", SourceGDI
->BitsPerPixel
);
365 DIB_24BPP_TransparentBlt(SURFOBJ
*DestSurf
, SURFOBJ
*SourceSurf
,
366 PSURFGDI DestGDI
, PSURFGDI SourceGDI
,
367 RECTL
* DestRect
, POINTL
*SourcePoint
,
368 XLATEOBJ
*ColorTranslation
, ULONG iTransColor
)
370 ULONG X
, Y
, SourceX
, SourceY
, Source
, wd
, Dest
;
373 SourceY
= SourcePoint
->y
;
374 DestBits
= (BYTE
*)(DestSurf
->pvScan0
+
375 (DestRect
->left
<< 2) +
376 DestRect
->top
* DestSurf
->lDelta
);
377 wd
= ((DestRect
->right
- DestRect
->left
) << 2) - DestSurf
->lDelta
;
379 for(Y
= DestRect
->top
; Y
< DestRect
->bottom
; Y
++)
381 SourceX
= SourcePoint
->x
;
382 for(X
= DestRect
->left
; X
< DestRect
->right
; X
++, DestBits
+= 3, SourceX
++)
384 Source
= DIB_GetSourceIndex(SourceSurf
, SourceGDI
, SourceX
, SourceY
);
385 if(Source
!= iTransColor
)
387 Dest
= XLATEOBJ_iXlate(ColorTranslation
, Source
) & 0xFFFFFF;
388 *(PUSHORT
)(DestBits
) = Dest
& 0xFFFF;
389 *(DestBits
+ 2) = Dest
>> 16;
394 DestBits
= (BYTE
*)((ULONG_PTR
)DestBits
- wd
);