[FFmpeg-cvslog] sws: factor out gamma-correct scaling

Anton Khirnov git at videolan.org
Sat Jul 3 17:20:03 EEST 2021


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Wed May 19 10:12:15 2021 +0200| [44f12718bfba8d1dd2e0757c13ddb91ea349f996] | committer: Anton Khirnov

sws: factor out gamma-correct scaling

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=44f12718bfba8d1dd2e0757c13ddb91ea349f996
---

 libswscale/swscale.c | 53 +++++++++++++++++++++++++++++-----------------------
 1 file changed, 30 insertions(+), 23 deletions(-)

diff --git a/libswscale/swscale.c b/libswscale/swscale.c
index 9743c56295..876dc05442 100644
--- a/libswscale/swscale.c
+++ b/libswscale/swscale.c
@@ -811,6 +811,34 @@ static void update_palette(SwsContext *c, const uint32_t *pal)
     }
 }
 
+static int scale_gamma(SwsContext *c,
+                       const uint8_t * const srcSlice[], const int srcStride[],
+                       int srcSliceY, int srcSliceH,
+                       uint8_t * const dst[], const int dstStride[])
+{
+        int ret = sws_scale(c->cascaded_context[0],
+                    srcSlice, srcStride, srcSliceY, srcSliceH,
+                    c->cascaded_tmp, c->cascaded_tmpStride);
+
+        if (ret < 0)
+            return ret;
+
+        if (c->cascaded_context[2])
+            ret = sws_scale(c->cascaded_context[1], (const uint8_t * const *)c->cascaded_tmp, c->cascaded_tmpStride, srcSliceY, srcSliceH, c->cascaded1_tmp, c->cascaded1_tmpStride);
+        else
+            ret = sws_scale(c->cascaded_context[1], (const uint8_t * const *)c->cascaded_tmp, c->cascaded_tmpStride, srcSliceY, srcSliceH, dst, dstStride);
+
+        if (ret < 0)
+            return ret;
+
+        if (c->cascaded_context[2]) {
+            ret = sws_scale(c->cascaded_context[2],
+                        (const uint8_t * const *)c->cascaded1_tmp, c->cascaded1_tmpStride, c->cascaded_context[1]->dstY - ret, c->cascaded_context[1]->dstY,
+                        dst, dstStride);
+        }
+        return ret;
+}
+
 /**
  * swscale wrapper, so we don't need to export the SwsContext.
  * Assumes planar YUV to be in YUV order instead of YVU.
@@ -848,29 +876,8 @@ int attribute_align_arg sws_scale(struct SwsContext *c,
         return AVERROR(EINVAL);
     }
 
-    if (c->gamma_flag && c->cascaded_context[0]) {
-        ret = sws_scale(c->cascaded_context[0],
-                    srcSlice, srcStride, srcSliceY, srcSliceH,
-                    c->cascaded_tmp, c->cascaded_tmpStride);
-
-        if (ret < 0)
-            return ret;
-
-        if (c->cascaded_context[2])
-            ret = sws_scale(c->cascaded_context[1], (const uint8_t * const *)c->cascaded_tmp, c->cascaded_tmpStride, srcSliceY, srcSliceH, c->cascaded1_tmp, c->cascaded1_tmpStride);
-        else
-            ret = sws_scale(c->cascaded_context[1], (const uint8_t * const *)c->cascaded_tmp, c->cascaded_tmpStride, srcSliceY, srcSliceH, dst, dstStride);
-
-        if (ret < 0)
-            return ret;
-
-        if (c->cascaded_context[2]) {
-            ret = sws_scale(c->cascaded_context[2],
-                        (const uint8_t * const *)c->cascaded1_tmp, c->cascaded1_tmpStride, c->cascaded_context[1]->dstY - ret, c->cascaded_context[1]->dstY,
-                        dst, dstStride);
-        }
-        return ret;
-    }
+    if (c->gamma_flag && c->cascaded_context[0])
+        return scale_gamma(c, srcSlice, srcStride, srcSliceY, srcSliceH, dst, dstStride);
 
     if (c->cascaded_context[0] && srcSliceY == 0 && srcSliceH == c->cascaded_context[0]->srcH) {
         ret = sws_scale(c->cascaded_context[0],



More information about the ffmpeg-cvslog mailing list