diff options
author | Luca Abeni <lucabe72@email.it> | 2006-10-17 10:26:37 +0000 |
---|---|---|
committer | Luca Abeni <lucabe72@email.it> | 2006-10-17 10:26:37 +0000 |
commit | 96db38083638dd0e271c42aa8ce73eced21eb4cd (patch) | |
tree | fdf0d12d72c546684116636bcf58d1ab3fda053d /libavcodec | |
parent | 4041a495a8a8beec448ac464762e2dcc41cf68a2 (diff) | |
download | ffmpeg-96db38083638dd0e271c42aa8ce73eced21eb4cd.tar.gz |
Implement sws_getCachedContext() in swscale emulation
Originally committed as revision 6718 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec')
-rw-r--r-- | libavcodec/imgresample.c | 36 | ||||
-rw-r--r-- | libavcodec/swscale.h | 5 |
2 files changed, 41 insertions, 0 deletions
diff --git a/libavcodec/imgresample.c b/libavcodec/imgresample.c index 18aec5624f..e294dbc2a6 100644 --- a/libavcodec/imgresample.c +++ b/libavcodec/imgresample.c @@ -676,6 +676,42 @@ void sws_freeContext(struct SwsContext *ctx) av_free(ctx); } + +/** + * Checks if context is valid or reallocs a new one instead. + * If context is NULL, just calls sws_getContext() to get a new one. + * Otherwise, checks if the parameters are the same already saved in context. + * If that is the case, returns the current context. + * Otherwise, frees context and gets a new one. + * + * Be warned that srcFilter, dstFilter are not checked, they are + * asumed to remain valid. + */ +struct SwsContext *sws_getCachedContext(struct SwsContext *ctx, + int srcW, int srcH, int srcFormat, + int dstW, int dstH, int dstFormat, int flags, + SwsFilter *srcFilter, SwsFilter *dstFilter, double *param) +{ + if (ctx != NULL) { + if ((ctx->resampling_ctx->iwidth != srcW) || + (ctx->resampling_ctx->iheight != srcH) || + (ctx->src_pix_fmt != srcFormat) || + (ctx->resampling_ctx->owidth != dstW) || + (ctx->resampling_ctx->oheight != dstH) || + (ctx->dst_pix_fmt != dstFormat)) + { + sws_freeContext(ctx); + ctx = NULL; + } + } + if (ctx == NULL) { + return sws_getContext(srcW, srcH, srcFormat, + dstW, dstH, dstFormat, flags, + srcFilter, dstFilter, param); + } + return ctx; +} + int sws_scale(struct SwsContext *ctx, uint8_t* src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t* dst[], int dstStride[]) { diff --git a/libavcodec/swscale.h b/libavcodec/swscale.h index 9dc3ca31f5..69d5c0f154 100644 --- a/libavcodec/swscale.h +++ b/libavcodec/swscale.h @@ -54,6 +54,11 @@ int sws_scale(struct SwsContext *ctx, uint8_t* src[], int srcStride[], void sws_freeContext(struct SwsContext *swsContext); +struct SwsContext *sws_getCachedContext(struct SwsContext *context, + int srcW, int srcH, int srcFormat, + int dstW, int dstH, int dstFormat, int flags, + SwsFilter *srcFilter, SwsFilter *dstFilter, double *param); + #ifdef __cplusplus } #endif |