⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cfbbitblt.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 2 页
字号:
    unsigned long   bitPlane;{    int	srcx, srcy, dstx, dsty, width, height;    int xoffSrc, xoffDst;    unsigned long *psrcBase, *pdstBase;    int	widthSrc, widthDst;    unsigned long *psrcLine, *pdstLine;    register unsigned long *psrc, *pdst;    register unsigned long bits, tmp;    register int leftShift, rightShift;    unsigned long startmask, endmask;    register int nl, nlMiddle;    int firstoff, secondoff;    unsigned long    src;    int nbox;    BoxPtr  pbox;    cfbGetLongWidthAndPointer (pSrcDrawable, widthSrc, psrcBase)    cfbGetLongWidthAndPointer (pDstDrawable, widthDst, pdstBase)    nbox = REGION_NUM_RECTS(prgnDst);    pbox = REGION_RECTS(prgnDst);    /* XXX ?? */    WAIT_READY_TO_RENDER(pSrcDrawable->pScreen);    SET_REGISTERS_FOR_WRITING(pDstDrawable->pScreen, ~0, GXcopy);    while (nbox--)    {	dstx = pbox->x1;	dsty = pbox->y1;	srcx = pptSrc->x;	srcy = pptSrc->y;	width = pbox->x2 - pbox->x1;	height = pbox->y2 - pbox->y1;	pbox++;	pptSrc++;	psrcLine = psrcBase + srcy * widthSrc + (srcx >> 5);	pdstLine = pdstBase + dsty * widthDst + (dstx >> 2);	xoffSrc = srcx & 0x1f;	xoffDst = dstx & 0x3;	if (xoffDst + width < 4)	{	    maskpartialbits(dstx, width, startmask);	    endmask = 0;	    nlMiddle = 0;	}	else	{	    maskbits(dstx, width, startmask, endmask, nlMiddle);	}	/*	 * compute constants for the first four bits to be	 * copied.  This avoids troubles with partial first	 * writes, and difficult shift computation	 */	if (startmask)	{	    firstoff = xoffSrc - xoffDst;	    if (firstoff > 28)		secondoff = 32 - firstoff;	    if (xoffDst)	    {	    	srcx += (4-xoffDst);	    	dstx += (4-xoffDst);	    	xoffSrc = srcx & 0x1f;	    }	}	leftShift = xoffSrc;	rightShift = 32 - leftShift;	if (cfb8StippleRRop == GXcopy)	{	    while (height--)	    {	    	psrc = psrcLine;	    	pdst = pdstLine;	    	psrcLine += widthSrc;	    	pdstLine += widthDst;	    	bits = *psrc++;	    	if (startmask)	    	{		    if (firstoff < 0)		    	tmp = BitRight (bits, -firstoff);		    else		    {		    	tmp = BitLeft (bits, firstoff);			/*			 * need a more cautious test for partialmask			 * case...			 */		    	if (firstoff >= 28)		    	{			    bits = *psrc++;			    if (firstoff != 28)				tmp |= BitRight (bits, secondoff);		    	}		    }		    *pdst = *pdst & ~startmask | GetFourPixels(tmp) & startmask;		    pdst++;	    	}	    	nl = nlMiddle;	    	while (nl >= 8)	    	{		    nl -= 8;		    tmp = BitLeft(bits, leftShift);		    bits = *psrc++;		    if (rightShift != 32)		    	tmp |= BitRight(bits, rightShift);#ifdef FAST_CONSTANT_OFFSET_MODE# define StorePixels(pdst,o,pixels)	(pdst)[o] = (pixels)# define EndStep(pdst,o)		(pdst) += (o)# define StoreRopPixels(pdst,o,and,xor)	(pdst)[o] = DoRRop((pdst)[o],and,xor);#else# define StorePixels(pdst,o,pixels)	*(pdst)++ = (pixels)# define EndStep(pdst,o)# define StoreRopPixels(pdst,o,and,xor)	*(pdst) = DoRRop(*(pdst),and,xor); (pdst)++;#endif#define Step(c)			NextFourBits(c);#define StoreBitsPlain(o,c)	StorePixels(pdst,o,GetFourPixels(c))#define StoreRopBitsPlain(o,c)	StoreRopPixels(pdst,o,\					cfb8StippleAnd[GetFourBits(c)], \					cfb8StippleXor[GetFourBits(c)])#define StoreBits0(c)		StoreBitsPlain(0,c)#define StoreRopBits0(c)	StoreRopBitsPlain(0,c)#if (BITMAP_BIT_ORDER == MSBFirst)# define StoreBits(o,c)	StoreBitsPlain(o,c)# define StoreRopBits(o,c)  StoreRopBitsPlain(o,c)# define FirstStep(c)	Step(c)#else# define StoreBits(o,c)	StorePixels(pdst,o,*((unsigned long *)\			    (((char *) cfb8Pixels) + (c & 0x3c))))# define StoreRopBits(o,c)  StoreRopPixels(pdst,o, \	    *((unsigned long *) (((char *) cfb8StippleAnd) + (c & 0x3c))), \	    *((unsigned long *) (((char *) cfb8StippleXor) + (c & 0x3c))))# define FirstStep(c)	c = BitLeft (c, 2);#endif		    StoreBits0(tmp);	FirstStep(tmp);		    StoreBits(1,tmp);	Step(tmp);		    StoreBits(2,tmp);	Step(tmp);		    StoreBits(3,tmp);	Step(tmp);		    StoreBits(4,tmp);	Step(tmp);		    StoreBits(5,tmp);	Step(tmp);		    StoreBits(6,tmp);	Step(tmp);		    StoreBits(7,tmp);   EndStep (pdst,8);	    	}	    	if (nl || endmask)	    	{		    tmp = BitLeft(bits, leftShift);		    /*		     * better condition needed -- mustn't run		     * off the end of the source...		     */		    if (rightShift != 32)		    {		    	bits = *psrc++;		    	tmp |= BitRight (bits, rightShift);		    }		    EndStep (pdst, nl);		    switch (nl)		    {		    case 7:			StoreBitsPlain(-7,tmp);	Step(tmp);		    case 6:			StoreBitsPlain(-6,tmp);	Step(tmp);		    case 5:			StoreBitsPlain(-5,tmp);	Step(tmp);		    case 4:			StoreBitsPlain(-4,tmp);	Step(tmp);		    case 3:			StoreBitsPlain(-3,tmp);	Step(tmp);		    case 2:			StoreBitsPlain(-2,tmp);	Step(tmp);		    case 1:			StoreBitsPlain(-1,tmp);	Step(tmp);		    }		    if (endmask)		    	*pdst = *pdst & ~endmask | GetFourPixels(tmp) & endmask;	    	}	    }	}	else	{	    while (height--)	    {	    	psrc = psrcLine;	    	pdst = pdstLine;	    	psrcLine += widthSrc;	    	pdstLine += widthDst;	    	bits = *psrc++;	    	if (startmask)	    	{		    if (firstoff < 0)		    	tmp = BitRight (bits, -firstoff);		    else		    {		    	tmp = BitLeft (bits, firstoff);		    	if (firstoff >= 28)		    	{			    bits = *psrc++;			    if (firstoff != 28)				tmp |= BitRight (bits, secondoff);		    	}		    }		    src = GetFourBits(tmp);		    *pdst = MaskRRopPixels (*pdst, src, startmask);		    pdst++;	    	}	    	nl = nlMiddle;		while (nl >= 8)		{		    nl -= 8;		    tmp = BitLeft(bits, leftShift);		    bits = *psrc++;		    if (rightShift != 32)			tmp |= BitRight(bits, rightShift);		    StoreRopBits0(tmp);	FirstStep(tmp);		    StoreRopBits(1,tmp);	Step(tmp);		    StoreRopBits(2,tmp);	Step(tmp);		    StoreRopBits(3,tmp);	Step(tmp);		    StoreRopBits(4,tmp);	Step(tmp);		    StoreRopBits(5,tmp);	Step(tmp);		    StoreRopBits(6,tmp);	Step(tmp);		    StoreRopBits(7,tmp);	EndStep(pdst,8);		}	    	if (nl || endmask)	    	{		    tmp = BitLeft(bits, leftShift);		    /*		     * better condition needed -- mustn't run		     * off the end of the source...		     */		    if (rightShift != 32)		    {		    	bits = *psrc++;		    	tmp |= BitRight (bits, rightShift);		    }		    while (nl--)		    {			src = GetFourBits (tmp);			*pdst = RRopPixels (*pdst, src);		    	pdst++;			NextFourBits(tmp);		    }		    if (endmask)		    {			src = GetFourBits (tmp);			*pdst = MaskRRopPixels (*pdst, src, endmask);		    }	    	}	    }	}    }}#endifRegionPtr cfbCopyPlane(pSrcDrawable, pDstDrawable,	    pGC, srcx, srcy, width, height, dstx, dsty, bitPlane)    DrawablePtr 	pSrcDrawable;    DrawablePtr		pDstDrawable;    GCPtr		pGC;    int 		srcx, srcy;    int 		width, height;    int 		dstx, dsty;    unsigned long	bitPlane;{    RegionPtr	ret;    extern RegionPtr    miHandleExposures();    int		(*doBitBlt)();#if (PPW == 4)    extern cfbCopyPlane8to1();    if (pSrcDrawable->bitsPerPixel == 1 && pDstDrawable->bitsPerPixel == 8)    {    	if (bitPlane == 1)	{       	    doBitBlt = cfbCopyPlane1to8;	    cfb8CheckOpaqueStipple (pGC->alu,				    pGC->fgPixel, pGC->bgPixel,				    pGC->planemask);    	    ret = cfbBitBlt (pSrcDrawable, pDstDrawable,	    	    pGC, srcx, srcy, width, height, dstx, dsty, doBitBlt, bitPlane);	}	else	    ret = miHandleExposures (pSrcDrawable, pDstDrawable,	    	pGC, srcx, srcy, width, height, dstx, dsty, bitPlane);    }    else if (pSrcDrawable->bitsPerPixel == 8 && pDstDrawable->bitsPerPixel == 1)    {	extern	int InverseAlu[16];	int oldalu;	oldalu = pGC->alu;    	if ((pGC->fgPixel & 1) == 0 && (pGC->bgPixel&1) == 1)	    pGC->alu = InverseAlu[pGC->alu];    	else if ((pGC->fgPixel & 1) == (pGC->bgPixel & 1))	    pGC->alu = mfbReduceRop(pGC->alu, pGC->fgPixel);	ret = cfbBitBlt (pSrcDrawable, pDstDrawable,		    pGC, srcx, srcy, width, height, dstx, dsty, cfbCopyPlane8to1, bitPlane);	pGC->alu = oldalu;    }    else    {	PixmapPtr	pBitmap;	ScreenPtr	pScreen = pSrcDrawable->pScreen;	GCPtr		pGC1;	unsigned long	fg, bg;	pBitmap = (*pScreen->CreatePixmap) (pScreen, width, height, 1);	if (!pBitmap)	    return NULL;	pGC1 = GetScratchGC (1, pScreen);	if (!pGC1)	{	    (*pScreen->DestroyPixmap) (pBitmap);	    return NULL;	}	/*	 * don't need to set pGC->fgPixel,bgPixel as copyPlane8to1	 * ignores pixel values, expecting the rop to "do the	 * right thing", which GXcopy will.	 */	ValidateGC ((DrawablePtr) pBitmap, pGC1);	/* no exposures here, scratch GC's don't get graphics expose */	(void) cfbBitBlt (pSrcDrawable, (DrawablePtr) pBitmap,			    pGC1, srcx, srcy, width, height, 0, 0, cfbCopyPlane8to1, bitPlane);	cfb8CheckOpaqueStipple (pGC->alu,				pGC->fgPixel, pGC->bgPixel,				pGC->planemask);	/* no exposures here, copy bits from inside a pixmap */	(void) cfbBitBlt ((DrawablePtr) pBitmap, pDstDrawable, pGC,			    0, 0, width, height, dstx, dsty, cfbCopyPlane1to8, 1);	FreeScratchGC (pGC1);	(*pScreen->DestroyPixmap) (pBitmap);	/* compute resultant exposures */	ret = miHandleExposures (pSrcDrawable, pDstDrawable, pGC,				 srcx, srcy, width, height,				 dstx, dsty, bitPlane);    }    return ret;#else    return miCopyPlane (pSrcDrawable, pDstDrawable,	    pGC, srcx, srcy, width, height, dstx, dsty, bitPlane);#endif}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -