3 |
* XVID MPEG-4 VIDEO CODEC |
* XVID MPEG-4 VIDEO CODEC |
4 |
* - Encoder main module - |
* - Encoder main module - |
5 |
* |
* |
6 |
* Copyright(C) 2002 Michael Militzer |
* Copyright(C) 2002 Michael Militzer <isibaar@xvid.org> |
7 |
|
* 2002 Peter Ross <pross@xvid.org> |
8 |
|
* 2002 Daniel Smith <danielsmith@astroboymail.com> |
9 |
* |
* |
10 |
* This program is an implementation of a part of one or more MPEG-4 |
* This program is an implementation of a part of one or more MPEG-4 |
11 |
* Video tools as specified in ISO/IEC 14496-2 standard. Those intending |
* Video tools as specified in ISO/IEC 14496-2 standard. Those intending |
30 |
* along with this program; if not, write to the Free Software |
* along with this program; if not, write to the Free Software |
31 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
32 |
* |
* |
33 |
* $Id: encoder.c,v 1.80 2002-09-05 19:34:35 edgomez Exp $ |
* $Id: encoder.c,v 1.86 2002-10-19 12:20:33 edgomez Exp $ |
34 |
* |
* |
35 |
****************************************************************************/ |
****************************************************************************/ |
36 |
|
|
259 |
image_null(&pEnc->reference->image); |
image_null(&pEnc->reference->image); |
260 |
image_null(&pEnc->vInterH); |
image_null(&pEnc->vInterH); |
261 |
image_null(&pEnc->vInterV); |
image_null(&pEnc->vInterV); |
|
image_null(&pEnc->vInterVf); |
|
262 |
image_null(&pEnc->vInterHV); |
image_null(&pEnc->vInterHV); |
|
image_null(&pEnc->vInterHVf); |
|
263 |
|
|
264 |
#ifdef _DEBUG_PSNR |
#ifdef _DEBUG_PSNR |
265 |
if (image_create |
if (image_create |
284 |
pEnc->mbParam.edged_height) < 0) |
pEnc->mbParam.edged_height) < 0) |
285 |
goto xvid_err_memory3; |
goto xvid_err_memory3; |
286 |
if (image_create |
if (image_create |
|
(&pEnc->vInterVf, pEnc->mbParam.edged_width, |
|
|
pEnc->mbParam.edged_height) < 0) |
|
|
goto xvid_err_memory3; |
|
|
if (image_create |
|
287 |
(&pEnc->vInterHV, pEnc->mbParam.edged_width, |
(&pEnc->vInterHV, pEnc->mbParam.edged_width, |
288 |
pEnc->mbParam.edged_height) < 0) |
pEnc->mbParam.edged_height) < 0) |
289 |
goto xvid_err_memory3; |
goto xvid_err_memory3; |
|
if (image_create |
|
|
(&pEnc->vInterHVf, pEnc->mbParam.edged_width, |
|
|
pEnc->mbParam.edged_height) < 0) |
|
|
goto xvid_err_memory3; |
|
290 |
|
|
291 |
pParam->handle = (void *) pEnc; |
pParam->handle = (void *) pEnc; |
292 |
|
|
320 |
pEnc->mbParam.edged_height); |
pEnc->mbParam.edged_height); |
321 |
image_destroy(&pEnc->vInterV, pEnc->mbParam.edged_width, |
image_destroy(&pEnc->vInterV, pEnc->mbParam.edged_width, |
322 |
pEnc->mbParam.edged_height); |
pEnc->mbParam.edged_height); |
|
image_destroy(&pEnc->vInterVf, pEnc->mbParam.edged_width, |
|
|
pEnc->mbParam.edged_height); |
|
323 |
image_destroy(&pEnc->vInterHV, pEnc->mbParam.edged_width, |
image_destroy(&pEnc->vInterHV, pEnc->mbParam.edged_width, |
324 |
pEnc->mbParam.edged_height); |
pEnc->mbParam.edged_height); |
|
image_destroy(&pEnc->vInterHVf, pEnc->mbParam.edged_width, |
|
|
pEnc->mbParam.edged_height); |
|
325 |
|
|
326 |
xvid_err_memory2: |
xvid_err_memory2: |
327 |
xvid_free(pEnc->current->mbs); |
xvid_free(pEnc->current->mbs); |
363 |
pEnc->mbParam.edged_height); |
pEnc->mbParam.edged_height); |
364 |
image_destroy(&pEnc->vInterV, pEnc->mbParam.edged_width, |
image_destroy(&pEnc->vInterV, pEnc->mbParam.edged_width, |
365 |
pEnc->mbParam.edged_height); |
pEnc->mbParam.edged_height); |
|
image_destroy(&pEnc->vInterVf, pEnc->mbParam.edged_width, |
|
|
pEnc->mbParam.edged_height); |
|
366 |
image_destroy(&pEnc->vInterHV, pEnc->mbParam.edged_width, |
image_destroy(&pEnc->vInterHV, pEnc->mbParam.edged_width, |
367 |
pEnc->mbParam.edged_height); |
pEnc->mbParam.edged_height); |
|
image_destroy(&pEnc->vInterHVf, pEnc->mbParam.edged_width, |
|
|
pEnc->mbParam.edged_height); |
|
368 |
|
|
369 |
#ifdef _DEBUG_PSNR |
#ifdef _DEBUG_PSNR |
370 |
image_destroy(&pEnc->sOriginal, pEnc->mbParam.edged_width, |
image_destroy(&pEnc->sOriginal, pEnc->mbParam.edged_width, |
544 |
emms(); |
emms(); |
545 |
|
|
546 |
if (pFrame->quant == 0) { |
if (pFrame->quant == 0) { |
547 |
RateControlUpdate(&pEnc->rate_control, pEnc->current->quant, |
RateControlUpdate(&pEnc->rate_control, (int16_t)pEnc->current->quant, |
548 |
pFrame->length, pFrame->intra); |
pFrame->length, pFrame->intra); |
549 |
} |
} |
550 |
#ifdef _DEBUG_PSNR |
#ifdef _DEBUG_PSNR |
873 |
DECLARE_ALIGNED_MATRIX(qcoeff, 6, 64, int16_t, CACHE_LINE); |
DECLARE_ALIGNED_MATRIX(qcoeff, 6, 64, int16_t, CACHE_LINE); |
874 |
|
|
875 |
int iLimit; |
int iLimit; |
876 |
int x, y, k; |
unsigned int x, y; |
877 |
int iSearchRange; |
int iSearchRange; |
878 |
int bIntra; |
int bIntra; |
879 |
|
|
882 |
|
|
883 |
start_timer(); |
start_timer(); |
884 |
image_setedges(pRef, pEnc->mbParam.edged_width, pEnc->mbParam.edged_height, |
image_setedges(pRef, pEnc->mbParam.edged_width, pEnc->mbParam.edged_height, |
885 |
pEnc->mbParam.width, pEnc->mbParam.height, |
pEnc->mbParam.width, pEnc->mbParam.height); |
|
pEnc->current->global_flags & XVID_INTERLACING); |
|
886 |
stop_edges_timer(); |
stop_edges_timer(); |
887 |
|
|
888 |
pEnc->mbParam.m_rounding_type = 1 - pEnc->mbParam.m_rounding_type; |
pEnc->mbParam.m_rounding_type = 1 - pEnc->mbParam.m_rounding_type; |
983 |
CodeIntraMB(pEnc, pMB); |
CodeIntraMB(pEnc, pMB); |
984 |
MBTransQuantIntra(&pEnc->mbParam, pEnc->current, pMB, x, y, |
MBTransQuantIntra(&pEnc->mbParam, pEnc->current, pMB, x, y, |
985 |
dct_codes, qcoeff); |
dct_codes, qcoeff); |
|
} |
|
986 |
|
|
987 |
start_timer(); |
start_timer(); |
988 |
MBPrediction(pEnc->current, x, y, pEnc->mbParam.mb_width, qcoeff); |
MBPrediction(pEnc->current, x, y, pEnc->mbParam.mb_width, qcoeff); |
989 |
stop_prediction_timer(); |
stop_prediction_timer(); |
990 |
|
} |
991 |
|
|
992 |
if (pMB->mode == MODE_INTRA || pMB->mode == MODE_INTRA_Q) { |
if (pMB->mode == MODE_INTRA || pMB->mode == MODE_INTRA_Q) { |
993 |
pEnc->sStat.kblks++; |
pEnc->sStat.kblks++; |