Mercurial > libavcodec.hg
changeset 4036:207c22206d53 libavcodec
Implement sws_getCachedContext() in swscale emulation
author | lucabe |
---|---|
date | Tue, 17 Oct 2006 10:26:37 +0000 |
parents | b7f31a32bb30 |
children | 53be304c7f54 |
files | imgresample.c swscale.h |
diffstat | 2 files changed, 41 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/imgresample.c Tue Oct 17 09:38:37 2006 +0000 +++ b/imgresample.c Tue Oct 17 10:26:37 2006 +0000 @@ -676,6 +676,42 @@ 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[]) {
--- a/swscale.h Tue Oct 17 09:38:37 2006 +0000 +++ b/swscale.h Tue Oct 17 10:26:37 2006 +0000 @@ -54,6 +54,11 @@ 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