[vlc-devel] [PATCH 1/7] Puzzle: add dedicated bezier functions

Denis Charmet typx at dinauz.org
Mon Apr 15 16:48:54 CEST 2013


Le lundi 15 avril 2013 à 02:11:55, Vianney Boyer a écrit :
> +    if (!b_fit) {
> +        free(ps_new_pt);
> +        ps_new_pt = NULL;
> +    }
In that case the following code will crash, maybe you should return NULL
> +
> +    /* global scale shall be applied: */
> +    f_current_scale = f_current_scale * (0.5 + 0.5*
> (float)i_shape_size / 100);
> +    for (uint8_t i_p = 0; i_p < i_last_pt; i_p++) {
> +        if ( i_p == 0 || i_p == 1 )
> +            ps_new_pt[i_p].f_x = ps_pt[i_p].f_x * f_x_ratio + f_x_offset;
> +        else if ( i_p == i_last_pt - 2 || i_p == i_last_pt - 1 )
> +            ps_new_pt[i_p].f_x = ps_pt[i_p].f_x * f_x_ratio + f_x_offset;
> +        else
> +            ps_new_pt[i_p].f_x = ps_pt[i_p].f_x * f_x_ratio *
> f_current_scale + f_x_offset;
> +        ps_new_pt[i_p].f_y = ps_pt[i_p].f_y * f_y_ratio *
> f_current_scale + f_y_offset;
> +    }
> +
> +    return ps_new_pt;
> +}

> +point_t *puzzle_curve_H_2_negative(uint8_t i_pts_nbr, point_t *ps_pt)
> +{
> +    if (ps_pt == NULL)
> +        return NULL;
> +
> +    point_t *ps_new_pt = malloc( sizeof( point_t ) * (3 *
> (i_pts_nbr-1) + 1) );
> +    if (ps_new_pt == NULL)
> +        return NULL;
> +
> +    for (uint8_t i=0; i < (3 * (i_pts_nbr-1) + 1); i++) {
> +        ps_new_pt[i].f_x = ps_pt[i].f_x;
> +        ps_new_pt[i].f_y = -ps_pt[i].f_y;
> +    }
> +
> +    return ps_new_pt;
> +}
> +
> +/*****************************************************************************
> + * compute vertical data to create negative ones
> + *****************************************************************************/
> +point_t *puzzle_curve_V_2_negative(uint8_t i_pts_nbr, point_t *ps_pt)
> +{
> +    if (ps_pt == NULL)
> +        return NULL;
> +
> +    point_t *ps_new_pt = malloc( sizeof( point_t ) * (3 *
> (i_pts_nbr-1) + 1) );
> +    if (ps_new_pt == NULL)
> +        return NULL;
> +
> +    for (uint8_t i=0; i < (3 * (i_pts_nbr-1) + 1); i++) {
> +        ps_new_pt[i].f_x = -ps_pt[i].f_x;
> +        ps_new_pt[i].f_y = ps_pt[i].f_y;
> +    }
> +
> +    return ps_new_pt;
> +}
> +
> +/*****************************************************************************
> + * generate random bezier data
> + *****************************************************************************/
> +point_t *puzzle_rand_bezier(uint8_t i_pts_nbr)
> +{
> +#define NB_PRIM 13
> +/*****************************************************************************
> + * The table below contains bezier points that creates a typical
> + * jigsaw puzzle piece shape. One set has been defined manually.
> + * Then random modifications have been applied.
> + * The best results have been selected and are included here.
> + *****************************************************************************/
> +    point_t ps_pt[NB_PRIM][19] = {  {{ -1,    0}, {
> -0.708333333333333,    0},
 {0.39345790442032,   -0.1704960590812},
> [...]
> +                               { 0.713223372514099,
> -0.000707944210808817}, {1,   0}}
> +                               };
This should be const.
> +
> +    if (i_pts_nbr != 7)
> +        return NULL;

If you fix your point number to 7, why making it variable?

Regards,

-- 
TypX
Le mauvais esprit est un art de vivre



More information about the vlc-devel mailing list