Reorganize header #includes: Unconditionally #include standard C headers,
[ffmpeg.git] / libavfilter / avfilter.c
index 2582276..1dbc016 100644 (file)
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavcodec/imgconvert.h"
 #include "avfilter.h"
 
+unsigned avfilter_version(void) {
+    return LIBAVFILTER_VERSION_INT;
+}
+
 /** list of registered filters */
 struct FilterList
 {
@@ -85,7 +90,7 @@ int avfilter_link(AVFilterContext *src, unsigned srcpad,
     link->dst     = dst;
     link->srcpad  = srcpad;
     link->dstpad  = dstpad;
-    link->format  = -1;
+    link->format  = PIX_FMT_NONE;
 
     return 0;
 }
@@ -245,6 +250,7 @@ void avfilter_draw_slice(AVFilterLink *link, int y, int h)
 {
     uint8_t *src[4], *dst[4];
     int i, j, hsub, vsub;
+    void (*draw_slice)(AVFilterLink *, int, int);
 
     /* copy the slice if needed for permission reasons */
     if(link->srcpic) {
@@ -261,18 +267,22 @@ void avfilter_draw_slice(AVFilterLink *link, int y, int h)
         }
 
         for(i = 0; i < 4; i ++) {
+            int planew =
+                ff_get_plane_bytewidth(link->format, link->cur_pic->w, i);
+
             if(!src[i]) continue;
 
             for(j = 0; j < h >> (i==0 ? 0 : vsub); j ++) {
-                memcpy(dst[i], src[i], link->cur_pic->linesize[i]);
+                memcpy(dst[i], src[i], planew);
                 src[i] += link->srcpic ->linesize[i];
                 dst[i] += link->cur_pic->linesize[i];
             }
         }
     }
 
-    if(link_dpad(link).draw_slice)
-        link_dpad(link).draw_slice(link, y, h);
+    if(!(draw_slice = link_dpad(link).draw_slice))
+        draw_slice = avfilter_default_draw_slice;
+    draw_slice(link, y, h);
 }
 
 AVFilter *avfilter_get_by_name(const char *name)
@@ -319,6 +329,11 @@ static const char *filter_name(void *p)
     return filter->filter->name;
 }
 
+static const AVClass avfilter_class = {
+    "AVFilter",
+    filter_name
+};
+
 AVFilterContext *avfilter_open(AVFilter *filter, const char *inst_name)
 {
     AVFilterContext *ret;
@@ -326,23 +341,26 @@ AVFilterContext *avfilter_open(AVFilter *filter, const char *inst_name)
     if (!filter)
         return 0;
 
-    ret = av_malloc(sizeof(AVFilterContext));
+    ret = av_mallocz(sizeof(AVFilterContext));
 
-    ret->av_class = av_mallocz(sizeof(AVClass));
-    ret->av_class->item_name = filter_name;
+    ret->av_class = &avfilter_class;
     ret->filter   = filter;
     ret->name     = inst_name ? av_strdup(inst_name) : NULL;
     ret->priv     = av_mallocz(filter->priv_size);
 
     ret->input_count  = pad_count(filter->inputs);
-    ret->input_pads   = av_malloc(sizeof(AVFilterPad) * ret->input_count);
-    memcpy(ret->input_pads, filter->inputs, sizeof(AVFilterPad)*ret->input_count);
-    ret->inputs       = av_mallocz(sizeof(AVFilterLink*) * ret->input_count);
+    if (ret->input_count) {
+        ret->input_pads   = av_malloc(sizeof(AVFilterPad) * ret->input_count);
+        memcpy(ret->input_pads, filter->inputs, sizeof(AVFilterPad) * ret->input_count);
+        ret->inputs       = av_mallocz(sizeof(AVFilterLink*) * ret->input_count);
+    }
 
     ret->output_count = pad_count(filter->outputs);
-    ret->output_pads  = av_malloc(sizeof(AVFilterPad) * ret->output_count);
-    memcpy(ret->output_pads, filter->outputs, sizeof(AVFilterPad)*ret->output_count);
-    ret->outputs      = av_mallocz(sizeof(AVFilterLink*) * ret->output_count);
+    if (ret->output_count) {
+        ret->output_pads  = av_malloc(sizeof(AVFilterPad) * ret->output_count);
+        memcpy(ret->output_pads, filter->outputs, sizeof(AVFilterPad) * ret->output_count);
+        ret->outputs      = av_mallocz(sizeof(AVFilterLink*) * ret->output_count);
+    }
 
     return ret;
 }
@@ -371,7 +389,6 @@ void avfilter_destroy(AVFilterContext *filter)
     av_freep(&filter->inputs);
     av_freep(&filter->outputs);
     av_freep(&filter->priv);
-    av_freep(&filter->av_class);
     av_free(filter);
 }