Mercurial > libavcodec.hg
comparison opt.c @ 3731:8b8773577dd9 libavcodec
Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
author | takis |
---|---|
date | Mon, 18 Sep 2006 11:35:48 +0000 |
parents | 73626972ccbb |
children | 6c407dc6ab4a |
comparison
equal
deleted
inserted
replaced
3730:aae4aed137ea | 3731:8b8773577dd9 |
---|---|
25 */ | 25 */ |
26 | 26 |
27 #include "avcodec.h" | 27 #include "avcodec.h" |
28 #include "opt.h" | 28 #include "opt.h" |
29 | 29 |
30 /** | 30 static int8_t si_prefixes['z' - 'E' + 1]={ |
31 * strtod() function extended with 'k', 'M' and 'B' postfixes. | 31 ['y'-'E']= -24, |
32 * This allows using kB, MB, k, M and B as a postfix. This function | 32 ['z'-'E']= -21, |
33 * assumes that the unit of numbers is bits not bytes. | 33 ['a'-'E']= -18, |
34 ['f'-'E']= -15, | |
35 ['p'-'E']= -12, | |
36 ['n'-'E']= - 9, | |
37 ['u'-'E']= - 6, | |
38 ['m'-'E']= - 3, | |
39 ['c'-'E']= - 2, | |
40 ['d'-'E']= - 1, | |
41 ['h'-'E']= 2, | |
42 ['k'-'E']= 3, | |
43 ['K'-'E']= 3, | |
44 ['M'-'E']= 6, | |
45 ['G'-'E']= 9, | |
46 ['T'-'E']= 12, | |
47 ['P'-'E']= 15, | |
48 ['E'-'E']= 18, | |
49 ['Z'-'E']= 21, | |
50 ['Y'-'E']= 24, | |
51 }; | |
52 | |
53 /** strtod() function extended with 'k', 'M', 'G', 'ki', 'Mi', 'Gi' and 'B' | |
54 * postfixes. This allows using f.e. kB, MiB, G and B as a postfix. This | |
55 * function assumes that the unit of numbers is bits not bytes. | |
34 */ | 56 */ |
35 static double av_strtod(const char *name, char **tail) { | 57 double av_strtod(const char *name, char **tail) { |
36 double d; | 58 double d; |
37 d= strtod(name, tail); | 59 int p = 0; |
38 if(*tail>name && (**tail=='k')) { | 60 char *next; |
39 d*=1000; | 61 d = strtod(name, &next); |
40 (*tail)++; | 62 /* if parsing succeeded, check for and interpret postfixes */ |
41 } | 63 if (next!=name) { |
42 else if(*tail && (**tail=='M')) { | 64 |
43 d*=1000000; | 65 if(*next >= 'E' && *next <= 'z'){ |
44 (*tail)++; | 66 int e= si_prefixes[*next - 'E']; |
45 } | 67 if(e){ |
46 else if(*tail && (**tail=='G')) { | 68 if(next[1] == 'i'){ |
47 d*=1000000000; | 69 d*= pow( 2, e/0.3); |
48 (*tail)++; | 70 next+=2; |
49 } | 71 }else{ |
50 if(*tail && (**tail=='B')) { | 72 d*= pow(10, e); |
51 d*=8; | 73 next++; |
52 (*tail)++; | 74 } |
53 } | 75 } |
76 } | |
77 | |
78 if(*next=='B') { | |
79 d*=8; | |
80 *next++; | |
81 } | |
82 } | |
83 /* if requested, fill in tail with the position after the last parsed | |
84 character */ | |
85 if (tail) | |
86 *tail = next; | |
54 return d; | 87 return d; |
55 } | 88 } |
56 | 89 |
57 static double av_parse_num(const char *name, char **tail){ | 90 static double av_parse_num(const char *name, char **tail){ |
58 double d; | 91 double d; |