[Ffmpeg-devel] [PATCH] watermark.c improvement when using images as input

Mihail Stoyanov screamer
Fri Oct 20 12:28:37 CEST 2006


This patch optimizes watermark.c when using images as input. It will check if the current pixel RGB (of the input image) is equal to the threshold before doing any other calculations, thus skipping useless itterations.

Original watermark.c
-> Convert time: 00:31

Patched watermark.c
-> Convert time: 00:26


It's not a HUGE improvement but still it gives like 15%+ boost when working with huge sources (width 720+) and very small watermark images

Here's the patch

--- watermark_orig.c    2006-10-19 03:19:32.000000000 +0300
+++ watermark.c 2006-10-19 17:48:21.000000000 +0300
@@ -256,35 +256,40 @@
             mpoffs = offsm + (((x * xm_size) / src_width) * 4);
             p_pixel = (uint32_t *)&((pFrameRGB->data[0])[mpoffs]);
             pixelm = *p_pixel;
-            p_pixel = (uint32_t *)&((pict->data[0])[offs]);
-            pixel = *p_pixel;
-//          pixelm = *((uint32_t *)&(pFrameRGB->data[mpoffs]));
-            pixel_meck = pixel & 0xff000000;
+           if (thrR == (int)((pixelm >> 16) & 0xff) &&
+               thrG == (int)((pixelm >> 8) & 0xff) &&
+               thrB == (int)((pixelm >> 0) & 0xff)) {
+               offs += 4;
+           } else {
+               p_pixel = (uint32_t *)&((pict->data[0])[offs]);
+               pixel = *p_pixel;
+               pixel_meck = pixel & 0xff000000;
+
+               // R
+               tmp = (int)((pixel >> 16) & 0xff) + (int)((pixelm >> 16) & 0xff) - thrR;
+               if (tmp > 255) tmp = 255;
+               if (tmp < 0) tmp = 0;
+               pixel_meck |= (tmp << 16) & 0xff0000;
+               // G
+               tmp = (int)((pixel >> 8) & 0xff) + (int)((pixelm >> 8) & 0xff) - thrG;
+               if (tmp > 255) tmp = 255;
+               if (tmp < 0) tmp = 0;
+               pixel_meck |= (tmp << 8) & 0xff00;
+               // B
+               tmp = (int)((pixel >> 0) & 0xff) + (int)((pixelm >> 0) & 0xff) - thrB;
+               if (tmp > 255) tmp = 255;
+               if (tmp < 0) tmp = 0;
+               pixel_meck |= (tmp << 0) & 0xff;
+
+
+               // test:
+               //pixel_meck = pixel & 0xff000000;
+               //pixel_meck |= (pixelm & 0x00ffffff);

-            // R
-            tmp = (int)((pixel >> 16) & 0xff) + (int)((pixelm >> 16) & 0xff) -thrR;
-            if (tmp > 255) tmp = 255;
-            if (tmp < 0) tmp = 0;
-            pixel_meck |= (tmp << 16) & 0xff0000;
-            // G
-            tmp = (int)((pixel >> 8) & 0xff) + (int)((pixelm >> 8) & 0xff) - thrG;
-            if (tmp > 255) tmp = 255;
-            if (tmp < 0) tmp = 0;
-            pixel_meck |= (tmp << 8) & 0xff00;
-            // B
-            tmp = (int)((pixel >> 0) & 0xff) + (int)((pixelm >> 0) & 0xff) - thrB;
-            if (tmp > 255) tmp = 255;
-            if (tmp < 0) tmp = 0;
-            pixel_meck |= (tmp << 0) & 0xff;
-
-
-            // test:
-            //pixel_meck = pixel & 0xff000000;
-            //pixel_meck |= (pixelm & 0x00ffffff);
+                *p_pixel = pixel_meck;

-            *p_pixel = pixel_meck;
-
-            offs += 4;
+               offs += 4;
+           }
         } // foreach X
     } // foreach Y




More information about the ffmpeg-devel mailing list