1999-08-27 06:29:37 +08:00
|
|
|
#include "config.h"
|
2001-12-29 21:26:29 +08:00
|
|
|
|
1999-08-27 06:29:37 +08:00
|
|
|
#include <string.h>
|
2001-12-29 21:26:29 +08:00
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2003-02-04 20:50:42 +08:00
|
|
|
#include <libgimp/gimp.h>
|
2002-11-20 04:25:57 +08:00
|
|
|
#include <libgimp/gimpui.h>
|
2002-05-25 01:19:50 +08:00
|
|
|
|
1999-08-27 06:29:37 +08:00
|
|
|
#include "gimpressionist.h"
|
|
|
|
#include "ppmtool.h"
|
2004-07-08 23:55:14 +08:00
|
|
|
#include "infile.h"
|
2006-10-31 05:36:08 +08:00
|
|
|
#include "preview.h"
|
2001-12-29 21:26:29 +08:00
|
|
|
|
|
|
|
#include "libgimp/stdplugins-intl.h"
|
|
|
|
|
1999-08-27 06:29:37 +08:00
|
|
|
|
2004-05-25 23:27:46 +08:00
|
|
|
static GtkWidget *preview = NULL;
|
2004-07-08 23:55:14 +08:00
|
|
|
static GtkWidget *previewbutton = NULL;
|
2004-05-25 23:27:46 +08:00
|
|
|
|
2005-10-06 19:10:34 +08:00
|
|
|
void
|
|
|
|
preview_set_button_label (const gchar *text)
|
2004-07-08 23:55:14 +08:00
|
|
|
{
|
2005-10-06 19:10:34 +08:00
|
|
|
g_object_set (previewbutton,
|
|
|
|
"label", text,
|
|
|
|
"use-underline", TRUE,
|
|
|
|
NULL);
|
2004-07-08 23:55:14 +08:00
|
|
|
}
|
1999-08-27 06:29:37 +08:00
|
|
|
|
2004-09-03 07:28:44 +08:00
|
|
|
static void
|
|
|
|
drawalpha (ppm_t *p, ppm_t *a)
|
1999-08-27 06:29:37 +08:00
|
|
|
{
|
2004-09-03 07:28:44 +08:00
|
|
|
int x, y, g;
|
1999-08-27 06:29:37 +08:00
|
|
|
double v;
|
2004-09-03 07:28:44 +08:00
|
|
|
int gridsize = 16;
|
|
|
|
int rowstride = p->width * 3;
|
|
|
|
|
|
|
|
for (y = 0; y < p->height; y++)
|
|
|
|
{
|
|
|
|
for (x = 0; x < p->width; x++)
|
|
|
|
{
|
|
|
|
int k = y * rowstride + x * 3;
|
|
|
|
|
|
|
|
if (!a->col[k])
|
|
|
|
continue;
|
|
|
|
|
|
|
|
v = 1.0 - a->col[k] / 255.0;
|
|
|
|
g = ((x / gridsize + y / gridsize) % 2) * 60 + 100;
|
|
|
|
p->col[k+0] *= v;
|
|
|
|
p->col[k+1] *= v;
|
|
|
|
p->col[k+2] *= v;
|
|
|
|
v = 1.0 - v;
|
|
|
|
p->col[k+0] += g*v;
|
|
|
|
p->col[k+1] += g*v;
|
|
|
|
p->col[k+2] += g*v;
|
|
|
|
}
|
1999-08-27 06:29:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-03 07:28:44 +08:00
|
|
|
static ppm_t preview_ppm = {0, 0, NULL};
|
|
|
|
static ppm_t alpha_ppm = {0, 0, NULL};
|
|
|
|
static ppm_t backup_ppm = {0, 0, NULL};
|
|
|
|
static ppm_t alpha_backup_ppm = {0, 0, NULL};
|
2004-07-02 21:31:25 +08:00
|
|
|
|
2004-09-03 07:28:44 +08:00
|
|
|
void
|
|
|
|
preview_free_resources (void)
|
2004-07-02 21:31:25 +08:00
|
|
|
{
|
2004-07-15 19:58:47 +08:00
|
|
|
ppm_kill (&preview_ppm);
|
|
|
|
ppm_kill (&alpha_ppm);
|
|
|
|
ppm_kill (&backup_ppm);
|
|
|
|
ppm_kill (&alpha_backup_ppm);
|
2004-07-02 21:31:25 +08:00
|
|
|
}
|
|
|
|
|
2004-05-25 23:27:46 +08:00
|
|
|
void
|
|
|
|
updatepreview (GtkWidget *wg, gpointer d)
|
1999-08-27 06:29:37 +08:00
|
|
|
{
|
2008-01-27 21:08:08 +08:00
|
|
|
if (!PPM_IS_INITED (&backup_ppm))
|
|
|
|
{
|
|
|
|
infile_copy_to_ppm (&backup_ppm);
|
|
|
|
if ((backup_ppm.width != PREVIEWSIZE) ||
|
|
|
|
(backup_ppm.height != PREVIEWSIZE))
|
|
|
|
resize_fast (&backup_ppm, PREVIEWSIZE, PREVIEWSIZE);
|
2004-09-03 07:28:44 +08:00
|
|
|
if (img_has_alpha)
|
2008-01-27 21:08:08 +08:00
|
|
|
{
|
|
|
|
infile_copy_alpha_to_ppm (&alpha_backup_ppm);
|
|
|
|
if ((alpha_backup_ppm.width != PREVIEWSIZE) ||
|
|
|
|
(alpha_backup_ppm.height != PREVIEWSIZE))
|
|
|
|
resize_fast (&alpha_backup_ppm, PREVIEWSIZE, PREVIEWSIZE);
|
|
|
|
}
|
|
|
|
}
|
1999-08-27 06:29:37 +08:00
|
|
|
|
2008-01-27 21:08:08 +08:00
|
|
|
if (!PPM_IS_INITED (&preview_ppm))
|
|
|
|
{
|
|
|
|
ppm_copy (&backup_ppm, &preview_ppm);
|
2004-07-31 16:42:44 +08:00
|
|
|
|
2004-09-03 07:28:44 +08:00
|
|
|
if (img_has_alpha)
|
2008-01-27 21:08:08 +08:00
|
|
|
ppm_copy (&alpha_backup_ppm, &alpha_ppm);
|
2004-09-03 07:28:44 +08:00
|
|
|
}
|
2008-01-27 21:08:08 +08:00
|
|
|
|
|
|
|
if (d)
|
|
|
|
{
|
|
|
|
store_values ();
|
|
|
|
|
|
|
|
if (GPOINTER_TO_INT (d) != 2)
|
|
|
|
repaint (&preview_ppm, &alpha_ppm);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (img_has_alpha)
|
|
|
|
drawalpha (&preview_ppm, &alpha_ppm);
|
|
|
|
|
|
|
|
gimp_preview_area_draw (GIMP_PREVIEW_AREA (preview),
|
|
|
|
0, 0, PREVIEWSIZE, PREVIEWSIZE,
|
|
|
|
GIMP_RGB_IMAGE,
|
|
|
|
preview_ppm.col,
|
|
|
|
PREVIEWSIZE * 3);
|
|
|
|
|
|
|
|
ppm_kill (&preview_ppm);
|
|
|
|
if (img_has_alpha)
|
|
|
|
ppm_kill (&alpha_ppm);
|
2004-07-31 16:42:44 +08:00
|
|
|
}
|
2004-05-25 23:27:46 +08:00
|
|
|
|
2004-07-31 16:42:44 +08:00
|
|
|
static void
|
|
|
|
preview_size_allocate (GtkWidget *preview)
|
|
|
|
{
|
|
|
|
updatepreview (preview, GINT_TO_POINTER (0));
|
1999-08-27 06:29:37 +08:00
|
|
|
}
|
|
|
|
|
2004-05-25 23:27:46 +08:00
|
|
|
GtkWidget *
|
|
|
|
create_preview (void)
|
1999-08-27 06:29:37 +08:00
|
|
|
{
|
2004-05-25 23:27:46 +08:00
|
|
|
GtkWidget *hbox;
|
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *frame;
|
|
|
|
GtkWidget *button;
|
|
|
|
|
|
|
|
vbox = gtk_vbox_new (FALSE, 6);
|
|
|
|
|
|
|
|
frame = gtk_frame_new (NULL);
|
|
|
|
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
|
2004-09-03 07:28:44 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 5);
|
2004-05-25 23:27:46 +08:00
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
2004-07-31 16:42:44 +08:00
|
|
|
preview = gimp_preview_area_new ();
|
|
|
|
gtk_widget_set_size_request (preview, PREVIEWSIZE, PREVIEWSIZE);
|
|
|
|
|
2004-05-25 23:27:46 +08:00
|
|
|
gtk_container_add (GTK_CONTAINER (frame), preview);
|
|
|
|
gtk_widget_show (preview);
|
2004-07-31 16:42:44 +08:00
|
|
|
/* This is so the preview will be displayed when the dialog is invoked. */
|
|
|
|
g_signal_connect (preview, "size-allocate",
|
|
|
|
G_CALLBACK (preview_size_allocate), NULL);
|
2004-05-25 23:27:46 +08:00
|
|
|
|
|
|
|
hbox = gtk_hbox_new (TRUE, 6);
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (hbox);
|
|
|
|
|
2004-09-03 07:28:44 +08:00
|
|
|
previewbutton = button = gtk_button_new_with_mnemonic (_("_Update"));
|
2004-05-25 23:27:46 +08:00
|
|
|
g_signal_connect (button, "clicked",
|
2004-07-02 21:31:25 +08:00
|
|
|
G_CALLBACK (updatepreview), (gpointer) 1);
|
2004-05-25 23:27:46 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (button);
|
|
|
|
gimp_help_set_help_data (button,
|
2004-07-02 21:31:25 +08:00
|
|
|
_("Refresh the Preview window"), NULL);
|
1999-08-27 06:29:37 +08:00
|
|
|
|
2004-05-25 23:27:46 +08:00
|
|
|
button = gtk_button_new_from_stock (GIMP_STOCK_RESET);
|
|
|
|
g_signal_connect (button, "clicked",
|
|
|
|
G_CALLBACK (updatepreview), (gpointer) 2);
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (button);
|
|
|
|
gimp_help_set_help_data (button,
|
2004-07-02 21:31:25 +08:00
|
|
|
_("Revert to the original image"), NULL);
|
1999-08-27 06:29:37 +08:00
|
|
|
|
2004-05-25 23:27:46 +08:00
|
|
|
return vbox;
|
1999-08-27 06:29:37 +08:00
|
|
|
}
|