changeset 32127:24299859359f

swscale-test: move conversion from ref to source back to doTest() The source format parameters are kept in static variables and conversion from ref to source is only made when any parameter changes.
author ramiro
date Sun, 12 Sep 2010 18:14:42 +0000
parents 98f341e62270
children b294dffc2abd
files libswscale/swscale-test.c
diffstat 1 files changed, 43 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/libswscale/swscale-test.c	Sun Sep 12 17:05:44 2010 +0000
+++ b/libswscale/swscale-test.c	Sun Sep 12 18:14:42 2010 +0000
@@ -74,10 +74,13 @@
 // test by ref -> src -> dst -> out & compare out against ref
 // ref & out are YV12
 static int doTest(uint8_t *ref[4], int refStride[4], int w, int h,
-                  uint8_t *src[4], int srcStride[4],
                   enum PixelFormat srcFormat, enum PixelFormat dstFormat,
                   int srcW, int srcH, int dstW, int dstH, int flags)
 {
+    static enum PixelFormat cur_srcFormat;
+    static int cur_srcW, cur_srcH, cur_flags;
+    static uint8_t *src[4];
+    static int srcStride[4];
     uint8_t *dst[4] = {0};
     uint8_t *out[4] = {0};
     int dstStride[4];
@@ -87,6 +90,44 @@
     uint32_t crc = 0;
     int res = 0;
 
+    if (cur_srcFormat != srcFormat || cur_srcW != srcW || cur_srcH != srcH || cur_flags != flags) {
+        struct SwsContext *srcContext = NULL;
+        int p;
+
+        for (p = 0; p < 4; p++)
+            if (src[p])
+                av_freep(&src[p]);
+
+        av_image_fill_linesizes(srcStride, srcFormat, srcW);
+        for (p = 0; p < 4; p++) {
+            if (srcStride[p])
+                src[p] = av_mallocz(srcStride[p]*srcH+16);
+            if (srcStride[p] && !src[p]) {
+                perror("Malloc");
+                res = -1;
+
+                goto end;
+            }
+        }
+        srcContext = sws_getContext(w, h, PIX_FMT_YUVA420P, srcW, srcH,
+                                    srcFormat, flags, NULL, NULL, NULL);
+        if (!srcContext) {
+            fprintf(stderr, "Failed to get %s ---> %s\n",
+                    av_pix_fmt_descriptors[PIX_FMT_YUVA420P].name,
+                    av_pix_fmt_descriptors[srcFormat].name);
+            res = -1;
+
+            goto end;
+        }
+        sws_scale(srcContext, ref, refStride, 0, h, src, srcStride);
+        sws_freeContext(srcContext);
+
+        cur_srcFormat = srcFormat;
+        cur_srcW = srcW;
+        cur_srcH = srcH;
+        cur_flags = flags;
+    }
+
     av_image_fill_linesizes(dstStride, dstFormat, dstW);
     for (i=0; i<4; i++) {
         /* Image buffers passed into libswscale can be allocated any way you
@@ -201,39 +242,11 @@
             fflush(stdout);
 
             for (k = 0; flags[k] && !res; k++) {
-                struct SwsContext *srcContext = NULL;
-                uint8_t *src[4] = {0};
-                int srcStride[4];
-                int p;
-                av_image_fill_linesizes(srcStride, srcFormat, srcW);
-                for (p = 0; p < 4; p++) {
-                    if (srcStride[p])
-                        src[p] = av_mallocz(srcStride[p]*srcH+16);
-                    if (srcStride[p] && !src[p]) {
-                        perror("Malloc");
-                        return;
-                    }
-                }
-                srcContext = sws_getContext(w, h, PIX_FMT_YUVA420P, srcW, srcH,
-                                            srcFormat, flags[k], NULL, NULL, NULL);
-                if (!srcContext) {
-                   fprintf(stderr, "Failed to get %s ---> %s\n",
-                            av_pix_fmt_descriptors[PIX_FMT_YUVA420P].name,
-                            av_pix_fmt_descriptors[srcFormat].name);
-                   return;
-                }
-                sws_scale(srcContext, ref, refStride, 0, h, src, srcStride);
-
                 for (i = 0; dstW[i] && !res; i++)
                     for (j = 0; dstH[j] && !res; j++)
-                        res = doTest(ref, refStride, w, h, src, srcStride,
+                        res = doTest(ref, refStride, w, h,
                                      srcFormat, dstFormat,
                                      srcW, srcH, dstW[i], dstH[j], flags[k]);
-
-                sws_freeContext(srcContext);
-                for (p = 0; p < 4; p++)
-                    if (srcStride[p])
-                        av_free(src[p]);
             }
         }
     }