📄 jpegfielddec.c
字号:
///////////////////////////////////////////////////////////////////////////////
//
// JPEGFieldDec.c
//
// DESCRIPTION
// Decode one field of an JPEG frame.
//
//
//
///////////////////////////////////////////////////////////////////////////////
#include "JPEGFieldDec.h"
/////////////////////////////////////////////////////////////////////////////
// NAME
// JPEGFieldDecConfig
//
// DESCRIPTION
// Prepare the JPEGFieldDec structure which will be used in storing the
// decoded MCUs to the buffer for decoded image.
//
// INPUTS
// decodedImage - pointer to decoded image structure
// pFrameHeader - pointer to frame header structure
// sizex - width of field
// sizey - height of field
// interlaced - whether the image is interlaced
//
// OUTPUTS
// decodedImage - setup this structure
//
// RETURN VALUE
// Returns JPEG_OK if successful, returns an error code otherwise.
//
/////////////////////////////////////////////////////////////////////////////
int JPEGFieldDecConfig
(
JPEGFieldDec *decodedImage,
JPEGFrameHeader *pFrameHeader,
int sizex,
int sizey,
int interlaced
)
{
OP_UINT16 fieldWidth;
OP_UINT16 fieldHeight;
OP_UINT16 numx;
OP_UINT16 numy;
fieldWidth = pFrameHeader->frameWidth;
fieldHeight = pFrameHeader->frameHeight;
decodedImage->frmWidth = fieldWidth;
decodedImage->frmHeight = fieldHeight;
if (interlaced)
{
decodedImage->frmHeight <<= 1;
}
// decodedImage->frameTopDown = 0;
decodedImage->mcuSizeX = 8;
decodedImage->mcuSizeY = 8;
// assume integer number of MCUs
if (pFrameHeader->numComponents == 3)
{
switch (pFrameHeader->frameCompBlocks[0].sampFactor)
{
case 0x11:
decodedImage->jpegCSF = CSF_JPEG_YCBCR_444;
numx = fieldWidth >> 3;
if((fieldWidth & 0x0007) != 0)
{
numx++;
}
numy = fieldHeight >> 3;
if((fieldHeight & 0x0007) != 0)
{
numy++;
}
decodedImage->numMCUs = numx * numy;
decodedImage->mcuSizeX = 8;
decodedImage->mcuSizeY = 8;
break;
case 0x21:
decodedImage->jpegCSF = CSF_JPEG_YCBCR_422;
numx = fieldWidth >> 4;
if((fieldWidth & 0x000F) != 0)
{
numx++;
}
numy = fieldHeight >> 3;
if((fieldHeight & 0x0007) != 0)
{
numy++;
}
decodedImage->numMCUs = numx * numy;
decodedImage->mcuSizeX = 16;
decodedImage->mcuSizeY = 8;
break;
case 0x22:
decodedImage->jpegCSF = CSF_JPEG_YCBCR_420;
numx = fieldWidth >> 4;
if((fieldWidth & 0x000F) != 0)
{
numx++;
}
numy = fieldHeight >> 4;
if((fieldHeight & 0x000F) != 0)
{
numy++;
}
decodedImage->numMCUs = numx * numy;
decodedImage->mcuSizeX = 16;
decodedImage->mcuSizeY = 16;
break;
default:
return JPEG_ERR_FRAME_HEADER;
}
}
else
{
return JPEG_ERR_FRAME_HEADER;
}
// Application may supply the screen buffer as the destination buffer
// The screen buffer has a different width from the image width
decodedImage->frmBufWidth = sizex;
decodedImage->frmBufHeight = sizey;
decodedImage->frmRowWidth = fieldWidth;
switch (decodedImage->outputCSF)
{
case CSF_OUTPUT_RGB565:
case CSF_OUTPUT_RGB:
decodedImage->frmBufWidth *= (decodedImage->numBits) >> 3;
decodedImage->frmRowWidth *= (decodedImage->numBits) >> 3;
break;
default:
break;
}
// put into the buffer every other row
if (interlaced)
{
decodedImage->fieldRowDist = decodedImage->frmBufWidth << 1;
}
else
{
decodedImage->fieldRowDist = decodedImage->frmBufWidth;
}
// inversed
// if (decodedImage->frameTopDown == 0)
// decodedImage->fieldRowDist = - decodedImage->fieldRowDist;
// CSF_JPEG_YCBCR_420 will generate the data of 2 MCU rows
if (decodedImage->jpegCSF == CSF_JPEG_YCBCR_420)
{
decodedImage->mcuRowWidth = decodedImage->fieldRowDist << 4;
}
else
{
decodedImage->mcuRowWidth = decodedImage->fieldRowDist << 3;
}
return JPEG_OK;
}
/////////////////////////////////////////////////////////////////////////////
// NAME
// JPEGFieldDecInitialize
//
// DESCRIPTION
// Initialize the JPEGFieldDec structure, which helps save a decoded MCU
// to a buffer for the decoded image.
//
// INPUTS
// decodedImage - pointer to decoded image structure
// fieldIdx - index of the field
// outputBuffer - pointer to output frame buffer
// xDst - x location of the output image
// yDst - y location of the output image
//
// OUTPUTS
// decodedImage - setup this structure
//
// RETURN VALUE
// Always returns JPEG_OK
//
/////////////////////////////////////////////////////////////////////////////
int JPEGFieldDecInitialize
(
JPEGFieldDec *decodedImage,
int fieldIdx,
unsigned char *outputBuffer,
int xDst,
int yDst
)
{
// initialize parameters for simplifying storing the decoded data
// if (decodedImage->frameTopDown)
// {
// top down
decodedImage->mcuBufRow = outputBuffer;
// this is the second field
if (fieldIdx == 2)
{
decodedImage->mcuBufRow += decodedImage->frmBufWidth;
}
else
{
int vertOffset;
vertOffset = decodedImage->frmBufHeight - decodedImage->frmHeight - yDst;
// other formats, it is possible that buffer for video frame is
// only portion of the outputBuffer, consider the offset
decodedImage->mcuBufRow += xDst * (decodedImage->numBits >> 3) +
vertOffset * decodedImage->frmBufWidth;
}
// }
/* else
{
// bottom up
decodedImage->mcuBufRow = outputBuffer +
(decodedImage->frmBufHeight - yDst - 1) * decodedImage->frmBufWidth;
// this is the second field
if (fieldIdx == 2)
decodedImage->mcuBufRow -= decodedImage->frmBufWidth;
// these are the bitmap formats without hardware support
// we assume the buffer supplied will be the right size
decodedImage->mcuBufRow += xDst * (decodedImage->numBits >> 3);
} */
decodedImage->mcuBufRowEnd = decodedImage->mcuBufRow + decodedImage->frmRowWidth;
decodedImage->mcuBuf = decodedImage->mcuBufRow;
return JPEG_OK;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -