From 612705daa5651be2888fb5cc24fa4e067bed7381 Mon Sep 17 00:00:00 2001 From: Sven Neumann Date: Mon, 12 Jun 2006 17:00:02 +0000 Subject: [PATCH] plug-ins/FractalExplorer/Dialogs.c applied patch from Joao S. O. Bueno 2006-06-12 Sven Neumann * plug-ins/FractalExplorer/Dialogs.c * plug-ins/FractalExplorer/FractalExplorer.[ch]: applied patch from Joao S. O. Bueno Calligaris that makes the plug-in work on grayscale images and makes it override the alpha channel (bug #340771). --- ChangeLog | 7 +++ plug-ins/FractalExplorer/Dialogs.c | 23 ++++---- plug-ins/FractalExplorer/FractalExplorer.c | 61 +++++++++++++--------- plug-ins/FractalExplorer/FractalExplorer.h | 13 +++-- 4 files changed, 66 insertions(+), 38 deletions(-) diff --git a/ChangeLog b/ChangeLog index 29820acb21..c62add6e8b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2006-06-12 Sven Neumann + + * plug-ins/FractalExplorer/Dialogs.c + * plug-ins/FractalExplorer/FractalExplorer.[ch]: applied patch from + Joao S. O. Bueno Calligaris that makes the plug-in work on grayscale + images and makes it override the alpha channel (bug #340771). + 2006-06-12 Tor Lillqvist * app/plug-in/gimpenvirontable.c (gimp_environ_table_populate): diff --git a/plug-ins/FractalExplorer/Dialogs.c b/plug-ins/FractalExplorer/Dialogs.c index d6475dfa64..f0308c5a23 100644 --- a/plug-ins/FractalExplorer/Dialogs.c +++ b/plug-ins/FractalExplorer/Dialogs.c @@ -1414,9 +1414,9 @@ dialog_update_preview (void) } color = (int) (((zaehler - adjust) * (wvals.ncolors - 1)) / iteration); - p_ul[0] = colormap[color][0]; - p_ul[1] = colormap[color][1]; - p_ul[2] = colormap[color][2]; + p_ul[0] = colormap[color].r; + p_ul[1] = colormap[color].g; + p_ul[2] = colormap[color].b; p_ul += 3; px += 1; } /* for */ @@ -1457,8 +1457,9 @@ cmap_preview_size_allocate (GtkWidget *widget, } else { - for (j = 0; j < 3; j++) - b[(y*allocation->width + x) * 3 + j] = colormap[i][j]; + b[(y*allocation->width + x) * 3] = colormap[i].r; + b[(y*allocation->width + x) * 3 + 1] = colormap[i].g; + b[(y*allocation->width + x) * 3 + 2] = colormap[i].b; } } } @@ -1502,7 +1503,6 @@ void make_color_map (void) { gint i; - gint j; gint r; gint gr; gint bl; @@ -1534,8 +1534,9 @@ make_color_map (void) for (i = 0; i < wvals.ncolors; i++) if (wvals.colormode == 1) { - for (j = 0; j < 3; j++) - colormap[i][j] = (int) (gradient_samples[i * 4 + j] * 255.0); + colormap[i].r = (guchar)(gradient_samples[i * 4] * 255.9); + colormap[i].g = (guchar)(gradient_samples[i * 4 + 1] * 255.9); + colormap[i].b = (guchar)(gradient_samples[i * 4 + 2] * 255.9); } else { @@ -1600,9 +1601,9 @@ make_color_map (void) if (wvals.blueinvert) bl = 255 - bl; - colormap[i][0] = r; - colormap[i][1] = gr; - colormap[i][2] = bl; + colormap[i].r = r; + colormap[i].g = gr; + colormap[i].b = bl; } } diff --git a/plug-ins/FractalExplorer/FractalExplorer.c b/plug-ins/FractalExplorer/FractalExplorer.c index 6069aec92f..1dee8e429b 100644 --- a/plug-ins/FractalExplorer/FractalExplorer.c +++ b/plug-ins/FractalExplorer/FractalExplorer.c @@ -95,11 +95,12 @@ gdouble *gg; gint line_no; gchar *filename; clrmap colormap; +vlumap valuemap; gchar *fractalexplorer_path = NULL; static gfloat cx = -0.75; static gfloat cy = -0.2; -static GimpDrawable *drawable; +GimpDrawable *drawable; static GList *fractalexplorer_list = NULL; explorer_interface_t wint = @@ -247,7 +248,7 @@ query (void) "Daniel Cotting (cotting@multimania.com, www.multimania.com/cotting)", "December, 1998", N_("_Fractal Explorer..."), - "RGB*", + "RGB*, GRAY*", GIMP_PLUGIN, G_N_ELEMENTS (args), 0, args, NULL); @@ -374,8 +375,8 @@ run (const gchar *name, if (status == GIMP_PDB_SUCCESS) { - /* Make sure that the drawable is indexed or RGB color */ - if (gimp_drawable_is_rgb (drawable->drawable_id)) + /* Make sure that the drawable is not indexed */ + if (! gimp_drawable_is_indexed (drawable->drawable_id)) { gimp_progress_init (_("Rendering fractal")); @@ -413,7 +414,7 @@ explorer (GimpDrawable * drawable) GimpPixelRgn destPR; gint width; gint height; - gint bytes; + gint bpp; gint row; gint x1; gint y1; @@ -435,11 +436,11 @@ explorer (GimpDrawable * drawable) */ width = drawable->width; height = drawable->height; - bytes = drawable->bpp; + bpp = drawable->bpp; /* allocate row buffers */ - src_row = g_new (guchar, bytes * (x2 - x1)); - dest_row = g_new (guchar, bytes * (x2 - x1)); + src_row = g_new (guchar, bpp * (x2 - x1)); + dest_row = g_new (guchar, bpp * (x2 - x1)); /* initialize the pixel regions */ gimp_pixel_rgn_init (&srcPR, drawable, 0, 0, width, height, FALSE, FALSE); @@ -450,6 +451,16 @@ explorer (GimpDrawable * drawable) xdiff = (xmax - xmin) / xbild; ydiff = (ymax - ymin) / ybild; + /* for grayscale drawables */ + if (bpp < 3) + { + gint i; + for (i = 0; i < MAXNCOLORS; i++) + valuemap[i] = GIMP_RGB_LUMINANCE (colormap[i].r, + colormap[i].g, + colormap[i].b); + } + for (row = y1; row < y2; row++) { gimp_pixel_rgn_get_row (&srcPR, src_row, x1, row, (x2 - x1)); @@ -458,7 +469,7 @@ explorer (GimpDrawable * drawable) dest_row, row, (x2 - x1), - bytes); + bpp); /* store the dest */ gimp_pixel_rgn_set_row (&destPR, dest_row, x1, row, (x2 - x1)); @@ -485,10 +496,9 @@ explorer_render_row (const guchar *src_row, guchar *dest_row, gint row, gint row_width, - gint bytes) + gint bpp) { gint col; - gint bytenum; gdouble a; gdouble b; gdouble x; @@ -507,7 +517,7 @@ explorer_render_row (const guchar *src_row, gdouble adjust; gdouble cx; gdouble cy; - gint zaehler; + gint counter; gint color; gint iteration; gint useloglog; @@ -531,9 +541,9 @@ explorer_render_row (const guchar *src_row, x = 0; y = 0; } - for (zaehler = 0; - (zaehler < iteration) && ((x * x + y * y) < 4); - zaehler++) + for (counter = 0; + (counter < iteration) && ((x * x + y * y) < 4); + counter++) { oldx=x; oldy=y; @@ -656,16 +666,19 @@ explorer_render_row (const guchar *src_row, adjust = 0.0; } - color = (int) (((zaehler - adjust) * (wvals.ncolors - 1)) / iteration); - dest_row[col * bytes + 0] = colormap[color][0]; - dest_row[col * bytes + 1] = colormap[color][1]; - dest_row[col * bytes + 2] = colormap[color][2]; + color = (int) (((counter - adjust) * (wvals.ncolors - 1)) / iteration); + if (bpp >= 3) + { + dest_row[col * bpp + 0] = colormap[color].r; + dest_row[col * bpp + 1] = colormap[color].g; + dest_row[col * bpp + 2] = colormap[color].b; + } + else + dest_row[col * bpp + 0] = valuemap[color]; + + if (! ( bpp % 2)) + dest_row [col * bpp + bpp - 1] = 255; - if (bytes > 3) - for (bytenum = 3; bytenum < bytes; bytenum++) - { - dest_row[col * bytes + bytenum] = src_row[col * bytes + bytenum]; - } } } diff --git a/plug-ins/FractalExplorer/FractalExplorer.h b/plug-ins/FractalExplorer/FractalExplorer.h index b28f50cef8..ad6b9d055d 100644 --- a/plug-ins/FractalExplorer/FractalExplorer.h +++ b/plug-ins/FractalExplorer/FractalExplorer.h @@ -78,9 +78,15 @@ typedef struct gint run; } explorer_interface_t; -typedef gint colorvalue[3]; +/* typedef gint colorvalue[3]; */ +typedef struct + { + guchar r, g, b; + } gucharRGB; -typedef colorvalue clrmap[MAXNCOLORS]; +typedef gucharRGB clrmap[MAXNCOLORS]; + +typedef guchar vlumap[MAXNCOLORS]; typedef struct { @@ -189,8 +195,9 @@ extern gchar *filename; extern clrmap colormap; extern gchar *fractalexplorer_path; + extern explorer_interface_t wint; extern explorer_vals_t wvals; - +extern GimpDrawable *drawable; #endif