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

📄 gperotate.cpp

📁 Lido PXA270平台开发板的最新BSP,包括源代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//

#include "precomp.h"

//#include <windows.h>
//#include <winddi.h>
//#include <gpe.h>

//#include <emul.h>
#include <ctblt.h>
#include <aablt.h>
//#include <memory.h>
//#include <wingdi.h>
#include "swblt.h"
#include "dispperf.h"

#if defined (OSV_PPC) || ( defined (_WINCEOSVER) && (_WINCEOSVER < 500))

#if defined (OSV_PPC) || ( defined (_WINCEOSVER) && (_WINCEOSVER >= 500))
extern ULONG g_BilinearMasks[4];
extern ULONG g_BilinearShifts[4];
#endif

unsigned long
RGBError(
	unsigned long v1,
	unsigned long v2
	);

void GPESurfRotate::RotateLineParms(GPELineParms * pParms)
{
long lTmp;

	switch (m_iRotate)
	{
	case DMDO_90:
        lTmp = pParms->xStart;
        pParms->xStart = pParms->yStart;
        pParms->yStart = (m_ScreenHeight - 1) - lTmp;
        pParms->iDir = (pParms->iDir - 2) < 0 ? (pParms->iDir + 6) : (pParms->iDir - 2);
        break;
	
    case DMDO_180:
        pParms->xStart = (m_ScreenWidth - 1) - pParms->xStart;
        pParms->yStart = (m_ScreenHeight - 1) - pParms->yStart;
        pParms->iDir = (pParms->iDir - 4) < 0 ? (pParms->iDir + 4) : (pParms->iDir - 4);
        break;
	
    case DMDO_270:
        lTmp = pParms->xStart;
        pParms->xStart = (m_ScreenWidth - 1) - pParms->yStart;
        pParms->yStart = lTmp;
        pParms->iDir = (pParms->iDir - 6) < 0 ? (pParms->iDir + 2) : (pParms->iDir - 6);
        break;
	
    default:
	 	break;
	}

	return;
}


void GPERotate::RotateRectl(RECTL *prcl)
{
	RECTL rclSwap = *prcl;
	switch (m_iRotate)
	{
	case DMDO_90:
		prcl->left = rclSwap.top;
		prcl->right = rclSwap.bottom;
		prcl->top = m_nScreenHeightSave - rclSwap.right;
		prcl->bottom = m_nScreenHeightSave - rclSwap.left;
		break;
		
	case DMDO_180:
		prcl->left = m_nScreenWidthSave - rclSwap.right;
		prcl->right = m_nScreenWidthSave  - rclSwap.left;
		prcl->top = m_nScreenHeightSave - rclSwap.bottom;
		prcl->bottom = m_nScreenHeightSave  - rclSwap.top;
		break;
		
	case DMDO_270:
		prcl->left = m_nScreenWidthSave  - rclSwap.bottom;
		prcl->right = m_nScreenWidthSave  - rclSwap.top;
		prcl->top = rclSwap.left;
		prcl->bottom = rclSwap.right;
		break;
		
	default:
	 	break;
	}
	return;
}

void GPERotate::RotateRectlBack(RECTL * prcl)
{
	RECTL rclSwap = *prcl;
	switch (m_iRotate)
	{
	case DMDO_90:
		prcl->top = rclSwap.left;
		prcl->bottom = rclSwap.right;
		prcl->left = m_nScreenHeightSave  - rclSwap.bottom;
		prcl->right = m_nScreenHeightSave  - rclSwap.top;
		break;
		
	case DMDO_180:
		prcl->left = m_nScreenWidthSave  - rclSwap.right;
		prcl->right = m_nScreenWidthSave  - rclSwap.left;
		prcl->top = m_nScreenHeightSave  - rclSwap.bottom;
		prcl->bottom = m_nScreenHeightSave  - rclSwap.top;
		break;
		
	case DMDO_270:
		prcl->top = m_nScreenWidthSave  - rclSwap.right;
		prcl->bottom = m_nScreenWidthSave  - rclSwap.left;
		prcl->left = rclSwap.top;
		prcl->right = rclSwap.bottom;
		break;
		
	default:
	 	break;
	}
}



//GPESurfRotate

GPESurfRotate::GPESurfRotate(int width, int height, PVOID pBits, int stride, EGPEFormat format)
 : GPESurf(width, height, pBits,stride,format)
{
	m_iRotate = 0;
	m_ScreenHeight = m_ScreenWidth = 0;
}


