third_party/libyuv/source/convert.cc
// Support converting from FOURCC_M420
// Useful for bandwidth constrained transports like USB 1.0 and 2.0 and for
// easy conversion to I420.
// M420 format description:
// M420 is row biplanar 420: 2 rows of Y and 1 row of UV.
// Chroma is half width / half height. (420)
// src_stride_m420 is row planar. Normally this will be the width in pixels.
//   The UV plane is half width, but 2 values, so src_stride_m420 applies to
//   this as well as the two Y planes.
Support converting from FOURCC_M420
Useful for bandwidth constrained transports like USB 1.0 and 2.0 and for
easy conversion to I420.
M420 format description:
M420 is row biplanar 420: 2 rows of Y and 1 row of UV.
Chroma is half width / half height. (420)
src_stride_m420 is row planar. Normally this will be the width in pixels.
The UV plane is half width, but 2 values, so src_stride_m420 applies to
this as well as the two Y planes.
Support converting from FOURCC_M420 Useful for bandwidth constrained transports like USB 1 . 0 and 2 . 0 and for easy conversion to I420 . M420 format description : M420 is row biplanar 420 : 2 rows of Y and 1 row of UV . Chroma is half width / half height . ( 420 ) src_stride_m420 is row planar . Normally this will be the width in pixels . The UV plane is half width but 2 values so src_stride_m420 applies to this as well as the two Y planes .
static int X420ToI420(const uint8_t* src_y,
                      int src_stride_y0,
                      int src_stride_y1,
                      const uint8_t* src_uv,
                      int src_stride_uv,
                      uint8_t* dst_y,
                      int dst_stride_y,
                      uint8_t* dst_u,
                      int dst_stride_u,
                      uint8_t* dst_v,
                      int dst_stride_v,
                      int width,
                      int height) {
  int halfwidth = (width + 1) >> 1;
  int halfheight = (height + 1) >> 1;
  if (!src_uv || !dst_u || !dst_v || width <= 0 || height == 0) {
    return -1;
  }
  if (height < 0) {
    height = -height;
    halfheight = (height + 1) >> 1;
    if (dst_y) {
      dst_y = dst_y + (height - 1) * dst_stride_y;
    }
    dst_u = dst_u + (halfheight - 1) * dst_stride_u;
    dst_v = dst_v + (halfheight - 1) * dst_stride_v;
    dst_stride_y = -dst_stride_y;
    dst_stride_u = -dst_stride_u;
    dst_stride_v = -dst_stride_v;
  }
  if (src_stride_y0 == width && src_stride_y1 == width &&
      dst_stride_y == width) {
    width *= height;
    height = 1;
    src_stride_y0 = src_stride_y1 = dst_stride_y = 0;
  }
  if (src_stride_uv == halfwidth * 2 && dst_stride_u == halfwidth &&
      dst_stride_v == halfwidth) {
    halfwidth *= halfheight;
    halfheight = 1;
    src_stride_uv = dst_stride_u = dst_stride_v = 0;
  }
  if (dst_y) {
    if (src_stride_y0 == src_stride_y1) {
      CopyPlane(src_y, src_stride_y0, dst_y, dst_stride_y, width, height);
    } else {
      CopyPlane2(src_y, src_stride_y0, src_stride_y1, dst_y, dst_stride_y,
                 width, height);
    }
  }
  SplitUVPlane(src_uv, src_stride_uv, dst_u, dst_stride_u, dst_v, dst_stride_v,
               halfwidth, halfheight);
  return 0;
}
static int X420ToI420 ( const uint8_t * src_y , int src_stride_y0 , int src_stride_y1 , const uint8_t * src_uv , int src_stride_uv , uint8_t * dst_y , int dst_stride_y , uint8_t * dst_u , int dst_stride_u , uint8_t * dst_v , int dst_stride_v , int width , int height ) { int halfwidth = ( width + 1 ) >> 1 ; int halfheight = ( height + 1 ) >> 1 ; if ( ! src_uv || ! dst_u || ! dst_v || width <= 0 || height == 0 ) { return -1 ; } if ( height < 0 ) { height = - height ; halfheight = ( height + 1 ) >> 1 ; if ( dst_y ) { dst_y = dst_y + ( height - 1 ) * dst_stride_y ; } dst_u = dst_u + ( halfheight - 1 ) * dst_stride_u ; dst_v = dst_v + ( halfheight - 1 ) * dst_stride_v ; dst_stride_y = - dst_stride_y ; dst_stride_u = - dst_stride_u ; dst_stride_v = - dst_stride_v ; } if ( src_stride_y0 == width && src_stride_y1 == width && dst_stride_y == width ) { width *= height ; height = 1 ; src_stride_y0 = src_stride_y1 = dst_stride_y = 0 ; } if ( src_stride_uv == halfwidth * 2 && dst_stride_u == halfwidth && dst_stride_v == halfwidth ) { halfwidth *= halfheight ; halfheight = 1 ; src_stride_uv = dst_stride_u = dst_stride_v = 0 ; } if ( dst_y ) { if ( src_stride_y0 == src_stride_y1 ) { CopyPlane ( src_y , src_stride_y0 , dst_y , dst_stride_y , width , height ) ; } else { CopyPlane2 ( src_y , src_stride_y0 , src_stride_y1 , dst_y , dst_stride_y , width , height ) ; } } SplitUVPlane ( src_uv , src_stride_uv , dst_u , dst_stride_u , dst_v , dst_stride_v , halfwidth , halfheight ) ; return 0 ; }
Support converting from FOURCC_M420
Useful for bandwidth constrained transports like USB 1.0 and 2.0 and for
easy conversion to I420.
Support converting from FOURCC_M420 Useful for bandwidth constrained transports like USB 1 . 0 and 2 . 0 and for easy conversion to I420 .
// Negative height means invert the image. // Coalesce rows. // Coalesce rows. // Split UV plane - NV12 / NV21