zoukankan      html  css  js  c++  java
  • 【转】YUV420P的格式以及转换为RGB565的代码(Android摄像头的输出一般为YUV420P)

     http://blog.csdn.net/daisyhd/article/details/38866809

    YUV420P的格式

    static void cvt_420p_to_rgb565(int width, int height, const unsigned char *src, unsigned short *dst)
    {
      int line, col, linewidth;
      int y, u, v, yy, vr, ug, vg, ub;
      int r, g, b;
      const unsigned char *py, *pu, *pv;

      linewidth = width >> 1;
      py = src;
      pu = py + (width * height);
      pv = pu + (width * height) / 4;

      y = *py++;
      yy = y << 8;
      u = *pu - 128;
      ug = 88 * u;
      ub = 454 * u;
      v = *pv - 128;
      vg = 183 * v;
      vr = 359 * v;

      for (line = 0; line < height; line++) {
        for (col = 0; col < width; col++) {
          r = (yy + vr) >> 8;
          g = (yy - ug - vg) >> 8;
          b = (yy + ub ) >> 8;

          if (r < 0) r = 0;
          if (r > 255) r = 255;
          if (g < 0) g = 0;
          if (g > 255) g = 255;
          if (b < 0) b = 0;
          if (b > 255) b = 255;
          *dst++ = (((unsigned short)r>>3)<<11) | (((unsigned short)g>>2)<<5) | (((unsigned short)b>>3)<<0); 
      
          y = *py++;
          yy = y << 8;
          if (col & 1) {
        pu++;
        pv++;

        u = *pu - 128;
        ug = 88 * u;
        ub = 454 * u;
        v = *pv - 128;
        vg = 183 * v;
        vr = 359 * v;
          }
        } 
        if ((line & 1) == 0) { 
          pu -= linewidth;
          pv -= linewidth;
        }
      } 
    }

  • 相关阅读:
    天明闹钟开发过程3
    降低 TCP ACK 延迟造成的网络性能损失
    TCP SYN,ACK 详解
    TCP的SEQ和ACK的生成
    python之线程(threading)
    python之进程(multiprocess)
    python之发送邮件~
    python之函数参数问题(参数为可变对象)
    python之斐波那契数列递归推导在性能方面的反思
    linux中一些简便的命令之tac/comm
  • 原文地址:https://www.cnblogs.com/exmyth/p/5125305.html
Copyright © 2011-2022 走看看