|
|
1.1 ! root 1: //-------------------------------------------------------------------------- ! 2: // ! 3: // Module Name: BRUSH.C ! 4: // ! 5: // Brief Description: This module contains the PSCRIPT driver's brush ! 6: // realization routines. ! 7: // ! 8: // Author: Kent Settle (kentse) ! 9: // Created: 13-Dec-1990 ! 10: // ! 11: // Copyright (c) 1990 - 1992 Microsoft Corporation ! 12: // ! 13: //-------------------------------------------------------------------------- ! 14: ! 15: #include "pscript.h" ! 16: #include "enable.h" ! 17: ! 18: #ifdef INDEX_PAL ! 19: #define RGBMASK 0x00FFFFFF ! 20: #endif ! 21: ! 22: //-------------------------------------------------------------------------- ! 23: // ! 24: // BOOL DrvRealizeBrush(pbo, psoTarget, psoPattern, psoMask, pxlo) ! 25: // BRUSHOBJ *pbo; ! 26: // SURFOBJ *psoTarget; ! 27: // SURFOBJ *psoPattern; ! 28: // SURFOBJ *psoMask; ! 29: // XLATEOBJ *pxlo; ! 30: // ! 31: // Requests the driver to realize a pattern defined by psoPattern for ! 32: // the surface defined by psoTarget. A realized brush contains the ! 33: // information and accelerators the driver needs to fill an area with ! 34: // a pattern. This information is defined by the driver and used only ! 35: // by the driver. The driver's realization of the brush should be ! 36: // written into the buffer allocated by calling BRUSHOBJ_pvAllocRBrush. ! 37: // ! 38: // This function is required for a driver that does any drawing to any ! 39: // surface. ! 40: // ! 41: // Parameters: ! 42: // pbo: ! 43: // Points to the BRUSHOBJ which is being realized. All the other ! 44: // parameters, except for psoTarget, can actually be queried from ! 45: // this object. We provide them as an optimization. pbo is best used ! 46: // only as a parameter for BRUSHOBJ_pvAllocRBrush, which allocates ! 47: // the memory for the realized brush. ! 48: // ! 49: // psoTarget: ! 50: // The object for the surface the brush is to be realized for. This ! 51: // surface will either be the physical surface for the device, or a ! 52: // device format bitmap. ! 53: // ! 54: // psoPattern: ! 55: // The surface describing the pattern for the brush. For a raster ! 56: // device this will always represent a bitmap. For a vector device ! 57: // this will always be one of the pattern surfaces returned by ! 58: // DrvEnablePDEV. ! 59: // ! 60: // psoMask: ! 61: // If this argument is not NULL, it provides a transparency mask for ! 62: // the brush. This is a one bit per pel bitmap having the same ! 63: // extent as the pattern. A mask bit of zero means that the pel is ! 64: // considered a background pel for the brush (In transparent ! 65: // background mode, the background pels would be left unaffected in a ! 66: // fill.) ! 67: // ! 68: // Plotters can ignore this argument as they are never expected to draw ! 69: // background information. ! 70: // ! 71: // pxlo: ! 72: // An XLATEOBJ which tells how to interpret the colors in the pattern. ! 73: // An XLATEOBJ service routine can be called to translate the colors to ! 74: // device color indices. Vector devices should translate color 0 ! 75: // through the XLATEOBJ to get the foreground color for the brush. ! 76: // ! 77: // Returns: ! 78: // TRUE if the brush was successfully realized. Otherwise, FALSE ! 79: // and an error code is logged. ! 80: // ! 81: // History: ! 82: // 13-Dec-1990 -by- Kent Settle (kentse) ! 83: // Wrote it. ! 84: // ! 85: // 16-Feb-1993 Tue 12:28:06 updated -by- Daniel Chou (danielc) ! 86: // Re-write so it takc iHatch rather go through the suface handle to ! 87: // check what type of pattern. ! 88: //-------------------------------------------------------------------------- ! 89: ! 90: BOOL DrvRealizeBrush(pbo, psoTarget, psoPattern, psoMask, pxlo, iHatch) ! 91: BRUSHOBJ *pbo; ! 92: SURFOBJ *psoTarget; ! 93: SURFOBJ *psoPattern; ! 94: SURFOBJ *psoMask; ! 95: XLATEOBJ *pxlo; ! 96: ULONG iHatch; ! 97: { ! 98: ULONG cbTotal, cbBits, cbColorTable; ! 99: PBYTE pbSrc, pbTarg; ! 100: DEVBRUSH *pBrush; ! 101: PDEVDATA pdev; ! 102: #ifdef INDEX_PAL ! 103: BOOL bDitherColor; ! 104: #endif ! 105: ! 106: UNREFERENCED_PARAMETER(psoMask); ! 107: ! 108: // get the pointer to our DEVDATA structure and make sure it is ours. ! 109: ! 110: pdev = (PDEVDATA) psoTarget->dhpdev; ! 111: ! 112: if (bValidatePDEV(pdev) == FALSE) ! 113: { ! 114: RIP("PSCRIPT!DrvRealizeBrush: invalid pdev.\n"); ! 115: SetLastError(ERROR_INVALID_PARAMETER); ! 116: return(FALSE); ! 117: } ! 118: ! 119: #ifdef INDEX_PAL ! 120: // see if this is just a solid color to realize. ! 121: ! 122: bDitherColor = FALSE; ! 123: ! 124: if (iHatch & RB_DITHERCOLOR) ! 125: { ! 126: bDitherColor = TRUE; ! 127: cbBits = 0; ! 128: } ! 129: else if (iHatch >= HS_DDI_MAX) ! 130: #else ! 131: if (iHatch >= HS_DDI_MAX) ! 132: #endif ! 133: { ! 134: // we have a bitmap for the pattern. ! 135: // determine the size of the bitmap, remembering that the ! 136: // bitmaps are DWORD (32 bit) bounded. ! 137: ! 138: // how many pels per scanline? ! 139: ! 140: cbBits = psoPattern->sizlBitmap.cx; ! 141: ! 142: // times how many bits per pel. ! 143: ! 144: switch (psoPattern->iBitmapFormat) ! 145: { ! 146: case BMF_1BPP: ! 147: break; ! 148: ! 149: case BMF_4BPP: ! 150: cbBits *= 4; ! 151: break; ! 152: ! 153: case BMF_8BPP: ! 154: cbBits *= 8; ! 155: break; ! 156: ! 157: case BMF_16BPP: ! 158: cbBits *= 16; ! 159: break; ! 160: ! 161: case BMF_24BPP: ! 162: cbBits *= 24; ! 163: break; ! 164: ! 165: case BMF_32BPP: ! 166: cbBits *= 32; ! 167: break; ! 168: } ! 169: ! 170: // cbBits now equals the number of bits per scanline. ! 171: // convert it to the number of bytes per scanline, taking into ! 172: // account that scanlines are padded out to 32 bit boundaries. ! 173: ! 174: cbBits = (((cbBits + 31) / 32) * 4); ! 175: ! 176: // now that we have the number of bytes per scanline, get the ! 177: // total number of bytes. ! 178: ! 179: cbBits *= psoPattern->sizlBitmap.cy; ! 180: } ! 181: else ! 182: { ! 183: // we have one of the predefined patterns. ! 184: ! 185: cbBits = 0; ! 186: } ! 187: ! 188: // leave room for the color table. ! 189: ! 190: #ifdef INDEX_PAL ! 191: if (bDitherColor) ! 192: cbColorTable = 0; ! 193: else ! 194: #endif ! 195: cbColorTable = (pxlo->cEntries * sizeof(ULONG)); ! 196: ! 197: // allocate new brush. ! 198: ! 199: cbTotal = sizeof(DEVBRUSH) + cbBits + cbColorTable; ! 200: pBrush = BRUSHOBJ_pvAllocRbrush(pbo, cbTotal); ! 201: ! 202: if (!pBrush) ! 203: { ! 204: RIP("PSCRIPT!DrvRealizeBrush: brush allocation failed.\n"); ! 205: return(FALSE); ! 206: } ! 207: ! 208: // fill in the DEVBRUSH information. ! 209: ! 210: #ifdef INDEX_PAL ! 211: if (bDitherColor) ! 212: pBrush->iSolidColor = (iHatch & RGBMASK); ! 213: else ! 214: { ! 215: pBrush->iSolidColor = NOT_SOLID_COLOR; ! 216: pBrush->iPatIndex = iHatch; ! 217: pBrush->cXlate = pxlo->cEntries; ! 218: pBrush->offsetXlate = sizeof(DEVBRUSH) + cbBits; ! 219: ! 220: pbTarg = (PBYTE)((DEVBRUSH *)pBrush) + pBrush->offsetXlate; ! 221: ! 222: CopyMemory(pbTarg, (PBYTE)pxlo->pulXlate, cbColorTable); ! 223: ! 224: if (iHatch >= HS_DDI_MAX) ! 225: { ! 226: // we have a bitmap for the pattern. fill in the appropriate ! 227: // information in the DEVBRUSH, including the bitmap itself. ! 228: ! 229: pBrush->sizlBitmap = psoPattern->sizlBitmap; ! 230: pBrush->iFormat = (ULONG)psoPattern->iBitmapFormat; ! 231: pBrush->flBitmap = (FLONG)psoPattern->fjBitmap; ! 232: ! 233: // get a pointer to the pattern bits. ! 234: ! 235: pbSrc = (PBYTE) psoPattern->pvBits; ! 236: ! 237: // get a pointer to the destination in the brush. ! 238: ! 239: pbTarg = (PBYTE)((DEVBRUSH *)pBrush)->ajBits; ! 240: ! 241: // copy the bits from the pattern surface to the brush. ! 242: ! 243: memcpy(pbTarg, pbSrc, cbBits); ! 244: } ! 245: } ! 246: #else ! 247: pBrush->iPatIndex = iHatch; ! 248: pBrush->cXlate = pxlo->cEntries; ! 249: pBrush->offsetXlate = sizeof(DEVBRUSH) + cbBits; ! 250: ! 251: pbTarg = (PBYTE)((DEVBRUSH *)pBrush) + pBrush->offsetXlate; ! 252: ! 253: CopyMemory(pbTarg, (PBYTE)pxlo->pulXlate, cbColorTable); ! 254: ! 255: if (iHatch >= HS_DDI_MAX) ! 256: { ! 257: // we have a bitmap for the pattern. fill in the appropriate ! 258: // information in the DEVBRUSH, including the bitmap itself. ! 259: ! 260: pBrush->sizlBitmap = psoPattern->sizlBitmap; ! 261: pBrush->iFormat = (ULONG)psoPattern->iBitmapFormat; ! 262: pBrush->flBitmap = (FLONG)psoPattern->fjBitmap; ! 263: ! 264: // get a pointer to the pattern bits. ! 265: ! 266: pbSrc = (PBYTE) psoPattern->pvBits; ! 267: ! 268: // get a pointer to the destination in the brush. ! 269: ! 270: pbTarg = (PBYTE)((DEVBRUSH *)pBrush)->ajBits; ! 271: ! 272: // copy the bits from the pattern surface to the brush. ! 273: ! 274: memcpy(pbTarg, pbSrc, cbBits); ! 275: } ! 276: #endif ! 277: // set the pointer to our brush in the BRUSHOBJ. REMEMBER, ! 278: // the engine will take care of discarding this memory, so ! 279: // we don't have to. ! 280: ! 281: pbo->pvRbrush = (PVOID)pBrush; ! 282: ! 283: return(TRUE); ! 284: } ! 285: ! 286: #ifdef INDEX_PAL ! 287: //-------------------------------------------------------------------------- ! 288: // ULONG DrvDitherColor(dhpdev, iMode, rgb, pul) ! 289: // DHPDEV dhpdev; ! 290: // ULONG iMode; ! 291: // ULONG rgb; ! 292: // ULONG *pul; ! 293: // ! 294: // Returns: ! 295: // DCR_HALFTONE - tells the engine to halftone a brush for me. ! 296: // ! 297: // History: ! 298: // 31-May-1993 -by- Kent Settle (kentse) ! 299: // Wrote it. ! 300: //-------------------------------------------------------------------------- ! 301: ! 302: ULONG DrvDitherColor(dhpdev, iMode, rgb, pul) ! 303: DHPDEV dhpdev; ! 304: ULONG iMode; ! 305: ULONG rgb; ! 306: ULONG *pul; ! 307: { ! 308: return(DCR_HALFTONE); ! 309: } ! 310: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.