Hi there. I want to make public some change made in mosaic.c that will allow a penrose rhombs grid. The diff can be also found on http://fenrir.info.uaic.ro/~catam3/shits/mosaic.diff. -- Catalin Mitrofan catam@xxxxxxxxxxx
--- gimp-1.2.1/plug-ins/mosaic/mosaic.c Tue Mar 6 17:29:25 2001 +++ gimp-1.2.1/plug-ins/mosaic/mosaic.c.orig Wed Aug 23 13:23:08 2000 @@ -26,7 +26,6 @@ #include <stdlib.h> #include <string.h> -#include <math.h> #include <gtk/gtk.h> @@ -52,7 +51,6 @@ #define SQUARES 0 #define HEXAGONS 1 #define OCTAGONS 2 -#define PENROSE_ROMBS 3 #define SMOOTH 0 #define ROUGH 1 @@ -60,32 +58,6 @@ #define BW 0 #define FG_BG 1 -#define ATILE 0 -#define BTILE 1 -#define CTILE 2 -#define DTILE 3 -#define PHI 1.618033989 - -#define TN_DEF_VAL .65 -typedef struct { - long k1, k2, k3; -} k; - -typedef struct { - long x, y; -} point; - -static point big[4], little[4]; - -//hardcoded neighbours -int neighbours[4][8][4] = {{{2, 2, 3, 0}, {2, 3, 7, 0}, {6, 2, 3, 0}, {6, 3, 7, 0}, {3, 6, 3, 0}, {3, 7, 7, 0}, {7, 6, 3, 0}, {7, 7, 7, 0}}, {{1, 1, 0, 3}, {1, 5, 0, 3}, {3, 1, 0, 7}, {3, 5, 0, 7}, {5, 3, 0, 3}, {5, 7, 0, 3}, {7, 3, 0, 7}, {7, 7, 0, 7}}, {{0, 2, 2, 0}, {0, 6, 2, 0}, {0, 3, 6, 0}, {0, 7, 6, 0}, {0, 2, 2, 1}, {0, 6, 2, 1}, {0, 3, 6, 1}, {0, 7, 6, 1}}, {{1, 0, 0, 1}, {3, 0, 0, 5}, {5, 0, 0, 1}, {7, 0, 0, 5}, {1, 0, 0, 3}, {3, 0, 0, 7}, {5, 0, 0, 3}, {7, 0, 0, 7}}}; - - -void A(int, float, float, int, int, int); -void B(int, float, float, int, int, int); -void C(int, float, float, int, int, int); -void D(int, float, float, int, int, int); - typedef struct { gdouble x, y; @@ -117,7 +89,6 @@ gint tile_type; gint tile_surface; gint grout_color; - gint allow_split_poligon; } MosaicVals; typedef struct @@ -128,10 +99,10 @@ /* Declare local functions. */ static void query (void); -static void run (gchar *name, - gint nparams, +static void run (gchar *name, + gint nparams, GimpParam *param, - gint *nreturn_vals, + gint *nreturn_vals, GimpParam **return_vals); static void mosaic (GimpDrawable *drawable); @@ -142,7 +113,7 @@ /* gradient finding machinery */ static void find_gradients (GimpDrawable *drawable, - gdouble std_dev); + gdouble std_dev); static void find_max_gradient (GimpPixelRgn *src_rgn, GimpPixelRgn *dest_rgn); @@ -182,9 +153,9 @@ gint x2, gint y2); static void grid_render (GimpDrawable * drawable); -static void split_poly (Polygon * poly, +static void split_poly (Polygon * poly, GimpDrawable * drawable, - guchar * col, + guchar * col, gdouble * dir, gdouble color_vary); static void clip_poly (gdouble * vec, @@ -264,17 +235,6 @@ gdouble * max_x, gdouble * max_y); static void polygon_reset (Polygon * poly); -static void my_radio_button_update (GtkWidget *widget, - gpointer data); -static void set_sensitive_tn(gint val); -static double my_cos(int angle); -static double my_sin(int angle); -static int some_in_common(point *p1, int n1, point *p2, int n2); -static void plotp(int type, float x, float y, int angle, int included); -static void plot(float x, float y, int angle, int type, int n, int included); - - - /* * Some static variables @@ -296,10 +256,6 @@ static guchar back[4]; static guchar fore[4]; static SpecVec vecs[MAX_POINTS]; -static GimpDrawable *gd; -static gint pe_size; -static double pe_cos[10], pe_sin[10]; -static double *pe_len; static MosaicVals mvals = @@ -307,15 +263,14 @@ 15.0, /* tile_size */ 4.0, /* tile_height */ 1.0, /* tile_spacing */ - TN_DEF_VAL, /* tile_neatness */ + 0.65, /* tile_neatness */ 135, /* light_dir */ 0.2, /* color_variation */ 1, /* antialiasing */ 1, /* color_averaging */ HEXAGONS, /* tile_type */ SMOOTH, /* tile_surface */ - BW, /* grout_color */ - 1 /* allow_split_poligon */ + BW /* grout_color */ }; static MosaicInterface mint = @@ -352,8 +307,7 @@ { GIMP_PDB_INT32, "color_averaging", "Tile color based on average of subsumed pixels" }, { GIMP_PDB_INT32, "tile_type", "Tile geometry: { SQUARES (0), HEXAGONS (1), OCTAGONS (2) }" }, { GIMP_PDB_INT32, "tile_surface", "Surface characteristics: { SMOOTH (0), ROUGH (1) }" }, - { GIMP_PDB_INT32, "grout_color", "Grout color (black/white or fore/background): { BW (0), FG_BG (1) }" }, - { GIMP_PDB_INT32, "allow_split_poligon", "Allow split poligon if magnitude is to high" } + { GIMP_PDB_INT32, "grout_color", "Grout color (black/white or fore/background): { BW (0), FG_BG (1) }" } }; static GimpParamDef *return_vals = NULL; @@ -376,10 +330,10 @@ } static void -run (gchar *name, - gint nparams, +run (gchar *name, + gint nparams, GimpParam *param, - gint *nreturn_vals, + gint *nreturn_vals, GimpParam **return_vals) { static GimpParam values[1]; @@ -424,8 +378,6 @@ mvals.tile_type = param[11].data.d_int32; mvals.tile_surface = param[12].data.d_int32; mvals.grout_color = param[13].data.d_int32; - mvals.allow_split_poligon = (param[14].data.d_int32) ? TRUE : FALSE; - } if (status == GIMP_PDB_SUCCESS && (mvals.tile_type < SQUARES || mvals.tile_type > OCTAGONS)) @@ -514,8 +466,7 @@ } /* Deform the tiles based on image content */ - if (mvals.tile_spacing != PENROSE_ROMBS) - grid_localize (x1, y1, x2, y2); + grid_localize (x1, y1, x2, y2); switch (mvals.grout_color) { @@ -554,9 +505,6 @@ gimp_drawable_update (drawable->id, x1, y1, (x2 - x1), (y2 - y1)); } - -GtkObject *scale_tn; - static gint mosaic_dialog (void) { @@ -669,22 +617,13 @@ (mvals.grout_color == FG_BG)); gtk_widget_show (toggle); - toggle = gtk_check_button_new_with_label ( _("Allow split poligon")); - gtk_box_pack_start (GTK_BOX (toggle_vbox), toggle, FALSE, FALSE, 0); - gtk_signal_connect (GTK_OBJECT (toggle), "toggled", - GTK_SIGNAL_FUNC (gimp_toggle_button_update), - &mvals.allow_split_poligon); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), - mvals.allow_split_poligon); - gtk_widget_show (toggle); - gtk_widget_show (toggle_vbox); gtk_widget_show (frame); gtk_widget_show (hbox); /* tiling primitive */ frame = gimp_radio_group_new2 (TRUE, _("Tiling Primitives"), - my_radio_button_update, + gimp_radio_button_update, &mvals.tile_type, (gpointer) mvals.tile_type, _("Squares"), @@ -693,8 +632,6 @@ (gpointer) HEXAGONS, NULL, _("Octagons & Squares"), (gpointer) OCTAGONS, NULL, - _("Penrose rombs"), - (gpointer) PENROSE_ROMBS, NULL, NULL); gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0); @@ -724,7 +661,7 @@ scale_data = gimp_scale_entry_new (GTK_TABLE (table), 0, 1, _("Tile Height:"), SCALE_WIDTH, 0, - mvals.tile_height, 0.0, 50.0, 1.0, 10.0, 1, + mvals.tile_height, 1.0, 50.0, 1.0, 10.0, 1, TRUE, 0, 0, NULL, NULL); gtk_signal_connect (GTK_OBJECT (scale_data), "value_changed", @@ -750,7 +687,6 @@ GTK_SIGNAL_FUNC (gimp_double_adjustment_update), &mvals.tile_neatness); - scale_tn = scale_data; scale_data = gimp_scale_entry_new (GTK_TABLE (table), 0, 4, _("Light Direction:"), SCALE_WIDTH, 0, mvals.light_dir, 0.0, 360.0, 1.0, 15.0, 1, @@ -769,7 +705,7 @@ gtk_signal_connect (GTK_OBJECT (scale_data), "value_changed", GTK_SIGNAL_FUNC (gimp_double_adjustment_update), &mvals.color_variation); - set_sensitive_tn(mvals.tile_type != PENROSE_ROMBS); + gtk_widget_show (frame); gtk_widget_show (table); @@ -796,7 +732,7 @@ static void find_gradients (GimpDrawable *drawable, - gdouble std_dev) + gdouble std_dev) { GimpPixelRgn src_rgn; GimpPixelRgn dest_rgn; @@ -816,9 +752,9 @@ bytes = drawable->bpp; /* allocate the gradient maps */ - h_grad = (guchar *) malloc (width * height); - v_grad = (guchar *) malloc (width * height); - m_grad = (guchar *) malloc (width * height); + h_grad = g_new (guchar, width * height); + v_grad = g_new (guchar, width * height); + m_grad = g_new (guchar, width * height); /* Calculate total number of rows to be processed */ rows = width * 2 + height * 2; @@ -941,11 +877,11 @@ static void gaussian_deriv (GimpPixelRgn *src_rgn, GimpPixelRgn *dest_rgn, - gint type, - gdouble std_dev, - gint *prog, - gint max_prog, - gint ith_prog) + gint type, + gdouble std_dev, + gint *prog, + gint max_prog, + gint ith_prog) { guchar *dest, *dp; guchar *src, *sp, *s; @@ -971,7 +907,7 @@ /* allocate buffers for get/set pixel region rows/cols */ length = MAX (src_rgn->w, src_rgn->h) * bytes; - data = (guchar *) malloc (length * 2); + data = g_new (guchar, length * 2); src = data; dest = data + length; @@ -985,7 +921,7 @@ /* initialize */ curve = curve_array + length; sum = sum_array + length; - buf = (gint *) malloc (sizeof (gint) * MAX ((x2 - x1), (y2 - y1)) * bytes); + buf = g_new (gint, MAX ((x2 - x1), (y2 - y1)) * bytes); if (type == VERTICAL) { @@ -1077,7 +1013,7 @@ gimp_pixel_rgn_set_col (dest_rgn, dest, col, y1, (y2 - y1)); if (! ((*prog)++ % ith_prog)) - gimp_progress_update ((double) *prog / (double) max_prog); + gimp_progress_update ((gdouble) *prog / (gdouble) max_prog); } if (type == HORIZONTAL) @@ -1170,11 +1106,11 @@ gimp_pixel_rgn_set_row (dest_rgn, dest, x1, row, (x2 - x1)); if (! ((*prog)++ % ith_prog)) - gimp_progress_update ((double) *prog / (double) max_prog); + gimp_progress_update ((gdouble) *prog / (gdouble) max_prog); } - free (buf); - free (data); + g_free (buf); + g_free (data); #ifndef UNOPTIMIZED_CODE /* end bad hack */ #undef length @@ -1274,7 +1210,7 @@ rows = (height + size - 1) / size; cols = (width + size - 1) / size; - grid = (Vertex *) malloc (sizeof (Vertex) * (cols + 2) * (rows + 2)); + grid = g_new (Vertex, (cols + 2) * (rows + 2)); grid += (cols + 2) + 1; for (i = -1; i <= rows; i++) @@ -1319,7 +1255,7 @@ rows = ((height + hex_height - 1) / hex_height); cols = ((width + hex_width * 2 - 1) / hex_width); - grid = (Vertex *) malloc (sizeof (Vertex) * (cols + 2) * 4 * (rows + 2)); + grid = g_new (Vertex, (cols + 2) * 4 * (rows + 2)); grid += (cols + 2) * 4 + 4; for (i = -1; i <= rows; i++) @@ -1370,7 +1306,7 @@ rows = ((height + oct_size - 1) / oct_size); cols = ((width + oct_size * 2 - 1) / oct_size); - grid = (Vertex *) malloc (sizeof (Vertex) * (cols + 2) * 8 * (rows + 2)); + grid = g_new (Vertex, (cols + 2) * 8 * (rows + 2)); grid += (cols + 2) * 8 + 8; for (i = -1; i < rows + 1; i++) @@ -1472,23 +1408,6 @@ } - - - - -void print_points(point * p, int n) -{ - int i; - static int count = 0; - guchar col[4]; - Polygon poly; - polygon_reset(&poly); - for(i = 0; i < n; i++) - polygon_add_point (&poly, p[i].x, p[i].y); - process_poly (&poly, mvals.allow_split_poligon, gd, col, 1); - gimp_progress_update ((double) count++ / (double) pe_size); -} - static void grid_render (GimpDrawable *drawable) { @@ -1520,218 +1439,167 @@ *data++ = back[i]; } - if (mvals.tile_type == PENROSE_ROMBS) { - int xcen = (x1 + x2) / 2, ycen = (y1 + y2) / 2, xlen = x2 - x1, ylen = - y2 - y1, len, n; - float angle, temp; - int i; - double *saved_pe_len; - gd = drawable; - if (xlen == ylen) { - len = PHI * (x2 - x1) / sqrt(2 * (3 - PHI)); - angle = G_PI / 4; - } else if (xlen < ylen) { - len = ylen / 2 + xlen / 2 * sqrt((1 + PHI) / (3 - PHI)); - angle = G_PI / 2; - } else { - len = xlen / 2 + ylen / 2 * sqrt((1 + PHI) / (3 - PHI)); - angle = 0; - } + size = (grid_rows + grid_row_pad) * (grid_cols + grid_col_pad); + frac_size = (gint) (size * mvals.color_variation); + count = 0; - len *= 2 / PHI; - n = floor(log(len / mvals.tile_size) / log(PHI)) + 1; - len = mvals.tile_size * pow(PHI, n); - pe_size = 2 * (xlen + 2 * mvals.tile_size) * (ylen + 2 * mvals.tile_size) * (2 + 3 * PHI) / (mvals.tile_size * mvals.tile_size * (2 + PHI) * sqrt(4 * PHI + 3)); - big[0].x = x1 - mvals.tile_size; - big[0].y = y1 - mvals.tile_size; - big[2].x = x2 + mvals.tile_size; - big[2].y = y2 + mvals.tile_size; - big[1].x = big[2].x; - big[1].y = big[0].y; - big[3].x = big[0].x; - big[3].y = big[2].y; - little[0].x = x1; - little[0].y = y1; - little[1].x = x2; - little[1].y = y1; - little[2].x = x2; - little[2].y = y2; - little[3].x = x1; - little[3].y = y2; - for(i = 0; i < 10; i++) { - pe_sin[i] = sin(angle + G_PI / 5 * i); - pe_cos[i] = cos(angle + G_PI / 5 * i); - } - saved_pe_len = calloc(n + 3, sizeof (double)); - for(pe_len = saved_pe_len + 1, i = n + 1, temp = len * PHI; i >= -1; i--, temp /= PHI) - pe_len[i] = temp; - A(n, xcen + pe_len[n + 1] / 2 * my_cos(0), ycen + pe_len[n + 1] / 2 * my_sin(0), - 0, 4, 0); - B(n, xcen + pe_len[n + 1] / 2 * my_cos(0), ycen + pe_len[n + 1] / 2 * my_sin(0), - 5, 4, 0); - free(saved_pe_len); - } else { - size = (grid_rows + grid_row_pad) * (grid_cols + grid_col_pad); - frac_size = (gint) (size * mvals.color_variation); - count = 0; + for (i = -grid_row_pad; i < grid_rows; i++) + for (j = -grid_col_pad; j < grid_cols; j++) + { + vary = ((rand () % size) < frac_size) ? 1 : 0; - for (i = -grid_row_pad; i < grid_rows; i++) - for (j = -grid_col_pad; j < grid_cols; j++) - { - vary = ((rand () % size) < frac_size) ? 1 : 0; + index = i * grid_rowstride + j * grid_multiple; - index = i * grid_rowstride + j * grid_multiple; + switch (mvals.tile_type) + { + case SQUARES: + polygon_reset (&poly); + polygon_add_point (&poly, + grid[index].x, + grid[index].y); + polygon_add_point (&poly, + grid[index + 1].x, + grid[index + 1].y); + polygon_add_point (&poly, + grid[index + grid_rowstride + 1].x, + grid[index + grid_rowstride + 1].y); + polygon_add_point (&poly, + grid[index + grid_rowstride].x, + grid[index + grid_rowstride].y); + + process_poly (&poly, TRUE, drawable, col, vary); + break; + + case HEXAGONS: + /* The main hexagon */ + polygon_reset (&poly); + polygon_add_point (&poly, + grid[index].x, + grid[index].y); + polygon_add_point (&poly, + grid[index + 1].x, + grid[index + 1].y); + polygon_add_point (&poly, + grid[index + 2].x, + grid[index + 2].y); + polygon_add_point (&poly, + grid[index + grid_rowstride + 1].x, + grid[index + grid_rowstride + 1].y); + polygon_add_point (&poly, + grid[index + grid_rowstride].x, + grid[index + grid_rowstride].y); + polygon_add_point (&poly, + grid[index + 3].x, + grid[index + 3].y); + process_poly (&poly, TRUE, drawable, col, vary); + + /* The auxillary hexagon */ + polygon_reset (&poly); + polygon_add_point (&poly, + grid[index + 2].x, + grid[index + 2].y); + polygon_add_point (&poly, + grid[index + grid_multiple * 2 - 1].x, + grid[index + grid_multiple * 2 - 1].y); + polygon_add_point (&poly, + grid[index + grid_rowstride + grid_multiple].x, + grid[index + grid_rowstride + grid_multiple].y); + polygon_add_point (&poly, + grid[index + grid_rowstride + grid_multiple + 3].x, + grid[index + grid_rowstride + grid_multiple + 3].y); + polygon_add_point (&poly, + grid[index + grid_rowstride + 2].x, + grid[index + grid_rowstride + 2].y); + polygon_add_point (&poly, + grid[index + grid_rowstride + 1].x, + grid[index + grid_rowstride + 1].y); + process_poly (&poly, TRUE, drawable, col, vary); + break; + + case OCTAGONS: + /* The main octagon */ + polygon_reset (&poly); + for (k = 0; k < 8; k++) + polygon_add_point (&poly, + grid[index + k].x, + grid[index + k].y); + process_poly (&poly, TRUE, drawable, col, vary); + + /* The auxillary octagon */ + polygon_reset (&poly); + polygon_add_point (&poly, + grid[index + 3].x, + grid[index + 3].y); + polygon_add_point (&poly, + grid[index + grid_multiple * 2 - 2].x, + grid[index + grid_multiple * 2 - 2].y); + polygon_add_point (&poly, + grid[index + grid_multiple * 2 - 3].x, + grid[index + grid_multiple * 2 - 3].y); + polygon_add_point (&poly, + grid[index + grid_rowstride + grid_multiple].x, + grid[index + grid_rowstride + grid_multiple].y); + polygon_add_point (&poly, + grid[index + grid_rowstride + grid_multiple * 2 - 1].x, + grid[index + grid_rowstride + grid_multiple * 2 - 1].y); + polygon_add_point (&poly, + grid[index + grid_rowstride + 2].x, + grid[index + grid_rowstride + 2].y); + polygon_add_point (&poly, + grid[index + grid_rowstride + 1].x, + grid[index + grid_rowstride + 1].y); + polygon_add_point (&poly, + grid[index + 4].x, + grid[index + 4].y); + process_poly (&poly, TRUE, drawable, col, vary); + + /* The main square */ + polygon_reset (&poly); + polygon_add_point (&poly, + grid[index + 2].x, + grid[index + 2].y); + polygon_add_point (&poly, + grid[index + grid_multiple * 2 - 1].x, + grid[index + grid_multiple * 2 - 1].y); + polygon_add_point (&poly, + grid[index + grid_multiple * 2 - 2].x, + grid[index + grid_multiple * 2 - 2].y); + polygon_add_point (&poly, + grid[index + 3].x, + grid[index + 3].y); + process_poly (&poly, FALSE, drawable, col, vary); + + /* The auxillary square */ + polygon_reset (&poly); + polygon_add_point (&poly, + grid[index + 5].x, + grid[index + 5].y); + polygon_add_point (&poly, + grid[index + 4].x, + grid[index + 4].y); + polygon_add_point (&poly, + grid[index + grid_rowstride + 1].x, + grid[index + grid_rowstride + 1].y); + polygon_add_point (&poly, + grid[index + grid_rowstride].x, + grid[index + grid_rowstride].y); + process_poly (&poly, FALSE, drawable, col, vary); + break; + } - switch (mvals.tile_type) - { - case SQUARES: - polygon_reset (&poly); - polygon_add_point (&poly, - grid[index].x, - grid[index].y); - polygon_add_point (&poly, - grid[index + 1].x, - grid[index + 1].y); - polygon_add_point (&poly, - grid[index + grid_rowstride + 1].x, - grid[index + grid_rowstride + 1].y); - polygon_add_point (&poly, - grid[index + grid_rowstride].x, - grid[index + grid_rowstride].y); - - process_poly (&poly, mvals.allow_split_poligon, drawable, col, vary); - break; - - case HEXAGONS: - /* The main hexagon */ - polygon_reset (&poly); - polygon_add_point (&poly, - grid[index].x, - grid[index].y); - polygon_add_point (&poly, - grid[index + 1].x, - grid[index + 1].y); - polygon_add_point (&poly, - grid[index + 2].x, - grid[index + 2].y); - polygon_add_point (&poly, - grid[index + grid_rowstride + 1].x, - grid[index + grid_rowstride + 1].y); - polygon_add_point (&poly, - grid[index + grid_rowstride].x, - grid[index + grid_rowstride].y); - polygon_add_point (&poly, - grid[index + 3].x, - grid[index + 3].y); - process_poly (&poly, mvals.allow_split_poligon, drawable, col, vary); - - /* The auxillary hexagon */ - polygon_reset (&poly); - polygon_add_point (&poly, - grid[index + 2].x, - grid[index + 2].y); - polygon_add_point (&poly, - grid[index + grid_multiple * 2 - 1].x, - grid[index + grid_multiple * 2 - 1].y); - polygon_add_point (&poly, - grid[index + grid_rowstride + grid_multiple].x, - grid[index + grid_rowstride + grid_multiple].y); - polygon_add_point (&poly, - grid[index + grid_rowstride + grid_multiple + 3].x, - grid[index + grid_rowstride + grid_multiple + 3].y); - polygon_add_point (&poly, - grid[index + grid_rowstride + 2].x, - grid[index + grid_rowstride + 2].y); - polygon_add_point (&poly, - grid[index + grid_rowstride + 1].x, - grid[index + grid_rowstride + 1].y); - process_poly (&poly, mvals.allow_split_poligon, drawable, col, vary); - break; - - case OCTAGONS: - /* The main octagon */ - polygon_reset (&poly); - for (k = 0; k < 8; k++) - polygon_add_point (&poly, - grid[index + k].x, - grid[index + k].y); - process_poly (&poly, mvals.allow_split_poligon, drawable, col, vary); - - /* The auxillary octagon */ - polygon_reset (&poly); - polygon_add_point (&poly, - grid[index + 3].x, - grid[index + 3].y); - polygon_add_point (&poly, - grid[index + grid_multiple * 2 - 2].x, - grid[index + grid_multiple * 2 - 2].y); - polygon_add_point (&poly, - grid[index + grid_multiple * 2 - 3].x, - grid[index + grid_multiple * 2 - 3].y); - polygon_add_point (&poly, - grid[index + grid_rowstride + grid_multiple].x, - grid[index + grid_rowstride + grid_multiple].y); - polygon_add_point (&poly, - grid[index + grid_rowstride + grid_multiple * 2 - 1].x, - grid[index + grid_rowstride + grid_multiple * 2 - 1].y); - polygon_add_point (&poly, - grid[index + grid_rowstride + 2].x, - grid[index + grid_rowstride + 2].y); - polygon_add_point (&poly, - grid[index + grid_rowstride + 1].x, - grid[index + grid_rowstride + 1].y); - polygon_add_point (&poly, - grid[index + 4].x, - grid[index + 4].y); - process_poly (&poly, mvals.allow_split_poligon, drawable, col, vary); - - /* The main square */ - polygon_reset (&poly); - polygon_add_point (&poly, - grid[index + 2].x, - grid[index + 2].y); - polygon_add_point (&poly, - grid[index + grid_multiple * 2 - 1].x, - grid[index + grid_multiple * 2 - 1].y); - polygon_add_point (&poly, - grid[index + grid_multiple * 2 - 2].x, - grid[index + grid_multiple * 2 - 2].y); - polygon_add_point (&poly, - grid[index + 3].x, - grid[index + 3].y); - process_poly (&poly, FALSE, drawable, col, vary); - - /* The auxillary square */ - polygon_reset (&poly); - polygon_add_point (&poly, - grid[index + 5].x, - grid[index + 5].y); - polygon_add_point (&poly, - grid[index + 4].x, - grid[index + 4].y); - polygon_add_point (&poly, - grid[index + grid_rowstride + 1].x, - grid[index + grid_rowstride + 1].y); - polygon_add_point (&poly, - grid[index + grid_rowstride].x, - grid[index + grid_rowstride].y); - process_poly (&poly, FALSE, drawable, col, vary); - break; - } + gimp_progress_update ((double) count++ / (double) size); + } - gimp_progress_update ((double) count++ / (double) size); - } - } gimp_progress_update (1.0); } static void -process_poly (Polygon *poly, - gint allow_split, +process_poly (Polygon *poly, + gint allow_split, GimpDrawable *drawable, - guchar *col, - gint vary) + guchar *col, + gint vary) { gdouble dir[2]; gdouble loc[2]; @@ -1769,10 +1637,10 @@ static void -render_poly (Polygon *poly, +render_poly (Polygon *poly, GimpDrawable *drawable, - guchar *col, - gdouble vary) + guchar *col, + gdouble vary) { gdouble cx, cy; @@ -1791,11 +1659,11 @@ static void -split_poly (Polygon *poly, +split_poly (Polygon *poly, GimpDrawable *drawable, - guchar *col, - gdouble *dir, - gdouble vary) + guchar *col, + gdouble *dir, + gdouble vary) { Polygon new_poly; gdouble spacing; @@ -1853,13 +1721,13 @@ static void -clip_poly (double *dir, - double *pt, - Polygon *poly, - Polygon *poly_new) +clip_poly (gdouble *dir, + gdouble *pt, + Polygon *poly, + Polygon *poly_new) { - int i; - double x1, y1, x2, y2; + gint i; + gdouble x1, y1, x2, y2; for (i = 0; i < poly->npts; i++) { @@ -1969,15 +1837,15 @@ loc[1] = 0.0; polygon_extents (poly, &dmin_x, &dmin_y, &dmax_x, &dmax_y); - min_x = (int) dmin_x; - min_y = (int) dmin_y; - max_x = (int) dmax_x; - max_y = (int) dmax_y; + min_x = (gint) dmin_x; + min_y = (gint) dmin_y; + max_x = (gint) dmax_x; + max_y = (gint) dmax_y; size_y = max_y - min_y; size_x = max_x - min_x; - min_scanlines = (int *) malloc (sizeof (int) * size_y); - max_scanlines = (int *) malloc (sizeof (int) * size_y); + min_scanlines = g_new (gint, size_y); + max_scanlines = g_new (gint, size_y); for (i = 0; i < size_y; i++) { min_scanlines[i] = max_x; @@ -1986,10 +1854,10 @@ for (i = 0; i < poly->npts; i++) { - xs = (int) ((i) ? poly->pts[i-1].x : poly->pts[poly->npts-1].x); - ys = (int) ((i) ? poly->pts[i-1].y : poly->pts[poly->npts-1].y); - xe = (int) poly->pts[i].x; - ye = (int) poly->pts[i].y; + xs = (gint) ((i) ? poly->pts[i-1].x : poly->pts[poly->npts-1].x); + ys = (gint) ((i) ? poly->pts[i-1].y : poly->pts[poly->npts-1].y); + xe = (gint) poly->pts[i].x; + ye = (gint) poly->pts[i].y; convert_segment (xs, ys, xe, ye, min_y, min_scanlines, max_scanlines); @@ -2039,16 +1907,16 @@ loc[1] = 0.0; } - free (min_scanlines); - free (max_scanlines); + g_free (min_scanlines); + g_free (max_scanlines); } static void -find_poly_color (Polygon *poly, +find_poly_color (Polygon *poly, GimpDrawable *drawable, - guchar *col, - gdouble color_var) + guchar *col, + gdouble color_var) { GimpPixelRgn src_rgn; gdouble dmin_x, dmin_y; @@ -2080,8 +1948,8 @@ size_y = max_y - min_y; size_x = max_x - min_x; - min_scanlines = (gint *) malloc (sizeof (gint) * size_y); - max_scanlines = (gint *) malloc (sizeof (gint) * size_y); + min_scanlines = g_new (int, size_y); + max_scanlines = g_new (int, size_y); for (i = 0; i < size_y; i++) { min_scanlines[i] = max_x; @@ -2134,8 +2002,8 @@ col[b] = col_sum[b]; } - free (min_scanlines); - free (max_scanlines); + g_free (min_scanlines); + g_free (max_scanlines); } @@ -2152,9 +2020,9 @@ static void -fill_poly_color (Polygon *poly, +fill_poly_color (Polygon *poly, GimpDrawable *drawable, - guchar *col) + guchar *col) { GimpPixelRgn src_rgn; gdouble dmin_x, dmin_y; @@ -2178,7 +2046,7 @@ gint supersample2; gint x1, y1, x2, y2; Vertex *pts_tmp; - const int poly_npts = poly->npts; + const gint poly_npts = poly->npts; /* Determine antialiasing */ if (mvals.antialiasing) @@ -2226,8 +2094,8 @@ size_y = (max_y - min_y) * supersample; size_x = (max_x - min_x) * supersample; - min_scanlines = min_scanlines_iter = (gint *) malloc (sizeof (gint) * size_y); - max_scanlines = max_scanlines_iter = (gint *) malloc (sizeof (gint) * size_y); + min_scanlines = min_scanlines_iter = g_new (gint, size_y); + max_scanlines = max_scanlines_iter = g_new (gint, size_y); for (i = 0; i < size_y; i++) { min_scanlines[i] = max_x * supersample; @@ -2273,7 +2141,7 @@ drawable->width, drawable->height, TRUE, TRUE); - vals = (gint *) malloc (sizeof (gint) * size_x); + vals = g_new (gint, size_x); for (i = 0; i < size_y; i++, min_scanlines_iter++, max_scanlines_iter++) { if (! (i % supersample)) @@ -2325,16 +2193,16 @@ } } - free (vals); - free (min_scanlines); - free (max_scanlines); + g_free (vals); + g_free (min_scanlines); + g_free (max_scanlines); } static void -fill_poly_image (Polygon *poly, +fill_poly_image (Polygon *poly, GimpDrawable *drawable, - gdouble vary) + gdouble vary) { GimpPixelRgn src_rgn, dest_rgn; gdouble dmin_x, dmin_y; @@ -2390,8 +2258,8 @@ size_y = (max_y - min_y) * supersample; size_x = (max_x - min_x) * supersample; - min_scanlines = (gint *) malloc (sizeof (gint) * size_y); - max_scanlines = (gint *) malloc (sizeof (gint) * size_y); + min_scanlines = g_new (gint, size_y); + max_scanlines = g_new (gint, size_y); for (i = 0; i < size_y; i++) { min_scanlines[i] = max_x * supersample; @@ -2420,7 +2288,7 @@ gimp_pixel_rgn_init (&dest_rgn, drawable, 0, 0, drawable->width, drawable->height, TRUE, TRUE); - vals = (gint *) malloc (sizeof (gint) * size_x); + vals = g_new (gint, size_x); for (i = 0; i < size_y; i++) { if (! (i % supersample)) @@ -2483,9 +2351,9 @@ } } - free (vals); - free (min_scanlines); - free (max_scanlines); + g_free (vals); + g_free (min_scanlines); + g_free (max_scanlines); } @@ -2542,7 +2410,7 @@ /* If the distance to an edge is less than the tile_spacing, there * will be no highlight as the tile blends to background here */ - if (dist < 1.0 || !mvals.tile_height) + if (dist < 1.0) contrib += vecs[i].light; else if (dist <= mvals.tile_height) contrib += vecs[i].light * (1.0 - (dist / mvals.tile_height)); @@ -2691,306 +2559,4 @@ polygon_reset (Polygon *poly) { poly->npts = 0; -} - - -int sgn(long x) -{ - if(x < 0) - return -1; - else if(x == 0) - return 0; - else - return 1; -} - - - -//if p1 includes p2 return 2; elsif p2 includes p1 return -1; elsif p1 && p2 have some points in common return 1; else return 0 - -int some_in_common(point *p1, int n1, point *p2, int n2) -{ - int i, j, o = 1; - long k1, k2, k3; - k kp2[n2], *pkp2; - point c1 = {0, 0}, c2 = {0, 0}, *pi1, *pi2, *pj1, *pj2; - - for (i = 0; i < n1; i++) { - c1.x += p1[i].x; - c1.y += p1[i].y; - } - for (j = 0; j < n2; j++) { - c2.x += p2[j].x; - c2.y += p2[j].y; - pj1 = p2 + j; - if (j == n2 - 1) - pj2 = p2; - else - pj2 = p2 + j + 1; - pkp2 = kp2 + j; - pkp2->k1 = pj2->y - pj1->y; - pkp2->k2 = pj1->x - pj2->x; - pkp2->k3 = pj2->x * pj1->y - pj2->y * pj1->x; - } - - for (i = 0; i < n1; i++) { - pi1 = p1 + i; - if (i == n1 - 1) - pi2 = p1; - else - pi2 = p1 + i + 1; - k1 = pi2->y - pi1->y; - k2 = pi1->x - pi2->x; - k3 = pi2->x * pi1->y - pi2->y * pi1->x; - if (o && sgn(c1.x * k1 + c1.y * k2 + n1 * k3) * sgn(c2.x * k1 + c2.y * k2 + n2 * k3) <= 0) - o = 0; - for(j = 0; j < n2; j++) { - pj1 = p2 + j; - if (j == n2 - 1) - pj2 = p2; - else - pj2 = p2 + j + 1; - pkp2 = kp2 + j; - if ( (sgn(pj1->x * k1 + pj1->y * k2 + k3) * sgn(pj2->x * k1 + pj2->y * k2 + k3) <= 0) && sgn(pi1->x * pkp2->k1 + pi1->y * pkp2->k2 + pkp2->k3) * sgn(pi2->x * pkp2->k1 + pi2->y * pkp2->k2 + pkp2->k3) <= 0) - return 1; - } - } - if (o) - return 2; - for (j = 0; j < n2; j++) { - pj1 = p2 + j; - if (j == n2 - 1) - pj2 = p2; - else - pj2 = p2 + j + 1; - pkp2 = kp2 + j; - if (sgn(c1.x * pkp2->k1 + c1.y * pkp2->k2 + n1 * pkp2->k3) * sgn(c2.x * pkp2->k1 + c2.y * pkp2->k2 + n2 * pkp2->k3) <= 0) - return 0; - } - return -1; -} - -double my_cos(int angle) { - return pe_cos[(angle + 10) % 10]; -} - -double my_sin(int angle) { - return pe_sin[(angle + 10) % 10]; -} - - -void plotp(int type, float x, float y, int angle, int included) -{ - point p[4]; - float len = pe_len[0]; - - if (type == ATILE) { - p[0].x = rintl(x - pe_len[1] * my_cos(angle)); - p[0].y = rintl(y - pe_len[1] * my_sin(angle)); - p[1].x = rintl(x + len * my_cos(angle - 4)); - p[1].y = rintl(y + len * my_sin(angle - 4)); - p[2].x = rintl(x); - p[2].y = rintl(y); - p[3].x = rintl(x + len * my_cos(angle + 4)); - p[3].y = rintl(y + len * my_sin(angle + 4)); - } else if (type == BTILE) { - p[0].x = rintl(x); - p[0].y = rintl(y); - p[1].x = rintl(x + len * my_cos(angle - 1)); - p[1].y = rintl(y + len * my_sin(angle - 1)); - p[2].x = rintl(x + pe_len[1] * my_cos(angle)); - p[2].y = rintl(y + pe_len[1] * my_sin(angle)); - p[3].x = rintl(x + len * my_cos(angle + 1)); - p[3].y = rintl(y + len * my_sin(angle + 1)); - } else if (type == CTILE) { - p[0].x = rintl(x); - p[0].y = rintl(y); - p[1].x = rintl(x + len * my_cos(angle - 2)); - p[1].y = rintl(y + len * my_sin(angle - 2)); - p[2].x = rintl(x + pe_len[-1] * my_cos(angle)); - p[2].y = rintl(y + pe_len[-1] * my_sin(angle)); - p[3].x = rintl(x + len * my_cos(angle + 2)); - p[3].y = rintl(y + len * my_sin(angle + 2)); - } else /* type == DTILE */ { - p[0].x = rintl(x - pe_len[-1] * my_cos(angle)); - p[0].y = rintl(y - pe_len[-1] * my_sin(angle)); - p[1].x = rintl(x + len * my_cos(angle - 3)); - p[1].y = rintl(y + len * my_sin(angle - 3)); - p[2].x = rintl(x); - p[2].y = rintl(y); - p[3].x = rintl(x + len * my_cos(angle + 3)); - p[3].y = rintl(y + len * my_sin(angle + 3)); - } - if (included || some_in_common(p, 4, little, 4)) { - print_points(p, 4); - } -} - -void plot(float x, float y, int angle, int type, int n, int included) -{ - if ((type == ATILE) || (type == CTILE) || !(n & 4) ) { - switch(type) { - case ATILE: - plotp(ATILE, x, y, angle, included); - break; - - case BTILE: - plotp(BTILE, x, y, angle, included); - break; - - case CTILE: - plotp(CTILE, x, y, angle, included); - break; - - case DTILE: - plotp(DTILE, x, y, angle, included); - break; - } - } -} - -void A(int k, float x, float y, int angle, int n, int included) -{ - float x1, y1, x3, y3; - point p[3]; - int r; - if (!k) - plot(x, y, angle, ATILE, n, included); - else { - p[0].x = rintl(x1 = x - pe_len[k + 1] * my_cos(angle)); - p[0].y = rintl(y1 = y - pe_len[k + 1] * my_sin(angle)); - p[1].x = rintl(x); - p[1].y = rintl(y); - p[2].x = rintl(x3 = x + pe_len[k] * my_cos(angle + 4)); - p[2].y = rintl(y3 = y + pe_len[k] * my_sin(angle + 4)); - - if (!included) { - r = some_in_common(p, 3, big, 4); - if (!r) - return; - if (r == -1) - included = 1; - } - B(k - 1, x1, y1, angle, neighbours[ATILE][n][BTILE], included); - A(k - 1, x3, y3, angle + 4, neighbours[ATILE][n][ATILE], included); - C(k - 1, x3, y3, angle + 6, neighbours[ATILE][n][CTILE], included); - } -} - -void B(int k, float x, float y, int angle, int n, int included) -{ - float x2, y2, x3, y3; - point p[3]; - int r; - if (!k) - plot(x, y, angle, BTILE, n, included); - else { - p[0].x = rintl(x); - p[0].y = rintl(y); - p[1].x = rintl(x2 = x + pe_len[k + 1] * my_cos(angle)); - p[1].y = rintl(y2 = y + pe_len[k + 1] * my_sin(angle)); - p[2].x = rintl(x3 = x + pe_len[k] * my_cos(angle + 1)); - p[2].y = rintl(y3 = y + pe_len[k] * my_sin(angle + 1)); - - if (!included) { - r = some_in_common(p, 3, big, 4); - if (!r) - return; - if (r == -1) - included = 1; - } - B(k - 1, x3, y3, angle + 6, neighbours[BTILE][n][BTILE], included); - A(k - 1, x2, y2, angle, neighbours[BTILE][n][ATILE], included); - D(k - 1, x3, y3, angle + 4, neighbours[BTILE][n][DTILE], included); - } -} - -void C(int k, float x, float y, int angle, int n, int included) -{ - float x2, y2, x3, y3; - point p[3]; - int r; - if (!k) - plot(x, y, angle, CTILE, n, included); - else { - p[0].x = rintl(x); - p[0].y = rintl(y); - p[1].x = rintl(x2 = x + pe_len[k - 1] * my_cos(angle)); - p[1].y = rintl(y2 = y + pe_len[k - 1] * my_sin(angle)); - p[2].x = rintl(x3 = x + pe_len[k] * my_cos(angle + 2)); - p[2].y = rintl(y3 = y + pe_len[k] * my_sin(angle + 2)); - - if (!included) { - r = some_in_common(p, 3, big, 4); - if (!r) - return; - if (r == -1) - included = 1; - } - - C(k - 1, x2, y2, angle + 3, neighbours[CTILE][n][CTILE], included); - B(k - 1, x3, y3, angle + 7, neighbours[CTILE][n][BTILE], included); - } -} - - -void D(int k, float x, float y, int angle, int n, int included) -{ - float x1, y1, x3, y3; - point p[3]; - int r; - if (!k) - plot(x, y, angle, DTILE, n, included); - else { - p[0].x = rintl(x1 = x - pe_len[k - 1] * my_cos(angle)); - p[0].y = rintl(y1 = y - pe_len[k - 1] * my_sin(angle)); - p[1].x = rintl(x); - p[1].y = rintl(y); - p[2].x = rintl(x3 = x + pe_len[k] * my_cos(angle + 3)); - p[2].y = rintl(y3 = y + pe_len[k] * my_sin(angle + 3)); - if (!included) { - r = some_in_common(p, 3, big, 4); - if (!r) - return; - if (r == -1) - included = 1; - } - D(k - 1, x1, y1, angle + 7, neighbours[DTILE][n][DTILE], included); - A(k - 1, x3, y3, angle + 3, neighbours[DTILE][n][ATILE], included); - } -} - - -void -my_radio_button_update (GtkWidget *widget, - gpointer data) -{ - gint *toggle_val; - - if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget))) - { - toggle_val = (gint *) data; - - *toggle_val = - GPOINTER_TO_INT (gtk_object_get_user_data (GTK_OBJECT (widget))); - - set_sensitive_tn(*toggle_val != PENROSE_ROMBS); - - } - - gimp_toggle_button_sensitive_update (GTK_TOGGLE_BUTTON (widget)); -} - -void set_sensitive_tn(gint val) -{ - static gdouble tn_val = TN_DEF_VAL; - gtk_widget_set_sensitive (gtk_object_get_data(scale_tn, "label"), val); - gtk_widget_set_sensitive (gtk_object_get_data(scale_tn, "scale"), val); - gtk_widget_set_sensitive (gtk_object_get_data(scale_tn, "spinbutton"), val); - if(val) { - gtk_adjustment_set_value (GTK_ADJUSTMENT (scale_tn), tn_val); - } else { - tn_val = mvals.tile_neatness; - gtk_adjustment_set_value (GTK_ADJUSTMENT (scale_tn), 1); - } }