cleaned it up, fixed a (documented) memory leak and the weird behaviour of

* plug-ins/common/newsprint.c: cleaned it up, fixed a (documented) memory
  leak and the weird behaviour of the resolution scales.
This commit is contained in:
David Odin
2004-10-23 21:29:56 +00:00
parent e4202235f0
commit c44f008737
2 changed files with 45 additions and 33 deletions

View File

@ -1,3 +1,8 @@
2004-10-23 DindinX <dindinx@gimp.org>
* plug-ins/common/newsprint.c: cleaned it up, fixed a (documented)
memory leak and the weird behaviour of the resolution scales.
2004-10-23 DindinX <dindinx@gimp.org> 2004-10-23 DindinX <dindinx@gimp.org>
* plug-ins/common/newsprint.c: added a preview. * plug-ins/common/newsprint.c: added a preview.

View File

@ -227,9 +227,10 @@ typedef struct
/* bits of state used by the UI, but not visible from the PDB */ /* bits of state used by the UI, but not visible from the PDB */
typedef struct typedef struct
{ {
gint input_spi; /* input samples per inch */ gdouble input_spi; /* input samples per inch */
gdouble output_lpi; /* desired output lines per inch */ gdouble output_lpi; /* desired output lines per inch */
gint lock_channels; /* changes to one channel affect all */ gboolean lock_channels; /* changes to one channel affect all */
gboolean preview;
} NewsprintUIValues; } NewsprintUIValues;
@ -312,9 +313,10 @@ static const NewsprintValues factory_defaults =
static const NewsprintUIValues factory_defaults_ui = static const NewsprintUIValues factory_defaults_ui =
{ {
72, /* input spi */ 72, /* input spi */
7.2, /* output lpi */ 7.2, /* output lpi */
FALSE /* lock channels */ FALSE, /* lock channels */
TRUE /* preview */
}; };
/* Mutable copy for normal use. Initialised in run(). */ /* Mutable copy for normal use. Initialised in run(). */
@ -723,7 +725,7 @@ preview_update (channel_st *st)
if (!spotfn_list[sfn].prev_thresh) if (!spotfn_list[sfn].prev_thresh)
{ {
spotfn_list[sfn].prev_thresh = spotfn_list[sfn].prev_thresh =
spot2thresh (sfn, SPOT_PREVIEW_SZ*PREVIEW_OVERSAMPLE); spot2thresh (sfn, SPOT_PREVIEW_SZ * PREVIEW_OVERSAMPLE);
} }
thresh = spotfn_list[sfn].prev_thresh; thresh = spotfn_list[sfn].prev_thresh;
@ -878,6 +880,8 @@ lpi_callback (GtkAdjustment *adjustment,
gimp_double_adjustment_update (adjustment, &pvals_ui.output_lpi); gimp_double_adjustment_update (adjustment, &pvals_ui.output_lpi);
g_print ("lpi (%g / %g = %d)\n", pvals_ui.input_spi, pvals_ui.output_lpi, pvals.cell_width);
g_signal_handlers_block_by_func (st->cellsize, g_signal_handlers_block_by_func (st->cellsize,
cellsize_callback, cellsize_callback,
data); data);
@ -898,6 +902,7 @@ spi_callback (GtkAdjustment *adjustment,
gimp_double_adjustment_update (adjustment, &pvals_ui.input_spi); gimp_double_adjustment_update (adjustment, &pvals_ui.input_spi);
g_print ("spi (%g / %g = %d)\n", pvals_ui.input_spi, pvals_ui.output_lpi, pvals.cell_width);
g_signal_handlers_block_by_func (st->output_lpi, g_signal_handlers_block_by_func (st->output_lpi,
lpi_callback, lpi_callback,
data); data);
@ -918,6 +923,7 @@ cellsize_callback (GtkAdjustment *adjustment,
gimp_int_adjustment_update (adjustment, &pvals.cell_width); gimp_int_adjustment_update (adjustment, &pvals.cell_width);
g_print ("cell (%g / %g = %d)\n", pvals_ui.input_spi, pvals_ui.output_lpi, pvals.cell_width);
g_signal_handlers_block_by_func (st->output_lpi, g_signal_handlers_block_by_func (st->output_lpi,
lpi_callback, lpi_callback,
data); data);
@ -1207,7 +1213,7 @@ newsprint_dialog (GimpDrawable *drawable)
TRUE, TRUE, 0); TRUE, TRUE, 0);
gtk_widget_show (main_vbox); gtk_widget_show (main_vbox);
preview = gimp_drawable_preview_new (drawable, NULL); // FIXME preview = gimp_drawable_preview_new (drawable, &pvals_ui.preview);
gtk_box_pack_start_defaults (GTK_BOX (main_vbox), preview); gtk_box_pack_start_defaults (GTK_BOX (main_vbox), preview);
gtk_widget_show (preview); gtk_widget_show (preview);
g_signal_connect_swapped (preview, "invalidated", g_signal_connect_swapped (preview, "invalidated",
@ -1749,28 +1755,28 @@ newsprint (GimpDrawable *drawable,
GimpPreview *preview) GimpPreview *preview)
{ {
GimpPixelRgn src_rgn, dest_rgn; GimpPixelRgn src_rgn, dest_rgn;
guchar *src_row, *dest_row; guchar *src_row, *dest_row;
guchar *src, *dest; guchar *src, *dest;
guchar *thresh[4]; guchar *thresh[4] = { NULL, NULL, NULL, NULL };
gdouble r; gdouble r;
gdouble theta; gdouble theta;
gdouble rot[4]; gdouble rot[4];
gint bpp, colour_bpp; gint bpp, colour_bpp;
gint has_alpha; gint has_alpha;
gint b; gint b;
gint tile_width; gint tile_width;
gint width; gint width;
gint row, col; gint row, col;
gint x, y, x_step, y_step; gint x, y, x_step, y_step;
gint x1, y1, x2, y2; gint x1, y1, x2, y2;
gint preview_width, preview_height; gint preview_width, preview_height;
gint rx, ry; gint rx, ry;
gint progress, max_progress; gint progress, max_progress;
gint oversample; gint oversample;
gint colourspace; gint colourspace;
gpointer pr; gpointer pr;
gint w002; gint w002;
guchar *preview_buffer = NULL; guchar *preview_buffer = NULL;
#ifdef TIMINGS #ifdef TIMINGS
GTimer *timer = g_timer_new (); GTimer *timer = g_timer_new ();
@ -1901,7 +1907,7 @@ do { \
FALSE/*dirty*/, FALSE/*shadow*/); FALSE/*dirty*/, FALSE/*shadow*/);
gimp_pixel_rgn_init (&dest_rgn, drawable, x, y, x_step, y_step, gimp_pixel_rgn_init (&dest_rgn, drawable, x, y, x_step, y_step,
TRUE, TRUE/*shadow*/); TRUE/*dirty*/, TRUE/*shadow*/);
/* page in the image, one tile at a time */ /* page in the image, one tile at a time */
for (pr = gimp_pixel_rgns_register (2, &src_rgn, &dest_rgn); for (pr = gimp_pixel_rgns_register (2, &src_rgn, &dest_rgn);
@ -2057,8 +2063,9 @@ do { \
g_timer_destroy (timer); g_timer_destroy (timer);
#endif #endif
/* We don't free the threshold matrices, since we're about to for (b = 0; b < 4; b++)
* exit, and the OS should clean up after us. */ if (thresh[b])
g_free (thresh[b]);
if (preview) if (preview)
{ {