• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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., 51 Franklin St, Fifth Floor,
17  * Boston, MA 02110-1301, 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 static GList *masks = NULL;
28 
29 void
_gst_mask_init(void)30 _gst_mask_init (void)
31 {
32   _gst_barboxwipes_register ();
33 }
34 
35 static gint
gst_mask_compare(GstMaskDefinition * def1,GstMaskDefinition * def2)36 gst_mask_compare (GstMaskDefinition * def1, GstMaskDefinition * def2)
37 {
38   return (def1->type - def2->type);
39 }
40 
41 void
_gst_mask_register(const GstMaskDefinition * definition)42 _gst_mask_register (const GstMaskDefinition * definition)
43 {
44   masks =
45       g_list_insert_sorted (masks, (gpointer) definition,
46       (GCompareFunc) gst_mask_compare);
47 }
48 
49 const GList *
gst_mask_get_definitions(void)50 gst_mask_get_definitions (void)
51 {
52   return masks;
53 }
54 
55 static GstMaskDefinition *
gst_mask_find_definition(gint type)56 gst_mask_find_definition (gint type)
57 {
58   GList *walk = masks;
59 
60   while (walk) {
61     GstMaskDefinition *def = (GstMaskDefinition *) walk->data;
62 
63     if (def->type == type)
64       return def;
65 
66     walk = g_list_next (walk);
67   }
68   return NULL;
69 }
70 
71 GstMask *
gst_mask_factory_new(gint type,gboolean invert,gint bpp,gint width,gint height)72 gst_mask_factory_new (gint type, gboolean invert, gint bpp, gint width,
73     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 
89     if (((guint64) width * (guint64) height * sizeof (guint32)) > G_MAXUINT) {
90       GST_WARNING ("width x height overflows");
91       g_free (mask);
92       return NULL;
93     }
94 
95     mask->data = g_malloc (width * height * sizeof (guint32));
96 
97     definition->draw_func (mask);
98 
99     if (invert) {
100       gint i, j;
101       guint32 *datap = mask->data;
102       guint32 max = (1 << bpp);
103 
104       for (i = 0; i < height; i++) {
105         for (j = 0; j < width; j++) {
106           *datap = max - *datap;
107           datap++;
108         }
109       }
110     }
111   }
112 
113   return mask;
114 }
115 
116 void
_gst_mask_default_destroy(GstMask * mask)117 _gst_mask_default_destroy (GstMask * mask)
118 {
119   g_free (mask->data);
120   g_free (mask);
121 }
122 
123 void
gst_mask_destroy(GstMask * mask)124 gst_mask_destroy (GstMask * mask)
125 {
126   if (mask->destroy_func)
127     mask->destroy_func (mask);
128 }
129