21 |
* along with this program ; if not, write to the Free Software |
* along with this program ; if not, write to the Free Software |
22 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
23 |
* |
* |
24 |
* $Id: encoder.c,v 1.116 2004-12-10 05:37:11 syskin Exp $ |
* $Id: encoder.c,v 1.118 2005-05-23 09:29:43 Skal Exp $ |
25 |
* |
* |
26 |
****************************************************************************/ |
****************************************************************************/ |
27 |
|
|
85 |
/* |
/* |
86 |
* Simplify the "fincr/fbase" fraction |
* Simplify the "fincr/fbase" fraction |
87 |
*/ |
*/ |
88 |
|
static int |
89 |
|
gcd(int a, int b) |
90 |
|
{ |
91 |
|
int r ; |
92 |
|
|
93 |
|
if (b > a) { |
94 |
|
r = a; |
95 |
|
a = b; |
96 |
|
b = r; |
97 |
|
} |
98 |
|
|
99 |
|
while ((r = a % b)) { |
100 |
|
a = b; |
101 |
|
b = r; |
102 |
|
} |
103 |
|
return b; |
104 |
|
} |
105 |
|
|
106 |
static void |
static void |
107 |
simplify_time(int *inc, int *base) |
simplify_time(int *inc, int *base) |
108 |
{ |
{ |
109 |
/* common factor */ |
/* common factor */ |
110 |
int i = *inc; |
const int s = gcd(*inc, *base); |
111 |
while (i > 1) { |
*inc /= s; |
112 |
if (*inc % i == 0 && *base % i == 0) { |
*base /= s; |
|
*inc /= i; |
|
|
*base /= i; |
|
|
i = *inc; |
|
|
continue; |
|
|
} |
|
|
i--; |
|
|
} |
|
113 |
|
|
114 |
if (*base > 65535 || *inc > 65535) { |
if (*base > 65535 || *inc > 65535) { |
115 |
int *biggest; |
int *biggest; |
125 |
} |
} |
126 |
|
|
127 |
div = ((float)*biggest)/((float)65535); |
div = ((float)*biggest)/((float)65535); |
128 |
*biggest = (int)(((float)*biggest)/div); |
*biggest = (unsigned int)(((float)*biggest)/div); |
129 |
*other = (int)(((float)*other)/div); |
*other = (unsigned int)(((float)*other)/div); |
130 |
} |
} |
131 |
} |
} |
132 |
|
|
157 |
|
|
158 |
/* global flags */ |
/* global flags */ |
159 |
pEnc->mbParam.global_flags = create->global; |
pEnc->mbParam.global_flags = create->global; |
160 |
|
if ((pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED)) |
161 |
|
pEnc->mbParam.global_flags |= XVID_GLOBAL_DIVX5_USERDATA; |
162 |
|
|
163 |
/* width, height */ |
/* width, height */ |
164 |
pEnc->mbParam.width = create->width; |
pEnc->mbParam.width = create->width; |
172 |
pEnc->mbParam.fincr = MAX(create->fincr, 0); |
pEnc->mbParam.fincr = MAX(create->fincr, 0); |
173 |
pEnc->mbParam.fbase = create->fincr <= 0 ? 25 : create->fbase; |
pEnc->mbParam.fbase = create->fincr <= 0 ? 25 : create->fbase; |
174 |
if (pEnc->mbParam.fincr>0) |
if (pEnc->mbParam.fincr>0) |
175 |
simplify_time(&pEnc->mbParam.fincr, &pEnc->mbParam.fbase); |
simplify_time((int*)&pEnc->mbParam.fincr, (int*)&pEnc->mbParam.fbase); |
176 |
|
|
177 |
/* zones */ |
/* zones */ |
178 |
if(create->num_zones > 0) { |
if(create->num_zones > 0) { |
885 |
#endif |
#endif |
886 |
} |
} |
887 |
|
|
|
static int |
|
|
gcd(int a, int b) |
|
|
{ |
|
|
int r ; |
|
|
|
|
|
if (b > a) { |
|
|
r = a; |
|
|
a = b; |
|
|
b = r; |
|
|
} |
|
|
|
|
|
while ((r = a % b)) { |
|
|
a = b; |
|
|
b = r; |
|
|
} |
|
|
return b; |
|
|
} |
|
|
|
|
888 |
static void |
static void |
889 |
simplify_par(int *par_width, int *par_height) |
simplify_par(int *par_width, int *par_height) |
890 |
{ |
{ |
1148 |
type = frame->type; |
type = frame->type; |
1149 |
pEnc->current->quant = frame->quant; |
pEnc->current->quant = frame->quant; |
1150 |
|
|
1151 |
call_plugins(pEnc, pEnc->current, NULL, XVID_PLG_BEFORE, &type, &pEnc->current->quant, stats); |
call_plugins(pEnc, pEnc->current, NULL, XVID_PLG_BEFORE, &type, (int*)&pEnc->current->quant, stats); |
1152 |
|
|
1153 |
if (type > 0){ /* XVID_TYPE_?VOP */ |
if (type > 0){ /* XVID_TYPE_?VOP */ |
1154 |
type = type2coding(type); /* convert XVID_TYPE_?VOP to bitstream coding type */ |
type = type2coding(type); /* convert XVID_TYPE_?VOP to bitstream coding type */ |
1251 |
SWAP(FRAMEINFO*, pEnc->current, pEnc->bframes[pEnc->bframenum_tail]); |
SWAP(FRAMEINFO*, pEnc->current, pEnc->bframes[pEnc->bframenum_tail]); |
1252 |
|
|
1253 |
if ((pEnc->current->vop_flags & XVID_VOP_DEBUG)) { |
if ((pEnc->current->vop_flags & XVID_VOP_DEBUG)) { |
1254 |
image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 100, "DX50 BVOP->PVOP"); |
image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 100, "CLOSED GOP BVOP->PVOP"); |
1255 |
} |
} |
1256 |
|
|
1257 |
/* convert B-VOP quant to P-VOP */ |
/* convert B-VOP quant to P-VOP */ |