美文网首页
【蜗牛黑板报】常用代码总结

【蜗牛黑板报】常用代码总结

作者: 技术是神奇的 | 来源:发表于2020-05-11 00:32 被阅读0次

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;

    }

  }

}

相关文章

网友评论

      本文标题:【蜗牛黑板报】常用代码总结

      本文链接:https://www.haomeiwen.com/subject/hnbenhtx.html