Image *CreateI420Image() { PlanarYCbCrImage *image = new RecyclingPlanarYCbCrImage(new BufferRecycleBin()); PlanarYCbCrData data; data.mPicSize = mImageSize; const uint32_t yPlaneSize = mImageSize.width * mImageSize.height; const uint32_t halfWidth = (mImageSize.width + 1) / 2; const uint32_t halfHeight = (mImageSize.height + 1) / 2; const uint32_t uvPlaneSize = halfWidth * halfHeight; // Y plane. uint8_t *y = mSourceBuffer.Elements(); data.mYChannel = y; data.mYSize.width = mImageSize.width; data.mYSize.height = mImageSize.height; data.mYStride = mImageSize.width; data.mYSkip = 0; // Cr plane. uint8_t *cr = y + yPlaneSize + uvPlaneSize; data.mCrChannel = cr; data.mCrSkip = 0; // Cb plane uint8_t *cb = y + yPlaneSize; data.mCbChannel = cb; data.mCbSkip = 0; // CrCb plane vectors. data.mCbCrStride = halfWidth; data.mCbCrSize.width = halfWidth; data.mCbCrSize.height = halfHeight; image->CopyData(data); return image; }