5 #include "../vgavideo/vgavideo.h"
9 typedef BOOL (*PFN_VGABlt)(SURFOBJ*, SURFOBJ*, XLATEOBJ*, RECTL*, POINTL*);
12 DIBtoVGA(SURFOBJ *Dest, SURFOBJ *Source, XLATEOBJ *ColorTranslation,
13 RECTL *DestRect, POINTL *SourcePoint)
15 LONG i, j, dx, dy, alterx, altery, idxColor, RGBulong = 0, c8;
16 BYTE *GDIpos, *initial, *tMask, *lMask;
18 GDIpos = Source->pvScan0;
20 dx = DestRect->right - DestRect->left;
21 dy = DestRect->bottom - DestRect->top;
23 alterx = abs(SourcePoint->x - DestRect->left);
24 altery = abs(SourcePoint->y - DestRect->top);
26 if (NULL == ColorTranslation)
28 DIB_BltToVGA(DestRect->left, DestRect->top, dx, dy,
29 Source->pvScan0 + SourcePoint->y * Source->lDelta + (SourcePoint->x >> 1),
34 /* Perform color translation */
35 for (j = SourcePoint->y; j < SourcePoint->y+dy; j++)
39 for (i=SourcePoint->x; i<SourcePoint->x+dx; i++)
41 idxColor = XLATEOBJ_iXlate(ColorTranslation, *GDIpos);
42 vgaPutPixel(i+alterx, j+altery, idxColor);
45 GDIpos = initial + Source->lDelta;
51 VGAtoDIB(SURFOBJ *Dest, SURFOBJ *Source, XLATEOBJ *ColorTranslation,
52 RECTL *DestRect, POINTL *SourcePoint)
54 LONG i, j, dx, dy, RGBulong;
55 BYTE *GDIpos, *initial, idxColor;
57 // Used by the temporary DFB
60 PSURFOBJ TargetBitmapSurf;
61 HBITMAP hTargetBitmap;
65 // FIXME: Optimize to retrieve entire bytes at a time (see /display/vgavideo/vgavideo.c:vgaGetByte)
67 GDIpos = Dest->pvBits /* + (DestRect->top * Dest->lDelta) + (DestRect->left >> 1) */ ;
68 dx = DestRect->right - DestRect->left;
69 dy = DestRect->bottom - DestRect->top;
71 if(ColorTranslation == NULL)
73 // Prepare a Dest Dev Target and copy from the DFB to the DIB
74 DestDevSurf.NextScan = Dest->lDelta;
75 DestDevSurf.StartBmp = Dest->pvScan0;
77 DIB_BltFromVGA(SourcePoint->x, SourcePoint->y, dx, dy, Dest->pvBits, Dest->lDelta);
81 for(j=SourcePoint->y; j<SourcePoint->y+dy; j++)
84 for(i=SourcePoint->x; i<SourcePoint->x+dx; i++)
86 *GDIpos = XLATEOBJ_iXlate(ColorTranslation, vgaGetPixel(i, j));
89 GDIpos = initial + Dest->lDelta;
95 DFBtoVGA(SURFOBJ *Dest, SURFOBJ *Source, XLATEOBJ *ColorTranslation,
96 RECTL *DestRect, POINTL *SourcePoint)
98 // Do DFBs need color translation??
102 VGAtoDFB(SURFOBJ *Dest, SURFOBJ *Source, XLATEOBJ *ColorTranslation,
103 RECTL *DestRect, POINTL *SourcePoint)
105 // Do DFBs need color translation??
109 VGAtoVGA(SURFOBJ *Dest, SURFOBJ *Source, XLATEOBJ *ColorTranslation,
110 RECTL *DestRect, POINTL *SourcePoint)
112 // FIXME: Use fast blts instead of get and putpixels
114 int i, j, dx, dy, alterx, altery, BltDirection;
118 dx = DestRect->right - DestRect->left;
119 dy = DestRect->bottom - DestRect->top;
121 alterx = abs(SourcePoint->x - DestRect->left);
122 altery = abs(SourcePoint->y - DestRect->top);
124 // Determine bltting direction
125 // FIXME: should we perhaps make this an EngXxx function? Determining
126 // direction is probably used whenever the surfaces are the same (not
128 if (SourcePoint->y >= DestRect->top)
130 if (SourcePoint->x >= DestRect->left)
132 BltDirection = CD_RIGHTDOWN;
136 BltDirection = CD_LEFTDOWN;
141 if (SourcePoint->x >= DestRect->left)
143 BltDirection = CD_RIGHTUP;
147 BltDirection = CD_LEFTUP;
151 // Do the VGA to VGA BitBlt
152 // FIXME: Right now we're only doing CN_LEFTDOWN and we're using slow
153 // get and put pixel routines
155 for(j=SourcePoint->y; j<SourcePoint->y+dy; j++)
157 for(i=SourcePoint->x; i<SourcePoint->x+dx; i++)
159 vgaPutPixel(i+alterx, j+altery, vgaGetPixel(i, j));
167 VGADDI_BltBrush(SURFOBJ* Dest, XLATEOBJ* ColorTranslation, RECTL* DestRect,
168 BRUSHOBJ* Brush, POINTL* BrushPoint, ROP4 Rop4)
178 /* Punt brush blts to non-device surfaces. */
179 if (Dest->iType != STYPE_DEVICE)
184 /* Punt pattern fills. */
185 if (Rop4 == PATCOPY && Brush->iSolidColor == 0xFFFFFFFF)
191 SolidColor = Brush->iSolidColor;
193 else if (Rop4 == WHITENESS)
202 /* Fill any pixels on the left which don't fall into a full row of eight. */
203 if ((DestRect->left % 8) != 0)
205 /* Disable writes to pixels outside of the destination rectangle. */
206 Mask = (1 << (8 - (DestRect->left % 8))) - 1;
207 if ((DestRect->right - DestRect->left) < (8 - (DestRect->left % 8)))
209 Mask &= ~((1 << (8 - (DestRect->right % 8))) - 1);
211 WRITE_PORT_UCHAR((PUCHAR)GRA_I, 0x08);
212 WRITE_PORT_UCHAR((PUCHAR)GRA_D, Mask);
214 /* Write the same color to each pixel. */
215 Video = (PUCHAR)vidmem + DestRect->top * 80 + (DestRect->left >> 3);
216 for (i = DestRect->top; i < DestRect->bottom; i++, Video+=80)
218 (VOID)READ_REGISTER_UCHAR(Video);
219 WRITE_REGISTER_UCHAR(Video, SolidColor);
223 /* Enable writes to all pixels. */
224 WRITE_PORT_UCHAR((PUCHAR)GRA_I, 0x08);
225 WRITE_PORT_UCHAR((PUCHAR)GRA_D, 0xFF);
227 /* Have we finished. */
228 if ((DestRect->right - DestRect->left) < (8 - (DestRect->left % 8)))
233 /* Fill any whole rows of eight pixels. */
234 Left = (DestRect->left + 7) & ~0x7;
235 Length = (DestRect->right >> 3) - (Left >> 3);
236 for (i = DestRect->top; i < DestRect->bottom; i++)
238 Video = (PUCHAR)vidmem + i * 80 + (Left >> 3);
239 for (j = 0; j < Length; j++, Video++)
241 WRITE_REGISTER_UCHAR(Video, SolidColor);
245 /* Fill any pixels on the right which don't fall into a complete row. */
246 if ((DestRect->right % 8) != 0)
248 /* Disable writes to pixels outside the destination rectangle. */
249 Mask = ~((1 << (8 - (DestRect->right % 8))) - 1);
250 WRITE_PORT_UCHAR((PUCHAR)GRA_I, 0x08);
251 WRITE_PORT_UCHAR((PUCHAR)GRA_D, Mask);
253 Video = (PUCHAR)vidmem + DestRect->top * 80 + (DestRect->right >> 3);
254 for (i = DestRect->top; i < DestRect->bottom; i++, Video+=80)
256 /* Read the existing colours for this pixel into the latches. */
257 (VOID)READ_REGISTER_UCHAR(Video);
258 /* Write the new colour for the pixels selected in the mask. */
259 WRITE_REGISTER_UCHAR(Video, SolidColor);
262 /* Restore the default write masks. */
263 WRITE_PORT_UCHAR((PUCHAR)GRA_I, 0x08);
264 WRITE_PORT_UCHAR((PUCHAR)GRA_D, 0xFF);
270 VGADDI_BltSrc(SURFOBJ *Dest, SURFOBJ *Source, XLATEOBJ *ColorTranslation,
271 RECTL *DestRect, POINTL *SourcePoint)
275 PFN_VGABlt BltOperation;
278 SourceType = Source->iType;
280 if (SourceType == STYPE_BITMAP && Dest->iType == STYPE_DEVICE)
282 BltOperation = DIBtoVGA;
284 else if (SourceType == STYPE_DEVICE && Dest->iType == STYPE_BITMAP)
286 BltOperation = VGAtoDIB;
288 else if (SourceType == STYPE_DEVICE && Dest->iType == STYPE_DEVICE)
290 BltOperation = VGAtoVGA;
292 else if (SourceType == STYPE_DEVBITMAP && Dest->iType == STYPE_DEVICE)
294 BltOperation = DFBtoVGA;
296 else if (SourceType == STYPE_DEVICE && Dest->iType == STYPE_DEVBITMAP)
298 BltOperation = VGAtoDFB;
302 /* Punt blts not involving a device or a device-bitmap. */
306 BltOperation(Dest, Source, ColorTranslation, DestRect, SourcePoint);
311 VGADDI_BltMask(SURFOBJ *Dest, SURFOBJ *Mask, XLATEOBJ *ColorTranslation,
312 RECTL *DestRect, POINTL *MaskPoint, BRUSHOBJ* Brush,
315 LONG i, j, dx, dy, idxColor, RGBulong = 0, c8;
316 BYTE *initial, *tMask, *lMask;
318 dx = DestRect->right - DestRect->left;
319 dy = DestRect->bottom - DestRect->top;
321 if (ColorTranslation == NULL)
325 tMask = Mask->pvBits;
332 if((*lMask & maskbit[c8]) != 0)
334 vgaPutPixel(DestRect->left + i, DestRect->top + j, Brush->iSolidColor);
337 if(c8 == 8) { lMask++; c8=0; }
339 tMask += Mask->lDelta;
346 DrvBitBlt(SURFOBJ *Dest,
350 XLATEOBJ *ColorTranslation,
358 /* Punt bitblts with complex clipping to the GDI. */
369 return(VGADDI_BltBrush(Dest, ColorTranslation, DestRect, Brush,
373 if (BMF_4BPP == Source->iBitmapFormat && BMF_4BPP == Dest->iBitmapFormat)
375 return(VGADDI_BltSrc(Dest, Source, ColorTranslation, DestRect,
384 return(VGADDI_BltMask(Dest, Mask, ColorTranslation, DestRect,
385 MaskPoint, Brush, BrushPoint));