blob: 96fba81619b4eadd760b92b6696e127c2af91cf7 [file] [log] [blame]
Deb Mukherjeecacea002014-01-23 14:53:53 -08001/*
Krishna Rapaka7319db52021-09-28 20:35:29 -07002 * Copyright (c) 2021, Alliance for Open Media. All rights reserved
Deb Mukherjeecacea002014-01-23 14:53:53 -08003 *
Vibhoothi41c6dd72021-10-12 18:48:26 +00004 * This source code is subject to the terms of the BSD 3-Clause Clear License
5 * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
6 * License was not distributed with this source code in the LICENSE file, you
7 * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/. If the
8 * Alliance for Open Media Patent License 1.0 was not distributed with this
9 * source code in the PATENTS file, you can obtain it at
10 * aomedia.org/license/patent-license/.
Deb Mukherjeecacea002014-01-23 14:53:53 -080011 */
12
13#include <assert.h>
14#include <limits.h>
15#include <math.h>
16#include <stdio.h>
17#include <stdlib.h>
18#include <string.h>
19
Tom Finegan77902132018-05-21 10:19:15 -070020#include "av1/common/resize.h"
21#include "common/tools_common.h"
Deb Mukherjeecacea002014-01-23 14:53:53 -080022
Tom Finegan9e96bdc2015-02-04 16:11:57 -080023static const char *exec_name = NULL;
24
25static void usage() {
Deb Mukherjeecacea002014-01-23 14:53:53 -080026 printf("Usage:\n");
27 printf("%s <input_yuv> <width>x<height> <target_width>x<target_height> ",
Tom Finegan9e96bdc2015-02-04 16:11:57 -080028 exec_name);
Deb Mukherjeecacea002014-01-23 14:53:53 -080029 printf("<output_yuv> [<frames>]\n");
30}
31
James Zern59e7a472015-05-09 10:33:26 -070032void usage_exit(void) {
Tom Finegan9e96bdc2015-02-04 16:11:57 -080033 usage();
34 exit(EXIT_FAILURE);
35}
36
Deb Mukherjeecacea002014-01-23 14:53:53 -080037static int parse_dim(char *v, int *width, int *height) {
38 char *x = strchr(v, 'x');
clang-format397d9642016-08-08 18:51:16 -070039 if (x == NULL) x = strchr(v, 'X');
40 if (x == NULL) return 0;
Deb Mukherjeecacea002014-01-23 14:53:53 -080041 *width = atoi(v);
42 *height = atoi(&x[1]);
43 if (*width <= 0 || *height <= 0)
44 return 0;
45 else
46 return 1;
47}
48
49int main(int argc, char *argv[]) {
50 char *fin, *fout;
51 FILE *fpin, *fpout;
52 uint8_t *inbuf, *outbuf;
53 uint8_t *inbuf_u, *outbuf_u;
54 uint8_t *inbuf_v, *outbuf_v;
55 int f, frames;
56 int width, height, target_width, target_height;
57
Tom Finegan9e96bdc2015-02-04 16:11:57 -080058 exec_name = argv[0];
59
Deb Mukherjeecacea002014-01-23 14:53:53 -080060 if (argc < 5) {
61 printf("Incorrect parameters:\n");
Tom Finegan9e96bdc2015-02-04 16:11:57 -080062 usage();
Deb Mukherjeecacea002014-01-23 14:53:53 -080063 return 1;
64 }
65
66 fin = argv[1];
67 fout = argv[4];
68 if (!parse_dim(argv[2], &width, &height)) {
69 printf("Incorrect parameters: %s\n", argv[2]);
Tom Finegan9e96bdc2015-02-04 16:11:57 -080070 usage();
Deb Mukherjeecacea002014-01-23 14:53:53 -080071 return 1;
72 }
73 if (!parse_dim(argv[3], &target_width, &target_height)) {
74 printf("Incorrect parameters: %s\n", argv[3]);
Tom Finegan9e96bdc2015-02-04 16:11:57 -080075 usage();
Deb Mukherjeecacea002014-01-23 14:53:53 -080076 return 1;
77 }
78
79 fpin = fopen(fin, "rb");
80 if (fpin == NULL) {
81 printf("Can't open file %s to read\n", fin);
Tom Finegan9e96bdc2015-02-04 16:11:57 -080082 usage();
Deb Mukherjeecacea002014-01-23 14:53:53 -080083 return 1;
84 }
85 fpout = fopen(fout, "wb");
86 if (fpout == NULL) {
Yaowu Xu2df76f22020-04-10 09:37:34 -070087 fclose(fpin);
Deb Mukherjeecacea002014-01-23 14:53:53 -080088 printf("Can't open file %s to write\n", fout);
Tom Finegan9e96bdc2015-02-04 16:11:57 -080089 usage();
Deb Mukherjeecacea002014-01-23 14:53:53 -080090 return 1;
91 }
92 if (argc >= 6)
93 frames = atoi(argv[5]);
94 else
95 frames = INT_MAX;
96
clang-format397d9642016-08-08 18:51:16 -070097 printf("Input size: %dx%d\n", width, height);
98 printf("Target size: %dx%d, Frames: ", target_width, target_height);
Deb Mukherjeecacea002014-01-23 14:53:53 -080099 if (frames == INT_MAX)
100 printf("All\n");
101 else
102 printf("%d\n", frames);
103
clang-format397d9642016-08-08 18:51:16 -0700104 inbuf = (uint8_t *)malloc(width * height * 3 / 2);
105 outbuf = (uint8_t *)malloc(target_width * target_height * 3 / 2);
Deb Mukherjeecacea002014-01-23 14:53:53 -0800106 inbuf_u = inbuf + width * height;
107 inbuf_v = inbuf_u + width * height / 4;
108 outbuf_u = outbuf + target_width * target_height;
109 outbuf_v = outbuf_u + target_width * target_height / 4;
110 f = 0;
111 while (f < frames) {
clang-format397d9642016-08-08 18:51:16 -0700112 if (fread(inbuf, width * height * 3 / 2, 1, fpin) != 1) break;
Yaowu Xuf883b422016-08-30 14:01:10 -0700113 av1_resize_frame420(inbuf, width, inbuf_u, inbuf_v, width / 2, height,
clang-format397d9642016-08-08 18:51:16 -0700114 width, outbuf, target_width, outbuf_u, outbuf_v,
115 target_width / 2, target_height, target_width);
Deb Mukherjeecacea002014-01-23 14:53:53 -0800116 fwrite(outbuf, target_width * target_height * 3 / 2, 1, fpout);
117 f++;
118 }
119 printf("%d frames processed\n", f);
120 fclose(fpin);
121 fclose(fpout);
122
123 free(inbuf);
124 free(outbuf);
125 return 0;
126}