void GPESurfRotate::SetRotation(int width, int height, int iRotate)
{
	m_iRotate = iRotate;
#if defined (_WINCEOSVER) && (_WINCEOSVER >= 500)
	m_BytesPixel = EGPEFormatToBpp[m_Format.m_eFormat] >> 3;
#else
	m_BytesPixel = EGPEFormatToBpp[m_eFormat] >> 3;
#endif
	m_nWidth = width;
	m_nHeight = height;
	switch (iRotate)
	{
	case DMDO_90:
	case DMDO_270:
		m_ScreenHeight = m_nWidth;
		m_ScreenWidth = m_nHeight;
		break;
		
	case DMDO_0:
	case DMDO_180:
	default:
		m_ScreenWidth = m_nWidth;
		m_ScreenHeight = m_nHeight;
		break;
	}
}
	
void GPESurfRotate::RotatePathdata(PATHDATA *ppd)
{
	ULONG  cptfx, iPoint;
	POINTFIX *pptfx;

	cptfx = ppd->count;
 	switch(m_iRotate)
 	{
 	case DMDO_90:   
	    for (pptfx = ppd->pptfx, iPoint=0; iPoint < cptfx; iPoint++, pptfx ++)
	    { 	
			FIX fxSwap = pptfx->x;
            pptfx->x = pptfx->y;
            pptfx->y = LTOFX(m_ScreenHeight-1) - fxSwap;
	    }
	    break;

    case DMDO_180:    
    	for (pptfx = ppd->pptfx, iPoint = 0; iPoint < cptfx; iPoint ++, pptfx ++)
    	{
            pptfx->x = LTOFX(m_ScreenWidth-1) - pptfx->x;
            pptfx->y = LTOFX(m_ScreenHeight-1) - pptfx->y;
    	}
    	break;

    case DMDO_270:
        for (pptfx = ppd->pptfx, iPoint = 0; iPoint < cptfx; iPoint ++, pptfx ++)
    	{
        	
        		FIX fxSwap = pptfx->x;
            	pptfx->x = LTOFX(m_ScreenWidth-1) - pptfx->y;
            	pptfx->y = fxSwap;
        }	
    	break;
    default:
    	break;
 	}
 	return;
}

void GPESurfRotate::RotatePathdataBack(PATHDATA * ppd)
{
	ULONG  cptfx, iPoint;
	POINTFIX *pptfx;

	cptfx = ppd->count;
	switch (m_iRotate)
	{
	case DMDO_90:    
    	for (pptfx = ppd->pptfx, iPoint=0; iPoint < cptfx; iPoint++, pptfx ++)
	    { 
        		FIX fxSwap = pptfx->x;
            	pptfx->x = LTOFX(m_ScreenHeight-1) - pptfx->y;
            	pptfx->y = fxSwap;
    	}
		break;
		
	case DMDO_180:    
	 for (pptfx = ppd->pptfx, iPoint=0; iPoint < cptfx; iPoint++, pptfx ++)
	    { 
    	
            	pptfx->x = LTOFX(m_ScreenWidth-1) - pptfx->x;
            	pptfx->y = LTOFX(m_ScreenHeight-1) - pptfx->y;
        	
    	}
		break;
		
	case DMDO_270:
        for (pptfx = ppd->pptfx, iPoint=0; iPoint < cptfx; iPoint++, pptfx ++)
	    { 
        	
        		FIX fxSwap = pptfx->x;
            	pptfx->x = pptfx->y;
            	pptfx->y = LTOFX(m_ScreenWidth-1) - fxSwap;
        	
    	}
		break;
		
	default:
	 	break;
	}	
	return;
}




void GPESurfRotate::RotateRectl(RECTL *prcl)
{
	RECTL rclSwap = *prcl;
	switch (m_iRotate)
	{
	case DMDO_90:
		prcl->left = rclSwap.top;
		prcl->right = rclSwap.bottom;
		prcl->top = m_ScreenHeight - rclSwap.right;
		prcl->bottom = m_ScreenHeight - rclSwap.left;
		break;
		
	case DMDO_180:
		prcl->left = m_ScreenWidth - rclSwap.right;
		prcl->right = m_ScreenWidth  - rclSwap.left;
		prcl->top = m_ScreenHeight - rclSwap.bottom;
		prcl->bottom = m_ScreenHeight  - rclSwap.top;
		break;
		
	case DMDO_270:
		prcl->left = m_ScreenWidth  - rclSwap.bottom;
		prcl->right = m_ScreenWidth  - rclSwap.top;
		prcl->top = rclSwap.left;
		prcl->bottom = rclSwap.right;
		break;
		
	default:
	 	break;
	}
	return;
}

