// YV12 To NV21
private void YV12toNV21(final byte[] input, final byte[] output, final int width, final int height) {
long startMs = System.currentTimeMillis();
final int frameSize = width * height;
final int qFrameSize = frameSize / 4;
final int tempFrameSize = frameSize * 5 / 4;
System.arraycopy(input, 0, output, 0, frameSize); // Y
for (int i = 0; i < qFrameSize; i++) {
output[frameSize + i * 2] = input[frameSize + i]; // Cb (U)
output[frameSize + i * 2 + 1] = input[tempFrameSize + i]; // Cr (V)
}
}
//I420 To NV21
private void I420ToNV21(final byte[] input, final byte[] output, final int width, final int height) {
//long startMs = System.currentTimeMillis();
final int frameSize = width * height;
final int qFrameSize = frameSize / 4;
final int tempFrameSize = frameSize * 5 / 4;
System.arraycopy(input, 0, output, 0, frameSize); // Y
for (int i = 0; i < qFrameSize; i++) {
output[frameSize + i * 2] = input[tempFrameSize + i]; // Cb (U)
output[frameSize + i * 2 + 1] = input[frameSize + i]; // Cr (V)
}
}
//YV12Resize
private void YV12Resize(byte[] pSrc,Point szSrc,byte[] pDst,Point szDst){int srcPitchY=szSrc.x,srcPitchUV=szSrc.x/2,dstPitchY=szDst.x,dstPitchUV=szDst.x/2;int rateX=(szSrc.x<<16)/szDst.x;int rateY=(szSrc.y<<16)/szDst.y;for (int i=0;i>16;for (int j=0;j>16;pDst[dstPitchY * i + j] = pSrc[srcY*srcPitchY + srcX];//*(pSrcYLine+srcX);}}for (int i=0;i>16;for (int j=0;j>16;
pDst[dstPitchY*szDst.y+i*dstPitchUV + j] = pSrc[srcPitchY*szSrc.y+srcY*srcPitchUV + srcX];//*(pSrcVLine+srcX);
pDst[dstPitchY*szDst.y+i*dstPitchUV + dstPitchUV*szDst.y/2 + j]= pSrc[srcPitchY*szSrc.y+srcY*srcPitchUV + srcPitchUV*szSrc.y/2 + srcX];
}
}
}
// eg.
private void test(){
byte[] resizeYV12 = new byte[destWidth * destHeight * 3 / 2];
Point pointSrc = new Point(mSize.width, mSize.height);
try {
YV12Resize(mData, pointSrc, resizeYV12, new Point(destWidth, destHeight));
} catch (Exception e) {
// TODO: handle exception
return null;
}
}