android/ringlibsdl/project/jni/libwebp-0.3.0/examples/dwebp.c
// format=PGM: save a grayscale PGM file using the IMC4 layout
// (http://www.fourcc.org/yuv.php#IMC4). This is a very convenient format for
// viewing the samples, esp. for odd dimensions.
// format=YUV: just save the Y/U/V/A planes sequentially without header.
format=PGM: save a grayscale PGM file using the IMC4 layout
. This is a very convenient format for
viewing the samples, esp. for odd dimensions.
format=YUV: just save the Y/U/V/A planes sequentially without header.
format = PGM : save a grayscale PGM file using the IMC4 layout . This is a very convenient format for viewing the samples esp . for odd dimensions . format = YUV : just save the Y / U / V / A planes sequentially without header .
static int WritePGMOrYUV(FILE* fout, const WebPDecBuffer* const buffer,
                         OutputFileFormat format) {
  const int width = buffer->width;
  const int height = buffer->height;
  const WebPYUVABuffer* const yuv = &buffer->u.YUVA;
  int ok = 1;
  int y;
  const int pad = (format == YUV) ? 0 : 1;
  const int uv_width = (width + 1) / 2;
  const int uv_height = (height + 1) / 2;
  const int out_stride = (width + pad) & ~pad;
  const int a_height = yuv->a ? height : 0;
  if (format == PGM) {
    fprintf(fout, "P5\n%d %d\n255\n",
            out_stride, height + uv_height + a_height);
  }
  for (y = 0; ok && y < height; ++y) {
    ok &= (fwrite(yuv->y + y * yuv->y_stride, width, 1, fout) == 1);
    if (format == PGM) {
      if (width & 1) fputc(0, fout);    
    }
  }
  if (format == PGM) {   
    for (y = 0; ok && y < uv_height; ++y) {
      ok &= (fwrite(yuv->u + y * yuv->u_stride, uv_width, 1, fout) == 1);
      ok &= (fwrite(yuv->v + y * yuv->v_stride, uv_width, 1, fout) == 1);
    }
  } else {
    for (y = 0; ok && y < uv_height; ++y) {
      ok &= (fwrite(yuv->u + y * yuv->u_stride, uv_width, 1, fout) == 1);
    }
    for (y = 0; ok && y < uv_height; ++y) {
      ok &= (fwrite(yuv->v + y * yuv->v_stride, uv_width, 1, fout) == 1);
    }
  }
  for (y = 0; ok && y < a_height; ++y) {
    ok &= (fwrite(yuv->a + y * yuv->a_stride, width, 1, fout) == 1);
    if (format == PGM) {
      if (width & 1) fputc(0, fout);    
    }
  }
  return ok;
}
static int WritePGMOrYUV ( FILE * fout , const WebPDecBuffer * const buffer , OutputFileFormat format ) { const int width = buffer -> width ; const int height = buffer -> height ; const WebPYUVABuffer * const yuv = & buffer -> u . YUVA ; int ok = 1 ; int y ; const int pad = ( format == YUV ) ? 0 : 1 ; const int uv_width = ( width + 1 ) / 2 ; const int uv_height = ( height + 1 ) / 2 ; const int out_stride = ( width + pad ) & ~ pad ; const int a_height = yuv -> a ? height : 0 ; if ( format == PGM ) { fprintf ( fout , " \n \n \n " , out_stride , height + uv_height + a_height ) ; } for ( y = 0 ; ok && y < height ; ++ y ) { ok &= ( fwrite ( yuv -> y + y * yuv -> y_stride , width , 1 , fout ) == 1 ) ; if ( format == PGM ) { if ( width & 1 ) fputc ( 0 , fout ) ; } } if ( format == PGM ) { for ( y = 0 ; ok && y < uv_height ; ++ y ) { ok &= ( fwrite ( yuv -> u + y * yuv -> u_stride , uv_width , 1 , fout ) == 1 ) ; ok &= ( fwrite ( yuv -> v + y * yuv -> v_stride , uv_width , 1 , fout ) == 1 ) ; } } else { for ( y = 0 ; ok && y < uv_height ; ++ y ) { ok &= ( fwrite ( yuv -> u + y * yuv -> u_stride , uv_width , 1 , fout ) == 1 ) ; } for ( y = 0 ; ok && y < uv_height ; ++ y ) { ok &= ( fwrite ( yuv -> v + y * yuv -> v_stride , uv_width , 1 , fout ) == 1 ) ; } } for ( y = 0 ; ok && y < a_height ; ++ y ) { ok &= ( fwrite ( yuv -> a + y * yuv -> a_stride , width , 1 , fout ) == 1 ) ; if ( format == PGM ) { if ( width & 1 ) fputc ( 0 , fout ) ; } } return ok ; }
format=PGM: save a grayscale PGM file using the IMC4 layout
(http://www.fourcc.org/yuv.php#IMC4).
format = PGM : save a grayscale PGM file using the IMC4 layout ( http : // www . fourcc . org / yuv . php#IMC4 ) .
// padding byte // IMC4 layout // padding byte