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.26 2004/05/10 17:07:17 weiden Exp $ */
23 DIB_24BPP_PutPixel(SURFOBJ
*SurfObj
, LONG x
, LONG y
, ULONG c
)
25 PBYTE addr
= SurfObj
->pvScan0
+ (y
* SurfObj
->lDelta
) + (x
<< 1) + x
;
26 *(PUSHORT
)(addr
) = c
& 0xFFFF;
27 *(addr
+ 2) = (c
>> 16) & 0xFF;
31 DIB_24BPP_GetPixel(SURFOBJ
*SurfObj
, LONG x
, LONG y
)
33 PBYTE addr
= SurfObj
->pvScan0
+ y
* SurfObj
->lDelta
+ (x
<< 1) + x
;
34 return *(PUSHORT
)(addr
) + (*(addr
+ 2) << 16);
38 DIB_24BPP_HLine(SURFOBJ
*SurfObj
, LONG x1
, LONG x2
, LONG y
, ULONG c
)
40 PBYTE addr
= SurfObj
->pvScan0
+ y
* SurfObj
->lDelta
+ (x1
<< 1) + x1
;
45 *(PUSHORT
)(addr
) = c
& 0xFFFF;
54 DIB_24BPP_VLine(SURFOBJ
*SurfObj
, LONG x
, LONG y1
, LONG y2
, ULONG c
)
56 PBYTE addr
= SurfObj
->pvScan0
+ y1
* SurfObj
->lDelta
+ (x
<< 1) + x
;
57 LONG lDelta
= SurfObj
->lDelta
;
61 *(PUSHORT
)(addr
) = c
& 0xFFFF;
62 *(addr
+ 2) = c
>> 16;
69 DIB_24BPP_BitBltSrcCopy( SURFOBJ
*DestSurf
, SURFOBJ
*SourceSurf
,
70 SURFGDI
*DestGDI
, SURFGDI
*SourceGDI
,
71 PRECTL DestRect
, POINTL
*SourcePoint
,
72 XLATEOBJ
*ColorTranslation
)
74 LONG i
, j
, sx
, sy
, xColor
, f1
;
75 PBYTE SourceBits
, DestBits
, SourceLine
, DestLine
;
76 PBYTE SourceBits_4BPP
, SourceLine_4BPP
;
77 PWORD SourceBits_16BPP
, SourceLine_16BPP
;
79 DestBits
= DestSurf
->pvScan0
+ (DestRect
->top
* DestSurf
->lDelta
) + DestRect
->left
* 3;
81 switch(SourceGDI
->BitsPerPixel
)
87 for (j
=DestRect
->top
; j
<DestRect
->bottom
; j
++)
90 for (i
=DestRect
->left
; i
<DestRect
->right
; i
++)
92 if(DIB_1BPP_GetPixel(SourceSurf
, sx
, sy
) == 0)
94 DIB_24BPP_PutPixel(DestSurf
, i
, j
, XLATEOBJ_iXlate(ColorTranslation
, 0));
96 DIB_24BPP_PutPixel(DestSurf
, i
, j
, XLATEOBJ_iXlate(ColorTranslation
, 1));
105 SourceBits_4BPP
= SourceSurf
->pvScan0
+ (SourcePoint
->y
* SourceSurf
->lDelta
) + (SourcePoint
->x
>> 1);
107 for (j
=DestRect
->top
; j
<DestRect
->bottom
; j
++)
109 SourceLine_4BPP
= SourceBits_4BPP
;
114 for (i
=DestRect
->left
; i
<DestRect
->right
; i
++)
116 xColor
= XLATEOBJ_iXlate(ColorTranslation
,
117 (*SourceLine_4BPP
& altnotmask
[f1
]) >> (4 * (1 - f1
)));
118 *DestLine
++ = xColor
& 0xff;
119 *(PWORD
)DestLine
= xColor
>> 8;
121 if(f1
== 1) { SourceLine_4BPP
++; f1
= 0; } else { f1
= 1; }
125 SourceBits_4BPP
+= SourceSurf
->lDelta
;
126 DestBits
+= DestSurf
->lDelta
;
131 SourceLine
= SourceSurf
->pvScan0
+ (SourcePoint
->y
* SourceSurf
->lDelta
) + SourcePoint
->x
;
134 for (j
= DestRect
->top
; j
< DestRect
->bottom
; j
++)
136 SourceBits
= SourceLine
;
139 for (i
= DestRect
->left
; i
< DestRect
->right
; i
++)
141 xColor
= XLATEOBJ_iXlate(ColorTranslation
, *SourceBits
);
142 *DestBits
= xColor
& 0xff;
143 *(PWORD
)(DestBits
+ 1) = xColor
>> 8;
148 SourceLine
+= SourceSurf
->lDelta
;
149 DestLine
+= DestSurf
->lDelta
;
154 SourceBits_16BPP
= SourceSurf
->pvScan0
+ (SourcePoint
->y
* SourceSurf
->lDelta
) + 2 * SourcePoint
->x
;
156 for (j
=DestRect
->top
; j
<DestRect
->bottom
; j
++)
158 SourceLine_16BPP
= SourceBits_16BPP
;
161 for (i
=DestRect
->left
; i
<DestRect
->right
; i
++)
163 xColor
= XLATEOBJ_iXlate(ColorTranslation
, *SourceLine_16BPP
);
164 *DestLine
++ = xColor
& 0xff;
165 *(PWORD
)DestLine
= xColor
>> 8;
170 SourceBits_16BPP
= (PWORD
)((PBYTE
)SourceBits_16BPP
+ SourceSurf
->lDelta
);
171 DestBits
+= DestSurf
->lDelta
;
176 if (NULL
== ColorTranslation
|| 0 != (ColorTranslation
->flXlate
& XO_TRIVIAL
))
178 if (DestRect
->top
< SourcePoint
->y
)
180 SourceBits
= SourceSurf
->pvScan0
+ (SourcePoint
->y
* SourceSurf
->lDelta
) + 3 * SourcePoint
->x
;
181 for (j
= DestRect
->top
; j
< DestRect
->bottom
; j
++)
183 RtlMoveMemory(DestBits
, SourceBits
, 3 * (DestRect
->right
- DestRect
->left
));
184 SourceBits
+= SourceSurf
->lDelta
;
185 DestBits
+= DestSurf
->lDelta
;
190 SourceBits
= SourceSurf
->pvScan0
+ ((SourcePoint
->y
+ DestRect
->bottom
- DestRect
->top
- 1) * SourceSurf
->lDelta
) + 3 * SourcePoint
->x
;
191 DestBits
= DestSurf
->pvScan0
+ ((DestRect
->bottom
- 1) * DestSurf
->lDelta
) + 3 * DestRect
->left
;
192 for (j
= DestRect
->bottom
- 1; DestRect
->top
<= j
; j
--)
194 RtlMoveMemory(DestBits
, SourceBits
, 3 * (DestRect
->right
- DestRect
->left
));
195 SourceBits
-= SourceSurf
->lDelta
;
196 DestBits
-= DestSurf
->lDelta
;
203 DPRINT1("DIB_24BPP_Bitblt: Unhandled ColorTranslation for 16 -> 16 copy");
209 SourceLine
= SourceSurf
->pvScan0
+ (SourcePoint
->y
* SourceSurf
->lDelta
) + 4 * SourcePoint
->x
;
212 for (j
= DestRect
->top
; j
< DestRect
->bottom
; j
++)
214 SourceBits
= SourceLine
;
217 for (i
= DestRect
->left
; i
< DestRect
->right
; i
++)
219 xColor
= XLATEOBJ_iXlate(ColorTranslation
, *((PDWORD
) SourceBits
));
220 *DestBits
= xColor
& 0xff;
221 *(PWORD
)(DestBits
+ 1) = xColor
>> 8;
226 SourceLine
+= SourceSurf
->lDelta
;
227 DestLine
+= DestSurf
->lDelta
;
232 DbgPrint("DIB_24BPP_Bitblt: Unhandled Source BPP: %u\n", SourceGDI
->BitsPerPixel
);
240 DIB_24BPP_BitBlt(SURFOBJ
*DestSurf
, SURFOBJ
*SourceSurf
,
241 SURFGDI
*DestGDI
, SURFGDI
*SourceGDI
,
242 PRECTL DestRect
, POINTL
*SourcePoint
,
243 BRUSHOBJ
*Brush
, POINTL BrushOrigin
,
244 XLATEOBJ
*ColorTranslation
, ULONG Rop4
)
247 ULONG SourceX
, SourceY
;
248 ULONG Dest
, Source
, Pattern
= 0, PatternY
;
252 /* Pattern brushes */
253 PGDIBRUSHOBJ GdiBrush
;
254 HBITMAP PatternSurface
= NULL
;
256 ULONG PatternWidth
, PatternHeight
;
260 return DIB_24BPP_BitBltSrcCopy(
270 UsesSource
= ((Rop4
& 0xCC0000) >> 2) != (Rop4
& 0x330000);
271 UsesPattern
= (((Rop4
& 0xF00000) >> 4) != (Rop4
& 0x0F0000)) && Brush
;
275 if (Brush
->iSolidColor
== 0xFFFFFFFF)
277 PBITMAPOBJ PatternBitmap
;
279 GdiBrush
= CONTAINING_RECORD(
284 PatternBitmap
= BITMAPOBJ_LockBitmap(GdiBrush
->hbmPattern
);
285 PatternSurface
= BitmapToSurf(PatternBitmap
, NULL
);
286 BITMAPOBJ_UnlockBitmap(GdiBrush
->hbmPattern
);
288 PatternObj
= (SURFOBJ
*)AccessUserObject((ULONG
)PatternSurface
);
289 PatternWidth
= PatternObj
->sizlBitmap
.cx
;
290 PatternHeight
= PatternObj
->sizlBitmap
.cy
;
297 Pattern
= Brush
->iSolidColor
;
301 SourceY
= SourcePoint
->y
;
304 (DestRect
->left
<< 1) + DestRect
->left
+
305 DestRect
->top
* DestSurf
->lDelta
);
307 for (Y
= DestRect
->top
; Y
< DestRect
->bottom
; Y
++)
309 SourceX
= SourcePoint
->x
;
312 PatternY
= (Y
+ BrushOrigin
.y
) % PatternHeight
;
314 for (X
= DestRect
->left
; X
< DestRect
->right
; X
++, DestBits
+= 3, SourceX
++)
316 Dest
= *((PUSHORT
)DestBits
) + (*(DestBits
+ 2) << 16);
320 Source
= DIB_GetSource(SourceSurf
, SourceGDI
, SourceX
, SourceY
, ColorTranslation
);
325 Pattern
= DIB_1BPP_GetPixel(PatternObj
, (X
+ BrushOrigin
.x
) % PatternWidth
, PatternY
) ? GdiBrush
->crFore
: GdiBrush
->crBack
;
328 Dest
= DIB_DoRop(Rop4
, Dest
, Source
, Pattern
) & 0xFFFFFF;
329 *(PUSHORT
)(DestBits
) = Dest
& 0xFFFF;
330 *(DestBits
+ 2) = Dest
>> 16;
334 DestBits
-= (DestRect
->right
- DestRect
->left
) * 3;
335 DestBits
+= DestSurf
->lDelta
;
338 if (PatternSurface
!= NULL
)
339 EngDeleteSurface((HSURF
)PatternSurface
);
344 BOOLEAN
DIB_24BPP_StretchBlt(SURFOBJ
*DestSurf
, SURFOBJ
*SourceSurf
,
345 SURFGDI
*DestGDI
, SURFGDI
*SourceGDI
,
346 RECTL
* DestRect
, RECTL
*SourceRect
,
347 POINTL
* MaskOrigin
, POINTL BrushOrigin
,
348 XLATEOBJ
*ColorTranslation
, ULONG Mode
)
350 DbgPrint("DIB_24BPP_StretchBlt: Source BPP: %u\n", SourceGDI
->BitsPerPixel
);
355 DIB_24BPP_TransparentBlt(SURFOBJ
*DestSurf
, SURFOBJ
*SourceSurf
,
356 PSURFGDI DestGDI
, PSURFGDI SourceGDI
,
357 RECTL
* DestRect
, POINTL
*SourcePoint
,
358 XLATEOBJ
*ColorTranslation
, ULONG iTransColor
)
360 ULONG X
, Y
, SourceX
, SourceY
, Source
, wd
, Dest
;
363 SourceY
= SourcePoint
->y
;
364 DestBits
= (BYTE
*)(DestSurf
->pvScan0
+
365 (DestRect
->left
<< 2) +
366 DestRect
->top
* DestSurf
->lDelta
);
367 wd
= DestSurf
->lDelta
- ((DestRect
->right
- DestRect
->left
) << 2);
369 for(Y
= DestRect
->top
; Y
< DestRect
->bottom
; Y
++)
371 SourceX
= SourcePoint
->x
;
372 for(X
= DestRect
->left
; X
< DestRect
->right
; X
++, DestBits
+= 3, SourceX
++)
374 Source
= DIB_GetSourceIndex(SourceSurf
, SourceGDI
, SourceX
, SourceY
);
375 if(Source
!= iTransColor
)
377 Dest
= XLATEOBJ_iXlate(ColorTranslation
, Source
) & 0xFFFFFF;
378 *(PUSHORT
)(DestBits
) = Dest
& 0xFFFF;
379 *(DestBits
+ 2) = Dest
>> 16;
384 DestBits
= (BYTE
*)((ULONG_PTR
)DestBits
+ wd
);