13c79b34495df7d79d74d4b04493b7fe35e09df4
[platform/upstream/gst-plugins-good.git] / gst / smpte / gstmask.c
1 /* GStreamer
2  * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23
24 #include "gstmask.h"
25 #include "paint.h"
26
27 extern void _gst_barboxwipes_register (void);
28
29 static GList *masks = NULL;
30
31 void
32 _gst_mask_init (void)
33 {
34   _gst_barboxwipes_register ();
35 }
36
37 static gint
38 gst_mask_compare (GstMaskDefinition *def1,
39                   GstMaskDefinition *def2)
40 {
41   return (def1->type - def2->type);
42 }
43
44 void
45 _gst_mask_register (GstMaskDefinition *definition)
46 {
47   masks = g_list_insert_sorted (masks, definition, (GCompareFunc) gst_mask_compare);
48 }
49
50 const GList*
51 gst_mask_get_definitions (void)
52 {
53   return masks;
54 }
55
56 static GstMaskDefinition*
57 gst_mask_find_definition (gint type)
58 {
59   GList *walk = masks;
60
61   while (walk) {
62     GstMaskDefinition *def = (GstMaskDefinition *) walk->data;
63
64     if (def->type == type)
65       return def;
66     
67     walk = g_list_next (walk);
68   }
69   return NULL;
70 }
71
72 GstMask*
73 gst_mask_factory_new (gint type, gint bpp, gint width, gint height)
74 {
75   GstMaskDefinition *definition;
76   GstMask *mask = NULL;
77
78   definition = gst_mask_find_definition (type);
79   if (definition) {
80     mask = g_new0 (GstMask, 1);
81
82     mask->type = definition->type;
83     mask->bpp = bpp;
84     mask->width = width;
85     mask->height = height;
86     mask->destroy_func = definition->destroy_func;
87     mask->user_data = definition->user_data;
88     mask->data = g_malloc (width * height * sizeof (guint32));
89
90     if (definition->draw_func)
91       definition->draw_func (mask);
92   }
93
94   return mask;
95 }
96
97 void
98 _gst_mask_default_destroy (GstMask *mask)
99 {
100   g_free (mask->data);
101   g_free (mask);
102 }
103
104 void
105 gst_mask_destroy (GstMask *mask)
106 {
107   if (mask->destroy_func)
108     mask->destroy_func (mask);
109 }