2 * Copyright (c) 2014 The WebM project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
18 #include "./vp9/encoder/vp9_resize.h"
20 static void usage(char *progname
) {
22 printf("%s <input_yuv> <width>x<height> <target_width>x<target_height> ",
24 printf("<output_yuv> [<frames>]\n");
27 static int parse_dim(char *v
, int *width
, int *height
) {
28 char *x
= strchr(v
, 'x');
34 *height
= atoi(&x
[1]);
35 if (*width
<= 0 || *height
<= 0)
41 int main(int argc
, char *argv
[]) {
44 uint8_t *inbuf
, *outbuf
;
45 uint8_t *inbuf_u
, *outbuf_u
;
46 uint8_t *inbuf_v
, *outbuf_v
;
48 int width
, height
, target_width
, target_height
;
51 printf("Incorrect parameters:\n");
58 if (!parse_dim(argv
[2], &width
, &height
)) {
59 printf("Incorrect parameters: %s\n", argv
[2]);
63 if (!parse_dim(argv
[3], &target_width
, &target_height
)) {
64 printf("Incorrect parameters: %s\n", argv
[3]);
69 fpin
= fopen(fin
, "rb");
71 printf("Can't open file %s to read\n", fin
);
75 fpout
= fopen(fout
, "wb");
77 printf("Can't open file %s to write\n", fout
);
82 frames
= atoi(argv
[5]);
86 printf("Input size: %dx%d\n",
88 printf("Target size: %dx%d, Frames: ",
89 target_width
, target_height
);
90 if (frames
== INT_MAX
)
93 printf("%d\n", frames
);
95 inbuf
= (uint8_t*)malloc(width
* height
* 3 / 2);
96 outbuf
= (uint8_t*)malloc(target_width
* target_height
* 3 / 2);
97 inbuf_u
= inbuf
+ width
* height
;
98 inbuf_v
= inbuf_u
+ width
* height
/ 4;
99 outbuf_u
= outbuf
+ target_width
* target_height
;
100 outbuf_v
= outbuf_u
+ target_width
* target_height
/ 4;
103 if (fread(inbuf
, width
* height
* 3 / 2, 1, fpin
) != 1)
105 vp9_resize_frame420(inbuf
, width
, inbuf_u
, inbuf_v
, width
/ 2,
107 outbuf
, target_width
, outbuf_u
, outbuf_v
,
109 target_height
, target_width
);
110 fwrite(outbuf
, target_width
* target_height
* 3 / 2, 1, fpout
);
113 printf("%d frames processed\n", f
);