void GPESurfRotate::RotateRectlBack(RECTL * prcl)
{
	RECTL rclSwap = *prcl;
	switch (m_iRotate)
	{
	case DMDO_90:
		prcl->top = rclSwap.left;
		prcl->bottom = rclSwap.right;
		prcl->left = m_ScreenHeight  - rclSwap.bottom;
		prcl->right = m_ScreenHeight  - rclSwap.top;
		break;
		
	case DMDO_180:
		prcl->left = m_ScreenWidth  - rclSwap.right;
		prcl->right = m_ScreenWidth  - rclSwap.left;
		prcl->top = m_ScreenHeight  - rclSwap.bottom;
		prcl->bottom = m_ScreenHeight  - rclSwap.top;
		break;
		
	case DMDO_270:
		prcl->top = m_ScreenWidth  - rclSwap.right;
		prcl->bottom = m_ScreenWidth  - rclSwap.left;
		prcl->left = rclSwap.top;
		prcl->right = rclSwap.bottom;
		break;
		
	default:
	 	break;
	}
}


unsigned char *GPESurfRotate::GetPtr(int x, int y)
{
	unsigned char *ptr = (unsigned char*)m_pVirtAddr;

#if defined (_WINCEOSVER) && (_WINCEOSVER >= 500)
    int bpp = EGPEFormatToBpp[m_Format.m_eFormat];
#else
    int bpp = EGPEFormatToBpp[m_eFormat];
#endif


	if (15 == bpp) bpp++;

	switch (m_iRotate)
	{
	case DMDO_90:
		ptr += (m_ScreenHeight -1 - x)*m_nStrideBytes + ((y * bpp) >> 3);
		break;
	case DMDO_180:
		ptr += (m_ScreenHeight - 1 - y)*m_nStrideBytes + (((m_ScreenWidth -1 - x)* bpp) >> 3);
		break;
	case DMDO_270:
		ptr += x * m_nStrideBytes + (((m_ScreenWidth - 1 - y)* bpp) >> 3);
		break;
	case DMDO_0:
		ptr += ((x * bpp) >> 3) + y * m_nStrideBytes;
	default:
		break;
	}

	return ptr;
}


GPESurfRotate::~GPESurfRotate()
{
}


class PixelIteratorRotate : public PixelIterator
{
public:
	// Fixed upon creation:
	unsigned char     *OrigPtr;
	int                 ColIncrement;
	int                Stride;
	WORD               IRotate;
	int                Width;
	int                Height;
	BOOL               IsRotate;
	
	// IteratorState
	POINTL             CurrentCoord;
	POINTL              RowCoord;
	
	void				InitPixelIterator(
							GPESurf *pSurf,
							int xPositive,
							int yPositive,
							RECTL *prcl,
							int xSkip,
							int ySkip);
	unsigned char         *GetPtr(void);
};

void PixelIteratorRotate::InitPixelIterator(
	GPESurf *pSurf,
	int xPositive,
	int yPositive,
	RECTL *prcl,
	int xSkip,
	int ySkip)
{
	DEBUGMSG(GPE_ZONE_BLT_LO,(TEXT("PixelIterator::PixelIterator, prcl= l:%d,t:%d - r:%d,b:%d Bpp=%d\r\n"),
		prcl->left, prcl->top, prcl->right, prcl->bottom, EGPEFormatToBpp[pSurf->Format()]
		));

	IsRotate = pSurf->IsRotate();
	IRotate = 0;
	Bpp = EGPEFormatToBpp[pSurf->Format()];
	Ptr = RowPtr = OrigPtr = 0;
	CacheState = CacheStateIncrement = CacheStateIncrementDirty
	           = CacheStateNewDWord = CacheStateNewRow = 0;
	           
	if (pSurf->IsRotate())
	{
	// Set pointer to start of first row to use
		GPESurfRotate *pSurfRotate = (GPESurfRotate *)pSurf;
		OrigPtr = (unsigned char *)(pSurf->Buffer());
		RowCoord.x = RowCoord.y = CurrentCoord.x = CurrentCoord.y = 0;	
		IRotate	 = 	pSurfRotate->Rotate();
		Stride = pSurfRotate->Stride();
		Width = pSurfRotate->ScreenWidth() - 1;    // 0 indexed
		Height = pSurfRotate->ScreenHeight() - 1;  // 0 indexed

		ASSERT(Bpp >= 8);
	
		if( yPositive )
		{
			RowIncrement = 1;
			RowCoord.y += prcl->top + ySkip;
		}
		else
		{
			RowIncrement = -1;
			RowCoord.y += (prcl->bottom-1-ySkip);
		}

		if( xPositive )
		{
			ColIncrement = 1;
			RowCoord.x += prcl->left + xSkip;
		}
		else
		{
			ColIncrement = -1;
			RowCoord.x += prcl->right-1-xSkip;
		}

		BytesPerAccess = Bpp/8;  
		Mask = (0xffffffff >> (32-Bpp));
	}
	else 
		PixelIterator::InitPixelIterator(pSurf, 
										 xPositive, 
										 yPositive, 
										 prcl, 
										 xSkip, 
										 ySkip);

}


unsigned char *PixelIteratorRotate::GetPtr()
{

⌨️ 快捷键说明

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