2
* (c) Adam D. Moss : 1998-2000 : adam@gimp.org : adam@foxbox.org
4
* This is part of the GIMP package and is released under the GNU
9
* Version 1.06 : 2000-12-12
12
* "Out of hyding" remix. Dr Jekyll is still suspiciously
13
* absent from the fine bogey tale until Chapter Three.
16
* Sub-pixel jitter is now less severe and less coarse.
19
* Wigglyness and button-click fun.
22
* Fix for pseudocolor displays w/gdkrgb.
25
* Massive speedup if you have a very recent version of GTK 1.1.
26
* Removed possible div-by-0 errors, took the plugin out
27
* of hiding (guess we need a new easter-egg for GIMP 1.2!)
37
#include <libgimp/gimp.h>
38
#include <libgimp/gimpui.h>
40
#include "libgimp/stdplugins-intl.h"
43
/* Declare local functions. */
44
static void query (void);
45
static void run (const gchar *name,
47
const GimpParam *param,
49
GimpParam **return_vals);
51
static void do_fun (void);
53
static void window_response_callback (GtkWidget *widget,
56
static gboolean do_iteration (void);
57
static gboolean toggle_feedbacktype (GtkWidget *widget,
58
GdkEventButton *bevent);
60
static void render_frame (void);
61
static void init_preview_misc (void);
64
GimpPlugInInfo PLUG_IN_INFO =
68
query, /* query_proc */
73
static const guint width = 256;
74
static const guint height = 256;
79
#define LUTSIZEMASK ((LUTSIZE)-1)
80
static gint wigglelut[LUTSIZE];
84
static gint wiggleamp = LOWAMP;
87
/* Global widgets'n'stuff */
88
static guchar *seed_data;
89
static guchar *preview_data1;
90
static guchar *preview_data2;
92
static GtkWidget *drawing_area;
94
static gint32 image_id;
95
static GimpDrawable *drawable;
96
static GimpImageBaseType imagetype;
97
static guchar *palette;
100
static guint idle_tag;
101
static gboolean feedbacktype = FALSE;
102
static gboolean wiggly = TRUE;
103
static gboolean rgb_mode;
111
static GimpParamDef args[] =
113
{ GIMP_PDB_INT32, "run_mode", "Must be interactive (1)" },
114
{ GIMP_PDB_IMAGE, "image", "Input Image" },
115
{ GIMP_PDB_DRAWABLE, "drawable", "Input Drawable" }
118
gimp_install_procedure ("plug_in_the_old_egg",
119
"A big hello from the GIMP team!",
121
"Adam D. Moss <adam@gimp.org>",
122
"Adam D. Moss <adam@gimp.org>",
125
"RGB*, INDEXED*, GRAY*",
127
G_N_ELEMENTS (args), 0,
130
gimp_plugin_menu_register ("plug_in_the_old_egg", "<Image>/Filters/Toys");
134
run (const gchar *name,
136
const GimpParam *param,
138
GimpParam **return_vals)
140
static GimpParam values[1];
141
GimpRunMode run_mode;
142
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
147
*return_vals = values;
149
run_mode = param[0].data.d_int32;
153
if (run_mode == GIMP_RUN_NONINTERACTIVE ||
156
status = GIMP_PDB_CALLING_ERROR;
159
if (status == GIMP_PDB_SUCCESS)
161
image_id = param[1].data.d_image;
162
drawable = gimp_drawable_get (param[2].data.d_drawable);
167
status = GIMP_PDB_CALLING_ERROR;
170
values[0].type = GIMP_PDB_STATUS;
171
values[0].data.d_status = status;
183
gimp_ui_init ("gee_zoom", TRUE);
185
dlg = gimp_dialog_new (_("GEE-ZOOM"), "gee_zoom",
187
gimp_standard_help_func, "plug-in-the-old-egg",
190
button = gtk_dialog_add_button (GTK_DIALOG (dlg),
191
_("Thank you for choosing GIMP"),
194
g_signal_connect (dlg, "response",
195
G_CALLBACK (window_response_callback),
198
gimp_help_set_help_data (button,
199
_("An obsolete creation of Adam D. Moss / "
200
"adam@gimp.org / adam@foxbox.org / 1998-2000"),
203
/* The 'fun' half of the dialog */
205
frame = gtk_frame_new (NULL);
206
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
207
gtk_container_set_border_width (GTK_CONTAINER (frame), 12);
208
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox),
209
frame, FALSE, FALSE, 0);
210
gtk_widget_show (frame);
212
drawing_area = gtk_drawing_area_new ();
213
gtk_widget_set_size_request (drawing_area, width, height);
214
gtk_container_add (GTK_CONTAINER (frame), drawing_area);
215
gtk_widget_show (drawing_area);
217
gtk_widget_add_events (drawing_area,
218
GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
220
g_signal_connect (drawing_area, "button_release_event",
221
G_CALLBACK (toggle_feedbacktype),
224
gtk_widget_show (dlg);
226
idle_tag = g_idle_add_full (G_PRIORITY_LOW,
227
(GSourceFunc) do_iteration,
238
for (i=0; i<LUTSIZE; i++)
240
wigglelut[i] = RINT((double)(wiggleamp<<11))*(sin((double)(i) /
241
((double)LUTSIZEMASK /
250
imagetype = gimp_image_base_type(image_id);
252
if (imagetype == GIMP_INDEXED)
253
palette = gimp_image_get_colormap (image_id, &ncolours);
256
gimp_tile_cache_ntiles (1);
258
init_preview_misc ();
269
/* Rendering Functions */
271
/* Adam's silly algorithm. */
273
domap1 (unsigned char *src, unsigned char *dest,
274
int bx, int by, int cx, int cy)
277
signed int bycxmcybx;
283
static unsigned int grrr=0;
293
bycxmcybx = (by*cx-cy*bx);
298
/* A little sub-pixel jitter to liven things up. */
299
basesx = ((g_rand_int_range (gr, 0, 29<<19)/bycxmcybx)) +
300
((-128-((128*256)/(cx+bx)))<<11);
301
basesy = ((g_rand_int_range (gr, 0, 29<<19)/bycxmcybx)) +
302
((-128-((128*256)/(cy+by)))<<11);
304
bx2 = ((bx)<<19)/bycxmcybx;
305
cx2 = ((cx)<<19)/bycxmcybx;
306
by2 = ((by)<<19)/bycxmcybx;
307
cy2 = ((cy)<<19)/bycxmcybx;
309
for (dy=0;dy<256;dy++)
320
sx += wigglelut[(((basesy)>>11)+grrr) & LUTSIZEMASK];
321
sy += wigglelut[(((basesx)>>11)+(grrr/3)) & LUTSIZEMASK];
349
domap3(unsigned char *src, unsigned char *dest,
350
int bx, int by, int cx, int cy)
353
signed int bycxmcybx;
359
static unsigned int grrr=0;
369
bycxmcybx = (by*cx-cy*bx);
374
/* A little sub-pixel jitter to liven things up. */
375
basesx = ((g_rand_int_range (gr, 0, 29<<19)/bycxmcybx)) +
376
((-128-((128*256)/(cx+bx)))<<11);
377
basesy = ((g_rand_int_range (gr, 0, 29<<19)/bycxmcybx)) +
378
((-128-((128*256)/(cy+by)))<<11);
380
bx2 = ((bx)<<19)/bycxmcybx;
381
cx2 = ((cx)<<19)/bycxmcybx;
382
by2 = ((by)<<19)/bycxmcybx;
383
cy2 = ((cy)<<19)/bycxmcybx;
385
for (dy=0;dy<256;dy++)
396
sx += wigglelut[(((basesy)>>11)+grrr) & LUTSIZEMASK];
397
sy += wigglelut[(((basesx)>>11)+(grrr/3)) & LUTSIZEMASK];
435
static int frame = 0;
437
static gint xp=128, yp=128;
439
GdkModifierType mask;
442
if (! GTK_WIDGET_DRAWABLE (drawing_area))
445
pixels = width*height*(rgb_mode?3:1);
448
preview_data2 = preview_data1;
453
for (i=0;i<pixels;i++)
461
gdk_window_get_pointer (drawing_area->window, &rxp, &ryp, &mask);
463
if ((abs(rxp)>60)||(abs(ryp)>60))
471
domap3(preview_data2, preview_data1,
477
gdk_draw_rgb_image (drawing_area->window,
478
drawing_area->style->white_gc,
480
GDK_RGB_DITHER_NORMAL,
481
preview_data1, width * 3);
483
/* memcpy(preview_data1, seed_data, 256*256*3); */
489
for (i=0;i<pixels;i++)
492
t = preview_data1[i] + seed_data[i] - 128;
493
preview_data1[i] = /*CLAMP(t,0,255);*/
494
(t&256)? (~(t>>10)) : t; /* Quick specialized clamp */
499
gint pixwords = pixels/sizeof(gint32);
500
gint32* seedwords = (gint32*) seed_data;
501
gint32* prevwords = (gint32*) preview_data1;
503
for (i=0;i<pixwords;i++)
505
/*preview_data1[i] = (preview_data1[i]*2 +
508
/* mod'd version of the below for a 'deeper' mix */
510
((prevwords[i] >> 1) & 0x7f7f7f7f) +
511
((prevwords[i] >> 2) & 0x3f3f3f3f) +
512
((seedwords[i] >> 2) & 0x3f3f3f3f);
513
/* This is from Raph L... it should be a fast 50%/50%
514
blend, though I don't know if 50%/50% is as nice as
518
((prevwords[i] >> 1) & 0x7f7f7f7f) +
519
((seedwords[i] >> 1) & 0x7f7f7f7f) +
520
(prevwords[i] & seedwords[i] & 0x01010101); */
527
domap1(preview_data2, preview_data1,
533
gdk_draw_gray_image (drawing_area->window,
534
drawing_area->style->white_gc,
536
GDK_RGB_DITHER_NORMAL,
537
preview_data1, width);
542
for (i=0;i<pixels;i++)
545
t = preview_data1[i] + seed_data[i] - 128;
546
preview_data1[i] = /*CLAMP(t,0,255);*/
547
(t&256)? (~(t>>10)) : t; /* Quick specialized clamp */
552
gint pixwords = pixels/sizeof(gint32);
553
gint32* seedwords = (gint32*) seed_data;
554
gint32* prevwords = (gint32*) preview_data1;
556
for (i=0;i<pixwords;i++)
559
/* mod'd version of the below for a 'deeper' mix */
561
((prevwords[i] >> 1) & 0x7f7f7f7f) +
562
((prevwords[i] >> 2) & 0x3f3f3f3f) +
563
((seedwords[i] >> 2) & 0x3f3f3f3f);
564
/* This is from Raph L... it should be a fast 50%/50%
565
blend, though I don't know if 50%/50% is as nice as
569
((prevwords[i] >> 1) & 0x7f7f7f7f) +
570
((seedwords[i] >> 1) & 0x7f7f7f7f) +
571
(prevwords[i] & seedwords[i] & 0x01010101); */
581
init_preview_misc (void)
583
GimpPixelRgn pixel_rgn;
587
if ((imagetype == GIMP_RGB) || (imagetype == GIMP_INDEXED))
592
has_alpha = gimp_drawable_has_alpha(drawable->drawable_id);
594
seed_data = g_malloc(width*height*4);
595
preview_data1 = g_malloc(width*height*(rgb_mode?3:1));
596
preview_data2 = g_malloc(width*height*(rgb_mode?3:1));
598
if ((drawable->width<256) || (drawable->height<256))
602
if (i < drawable->height)
604
gimp_pixel_rgn_init (&pixel_rgn,
607
(drawable->width/2-128):0,
608
(drawable->height>256?
609
(drawable->height/2-128):0)+i,
610
MIN(256,drawable->width),
614
gimp_pixel_rgn_get_rect (&pixel_rgn,
618
drawable->width<256 ?
619
(256-drawable->width)/2 :
624
drawable->height<256 ?
625
(256-drawable->height)/2 :
630
(drawable->drawable_id)
633
(drawable->width/2-128):0,
634
(drawable->height>256?
635
(drawable->height/2-128):0)+i,
636
MIN(256,drawable->width),
643
gimp_pixel_rgn_init (&pixel_rgn,
645
drawable->width>256?(drawable->width/2-128):0,
646
drawable->height>256?(drawable->height/2-128):0,
647
MIN(256,drawable->width),
648
MIN(256,drawable->height),
651
gimp_pixel_rgn_get_rect (&pixel_rgn,
653
drawable->width>256?(drawable->width/2-128):0,
654
drawable->height>256?(drawable->height/2-128):0,
655
MIN(256,drawable->width),
656
MIN(256,drawable->height));
659
gimp_drawable_detach(drawable);
662
/* convert the image data of varying types into flat grey or rgb. */
668
for (i=width*height;i>0;i--)
670
seed_data[3*(i-1)+2] =
671
((palette[3*(seed_data[(i-1)*2])+2]*seed_data[(i-1)*2+1])/255)
672
+ ((255-seed_data[(i-1)*2+1]) * g_rand_int_range (gr, 0, 256))/255;
673
seed_data[3*(i-1)+1] =
674
((palette[3*(seed_data[(i-1)*2])+1]*seed_data[(i-1)*2+1])/255)
675
+ ((255-seed_data[(i-1)*2+1]) * g_rand_int_range (gr, 0, 256))/255;
676
seed_data[3*(i-1)+0] =
677
((palette[3*(seed_data[(i-1)*2])+0]*seed_data[(i-1)*2+1])/255)
678
+ ((255-seed_data[(i-1)*2+1]) * g_rand_int_range (gr, 0, 256))/255;
683
for (i=width*height;i>0;i--)
685
seed_data[3*(i-1)+2] = palette[3*(seed_data[i-1])+2];
686
seed_data[3*(i-1)+1] = palette[3*(seed_data[i-1])+1];
687
seed_data[3*(i-1)+0] = palette[3*(seed_data[i-1])+0];
695
for (i=0;i<width*height;i++)
698
(seed_data[i*2]*seed_data[i*2+1])/255
699
+ ((255-seed_data[i*2+1]) * g_rand_int_range (gr, 0, 256))/255;
707
for (i=0;i<width*height;i++)
710
(seed_data[i*4+2]*seed_data[i*4+3])/255
711
+ ((255-seed_data[i*4+3]) * g_rand_int_range (gr, 0, 256))/255;
713
(seed_data[i*4+1]*seed_data[i*4+3])/255
714
+ ((255-seed_data[i*4+3]) * g_rand_int_range (gr, 0, 256))/255;
716
(seed_data[i*4+0]*seed_data[i*4+3])/255
717
+ ((255-seed_data[i*4+3]) * g_rand_int_range (gr, 0, 256))/255;
744
window_response_callback (GtkWidget *widget,
748
g_source_remove (idle_tag);
751
gtk_widget_destroy (widget);
755
toggle_feedbacktype (GtkWidget *widget,
756
GdkEventButton *bevent)
758
if (bevent->state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_MOD1_MASK))
760
wiggleamp = bevent->x/5;
768
if (bevent->state & GDK_BUTTON1_MASK)
769
feedbacktype = !feedbacktype;
771
if (bevent->state & GDK_BUTTON2_MASK)
774
if (bevent->state & GDK_BUTTON3_MASK)
776
if (wiggleamp == LOWAMP)