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

📄 resize.c

📁 是一个手机功能的模拟程序
💻 C
字号:
//===========================================================================
//	RESIZE.C
//	This file contains RESIZE functons used by the JPEG library but not exposed
//	to the outside world.
//---------------------------------------------------------------------------
//  Copyright (c) 2003 Epson Research and Development, Inc.
//  All Rights Reserved.
//===========================================================================
//Test

//-----------------------------------------------------------------------------
// Include Files
//-----------------------------------------------------------------------------
#include "JPEGComm.h"
#include "hal.h"

//-----------------------------------------------------------------------------
// Local Function Prototypes
//-----------------------------------------------------------------------------
static Boolean prvSetResizePos( UInt16 pos, UInt16 index1, UInt16 index2, int bits );

//-----------------------------------------------------------------------------
//	prvGetResize - retrieves resize enable status
//
//	Input:	n/a
//
//	Output:	TRUE means Resize enabled
//			FALSE means Resize disabled
//
//-----------------------------------------------------------------------------
Boolean prvGetResize( void )
{
	UInt8 resize = halReadReg8( REG0202_RESIZE );
	//76543210b
	//|||||||+--Resize Enable
	//||||||+---Resize Register Update VSYNC Enable
	//|||||+----Resize Independent Horizontal/Vertical Scale Enable
	//+++++-----n/a
	Boolean fEnable = (resize & 1) ? TRUE : FALSE;
	return ( fEnable );
}

//-----------------------------------------------------------------------------
//	prvSetResize - sets resize enable status
//
//	Input:	fEnable		TRUE means Resize logic enabled
//						FALSE means Resize logic disabled
//			pJpegInfo	pointer to JPEGINFO object
//
//	Output:	TRUE means success
//			FALSE means not success
//
//-----------------------------------------------------------------------------
Boolean prvSetResize( Boolean fEnable, JPEGINFO* pJpegInfo )
{
	UInt8	resize = halReadReg8( REG0202_RESIZE );
	//76543210b
	//|||||||+--Resize Enable
	//||||||+---Resize Register Update VSYNC Enable
	//|||||+----Resize Independent Horizontal/Vertical Scale Enable
	//+++++-----n/a
	resize &= (~1);
	resize |= fEnable ? 1 : 0;
	halWriteReg8( REG0202_RESIZE, resize );
	return TRUE;
}

//-----------------------------------------------------------------------------
//	prvGetResizeHScaleRate - retrieves horizontal resize Scale rate
//
//	Input:	n/a
//
//	Output:	ScaleRate
//
//-----------------------------------------------------------------------------
UInt8 prvGetResizeHScaleRate( void )
{
	UInt8 scaleRate = 1;
	UInt8 scaleMode = prvGetResizeScaleMode();
	switch( scaleMode )
	{
	case 1:
	case 2:
		scaleRate = halReadReg8( REG020C_RESIZEHSCALE );
		break;

	default:
		break;
	}
	return ( scaleRate );
}

//-----------------------------------------------------------------------------
//	prvSetResizeHScaleRate - sets resizer Scale mode
//
//	Input:	scaleRate
//			pJpegInfo			pointer to JPEGINFO object
//
//	Output:	TRUE means success
//			FALSE means not success
//
//-----------------------------------------------------------------------------
Boolean prvSetResizeHScaleRate( UInt8 scaleRate, JPEGINFO* pJpegInfo )
{
	Boolean fSuccess = (scaleRate <= 32) ? TRUE : FALSE;
	if ( !fSuccess )
		jpegSetLastError( JPEG_ERR_INVALID_PARAM );
	else
		halWriteReg8( REG020C_RESIZEHSCALE, scaleRate );

	return ( fSuccess );
}

