gst/games/gstpuzzle.c: no memleaks, please change initialization code around so we don't reshuffle on resize fix anot...

Original commit message from CVS:
* gst/games/gstpuzzle.c: (gst_puzzle_get_type),
(gst_puzzle_class_init), (gst_puzzle_finalize):
no memleaks, please
(gst_puzzle_create), (gst_puzzle_init),
(gst_puzzle_set_property), (gst_puzzle_setup):
change initialization code around so we don't reshuffle on resize
(draw_puzzle):
fix another stupid typo
This commit is contained in:
Benjamin Otte 2005-01-06 18:44:08 +00:00
parent bc9ee3da4e
commit 5bddeb9d5b
2 changed files with 55 additions and 12 deletions

View file

@ -1,3 +1,14 @@
2005-01-06 Benjamin Otte <otte@gnome.org>
* gst/games/gstpuzzle.c: (gst_puzzle_get_type),
(gst_puzzle_class_init), (gst_puzzle_finalize):
no memleaks, please
(gst_puzzle_create), (gst_puzzle_init),
(gst_puzzle_set_property), (gst_puzzle_setup):
change initialization code around so we don't reshuffle on resize
(draw_puzzle):
fix another stupid typo
2005-01-06 Benjamin Otte <otte@gnome.org> 2005-01-06 Benjamin Otte <otte@gnome.org>
* gst/games/gstvideoimage.c: (copy_hline_YUY2): * gst/games/gstvideoimage.c: (copy_hline_YUY2):

View file

