[FFmpeg-soc] [soc]: r4277 - libavfilter/vf_drawbox.c

stefano subversion at mplayerhq.hu
Sun May 17 15:08:57 CEST 2009


Author: stefano
Date: Sun May 17 15:08:56 2009
New Revision: 4277

Log:
Make use of av_parse_color().

Modified:
   libavfilter/vf_drawbox.c

Modified: libavfilter/vf_drawbox.c
==============================================================================
--- libavfilter/vf_drawbox.c	Sat May 16 18:59:43 2009	(r4276)
+++ libavfilter/vf_drawbox.c	Sun May 17 15:08:56 2009	(r4277)
@@ -26,6 +26,8 @@
 #include <ctype.h>
 
 #include "avfilter.h"
+#include "parseutils.h"
+#include "libavcodec/colorspace.h"
 
 typedef struct
 {
@@ -35,19 +37,6 @@ typedef struct
     unsigned char cr;
 } box_color;
 
-#define NUM_COLORS 8
-static box_color colors[] =
-{
-    {.name = "blue",   .y =  40, .cr = 109, .cb = 240},
-    {.name = "red",    .y =  81, .cr = 240, .cb =  90},
-    {.name = "black",  .y =  16, .cr = 128, .cb = 128},
-    {.name = "white",  .y = 255, .cr = 128, .cb = 128},
-    {.name = "green",  .y = 144, .cr =  34, .cb =  53},
-    {.name = "yellow", .y = 210, .cr = 146, .cb =  16},
-    {.name = "gray",   .y = 128, .cr = 128, .cb = 128},
-    {.name = "grey",   .y = 128, .cr = 128, .cb = 128}
-};
-
 typedef struct
 {
     int x, y, w, h;
@@ -55,34 +44,11 @@ typedef struct
     int vsub, hsub;   //< chroma subsampling
 } BoxContext;
 
-static void box_strlwr(char *str)
-{
-    int i = 0;
-    while(str[i] != '\0') {
-        if(isupper(str[i]))
-            str[i] = tolower(str[i]);
-
-        i++;
-    }
-}
-
-static box_color get_color(char *color)
-{
-    box_color tmp;
-    int i;
-    box_strlwr(color);
-    for(i = NUM_COLORS - 1; i >= 0; i--) {
-        tmp = colors[i];
-        if(!strcmp(color, colors[i].name))
-            break;
-    }
-    return tmp;
-}
-
 static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
 {
     BoxContext *context= ctx->priv;
     char tmp[1024];
+    uint8_t rgba_color[4];
 
     if(!args || strlen(args) > 1024) {
         av_log(ctx, AV_LOG_ERROR, "Invalid arguments!\n");
@@ -92,7 +58,13 @@ static av_cold int init(AVFilterContext 
     sscanf(args, "%d:%d:%d:%d:%s", &(context->x), &(context->y),
            &(context->w), &(context->h), tmp);
 
-    context->color = get_color(tmp);
+    if (av_parse_color(rgba_color, tmp, context) < 0)
+        return -1;
+
+    context->color.y  = RGB_TO_Y(rgba_color[0], rgba_color[1], rgba_color[2]);
+    context->color.cb = RGB_TO_U(rgba_color[0], rgba_color[1], rgba_color[2], 0);
+    context->color.cr = RGB_TO_V(rgba_color[0], rgba_color[1], rgba_color[2], 0);
+
     return 0;
 }
 


More information about the FFmpeg-soc mailing list