diff --git a/ChangeLog b/ChangeLog index b7a917b1fd..362de43810 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +Sat Aug 21 16:53:17 BST 1999 Adam D. Moss + + * plug-ins/common/jpeg.c: Preview layers need to be alpha-padded, + since they're not on the bottom of the stack. That's a GIMP rule. + + Plus... use new API functions gimp_image_{freeze,thaw}_undo() to avoid + the dilemma of either consuming a squillion superfluous tiles or + clobbering the whole undo stack. + + * app/gimage.h + * app/gimage_cmds.c + * app/gimpimage.c + * libgimp/gimp.h + * libgimp/gimpimage.c: New API functions + gimp_image_{freeze,thaw}_undo() to avoid the above twin evils. + Similar to gimp_image_{disable,enable}_undo() but without + clobbering the undo stack (I would have simply changed the latter, + but too many plugins seem to rely on that behaviour). See the PDB + docs for slightly more information. + Sat Aug 21 8:47:00 CST 1999 Seth Burgess * plug-ins/common/jpeg.c : added a patch by Xach for slider diff --git a/app/core/gimpimage-guides.c b/app/core/gimpimage-guides.c index 809ed36828..8145ad39a6 100644 --- a/app/core/gimpimage-guides.c +++ b/app/core/gimpimage-guides.c @@ -3337,11 +3337,16 @@ gimp_image_filename (GimpImage *gimage) } int -gimp_image_enable_undo (GimpImage *gimage) +gimp_image_freeze_undo (GimpImage *gimage) { - /* Free all undo steps as they are now invalidated */ - undo_free (gimage); + gimage->undo_on = FALSE; + return TRUE; +} + +int +gimp_image_thaw_undo (GimpImage *gimage) +{ gimage->undo_on = TRUE; return TRUE; @@ -3350,8 +3355,16 @@ gimp_image_enable_undo (GimpImage *gimage) int gimp_image_disable_undo (GimpImage *gimage) { - gimage->undo_on = FALSE; - return TRUE; + return gimp_image_freeze_undo (gimage); +} + +int +gimp_image_enable_undo (GimpImage *gimage) +{ + /* Free all undo steps as they are now invalidated */ + undo_free (gimage); + + return gimp_image_thaw_undo (gimage); } int @@ -3559,7 +3572,8 @@ gimp_image_construct_composite_preview (GimpImage *gimage, * composite preview... * Indexed images are actually already converted to RGB and RGBA, * so just project them as if they were type "intensity" - * Send in all TRUE for visible since that info doesn't matter for previews + * Send in all TRUE for visible since that info doesn't matter + * for previews */ switch (drawable_type (GIMP_DRAWABLE(layer))) { diff --git a/app/core/gimpimage-merge.c b/app/core/gimpimage-merge.c index 809ed36828..8145ad39a6 100644 --- a/app/core/gimpimage-merge.c +++ b/app/core/gimpimage-merge.c @@ -3337,11 +3337,16 @@ gimp_image_filename (GimpImage *gimage) } int -gimp_image_enable_undo (GimpImage *gimage) +gimp_image_freeze_undo (GimpImage *gimage) { - /* Free all undo steps as they are now invalidated */ - undo_free (gimage); + gimage->undo_on = FALSE; + return TRUE; +} + +int +gimp_image_thaw_undo (GimpImage *gimage) +{ gimage->undo_on = TRUE; return TRUE; @@ -3350,8 +3355,16 @@ gimp_image_enable_undo (GimpImage *gimage) int gimp_image_disable_undo (GimpImage *gimage) { - gimage->undo_on = FALSE; - return TRUE; + return gimp_image_freeze_undo (gimage); +} + +int +gimp_image_enable_undo (GimpImage *gimage) +{ + /* Free all undo steps as they are now invalidated */ + undo_free (gimage); + + return gimp_image_thaw_undo (gimage); } int @@ -3559,7 +3572,8 @@ gimp_image_construct_composite_preview (GimpImage *gimage, * composite preview... * Indexed images are actually already converted to RGB and RGBA, * so just project them as if they were type "intensity" - * Send in all TRUE for visible since that info doesn't matter for previews + * Send in all TRUE for visible since that info doesn't matter + * for previews */ switch (drawable_type (GIMP_DRAWABLE(layer))) { diff --git a/app/core/gimpimage-projection.c b/app/core/gimpimage-projection.c index 809ed36828..8145ad39a6 100644 --- a/app/core/gimpimage-projection.c +++ b/app/core/gimpimage-projection.c @@ -3337,11 +3337,16 @@ gimp_image_filename (GimpImage *gimage) } int -gimp_image_enable_undo (GimpImage *gimage) +gimp_image_freeze_undo (GimpImage *gimage) { - /* Free all undo steps as they are now invalidated */ - undo_free (gimage); + gimage->undo_on = FALSE; + return TRUE; +} + +int +gimp_image_thaw_undo (GimpImage *gimage) +{ gimage->undo_on = TRUE; return TRUE; @@ -3350,8 +3355,16 @@ gimp_image_enable_undo (GimpImage *gimage) int gimp_image_disable_undo (GimpImage *gimage) { - gimage->undo_on = FALSE; - return TRUE; + return gimp_image_freeze_undo (gimage); +} + +int +gimp_image_enable_undo (GimpImage *gimage) +{ + /* Free all undo steps as they are now invalidated */ + undo_free (gimage); + + return gimp_image_thaw_undo (gimage); } int @@ -3559,7 +3572,8 @@ gimp_image_construct_composite_preview (GimpImage *gimage, * composite preview... * Indexed images are actually already converted to RGB and RGBA, * so just project them as if they were type "intensity" - * Send in all TRUE for visible since that info doesn't matter for previews + * Send in all TRUE for visible since that info doesn't matter + * for previews */ switch (drawable_type (GIMP_DRAWABLE(layer))) { diff --git a/app/core/gimpimage-resize.c b/app/core/gimpimage-resize.c index 809ed36828..8145ad39a6 100644 --- a/app/core/gimpimage-resize.c +++ b/app/core/gimpimage-resize.c @@ -3337,11 +3337,16 @@ gimp_image_filename (GimpImage *gimage) } int -gimp_image_enable_undo (GimpImage *gimage) +gimp_image_freeze_undo (GimpImage *gimage) { - /* Free all undo steps as they are now invalidated */ - undo_free (gimage); + gimage->undo_on = FALSE; + return TRUE; +} + +int +gimp_image_thaw_undo (GimpImage *gimage) +{ gimage->undo_on = TRUE; return TRUE; @@ -3350,8 +3355,16 @@ gimp_image_enable_undo (GimpImage *gimage) int gimp_image_disable_undo (GimpImage *gimage) { - gimage->undo_on = FALSE; - return TRUE; + return gimp_image_freeze_undo (gimage); +} + +int +gimp_image_enable_undo (GimpImage *gimage) +{ + /* Free all undo steps as they are now invalidated */ + undo_free (gimage); + + return gimp_image_thaw_undo (gimage); } int @@ -3559,7 +3572,8 @@ gimp_image_construct_composite_preview (GimpImage *gimage, * composite preview... * Indexed images are actually already converted to RGB and RGBA, * so just project them as if they were type "intensity" - * Send in all TRUE for visible since that info doesn't matter for previews + * Send in all TRUE for visible since that info doesn't matter + * for previews */ switch (drawable_type (GIMP_DRAWABLE(layer))) { diff --git a/app/core/gimpimage-scale.c b/app/core/gimpimage-scale.c index 809ed36828..8145ad39a6 100644 --- a/app/core/gimpimage-scale.c +++ b/app/core/gimpimage-scale.c @@ -3337,11 +3337,16 @@ gimp_image_filename (GimpImage *gimage) } int -gimp_image_enable_undo (GimpImage *gimage) +gimp_image_freeze_undo (GimpImage *gimage) { - /* Free all undo steps as they are now invalidated */ - undo_free (gimage); + gimage->undo_on = FALSE; + return TRUE; +} + +int +gimp_image_thaw_undo (GimpImage *gimage) +{ gimage->undo_on = TRUE; return TRUE; @@ -3350,8 +3355,16 @@ gimp_image_enable_undo (GimpImage *gimage) int gimp_image_disable_undo (GimpImage *gimage) { - gimage->undo_on = FALSE; - return TRUE; + return gimp_image_freeze_undo (gimage); +} + +int +gimp_image_enable_undo (GimpImage *gimage) +{ + /* Free all undo steps as they are now invalidated */ + undo_free (gimage); + + return gimp_image_thaw_undo (gimage); } int @@ -3559,7 +3572,8 @@ gimp_image_construct_composite_preview (GimpImage *gimage, * composite preview... * Indexed images are actually already converted to RGB and RGBA, * so just project them as if they were type "intensity" - * Send in all TRUE for visible since that info doesn't matter for previews + * Send in all TRUE for visible since that info doesn't matter + * for previews */ switch (drawable_type (GIMP_DRAWABLE(layer))) { diff --git a/app/core/gimpimage.c b/app/core/gimpimage.c index 809ed36828..8145ad39a6 100644 --- a/app/core/gimpimage.c +++ b/app/core/gimpimage.c @@ -3337,11 +3337,16 @@ gimp_image_filename (GimpImage *gimage) } int -gimp_image_enable_undo (GimpImage *gimage) +gimp_image_freeze_undo (GimpImage *gimage) { - /* Free all undo steps as they are now invalidated */ - undo_free (gimage); + gimage->undo_on = FALSE; + return TRUE; +} + +int +gimp_image_thaw_undo (GimpImage *gimage) +{ gimage->undo_on = TRUE; return TRUE; @@ -3350,8 +3355,16 @@ gimp_image_enable_undo (GimpImage *gimage) int gimp_image_disable_undo (GimpImage *gimage) { - gimage->undo_on = FALSE; - return TRUE; + return gimp_image_freeze_undo (gimage); +} + +int +gimp_image_enable_undo (GimpImage *gimage) +{ + /* Free all undo steps as they are now invalidated */ + undo_free (gimage); + + return gimp_image_thaw_undo (gimage); } int @@ -3559,7 +3572,8 @@ gimp_image_construct_composite_preview (GimpImage *gimage, * composite preview... * Indexed images are actually already converted to RGB and RGBA, * so just project them as if they were type "intensity" - * Send in all TRUE for visible since that info doesn't matter for previews + * Send in all TRUE for visible since that info doesn't matter + * for previews */ switch (drawable_type (GIMP_DRAWABLE(layer))) { diff --git a/app/core/gimpprojection-construct.c b/app/core/gimpprojection-construct.c index 809ed36828..8145ad39a6 100644 --- a/app/core/gimpprojection-construct.c +++ b/app/core/gimpprojection-construct.c @@ -3337,11 +3337,16 @@ gimp_image_filename (GimpImage *gimage) } int -gimp_image_enable_undo (GimpImage *gimage) +gimp_image_freeze_undo (GimpImage *gimage) { - /* Free all undo steps as they are now invalidated */ - undo_free (gimage); + gimage->undo_on = FALSE; + return TRUE; +} + +int +gimp_image_thaw_undo (GimpImage *gimage) +{ gimage->undo_on = TRUE; return TRUE; @@ -3350,8 +3355,16 @@ gimp_image_enable_undo (GimpImage *gimage) int gimp_image_disable_undo (GimpImage *gimage) { - gimage->undo_on = FALSE; - return TRUE; + return gimp_image_freeze_undo (gimage); +} + +int +gimp_image_enable_undo (GimpImage *gimage) +{ + /* Free all undo steps as they are now invalidated */ + undo_free (gimage); + + return gimp_image_thaw_undo (gimage); } int @@ -3559,7 +3572,8 @@ gimp_image_construct_composite_preview (GimpImage *gimage, * composite preview... * Indexed images are actually already converted to RGB and RGBA, * so just project them as if they were type "intensity" - * Send in all TRUE for visible since that info doesn't matter for previews + * Send in all TRUE for visible since that info doesn't matter + * for previews */ switch (drawable_type (GIMP_DRAWABLE(layer))) { diff --git a/app/gimage.h b/app/gimage.h index a885f6e826..3804958fd8 100644 --- a/app/gimage.h +++ b/app/gimage.h @@ -98,6 +98,8 @@ void gimage_foreach (GFunc func, gpointer user_data); #define gimage_filename gimp_image_filename #define gimage_enable_undo gimp_image_enable_undo #define gimage_disable_undo gimp_image_disable_undo +#define gimage_thaw_undo gimp_image_thaw_undo +#define gimage_freeze_undo gimp_image_freeze_undo #define gimage_dirty gimp_image_dirty #define gimage_clean gimp_image_clean #define gimage_clean_all gimp_image_clean_all diff --git a/app/gimage_cmds.c b/app/gimage_cmds.c index c013aeb5dd..56eaf5ea4f 100644 --- a/app/gimage_cmds.c +++ b/app/gimage_cmds.c @@ -63,6 +63,8 @@ static ProcRecord image_get_cmap_proc; static ProcRecord image_set_cmap_proc; static ProcRecord image_enable_undo_proc; static ProcRecord image_disable_undo_proc; +static ProcRecord image_thaw_undo_proc; +static ProcRecord image_freeze_undo_proc; static ProcRecord image_clean_all_proc; static ProcRecord image_floating_selection_proc; static ProcRecord image_floating_sel_attached_to_proc; @@ -121,6 +123,8 @@ register_gimage_procs (void) procedural_db_register (&image_set_cmap_proc); procedural_db_register (&image_enable_undo_proc); procedural_db_register (&image_disable_undo_proc); + procedural_db_register (&image_thaw_undo_proc); + procedural_db_register (&image_freeze_undo_proc); procedural_db_register (&image_clean_all_proc); procedural_db_register (&image_floating_selection_proc); procedural_db_register (&image_floating_sel_attached_to_proc); @@ -1906,6 +1910,7 @@ static ProcRecord image_set_cmap_proc = { { image_set_cmap_invoker } } }; + static Argument * image_enable_undo_invoker (Argument *args) { @@ -1962,6 +1967,64 @@ static ProcRecord image_enable_undo_proc = { { image_enable_undo_invoker } } }; + +static Argument * +image_thaw_undo_invoker (Argument *args) +{ + gboolean success = TRUE; + Argument *return_args; + GimpImage *gimage; + + gimage = pdb_id_to_image (args[0].value.pdb_int); + if (gimage == NULL) + success = FALSE; + + if (success) + success = gimage_thaw_undo (gimage); + + return_args = procedural_db_return_args (&image_thaw_undo_proc, success); + + if (success) + return_args[1].value.pdb_int = success ? TRUE : FALSE; + + return return_args; +} + +static ProcArg image_thaw_undo_inargs[] = +{ + { + PDB_IMAGE, + "image", + "The image" + } +}; + +static ProcArg image_thaw_undo_outargs[] = +{ + { + PDB_INT32, + "thawed", + "True if the image undo has been thawed" + } +}; + +static ProcRecord image_thaw_undo_proc = +{ + "gimp_image_thaw_undo", + "Thaw the image's undo stack.", + "This procedure thaws the image's undo stack, allowing subsequent operations to store their undo steps. This is generally called in conjunction with 'gimp_image_disable_freeze' to temporarily freeze an image undo stack. 'gimp_image_thaw_undo' does NOT free the undo stack as 'gimp_image_enable_undo' does, so is suited for situations where one wishes to leave the undo stack in the same state in which one found it despite non-destructively playing with the image in the meantime. An example would be in-situ plugin previews. Balancing freezes and thaws and ensuring image consistancy is the responsibility of the caller.", + "Adam D. Moss", + "Adam D. Moss", + "1999", + PDB_INTERNAL, + 1, + image_thaw_undo_inargs, + 1, + image_thaw_undo_outargs, + { { image_thaw_undo_invoker } } +}; + +/////////////// static Argument * image_disable_undo_invoker (Argument *args) { @@ -2018,6 +2081,62 @@ static ProcRecord image_disable_undo_proc = { { image_disable_undo_invoker } } }; +static Argument * +image_freeze_undo_invoker (Argument *args) +{ + gboolean success = TRUE; + Argument *return_args; + GimpImage *gimage; + + gimage = pdb_id_to_image (args[0].value.pdb_int); + if (gimage == NULL) + success = FALSE; + + if (success) + success = gimage_freeze_undo (gimage); + + return_args = procedural_db_return_args (&image_freeze_undo_proc, success); + + if (success) + return_args[1].value.pdb_int = success ? TRUE : FALSE; + + return return_args; +} + +static ProcArg image_freeze_undo_inargs[] = +{ + { + PDB_IMAGE, + "image", + "The image" + } +}; + +static ProcArg image_freeze_undo_outargs[] = +{ + { + PDB_INT32, + "frozen", + "True if the image undo has been frozen" + } +}; + +static ProcRecord image_freeze_undo_proc = +{ + "gimp_image_freeze_undo", + "Freeze the image's undo stack.", + "This procedure freezes the image's undo stack, allowing subsequent operations to ignore their undo steps. This is generally called in conjunction with 'gimp_image_thaw_undo' to temporarily disable an image undo stack. This is advantageous because saving undo steps can be time and memory intensive. 'gimp_image_{freeze,thaw}_undo' and 'gimp_image_{disable,enable}_undo' differ in that the former does not free up all undo steps when undo is thawed, so is more suited to interactive in-situ previews. It is important in this case that the image is back to the same state it was frozen in before thawing, else 'undo' behaviour is undefined.", + "Adam D. Moss", + "Adam D. Moss", + "1999", + PDB_INTERNAL, + 1, + image_freeze_undo_inargs, + 1, + image_freeze_undo_outargs, + { { image_freeze_undo_invoker } } +}; + static Argument * image_clean_all_invoker (Argument *args) { diff --git a/app/gimpimage.c b/app/gimpimage.c index 809ed36828..8145ad39a6 100644 --- a/app/gimpimage.c +++ b/app/gimpimage.c @@ -3337,11 +3337,16 @@ gimp_image_filename (GimpImage *gimage) } int -gimp_image_enable_undo (GimpImage *gimage) +gimp_image_freeze_undo (GimpImage *gimage) { - /* Free all undo steps as they are now invalidated */ - undo_free (gimage); + gimage->undo_on = FALSE; + return TRUE; +} + +int +gimp_image_thaw_undo (GimpImage *gimage) +{ gimage->undo_on = TRUE; return TRUE; @@ -3350,8 +3355,16 @@ gimp_image_enable_undo (GimpImage *gimage) int gimp_image_disable_undo (GimpImage *gimage) { - gimage->undo_on = FALSE; - return TRUE; + return gimp_image_freeze_undo (gimage); +} + +int +gimp_image_enable_undo (GimpImage *gimage) +{ + /* Free all undo steps as they are now invalidated */ + undo_free (gimage); + + return gimp_image_thaw_undo (gimage); } int @@ -3559,7 +3572,8 @@ gimp_image_construct_composite_preview (GimpImage *gimage, * composite preview... * Indexed images are actually already converted to RGB and RGBA, * so just project them as if they were type "intensity" - * Send in all TRUE for visible since that info doesn't matter for previews + * Send in all TRUE for visible since that info doesn't matter + * for previews */ switch (drawable_type (GIMP_DRAWABLE(layer))) { diff --git a/libgimp/gimp.h b/libgimp/gimp.h index 85b3761bfc..936618240d 100644 --- a/libgimp/gimp.h +++ b/libgimp/gimp.h @@ -439,6 +439,8 @@ void gimp_image_add_layer_mask (gint32 image_ID, void gimp_image_clean_all (gint32 image_ID); void gimp_image_disable_undo (gint32 image_ID); void gimp_image_enable_undo (gint32 image_ID); +void gimp_image_freeze_undo (gint32 image_ID); +void gimp_image_thaw_undo (gint32 image_ID); void gimp_undo_push_group_start (gint32 image_ID); void gimp_undo_push_group_end (gint32 image_ID); void gimp_image_clean_all (gint32 image_ID); diff --git a/libgimp/gimpimage.c b/libgimp/gimpimage.c index 3bc855151d..cabeb4e4ee 100644 --- a/libgimp/gimpimage.c +++ b/libgimp/gimpimage.c @@ -361,6 +361,34 @@ gimp_image_enable_undo (gint32 image_ID) gimp_destroy_params (return_vals, nreturn_vals); } +void +gimp_image_freeze_undo (gint32 image_ID) +{ + GParam *return_vals; + int nreturn_vals; + + return_vals = gimp_run_procedure ("gimp_image_freeze_undo", + &nreturn_vals, + PARAM_IMAGE, image_ID, + PARAM_END); + + gimp_destroy_params (return_vals, nreturn_vals); +} + +void +gimp_image_thaw_undo (gint32 image_ID) +{ + GParam *return_vals; + int nreturn_vals; + + return_vals = gimp_run_procedure ("gimp_image_thaw_undo", + &nreturn_vals, + PARAM_IMAGE, image_ID, + PARAM_END); + + gimp_destroy_params (return_vals, nreturn_vals); +} + void gimp_undo_push_group_start (gint32 image_ID) { diff --git a/libgimp/gimpimage_pdb.c b/libgimp/gimpimage_pdb.c index 3bc855151d..cabeb4e4ee 100644 --- a/libgimp/gimpimage_pdb.c +++ b/libgimp/gimpimage_pdb.c @@ -361,6 +361,34 @@ gimp_image_enable_undo (gint32 image_ID) gimp_destroy_params (return_vals, nreturn_vals); } +void +gimp_image_freeze_undo (gint32 image_ID) +{ + GParam *return_vals; + int nreturn_vals; + + return_vals = gimp_run_procedure ("gimp_image_freeze_undo", + &nreturn_vals, + PARAM_IMAGE, image_ID, + PARAM_END); + + gimp_destroy_params (return_vals, nreturn_vals); +} + +void +gimp_image_thaw_undo (gint32 image_ID) +{ + GParam *return_vals; + int nreturn_vals; + + return_vals = gimp_run_procedure ("gimp_image_thaw_undo", + &nreturn_vals, + PARAM_IMAGE, image_ID, + PARAM_END); + + gimp_destroy_params (return_vals, nreturn_vals); +} + void gimp_undo_push_group_start (gint32 image_ID) { diff --git a/plug-ins/common/jpeg.c b/plug-ins/common/jpeg.c index 98e479ff8e..b9ebd2934e 100644 --- a/plug-ins/common/jpeg.c +++ b/plug-ins/common/jpeg.c @@ -90,6 +90,19 @@ * ...and thus ends my additions to the JPEG plug-in. I hope. *sigh* :-) */ +/* + * 21-AUG-99 - Bunch O' Fixes. + * - Adam D. Moss + * + * We now correctly create an alpha-padded layer for our preview -- + * having a non-background non-alpha layer is a no-no in GIMP. + * + * I've also tweaked the GIMP undo API a little and changed the JPEG + * plugin to use gimp_image_{freeze,thaw}_undo so that it doesn't store + * up a whole load of superfluous tile data every time the preview is + * changed. + */ + #include #include #include @@ -272,11 +285,11 @@ query () { PARAM_STRING, "raw_filename", "The name of the file to save the image in" }, { PARAM_FLOAT, "quality", "Quality of saved image (0 <= quality <= 1)" }, { PARAM_FLOAT, "smoothing", "Smoothing factor for saved image (0 <= smoothing <= 1)" }, - { PARAM_INT32, "optimize", "Optimization of entropy encoding parameters" }, - { PARAM_INT32, "progressive", "Enable progressive jpeg image loading - ignored if not compiled with HAVE_PROGRESSIVE_JPEG" }, + { PARAM_INT32, "optimize", "Optimization of entropy encoding parameters (0/1)" }, + { PARAM_INT32, "progressive", "Enable progressive jpeg image loading - ignored if not compiled with HAVE_PROGRESSIVE_JPEG (0/1)" }, { PARAM_STRING, "comment", "Image comment" }, { PARAM_INT32, "subsmp", "The subsampling option number" }, - { PARAM_INT32, "baseline", "Force creation of a baseline JPEG (non-baseline JPEGs can't be read by all decoders)" }, + { PARAM_INT32, "baseline", "Force creation of a baseline JPEG (non-baseline JPEGs can't be read by all decoders) (0/1)" }, { PARAM_INT32, "restart", "Frequency of restart markers (in rows, 0 = no restart markers)" }, { PARAM_INT32, "dct", "DCT algorithm to use (speed/quality tradeoff)" } }; @@ -404,8 +417,11 @@ run (char *name, } #endif /* GIMP_HAVE_PARASITES */ - /* sg - reduce the number of undo slots used for the preview */ + /* we start an undo_group and immediately freeze undo saving + so that we can avoid sucking up tile cache with our unneeded + preview steps. */ gimp_undo_push_group_start (image_ID); + gimp_image_freeze_undo(image_ID); /* prepare for the preview */ image_ID_global = image_ID; @@ -413,6 +429,9 @@ run (char *name, /* First acquire information with a dialog */ err = save_dialog (); + + /* thaw undo saving and end the undo_group. */ + gimp_image_thaw_undo(image_ID); gimp_undo_push_group_end (image_ID); if (!err) @@ -613,6 +632,7 @@ load_image (char *filename, GRunModeType runmode, int preview) struct my_error_mgr jerr; FILE *infile; guchar *buf; + guchar *padded_buf = NULL; guchar **rowbuf; char *name; int image_type; @@ -739,22 +759,30 @@ load_image (char *filename, GRunModeType runmode, int preview) /* temporary buffer */ tile_height = gimp_tile_height (); buf = g_new (guchar, tile_height * cinfo.output_width * cinfo.output_components); + + if (preview) + padded_buf = g_new (guchar, tile_height * cinfo.output_width * + (cinfo.output_components + 1)); + rowbuf = g_new (guchar*, tile_height); for (i = 0; i < tile_height; i++) rowbuf[i] = buf + cinfo.output_width * cinfo.output_components * i; /* Create a new image of the proper size and associate the filename with it. + + Preview layers, not being on the bottom of a layer stack, MUST HAVE + AN ALPHA CHANNEL! */ switch (cinfo.output_components) { case 1: image_type = GRAY; - layer_type = GRAY_IMAGE; + layer_type = preview ? GRAYA_IMAGE : GRAY_IMAGE; break; case 3: image_type = RGB; - layer_type = RGB_IMAGE; + layer_type = preview ? RGBA_IMAGE : RGB_IMAGE; break; default: g_message (_("don't know how to load JPEGs\nwith %d color channels"), @@ -846,7 +874,37 @@ load_image (char *filename, GRunModeType runmode, int preview) gimp_pixel_rgn_set_row (&pixel_rgn, tilerow[i - start], 0, i, drawable->width); */ - gimp_pixel_rgn_set_rect (&pixel_rgn, buf, 0, start, drawable->width, scanlines); + if (preview) /* Add a dummy alpha channel -- convert buf to padded_buf */ + { + guchar *dest = padded_buf; + guchar *src = buf; + gint num = drawable->width * scanlines; + + switch (cinfo.output_components) + { + case 1: + for (i=0; iwidth, scanlines); if (runmode != RUN_NONINTERACTIVE) { @@ -869,6 +927,8 @@ load_image (char *filename, GRunModeType runmode, int preview) /* free up the temporary buffers */ g_free (rowbuf); g_free (buf); + if (preview) + g_free (padded_buf); /* After finish_decompress, we can close the input file. * Here we postpone it until after no more JPEG errors are possible, @@ -1502,6 +1562,7 @@ save_dialog () gtk_scale_set_value_pos (GTK_SCALE (restart_markers_scale), GTK_POS_TOP); gtk_scale_set_digits (GTK_SCALE (restart_markers_scale), 0); gtk_range_set_update_policy (GTK_RANGE (restart_markers_scale), GTK_UPDATE_DELAYED); + gtk_signal_connect (GTK_OBJECT (scale_data), "value_changed", (GtkSignalFunc) save_restart_update, restart); diff --git a/plug-ins/jpeg/jpeg-load.c b/plug-ins/jpeg/jpeg-load.c index 98e479ff8e..b9ebd2934e 100644 --- a/plug-ins/jpeg/jpeg-load.c +++ b/plug-ins/jpeg/jpeg-load.c @@ -90,6 +90,19 @@ * ...and thus ends my additions to the JPEG plug-in. I hope. *sigh* :-) */ +/* + * 21-AUG-99 - Bunch O' Fixes. + * - Adam D. Moss + * + * We now correctly create an alpha-padded layer for our preview -- + * having a non-background non-alpha layer is a no-no in GIMP. + * + * I've also tweaked the GIMP undo API a little and changed the JPEG + * plugin to use gimp_image_{freeze,thaw}_undo so that it doesn't store + * up a whole load of superfluous tile data every time the preview is + * changed. + */ + #include #include #include @@ -272,11 +285,11 @@ query () { PARAM_STRING, "raw_filename", "The name of the file to save the image in" }, { PARAM_FLOAT, "quality", "Quality of saved image (0 <= quality <= 1)" }, { PARAM_FLOAT, "smoothing", "Smoothing factor for saved image (0 <= smoothing <= 1)" }, - { PARAM_INT32, "optimize", "Optimization of entropy encoding parameters" }, - { PARAM_INT32, "progressive", "Enable progressive jpeg image loading - ignored if not compiled with HAVE_PROGRESSIVE_JPEG" }, + { PARAM_INT32, "optimize", "Optimization of entropy encoding parameters (0/1)" }, + { PARAM_INT32, "progressive", "Enable progressive jpeg image loading - ignored if not compiled with HAVE_PROGRESSIVE_JPEG (0/1)" }, { PARAM_STRING, "comment", "Image comment" }, { PARAM_INT32, "subsmp", "The subsampling option number" }, - { PARAM_INT32, "baseline", "Force creation of a baseline JPEG (non-baseline JPEGs can't be read by all decoders)" }, + { PARAM_INT32, "baseline", "Force creation of a baseline JPEG (non-baseline JPEGs can't be read by all decoders) (0/1)" }, { PARAM_INT32, "restart", "Frequency of restart markers (in rows, 0 = no restart markers)" }, { PARAM_INT32, "dct", "DCT algorithm to use (speed/quality tradeoff)" } }; @@ -404,8 +417,11 @@ run (char *name, } #endif /* GIMP_HAVE_PARASITES */ - /* sg - reduce the number of undo slots used for the preview */ + /* we start an undo_group and immediately freeze undo saving + so that we can avoid sucking up tile cache with our unneeded + preview steps. */ gimp_undo_push_group_start (image_ID); + gimp_image_freeze_undo(image_ID); /* prepare for the preview */ image_ID_global = image_ID; @@ -413,6 +429,9 @@ run (char *name, /* First acquire information with a dialog */ err = save_dialog (); + + /* thaw undo saving and end the undo_group. */ + gimp_image_thaw_undo(image_ID); gimp_undo_push_group_end (image_ID); if (!err) @@ -613,6 +632,7 @@ load_image (char *filename, GRunModeType runmode, int preview) struct my_error_mgr jerr; FILE *infile; guchar *buf; + guchar *padded_buf = NULL; guchar **rowbuf; char *name; int image_type; @@ -739,22 +759,30 @@ load_image (char *filename, GRunModeType runmode, int preview) /* temporary buffer */ tile_height = gimp_tile_height (); buf = g_new (guchar, tile_height * cinfo.output_width * cinfo.output_components); + + if (preview) + padded_buf = g_new (guchar, tile_height * cinfo.output_width * + (cinfo.output_components + 1)); + rowbuf = g_new (guchar*, tile_height); for (i = 0; i < tile_height; i++) rowbuf[i] = buf + cinfo.output_width * cinfo.output_components * i; /* Create a new image of the proper size and associate the filename with it. + + Preview layers, not being on the bottom of a layer stack, MUST HAVE + AN ALPHA CHANNEL! */ switch (cinfo.output_components) { case 1: image_type = GRAY; - layer_type = GRAY_IMAGE; + layer_type = preview ? GRAYA_IMAGE : GRAY_IMAGE; break; case 3: image_type = RGB; - layer_type = RGB_IMAGE; + layer_type = preview ? RGBA_IMAGE : RGB_IMAGE; break; default: g_message (_("don't know how to load JPEGs\nwith %d color channels"), @@ -846,7 +874,37 @@ load_image (char *filename, GRunModeType runmode, int preview) gimp_pixel_rgn_set_row (&pixel_rgn, tilerow[i - start], 0, i, drawable->width); */ - gimp_pixel_rgn_set_rect (&pixel_rgn, buf, 0, start, drawable->width, scanlines); + if (preview) /* Add a dummy alpha channel -- convert buf to padded_buf */ + { + guchar *dest = padded_buf; + guchar *src = buf; + gint num = drawable->width * scanlines; + + switch (cinfo.output_components) + { + case 1: + for (i=0; iwidth, scanlines); if (runmode != RUN_NONINTERACTIVE) { @@ -869,6 +927,8 @@ load_image (char *filename, GRunModeType runmode, int preview) /* free up the temporary buffers */ g_free (rowbuf); g_free (buf); + if (preview) + g_free (padded_buf); /* After finish_decompress, we can close the input file. * Here we postpone it until after no more JPEG errors are possible, @@ -1502,6 +1562,7 @@ save_dialog () gtk_scale_set_value_pos (GTK_SCALE (restart_markers_scale), GTK_POS_TOP); gtk_scale_set_digits (GTK_SCALE (restart_markers_scale), 0); gtk_range_set_update_policy (GTK_RANGE (restart_markers_scale), GTK_UPDATE_DELAYED); + gtk_signal_connect (GTK_OBJECT (scale_data), "value_changed", (GtkSignalFunc) save_restart_update, restart); diff --git a/plug-ins/jpeg/jpeg-load.h b/plug-ins/jpeg/jpeg-load.h index 98e479ff8e..b9ebd2934e 100644 --- a/plug-ins/jpeg/jpeg-load.h +++ b/plug-ins/jpeg/jpeg-load.h @@ -90,6 +90,19 @@ * ...and thus ends my additions to the JPEG plug-in. I hope. *sigh* :-) */ +/* + * 21-AUG-99 - Bunch O' Fixes. + * - Adam D. Moss + * + * We now correctly create an alpha-padded layer for our preview -- + * having a non-background non-alpha layer is a no-no in GIMP. + * + * I've also tweaked the GIMP undo API a little and changed the JPEG + * plugin to use gimp_image_{freeze,thaw}_undo so that it doesn't store + * up a whole load of superfluous tile data every time the preview is + * changed. + */ + #include #include #include @@ -272,11 +285,11 @@ query () { PARAM_STRING, "raw_filename", "The name of the file to save the image in" }, { PARAM_FLOAT, "quality", "Quality of saved image (0 <= quality <= 1)" }, { PARAM_FLOAT, "smoothing", "Smoothing factor for saved image (0 <= smoothing <= 1)" }, - { PARAM_INT32, "optimize", "Optimization of entropy encoding parameters" }, - { PARAM_INT32, "progressive", "Enable progressive jpeg image loading - ignored if not compiled with HAVE_PROGRESSIVE_JPEG" }, + { PARAM_INT32, "optimize", "Optimization of entropy encoding parameters (0/1)" }, + { PARAM_INT32, "progressive", "Enable progressive jpeg image loading - ignored if not compiled with HAVE_PROGRESSIVE_JPEG (0/1)" }, { PARAM_STRING, "comment", "Image comment" }, { PARAM_INT32, "subsmp", "The subsampling option number" }, - { PARAM_INT32, "baseline", "Force creation of a baseline JPEG (non-baseline JPEGs can't be read by all decoders)" }, + { PARAM_INT32, "baseline", "Force creation of a baseline JPEG (non-baseline JPEGs can't be read by all decoders) (0/1)" }, { PARAM_INT32, "restart", "Frequency of restart markers (in rows, 0 = no restart markers)" }, { PARAM_INT32, "dct", "DCT algorithm to use (speed/quality tradeoff)" } }; @@ -404,8 +417,11 @@ run (char *name, } #endif /* GIMP_HAVE_PARASITES */ - /* sg - reduce the number of undo slots used for the preview */ + /* we start an undo_group and immediately freeze undo saving + so that we can avoid sucking up tile cache with our unneeded + preview steps. */ gimp_undo_push_group_start (image_ID); + gimp_image_freeze_undo(image_ID); /* prepare for the preview */ image_ID_global = image_ID; @@ -413,6 +429,9 @@ run (char *name, /* First acquire information with a dialog */ err = save_dialog (); + + /* thaw undo saving and end the undo_group. */ + gimp_image_thaw_undo(image_ID); gimp_undo_push_group_end (image_ID); if (!err) @@ -613,6 +632,7 @@ load_image (char *filename, GRunModeType runmode, int preview) struct my_error_mgr jerr; FILE *infile; guchar *buf; + guchar *padded_buf = NULL; guchar **rowbuf; char *name; int image_type; @@ -739,22 +759,30 @@ load_image (char *filename, GRunModeType runmode, int preview) /* temporary buffer */ tile_height = gimp_tile_height (); buf = g_new (guchar, tile_height * cinfo.output_width * cinfo.output_components); + + if (preview) + padded_buf = g_new (guchar, tile_height * cinfo.output_width * + (cinfo.output_components + 1)); + rowbuf = g_new (guchar*, tile_height); for (i = 0; i < tile_height; i++) rowbuf[i] = buf + cinfo.output_width * cinfo.output_components * i; /* Create a new image of the proper size and associate the filename with it. + + Preview layers, not being on the bottom of a layer stack, MUST HAVE + AN ALPHA CHANNEL! */ switch (cinfo.output_components) { case 1: image_type = GRAY; - layer_type = GRAY_IMAGE; + layer_type = preview ? GRAYA_IMAGE : GRAY_IMAGE; break; case 3: image_type = RGB; - layer_type = RGB_IMAGE; + layer_type = preview ? RGBA_IMAGE : RGB_IMAGE; break; default: g_message (_("don't know how to load JPEGs\nwith %d color channels"), @@ -846,7 +874,37 @@ load_image (char *filename, GRunModeType runmode, int preview) gimp_pixel_rgn_set_row (&pixel_rgn, tilerow[i - start], 0, i, drawable->width); */ - gimp_pixel_rgn_set_rect (&pixel_rgn, buf, 0, start, drawable->width, scanlines); + if (preview) /* Add a dummy alpha channel -- convert buf to padded_buf */ + { + guchar *dest = padded_buf; + guchar *src = buf; + gint num = drawable->width * scanlines; + + switch (cinfo.output_components) + { + case 1: + for (i=0; iwidth, scanlines); if (runmode != RUN_NONINTERACTIVE) { @@ -869,6 +927,8 @@ load_image (char *filename, GRunModeType runmode, int preview) /* free up the temporary buffers */ g_free (rowbuf); g_free (buf); + if (preview) + g_free (padded_buf); /* After finish_decompress, we can close the input file. * Here we postpone it until after no more JPEG errors are possible, @@ -1502,6 +1562,7 @@ save_dialog () gtk_scale_set_value_pos (GTK_SCALE (restart_markers_scale), GTK_POS_TOP); gtk_scale_set_digits (GTK_SCALE (restart_markers_scale), 0); gtk_range_set_update_policy (GTK_RANGE (restart_markers_scale), GTK_UPDATE_DELAYED); + gtk_signal_connect (GTK_OBJECT (scale_data), "value_changed", (GtkSignalFunc) save_restart_update, restart); diff --git a/plug-ins/jpeg/jpeg-save.c b/plug-ins/jpeg/jpeg-save.c index 98e479ff8e..b9ebd2934e 100644 --- a/plug-ins/jpeg/jpeg-save.c +++ b/plug-ins/jpeg/jpeg-save.c @@ -90,6 +90,19 @@ * ...and thus ends my additions to the JPEG plug-in. I hope. *sigh* :-) */ +/* + * 21-AUG-99 - Bunch O' Fixes. + * - Adam D. Moss + * + * We now correctly create an alpha-padded layer for our preview -- + * having a non-background non-alpha layer is a no-no in GIMP. + * + * I've also tweaked the GIMP undo API a little and changed the JPEG + * plugin to use gimp_image_{freeze,thaw}_undo so that it doesn't store + * up a whole load of superfluous tile data every time the preview is + * changed. + */ + #include #include #include @@ -272,11 +285,11 @@ query () { PARAM_STRING, "raw_filename", "The name of the file to save the image in" }, { PARAM_FLOAT, "quality", "Quality of saved image (0 <= quality <= 1)" }, { PARAM_FLOAT, "smoothing", "Smoothing factor for saved image (0 <= smoothing <= 1)" }, - { PARAM_INT32, "optimize", "Optimization of entropy encoding parameters" }, - { PARAM_INT32, "progressive", "Enable progressive jpeg image loading - ignored if not compiled with HAVE_PROGRESSIVE_JPEG" }, + { PARAM_INT32, "optimize", "Optimization of entropy encoding parameters (0/1)" }, + { PARAM_INT32, "progressive", "Enable progressive jpeg image loading - ignored if not compiled with HAVE_PROGRESSIVE_JPEG (0/1)" }, { PARAM_STRING, "comment", "Image comment" }, { PARAM_INT32, "subsmp", "The subsampling option number" }, - { PARAM_INT32, "baseline", "Force creation of a baseline JPEG (non-baseline JPEGs can't be read by all decoders)" }, + { PARAM_INT32, "baseline", "Force creation of a baseline JPEG (non-baseline JPEGs can't be read by all decoders) (0/1)" }, { PARAM_INT32, "restart", "Frequency of restart markers (in rows, 0 = no restart markers)" }, { PARAM_INT32, "dct", "DCT algorithm to use (speed/quality tradeoff)" } }; @@ -404,8 +417,11 @@ run (char *name, } #endif /* GIMP_HAVE_PARASITES */ - /* sg - reduce the number of undo slots used for the preview */ + /* we start an undo_group and immediately freeze undo saving + so that we can avoid sucking up tile cache with our unneeded + preview steps. */ gimp_undo_push_group_start (image_ID); + gimp_image_freeze_undo(image_ID); /* prepare for the preview */ image_ID_global = image_ID; @@ -413,6 +429,9 @@ run (char *name, /* First acquire information with a dialog */ err = save_dialog (); + + /* thaw undo saving and end the undo_group. */ + gimp_image_thaw_undo(image_ID); gimp_undo_push_group_end (image_ID); if (!err) @@ -613,6 +632,7 @@ load_image (char *filename, GRunModeType runmode, int preview) struct my_error_mgr jerr; FILE *infile; guchar *buf; + guchar *padded_buf = NULL; guchar **rowbuf; char *name; int image_type; @@ -739,22 +759,30 @@ load_image (char *filename, GRunModeType runmode, int preview) /* temporary buffer */ tile_height = gimp_tile_height (); buf = g_new (guchar, tile_height * cinfo.output_width * cinfo.output_components); + + if (preview) + padded_buf = g_new (guchar, tile_height * cinfo.output_width * + (cinfo.output_components + 1)); + rowbuf = g_new (guchar*, tile_height); for (i = 0; i < tile_height; i++) rowbuf[i] = buf + cinfo.output_width * cinfo.output_components * i; /* Create a new image of the proper size and associate the filename with it. + + Preview layers, not being on the bottom of a layer stack, MUST HAVE + AN ALPHA CHANNEL! */ switch (cinfo.output_components) { case 1: image_type = GRAY; - layer_type = GRAY_IMAGE; + layer_type = preview ? GRAYA_IMAGE : GRAY_IMAGE; break; case 3: image_type = RGB; - layer_type = RGB_IMAGE; + layer_type = preview ? RGBA_IMAGE : RGB_IMAGE; break; default: g_message (_("don't know how to load JPEGs\nwith %d color channels"), @@ -846,7 +874,37 @@ load_image (char *filename, GRunModeType runmode, int preview) gimp_pixel_rgn_set_row (&pixel_rgn, tilerow[i - start], 0, i, drawable->width); */ - gimp_pixel_rgn_set_rect (&pixel_rgn, buf, 0, start, drawable->width, scanlines); + if (preview) /* Add a dummy alpha channel -- convert buf to padded_buf */ + { + guchar *dest = padded_buf; + guchar *src = buf; + gint num = drawable->width * scanlines; + + switch (cinfo.output_components) + { + case 1: + for (i=0; iwidth, scanlines); if (runmode != RUN_NONINTERACTIVE) { @@ -869,6 +927,8 @@ load_image (char *filename, GRunModeType runmode, int preview) /* free up the temporary buffers */ g_free (rowbuf); g_free (buf); + if (preview) + g_free (padded_buf); /* After finish_decompress, we can close the input file. * Here we postpone it until after no more JPEG errors are possible, @@ -1502,6 +1562,7 @@ save_dialog () gtk_scale_set_value_pos (GTK_SCALE (restart_markers_scale), GTK_POS_TOP); gtk_scale_set_digits (GTK_SCALE (restart_markers_scale), 0); gtk_range_set_update_policy (GTK_RANGE (restart_markers_scale), GTK_UPDATE_DELAYED); + gtk_signal_connect (GTK_OBJECT (scale_data), "value_changed", (GtkSignalFunc) save_restart_update, restart); diff --git a/plug-ins/jpeg/jpeg-save.h b/plug-ins/jpeg/jpeg-save.h index 98e479ff8e..b9ebd2934e 100644 --- a/plug-ins/jpeg/jpeg-save.h +++ b/plug-ins/jpeg/jpeg-save.h @@ -90,6 +90,19 @@ * ...and thus ends my additions to the JPEG plug-in. I hope. *sigh* :-) */ +/* + * 21-AUG-99 - Bunch O' Fixes. + * - Adam D. Moss + * + * We now correctly create an alpha-padded layer for our preview -- + * having a non-background non-alpha layer is a no-no in GIMP. + * + * I've also tweaked the GIMP undo API a little and changed the JPEG + * plugin to use gimp_image_{freeze,thaw}_undo so that it doesn't store + * up a whole load of superfluous tile data every time the preview is + * changed. + */ + #include #include #include @@ -272,11 +285,11 @@ query () { PARAM_STRING, "raw_filename", "The name of the file to save the image in" }, { PARAM_FLOAT, "quality", "Quality of saved image (0 <= quality <= 1)" }, { PARAM_FLOAT, "smoothing", "Smoothing factor for saved image (0 <= smoothing <= 1)" }, - { PARAM_INT32, "optimize", "Optimization of entropy encoding parameters" }, - { PARAM_INT32, "progressive", "Enable progressive jpeg image loading - ignored if not compiled with HAVE_PROGRESSIVE_JPEG" }, + { PARAM_INT32, "optimize", "Optimization of entropy encoding parameters (0/1)" }, + { PARAM_INT32, "progressive", "Enable progressive jpeg image loading - ignored if not compiled with HAVE_PROGRESSIVE_JPEG (0/1)" }, { PARAM_STRING, "comment", "Image comment" }, { PARAM_INT32, "subsmp", "The subsampling option number" }, - { PARAM_INT32, "baseline", "Force creation of a baseline JPEG (non-baseline JPEGs can't be read by all decoders)" }, + { PARAM_INT32, "baseline", "Force creation of a baseline JPEG (non-baseline JPEGs can't be read by all decoders) (0/1)" }, { PARAM_INT32, "restart", "Frequency of restart markers (in rows, 0 = no restart markers)" }, { PARAM_INT32, "dct", "DCT algorithm to use (speed/quality tradeoff)" } }; @@ -404,8 +417,11 @@ run (char *name, } #endif /* GIMP_HAVE_PARASITES */ - /* sg - reduce the number of undo slots used for the preview */ + /* we start an undo_group and immediately freeze undo saving + so that we can avoid sucking up tile cache with our unneeded + preview steps. */ gimp_undo_push_group_start (image_ID); + gimp_image_freeze_undo(image_ID); /* prepare for the preview */ image_ID_global = image_ID; @@ -413,6 +429,9 @@ run (char *name, /* First acquire information with a dialog */ err = save_dialog (); + + /* thaw undo saving and end the undo_group. */ + gimp_image_thaw_undo(image_ID); gimp_undo_push_group_end (image_ID); if (!err) @@ -613,6 +632,7 @@ load_image (char *filename, GRunModeType runmode, int preview) struct my_error_mgr jerr; FILE *infile; guchar *buf; + guchar *padded_buf = NULL; guchar **rowbuf; char *name; int image_type; @@ -739,22 +759,30 @@ load_image (char *filename, GRunModeType runmode, int preview) /* temporary buffer */ tile_height = gimp_tile_height (); buf = g_new (guchar, tile_height * cinfo.output_width * cinfo.output_components); + + if (preview) + padded_buf = g_new (guchar, tile_height * cinfo.output_width * + (cinfo.output_components + 1)); + rowbuf = g_new (guchar*, tile_height); for (i = 0; i < tile_height; i++) rowbuf[i] = buf + cinfo.output_width * cinfo.output_components * i; /* Create a new image of the proper size and associate the filename with it. + + Preview layers, not being on the bottom of a layer stack, MUST HAVE + AN ALPHA CHANNEL! */ switch (cinfo.output_components) { case 1: image_type = GRAY; - layer_type = GRAY_IMAGE; + layer_type = preview ? GRAYA_IMAGE : GRAY_IMAGE; break; case 3: image_type = RGB; - layer_type = RGB_IMAGE; + layer_type = preview ? RGBA_IMAGE : RGB_IMAGE; break; default: g_message (_("don't know how to load JPEGs\nwith %d color channels"), @@ -846,7 +874,37 @@ load_image (char *filename, GRunModeType runmode, int preview) gimp_pixel_rgn_set_row (&pixel_rgn, tilerow[i - start], 0, i, drawable->width); */ - gimp_pixel_rgn_set_rect (&pixel_rgn, buf, 0, start, drawable->width, scanlines); + if (preview) /* Add a dummy alpha channel -- convert buf to padded_buf */ + { + guchar *dest = padded_buf; + guchar *src = buf; + gint num = drawable->width * scanlines; + + switch (cinfo.output_components) + { + case 1: + for (i=0; iwidth, scanlines); if (runmode != RUN_NONINTERACTIVE) { @@ -869,6 +927,8 @@ load_image (char *filename, GRunModeType runmode, int preview) /* free up the temporary buffers */ g_free (rowbuf); g_free (buf); + if (preview) + g_free (padded_buf); /* After finish_decompress, we can close the input file. * Here we postpone it until after no more JPEG errors are possible, @@ -1502,6 +1562,7 @@ save_dialog () gtk_scale_set_value_pos (GTK_SCALE (restart_markers_scale), GTK_POS_TOP); gtk_scale_set_digits (GTK_SCALE (restart_markers_scale), 0); gtk_range_set_update_policy (GTK_RANGE (restart_markers_scale), GTK_UPDATE_DELAYED); + gtk_signal_connect (GTK_OBJECT (scale_data), "value_changed", (GtkSignalFunc) save_restart_update, restart); diff --git a/plug-ins/jpeg/jpeg.c b/plug-ins/jpeg/jpeg.c index 98e479ff8e..b9ebd2934e 100644 --- a/plug-ins/jpeg/jpeg.c +++ b/plug-ins/jpeg/jpeg.c @@ -90,6 +90,19 @@ * ...and thus ends my additions to the JPEG plug-in. I hope. *sigh* :-) */ +/* + * 21-AUG-99 - Bunch O' Fixes. + * - Adam D. Moss + * + * We now correctly create an alpha-padded layer for our preview -- + * having a non-background non-alpha layer is a no-no in GIMP. + * + * I've also tweaked the GIMP undo API a little and changed the JPEG + * plugin to use gimp_image_{freeze,thaw}_undo so that it doesn't store + * up a whole load of superfluous tile data every time the preview is + * changed. + */ + #include #include #include @@ -272,11 +285,11 @@ query () { PARAM_STRING, "raw_filename", "The name of the file to save the image in" }, { PARAM_FLOAT, "quality", "Quality of saved image (0 <= quality <= 1)" }, { PARAM_FLOAT, "smoothing", "Smoothing factor for saved image (0 <= smoothing <= 1)" }, - { PARAM_INT32, "optimize", "Optimization of entropy encoding parameters" }, - { PARAM_INT32, "progressive", "Enable progressive jpeg image loading - ignored if not compiled with HAVE_PROGRESSIVE_JPEG" }, + { PARAM_INT32, "optimize", "Optimization of entropy encoding parameters (0/1)" }, + { PARAM_INT32, "progressive", "Enable progressive jpeg image loading - ignored if not compiled with HAVE_PROGRESSIVE_JPEG (0/1)" }, { PARAM_STRING, "comment", "Image comment" }, { PARAM_INT32, "subsmp", "The subsampling option number" }, - { PARAM_INT32, "baseline", "Force creation of a baseline JPEG (non-baseline JPEGs can't be read by all decoders)" }, + { PARAM_INT32, "baseline", "Force creation of a baseline JPEG (non-baseline JPEGs can't be read by all decoders) (0/1)" }, { PARAM_INT32, "restart", "Frequency of restart markers (in rows, 0 = no restart markers)" }, { PARAM_INT32, "dct", "DCT algorithm to use (speed/quality tradeoff)" } }; @@ -404,8 +417,11 @@ run (char *name, } #endif /* GIMP_HAVE_PARASITES */ - /* sg - reduce the number of undo slots used for the preview */ + /* we start an undo_group and immediately freeze undo saving + so that we can avoid sucking up tile cache with our unneeded + preview steps. */ gimp_undo_push_group_start (image_ID); + gimp_image_freeze_undo(image_ID); /* prepare for the preview */ image_ID_global = image_ID; @@ -413,6 +429,9 @@ run (char *name, /* First acquire information with a dialog */ err = save_dialog (); + + /* thaw undo saving and end the undo_group. */ + gimp_image_thaw_undo(image_ID); gimp_undo_push_group_end (image_ID); if (!err) @@ -613,6 +632,7 @@ load_image (char *filename, GRunModeType runmode, int preview) struct my_error_mgr jerr; FILE *infile; guchar *buf; + guchar *padded_buf = NULL; guchar **rowbuf; char *name; int image_type; @@ -739,22 +759,30 @@ load_image (char *filename, GRunModeType runmode, int preview) /* temporary buffer */ tile_height = gimp_tile_height (); buf = g_new (guchar, tile_height * cinfo.output_width * cinfo.output_components); + + if (preview) + padded_buf = g_new (guchar, tile_height * cinfo.output_width * + (cinfo.output_components + 1)); + rowbuf = g_new (guchar*, tile_height); for (i = 0; i < tile_height; i++) rowbuf[i] = buf + cinfo.output_width * cinfo.output_components * i; /* Create a new image of the proper size and associate the filename with it. + + Preview layers, not being on the bottom of a layer stack, MUST HAVE + AN ALPHA CHANNEL! */ switch (cinfo.output_components) { case 1: image_type = GRAY; - layer_type = GRAY_IMAGE; + layer_type = preview ? GRAYA_IMAGE : GRAY_IMAGE; break; case 3: image_type = RGB; - layer_type = RGB_IMAGE; + layer_type = preview ? RGBA_IMAGE : RGB_IMAGE; break; default: g_message (_("don't know how to load JPEGs\nwith %d color channels"), @@ -846,7 +874,37 @@ load_image (char *filename, GRunModeType runmode, int preview) gimp_pixel_rgn_set_row (&pixel_rgn, tilerow[i - start], 0, i, drawable->width); */ - gimp_pixel_rgn_set_rect (&pixel_rgn, buf, 0, start, drawable->width, scanlines); + if (preview) /* Add a dummy alpha channel -- convert buf to padded_buf */ + { + guchar *dest = padded_buf; + guchar *src = buf; + gint num = drawable->width * scanlines; + + switch (cinfo.output_components) + { + case 1: + for (i=0; iwidth, scanlines); if (runmode != RUN_NONINTERACTIVE) { @@ -869,6 +927,8 @@ load_image (char *filename, GRunModeType runmode, int preview) /* free up the temporary buffers */ g_free (rowbuf); g_free (buf); + if (preview) + g_free (padded_buf); /* After finish_decompress, we can close the input file. * Here we postpone it until after no more JPEG errors are possible, @@ -1502,6 +1562,7 @@ save_dialog () gtk_scale_set_value_pos (GTK_SCALE (restart_markers_scale), GTK_POS_TOP); gtk_scale_set_digits (GTK_SCALE (restart_markers_scale), 0); gtk_range_set_update_policy (GTK_RANGE (restart_markers_scale), GTK_UPDATE_DELAYED); + gtk_signal_connect (GTK_OBJECT (scale_data), "value_changed", (GtkSignalFunc) save_restart_update, restart); diff --git a/plug-ins/jpeg/jpeg.h b/plug-ins/jpeg/jpeg.h index 98e479ff8e..b9ebd2934e 100644 --- a/plug-ins/jpeg/jpeg.h +++ b/plug-ins/jpeg/jpeg.h @@ -90,6 +90,19 @@ * ...and thus ends my additions to the JPEG plug-in. I hope. *sigh* :-) */ +/* + * 21-AUG-99 - Bunch O' Fixes. + * - Adam D. Moss + * + * We now correctly create an alpha-padded layer for our preview -- + * having a non-background non-alpha layer is a no-no in GIMP. + * + * I've also tweaked the GIMP undo API a little and changed the JPEG + * plugin to use gimp_image_{freeze,thaw}_undo so that it doesn't store + * up a whole load of superfluous tile data every time the preview is + * changed. + */ + #include #include #include @@ -272,11 +285,11 @@ query () { PARAM_STRING, "raw_filename", "The name of the file to save the image in" }, { PARAM_FLOAT, "quality", "Quality of saved image (0 <= quality <= 1)" }, { PARAM_FLOAT, "smoothing", "Smoothing factor for saved image (0 <= smoothing <= 1)" }, - { PARAM_INT32, "optimize", "Optimization of entropy encoding parameters" }, - { PARAM_INT32, "progressive", "Enable progressive jpeg image loading - ignored if not compiled with HAVE_PROGRESSIVE_JPEG" }, + { PARAM_INT32, "optimize", "Optimization of entropy encoding parameters (0/1)" }, + { PARAM_INT32, "progressive", "Enable progressive jpeg image loading - ignored if not compiled with HAVE_PROGRESSIVE_JPEG (0/1)" }, { PARAM_STRING, "comment", "Image comment" }, { PARAM_INT32, "subsmp", "The subsampling option number" }, - { PARAM_INT32, "baseline", "Force creation of a baseline JPEG (non-baseline JPEGs can't be read by all decoders)" }, + { PARAM_INT32, "baseline", "Force creation of a baseline JPEG (non-baseline JPEGs can't be read by all decoders) (0/1)" }, { PARAM_INT32, "restart", "Frequency of restart markers (in rows, 0 = no restart markers)" }, { PARAM_INT32, "dct", "DCT algorithm to use (speed/quality tradeoff)" } }; @@ -404,8 +417,11 @@ run (char *name, } #endif /* GIMP_HAVE_PARASITES */ - /* sg - reduce the number of undo slots used for the preview */ + /* we start an undo_group and immediately freeze undo saving + so that we can avoid sucking up tile cache with our unneeded + preview steps. */ gimp_undo_push_group_start (image_ID); + gimp_image_freeze_undo(image_ID); /* prepare for the preview */ image_ID_global = image_ID; @@ -413,6 +429,9 @@ run (char *name, /* First acquire information with a dialog */ err = save_dialog (); + + /* thaw undo saving and end the undo_group. */ + gimp_image_thaw_undo(image_ID); gimp_undo_push_group_end (image_ID); if (!err) @@ -613,6 +632,7 @@ load_image (char *filename, GRunModeType runmode, int preview) struct my_error_mgr jerr; FILE *infile; guchar *buf; + guchar *padded_buf = NULL; guchar **rowbuf; char *name; int image_type; @@ -739,22 +759,30 @@ load_image (char *filename, GRunModeType runmode, int preview) /* temporary buffer */ tile_height = gimp_tile_height (); buf = g_new (guchar, tile_height * cinfo.output_width * cinfo.output_components); + + if (preview) + padded_buf = g_new (guchar, tile_height * cinfo.output_width * + (cinfo.output_components + 1)); + rowbuf = g_new (guchar*, tile_height); for (i = 0; i < tile_height; i++) rowbuf[i] = buf + cinfo.output_width * cinfo.output_components * i; /* Create a new image of the proper size and associate the filename with it. + + Preview layers, not being on the bottom of a layer stack, MUST HAVE + AN ALPHA CHANNEL! */ switch (cinfo.output_components) { case 1: image_type = GRAY; - layer_type = GRAY_IMAGE; + layer_type = preview ? GRAYA_IMAGE : GRAY_IMAGE; break; case 3: image_type = RGB; - layer_type = RGB_IMAGE; + layer_type = preview ? RGBA_IMAGE : RGB_IMAGE; break; default: g_message (_("don't know how to load JPEGs\nwith %d color channels"), @@ -846,7 +874,37 @@ load_image (char *filename, GRunModeType runmode, int preview) gimp_pixel_rgn_set_row (&pixel_rgn, tilerow[i - start], 0, i, drawable->width); */ - gimp_pixel_rgn_set_rect (&pixel_rgn, buf, 0, start, drawable->width, scanlines); + if (preview) /* Add a dummy alpha channel -- convert buf to padded_buf */ + { + guchar *dest = padded_buf; + guchar *src = buf; + gint num = drawable->width * scanlines; + + switch (cinfo.output_components) + { + case 1: + for (i=0; iwidth, scanlines); if (runmode != RUN_NONINTERACTIVE) { @@ -869,6 +927,8 @@ load_image (char *filename, GRunModeType runmode, int preview) /* free up the temporary buffers */ g_free (rowbuf); g_free (buf); + if (preview) + g_free (padded_buf); /* After finish_decompress, we can close the input file. * Here we postpone it until after no more JPEG errors are possible, @@ -1502,6 +1562,7 @@ save_dialog () gtk_scale_set_value_pos (GTK_SCALE (restart_markers_scale), GTK_POS_TOP); gtk_scale_set_digits (GTK_SCALE (restart_markers_scale), 0); gtk_range_set_update_policy (GTK_RANGE (restart_markers_scale), GTK_UPDATE_DELAYED); + gtk_signal_connect (GTK_OBJECT (scale_data), "value_changed", (GtkSignalFunc) save_restart_update, restart);