//-----------------------------------------------------------------------------
//	prvGetResizeIndScaleRate - retrieves status of Independent horizontal
//								/vertical Scale enable
//
//	Input:	n/a
//
//	Output:	TRUE means horizontal and vertical Scale is independent
//			FALSE means horizontal and vertical Scale is the same
//
//-----------------------------------------------------------------------------
Boolean prvGetResizeIndScaleRate( void )
{
	UInt8 globalResize = halReadReg8( REG0202_RESIZE );
	Boolean fEnable = (globalResize & 0x04) ? TRUE : FALSE;
	return ( fEnable );
}

//-----------------------------------------------------------------------------
//	prvSetResizeIndScaleRate - Sets status of Independent horizontal
//								/vertical Scale enable
//
//	Input:	fEnable		TRUE means horizontal and vertical Scale is independent
//						FALSE means horizontal and vertical Scale is the same
//			pJpegInfo	pointer to JPEGINFO object
//
//	Output:	TRUE means success
//			FALSE means not success
//
//-----------------------------------------------------------------------------
Boolean prvSetResizeIndScaleRate( Boolean fEnable, JPEGINFO* pJpegInfo )
{
	UInt8 globalResize = halReadReg8( REG0202_RESIZE );
	globalResize &= ~0x04;
	globalResize |= fEnable ? 0x04 : 0x00;
	halWriteReg8( REG0202_RESIZE, globalResize );
	return TRUE;
}

//-----------------------------------------------------------------------------
//	prvGetResizeScaleMode - Retrieves Capture Scale Mode as degree of 
//								reduction
//
//	Input:	n/a
//
//	Output:	View resize Scale mode
//
//-----------------------------------------------------------------------------
UInt8 prvGetResizeScaleMode( void )
{
	return ( halReadReg8(REG0210_RESIZEOP) & 0x3 );
}

//-----------------------------------------------------------------------------
//	prvSetResizeScaleMode - sets Resize Scale Mode
//
//	Input:	scaleMode	resize Scale mode
//			pJpegInfo	pointer to JPEGINFO object
//
//	Output:	TRUE means success
//			FALSE means not success
//
//-----------------------------------------------------------------------------
Boolean prvSetResizeScaleMode( UInt8 scaleMode, JPEGINFO* pJpegInfo )
{
	Boolean fSuccess = (scaleMode <= 3) ? TRUE : FALSE;
	if ( !fSuccess )
		jpegSetLastError( JPEG_ERR_INVALID_PARAM );
	else
		halWriteReg8( REG0210_RESIZEOP, (UInt8)((halReadReg8(REG0210_RESIZEOP) & 0xFC) | scaleMode) );
	return ( fSuccess );
}

//-----------------------------------------------------------------------------
//	prvResetResize - resets software for resize
//
//	Input:	fEnable		as software reset enable or not enable
//			pJpegInfo	pointer to JPEGINFO object
//
//	Output:	TRUE means success
//			FALSE means not success
//
//-----------------------------------------------------------------------------
Boolean prvResetResize( Boolean fEnable, JPEGINFO* pJpegInfo )
{
	UInt8	resize = halReadReg8( REG0202_RESIZE );
	//76543210b
	//|||||||+--Resize Enable
	//||||||+---Resize Register Update VSYNC Enable
	//|||||+----Resize Independent Horizontal/Vertical Scale Enable
	//+++++-----n/a
	resize		&= (~0x80);
	resize		|= fEnable ? 0x80 : 0x00;
	halWriteReg8( REG0202_RESIZE, resize );
	return TRUE;
}

//-----------------------------------------------------------------------------
//	prvGetResizeVScaleRate - retrieves vertical resize Scale mode
//
//	Input:	n/a
//
//	Output:	vertical resize Scale rate
//
//-----------------------------------------------------------------------------
UInt8 prvGetResizeVScaleRate( void )
{
	// Assume no Scale rate
	UInt8 scaleRate = 1;
	UInt8 scaleMode = prvGetResizeScaleMode();
	switch( scaleMode )
	{
	case 1:
	case 2:
		{
			Boolean fIndScaleRate = prvGetResizeIndScaleRate();
			if ( fIndScaleRate )
			{
				scaleRate = halReadReg8( REG020E_RESIZEVSCALE );
			}
			else
			{
				scaleRate = prvGetResizeHScaleRate();
			}
		}
		break;

	default:
		break;
	}
	return ( scaleRate );
}

//-----------------------------------------------------------------------------
//	prvSetResizeVScaleRate - sets view resizer Scale rate
//
//	Input:	scaleRate
//			pJpegInfo			pointer to JPEGINFO object
//
//	Output:	TRUE means success
//			FALSE means not success
//
//-----------------------------------------------------------------------------
Boolean prvSetResizeVScaleRate( UInt8 scaleRate, JPEGINFO* pJpegInfo )
{
	Boolean fSuccess = (scaleRate <= 32) ? TRUE : FALSE;
	if ( !fSuccess )
		jpegSetLastError( JPEG_ERR_INVALID_PARAM );
	else
		halWriteReg8( REG020E_RESIZEVSCALE, scaleRate );

	return ( fSuccess );
}

//-----------------------------------------------------------------------------
//	prvGetResizeRect - acquires rectangle parameters
//
//	Input:	pXStart
//			pYStart
//			pXEnd
//			pYEnd
//
//	Output:	n/a
//
//-----------------------------------------------------------------------------
void prvGetResizeRect( UInt16* pXStart, UInt16* pYStart, UInt16* pXEnd, UInt16* pYEnd )
{
	*pXStart	= prvHalReadReg16( REG0204_RESIZESX0, REG0205_RESIZESX1 );
	*pYStart	= prvHalReadReg16( REG0206_RESIZESY0, REG0207_RESIZESY1 );
	*pXEnd		= prvHalReadReg16( REG0208_RESIZEEX0, REG0209_RESIZEEX1 );
	*pYEnd		= prvHalReadReg16( REG020A_RESIZEEY0, REG020B_RESIZEEY1 );
}

//-----------------------------------------------------------------------------
//	prvSetResizeRect - acquires rectangle parameters
//
//	Input:	XStart
//			YStart
//			XEnd
//			YEnd
//			pJpegInfo		pointer to JPEGINFO object
//
//	Output:	TRUE means success
//			FALSE means not success
//
//-----------------------------------------------------------------------------
Boolean prvSetResizeRect( UInt16 XStart, UInt16 YStart, UInt16 XEnd, UInt16 YEnd  )
{
	Boolean fSuccess = prvSetResizePos( XStart, REG0204_RESIZESX0, REG0205_RESIZESX1, 10 );
	if ( fSuccess )
	{
		fSuccess = prvSetResizePos( YStart, REG0206_RESIZESY0, REG0207_RESIZESY1, 9 );
		if ( fSuccess )
		{
			fSuccess = prvSetResizePos( XEnd, REG0208_RESIZEEX0, REG0209_RESIZEEX1, 10 );
			if ( fSuccess )
			{
				fSuccess = prvSetResizePos( YEnd, REG020A_RESIZEEY0, REG020B_RESIZEEY1, 9 );
			}
		}
	}
	return ( fSuccess );
}

//-----------------------------------------------------------------------------
//	prvSetResizePos - sets resize register
//
//	Input:	pos				start x position for resize
//			index1
//			index2
//			pJpegInfo		pointer to JPEGINFO object
//			bits
//
//	Output:	TRUE means success
//			FALSE means not success
//
//-----------------------------------------------------------------------------
Boolean prvSetResizePos( UInt16 pos, UInt16 index1, UInt16 index2, int bits )
{
	UInt16	max			= bits==9 ? 0x1FF : 0x3FF;
	Boolean fSuccess	= (pos <= max) ? TRUE : FALSE;
	if ( !fSuccess )
	{
		jpegSetLastError( JPEG_ERR_DIM_RESTRICT );
	}
	else
	{
		UInt8 lsb = (UInt8)(pos & 0x00FF);
		UInt8 msb = (UInt8)(pos >> 8);
		halWriteReg8( index1, lsb );
		halWriteReg8( index2, msb );
	}
	return ( fSuccess );
}

⌨️ 快捷键说明

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