World of Might and Magic  0.2.0
Open reimplementation of Might and Magic 6 7 8 game engine
AVRational
+ Граф связей класса AVRational:

Файлы

файл  rational.h
 

Классы

struct  AVRational
 

Определения типов

typedef struct AVRational AVRational
 

Функции

static AVRational av_make_q (int num, int den)
 
static int av_cmp_q (AVRational a, AVRational b)
 
static double av_q2d (AVRational a)
 
int av_reduce (int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
 
AVRational av_mul_q (AVRational b, AVRational c) av_const
 
AVRational av_div_q (AVRational b, AVRational c) av_const
 
AVRational av_add_q (AVRational b, AVRational c) av_const
 
AVRational av_sub_q (AVRational b, AVRational c) av_const
 
static av_always_inline AVRational av_inv_q (AVRational q)
 
AVRational av_d2q (double d, int max) av_const
 
int av_nearer_q (AVRational q, AVRational q1, AVRational q2)
 
int av_find_nearest_q_idx (AVRational q, const AVRational *q_list)
 
uint32_t av_q2intfloat (AVRational q)
 

Подробное описание

Rational number calculation.

While rational numbers can be expressed as floating-point numbers, the conversion process is a lossy one, so are floating-point operations. On the other hand, the nature of FFmpeg demands highly accurate calculation of timestamps. This set of rational number utilities serves as a generic interface for manipulating rational numbers as pairs of numerators and denominators.

Many of the functions that operate on AVRational's have the suffix _q, in reference to the mathematical symbol "ℚ" (Q) which denotes the set of all rational numbers.

Типы

◆ AVRational

typedef struct AVRational AVRational

#include <C:/git/world-of-might-and-magic/lib/win32/x86/ffmpeg-4.2.2/include/libavutil/rational.h>

Rational number (pair of numerator and denominator).

Функции

◆ av_make_q()

static AVRational av_make_q ( int  num,
int  den 
)
inlinestatic

#include <C:/git/world-of-might-and-magic/lib/win32/x86/ffmpeg-4.2.2/include/libavutil/rational.h>

Create an AVRational.

Useful for compilers that do not support compound literals.

Заметки
The return value is not reduced.
См. также
av_reduce()

См. определение в файле rational.h строка 71

72 {
73  AVRational r = { num, den };
74  return r;
75 }

◆ av_cmp_q()

static int av_cmp_q ( AVRational  a,
AVRational  b 
)
inlinestatic

#include <C:/git/world-of-might-and-magic/lib/win32/x86/ffmpeg-4.2.2/include/libavutil/rational.h>

Compare two rationals.

Аргументы
aFirst rational
bSecond rational
Возвращает
One of the following values:
  • 0 if a == b
  • 1 if a > b
  • -1 if a < b
  • INT_MIN if one of the values is of the form 0 / 0

См. определение в файле rational.h строка 89

89  {
90  const int64_t tmp= a.num * (int64_t)b.den - b.num * (int64_t)a.den;
91 
92  if(tmp) return (int)((tmp ^ a.den ^ b.den)>>63)|1;
93  else if(b.den && a.den) return 0;
94  else if(a.num && b.num) return (a.num>>31) - (b.num>>31);
95  else return INT_MIN;
96 }

◆ av_q2d()

static double av_q2d ( AVRational  a)
inlinestatic

#include <C:/git/world-of-might-and-magic/lib/win32/x86/ffmpeg-4.2.2/include/libavutil/rational.h>

Convert an AVRational to a double.

Аргументы
aAVRational to convert
Возвращает
a in floating-point form
См. также
av_d2q()

См. определение в файле rational.h строка 104

104  {
105  return a.num / (double) a.den;
106 }

Используется в av_ts_make_time_string() и AVVideoStream::open().

+ Граф вызова функции:

◆ av_reduce()

int av_reduce ( int *  dst_num,
int *  dst_den,
int64_t  num,
int64_t  den,
int64_t  max 
)

#include <C:/git/world-of-might-and-magic/lib/win32/x86/ffmpeg-4.2.2/include/libavutil/rational.h>

Reduce a fraction.

This is useful for framerate calculations.

Аргументы
[out]dst_numDestination numerator
[out]dst_denDestination denominator
[in]numSource numerator
[in]denSource denominator
[in]maxMaximum allowed values for dst_num & dst_den
Возвращает
1 if the operation is exact, 0 otherwise

◆ av_mul_q()

AVRational av_mul_q ( AVRational  b,
AVRational  c 
) const

#include <C:/git/world-of-might-and-magic/lib/win32/x86/ffmpeg-4.2.2/include/libavutil/rational.h>

Multiply two rationals.

Аргументы
bFirst rational
cSecond rational
Возвращает
b*c

◆ av_div_q()

AVRational av_div_q ( AVRational  b,
AVRational  c 
) const

#include <C:/git/world-of-might-and-magic/lib/win32/x86/ffmpeg-4.2.2/include/libavutil/rational.h>

Divide one rational by another.

Аргументы
bFirst rational
cSecond rational
Возвращает
b/c

◆ av_add_q()

AVRational av_add_q ( AVRational  b,
AVRational  c 
) const

#include <C:/git/world-of-might-and-magic/lib/win32/x86/ffmpeg-4.2.2/include/libavutil/rational.h>

Add two rationals.

Аргументы
bFirst rational
cSecond rational
Возвращает
b+c

◆ av_sub_q()

AVRational av_sub_q ( AVRational  b,
AVRational  c 
) const

#include <C:/git/world-of-might-and-magic/lib/win32/x86/ffmpeg-4.2.2/include/libavutil/rational.h>

Subtract one rational from another.

Аргументы
bFirst rational
cSecond rational
Возвращает
b-c

◆ av_inv_q()

static av_always_inline AVRational av_inv_q ( AVRational  q)
static

#include <C:/git/world-of-might-and-magic/lib/win32/x86/ffmpeg-4.2.2/include/libavutil/rational.h>

Invert a rational.

Аргументы
qvalue
Возвращает
1 / q

См. определение в файле rational.h строка 159

160 {
161  AVRational r = { q.den, q.num };
162  return r;
163 }

Перекрестные ссылки AVRational::den.

◆ av_d2q()

AVRational av_d2q ( double  d,
int  max 
) const

#include <C:/git/world-of-might-and-magic/lib/win32/x86/ffmpeg-4.2.2/include/libavutil/rational.h>

Convert a double precision floating point number to a rational.

In case of infinity, the returned value is expressed as {1, 0} or {-1, 0} depending on the sign.

Аргументы
ddouble to convert
maxMaximum allowed numerator and denominator
Возвращает
d in AVRational form
См. также
av_q2d()

◆ av_nearer_q()

int av_nearer_q ( AVRational  q,
AVRational  q1,
AVRational  q2 
)

#include <C:/git/world-of-might-and-magic/lib/win32/x86/ffmpeg-4.2.2/include/libavutil/rational.h>

Find which of the two rationals is closer to another rational.

Аргументы
qRational to be compared against
q1,q2Rationals to be tested
Возвращает
One of the following values:
  • 1 if q1 is nearer to q than q2
  • -1 if q2 is nearer to q than q1
  • 0 if they have the same distance

◆ av_find_nearest_q_idx()

int av_find_nearest_q_idx ( AVRational  q,
const AVRational q_list 
)

#include <C:/git/world-of-might-and-magic/lib/win32/x86/ffmpeg-4.2.2/include/libavutil/rational.h>

Find the value in a list of rationals nearest a given reference rational.

Аргументы
qReference rational
q_listArray of rationals terminated by {0, 0}
Возвращает
Index of the nearest value found in the array

◆ av_q2intfloat()

uint32_t av_q2intfloat ( AVRational  q)

#include <C:/git/world-of-might-and-magic/lib/win32/x86/ffmpeg-4.2.2/include/libavutil/rational.h>

Convert an AVRational to a IEEE 32-bit float expressed in fixed-point format.

Аргументы
qRational to be converted
Возвращает
Equivalent floating-point value, expressed as an unsigned 32-bit integer.
Заметки
The returned value is platform-indepedant.
q
GLdouble GLdouble GLdouble GLdouble q
Definition: SDL_opengl.h:2087
int64_t
__int64 int64_t
Definition: alext.h:31
num
GLuint num
Definition: SDL_opengl_glext.h:4959
b
GLboolean GLboolean GLboolean b
Definition: SDL_opengl_glext.h:1112
r
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
a
GLboolean GLboolean GLboolean GLboolean a
Definition: SDL_opengl_glext.h:1112
AVRational
Definition: rational.h:58
AVRational::den
int den
Denominator.
Definition: rational.h:60