Libav
parseutils.c
Go to the documentation of this file.
1 /*
2  * This file is part of Libav.
3  *
4  * Libav is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * Libav is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with Libav; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #include <stdint.h>
20 #include <stdio.h>
21 
22 #include "libavutil/common.h"
23 #include "libavutil/log.h"
24 #include "libavutil/rational.h"
25 #include "libavutil/parseutils.h"
26 
27 int main(void)
28 {
29  int i;
30  uint8_t rgba[4];
31  static const char *const rates[] = {
32  "-inf",
33  "inf",
34  "nan",
35  "123/0",
36  "-123 / 0",
37  "",
38  "/",
39  " 123 / 321",
40  "foo/foo",
41  "foo/1",
42  "1/foo",
43  "0/0",
44  "/0",
45  "1/",
46  "1",
47  "0",
48  "-123/123",
49  "-foo",
50  "123.23",
51  ".23",
52  "-.23",
53  "-0.234",
54  "-0.0000001",
55  " 21332.2324 ",
56  " -21332.2324 ",
57  };
58  static const char *const color_names[] = {
59  "foo",
60  "red",
61  "Red ",
62  "RED",
63  "Violet",
64  "Yellow",
65  "Red",
66  "0x000000",
67  "0x0000000",
68  "0xff000000",
69  "0x3e34ff",
70  "0x3e34ffaa",
71  "0xffXXee",
72  "0xfoobar",
73  "0xffffeeeeeeee",
74  "#ff0000",
75  "#ffXX00",
76  "ff0000",
77  "ffXX00",
78  "red@foo",
79  "random@10",
80  "0xff0000@1.0",
81  "red@",
82  "red@0xfff",
83  "red@0xf",
84  "red@2",
85  "red@0.1",
86  "red@-1",
87  "red@0.5",
88  "red@1.0",
89  "red@256",
90  "red@10foo",
91  "red@-1.0",
92  "red@-0.0",
93  };
94 
95  printf("Testing av_parse_video_rate()\n");
96 
97  for (i = 0; i < FF_ARRAY_ELEMS(rates); i++) {
98  int ret;
99  AVRational q = { 0, 0 };
100  ret = av_parse_video_rate(&q, rates[i]);
101  printf("'%s' -> %d/%d %s\n",
102  rates[i], q.num, q.den, ret ? "ERROR" : "OK");
103  }
104 
105  printf("\nTesting av_parse_color()\n");
106 
108 
109  for (i = 0; i < FF_ARRAY_ELEMS(color_names); i++) {
110  if (av_parse_color(rgba, color_names[i], -1, NULL) >= 0)
111  printf("%s -> R(%d) G(%d) B(%d) A(%d)\n",
112  color_names[i], rgba[0], rgba[1], rgba[2], rgba[3]);
113  }
114 
115  return 0;
116 }
int av_parse_video_rate(AVRational *rate, const char *arg)
Parse str and store the detected values in *rate.
Definition: parseutils.c:127
void av_log_set_level(int level)
Set the log level.
Definition: log.c:205
int num
numerator
Definition: rational.h:44
#define FF_ARRAY_ELEMS(a)
uint8_t
int av_parse_color(uint8_t *rgba_color, const char *color_string, int slen, void *log_ctx)
Put the RGBA values that correspond to color_string in rgba_color.
Definition: parseutils.c:305
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:145
NULL
Definition: eval.c:55
rational number numerator/denominator
Definition: rational.h:43
int main(void)
Definition: parseutils.c:27
misc parsing utilities
common internal and external API header
rational numbers
int den
denominator
Definition: rational.h:45
static const int rates[]
Definition: avresample.c:176