summaryrefslogtreecommitdiffstats
path: root/core/Scale.c
diff options
context:
space:
mode:
authorhandbrake <[email protected]>2006-01-14 13:34:42 +0000
committerhandbrake <[email protected]>2006-01-14 13:34:42 +0000
commitd35a2a23fe450c88925128b9db7c63a5f1ed395d (patch)
treeed7f6b0e4b1f118b0209c606448b693b822020fb /core/Scale.c
parent60925e41e540e9c79b522f4864296bc425fcc9e4 (diff)
HandBrake 0.6.2
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@15 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'core/Scale.c')
-rw-r--r--core/Scale.c194
1 files changed, 41 insertions, 153 deletions
diff --git a/core/Scale.c b/core/Scale.c
index 527882539..2908d6456 100644
--- a/core/Scale.c
+++ b/core/Scale.c
@@ -1,4 +1,4 @@
-/* $Id: Scale.c,v 1.10 2004/03/08 11:32:48 titer Exp $
+/* $Id: Scale.c,v 1.14 2004/05/02 16:25:00 titer Exp $
This file is part of the HandBrake source code.
Homepage: <http://handbrake.m0k.org/>.
@@ -6,13 +6,9 @@
#include "HBInternal.h"
-#define USE_FFMPEG
-
-#ifdef USE_FFMPEG
#include "ffmpeg/avcodec.h"
-#endif
-typedef struct HBScale
+struct HBWork
{
HB_WORK_COMMON_MEMBERS
@@ -20,114 +16,74 @@ typedef struct HBScale
HBTitle * title;
HBBuffer * deintBuffer;
- HBList * scaledBufferList;
-#ifdef USE_FFMPEG
ImgReSampleContext * context;
AVPicture rawPicture;
AVPicture deintPicture;
AVPicture scaledPicture;
-#endif
-} HBScale;
+};
/* Local prototypes */
static int ScaleWork( HBWork * );
-#ifndef USE_FFMPEG
-static void Deinterlace( uint8_t * in, uint8_t * out, int w, int h,
- int tcrop, int bcrop, int lcrop, int rcrop );
-static void Resample( uint8_t * in, uint8_t * out, int oldw, int oldh,
- int neww, int newh, int tcrop, int bcrop,
- int lcrop, int rcrop );
-#endif
HBWork * HBScaleInit( HBHandle * handle, HBTitle * title )
{
- HBScale * s;
- if( !( s = malloc( sizeof( HBScale ) ) ) )
+ HBWork * w;
+ if( !( w = malloc( sizeof( HBWork ) ) ) )
{
HBLog( "HBScaleInit: malloc() failed, gonna crash" );
return NULL;
}
- s->name = strdup( "Scale" );
- s->work = ScaleWork;
+ w->name = strdup( "Scale" );
+ w->work = ScaleWork;
- s->handle = handle;
- s->title = title;
+ w->handle = handle;
+ w->title = title;
/* Allocate a constant buffer used for deinterlacing */
- s->deintBuffer = HBBufferInit( 3 * title->inWidth *
- title->inHeight / 2 );
+ w->deintBuffer = HBBufferInit( 3 * title->inWidth *
+ title->inHeight / 2 );
-#ifdef USE_FFMPEG
- avpicture_fill( &s->deintPicture, s->deintBuffer->data,
+ avpicture_fill( &w->deintPicture, w->deintBuffer->data,
PIX_FMT_YUV420P, title->inWidth, title->inHeight );
/* Init libavcodec */
- s->context =
+ w->context =
img_resample_full_init( title->outWidth, title->outHeight,
title->inWidth, title->inHeight,
title->topCrop, title->bottomCrop,
title->leftCrop, title->rightCrop );
-#endif
-
- s->scaledBufferList = HBListInit();
- return (HBWork*) s;
+ return w;
}
-void HBScaleClose( HBWork ** _s )
+void HBScaleClose( HBWork ** _w )
{
- HBScale * s = (HBScale*) *_s;
-
-#ifdef USE_FFMPEG
- img_resample_close( s->context );
-#endif
- HBListClose( &s->scaledBufferList );
- HBBufferClose( &s->deintBuffer );
- free( s->name );
- free( s );
+ HBWork * w = *_w;
- *_s = NULL;
+ img_resample_close( w->context );
+ HBBufferClose( &w->deintBuffer );
+ free( w->name );
+ free( w );
+ *_w = NULL;
}
static int ScaleWork( HBWork * w )
{
- HBScale * s = (HBScale*) w;
- HBTitle * title = s->title;
+ HBTitle * title = w->title;
HBBuffer * rawBuffer;
HBBuffer * scaledBuffer;
HBBuffer * tmpBuffer;
-#ifndef USE_FFMPEG
- uint8_t * in, * out;
- int plane, shift;
-#endif
- int didSomething = 0;
-
- /* Push scaled buffer(s) */
- while( ( scaledBuffer = (HBBuffer*)
- HBListItemAt( s->scaledBufferList, 0 ) ) )
+ if( HBFifoIsHalfFull( title->scaledFifo ) )
{
- tmpBuffer = scaledBuffer;
- if( HBFifoPush( title->scaledFifo, &scaledBuffer ) )
- {
- didSomething = 1;
- HBListRemove( s->scaledBufferList, tmpBuffer );
- }
- else
- {
- return didSomething;
- }
+ return 0;
}
/* Get a new raw picture */
- if( ( rawBuffer = HBFifoPop( title->rawFifo ) ) )
- {
- didSomething = 1;
- }
- else
+ if( !( rawBuffer = HBFifoPop( title->rawFifo ) ) )
{
- return didSomething;
+ return 0;
}
/* Allocate new buffer for the scaled picture */
@@ -136,62 +92,26 @@ static int ScaleWork( HBWork * w )
scaledBuffer->position = rawBuffer->position;
scaledBuffer->pass = rawBuffer->pass;
-#ifdef USE_FFMPEG
/* libavcodec stuff */
- avpicture_fill( &s->rawPicture, rawBuffer->data, PIX_FMT_YUV420P,
+ avpicture_fill( &w->rawPicture, rawBuffer->data, PIX_FMT_YUV420P,
title->inWidth, title->inHeight );
- avpicture_fill( &s->scaledPicture, scaledBuffer->data,
+ avpicture_fill( &w->scaledPicture, scaledBuffer->data,
PIX_FMT_YUV420P, title->outWidth,
title->outHeight );
/* Do the job */
if( title->deinterlace )
{
- avpicture_deinterlace( &s->deintPicture, &s->rawPicture,
+ avpicture_deinterlace( &w->deintPicture, &w->rawPicture,
PIX_FMT_YUV420P, title->inWidth,
title->inHeight );
- img_resample( s->context, &s->scaledPicture,
- &s->deintPicture );
+ img_resample( w->context, &w->scaledPicture,
+ &w->deintPicture );
}
else
{
- img_resample( s->context, &s->scaledPicture, &s->rawPicture );
- }
-#else
- if( title->deinterlace )
- {
- in = rawBuffer->data;
- out = s->deintBuffer->data;
- for( plane = 0; plane < 3; plane++ )
- {
- shift = plane ? 1 : 0;
- Deinterlace( in, out, title->inWidth >> shift,
- title->inHeight >> shift,
- title->topCrop >> shift,
- title->bottomCrop >> shift,
- title->leftCrop >> shift,
- title->rightCrop >> shift );
- in += title->inWidth * title->inHeight >> ( 2 * shift );
- out += title->inWidth * title->inHeight >> ( 2 * shift );
- }
- }
-
- in = title->deinterlace ? s->deintBuffer->data : rawBuffer->data;
- out = scaledBuffer->data;
- for( plane = 0; plane < 3; plane++ )
- {
- shift = plane ? 1 : 0;
- Resample( in, out, title->inWidth >> shift,
- title->inHeight >> shift, title->outWidth >> shift,
- title->outHeight >> shift, title->topCrop >> shift,
- title->bottomCrop >> shift, title->leftCrop >> shift,
- title->rightCrop >> shift );
- in += title->inWidth * title->inHeight >> ( 2 * shift );
- out += title->outWidth * title->outHeight >> ( 2 * shift );;
+ img_resample( w->context, &w->scaledPicture, &w->rawPicture );
}
-#endif
-
- HBListAdd( s->scaledBufferList, scaledBuffer );
if( rawBuffer->repeat )
{
@@ -201,52 +121,20 @@ static int ScaleWork( HBWork * w )
memcpy( tmpBuffer->data, scaledBuffer->data,
scaledBuffer->size );
- HBListAdd( s->scaledBufferList, tmpBuffer );
- }
-
- /* Free memory */
- HBBufferClose( &rawBuffer );
-
- return didSomething;
-}
-
-#ifndef USE_FFMPEG
-static void Deinterlace( uint8_t * in, uint8_t * out, int w, int h,
- int tcrop, int bcrop, int lcrop, int rcrop )
-{
- int i, j;
-
- /* First line */
- if( !tcrop )
- {
- memcpy( out, in + lcrop, w - lcrop - rcrop );
- }
-
- /* Merge lines */
- for( i = MAX( 1, tcrop ); i < h - bcrop; i++ )
- {
- for( j = lcrop; j < w - rcrop; j++ )
+ if( !HBFifoPush( title->scaledFifo, &tmpBuffer ) )
{
- out[i*w+j] = ( in[(i-1)*w+j] + in[i*w+j] ) / 2;
+ HBLog( "HBScale: HBFifoPush failed" );
}
}
-}
-static void Resample( uint8_t * in, uint8_t * out, int oldw, int oldh,
- int neww, int newh, int tcrop, int bcrop,
- int lcrop, int rcrop )
-{
- int i, j;
- int cropw = oldw - lcrop - rcrop;
- int croph = oldh - tcrop - bcrop;
- for( i = 0; i < newh; i++ )
+ if( !HBFifoPush( title->scaledFifo, &scaledBuffer ) )
{
- for( j = 0; j < neww; j++ )
- {
- out[i*neww+j] = in[(tcrop+i*croph/newh)*oldw +
- lcrop+j*cropw/neww];
- }
+ HBLog( "HBScale: HBFifoPush failed" );
}
+
+ /* Free memory */
+ HBBufferClose( &rawBuffer );
+
+ return 1;
}
-#endif