[bash]bool Encode(const CVideoFrameIf& aSource, CVideoFrameIf& aDestination)
{
const int nOfComponents = 3;
// Prepares source image
Image srcImage;
ImageDataPtr srcDataPtr;
ImageDataOrder srcDataOrder;
ImageSamplingGeometry srcGeometry;
unsigned long srcWidth = aSource.GetWidth();
unsigned long srcHeight = aSource.GetHeight();
Rect srcRect(Point(0, 0), RectSize(srcWidth, srcHeight));
srcDataPtr.p8u = aSource.GetData();
srcDataOrder.ReAlloc(Interleaved, nOfComponents);
srcDataOrder.SetDataType(T8u);
srcDataOrder.PixelStep()[0] = nOfComponents;
srcDataOrder.LineStep() [0] = 2 * aSource.GetWidth(); // Y + U/2 + V/2
srcGeometry.ReAlloc(nOfComponents);
srcGeometry.SetEnumSampling(S422);
srcGeometry.SetRefGridRect(srcRect);
srcImage.ColorSpec().ReAlloc(nOfComponents);
srcImage.ColorSpec().SetComponentToColorMap(Direct);
srcImage.ColorSpec().SetColorSpecMethod(Enumerated);
srcImage.ColorSpec().SetEnumColorSpace(YCbCr);
for(int i = 0; i < nOfComponents; i++)
{
srcImage.ColorSpec().DataRange().SetAsRange8u(IPP_MAX_8U);
}
if( UIC::ExcStatusOk != srcImage.Buffer().Attach(&srcDataPtr, srcDataOrder, srcGeometry))
{
mLastError = "Could not attach data to image buffer";
return false;
}
if( UIC::ExcStatusOk != mEncoder.AttachImage(srcImage) )
{
mLastError = "Could not attach image to the encoder";
return false;
}
// Prepares destination image
CMemBuffOutput memBuf;
if( !BaseStream::IsOk( memBuf.Open(aDestination.GetData(), aDestination.GetFrameSize() ) ) )
{
mLastError = "Could not initialize memory buffer";
return false;
}
if( UIC::ExcStatusOk != mEncoder.AttachStream(memBuf) )
{
mLastError = "Could not attach stream";
return false;
}
// Adjusts encoder parameters
InputParams params;
Ipp16u tilesUniform[4] = {1, 1, 0, 0};
params.iQuality = GetQuality();
params.iOverlap = 0; // No Filter
params.iBands = 0; // All Bands
params.iSampling = 1; // 422
params.bAlphaPlane = 0; // No alpha plane
params.pTilesUniform = tilesUniform;
params.iTrim = 0;
params.iShift = 0;
params.bFrequency = 0;
params.bCMYKD = 0;
if( UIC::ExcStatusOk != mEncoder.SetParams(params) )
{
mLastError = "Could not set encoder parameters";
return false;
}
if( UIC::ExcStatusOk != mEncoder.WriteFileHeader(params.bAlphaPlane) )
{
mLastError = "Could not write file header";
return false;
}
if( UIC::ExcStatusOk != mEncoder.WriteHeader() )
{
mLastError = "Could not write image header";
return false;
}
if( UIC::ExcStatusOk != mEncoder.WriteData() )
{
mLastError = "Could not write data";
return false;
}
if( UIC::ExcStatusOk != mEncoder.FreeData() )
{
mLastError = "Could not free data";
return false;
}
}[/bash]
Link Copied
For more complete information about compiler optimizations, see our Optimization Notice.