summaryrefslogtreecommitdiff
path: root/libswscale
diff options
context:
space:
mode:
authorVĂ­ctor Paesa <wzrlpy@arsystel.com>2006-09-04 09:38:24 +0000
committerGuillaume Poirier <gpoirier@mplayerhq.hu>2006-09-04 09:38:24 +0000
commit22e469590583ebff6305698f0a49676007a6509a (patch)
tree31871ec7e5e87808d1ed18ef9068582b158af3fe /libswscale
parentd67898427b82f1fa92b32256d76ba7222d92c7ba (diff)
Add sws_getCachedContext(), which checks if context is valid or reallocs a new one instead.
Patch by Victor Paesa <wzrlpy@arsystel.com> Original thread: Date: Aug 31, 2006 7:15 PM Subject: [Ffmpeg-devel] [PATCH] Add sws_getCachedContext() to swscale library Originally committed as revision 19667 to svn://svn.mplayerhq.hu/mplayer/trunk/libswscale
Diffstat (limited to 'libswscale')
-rw-r--r--libswscale/swscale.c34
-rw-r--r--libswscale/swscale.h5
2 files changed, 39 insertions, 0 deletions
diff --git a/libswscale/swscale.c b/libswscale/swscale.c
index fc5690c738..7a8c202fcb 100644
--- a/libswscale/swscale.c
+++ b/libswscale/swscale.c
@@ -2754,3 +2754,37 @@ void sws_freeContext(SwsContext *c){
av_free(c);
}
+/**
+ * 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 *context,
+ int srcW, int srcH, int srcFormat,
+ int dstW, int dstH, int dstFormat, int flags,
+ SwsFilter *srcFilter, SwsFilter *dstFilter, double *param)
+{
+ if (context != NULL) {
+ if ((context->srcW != srcW) || (context->srcH != srcH) ||
+ (context->srcFormat != srcFormat) ||
+ (context->dstW != dstW) || (context->dstH != dstH) ||
+ (context->dstFormat != dstFormat) || (context->flags != flags) ||
+ (context->param != param))
+ {
+ sws_freeContext(context);
+ context = NULL;
+ }
+ }
+ if (context == NULL) {
+ return sws_getContext(srcW, srcH, srcFormat,
+ dstW, dstH, dstFormat, flags,
+ srcFilter, dstFilter, param);
+ }
+ return context;
+}
+
diff --git a/libswscale/swscale.h b/libswscale/swscale.h
index 2b558a25b7..ace89fa292 100644
--- a/libswscale/swscale.h
+++ b/libswscale/swscale.h
@@ -135,6 +135,11 @@ SwsFilter *sws_getDefaultFilter(float lumaGBlur, float chromaGBlur,
int verbose);
void sws_freeFilter(SwsFilter *filter);
+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