如果没有对齐,底边有时颜色会有点问题(比如绿色)。
所以专门写了代码进行对齐。
#define NV12_PACK 2 //如果没有对齐,NV12无法生成JPG,或者底边颜色异常。对齐时要避免剪切区域变小。 int clipNv12Pack(int* pnClipLeft, int* pnClipTop, int* pnClipWidth, int* pnClipHeight) { const int clipLeft = *pnClipLeft; const int clipTop = *pnClipTop; const int clipWidth = *pnClipWidth; const int clipHeight= *pnClipHeight; if (*pnClipLeft % NV12_PACK != 0) { *pnClipLeft = clipLeft/NV12_PACK*NV12_PACK; *pnClipWidth = clipWidth+(clipLeft-*pnClipLeft); } *pnClipWidth = (*pnClipWidth+NV12_PACK-1)/NV12_PACK*NV12_PACK; if (*pnClipTop % NV12_PACK != 0) { *pnClipTop = clipTop/NV12_PACK*NV12_PACK; *pnClipHeight= clipHeight+(clipTop-*pnClipTop); } *pnClipHeight = (*pnClipHeight+NV12_PACK-1)/NV12_PACK*NV12_PACK; return 0; }