mirror of https://github.com/GNOME/gimp.git
167 lines
4.0 KiB
C
167 lines
4.0 KiB
C
#include "config.h"
|
|
|
|
#include <string.h>
|
|
#ifdef HAVE_UNISTD_H
|
|
#include <unistd.h>
|
|
#endif
|
|
|
|
#ifdef __GNUC__
|
|
#warning GTK_DISABLE_DEPRECATED
|
|
#endif
|
|
#undef GTK_DISABLE_DEPRECATED
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <libgimp/gimp.h>
|
|
#include <libgimp/gimpui.h>
|
|
|
|
#include "gimpressionist.h"
|
|
#include "ppmtool.h"
|
|
|
|
#include "libgimp/stdplugins-intl.h"
|
|
|
|
|
|
static GtkWidget *preview = NULL;
|
|
|
|
|
|
static void drawalpha(ppm_t *p, ppm_t *a)
|
|
{
|
|
int x, y, g;
|
|
double v;
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
|
|
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};
|
|
|
|
void preview_free_resources (void)
|
|
{
|
|
killppm (&preview_ppm);
|
|
killppm (&alpha_ppm);
|
|
killppm (&backup_ppm);
|
|
killppm (&alpha_backup_ppm);
|
|
}
|
|
|
|
void
|
|
updatepreview (GtkWidget *wg, gpointer d)
|
|
{
|
|
gint i;
|
|
guchar buf[PREVIEWSIZE*3];
|
|
|
|
if(!infile.col && d)
|
|
grabarea();
|
|
|
|
if(!infile.col && !d) {
|
|
memset(buf, 0, sizeof(buf));
|
|
for(i = 0; i < PREVIEWSIZE; i++)
|
|
{
|
|
gtk_preview_draw_row (GTK_PREVIEW(preview), buf, 0, i, PREVIEWSIZE);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if(!backup_ppm.col)
|
|
{
|
|
copyppm(&infile, &backup_ppm);
|
|
if((backup_ppm.width != PREVIEWSIZE) || (backup_ppm.height != PREVIEWSIZE))
|
|
resize_fast(&backup_ppm, PREVIEWSIZE, PREVIEWSIZE);
|
|
if(img_has_alpha)
|
|
{
|
|
copyppm(&inalpha, &alpha_backup_ppm);
|
|
if((alpha_backup_ppm.width != PREVIEWSIZE) || (alpha_backup_ppm.height != PREVIEWSIZE))
|
|
resize_fast(&alpha_backup_ppm, PREVIEWSIZE, PREVIEWSIZE);
|
|
}
|
|
}
|
|
if(!preview_ppm.col)
|
|
{
|
|
copyppm(&backup_ppm, &preview_ppm);
|
|
if(img_has_alpha)
|
|
copyppm(&alpha_backup_ppm, &alpha_ppm);
|
|
}
|
|
if(d)
|
|
{
|
|
storevals();
|
|
|
|
if(GPOINTER_TO_INT(d) != 2)
|
|
repaint(&preview_ppm, &alpha_ppm);
|
|
}
|
|
if(img_has_alpha)
|
|
drawalpha(&preview_ppm, &alpha_ppm);
|
|
|
|
for(i = 0; i < PREVIEWSIZE; i++)
|
|
{
|
|
gtk_preview_draw_row(GTK_PREVIEW(preview),
|
|
(guchar*) &preview_ppm.col[i * PREVIEWSIZE * 3], 0, i,
|
|
PREVIEWSIZE);
|
|
}
|
|
killppm(&preview_ppm);
|
|
if(img_has_alpha)
|
|
killppm(&alpha_ppm);
|
|
}
|
|
|
|
gtk_widget_queue_draw (preview);
|
|
}
|
|
|
|
GtkWidget *
|
|
create_preview (void)
|
|
{
|
|
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);
|
|
gtk_box_pack_start(GTK_BOX (vbox), frame, FALSE, FALSE, 5);
|
|
gtk_widget_show (frame);
|
|
|
|
preview = gtk_preview_new (GTK_PREVIEW_COLOR);
|
|
gtk_preview_size (GTK_PREVIEW (preview), PREVIEWSIZE, PREVIEWSIZE);
|
|
gtk_container_add (GTK_CONTAINER (frame), preview);
|
|
gtk_widget_show (preview);
|
|
|
|
hbox = gtk_hbox_new (TRUE, 6);
|
|
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
|
|
gtk_widget_show (hbox);
|
|
|
|
previewbutton = button = gtk_button_new_with_mnemonic( _("_Update"));
|
|
g_signal_connect (button, "clicked",
|
|
G_CALLBACK (updatepreview), (gpointer) 1);
|
|
gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0);
|
|
gtk_widget_show (button);
|
|
gimp_help_set_help_data (button,
|
|
_("Refresh the Preview window"), NULL);
|
|
|
|
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,
|
|
_("Revert to the original image"), NULL);
|
|
|
|
return vbox;
|
|
}
|