Mercurial > mplayer.hg
comparison libmpdemux/yuv4mpeg_ratio.c @ 3786:7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
author | arpi |
---|---|
date | Thu, 27 Dec 2001 02:08:31 +0000 |
parents | |
children | 36589811e5d0 |
comparison
equal
deleted
inserted
replaced
3785:44c74b600573 | 3786:7ebf504c92d6 |
---|---|
1 /* | |
2 * yuv4mpeg_ratio.c: Functions for dealing with y4m_ratio_t datatype. | |
3 * | |
4 * Copyright (C) 2001 Matthew J. Marjanovic <maddog@mir.com> | |
5 * | |
6 * This file is part of the lavtools packaged (mjpeg.sourceforge.net) | |
7 * | |
8 * This program is free software; you can redistribute it and/or | |
9 * modify it under the terms of the GNU General Public License | |
10 * as published by the Free Software Foundation; either version 2 | |
11 * of the License, or (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, | |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 * GNU General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License | |
19 * along with this program; if not, write to the Free Software | |
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
21 * | |
22 */ | |
23 | |
24 #include "config.h" | |
25 | |
26 #include <string.h> | |
27 #include "yuv4mpeg.h" | |
28 #include "yuv4mpeg_intern.h" | |
29 | |
30 | |
31 /* useful list of standard framerates */ | |
32 const y4m_ratio_t y4m_fps_UNKNOWN = Y4M_FPS_UNKNOWN; | |
33 const y4m_ratio_t y4m_fps_NTSC_FILM = Y4M_FPS_NTSC_FILM; | |
34 const y4m_ratio_t y4m_fps_FILM = Y4M_FPS_FILM; | |
35 const y4m_ratio_t y4m_fps_PAL = Y4M_FPS_PAL; | |
36 const y4m_ratio_t y4m_fps_NTSC = Y4M_FPS_NTSC; | |
37 const y4m_ratio_t y4m_fps_30 = Y4M_FPS_30; | |
38 const y4m_ratio_t y4m_fps_PAL_FIELD = Y4M_FPS_PAL_FIELD; | |
39 const y4m_ratio_t y4m_fps_NTSC_FIELD = Y4M_FPS_NTSC_FIELD; | |
40 const y4m_ratio_t y4m_fps_60 = Y4M_FPS_60; | |
41 | |
42 /* useful list of standard pixel aspect ratios */ | |
43 const y4m_ratio_t y4m_sar_UNKNOWN = Y4M_SAR_UNKNOWN; | |
44 const y4m_ratio_t y4m_sar_SQUARE = Y4M_SAR_SQUARE; | |
45 const y4m_ratio_t y4m_sar_NTSC_CCIR601 = Y4M_SAR_NTSC_CCIR601; | |
46 const y4m_ratio_t y4m_sar_NTSC_16_9 = Y4M_SAR_NTSC_16_9; | |
47 const y4m_ratio_t y4m_sar_NTSC_SVCD_4_3 = Y4M_SAR_NTSC_SVCD_4_3; | |
48 const y4m_ratio_t y4m_sar_NTSC_SVCD_16_9 = Y4M_SAR_NTSC_SVCD_16_9; | |
49 const y4m_ratio_t y4m_sar_PAL_CCIR601 = Y4M_SAR_PAL_CCIR601; | |
50 const y4m_ratio_t y4m_sar_PAL_16_9 = Y4M_SAR_PAL_16_9; | |
51 const y4m_ratio_t y4m_sar_PAL_SVCD_4_3 = Y4M_SAR_PAL_SVCD_4_3; | |
52 const y4m_ratio_t y4m_sar_PAL_SVCD_16_9 = Y4M_SAR_PAL_SVCD_16_9; | |
53 | |
54 | |
55 /* | |
56 * Euler's algorithm for greatest common divisor | |
57 */ | |
58 | |
59 static int gcd(int a, int b) | |
60 { | |
61 a = (a >= 0) ? a : -a; | |
62 b = (b >= 0) ? b : -b; | |
63 | |
64 while (b > 0) { | |
65 int x = b; | |
66 b = a % b; | |
67 a = x; | |
68 } | |
69 return a; | |
70 } | |
71 | |
72 | |
73 /************************************************************************* | |
74 * | |
75 * Remove common factors from a ratio | |
76 * | |
77 *************************************************************************/ | |
78 | |
79 | |
80 void y4m_ratio_reduce(y4m_ratio_t *r) | |
81 { | |
82 int d; | |
83 if ((r->n == 0) && (r->d == 0)) return; /* "unknown" */ | |
84 d = gcd(r->n, r->d); | |
85 r->n /= d; | |
86 r->d /= d; | |
87 } | |
88 | |
89 | |
90 | |
91 /************************************************************************* | |
92 * | |
93 * Parse "nnn:ddd" into a ratio | |
94 * | |
95 * returns: Y4M_OK - success | |
96 * Y4M_ERR_RANGE - range error | |
97 * | |
98 *************************************************************************/ | |
99 | |
100 int y4m_parse_ratio(y4m_ratio_t *r, const char *s) | |
101 { | |
102 char *t = strchr(s, ':'); | |
103 | |
104 if (t == NULL) return Y4M_ERR_RANGE; | |
105 r->n = atoi(s); | |
106 r->d = atoi(t+1); | |
107 if (r->d < 0) return Y4M_ERR_RANGE; | |
108 /* 0:0 == unknown, so that is ok, otherwise zero denominator is bad */ | |
109 if ((r->d == 0) && (r->n != 0)) return Y4M_ERR_RANGE; | |
110 y4m_ratio_reduce(r); | |
111 return Y4M_OK; | |
112 } | |
113 |