gstmask.c 2.61 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/* GStreamer
 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
Tim-Philipp Müller's avatar
Tim-Philipp Müller committed
16 17
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA 02110-1301, USA.
18 19
 */

20 21 22
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
23 24

#include "gstmask.h"
25
#include "paint.h"
26 27 28 29 30 31 32 33 34 35

static GList *masks = NULL;

void
_gst_mask_init (void)
{
  _gst_barboxwipes_register ();
}

static gint
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
36
gst_mask_compare (GstMaskDefinition * def1, GstMaskDefinition * def2)
37 38 39 40 41
{
  return (def1->type - def2->type);
}

void
42
_gst_mask_register (const GstMaskDefinition * definition)
43
{
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
44
  masks =
45 46
      g_list_insert_sorted (masks, (gpointer) definition,
      (GCompareFunc) gst_mask_compare);
47 48
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
49
const GList *
50 51 52 53 54
gst_mask_get_definitions (void)
{
  return masks;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
55
static GstMaskDefinition *
56 57 58 59 60 61 62 63 64
gst_mask_find_definition (gint type)
{
  GList *walk = masks;

  while (walk) {
    GstMaskDefinition *def = (GstMaskDefinition *) walk->data;

    if (def->type == type)
      return def;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
65

66 67 68 69 70
    walk = g_list_next (walk);
  }
  return NULL;
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
71
GstMask *
72 73
gst_mask_factory_new (gint type, gboolean invert, gint bpp, gint width,
    gint height)
74 75 76 77 78 79
{
  GstMaskDefinition *definition;
  GstMask *mask = NULL;

  definition = gst_mask_find_definition (type);
  if (definition) {
80 81 82 83 84 85 86 87 88 89
    mask = g_new0 (GstMask, 1);

    mask->type = definition->type;
    mask->bpp = bpp;
    mask->width = width;
    mask->height = height;
    mask->destroy_func = definition->destroy_func;
    mask->user_data = definition->user_data;
    mask->data = g_malloc (width * height * sizeof (guint32));

90 91 92 93 94 95 96 97 98 99 100 101 102 103
    definition->draw_func (mask);

    if (invert) {
      gint i, j;
      guint32 *datap = mask->data;
      guint32 max = (1 << bpp);

      for (i = 0; i < height; i++) {
        for (j = 0; j < width; j++) {
          *datap = max - *datap;
          datap++;
        }
      }
    }
104 105 106 107 108 109
  }

  return mask;
}

void
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
110
_gst_mask_default_destroy (GstMask * mask)
111 112 113 114 115 116
{
  g_free (mask->data);
  g_free (mask);
}

void
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
117
gst_mask_destroy (GstMask * mask)
118 119 120 121
{
  if (mask->destroy_func)
    mask->destroy_func (mask);
}