Deb Mukherjee | cacea00 | 2014-01-23 14:53:53 -0800 | [diff] [blame] | 1 | /* |
Yaowu Xu | bde4ac8 | 2016-11-28 15:26:06 -0800 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
Deb Mukherjee | cacea00 | 2014-01-23 14:53:53 -0800 | [diff] [blame] | 3 | * |
Yaowu Xu | bde4ac8 | 2016-11-28 15:26:06 -0800 | [diff] [blame] | 4 | * This source code is subject to the terms of the BSD 2 Clause License and |
| 5 | * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License |
| 6 | * was not distributed with this source code in the LICENSE file, you can |
| 7 | * obtain it at www.aomedia.org/license/software. If the Alliance for Open |
| 8 | * Media Patent License 1.0 was not distributed with this source code in the |
| 9 | * PATENTS file, you can obtain it at www.aomedia.org/license/patent. |
Deb Mukherjee | cacea00 | 2014-01-23 14:53:53 -0800 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <assert.h> |
| 13 | #include <limits.h> |
| 14 | #include <math.h> |
| 15 | #include <stdio.h> |
| 16 | #include <stdlib.h> |
| 17 | #include <string.h> |
| 18 | |
James Zern | 59e7a47 | 2015-05-09 10:33:26 -0700 | [diff] [blame] | 19 | #include "../tools_common.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 20 | #include "../av1/encoder/av1_resize.h" |
Deb Mukherjee | cacea00 | 2014-01-23 14:53:53 -0800 | [diff] [blame] | 21 | |
Tom Finegan | 9e96bdc | 2015-02-04 16:11:57 -0800 | [diff] [blame] | 22 | static const char *exec_name = NULL; |
| 23 | |
| 24 | static void usage() { |
Deb Mukherjee | cacea00 | 2014-01-23 14:53:53 -0800 | [diff] [blame] | 25 | printf("Usage:\n"); |
| 26 | printf("%s <input_yuv> <width>x<height> <target_width>x<target_height> ", |
Tom Finegan | 9e96bdc | 2015-02-04 16:11:57 -0800 | [diff] [blame] | 27 | exec_name); |
Deb Mukherjee | cacea00 | 2014-01-23 14:53:53 -0800 | [diff] [blame] | 28 | printf("<output_yuv> [<frames>]\n"); |
| 29 | } |
| 30 | |
James Zern | 59e7a47 | 2015-05-09 10:33:26 -0700 | [diff] [blame] | 31 | void usage_exit(void) { |
Tom Finegan | 9e96bdc | 2015-02-04 16:11:57 -0800 | [diff] [blame] | 32 | usage(); |
| 33 | exit(EXIT_FAILURE); |
| 34 | } |
| 35 | |
Deb Mukherjee | cacea00 | 2014-01-23 14:53:53 -0800 | [diff] [blame] | 36 | static int parse_dim(char *v, int *width, int *height) { |
| 37 | char *x = strchr(v, 'x'); |
clang-format | 397d964 | 2016-08-08 18:51:16 -0700 | [diff] [blame] | 38 | if (x == NULL) x = strchr(v, 'X'); |
| 39 | if (x == NULL) return 0; |
Deb Mukherjee | cacea00 | 2014-01-23 14:53:53 -0800 | [diff] [blame] | 40 | *width = atoi(v); |
| 41 | *height = atoi(&x[1]); |
| 42 | if (*width <= 0 || *height <= 0) |
| 43 | return 0; |
| 44 | else |
| 45 | return 1; |
| 46 | } |
| 47 | |
| 48 | int main(int argc, char *argv[]) { |
| 49 | char *fin, *fout; |
| 50 | FILE *fpin, *fpout; |
| 51 | uint8_t *inbuf, *outbuf; |
| 52 | uint8_t *inbuf_u, *outbuf_u; |
| 53 | uint8_t *inbuf_v, *outbuf_v; |
| 54 | int f, frames; |
| 55 | int width, height, target_width, target_height; |
| 56 | |
Tom Finegan | 9e96bdc | 2015-02-04 16:11:57 -0800 | [diff] [blame] | 57 | exec_name = argv[0]; |
| 58 | |
Deb Mukherjee | cacea00 | 2014-01-23 14:53:53 -0800 | [diff] [blame] | 59 | if (argc < 5) { |
| 60 | printf("Incorrect parameters:\n"); |
Tom Finegan | 9e96bdc | 2015-02-04 16:11:57 -0800 | [diff] [blame] | 61 | usage(); |
Deb Mukherjee | cacea00 | 2014-01-23 14:53:53 -0800 | [diff] [blame] | 62 | return 1; |
| 63 | } |
| 64 | |
| 65 | fin = argv[1]; |
| 66 | fout = argv[4]; |
| 67 | if (!parse_dim(argv[2], &width, &height)) { |
| 68 | printf("Incorrect parameters: %s\n", argv[2]); |
Tom Finegan | 9e96bdc | 2015-02-04 16:11:57 -0800 | [diff] [blame] | 69 | usage(); |
Deb Mukherjee | cacea00 | 2014-01-23 14:53:53 -0800 | [diff] [blame] | 70 | return 1; |
| 71 | } |
| 72 | if (!parse_dim(argv[3], &target_width, &target_height)) { |
| 73 | printf("Incorrect parameters: %s\n", argv[3]); |
Tom Finegan | 9e96bdc | 2015-02-04 16:11:57 -0800 | [diff] [blame] | 74 | usage(); |
Deb Mukherjee | cacea00 | 2014-01-23 14:53:53 -0800 | [diff] [blame] | 75 | return 1; |
| 76 | } |
| 77 | |
| 78 | fpin = fopen(fin, "rb"); |
| 79 | if (fpin == NULL) { |
| 80 | printf("Can't open file %s to read\n", fin); |
Tom Finegan | 9e96bdc | 2015-02-04 16:11:57 -0800 | [diff] [blame] | 81 | usage(); |
Deb Mukherjee | cacea00 | 2014-01-23 14:53:53 -0800 | [diff] [blame] | 82 | return 1; |
| 83 | } |
| 84 | fpout = fopen(fout, "wb"); |
| 85 | if (fpout == NULL) { |
| 86 | printf("Can't open file %s to write\n", fout); |
Tom Finegan | 9e96bdc | 2015-02-04 16:11:57 -0800 | [diff] [blame] | 87 | usage(); |
Deb Mukherjee | cacea00 | 2014-01-23 14:53:53 -0800 | [diff] [blame] | 88 | return 1; |
| 89 | } |
| 90 | if (argc >= 6) |
| 91 | frames = atoi(argv[5]); |
| 92 | else |
| 93 | frames = INT_MAX; |
| 94 | |
clang-format | 397d964 | 2016-08-08 18:51:16 -0700 | [diff] [blame] | 95 | printf("Input size: %dx%d\n", width, height); |
| 96 | printf("Target size: %dx%d, Frames: ", target_width, target_height); |
Deb Mukherjee | cacea00 | 2014-01-23 14:53:53 -0800 | [diff] [blame] | 97 | if (frames == INT_MAX) |
| 98 | printf("All\n"); |
| 99 | else |
| 100 | printf("%d\n", frames); |
| 101 | |
clang-format | 397d964 | 2016-08-08 18:51:16 -0700 | [diff] [blame] | 102 | inbuf = (uint8_t *)malloc(width * height * 3 / 2); |
| 103 | outbuf = (uint8_t *)malloc(target_width * target_height * 3 / 2); |
Deb Mukherjee | cacea00 | 2014-01-23 14:53:53 -0800 | [diff] [blame] | 104 | inbuf_u = inbuf + width * height; |
| 105 | inbuf_v = inbuf_u + width * height / 4; |
| 106 | outbuf_u = outbuf + target_width * target_height; |
| 107 | outbuf_v = outbuf_u + target_width * target_height / 4; |
| 108 | f = 0; |
| 109 | while (f < frames) { |
clang-format | 397d964 | 2016-08-08 18:51:16 -0700 | [diff] [blame] | 110 | if (fread(inbuf, width * height * 3 / 2, 1, fpin) != 1) break; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 111 | av1_resize_frame420(inbuf, width, inbuf_u, inbuf_v, width / 2, height, |
clang-format | 397d964 | 2016-08-08 18:51:16 -0700 | [diff] [blame] | 112 | width, outbuf, target_width, outbuf_u, outbuf_v, |
| 113 | target_width / 2, target_height, target_width); |
Deb Mukherjee | cacea00 | 2014-01-23 14:53:53 -0800 | [diff] [blame] | 114 | fwrite(outbuf, target_width * target_height * 3 / 2, 1, fpout); |
| 115 | f++; |
| 116 | } |
| 117 | printf("%d frames processed\n", f); |
| 118 | fclose(fpin); |
| 119 | fclose(fpout); |
| 120 | |
| 121 | free(inbuf); |
| 122 | free(outbuf); |
| 123 | return 0; |
| 124 | } |