From 168db53bf471394ca9381b903d3e32d79664d8e5 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 23 Jan 2007 17:27:39 +0000 Subject: gst/smpte/: constify some static structs. Original commit message from CVS: * gst/smpte/barboxwipes.c: (gst_wipe_boxes_draw), (gst_wipe_triangles_clock_draw), (gst_wipe_triangles_draw): * gst/smpte/gstmask.c: (_gst_mask_register): * gst/smpte/gstmask.h: * gst/smpte/gstsmpte.c: (gst_smpte_update_mask): * gst/smpte/paint.c: (gst_smpte_paint_hbox), (draw_bresenham_line), (gst_smpte_paint_triangle_clock): constify some static structs. Don't update the mask if nothing changed to the params. Make sure we never draw outside of the picture. Fixes #398325. --- gst/smpte/barboxwipes.c | 89 +++++++++++++++++++++++++++++++++---------------- gst/smpte/gstmask.c | 5 +-- gst/smpte/gstmask.h | 10 +++--- gst/smpte/gstsmpte.c | 7 ++++ gst/smpte/paint.c | 11 +++--- 5 files changed, 82 insertions(+), 40 deletions(-) (limited to 'gst/smpte') diff --git a/gst/smpte/barboxwipes.c b/gst/smpte/barboxwipes.c index 7be26a35..01469a10 100644 --- a/gst/smpte/barboxwipes.c +++ b/gst/smpte/barboxwipes.c @@ -32,14 +32,14 @@ enum TRIGANLE_LINEAR = 4 }; -static gint boxes_1b[][7] = { +static const gint boxes_1b[][7] = { #define WIPE_B1_1 0 {BOX_VERTICAL, 0, 0, 0, 1, 1, 1}, #define WIPE_B1_2 1 {BOX_HORIZONTAL, 0, 0, 0, 1, 1, 1} }; -static gint boxes_2b[][7 * 2] = { +static const gint boxes_2b[][7 * 2] = { #define WIPE_B2_21 0 {BOX_VERTICAL, 0, 0, 1, 1, 2, 0, BOX_VERTICAL, 1, 0, 0, 2, 2, 1}, @@ -48,7 +48,7 @@ static gint boxes_2b[][7 * 2] = { BOX_HORIZONTAL, 0, 1, 0, 2, 2, 1}, }; -static gint box_clock_1b[][1 * 10] = { +static const gint box_clock_1b[][1 * 10] = { #define WIPE_B1_241 0 {BOX_CLOCK, 0, 0, 0, 1, 0, 0, 0, 1, 1}, #define WIPE_B1_242 1 @@ -60,7 +60,7 @@ static gint box_clock_1b[][1 * 10] = { }; #define WIPE_B2_221 0 -static gint box_clock_2b[][2 * 10] = { +static const gint box_clock_2b[][2 * 10] = { #define WIPE_B2_221 0 {BOX_CLOCK, 1, 0, 0, 2, 0, 0, 1, 2, 1, BOX_CLOCK, 1, 0, 0, 1, 2, 1, 0, 0, 2}, @@ -105,7 +105,7 @@ static gint box_clock_2b[][2 * 10] = { BOX_CLOCK, 2, 2, 0, 2, 1, 0, 0, 2, 1}, }; -static gint box_clock_4b[][4 * 10] = { +static const gint box_clock_4b[][4 * 10] = { #define WIPE_B4_201 0 {BOX_CLOCK, 1, 1, 0, 1, 0, 0, 2, 1, 1, BOX_CLOCK, 1, 1, 0, 2, 1, 1, 1, 2, 2, @@ -183,7 +183,7 @@ static gint box_clock_4b[][4 * 10] = { BOX_CLOCK, 2, 1, 0, 1, 1, 0, 2, 2, 1}, }; -static gint box_clock_8b[][8 * 10] = { +static const gint box_clock_8b[][8 * 10] = { #define WIPE_B8_261 0 {BOX_CLOCK, 2, 1, 0, 2, 2, 0, 4, 1, 1, BOX_CLOCK, 2, 1, 0, 4, 1, 1, 2, 0, 2, @@ -222,7 +222,7 @@ static gint box_clock_8b[][8 * 10] = { BOX_CLOCK, 3, 2, 0, 3, 4, 1, 2, 2, 2}, }; -static gint triangles_2t[][2 * 9] = { +static const gint triangles_2t[][2 * 9] = { /* 3 -> 6 */ #define WIPE_T2_3 0 {0, 0, 0, 0, 1, 1, 1, 1, 1, @@ -256,7 +256,7 @@ static gint triangles_2t[][2 * 9] = { 2, 0, 0, 2, 2, 0, 0, 2, 1}, }; -static gint triangles_3t[][3 * 9] = { +static const gint triangles_3t[][3 * 9] = { /* 23 -> 26 */ #define WIPE_T3_23 0 {0, 0, 1, 1, 0, 0, 0, 2, 1, @@ -276,7 +276,7 @@ static gint triangles_3t[][3 * 9] = { 0, 1, 0, 0, 2, 1, 2, 2, 1}, }; -static gint triangles_4t[][4 * 9] = { +static const gint triangles_4t[][4 * 9] = { #define WIPE_T4_61 0 {0, 0, 1, 1, 0, 0, 1, 2, 1, 0, 0, 1, 0, 2, 2, 1, 2, 1, @@ -324,7 +324,7 @@ static gint triangles_4t[][4 * 9] = { 2, 0, 1, 1, 1, 0, 2, 2, 1}, }; -static gint triangles_8t[][8 * 9] = { +static const gint triangles_8t[][8 * 9] = { /* 7 */ #define WIPE_T8_7 0 {0, 0, 0, 1, 0, 1, 1, 1, 1, @@ -373,7 +373,7 @@ static gint triangles_8t[][8 * 9] = { 2, 1, 0, 1, 2, 0, 2, 2, 1}, }; -static gint triangles_16t[][16 * 9] = { +static const gint triangles_16t[][16 * 9] = { /* 8 */ #define WIPE_T16_8 0 {0, 0, 1, 2, 0, 1, 1, 1, 0, @@ -398,14 +398,14 @@ typedef struct _GstWipeConfig GstWipeConfig; struct _GstWipeConfig { - gint *objects; + const gint *objects; gint nobjects; gint xscale; gint yscale; gint cscale; }; -static GstWipeConfig wipe_config[] = { +static const GstWipeConfig wipe_config[] = { #define WIPE_CONFIG_1 0 {boxes_1b[WIPE_B1_1], 1, 0, 0, 0}, /* 1 */ #define WIPE_CONFIG_2 WIPE_CONFIG_1+1 @@ -554,8 +554,8 @@ static GstWipeConfig wipe_config[] = { static void gst_wipe_boxes_draw (GstMask * mask) { - GstWipeConfig *config = mask->user_data; - gint *impacts = config->objects; + const GstWipeConfig *config = mask->user_data; + const gint *impacts = config->objects; gint width = (mask->width >> config->xscale); gint height = (mask->height >> config->yscale); gint depth = (1 << mask->bpp) >> config->cscale; @@ -565,22 +565,35 @@ gst_wipe_boxes_draw (GstMask * mask) for (i = 0; i < config->nobjects; i++) { switch (impacts[0]) { case BOX_VERTICAL: + /* vbox does not draw last pixels */ gst_smpte_paint_vbox (mask->data, mask->width, impacts[1] * width, impacts[2] * height, impacts[3] * depth, impacts[4] * width, impacts[5] * height, impacts[6] * depth); impacts += 7; break; case BOX_HORIZONTAL: + /* hbox does not draw last pixels */ gst_smpte_paint_hbox (mask->data, mask->width, impacts[1] * width, impacts[2] * height, impacts[3] * depth, impacts[4] * width, impacts[5] * height, impacts[6] * depth); impacts += 7; case BOX_CLOCK: + { + gint x0, y0, x1, y1, x2, y2; + + /* make sure not to draw outside the area */ + x0 = MIN (impacts[1] * width, mask->width - 1); + y0 = MIN (impacts[2] * height, mask->height - 1); + x1 = MIN (impacts[4] * width, mask->width - 1); + y1 = MIN (impacts[5] * height, mask->height - 1); + x2 = MIN (impacts[7] * width, mask->width - 1); + y2 = MIN (impacts[8] * height, mask->height - 1); + gst_smpte_paint_box_clock (mask->data, mask->width, - impacts[1] * width, impacts[2] * height, impacts[3] * depth, - impacts[4] * width, impacts[5] * height, impacts[6] * depth, - impacts[7] * width, impacts[8] * height, impacts[9] * depth); + x0, y0, impacts[3] * depth, x1, y1, impacts[6] * depth, + x2, y2, impacts[9] * depth); impacts += 10; + } default: break; } @@ -590,18 +603,27 @@ gst_wipe_boxes_draw (GstMask * mask) static void gst_wipe_triangles_clock_draw (GstMask * mask) { - GstWipeConfig *config = mask->user_data; - gint *impacts = config->objects; + const GstWipeConfig *config = mask->user_data; + const gint *impacts = config->objects; gint width = (mask->width >> config->xscale); gint height = (mask->height >> config->yscale); gint depth = (1 << mask->bpp) >> config->cscale; gint i; for (i = 0; i < config->nobjects; i++) { + gint x0, y0, x1, y1, x2, y2; + + /* make sure not to draw outside the area */ + x0 = MIN (impacts[0] * width, mask->width - 1); + y0 = MIN (impacts[1] * height, mask->height - 1); + x1 = MIN (impacts[3] * width, mask->width - 1); + y1 = MIN (impacts[4] * height, mask->height - 1); + x2 = MIN (impacts[6] * width, mask->width - 1); + y2 = MIN (impacts[7] * height, mask->height - 1); + gst_smpte_paint_triangle_clock (mask->data, mask->width, - impacts[0] * width, impacts[1] * height, impacts[2] * depth, - impacts[3] * width, impacts[4] * height, impacts[5] * depth, - impacts[6] * width, impacts[7] * height, impacts[8] * depth); + x0, y0, impacts[2] * depth, x1, y1, impacts[5] * depth, + x2, y2, impacts[8] * depth); impacts += 9; } } @@ -609,8 +631,8 @@ gst_wipe_triangles_clock_draw (GstMask * mask) static void gst_wipe_triangles_draw (GstMask * mask) { - GstWipeConfig *config = mask->user_data; - gint *impacts = config->objects; + const GstWipeConfig *config = mask->user_data; + const gint *impacts = config->objects; gint width = (mask->width >> config->xscale); gint height = (mask->height >> config->yscale); gint depth = (1 << mask->bpp) >> config->cscale; @@ -618,15 +640,24 @@ gst_wipe_triangles_draw (GstMask * mask) gint i; for (i = 0; i < config->nobjects; i++) { + gint x0, y0, x1, y1, x2, y2; + + /* make sure not to draw outside the area */ + x0 = MIN (impacts[0] * width, mask->width - 1); + y0 = MIN (impacts[1] * height, mask->height - 1); + x1 = MIN (impacts[3] * width, mask->width - 1); + y1 = MIN (impacts[4] * height, mask->height - 1); + x2 = MIN (impacts[6] * width, mask->width - 1); + y2 = MIN (impacts[7] * height, mask->height - 1); + gst_smpte_paint_triangle_linear (mask->data, mask->width, - impacts[0] * width, impacts[1] * height, impacts[2] * depth, - impacts[3] * width, impacts[4] * height, impacts[5] * depth, - impacts[6] * width, impacts[7] * height, impacts[8] * depth); + x0, y0, impacts[2] * depth, x1, y1, impacts[5] * depth, + x2, y2, impacts[8] * depth); impacts += 9; } } -static GstMaskDefinition definitions[] = { +static const GstMaskDefinition definitions[] = { {1, "bar-wipe-lr", "A bar moves from left to right", gst_wipe_boxes_draw, _gst_mask_default_destroy, diff --git a/gst/smpte/gstmask.c b/gst/smpte/gstmask.c index 0e2cf01f..dfb856c2 100644 --- a/gst/smpte/gstmask.c +++ b/gst/smpte/gstmask.c @@ -41,10 +41,11 @@ gst_mask_compare (GstMaskDefinition * def1, GstMaskDefinition * def2) } void -_gst_mask_register (GstMaskDefinition * definition) +_gst_mask_register (const GstMaskDefinition * definition) { masks = - g_list_insert_sorted (masks, definition, (GCompareFunc) gst_mask_compare); + g_list_insert_sorted (masks, (gpointer) definition, + (GCompareFunc) gst_mask_compare); } const GList * diff --git a/gst/smpte/gstmask.h b/gst/smpte/gstmask.h index bf63dc5a..f9cf6a9a 100644 --- a/gst/smpte/gstmask.h +++ b/gst/smpte/gstmask.h @@ -31,17 +31,17 @@ typedef void (*GstMaskDestroyFunc) (GstMask *mask); struct _GstMaskDefinition { gint type; - gchar *short_name; - gchar *long_name; + const gchar *short_name; + const gchar *long_name; GstMaskDrawFunc draw_func; GstMaskDestroyFunc destroy_func; - gpointer user_data; + gconstpointer user_data; }; struct _GstMask { gint type; guint32 *data; - gpointer user_data; + gconstpointer user_data; gint width; gint height; @@ -51,7 +51,7 @@ struct _GstMask { }; void _gst_mask_init (void); -void _gst_mask_register (GstMaskDefinition *definition); +void _gst_mask_register (const GstMaskDefinition *definition); void _gst_mask_default_destroy (GstMask *mask); diff --git a/gst/smpte/gstsmpte.c b/gst/smpte/gstsmpte.c index 471495b4..95fd31e2 100644 --- a/gst/smpte/gstsmpte.c +++ b/gst/smpte/gstsmpte.c @@ -280,6 +280,13 @@ gst_smpte_update_mask (GstSMPTE * smpte, gint type, gint depth, gint width, { GstMask *newmask; + if (smpte->mask) { + if (smpte->type == type && + smpte->depth == depth && + smpte->width == width && smpte->height == height) + return TRUE; + } + newmask = gst_mask_factory_new (type, depth, width, height); if (newmask) { if (smpte->mask) { diff --git a/gst/smpte/paint.c b/gst/smpte/paint.c index 9b60de37..25f82ea4 100644 --- a/gst/smpte/paint.c +++ b/gst/smpte/paint.c @@ -65,8 +65,6 @@ gst_smpte_paint_hbox (guint32 * dest, gint stride, g_assert (width > 0); g_assert (height > 0); - g_print ("vbox: %d %d %d %d %d %d\n", x0, y0, c0, x1, y1, c1); - dest = dest + y0 * stride + x0; for (i = 0; i < height; i++) { @@ -219,11 +217,13 @@ static void draw_bresenham_line (guint32 * dest, gint stride, gint x0, gint y0, gint x1, gint y1, guint32 col) { - gint dx = abs (x1 - x0); - gint dy = abs (y1 - y0); + gint dx, dy; gint x_incr, y_incr; gint i, dpr, dpru, P, indep; + dx = abs (x1 - x0); + dy = abs (y1 - y0); + dest = dest + y0 * stride + x0; x_incr = SIGN (x1 - x0); @@ -301,6 +301,9 @@ gst_smpte_paint_triangle_clock (guint32 * dest, gint stride, draw_bresenham_line (dest, stride, x0, y0, i, y1, (c2 * angle + c1 * (1.0 - angle))); } + } else { + g_warning ("paint triangle clock: not supported"); + return; } } -- cgit