1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
|
#include "config.h"
#include <string.h>
#include <gtk/gtk.h>
#include <libgimp/gimp.h>
#include <libgimp/gimpui.h>
#include "gimpressionist.h"
#include "ppmtool.h"
#include "infile.h"
#include "libgimp/stdplugins-intl.h"
static GtkWidget *preview = NULL;
static GtkWidget *previewbutton = NULL;
void preview_set_button_label (gchar * text)
{
gtk_label_set_text (GTK_LABEL (GTK_BIN (previewbutton)->child), text);
}
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)
{
ppm_kill (&preview_ppm);
ppm_kill (&alpha_ppm);
ppm_kill (&backup_ppm);
ppm_kill (&alpha_backup_ppm);
}
void
updatepreview (GtkWidget *wg, gpointer d)
{
/* This portion is remmed out because of the remming out of the
* code below.
* -- Shlomi Fish
* */
#if 0
guchar buf[PREVIEWSIZE*3];
if (!PPM_IS_INITED (&infile) && d)
grabarea();
#endif
/* It seems that infile.col must be true here. (after grabarea() that is.)
* Thus, I'm removing this entire portion of the code in hope that
* it works OK afterwards.
* -- Shlomi Fish
* */
#if 0
if (!PPM_IS_INITED (&infile) && !d) {
guchar *buffer;
buffer = g_new0 (guchar, 3*PREVIEWSIZE*PREVIEWSIZE);
gimp_preview_area_draw (GIMP_PREVIEW_AREA (preview),
0, 0, PREVIEWSIZE, PREVIEWSIZE,
GIMP_RGB_IMAGE,
buffer,
PREVIEWSIZE * 3);
g_free (buffer);
}
else
#endif
{
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);
if (img_has_alpha)
{
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);
}
}
if (!PPM_IS_INITED (&preview_ppm))
{
ppm_copy (&backup_ppm, &preview_ppm);
if (img_has_alpha)
ppm_copy (&alpha_backup_ppm, &alpha_ppm);
}
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);
}
}
static void
preview_size_allocate (GtkWidget *preview)
{
updatepreview (preview, GINT_TO_POINTER (0));
}
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 = gimp_preview_area_new ();
gtk_widget_set_size_request (preview, PREVIEWSIZE, PREVIEWSIZE);
gtk_container_add (GTK_CONTAINER (frame), preview);
gtk_widget_show (preview);
/* 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);
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;
}
|