2002-04-24 21:03:10 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
*
|
|
|
|
* dice.c: a 'dicing' effect
|
|
|
|
* copyright (c) 2001 Sam Mertens. This code is subject to the provisions of
|
2002-08-14 21:01:38 +00:00
|
|
|
* the GNU Library Public License.
|
2002-04-24 21:03:10 +00:00
|
|
|
*
|
|
|
|
* I suppose this looks similar to PuzzleTV, but it's not. The screen is
|
|
|
|
* divided into small squares, each of which is rotated either 0, 90, 180 or
|
|
|
|
* 270 degrees. The amount of rotation for each square is chosen at random.
|
|
|
|
*/
|
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2002-04-24 21:03:10 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <gst/gst.h>
|
2004-03-12 13:56:51 +00:00
|
|
|
#include <gstvideofilter.h>
|
2002-04-24 21:03:10 +00:00
|
|
|
|
|
|
|
#define GST_TYPE_DICETV \
|
|
|
|
(gst_dicetv_get_type())
|
|
|
|
#define GST_DICETV(obj) \
|
|
|
|
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_DICETV,GstDiceTV))
|
|
|
|
#define GST_DICETV_CLASS(klass) \
|
2004-03-12 13:56:51 +00:00
|
|
|
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_DICETV,GstDiceTVClass))
|
2002-04-24 21:03:10 +00:00
|
|
|
#define GST_IS_DICETV(obj) \
|
|
|
|
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_DICETV))
|
|
|
|
#define GST_IS_DICETV_CLASS(obj) \
|
|
|
|
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_DICETV))
|
|
|
|
|
|
|
|
typedef struct _GstDiceTV GstDiceTV;
|
|
|
|
typedef struct _GstDiceTVClass GstDiceTVClass;
|
|
|
|
|
|
|
|
#define DEFAULT_CUBE_BITS 4
|
|
|
|
#define MAX_CUBE_BITS 5
|
|
|
|
#define MIN_CUBE_BITS 0
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
typedef enum _dice_dir
|
2002-04-24 21:03:10 +00:00
|
|
|
{
|
2004-03-14 22:34:33 +00:00
|
|
|
DICE_UP = 0,
|
|
|
|
DICE_RIGHT = 1,
|
|
|
|
DICE_DOWN = 2,
|
|
|
|
DICE_LEFT = 3
|
2004-03-15 19:32:27 +00:00
|
|
|
}
|
|
|
|
DiceDir;
|
2002-04-24 21:03:10 +00:00
|
|
|
|
|
|
|
struct _GstDiceTV
|
|
|
|
{
|
2004-03-12 13:56:51 +00:00
|
|
|
GstVideofilter videofilter;
|
2002-04-24 21:03:10 +00:00
|
|
|
|
|
|
|
gint width, height;
|
2004-03-14 22:34:33 +00:00
|
|
|
gchar *dicemap;
|
2002-04-24 21:03:10 +00:00
|
|
|
|
|
|
|
gint g_cube_bits;
|
|
|
|
gint g_cube_size;
|
|
|
|
gint g_map_height;
|
|
|
|
gint g_map_width;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _GstDiceTVClass
|
|
|
|
{
|
2004-03-12 13:56:51 +00:00
|
|
|
GstVideofilterClass parent_class;
|
2002-04-24 21:03:10 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
void (*reset) (GstElement * element);
|
2002-04-24 21:03:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Filter signals and args */
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
/* FILL ME */
|
|
|
|
RESET_SIGNAL,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
ARG_0,
|
2004-05-21 22:39:30 +00:00
|
|
|
ARG_CUBE_BITS
|
2002-04-24 21:03:10 +00:00
|
|
|
};
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void gst_dicetv_base_init (gpointer g_class);
|
|
|
|
static void gst_dicetv_class_init (gpointer g_class, gpointer class_data);
|
|
|
|
static void gst_dicetv_init (GTypeInstance * instance, gpointer g_class);
|
2002-04-24 21:03:10 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void gst_dicetv_reset_handler (GstElement * elem);
|
|
|
|
static void gst_dicetv_create_map (GstDiceTV * filter);
|
2002-04-24 21:03:10 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void gst_dicetv_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_dicetv_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_dicetv_setup (GstVideofilter * videofilter);
|
|
|
|
static void gst_dicetv_draw (GstVideofilter * videofilter, void *d, void *s);
|
2002-04-24 21:03:10 +00:00
|
|
|
|
|
|
|
static guint gst_dicetv_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
GType
|
|
|
|
gst_dicetv_get_type (void)
|
2002-04-24 21:03:10 +00:00
|
|
|
{
|
|
|
|
static GType dicetv_type = 0;
|
|
|
|
|
|
|
|
if (!dicetv_type) {
|
|
|
|
static const GTypeInfo dicetv_info = {
|
2004-03-14 22:34:33 +00:00
|
|
|
sizeof (GstDiceTVClass),
|
2003-11-02 12:48:08 +00:00
|
|
|
gst_dicetv_base_init,
|
2002-04-24 21:03:10 +00:00
|
|
|
NULL,
|
|
|
|
(GClassInitFunc) gst_dicetv_class_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
sizeof (GstDiceTV),
|
|
|
|
0,
|
|
|
|
(GInstanceInitFunc) gst_dicetv_init,
|
|
|
|
};
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
dicetv_type =
|
2004-03-15 19:32:27 +00:00
|
|
|
g_type_register_static (GST_TYPE_VIDEOFILTER, "GstDiceTV", &dicetv_info,
|
|
|
|
0);
|
2002-04-24 21:03:10 +00:00
|
|
|
}
|
|
|
|
return dicetv_type;
|
|
|
|
}
|
|
|
|
|
2004-03-12 13:56:51 +00:00
|
|
|
static GstVideofilterFormat gst_dicetv_formats[] = {
|
2004-03-14 22:34:33 +00:00
|
|
|
{"RGB ", 32, gst_dicetv_draw, 24, G_BIG_ENDIAN, 0x00ff0000, 0x0000ff00,
|
|
|
|
0x000000ff},
|
|
|
|
{"RGB ", 32, gst_dicetv_draw, 24, G_BIG_ENDIAN, 0xff000000, 0x00ff0000,
|
|
|
|
0x0000ff00},
|
|
|
|
{"RGB ", 32, gst_dicetv_draw, 24, G_BIG_ENDIAN, 0x000000ff, 0x0000ff00,
|
|
|
|
0x00ff0000},
|
|
|
|
{"RGB ", 32, gst_dicetv_draw, 24, G_BIG_ENDIAN, 0x0000ff00, 0x00ff0000,
|
|
|
|
0xff000000},
|
2004-03-12 13:56:51 +00:00
|
|
|
};
|
|
|
|
|
2003-11-02 12:48:08 +00:00
|
|
|
static void
|
|
|
|
gst_dicetv_base_init (gpointer g_class)
|
|
|
|
{
|
2004-03-12 13:56:51 +00:00
|
|
|
/* elementfactory information */
|
2004-03-14 22:34:33 +00:00
|
|
|
static GstElementDetails gst_dicetv_details = GST_ELEMENT_DETAILS ("DiceTV",
|
|
|
|
"Filter/Effect/Video",
|
|
|
|
"'Dices' the screen up into many small squares",
|
|
|
|
"Wim Taymans <wim.taymans@chello.be>");
|
2003-11-02 12:48:08 +00:00
|
|
|
|
2004-03-12 13:56:51 +00:00
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
|
|
|
GstVideofilterClass *videofilter_class = GST_VIDEOFILTER_CLASS (g_class);
|
|
|
|
int i;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-11-02 12:48:08 +00:00
|
|
|
gst_element_class_set_details (element_class, &gst_dicetv_details);
|
2004-03-12 13:56:51 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
for (i = 0; i < G_N_ELEMENTS (gst_dicetv_formats); i++) {
|
|
|
|
gst_videofilter_class_add_format (videofilter_class,
|
2004-03-15 19:32:27 +00:00
|
|
|
gst_dicetv_formats + i);
|
2004-03-12 13:56:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gst_videofilter_class_add_pad_templates (GST_VIDEOFILTER_CLASS (g_class));
|
2003-11-02 12:48:08 +00:00
|
|
|
}
|
|
|
|
|
2002-04-24 21:03:10 +00:00
|
|
|
static void
|
2004-03-12 13:56:51 +00:00
|
|
|
gst_dicetv_class_init (gpointer g_class, gpointer class_data)
|
2002-04-24 21:03:10 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
2004-03-12 13:56:51 +00:00
|
|
|
GstVideofilterClass *videofilter_class;
|
|
|
|
GstDiceTVClass *dicetv_class;
|
2002-04-24 21:03:10 +00:00
|
|
|
|
2004-03-12 13:56:51 +00:00
|
|
|
gobject_class = G_OBJECT_CLASS (g_class);
|
|
|
|
videofilter_class = GST_VIDEOFILTER_CLASS (g_class);
|
|
|
|
dicetv_class = GST_DICETV_CLASS (g_class);
|
2002-04-24 21:03:10 +00:00
|
|
|
|
|
|
|
gst_dicetv_signals[RESET_SIGNAL] =
|
2004-03-14 22:34:33 +00:00
|
|
|
g_signal_new ("reset",
|
|
|
|
G_TYPE_FROM_CLASS (g_class),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (GstDiceTVClass, reset),
|
|
|
|
NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
|
2002-04-24 21:03:10 +00:00
|
|
|
|
2004-03-12 13:56:51 +00:00
|
|
|
dicetv_class->reset = gst_dicetv_reset_handler;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2004-03-12 13:56:51 +00:00
|
|
|
g_object_class_install_property (gobject_class, ARG_CUBE_BITS,
|
2004-03-14 22:34:33 +00:00
|
|
|
g_param_spec_int ("square_bits", "Square Bits", "The size of the Squares",
|
2004-03-15 19:32:27 +00:00
|
|
|
MIN_CUBE_BITS, MAX_CUBE_BITS, DEFAULT_CUBE_BITS, G_PARAM_READWRITE));
|
2002-04-24 21:03:10 +00:00
|
|
|
|
|
|
|
gobject_class->set_property = gst_dicetv_set_property;
|
|
|
|
gobject_class->get_property = gst_dicetv_get_property;
|
2004-03-12 13:56:51 +00:00
|
|
|
|
|
|
|
videofilter_class->setup = gst_dicetv_setup;
|
2002-04-24 21:03:10 +00:00
|
|
|
}
|
|
|
|
|
2004-03-12 13:56:51 +00:00
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_dicetv_setup (GstVideofilter * videofilter)
|
2002-04-24 21:03:10 +00:00
|
|
|
{
|
2004-03-12 13:56:51 +00:00
|
|
|
GstDiceTV *dicetv;
|
2002-04-24 21:03:10 +00:00
|
|
|
|
2004-03-12 13:56:51 +00:00
|
|
|
g_return_if_fail (GST_IS_DICETV (videofilter));
|
|
|
|
dicetv = GST_DICETV (videofilter);
|
2002-04-24 21:03:10 +00:00
|
|
|
|
2004-03-12 13:56:51 +00:00
|
|
|
dicetv->width = gst_videofilter_get_input_width (videofilter);
|
|
|
|
dicetv->height = gst_videofilter_get_input_height (videofilter);
|
2002-04-24 21:03:10 +00:00
|
|
|
|
2004-03-12 13:56:51 +00:00
|
|
|
g_free (dicetv->dicemap);
|
2004-03-14 22:34:33 +00:00
|
|
|
dicetv->dicemap =
|
|
|
|
(gchar *) g_malloc (dicetv->height * dicetv->width * sizeof (char));
|
2004-03-12 13:56:51 +00:00
|
|
|
gst_dicetv_create_map (dicetv);
|
2002-04-24 21:03:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_dicetv_init (GTypeInstance * instance, gpointer g_class)
|
2002-04-24 21:03:10 +00:00
|
|
|
{
|
2004-03-12 13:56:51 +00:00
|
|
|
GstDiceTV *filter = GST_DICETV (instance);
|
2002-04-24 21:03:10 +00:00
|
|
|
|
|
|
|
filter->dicemap = NULL;
|
|
|
|
filter->g_cube_bits = DEFAULT_CUBE_BITS;
|
|
|
|
filter->g_cube_size = 0;
|
|
|
|
filter->g_map_height = 0;
|
|
|
|
filter->g_map_width = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_dicetv_reset_handler (GstElement * element)
|
2002-04-24 21:03:10 +00:00
|
|
|
{
|
2002-04-24 23:09:13 +00:00
|
|
|
GstDiceTV *filter = GST_DICETV (element);
|
2002-04-24 21:03:10 +00:00
|
|
|
|
|
|
|
gst_dicetv_create_map (filter);
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int
|
|
|
|
fastrand (void)
|
2004-03-14 22:34:33 +00:00
|
|
|
{
|
2002-04-24 21:03:10 +00:00
|
|
|
static unsigned int fastrand_val;
|
|
|
|
|
|
|
|
return (fastrand_val = fastrand_val * 1103515245 + 12345);
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void
|
|
|
|
gst_dicetv_draw (GstVideofilter * videofilter, void *d, void *s)
|
2002-04-24 21:03:10 +00:00
|
|
|
{
|
2004-03-12 13:56:51 +00:00
|
|
|
GstDiceTV *filter;
|
|
|
|
guint32 *src;
|
|
|
|
guint32 *dest;
|
2002-04-24 21:03:10 +00:00
|
|
|
gint i;
|
|
|
|
gint map_x, map_y, map_i;
|
|
|
|
gint base;
|
|
|
|
gint dx, dy, di;
|
|
|
|
gint video_width = filter->width;
|
|
|
|
gint g_cube_bits = filter->g_cube_bits;
|
|
|
|
gint g_cube_size = filter->g_cube_size;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2004-03-12 13:56:51 +00:00
|
|
|
filter = GST_DICETV (videofilter);
|
2004-03-14 22:34:33 +00:00
|
|
|
src = (guint32 *) s;
|
|
|
|
dest = (guint32 *) d;
|
2004-03-12 13:56:51 +00:00
|
|
|
|
|
|
|
video_width = filter->width;
|
|
|
|
g_cube_bits = filter->g_cube_bits;
|
|
|
|
g_cube_size = filter->g_cube_size;
|
|
|
|
|
2002-04-24 21:03:10 +00:00
|
|
|
map_i = 0;
|
|
|
|
for (map_y = 0; map_y < filter->g_map_height; map_y++) {
|
|
|
|
for (map_x = 0; map_x < filter->g_map_width; map_x++) {
|
2004-03-14 22:34:33 +00:00
|
|
|
base = (map_y << g_cube_bits) * video_width + (map_x << g_cube_bits);
|
|
|
|
|
|
|
|
switch (filter->dicemap[map_i]) {
|
2004-03-15 19:32:27 +00:00
|
|
|
case DICE_UP:
|
|
|
|
for (dy = 0; dy < g_cube_size; dy++) {
|
|
|
|
i = base + dy * video_width;
|
|
|
|
for (dx = 0; dx < g_cube_size; dx++) {
|
|
|
|
dest[i] = src[i];
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DICE_LEFT:
|
|
|
|
for (dy = 0; dy < g_cube_size; dy++) {
|
|
|
|
i = base + dy * video_width;
|
|
|
|
|
|
|
|
for (dx = 0; dx < g_cube_size; dx++) {
|
|
|
|
di = base + (dx * video_width) + (g_cube_size - dy - 1);
|
|
|
|
dest[di] = src[i];
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DICE_DOWN:
|
|
|
|
for (dy = 0; dy < g_cube_size; dy++) {
|
|
|
|
di = base + dy * video_width;
|
|
|
|
i = base + (g_cube_size - dy - 1) * video_width + g_cube_size;
|
|
|
|
for (dx = 0; dx < g_cube_size; dx++) {
|
|
|
|
i--;
|
|
|
|
dest[di] = src[i];
|
|
|
|
di++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DICE_RIGHT:
|
|
|
|
for (dy = 0; dy < g_cube_size; dy++) {
|
|
|
|
i = base + (dy * video_width);
|
|
|
|
for (dx = 0; dx < g_cube_size; dx++) {
|
|
|
|
di = base + dy + (g_cube_size - dx - 1) * video_width;
|
|
|
|
dest[di] = src[i];
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
break;
|
2002-04-24 21:03:10 +00:00
|
|
|
}
|
|
|
|
map_i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void
|
|
|
|
gst_dicetv_create_map (GstDiceTV * filter)
|
2002-04-24 21:03:10 +00:00
|
|
|
{
|
|
|
|
gint x, y, i;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2002-04-24 21:03:10 +00:00
|
|
|
filter->g_map_height = filter->height >> filter->g_cube_bits;
|
|
|
|
filter->g_map_width = filter->width >> filter->g_cube_bits;
|
|
|
|
filter->g_cube_size = 1 << filter->g_cube_bits;
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
|
|
|
|
for (y = 0; y < filter->g_map_height; y++) {
|
2004-03-14 22:34:33 +00:00
|
|
|
for (x = 0; x < filter->g_map_width; x++) {
|
2002-04-24 21:03:10 +00:00
|
|
|
// dicemap[i] = ((i + y) & 0x3); /* Up, Down, Left or Right */
|
2004-03-14 22:34:33 +00:00
|
|
|
filter->dicemap[i] = (fastrand () >> 24) & 0x03;
|
2002-04-24 21:03:10 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_dicetv_set_property (GObject * object, guint prop_id, const GValue * value,
|
|
|
|
GParamSpec * pspec)
|
2002-04-24 21:03:10 +00:00
|
|
|
{
|
|
|
|
GstDiceTV *filter;
|
|
|
|
|
|
|
|
/* it's not null if we got it, but it might not be ours */
|
|
|
|
g_return_if_fail (GST_IS_DICETV (object));
|
|
|
|
|
|
|
|
filter = GST_DICETV (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_CUBE_BITS:
|
|
|
|
filter->g_cube_bits = g_value_get_int (value);
|
|
|
|
gst_dicetv_create_map (filter);
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_dicetv_get_property (GObject * object, guint prop_id, GValue * value,
|
|
|
|
GParamSpec * pspec)
|
2002-04-24 21:03:10 +00:00
|
|
|
{
|
|
|
|
GstDiceTV *filter;
|
|
|
|
|
|
|
|
/* it's not null if we got it, but it might not be ours */
|
|
|
|
g_return_if_fail (GST_IS_DICETV (object));
|
|
|
|
|
|
|
|
filter = GST_DICETV (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_CUBE_BITS:
|
|
|
|
g_value_set_int (value, filter->g_cube_bits);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|