以下是YV12数据顺时针和逆时针旋转90度的方法:
private void rotateYv12Degree90(byte[] src, int width, int height, byte[] dst, boolean clockwise) {
int area = width * height;
if (clockwise) {
rotateRectClockwiseDegree90(src, 0, width, height, dst, 0);
rotateRectClockwiseDegree90(src, area, width / 2, height / 2, dst, area);
rotateRectClockwiseDegree90(src, area * 5 / 4, width / 2, height / 2, dst, area * 5 / 4);
} else {
rotateRectAnticlockwiseDegree90(src, 0, width, height, dst, 0);
rotateRectAnticlockwiseDegree90(src, area, width / 2, height / 2, dst, area);
rotateRectAnticlockwiseDegree90(src, area * 5 / 4, width / 2, height / 2, dst, area * 5 / 4);
}
}
private void rotateRectClockwiseDegree90(byte[] src, int srcOffset, int width, int height, byte dst[], int dstOffset) {
int i, j;
int index = dstOffset;
for (i = 0; i < width; i++) {
for (j = height - 1; j >= 0; j--) {
dst[index] = src[srcOffset + j * width + i];
index++;
}
}
}
private void rotateRectAnticlockwiseDegree90(byte[] src, int srcOffset, int width, int height, byte dst[],
int dstOffset) {
int i, j;
int index = dstOffset;
for (i = width - 1; i >= 0; i--) {
for (j = 0; j < height; j++) {
dst[index] = src[srcOffset + j * width + i];
index++;
}
}
}
android camera YV12数据旋转方法
最新推荐文章于 2023-12-07 00:45:32 发布