@ -81,6 +81,7 @@ enum
static void gst_puzzle_base_init (gpointer g_class); static void gst_puzzle_base_init (gpointer g_class);
static void gst_puzzle_class_init (gpointer g_class, gpointer class_data); static void gst_puzzle_class_init (gpointer g_class, gpointer class_data);
static void gst_puzzle_init (GTypeInstance * instance, gpointer g_class); static void gst_puzzle_init (GTypeInstance * instance, gpointer g_class);
static void gst_puzzle_finalize (GObject * object);
static void gst_puzzle_set_property (GObject * object, guint prop_id, static void gst_puzzle_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec); const GValue * value, GParamSpec * pspec);
@ -90,6 +91,8 @@ static void gst_puzzle_get_property (GObject * object, guint prop_id,
static void gst_puzzle_setup (GstVideofilter * videofilter); static void gst_puzzle_setup (GstVideofilter * videofilter);
static void draw_puzzle (GstVideofilter * videofilter, void *destp, void *srcp); static void draw_puzzle (GstVideofilter * videofilter, void *destp, void *srcp);
static GstVideofilterClass *parent_class;
GType GType
gst_puzzle_get_type (void) gst_puzzle_get_type (void)
{ {
@ -157,8 +160,11 @@ gst_puzzle_class_init (gpointer g_class, gpointer class_data)
gobject_class = G_OBJECT_CLASS (g_class); gobject_class = G_OBJECT_CLASS (g_class);
videofilter_class = GST_VIDEOFILTER_CLASS (g_class); videofilter_class = GST_VIDEOFILTER_CLASS (g_class);
parent_class = g_type_class_peek_parent (g_class);
gobject_class->set_property = gst_puzzle_set_property; gobject_class->set_property = gst_puzzle_set_property;
gobject_class->get_property = gst_puzzle_get_property; gobject_class->get_property = gst_puzzle_get_property;
gobject_class->finalize = gst_puzzle_finalize;
g_object_class_install_property (gobject_class, ARG_ROWS, g_object_class_install_property (gobject_class, ARG_ROWS,
g_param_spec_uint ("rows", "rows", "number of rows in puzzle", g_param_spec_uint ("rows", "rows", "number of rows in puzzle",
@ -170,6 +176,17 @@ gst_puzzle_class_init (gpointer g_class, gpointer class_data)
videofilter_class->setup = gst_puzzle_setup; videofilter_class->setup = gst_puzzle_setup;
} }
static void
gst_puzzle_finalize (GObject * object)
{
GstPuzzle *puzzle;
puzzle = GST_PUZZLE (object);
g_free (puzzle->permutation);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void G_GNUC_UNUSED static void G_GNUC_UNUSED
gst_puzzle_solve (GstPuzzle * puzzle) gst_puzzle_solve (GstPuzzle * puzzle)
{ {
@ -366,14 +383,38 @@ nav_event_handler (GstPad * pad, GstEvent * event)
return gst_pad_event_default (pad, event); return gst_pad_event_default (pad, event);
} }
static void
gst_puzzle_create (GstPuzzle * puzzle)
{
guint i;
puzzle->tiles = puzzle->rows * puzzle->columns;
g_assert (puzzle->tiles);
g_free (puzzle->permutation);
puzzle->permutation = g_new (guint, puzzle->tiles);
for (i = 0; i < puzzle->tiles; i++) {
puzzle->permutation[i] = i;
}
puzzle->position = puzzle->tiles - 1;
/* shuffle a bit */
gst_puzzle_shuffle (puzzle);
}
static void static void
gst_puzzle_init (GTypeInstance * instance, gpointer g_class) gst_puzzle_init (GTypeInstance * instance, gpointer g_class)
{ {
GstVideofilter *videofilter; GstVideofilter *videofilter;
GstPuzzle *puzzle;
videofilter = GST_VIDEOFILTER (instance); videofilter = GST_VIDEOFILTER (instance);
puzzle = GST_PUZZLE (instance);
/* FIXME: this is evil */ /* FIXME: this is evil */
gst_pad_set_event_function (videofilter->srcpad, nav_event_handler); gst_pad_set_event_function (videofilter->srcpad, nav_event_handler);
/* set this so we don't crash when initializing */
puzzle->rows = 1;
puzzle->columns = 1;
} }
static void static void
@ -390,11 +431,11 @@ gst_puzzle_set_property (GObject * object, guint prop_id,
switch (prop_id) { switch (prop_id) {
case ARG_COLUMNS: case ARG_COLUMNS:
src->columns = g_value_get_uint (value); src->columns = g_value_get_uint (value);
src->tiles = src->columns * src->rows; gst_puzzle_create (src);
break; break;
case ARG_ROWS: case ARG_ROWS:
src->rows = g_value_get_uint (value); src->rows = g_value_get_uint (value);
src->tiles = src->columns * src->rows; gst_puzzle_create (src);
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@ -429,19 +470,10 @@ static void
gst_puzzle_setup (GstVideofilter * videofilter) gst_puzzle_setup (GstVideofilter * videofilter)
{ {
GstPuzzle *puzzle; GstPuzzle *puzzle;
guint i;
g_return_if_fail (GST_IS_PUZZLE (videofilter)); g_return_if_fail (GST_IS_PUZZLE (videofilter));
puzzle = GST_PUZZLE (videofilter); puzzle = GST_PUZZLE (videofilter);
g_free (puzzle->permutation);
puzzle->permutation = g_new (guint, puzzle->tiles);
for (i = 0; i < puzzle->tiles; i++) {
puzzle->permutation[i] = i;
}
puzzle->position = puzzle->tiles - 1;
/* shuffle a bit */
gst_puzzle_shuffle (puzzle);
puzzle->format = NULL; puzzle->format = NULL;
} }
@ -476,7 +508,7 @@ draw_puzzle (GstVideofilter * videofilter, void *destp, void *srcp)
} }
if (height * puzzle->rows != gst_videofilter_get_input_height (videofilter)) { if (height * puzzle->rows != gst_videofilter_get_input_height (videofilter)) {
guint h = guint h =
gst_videofilter_get_input_width (videofilter) - height * puzzle->rows; gst_videofilter_get_input_height (videofilter) - height * puzzle->rows;
gst_video_image_copy_area (&dest, 0, height * puzzle->rows, &src, 0, gst_video_image_copy_area (&dest, 0, height * puzzle->rows, &src, 0,
height * puzzle->rows, gst_videofilter_get_input_width (videofilter), height * puzzle->rows, gst_videofilter_get_input_width (videofilter),