1. YUV420 mirror
// nv21 mirror
void yuv_mirror(unsigned char *src, int w, int h) {
int i;
int index;
unsigned char temp;
int a, b;
//mirror y
for (i = 0; i < h; i++) {
a = i * w;
b = (i + 1) * w - 1;
while (a < b) {
temp = src[a];
src[a] = src[b];
src[b] = temp;
a++;
b--;
}
}
// mirror u and v
index = w * h;
for (i = 0; i < h / 2; i++) {
a = i * w;
b = (i + 1) * w - 2;
while (a < b) {
temp = src[a + index];
src[a + index] = src[b + index];
src[b + index] = temp;
temp = src[a + index + 1];
src[a + index + 1] = src[b + index + 1];
src[b + index + 1] = temp;
a += 2;
b -= 2;
}
}
}
2.YUV420的Y flip, UV同理
unsigned char temp_buf[1024];
memset(temp_buf, 0, 1024);
unsigned char *pointer_input, *pointer_output = NULL;
a = h;
while(a > b) {
pointer_input = src + a * w;
pointer_output = src + b * w;
memcpy(temp_buf, pointer_input, w);
memcpy(pointer_input, pointer_output, w);
memcpy(pointer_output, temp_buf, w);
a--;
b++;
}
3.YUV420 nv21 flip
void yuv_flip(unsigned char *src, int w, int h) {
int i;
int index;
unsigned char temp;
int a, b = 0;
//flip y
for (i = 0; i < w; i++) {
a = i;
b = (h - 1) * w + i;
while (a < b) {
temp = src[a];
src[a] = src[b];
src[b] = temp;
a = a + w;
b = b - w;
}
}
// flip u and v
index = w * h;
for (i = 0; i < w; i++) {
a = i;
b = (0.5 * h - 1) * w + i;
while (a < b) {
temp = src[a + index];
src[a + index] = src[b + index];
src[b + index] = temp;
a = a + w;
b = b - w;
}
}
}
网友评论