Commit 692887db authored by Sven Neumann's avatar Sven Neumann
Browse files

more export fiddling and a small change to the undo_history


--Sven
parent dea7f1ce
Sat Oct 9 02:04:49 MEST 1999 Sven Neumann <sven@gimp.org>
* app/undo_history.c: catch another case where a new preview should
be drawn
* libgimp/gimpexport.[ch]: add NEED_ALPHA since gpb and gih need it
* plug-ins/common/aa.c: fixed my last change
* plug-ins/common/gpb.c: use the new NEED_ALPHA so gimp_export_image
prepares the images correctly
Fri Oct 8 15:04:45 PDT 1999 Manish Singh <yosh@gimp.org>
 
* libgimp/gimpintl.h
......@@ -18,7 +30,7 @@ Fri Oct 8 22:00:00 MEST 1999 Sven Neumann <sven@gimp.org>
* plug-ins/common/aa.c
* plug-ins/common/csource.c
* plug-ins/common/gbr.c
* plug-ins/common/gpb.c: more file plug-ins that make use the export
* plug-ins/common/gpb.c: more file plug-ins that make use of the export
functionality
 
* plug-ins/common/jpeg.c: set the filename of the export preview so
......
......@@ -43,6 +43,7 @@
*/
#include <gtk/gtk.h>
#include "gimprc.h"
#include "gimpui.h"
#include "temp_buf.h"
#include "undo.h"
......@@ -57,7 +58,7 @@
#define GRAD_CHECK_DARK (1.0 / 3.0)
#define GRAD_CHECK_LIGHT (2.0 / 3.0)
#define UNDO_THUMBNAIL_SIZE 24
#define UNDO_HISTORY_PREVIEW_SIZE 24
typedef struct
{
......@@ -165,13 +166,13 @@ undo_history_set_pixmap_idle (gpointer data)
/* Get right aspect ratio */
if (width > height)
{
height = (UNDO_THUMBNAIL_SIZE * height) / width;
width = UNDO_THUMBNAIL_SIZE;
height = (UNDO_HISTORY_PREVIEW_SIZE * height) / width;
width = UNDO_HISTORY_PREVIEW_SIZE;
}
else
{
width = (UNDO_THUMBNAIL_SIZE * width) / height;
height = UNDO_THUMBNAIL_SIZE;
width = (UNDO_HISTORY_PREVIEW_SIZE * width) / height;
height = UNDO_HISTORY_PREVIEW_SIZE;
}
buf = gimp_image_construct_composite_preview (idle->gimage, width, height);
......@@ -267,23 +268,31 @@ undo_history_set_pixmap_idle (gpointer data)
gtk_clist_set_pixmap (idle->clist, idle->row, 0, pixmap, NULL);
gdk_pixmap_unref (pixmap);
return (FALSE);
}
/* check if a preview is already made, otherwise gtk_idle_add the pixmap func */
static void
undo_history_set_pixmap (GtkCList *clist,
gint row,
GImage *gimage)
{
static idle_preview_args idle;
GdkPixmap *pixmap;
GdkPixmap *mask;
if (gtk_clist_get_pixmap (clist, row, 0, &pixmap, &mask))
return;
idle.clist = clist;
idle.row = row;
idle.gimage = gimage;
gtk_idle_add ((GtkFunction)undo_history_set_pixmap_idle, &idle);
}
/* close button clicked */
static void
undo_history_close_callback (GtkWidget *widget,
......@@ -436,8 +445,7 @@ undo_history_undo_event (GtkWidget *widget,
g_return_if_fail (cur_selection >= 1);
gtk_clist_select_row (clist, cur_selection - 1, -1);
cur_selection--;
if (!gtk_clist_get_pixmap (clist, cur_selection, 0, &pixmap, &mask))
undo_history_set_pixmap (clist, cur_selection, st->gimage);
undo_history_set_pixmap (clist, cur_selection, st->gimage);
if ( !(gtk_clist_row_is_visible (clist, cur_selection) & GTK_VISIBILITY_FULL))
gtk_clist_moveto (clist, cur_selection, 0, 0.0, 0.0);
break;
......@@ -447,8 +455,7 @@ undo_history_undo_event (GtkWidget *widget,
g_return_if_fail (cur_selection+1 < clist->rows);
gtk_clist_select_row (clist, cur_selection+1, -1);
cur_selection++;
if (!gtk_clist_get_pixmap (clist, cur_selection, 0, &pixmap, &mask))
undo_history_set_pixmap (clist, cur_selection, st->gimage);
undo_history_set_pixmap (clist, cur_selection, st->gimage);
if ( !(gtk_clist_row_is_visible (clist, cur_selection) & GTK_VISIBILITY_FULL))
gtk_clist_moveto (clist, cur_selection, 0, 1.0, 0.0);
break;
......@@ -501,6 +508,8 @@ undo_history_select_row_callback (GtkWidget *widget,
st->old_selection++;
}
undo_history_set_pixmap (GTK_CLIST (widget), cur_selection, st->gimage);
gtk_signal_handler_unblock_by_func (GTK_OBJECT (st->gimage),
undo_history_undo_event, st);
......@@ -634,8 +643,8 @@ undo_history_new (GImage *gimage)
st->clist = gtk_clist_new (3);
gtk_clist_set_selection_mode (GTK_CLIST (st->clist), GTK_SELECTION_BROWSE);
gtk_clist_set_reorderable (GTK_CLIST (st->clist), FALSE);
gtk_clist_set_row_height (GTK_CLIST (st->clist), UNDO_THUMBNAIL_SIZE + 2);
gtk_clist_set_column_width (GTK_CLIST (st->clist), 0, UNDO_THUMBNAIL_SIZE + 2);
gtk_clist_set_row_height (GTK_CLIST (st->clist), UNDO_HISTORY_PREVIEW_SIZE + 2);
gtk_clist_set_column_width (GTK_CLIST (st->clist), 0, UNDO_HISTORY_PREVIEW_SIZE + 2);
gtk_clist_set_column_width (GTK_CLIST (st->clist), 1, 18);
gtk_clist_set_column_min_width (GTK_CLIST (st->clist), 2, 64);
......
......@@ -80,6 +80,23 @@ export_convert_indexed (gint32 image_ID,
gimp_image_convert_indexed (image_ID, GIMP_FS_DITHER, GIMP_MAKE_PALETTE, 256, FALSE, FALSE, "");
}
static void
export_add_alpha (gint32 image_ID,
gint32 *drawable_ID)
{
gint nlayers;
gint i;
gint32 *layers;
layers = gimp_image_get_layers (image_ID, &nlayers);
for (i = 0; i < nlayers; i++)
{
if (!gimp_drawable_has_alpha (layers[i]))
gimp_layer_add_alpha (layers[i]);
}
g_free (layers);
}
/* a set of predefined actions */
static ExportAction export_action_merge =
......@@ -164,6 +181,14 @@ static ExportAction export_action_convert_indexed_or_grayscale =
0
};
static ExportAction export_action_add_alpha =
{
&export_add_alpha,
NULL,
N_("needs an alpha channel"),
{ N_("Add alpha channel"), NULL},
0
};
/* dialog functions */
......@@ -349,23 +374,44 @@ gimp_export_image (gint32 *image_ID_ptr,
GList *actions = NULL;
GList *list;
GimpImageBaseType type;
gint i;
gint nlayers;
gint32* layers;
gboolean added_flatten = FALSE;
ExportAction *action;
g_return_val_if_fail (*image_ID_ptr > -1 && *drawable_ID_ptr > -1, FALSE);
/* do some sanity checks */
if (cap & NEEDS_ALPHA)
cap |= CAN_HANDLE_ALPHA;
if (cap & CAN_HANDLE_LAYERS_AS_ANIMATION)
cap |= CAN_HANDLE_LAYERS;
/* check alpha */
g_free (gimp_image_get_layers (*image_ID_ptr, &nlayers));
if (nlayers > 1 || gimp_drawable_has_alpha (*drawable_ID_ptr))
layers = gimp_image_get_layers (*image_ID_ptr, &nlayers);
for (i = 0; i < nlayers; i++)
{
if ( !(cap & CAN_HANDLE_ALPHA ) )
if (gimp_drawable_has_alpha (layers[i]))
{
actions = g_list_append (actions, &export_action_flatten);
added_flatten = TRUE;
}
if ( !(cap & CAN_HANDLE_ALPHA) )
{
actions = g_list_append (actions, &export_action_flatten);
added_flatten = TRUE;
break;
}
}
else
{
if (cap & NEEDS_ALPHA)
{
actions = g_list_append (actions, &export_action_add_alpha);
break;
}
}
}
g_free (layers);
/* check multiple layers */
if (!added_flatten && nlayers > 1)
......
......@@ -28,6 +28,7 @@
#define CAN_HANDLE_ALPHA 1 << 3
#define CAN_HANDLE_LAYERS 1 << 4
#define CAN_HANDLE_LAYERS_AS_ANIMATION 1 << 5
#define NEEDS_ALPHA 1 << 6
typedef enum
{
......
......@@ -144,39 +144,38 @@ run (char *name,
values[0].type = PARAM_STATUS;
values[0].data.d_status = STATUS_CALLING_ERROR;
if (!aa_savable(param[2].data.d_int32))
run_mode = param[0].data.d_int32;
image_ID = param[1].data.d_int32;
drawable_ID = param[2].data.d_int32;
/* eventually export the image */
switch (run_mode)
{
case RUN_INTERACTIVE:
case RUN_WITH_LAST_VALS:
init_gtk ();
export = gimp_export_image (&image_ID, &drawable_ID, "AA",
(CAN_HANDLE_GRAY | CAN_HANDLE_ALPHA));
if (export == EXPORT_CANCEL)
{
values[0].data.d_status = STATUS_EXECUTION_ERROR;
return;
}
break;
default:
break;
}
if (!aa_savable (drawable_ID))
{
values[0].data.d_status = STATUS_CALLING_ERROR;
return;
}
run_mode = param[0].data.d_int32;
image_ID = param[1].data.d_int32;
drawable_ID = param[2].data.d_int32;
/* eventually export the image */
switch (run_mode)
{
case RUN_INTERACTIVE:
case RUN_WITH_LAST_VALS:
init_gtk ();
export = gimp_export_image (&image_ID, &drawable_ID, "AA",
(CAN_HANDLE_GRAY | CAN_HANDLE_ALPHA));
if (export == EXPORT_CANCEL)
{
*nreturn_vals = 1;
values[0].data.d_status = STATUS_EXECUTION_ERROR;
return;
}
break;
default:
break;
}
switch (run_mode)
{
case RUN_INTERACTIVE:
gimp_get_data("file_aa_save", &last_type);
gimp_get_data ("file_aa_save", &last_type);
output_type = type_dialog (last_type);
break;
......@@ -203,7 +202,7 @@ run (char *name,
return;
}
if (save_aa(output_type, param[3].data.d_string, image_ID, drawable_ID))
if (save_aa (output_type, param[3].data.d_string, image_ID, drawable_ID))
{
values[0].data.d_status = STATUS_EXECUTION_ERROR;
last_type = output_type;
......@@ -223,7 +222,7 @@ run (char *name,
static gint
save_aa (int output_type,
char *filename,
gint32 image,
gint32 image_ID,
gint32 drawable_ID)
{
aa_savedata savedata = {NULL, NULL};
......@@ -248,7 +247,7 @@ save_aa (int output_type,
if (context == NULL)
return 1;
gimp2aa (image, drawable_ID, context);
gimp2aa (image_ID, drawable_ID, context);
aa_flush (context);
aa_close (context);
......@@ -269,8 +268,8 @@ gimp2aa (gint32 image,
aa_renderparams *renderparams = NULL;
int bpp;
width = aa_imgwidth(context);
height = aa_imgheight(context);
width = aa_imgwidth (context);
height = aa_imgheight (context);
/*fprintf(stderr, "gimp2aa %i x %i\n", width, height); */
drawable = gimp_drawable_get(drawable_ID);
......
......@@ -1064,7 +1064,8 @@ run (char *name,
case RUN_WITH_LAST_VALS:
init_gtk ();
export = gimp_export_image (&image_ID, &drawable_ID, "GPB",
(CAN_HANDLE_RGB | CAN_HANDLE_ALPHA));
(CAN_HANDLE_RGB | CAN_HANDLE_ALPHA |
NEEDS_ALPHA ));
if (export == EXPORT_CANCEL)
{
*nreturn_vals = 1;
......@@ -1124,7 +1125,8 @@ run (char *name,
case RUN_WITH_LAST_VALS:
init_gtk ();
export = gimp_export_image (&image_ID, &drawable_ID, "GIH",
(CAN_HANDLE_RGB | CAN_HANDLE_ALPHA | CAN_HANDLE_LAYERS));
(CAN_HANDLE_RGB | CAN_HANDLE_ALPHA |
CAN_HANDLE_LAYERS | NEEDS_ALPHA));
if (export == EXPORT_CANCEL)
{
*nreturn_vals = 1;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment