Commit 97247b33 authored by David Odin's avatar David Odin
Browse files

ported to GimpPreviewArea, did some cleanup and removed tabs.

* plug-ins/common/jigsaw.c: ported to GimpPreviewArea, did some
  cleanup and removed tabs.
parent b3867f65
2004-08-07 DindinX <david@dindinx.org>
* plug-ins/common/jigsaw.c: ported to GimpPreviewArea, did some
cleanup and removed tabs.
2004-08-07 Sven Neumann <sven@gimp.org>
* configure.in: bumped version number to 2.1.4.
......
......@@ -46,8 +46,6 @@
#include "libgimp/stdplugins-intl.h"
#include "gimpoldpreview.h"
typedef enum
{
BEZIER_1,
......@@ -65,10 +63,10 @@ typedef enum
static void query (void);
static void run (const gchar *name,
gint nparams,
const GimpParam *param,
gint *nreturn_vals,
GimpParam **return_vals);
gint nparams,
const GimpParam *param,
gint *nreturn_vals,
GimpParam **return_vals);
static gint jigsaw (gboolean preview_mode);
static void jigsaw_values_changed (GtkWidget *widget, gpointer data);
......@@ -78,105 +76,89 @@ static gboolean dialog_box (void);
static void draw_jigsaw (guchar *buffer,
gint bufsize,
gint width,
gint height,
gint bytes,
gboolean preview_mode);
gint width,
gint height,
gint bytes,
gboolean preview_mode);
static void draw_vertical_border (guchar *buffer, gint bufsize,
gint width, gint height,
gint bytes, gint x_offset, gint ytiles,
gint blend_lines, gdouble blend_amount,
gboolean preview_mode);
gint bytes, gint x_offset, gint ytiles,
gint blend_lines, gdouble blend_amount);
static void draw_horizontal_border (guchar *buffer, gint bufsize,
gint width, gint bytes,
gint y_offset, gint xtiles,
gint blend_lines, gdouble blend_amount,
gboolean preview_mode);
gint blend_lines, gdouble blend_amount);
static void draw_vertical_line (guchar *buffer, gint bufsize,
gint width, gint bytes,
gint px[2], gint py[2],
gboolean preview_mode);
gint px[2], gint py[2]);
static void draw_horizontal_line (guchar *buffer, gint bufsize,
gint width, gint bytes,
gint px[2], gint py[2],
gboolean preview_mode);
gint px[2], gint py[2]);
static void darken_vertical_line (guchar *buffer, gint bufsize,
gint width, gint bytes,
gint *px, gint *py, gdouble delta,
gboolean preview_mode);
gint *px, gint *py, gdouble delta);
static void lighten_vertical_line (guchar *buffer, gint bufsize,
gint width, gint bytes,
gint *px, gint *py, gdouble delta,
gboolean preview_mode);
gint *px, gint *py, gdouble delta);
static void darken_horizontal_line (guchar *buffer, gint bufsize,
gint width, gint bytes,
gint *px, gint *py, gdouble delta,
gboolean preview_mode);
gint *px, gint *py, gdouble delta);
static void lighten_horizontal_line(guchar *buffer, gint bufsize,
gint width, gint bytes,
gint *px, gint *py, gdouble delta,
gboolean preview_mode);
gint *px, gint *py, gdouble delta);
static void draw_right_bump (guchar *buffer, gint bufsize,
gint width, gint bytes,
gint x_offset, gint curve_start_offset,
gint steps, gboolean preview_mode);
gint x_offset, gint curve_start_offset,
gint steps);
static void draw_left_bump (guchar *buffer, gint bufsize,
gint width, gint bytes,
gint x_offset, gint curve_start_offset,
gint steps, gboolean preview_mode);
gint x_offset, gint curve_start_offset,
gint steps);
static void draw_up_bump (guchar *buffer, gint bufsize,
gint width, gint bytes,
gint y_offset, gint curve_start_offset,
gint steps, gboolean preview_mode);
gint y_offset, gint curve_start_offset,
gint steps);
static void draw_down_bump (guchar *buffer, gint bufsize,
gint width, gint bytes,
gint y_offset, gint curve_start_offset,
gint steps, gboolean preview_mode);
gint y_offset, gint curve_start_offset,
gint steps);
static void darken_right_bump (guchar *buffer, gint bufsize,
gint width, gint bytes,
gint x_offset, gint curve_start_offset,
gint steps, gdouble delta, gint counter,
gboolean preview_mode);
gint x_offset, gint curve_start_offset,
gint steps, gdouble delta, gint counter);
static void lighten_right_bump (guchar *buffer, gint bufsize,
gint width, gint bytes,
gint x_offset, gint curve_start_offset,
gint steps, gdouble delta, gint counter,
gboolean preview_mode);
gint x_offset, gint curve_start_offset,
gint steps, gdouble delta, gint counter);
static void darken_left_bump (guchar *buffer, gint bufsize,
gint width, gint bytes,
gint x_offset, gint curve_start_offset,
gint steps, gdouble delta, gint counter,
gboolean preview_mode);
gint x_offset, gint curve_start_offset,
gint steps, gdouble delta, gint counter);
static void lighten_left_bump (guchar *buffer, gint bufsize,
gint width, gint bytes,
gint x_offset, gint curve_start_offset,
gint steps, gdouble delta, gint counter,
gboolean preview_mode);
gint x_offset, gint curve_start_offset,
gint steps, gdouble delta, gint counter);
static void darken_up_bump (guchar *buffer, gint bufsize,
gint width, gint bytes,
gint y_offset, gint curve_start_offest,
gint steps, gdouble delta, gint counter,
gboolean preview_mode);
gint y_offset, gint curve_start_offest,
gint steps, gdouble delta, gint counter);
static void lighten_up_bump (guchar *buffer, gint bufsize,
gint width, gint bytes,
gint y_offset, gint curve_start_offset,
gint steps, gdouble delta, gint counter,
gboolean preview_mode);
gint y_offset, gint curve_start_offset,
gint steps, gdouble delta, gint counter);
static void darken_down_bump (guchar *buffer, gint bufsize,
gint width, gint bytes,
gint y_offset, gint curve_start_offset,
gint steps, gdouble delta, gint counter,
gboolean preview_mode);
gint y_offset, gint curve_start_offset,
gint steps, gdouble delta, gint counter);
static void lighten_down_bump (guchar *buffer, gint bufsize,
gint width, gint bytes,
gint y_offset, gint curve_start_offset,
gint steps, gdouble delta, gint counter,
gboolean preview_mode);
gint y_offset, gint curve_start_offset,
gint steps, gdouble delta, gint counter);
static void generate_grid (gint width, gint height, gint xtiles, gint ytiles,
gint *x, gint *y);
gint *x, gint *y);
static void generate_bezier (gint px[4], gint py[4], gint steps,
gint *cachex, gint *cachey);
gint *cachex, gint *cachey);
static void malloc_cache (void);
static void free_cache (void);
static void init_right_bump (gint width, gint height);
......@@ -185,32 +167,27 @@ static void init_up_bump (gint width, gint height);
static void init_down_bump (gint width, gint height);
static void draw_bezier_line (guchar *buffer, gint bufsize,
gint width, gint bytes,
gint steps, gint *cx, gint *cy,
gboolean preview_mode);
gint steps, gint *cx, gint *cy);
static void darken_bezier_line (guchar *buffer, gint bufsize,
gint width, gint bytes,
gint x_offset, gint y_offset, gint steps,
gint *cx, gint *cy, gdouble delta,
gboolean preview_mode);
gint x_offset, gint y_offset, gint steps,
gint *cx, gint *cy, gdouble delta);
static void lighten_bezier_line (guchar *buffer, gint bufsize,
gint width, gint bytes,
gint x_offset, gint y_offset, gint steps,
gint *cx, gint *cy, gdouble delta,
gboolean preview_mode);
gint x_offset, gint y_offset, gint steps,
gint *cx, gint *cy, gdouble delta);
static void draw_bezier_vertical_border (guchar *buffer, gint bufsize,
gint width, gint height,
gint bytes,
gint x_offset, gint xtiles,
gint ytiles, gint blend_lines,
gdouble blend_amount, gint steps,
gboolean preview_mode);
gint x_offset, gint xtiles,
gint ytiles, gint blend_lines,
gdouble blend_amount, gint steps);
static void draw_bezier_horizontal_border (guchar *buffer, gint bufsize,
gint width, gint height,
gint bytes,
gint x_offset, gint xtiles,
gint ytiles, gint blend_lines,
gdouble blend_amount, gint steps,
gboolean preview_mode);
gint x_offset, gint xtiles,
gint ytiles, gint blend_lines,
gdouble blend_amount, gint steps);
static void check_config (gint width, gint height);
......@@ -380,7 +357,10 @@ static globals_t globals =
};
/* preview globals */
static GimpOldPreview *preview;
#define PREVIEW_SIZE 128
static GtkWidget *preview;
static gint preview_width, preview_height, preview_bpp;
static guchar *preview_cache;
MAIN ()
......@@ -400,16 +380,16 @@ query (void)
};
gimp_install_procedure ("plug_in_jigsaw",
"Renders a jigsaw puzzle look",
"Jigsaw puzzle look",
"Nigel Wetten",
"Nigel Wetten",
"May 2000",
N_("_Jigsaw..."),
"RGB*",
GIMP_PLUGIN,
G_N_ELEMENTS (args), 0,
args, NULL);
"Renders a jigsaw puzzle look",
"Jigsaw puzzle look",
"Nigel Wetten",
"Nigel Wetten",
"May 2000",
N_("_Jigsaw..."),
"RGB*",
GIMP_PLUGIN,
G_N_ELEMENTS (args), 0,
args, NULL);
gimp_plugin_menu_register ("plug_in_jigsaw",
N_("<Image>/Filters/Render/Pattern"));
......@@ -423,8 +403,8 @@ run (const gchar *name,
GimpParam **return_vals)
{
static GimpParam values[1];
GimpDrawable *drawable;
GimpRunMode run_mode;
GimpDrawable *drawable;
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
INIT_I18N ();
......@@ -438,36 +418,36 @@ run (const gchar *name,
{
case GIMP_RUN_NONINTERACTIVE:
if (nparams == 8)
{
config.x = param[3].data.d_int32;
config.y = param[4].data.d_int32;
config.style = param[5].data.d_int32;
config.blend_lines = param[6].data.d_int32;
config.blend_amount = param[7].data.d_float;
if (jigsaw(FALSE) == -1)
{
status = GIMP_PDB_EXECUTION_ERROR;
}
}
{
config.x = param[3].data.d_int32;
config.y = param[4].data.d_int32;
config.style = param[5].data.d_int32;
config.blend_lines = param[6].data.d_int32;
config.blend_amount = param[7].data.d_float;
if (jigsaw(FALSE) == -1)
{
status = GIMP_PDB_EXECUTION_ERROR;
}
}
else
{
status = GIMP_PDB_CALLING_ERROR;
}
{
status = GIMP_PDB_CALLING_ERROR;
}
break;
case GIMP_RUN_INTERACTIVE:
gimp_get_data("plug_in_jigsaw", &config);
if (! dialog_box())
{
status = GIMP_PDB_CANCEL;
break;
}
status = GIMP_PDB_CANCEL;
break;
}
gimp_progress_init (_("Assembling Jigsaw..."));
if (jigsaw(FALSE) == -1)
{
status = GIMP_PDB_CALLING_ERROR;
break;
}
{
status = GIMP_PDB_CALLING_ERROR;
break;
}
gimp_set_data("plug_in_jigsaw", &config, sizeof(config_t));
gimp_displays_flush();
break;
......@@ -475,14 +455,14 @@ run (const gchar *name,
case GIMP_RUN_WITH_LAST_VALS:
gimp_get_data("plug_in_jigsaw", &config);
if (jigsaw(FALSE) == -1)
{
status = GIMP_PDB_EXECUTION_ERROR;
gimp_message("An execution error occured.");
}
{
status = GIMP_PDB_EXECUTION_ERROR;
gimp_message("An execution error occured.");
}
else
{
gimp_displays_flush();
}
{
gimp_displays_flush();
}
} /* switch */
......@@ -492,44 +472,38 @@ run (const gchar *name,
*return_vals = values;
values[0].type = GIMP_PDB_STATUS;
values[0].data.d_status = status;
return;
}
static gint
jigsaw (gboolean preview_mode)
{
GimpPixelRgn src_pr, dest_pr;
guchar *buffer;
GimpPixelRgn src_pr, dest_pr;
guchar *buffer;
GimpDrawable *drawable = globals.drawable;
gint width;
gint height;
gint bytes;
gint buffer_size;
gint width;
gint height;
gint bytes;
gint buffer_size;
if (preview_mode)
{
width = preview->width;
height = preview->height;
bytes = preview->bpp;
buffer_size = preview->rowstride * height;
if (buffer_size == 0)
return -1;
width = preview_width;
height = preview_height;
}
else
{
width = drawable->width;
height = drawable->height;
bytes = drawable->bpp;
buffer_size = bytes * width * height;
}
bytes = drawable->bpp;
buffer_size = bytes * width * height;
/* setup image buffer */
buffer = g_malloc (buffer_size);
buffer = g_new (guchar, buffer_size);
if (preview_mode)
{
memcpy (buffer, preview->cache, buffer_size);
memcpy (buffer, preview_cache, buffer_size);
}
else
{
......@@ -550,15 +524,11 @@ jigsaw (gboolean preview_mode)
/* cleanup */
if (preview_mode)
{
int y;
for (y = 0; y < preview->height; y++)
{
gimp_old_preview_do_row (preview, y, preview->width,
&buffer[preview->rowstride * y]);
}
gtk_widget_queue_draw (preview->widget);
gimp_preview_area_draw (GIMP_PREVIEW_AREA (preview),
0, 0, width, height,
gimp_drawable_type (drawable->drawable_id),
buffer,
width * bytes);
}
else
{
......@@ -581,10 +551,10 @@ jigsaw_values_changed (GtkWidget *widget, gpointer data)
static void
generate_bezier (gint px[4],
gint py[4],
gint steps,
gint *cachex,
gint *cachey)
gint py[4],
gint steps,
gint *cachex,
gint *cachey)
{
gdouble t = 0.0;
gdouble sigma = 1.0 / steps;
......@@ -599,26 +569,25 @@ generate_bezier (gint px[4],
t3 = t2 * t;
t_1 = 1 - t;
x = t_1 * t_1 * t_1 * px[0]
+ 3 * t * t_1 * t_1 * px[1]
+ 3 * t2 * t_1 * px[2]
+ t3 * px[3];
+ 3 * t * t_1 * t_1 * px[1]
+ 3 * t2 * t_1 * px[2]
+ t3 * px[3];
y = t_1 * t_1 * t_1 * py[0]
+ 3 * t * t_1 * t_1 * py[1]
+ 3 * t2 * t_1 * py[2]
+ t3 * py[3];
+ 3 * t * t_1 * t_1 * py[1]
+ 3 * t2 * t_1 * py[2]
+ t3 * py[3];
cachex[i] = (gint) (x + 0.2);
cachey[i] = (gint) (y + 0.2);
} /* for */
return;
}
static void
draw_jigsaw (guchar *buffer,
gint bufsize,
gint width,
gint height,
gint bytes,
gboolean preview_mode)
gint width,
gint height,
gint bytes,
gboolean preview_mode)
{
gint i;
gint *x, *y;
......@@ -649,39 +618,39 @@ draw_jigsaw (guchar *buffer,
if (style == BEZIER_1)
{
for (i = 0; i < xlines; i++)
{
{
draw_vertical_border (buffer, bufsize, width, height, bytes,
x[i], ytiles,
blend_lines, blend_amount, preview_mode);
if (!preview_mode)
gimp_progress_update ((gdouble) i / (gdouble) progress_total);
}
blend_lines, blend_amount);
if (!preview_mode)
gimp_progress_update ((gdouble) i / (gdouble) progress_total);
}
for (i = 0; i < ylines; i++)
{
{
draw_horizontal_border (buffer, bufsize, width, bytes, y[i], xtiles,
blend_lines, blend_amount, preview_mode);
if (!preview_mode)
gimp_progress_update ((gdouble) (i + xlines) / (gdouble) progress_total);
}
blend_lines, blend_amount);
if (!preview_mode)
gimp_progress_update ((gdouble) (i + xlines) / (gdouble) progress_total);
}
}
else if (style == BEZIER_2)
{
for (i = 0; i < xlines; i++)
{
{
draw_bezier_vertical_border (buffer, bufsize, width, height, bytes,
x[i], xtiles, ytiles, blend_lines,
blend_amount, steps, preview_mode);
if (!preview_mode)
gimp_progress_update ((gdouble) i / (gdouble) progress_total);
}
blend_amount, steps);
if (!preview_mode)
gimp_progress_update ((gdouble) i / (gdouble) progress_total);
}
for (i = 0; i < ylines; i++)
{
{
draw_bezier_horizontal_border (buffer, bufsize, width, height, bytes,
y[i], xtiles, ytiles, blend_lines,
blend_amount, steps, preview_mode);
if (!preview_mode)
gimp_progress_update ((gdouble) (i + xlines) / (gdouble) progress_total);
}
blend_amount, steps);
if (!preview_mode)
gimp_progress_update ((gdouble) (i + xlines) / (gdouble) progress_total);
}
}
else
{
......@@ -691,21 +660,18 @@ draw_jigsaw (guchar *buffer,
g_free (globals.gridx);
g_free (globals.gridy);
return;
}
static void
draw_vertical_border (guchar *buffer,
gint bufsize,
gint width,
gint height,
gint bytes,
gint x_offset,
gint ytiles,
gint blend_lines,
gdouble blend_amount,
gboolean preview_mode)
gint width,
gint height,
gint bytes,
gint x_offset,
gint ytiles,
gint blend_lines,
gdouble blend_amount)
{
gint i, j;
gint tile_height = height / ytiles;
......@@ -724,116 +690,108 @@ draw_vertical_border (guchar *buffer,
{
right = g_random_int_range (0, 2);
if (right)
{
style_index = RIGHT;
}
{
style_index = RIGHT;
}
else
{
style_index = LEFT;
}
{
style_index = LEFT;
}
/* first straight line from top downwards */
px[0] = px[1] = x_offset;
py[0] = y_offset; py[1] = y_offset + curve_start_offset - 1;
draw_vertical_line (buffer, bufsize, width, bytes, px, py,
preview_mode);
draw_vertical_line (buffer, bufsize, width, bytes, px, py);
delta = blend_amount;
dy[0] = ly[0] = py[0]; dy[1] = ly[1] = py[1];
if (!right)
{
ly[1] += blend_lines + 2;
}
{
ly[1] += blend_lines + 2;
}
for (j = 0; j < blend_lines; j++)
{
dy[0]++; dy[1]--; ly[0]++; ly[1]--;
px[0] = x_offset - j - 1;
darken_vertical_line (buffer, bufsize, width, bytes, px, dy, delta,
preview_mode);
px[0] = x_offset + j + 1;
lighten_vertical_line (buffer, bufsize, width, bytes, px, ly, delta,
preview_mode);
delta -= sigma;
}
{