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->pvBits;
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 (ColorTranslation == NULL)
28 DIB_BltToVGA(DestRect->left, DestRect->top, dx, dy, Source->pvBits,
33 /* Perform color translation */
34 for (j = SourcePoint->y; j < SourcePoint->y+dy; j++)
38 for (i=SourcePoint->x; i<SourcePoint->x+dx; i++)
40 idxColor = XLATEOBJ_iXlate(ColorTranslation, *GDIpos);
41 vgaPutPixel(i+alterx, j+altery, idxColor);
44 GDIpos = initial + Source->lDelta;
50 VGAtoDIB(SURFOBJ *Dest, SURFOBJ *Source, XLATEOBJ *ColorTranslation,
51 RECTL *DestRect, POINTL *SourcePoint)
53 LONG i, j, dx, dy, RGBulong;
54 BYTE *GDIpos, *initial, idxColor;
56 // Used by the temporary DFB
59 PSURFOBJ TargetBitmapSurf;
60 HBITMAP hTargetBitmap;
64 // FIXME: Optimize to retrieve entire bytes at a time (see /display/vgavideo/vgavideo.c:vgaGetByte)
66 GDIpos = Dest->pvBits /* + (DestRect->top * Dest->lDelta) + (DestRect->left >> 1) */ ;
67 dx = DestRect->right - DestRect->left;
68 dy = DestRect->bottom - DestRect->top;
70 if(ColorTranslation == NULL)
72 // Prepare a Dest Dev Target and copy from the DFB to the DIB
73 DestDevSurf.NextScan = Dest->lDelta;
74 DestDevSurf.StartBmp = Dest->pvScan0;
76 DIB_BltFromVGA(SourcePoint->x, SourcePoint->y, dx, dy, Dest->pvBits, Dest->lDelta);
80 for(j=SourcePoint->y; j<SourcePoint->y+dy; j++)
83 for(i=SourcePoint->x; i<SourcePoint->x+dx; i++)
85 *GDIpos = XLATEOBJ_iXlate(ColorTranslation, vgaGetPixel(i, j));
88 GDIpos = initial + Dest->lDelta;
94 DFBtoVGA(SURFOBJ *Dest, SURFOBJ *Source, XLATEOBJ *ColorTranslation,
95 RECTL *DestRect, POINTL *SourcePoint)
97 // Do DFBs need color translation??
101 VGAtoDFB(SURFOBJ *Dest, SURFOBJ *Source, XLATEOBJ *ColorTranslation,
102 RECTL *DestRect, POINTL *SourcePoint)
104 // Do DFBs need color translation??
108 VGAtoVGA(SURFOBJ *Dest, SURFOBJ *Source, XLATEOBJ *ColorTranslation,
109 RECTL *DestRect, POINTL *SourcePoint)
111 // FIXME: Use fast blts instead of get and putpixels
113 int i, j, dx, dy, alterx, altery, BltDirection;
117 dx = DestRect->right - DestRect->left;
118 dy = DestRect->bottom - DestRect->top;
120 alterx = abs(SourcePoint->x - DestRect->left);
121 altery = abs(SourcePoint->y - DestRect->top);
123 // Determine bltting direction
124 // FIXME: should we perhaps make this an EngXxx function? Determining
125 // direction is probably used whenever the surfaces are the same (not
127 if (SourcePoint->y >= DestRect->top)
129 if (SourcePoint->x >= DestRect->left)
131 BltDirection = CD_RIGHTDOWN;
135 BltDirection = CD_LEFTDOWN;
140 if (SourcePoint->x >= DestRect->left)
142 BltDirection = CD_RIGHTUP;
146 BltDirection = CD_LEFTUP;
150 // Do the VGA to VGA BitBlt
151 // FIXME: Right now we're only doing CN_LEFTDOWN and we're using slow
152 // get and put pixel routines
154 for(j=SourcePoint->y; j<SourcePoint->y+dy; j++)
156 for(i=SourcePoint->x; i<SourcePoint->x+dx; i++)
158 vgaPutPixel(i+alterx, j+altery, vgaGetPixel(i, j));
166 VGADDI_BltBrush(SURFOBJ* Dest, XLATEOBJ* ColorTranslation, RECTL* DestRect,
167 BRUSHOBJ* Brush, POINTL* BrushPoint, ROP4 Rop4)
177 /* Punt brush blts to non-device surfaces. */
178 if (Dest->iType != STYPE_DEVICE)
183 /* Punt pattern fills. */
184 if (Rop4 == PATCOPY && Brush->iSolidColor == 0xFFFFFFFF)
190 SolidColor = Brush->iSolidColor;
192 else if (Rop4 == WHITENESS)
201 /* Fill any pixels on the left which don't fall into a full row of eight. */
202 if ((DestRect->left % 8) != 0)
204 /* Disable writes to pixels outside of the destination rectangle. */
205 Mask = (1 << (8 - (DestRect->left % 8))) - 1;
206 if ((DestRect->right - DestRect->left) < (8 - (DestRect->left % 8)))
208 Mask &= ~((1 << (8 - (DestRect->right % 8))) - 1);
210 WRITE_PORT_UCHAR((PUCHAR)GRA_I, 0x8);
211 WRITE_PORT_UCHAR((PUCHAR)GRA_D, Mask);
213 /* Write the same color to each pixel. */
214 Video = (PUCHAR)vidmem + DestRect->top * 80 + (DestRect->left >> 3);
215 for (i = DestRect->top; i < DestRect->bottom; i++, Video+=80)
217 (VOID)READ_REGISTER_UCHAR(Video);
218 WRITE_REGISTER_UCHAR(Video, SolidColor);
222 /* Enable writes to all pixels. */
223 WRITE_PORT_UCHAR((PUCHAR)GRA_I, 0x8);
224 WRITE_PORT_UCHAR((PUCHAR)GRA_D, 0xFF);
226 /* Have we finished. */
227 if ((DestRect->right - DestRect->left) < (8 - (DestRect->left % 8)))
232 /* Fill any whole rows of eight pixels. */
233 Left = (DestRect->left + 7) & ~0x7;
234 Length = (DestRect->right >> 3) - (Left >> 3);
235 for (i = DestRect->top; i < DestRect->bottom; i++)
237 Video = (PUCHAR)vidmem + i * 80 + (Left >> 3);
238 for (j = 0; j < Length; j++, Video++)
240 WRITE_REGISTER_UCHAR(Video, SolidColor);
244 /* Fill any pixels on the right which don't fall into a complete row. */
245 if ((DestRect->right % 8) != 0)
247 /* Disable writes to pixels outside the destination rectangle. */
248 Mask = ~((1 << (8 - (DestRect->right % 8))) - 1);
249 WRITE_PORT_UCHAR((PUCHAR)GRA_I, 0x8);
250 WRITE_PORT_UCHAR((PUCHAR)GRA_D, Mask);
252 Video = (PUCHAR)vidmem + DestRect->top * 80 + (DestRect->right >> 3);
253 for (i = DestRect->top; i < DestRect->bottom; i++, Video+=80)
255 /* Read the existing colours for this pixel into the latches. */
256 (VOID)READ_REGISTER_UCHAR(Video);
257 /* Write the new colour for the pixels selected in the mask. */
258 WRITE_REGISTER_UCHAR(Video, SolidColor);
261 /* Restore the default write masks. */
262 WRITE_PORT_UCHAR((PUCHAR)GRA_I, 0x8);
263 WRITE_PORT_UCHAR((PUCHAR)GRA_D, 0xFF);
269 VGADDI_BltSrc(SURFOBJ *Dest, SURFOBJ *Source, XLATEOBJ *ColorTranslation,
270 RECTL *DestRect, POINTL *SourcePoint)
274 PFN_VGABlt BltOperation;
277 SourceType = Source->iType;
279 if (SourceType == STYPE_BITMAP && Dest->iType == STYPE_DEVICE)
281 BltOperation = DIBtoVGA;
283 else if (SourceType == STYPE_DEVICE && Dest->iType == STYPE_BITMAP)
285 BltOperation = VGAtoDIB;
287 else if (SourceType == STYPE_DEVICE && Dest->iType == STYPE_DEVICE)
289 BltOperation = VGAtoVGA;
291 else if (SourceType == STYPE_DEVBITMAP && Dest->iType == STYPE_DEVICE)
293 BltOperation = DFBtoVGA;
295 else if (SourceType == STYPE_DEVICE && Dest->iType == STYPE_DEVBITMAP)
297 BltOperation = VGAtoDFB;
301 /* Punt blts not involving a device or a device-bitmap. */
305 BltOperation(Dest, Source, ColorTranslation, DestRect, SourcePoint);
310 VGADDI_BltMask(SURFOBJ *Dest, SURFOBJ *Mask, XLATEOBJ *ColorTranslation,
311 RECTL *DestRect, POINTL *MaskPoint, BRUSHOBJ* Brush,
314 LONG i, j, dx, dy, idxColor, RGBulong = 0, c8;
315 BYTE *initial, *tMask, *lMask;
317 dx = DestRect->right - DestRect->left;
318 dy = DestRect->bottom - DestRect->top;
320 if (ColorTranslation == NULL)
324 tMask = Mask->pvBits;
331 if((*lMask & maskbit[c8]) != 0)
333 vgaPutPixel(DestRect->left + i, DestRect->top + j, Brush->iSolidColor);
336 if(c8 == 8) { lMask++; c8=0; }
338 tMask += Mask->lDelta;
345 DrvBitBlt(SURFOBJ *Dest,
349 XLATEOBJ *ColorTranslation,
357 /* Punt bitblts with complex clipping to the GDI. */
368 return(VGADDI_BltBrush(Dest, ColorTranslation, DestRect, Brush,
372 return(VGADDI_BltSrc(Dest, Source, ColorTranslation, DestRect,
376 return(VGADDI_BltMask(Dest, Mask, ColorTranslation, DestRect,
377 MaskPoint, Brush, BrushPoint));