📄 mibitblt.c
字号:
/***********************************************************Copyright (c) 1987 X ConsortiumPermission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included inall copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER INAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR INCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.Except as contained in this notice, the name of the X Consortium shall not beused in advertising or otherwise to promote the sale, use or other dealingsin this Software without prior written authorization from the X Consortium.Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. All Rights ReservedPermission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and thatboth that copyright notice and this permission notice appear in supporting documentation, and that the name of Digital not beused in advertising or publicity pertaining to distribution of thesoftware without specific, written prior permission. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDINGALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALLDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES ORANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THISSOFTWARE.******************************************************************//* $XConsortium: mibitblt.c /main/55 1996/08/01 19:25:20 dpw $ *//* $XFree86: xc/programs/Xserver/mi/mibitblt.c,v 3.1 1996/12/23 07:09:43 dawes Exp $ *//* Author: Todd Newman (aided and abetted by Mr. Drewry) */#include "X.h"#include "Xprotostr.h"#include "misc.h"#include "gcstruct.h"#include "pixmapstr.h"#include "windowstr.h"#include "scrnintstr.h"#include "mi.h"#include "regionstr.h"#include "Xmd.h"#include "servermd.h"/* MICOPYAREA -- public entry for the CopyArea request * For each rectangle in the source region * get the pixels with GetSpans * set them in the destination with SetSpans * We let SetSpans worry about clipping to the destination. */RegionPtrmiCopyArea(pSrcDrawable, pDstDrawable, pGC, xIn, yIn, widthSrc, heightSrc, xOut, yOut) register DrawablePtr pSrcDrawable; register DrawablePtr pDstDrawable; GCPtr pGC; int xIn, yIn; int widthSrc, heightSrc; int xOut, yOut;{ DDXPointPtr ppt, pptFirst; unsigned int *pwidthFirst, *pwidth, *pbits; BoxRec srcBox, *prect; /* may be a new region, or just a copy */ RegionPtr prgnSrcClip; /* non-0 if we've created a src clip */ RegionPtr prgnExposed; int realSrcClip = 0; int srcx, srcy, dstx, dsty, i, j, y, width, height, xMin, xMax, yMin, yMax; unsigned int *ordering; int numRects; BoxPtr boxes; srcx = xIn + pSrcDrawable->x; srcy = yIn + pSrcDrawable->y; /* If the destination isn't realized, this is easy */ if (pDstDrawable->type == DRAWABLE_WINDOW && !((WindowPtr)pDstDrawable)->realized) return (RegionPtr)NULL; /* clip the source */ if (pSrcDrawable->type == DRAWABLE_PIXMAP) { BoxRec box; box.x1 = pSrcDrawable->x; box.y1 = pSrcDrawable->y; box.x2 = pSrcDrawable->x + (int) pSrcDrawable->width; box.y2 = pSrcDrawable->y + (int) pSrcDrawable->height; prgnSrcClip = REGION_CREATE(pGC->pScreen, &box, 1); realSrcClip = 1; } else { if (pGC->subWindowMode == IncludeInferiors) { prgnSrcClip = NotClippedByChildren ((WindowPtr) pSrcDrawable); realSrcClip = 1; } else prgnSrcClip = &((WindowPtr)pSrcDrawable)->clipList; } /* If the src drawable is a window, we need to translate the srcBox so * that we can compare it with the window's clip region later on. */ srcBox.x1 = srcx; srcBox.y1 = srcy; srcBox.x2 = srcx + widthSrc; srcBox.y2 = srcy + heightSrc; dstx = xOut; dsty = yOut; if (pGC->miTranslate) { dstx += pDstDrawable->x; dsty += pDstDrawable->y; } pptFirst = ppt = (DDXPointPtr) ALLOCATE_LOCAL(heightSrc * sizeof(DDXPointRec)); pwidthFirst = pwidth = (unsigned int *) ALLOCATE_LOCAL(heightSrc * sizeof(unsigned int)); numRects = REGION_NUM_RECTS(prgnSrcClip); boxes = REGION_RECTS(prgnSrcClip); ordering = (unsigned int *) ALLOCATE_LOCAL(numRects * sizeof(unsigned int)); if(!pptFirst || !pwidthFirst || !ordering) { if (ordering) DEALLOCATE_LOCAL(ordering); if (pwidthFirst) DEALLOCATE_LOCAL(pwidthFirst); if (pptFirst) DEALLOCATE_LOCAL(pptFirst); return (RegionPtr)NULL; } /* If not the same drawable then order of move doesn't matter. Following assumes that boxes are sorted from top to bottom and left to right. */ if ((pSrcDrawable != pDstDrawable) && ((pGC->subWindowMode != IncludeInferiors) || (pSrcDrawable->type == DRAWABLE_PIXMAP) || (pDstDrawable->type == DRAWABLE_PIXMAP))) for (i=0; i < numRects; i++) ordering[i] = i; else { /* within same drawable, must sequence moves carefully! */ if (dsty <= srcBox.y1) { /* Scroll up or stationary vertical. Vertical order OK */ if (dstx <= srcBox.x1) /* Scroll left or stationary horizontal. Horizontal order OK as well */ for (i=0; i < numRects; i++) ordering[i] = i; else { /* scroll right. must reverse horizontal banding of rects. */ for (i=0, j=1, xMax=0; i < numRects; j=i+1, xMax=i) { /* find extent of current horizontal band */ y=boxes[i].y1; /* band has this y coordinate */ while ((j < numRects) && (boxes[j].y1 == y)) j++; /* reverse the horizontal band in the output ordering */ for (j-- ; j >= xMax; j--, i++) ordering[i] = j; } } } else { /* Scroll down. Must reverse vertical banding. */ if (dstx < srcBox.x1) { /* Scroll left. Horizontal order OK. */ for (i=numRects-1, j=i-1, yMin=i, yMax=0; i >= 0; j=i-1, yMin=i) { /* find extent of current horizontal band */ y=boxes[i].y1; /* band has this y coordinate */ while ((j >= 0) && (boxes[j].y1 == y)) j--; /* reverse the horizontal band in the output ordering */ for (j++ ; j <= yMin; j++, i--, yMax++) ordering[yMax] = j; } } else /* Scroll right or horizontal stationary. Reverse horizontal order as well (if stationary, horizontal order can be swapped without penalty and this is faster to compute). */ for (i=0, j=numRects-1; i < numRects; i++, j--) ordering[i] = j; } } for(i = 0; i < numRects; i++) { prect = &boxes[ordering[i]]; xMin = max(prect->x1, srcBox.x1); xMax = min(prect->x2, srcBox.x2); yMin = max(prect->y1, srcBox.y1); yMax = min(prect->y2, srcBox.y2); /* is there anything visible here? */ if(xMax <= xMin || yMax <= yMin) continue; ppt = pptFirst; pwidth = pwidthFirst; y = yMin; height = yMax - yMin; width = xMax - xMin; for(j = 0; j < height; j++) { /* We must untranslate before calling GetSpans */ ppt->x = xMin; ppt++->y = y++; *pwidth++ = width; } pbits = (unsigned int *)xalloc(height * PixmapBytePad(width, pSrcDrawable->depth)); if (pbits) { (*pSrcDrawable->pScreen->GetSpans)(pSrcDrawable, width, pptFirst, (int *)pwidthFirst, height, (char *)pbits); ppt = pptFirst; pwidth = pwidthFirst; xMin -= (srcx - dstx); y = yMin - (srcy - dsty); for(j = 0; j < height; j++) { ppt->x = xMin; ppt++->y = y++; *pwidth++ = width; } (*pGC->ops->SetSpans)(pDstDrawable, pGC, (char *)pbits, pptFirst, (int *)pwidthFirst, height, TRUE); xfree(pbits); } } prgnExposed = miHandleExposures(pSrcDrawable, pDstDrawable, pGC, xIn, yIn, widthSrc, heightSrc, xOut, yOut, (unsigned long)0); if(realSrcClip) REGION_DESTROY(pGC->pScreen, prgnSrcClip); DEALLOCATE_LOCAL(ordering); DEALLOCATE_LOCAL(pwidthFirst); DEALLOCATE_LOCAL(pptFirst); return prgnExposed;}/* MIGETPLANE -- gets a bitmap representing one plane of pDraw * A helper used for CopyPlane and XY format GetImage * No clever strategy here, we grab a scanline at a time, pull out the * bits and then stuff them in a 1 bit deep map. */staticunsigned long *miGetPlane(pDraw, planeNum, sx, sy, w, h, result) DrawablePtr pDraw; int planeNum; /* number of the bitPlane */ int sx, sy, w, h; unsigned long *result;{ int i, j, k, width, bitsPerPixel, widthInBytes; DDXPointRec pt; unsigned long pixel; unsigned long bit; unsigned char *pCharsOut;#if BITMAP_SCANLINE_UNIT == 8#define OUT_TYPE unsigned char#endif#if BITMAP_SCANLINE_UNIT == 16#define OUT_TYPE CARD16#endif#if BITMAP_SCANLINE_UNIT == 32#define OUT_TYPE CARD32#endif#if BITMAP_SCANLINE_UNIT == 64#define OUT_TYPE CARD64#endif OUT_TYPE *pOut; int delta; sx += pDraw->x; sy += pDraw->y; widthInBytes = BitmapBytePad(w); if(!result) result = (unsigned long *)xalloc(h * widthInBytes); if (!result) return (unsigned long *)NULL; bitsPerPixel = pDraw->bitsPerPixel; bzero((char *)result, h * widthInBytes); pOut = (OUT_TYPE *) result; if(bitsPerPixel == 1) { pCharsOut = (unsigned char *) result; width = w; } else { delta = (widthInBytes / (BITMAP_SCANLINE_UNIT / 8)) - (w / BITMAP_SCANLINE_UNIT); width = 1;#if IMAGE_BYTE_ORDER == MSBFirst planeNum += (32 - bitsPerPixel);#endif } pt.y = sy; for (i = h; --i >= 0; pt.y++) { pt.x = sx; if(bitsPerPixel == 1) { (*pDraw->pScreen->GetSpans)(pDraw, width, &pt, &width, 1, (char *)pCharsOut); pCharsOut += widthInBytes; } else { k = 0; for(j = w; --j >= 0; pt.x++) { /* Fetch the next pixel */ (*pDraw->pScreen->GetSpans)(pDraw, width, &pt, &width, 1, (char *)&pixel); /* * Now get the bit and insert into a bitmap in XY format. */ bit = (pixel >> planeNum) & 1; /* XXX assuming bit order == byte order */#if BITMAP_BIT_ORDER == LSBFirst bit <<= k;#else bit <<= ((BITMAP_SCANLINE_UNIT - 1) - k);#endif *pOut |= (OUT_TYPE) bit; k++; if (k == BITMAP_SCANLINE_UNIT) { pOut++; k = 0; } } pOut += delta; } } return(result); }/* MIOPQSTIPDRAWABLE -- use pbits as an opaque stipple for pDraw. * Drawing through the clip mask we SetSpans() the bits into a * bitmap and stipple those bits onto the destination drawable by doing a * PolyFillRect over the whole drawable, * then we invert the bitmap by copying it onto itself with an alu of * GXinvert, invert the foreground/background colors of the gc, and draw * the background bits. * Note how the clipped out bits of the bitmap are always the background * color so that the stipple never causes FillRect to draw them. */voidmiOpqStipDrawable(pDraw, pGC, prgnSrc, pbits, srcx, w, h, dstx, dsty) DrawablePtr pDraw; GCPtr pGC; RegionPtr prgnSrc; unsigned long *pbits; int srcx, w, h, dstx, dsty;{ int oldfill, i; unsigned long oldfg; int *pwidth, *pwidthFirst; ChangeGCVal gcv[6]; PixmapPtr pStipple, pPixmap; DDXPointRec oldOrg; GCPtr pGCT; DDXPointPtr ppt, pptFirst; xRectangle rect; RegionPtr prgnSrcClip; pPixmap = (*pDraw->pScreen->CreatePixmap) (pDraw->pScreen, w + srcx, h, 1); if (!pPixmap) return; /* Put the image into a 1 bit deep pixmap */ pGCT = GetScratchGC(1, pDraw->pScreen); if (!pGCT) { (*pDraw->pScreen->DestroyPixmap)(pPixmap); return; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -