--- plugin_fixed.c 2003/03/23 04:03:01 1.1.2.1 +++ plugin_fixed.c 2003/10/01 23:23:01 1.1.2.4 @@ -1,25 +1,25 @@ /***************************************************************************** * - * XviD VBR Library - * - Fixed quantizer controller implementation - + * XviD VBR Library + * - Fixed quantizer controller implementation / Deprecated code - * - * Copyright (C) 2002 Edouard Gomez + * Copyright (C) 2002-2003 Edouard Gomez * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: plugin_fixed.c,v 1.1.2.1 2003/03/23 04:03:01 suxen_drol Exp $ + * $Id: plugin_fixed.c,v 1.1.2.4 2003/10/01 23:23:01 edgomez Exp $ * ****************************************************************************/ @@ -64,6 +64,7 @@ int low, high; int q, r; int a,b,min, max; + int m, M; int *dist; /* Low quant */ @@ -102,9 +103,9 @@ * length. Let's call 'r' the remaining part of the euclidian division. * * We could stop there and have something like this: - * M == quant type of the quantity 'max' - * m == quant type of the quantity 'min' - * + * M == quant type of the quantity 'max' + * m == quant type of the quantity 'min' + * * (MM.........Mm)*(MMMMMM...M) * '----------' '--------' * '----|------' |-> repeated 'r' times @@ -152,7 +153,7 @@ * */ - + max = MAX(nlow, nhigh); min = MIN(nlow, nhigh); @@ -167,10 +168,20 @@ /* How much packets of (q+1)M quantizers + 1m quantizer */ a = r; - + /* How much packets of (q)M quantizers + 1m quantizer */ b = min - r; + /* First we set M */ + M = (max==nhigh)?high:low; + + /* + * Then as we can't guarantee that max != min, we are forced to set + * the other one according to the first value. We can't use the first + * formula with s/max/min/ + */ + m = (M==high)?low:high; + /* * Ok now we know everything we have to know to distribute those funny * quantizers. What about just doing it ? @@ -184,10 +195,10 @@ int j; /* Repeat q+1 times the M quantizer */ - for(j=0; j<(q+1); j++) *(dist++) = (max==nhigh)?high:low; + for(j=0; j<(q+1); j++) *(dist++) = M; /* Put a m quantizer */ - *(dist++) = (min==nhigh)?high:low; + *(dist++) = m; } @@ -197,10 +208,10 @@ int j; /* Repeat q times the M quantizer */ - for(j=0; jquant_base = 1; rc->quant_increment = quant_low; - } + } /* How much low quants we have to distribute) */ nquant_low = rc->quant_base*(quant_low+1) - rc->quant_increment; @@ -245,15 +256,15 @@ /* Distribute the quantizers */ rc->nquant = distribute_quants(&rc->quant, - quant_low, - nquant_low, - nquant_high); + quant_low, + nquant_low, + nquant_high); if(rc->quant == NULL) { free(rc); return(XVID_ERR_MEMORY); } - + *handle = rc; return(0); }