📄 jpeg_mjpeg_yuvitu.c
字号:
For YUV420 to ITU656 Conversion:
Source -> YUV420, Destination -> ITU656 frame
uses 6 descriptors: 1st half of Y -> ITU656 field 1
U -> ITU656 field 1
V -> ITU656 field 1
2nd half of Y -> ITU656 field 2
U -> ITU656 field 2
V -> ITU656 field 2
*********************************************************************/
section("sdram0_bank1_cache")
void SetupMDMA_YUV420toITU656 (void)
{
u8 i; // index
u32 WidthOffset,HeightOffset; // Display offsets
u32 DisplayWidth; // Image Width to be displayed
u32 DisplayHeight; // Image Height to be displayed
// prepare MDMA for relevant YUV to ITU656 conversion
// complete descriptor setup with the "variable" parts that we now have after decoding the image
// Calculate Output image width & height. Maximum size can be ITU656 frame resolution
// calculate maximum Output display width and Offset to center in output display
if (JPEGImageWidth > ITU_PIXEL_PER_LINE)
{
DisplayWidth = ITU_PIXEL_PER_LINE;
WidthOffset = 0; // no width offset necessary for maximum resolution
}
else
{
DisplayWidth = JPEGImageWidth;
// Width offset = Number of pixels(Y) to skip per line
WidthOffset = (ITU_PIXEL_PER_LINE - DisplayWidth);
}
// calculate maximum Output display height and Offset to center in output display
if (JPEGImageHeight > ActiveFrameLines)
{
DisplayHeight = ActiveFrameLines;
HeightOffset = 0; // no height offset necessary for maximum resolution
}
else
{
DisplayHeight = JPEGImageHeight;
// Height offset = Number of active lines (data size in bytes) to skip
HeightOffset = (((ActiveFrameLines - DisplayHeight)/4) * DataPerLine);
}
// set XModify for all YUV420 to ITU656 conversion descriptors
for(i=0; i<6; i++)
{
SrcDescriptor[i].Large.XModify = sizeof(char); // 1 byte increment for YUV420 buffer read
DestDescriptor[i].Large.XModify = sizeof(int); // ITU656 Chroma stride should be 4 bytes
}
// XModify for ITU656 frame luma (luma stride should be only 2 bytes)
DestDescriptor[0].Large.XModify = sizeof(short);
DestDescriptor[3].Large.XModify = sizeof(short);
// setup 1st half of YUV source descriptor chain (MDMA)
// source Y 1st half
SrcDescriptor[0].Large.XCount = DisplayWidth;
SrcDescriptor[0].Large.YCount = DisplayHeight/2;
SrcDescriptor[0].Large.YModify = JPEGImageWidth + (JPEGImageWidth - DisplayWidth) + SrcDescriptor[0].Large.XModify;
// destination Y 1st half
DestDescriptor[0].Large.XCount = DisplayWidth;
DestDescriptor[0].Large.YCount = DisplayHeight/2;
DestDescriptor[0].Large.YModify = (WidthOffset*2) + ActiveVideoSkip + DestDescriptor[0].Large.XModify; // twice width offset to account for U/V data
// source U 1st half
SrcDescriptor[1].Large.XCount = DisplayWidth/2;
SrcDescriptor[1].Large.YCount = DisplayHeight/2;
SrcDescriptor[1].Large.YModify = (JPEGImageWidth - DisplayWidth)/2 + SrcDescriptor[1].Large.XModify;
// destination U 1st half
DestDescriptor[1].Large.XCount = DisplayWidth/2;
DestDescriptor[1].Large.YCount = DisplayHeight/2;
DestDescriptor[1].Large.YModify = (WidthOffset*2) + ActiveVideoSkip + DestDescriptor[1].Large.XModify; // twice width offset to account for U/V data
// source V 1st half
SrcDescriptor[2].Large.XCount = DisplayWidth/2;
SrcDescriptor[2].Large.YCount = DisplayHeight/2;
SrcDescriptor[2].Large.YModify = (JPEGImageWidth - DisplayWidth)/2 + SrcDescriptor[2].Large.XModify;
// destination V 1st half
DestDescriptor[2].Large.XCount = DisplayWidth/2;
DestDescriptor[2].Large.YCount = DisplayHeight/2;
DestDescriptor[2].Large.YModify = (WidthOffset*2) + ActiveVideoSkip + DestDescriptor[2].Large.XModify; // twice width offset to account for U/V data
// setup 2nd half of YUV source descriptor chain (MDMA)
// source Y 2nd half
SrcDescriptor[3].Large.XCount = DisplayWidth;
SrcDescriptor[3].Large.YCount = DisplayHeight/2;
SrcDescriptor[3].Large.YModify = JPEGImageWidth + (JPEGImageWidth - DisplayWidth) + SrcDescriptor[3].Large.XModify;
// destination Y 2nd half
DestDescriptor[3].Large.XCount = DisplayWidth;
DestDescriptor[3].Large.YCount = DisplayHeight/2;
DestDescriptor[3].Large.YModify = (WidthOffset*2) + ActiveVideoSkip + DestDescriptor[3].Large.XModify; // twice width offset to account for U/V data
// source U 2nd half
SrcDescriptor[4].Large.XCount = DisplayWidth/2;
SrcDescriptor[4].Large.YCount = DisplayHeight/2;
SrcDescriptor[4].Large.YModify = (JPEGImageWidth - DisplayWidth)/2 + SrcDescriptor[4].Large.XModify;
// destination U 2nd half
DestDescriptor[4].Large.XCount = DisplayWidth/2;
DestDescriptor[4].Large.YCount = DisplayHeight/2;
DestDescriptor[4].Large.YModify = (WidthOffset*2) + ActiveVideoSkip + DestDescriptor[4].Large.XModify; // twice width offset to account for U/V data
// source V 2nd half
SrcDescriptor[5].Large.XCount = DisplayWidth/2;
SrcDescriptor[5].Large.YCount = DisplayHeight/2;
SrcDescriptor[5].Large.YModify = (JPEGImageWidth - DisplayWidth)/2 + SrcDescriptor[5].Large.XModify;
// destination V 2nd half
DestDescriptor[5].Large.XCount = DisplayWidth/2;
DestDescriptor[5].Large.YCount = DisplayHeight/2;
DestDescriptor[5].Large.YModify = (WidthOffset*2) + ActiveVideoSkip + DestDescriptor[5].Large.XModify; // twice width offset to account for U/V data
// Enable callback flag for last Destination descriptor
DestDescriptor[5].Large.CallbackFlag = TRUE;
// Constants to update descriptor chain start addresses
// Source - YUV Buffers
// to reach source Y 1st half
SrcDescAddrUpdate[0] = 0;
// to reach source U 1st half
SrcDescAddrUpdate[1] = (JPEGImageWidth*JPEGImageHeight);
// to reach source V 1st half
SrcDescAddrUpdate[2] = (JPEGImageWidth*JPEGImageHeight*5/4);
// to reach source Y 2nd half
SrcDescAddrUpdate[3] = JPEGImageWidth;
// to reach source U 2nd half (same address as 1st half U)
SrcDescAddrUpdate[4] = (JPEGImageWidth*JPEGImageHeight);
// to reach source V 2nd half (same address as 1st half V)
SrcDescAddrUpdate[5] = (JPEGImageWidth*JPEGImageHeight*5/4);
// Destination - ITU656 buffers
// to reach destination Y 1st half
DestDescAddrUpdate[0] = (Field1Skip + ActiveVideoSkip + ITU_Y_OFFSET + WidthOffset + HeightOffset);
// to reach destination U 1st half
DestDescAddrUpdate[1] = (Field1Skip + ActiveVideoSkip + ITU_U_OFFSET + WidthOffset + HeightOffset);
// to reach destination V 1st half
DestDescAddrUpdate[2] = (Field1Skip + ActiveVideoSkip + ITU_V_OFFSET + WidthOffset + HeightOffset);
// to reach destination Y 2nd half
DestDescAddrUpdate[3] = (Field2Skip + ActiveVideoSkip + ITU_Y_OFFSET + WidthOffset + HeightOffset);
// to reach destination U 2nd half
DestDescAddrUpdate[4] = (Field2Skip + ActiveVideoSkip + ITU_U_OFFSET + WidthOffset + HeightOffset);
// to reach destination V 2nd half
DestDescAddrUpdate[5] = (Field2Skip + ActiveVideoSkip + ITU_V_OFFSET + WidthOffset + HeightOffset);
// Finally, update MDMA descriptor addresses
Update_MDMA_DescAddr ();
return;
}
/*********************************************************************
Function: SetupMDMA_ITU656toYUV420
Description: Configures MDMA Descriptors for ITU656 frame to
YUV420 conversion
For ITU656 to YUV420 Conversion:
Source -> ITU656 frame, Destination -> YUV420
uses 4 descriptors: ITU656 field 1 -> 1st half of Y
ITU656 field 1 -> U
ITU656 field 1 -> V
ITU656 field 2 -> 2nd half of Y
*********************************************************************/
section("sdram0_bank1_cache")
void SetupMDMA_ITU656toYUV420 (void)
{
u8 i; // index
u32 WidthOffset,HeightOffset; // Display offsets
// prepare MDMA for relevant YUV to ITU656 conversion
// complete descriptor setup with the "variable" parts that we now have after decoding the image
// calculate Offset to center in output display
if (JPEGImageWidth > ITU_PIXEL_PER_LINE)
WidthOffset = 0; // no width offset necessary for maximum resolution
else
// Width offset = Number of pixels(Y) to skip per line
WidthOffset = (ITU_PIXEL_PER_LINE - JPEGImageWidth);
// calculate Offset to center in output display
if (JPEGImageHeight > ActiveFrameLines)
HeightOffset = 0; // no height offset necessary for maximum resolution
else
// Height offset = Number of active lines (data size in bytes) to skip
HeightOffset = (((ActiveFrameLines - JPEGImageHeight)/4) * DataPerLine);
// set XModify for all ITU656 to YUV420 conversion descriptors
for(i=0; i<4; i++)
{
SrcDescriptor[i].Large.XModify = sizeof(int); // ITU656 Chroma stride should be 4 bytes
DestDescriptor[i].Large.XModify = sizeof(char); // 1 byte increment for YUV420 buffer read
}
// XModify for ITU656 frame luma (luma stride should be only 2 bytes)
SrcDescriptor[0].Large.XModify = sizeof(short);
SrcDescriptor[3].Large.XModify = sizeof(short);
// source Y 1st half from ITU656 (YUV422) buffer
SrcDescriptor[0].Large.XCount = JPEGImageWidth;
SrcDescriptor[0].Large.YCount = JPEGImageHeight/2;
SrcDescriptor[0].Large.YModify = ActiveVideoSkip + ((ITU_PIXEL_PER_LINE - JPEGImageWidth)*2) + SrcDescriptor[0].Large.XModify;
// destination Y 1st half to YUV420 buffer
DestDescriptor[0].Large.XCount = JPEGImageWidth;
DestDescriptor[0].Large.YCount = JPEGImageHeight/2;
DestDescriptor[0].Large.YModify = JPEGImageWidth + DestDescriptor[0].Large.XModify ;
// source U 1st half from ITU656 (YUV422) buffer
SrcDescriptor[1].Large.XCount = JPEGImageWidth/2;
SrcDescriptor[1].Large.YCount = JPEGImageHeight/2;
SrcDescriptor[1].Large.YModify = ActiveVideoSkip + ((ITU_PIXEL_PER_LINE - JPEGImageWidth)*2) + SrcDescriptor[1].Large.XModify;
// destination U to YUV420 buffer
DestDescriptor[1].Large.XCount = JPEGImageWidth/2;
DestDescriptor[1].Large.YCount = JPEGImageHeight/2;
DestDescriptor[1].Large.YModify = DestDescriptor[1].Large.XModify;
// source V 1st half from ITU656 (YUV422) buffer
SrcDescriptor[2].Large.XCount = JPEGImageWidth/2;
SrcDescriptor[2].Large.YCount = JPEGImageHeight/2;
SrcDescriptor[2].Large.YModify = ActiveVideoSkip + ((ITU_PIXEL_PER_LINE - JPEGImageWidth)*2) + SrcDescriptor[2].Large.XModify;
// destination V to YUV420 buffer
DestDescriptor[2].Large.XCount = JPEGImageWidth/2;
DestDescriptor[2].Large.YCount = JPEGImageHeight/2;
DestDescriptor[2].Large.YModify = DestDescriptor[2].Large.XModify;
// source Y 2nd half from ITU656 (YUV422) buffer
SrcDescriptor[3].Large.XCount = JPEGImageWidth;
SrcDescriptor[3].Large.YCount = JPEGImageHeight/2;
SrcDescriptor[3].Large.YModify = ActiveVideoSkip + ((ITU_PIXEL_PER_LINE - JPEGImageWidth)*2) + SrcDescriptor[3].Large.XModify;
// destination Y 2nd half to YUV420 buffer
DestDescriptor[3].Large.XCount = JPEGImageWidth;
DestDescriptor[3].Large.YCount = JPEGImageHeight/2;
DestDescriptor[3].Large.YModify = JPEGImageWidth + DestDescriptor[3].Large.XModify ;
// Enable callback flag for last Destination descriptor
DestDescriptor[3].Large.CallbackFlag = TRUE;
// Constants to update descriptor chain start addresses
// Source - video (ITU656) Buffers
// to reach source Y 1st half
SrcDescAddrUpdate[0] = (Field1Skip + ActiveVideoSkip + ITU_Y_OFFSET + WidthOffset + HeightOffset);
// to reach source U 1st half
SrcDescAddrUpdate[1] = (Field1Skip + ActiveVideoSkip + ITU_U_OFFSET + WidthOffset + HeightOffset);
// to reach source V 1st half
SrcDescAddrUpdate[2] = (Field1Skip + ActiveVideoSkip + ITU_V_OFFSET + WidthOffset + HeightOffset);
// to reach source Y 2nd half
SrcDescAddrUpdate[3] = (Field2Skip + ActiveVideoSkip + ITU_Y_OFFSET + WidthOffset + HeightOffset);
// ITU656 to YUV420 conversion only needs chain of 4 descriptors
SrcDescAddrUpdate[4] = 0;
SrcDescAddrUpdate[5] = 0;
// Destination - YUV buffers
// to reach destination Y 1st half
DestDescAddrUpdate[0] = 0;
// to reach destination U
DestDescAddrUpdate[1] = (JPEGImageWidth*JPEGImageHeight);
// to reach destination V
DestDescAddrUpdate[2] = (JPEGImageWidth*JPEGImageHeight*5/4);
// to reach destination Y 2nd half
DestDescAddrUpdate[3] = JPEGImageWidth;
// ITU656 to YUV420 conversion only needs chain of 4 descriptors
DestDescAddrUpdate[4] = 0;
DestDescAddrUpdate[5] = 0;
// Create the termination descriptor for the list
SrcDescriptor [3].Large.pNext = NULL;
DestDescriptor[3].Large.pNext = NULL;
SrcDescriptor [4].Large.pNext = NULL;
DestDescriptor[4].Large.pNext = NULL;
// Finally, update MDMA descriptor addresses
Update_MDMA_DescAddr ();
return;
}
/*****/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -