jpegcomm.c
来自「是一个手机功能的模拟程序」· C语言 代码 · 共 969 行 · 第 1/3 页
C
969 行
// Restore original settings
pJpegInfo->m_pBuf = pBuf;
pJpegInfo->m_EncSize = encSize;
}
return ( fSuccess );
}
//-----------------------------------------------------------------------------
// jpegWriteFile - writes JPEG encoded data to given file
// if R180 flag is set, we have to process and re-write the JPEG file.
//
// Input: pJpegInfo pointer to JPEGINFO structure
//
// Output: TRUE if data successfully written to file
// FALSE if data NOT successfully written to file
//
//-----------------------------------------------------------------------------
Boolean jpegWriteFile( JPEGINFO* pJpegInfo )
{
FILE* pStream;
Boolean fSuccess = mfCreateFile( pJpegInfo->m_pszFile, &pStream );
if ( fSuccess )
{
//printf( "Writing %s\n", pJpegInfo->m_pszFile );
fSuccess = mfWriteFile( pJpegInfo->m_pszFile, pStream, pJpegInfo->m_pBuf, pJpegInfo->m_EncSize );
fclose( pStream );
}
return ( fSuccess );
}
#endif
//-----------------------------------------------------------------------------
// jpegGetYUVFmt - get YUV Format Select
//
// Input: n/a
//
// Output: yuvFmt
//
//-----------------------------------------------------------------------------
jpegYUVFmt jpegGetYUVFmt( void )
{
UInt8 operationModeSetting = halReadReg8( REG1000_OPMODE );
//76543210
//||||||++--YUV Format Select
//|||||+----JPEG Operation Select
//||||+-----Marker Insert Enable
//|||+------DNL Insert Enable
//+++-------n/a
jpegYUVFmt yuvFmt = (jpegYUVFmt)(operationModeSetting & 0x03);
return ( yuvFmt );
}
//-----------------------------------------------------------------------------
// jpegYUVValue2Fmt - process function to interpret digits as enumerated constants
//
// Input: value to process
//
// Output: processed value
//
//-----------------------------------------------------------------------------
int jpegYUVValue2Fmt( int value )
{
int yuvFmt;
switch( value )
{
case 444:
yuvFmt = YUVFmt444;
break;
case 422:
default:
yuvFmt = YUVFmt422;
break;
case 420:
yuvFmt = YUVFmt420;
break;
case 411:
yuvFmt = YUVFmt411;
break;
}
return ( yuvFmt );
}
//-----------------------------------------------------------------------------
// prvGetCamClk - determines status of camera clock output
//
// Input: n/a
//
// Output: TRUE means clock output is enabled
// FALSE means clock output is disabled after 1 frame period finished.
//
//-----------------------------------------------------------------------------
Boolean prvGetCamClk( void )
{
UInt8 camModeSetting = halReadReg8( REG0104_CMMODE0 );
//76543210b
//|||||||+--CMCLK Output Enable
//||||||+---Camera Active Pulldown Enable
//|||||+----ITU-R BT656 Enable
//||||+-----ITU-R BT656 Interrupt Enable
//++++------n/a
Boolean fCamClk = (camModeSetting & 1) ? TRUE : FALSE;
return ( fCamClk );
}
//-----------------------------------------------------------------------------
// prvSetCamClk - sets status of camera clock output
//
// Input: fclkOut TRUE means Clk Out End
// FALSE means clock output is disabled after 1 frame period
// finished
//
// Output: n/a
//
//-----------------------------------------------------------------------------
void prvSetCamClk( Boolean fClkOut )
{
UInt8 camModeSetting = halReadReg8( REG0104_CMMODE0 );
//76543210b
//|||||||+--CMCLK Output Enable
//||||||+---Camera Active Pulldown Enable
//|||||+----ITU-R BT656 Enable
//||||+-----ITU-R BT656 Interrupt Enable
//++++------n/a
Boolean fPrevClk = (camModeSetting & 1) ? TRUE : FALSE;
camModeSetting &= (~1);
camModeSetting |= fClkOut ? 0x01 : 0x00;
halWriteReg8( REG0104_CMMODE0, camModeSetting );
if ( fClkOut != fPrevClk )
{
halDelayUS( 70 * 1000 );
}
}
//-----------------------------------------------------------------------------
// prvExitSequence - clean up after all JPEG encoding is complete
//
// Input: success current state of process
// fDecode flag to determine if decode shutdown required
//
// Output: true means success
// false means NOT success
//
//-----------------------------------------------------------------------------
Boolean prvExitSequence( Boolean fSuccess, Boolean fDecode )
{
// Check the JPEG operation Status
Boolean fComplete = prvGetOpWork() ? FALSE : TRUE;
if ( fSuccess )
{
fSuccess = fComplete;
if ( !fSuccess )
{
jpegSetLastError( JPEG_ERR_INCOMPLETE );
}
else
{
if ( fDecode )
{
switch ( (halReadReg8( REG101E_RSTOPSTATUS ) >> 3) & 0x0F )
{
default:
break;
case 0x0B:
jpegSetLastError( JPEG_ERR_RESTART_INTERVAL );
fSuccess = FALSE;
break;
case 0x0C:
jpegSetLastError( JPEG_ERR_IMAGE_SIZE );
fSuccess = FALSE;
break;
}
}
}
}
// Disable all interrupts
prvSetIrqControl( IrqDisable );
// Clear all status bits
prvSetJpegStatus( IrqDisable );
// Stop capturing
halReadReg8( REG1004_JPEGOP ); // Must be read before writing to REG[0810h].
halWriteReg8( REG0810_JPEGSTARTSTOP, 0x00 );
// Software reset the JPEG codec
prvResetJpegCodec( );
// Perform a JPEG Software Reset
prvSetJpeg( TRUE, TRUE );
// Disable the JPEG codec
prvSetJpeg( FALSE, FALSE );
return ( fSuccess );
}
//-----------------------------------------------------------------------------
// prvHalReadReg16 - retrieves 2 8-bt registers as a 16-bit value
//
// Input: lsbIndex LSB index to read
// msbIndex MSB index to read
//
// Output: 16-bit value read
//
//-----------------------------------------------------------------------------
UInt16 prvHalReadReg16( UInt16 lsbIndex, UInt16 msbIndex )
{
UInt8 lsb = halReadReg8( lsbIndex );
UInt8 msb = halReadReg8( msbIndex );
UInt16 value = (UInt16)((msb << 8) + lsb);
return ( value );
}
//-----------------------------------------------------------------------------
// prvHalReadReg24 - retrieves 3 consecutive 8-bit registers as 24-bit value
//
// Input: index starting index to read
//
// Output: 32-bit value read
//
//-----------------------------------------------------------------------------
UInt32 prvHalReadReg24( UInt16 index )
{
UInt8 lsb = halReadReg8( index + 0 );
UInt8 ob = halReadReg8( index + 1 );
UInt8 msb = halReadReg8( index + 2 );
UInt32 value = (UInt32)((msb << 16) + (ob << 8) + lsb);
return ( value );
}
//-----------------------------------------------------------------------------
// prvHalWriteReg16 - writes 2 8-bt registers by separating 16-bit value
//
// Input: lsbIndex LSB index to write
// msbIndex MSB index to write
// value 16-bit value written
//
// Output: 16-bit value read
//
//-----------------------------------------------------------------------------
void prvHalWriteReg16( UInt16 lsbIndex, UInt16 msbIndex, UInt16 value )
{
UInt8 lsb = (UInt8)(value & 0x00FF);
UInt8 msb = (UInt8)((value >> 8) & 0x00FF);
halWriteReg8( lsbIndex, lsb );
halWriteReg8( msbIndex, msb );
}
//-----------------------------------------------------------------------------
// prvHalWriteReg24 - writes 3 consecutive 8-bit registers by separating a
// 32-bit value
//
// Input: index starting index to write
// value 32-bit value
//
// Output: 32-bit value read
//
//-----------------------------------------------------------------------------
void prvHalWriteReg24( UInt16 index, UInt32 value )
{
UInt8 lsb = (UInt8)(value & 0x00FF);
UInt8 ob = (UInt8)((value >> 8) & 0x00FF);
UInt8 msb = (UInt8)((value >> 16) & 0x00FF);
halWriteReg8( index + 0, lsb );
halWriteReg8( index + 1, ob );
halWriteReg8( index + 2, msb );
}
//------------------------------------------------------------------------------
// prvGetIrqControl
//
// Input: n/a
//
// Return: prvJpegFlag
//
//------------------------------------------------------------------------------
prvJpegFlag prvGetIrqControl( void )
{
return ( prvHalReadReg16( REG080A_JPEGIRQ0, REG080C_JPEGIRQ1 ) );
//FEDBCA9876543210b
//|||||||||||||||+--Reserved JPEG Line Buffer Interrupt Enable
//||||||||||||||+---JPEG Codec Interrupt Enable
//|||||||||||||+----Line Buffer Overflow Interrupt Enable
//||||||||||||+-----n/a
//|||||||||||+------Decode Marker Read Interrupt Enable
//||||||||||+-------JPEG Decode Complete Interrupt Enable
//||||||||++--------n/a
//|||||||+----------JPEG Encode Overflow Interrupt Enable
//|||||++-----------n/a
//||||+-------------Encode Size Limit Over Interrupt Enable
//++++--------------n/a
}
//------------------------------------------------------------------------------
// prvSetIrqControl
//
// Input: flag flag to set
//
// Return: n/a
//
//------------------------------------------------------------------------------
void prvSetIrqControl( prvJpegFlag flag )
{
prvHalWriteReg16( REG080A_JPEGIRQ0, REG080C_JPEGIRQ1, (UInt16)flag );
//FEDBCA9876543210b
//|||||||||||||||+--Reserved JPEG Line Buffer Interrupt Enable
//||||||||||||||+---JPEG Codec Interrupt Enable
//|||||||||||||+----Line Buffer Overflow Interrupt Enable
//||||||||||||+-----n/a
//|||||||||||+------Decode Marker Read Interrupt Enable
//||||||||||+-------JPEG Decode Complete Interrupt Enable
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?