Commit 05bd8fc9 authored by Maurits Rijk's avatar Maurits Rijk
Browse files

Fix for #105062 + minor code clean-up

parent 07df250a
2003-02-04 Maurits Rijk <lpeek.mrijk@consunet.nl>
* plug-ins/common/polar.c (dialog_update_preview): use
gimp_get_bg_guchar routine.
* libgimp/gimpmiscui.[ch]: extracted a few reusable routines from
plasma.c and put them in here.
* plug-ins/common/plasma.c: fix for #105062 plus the usual code
clean-up.
2003-02-04 Sven Neumann <sven@gimp.org>
 
* app/widgets/gimpfontselection-dialog.c: use gtk_window_present()
......
......@@ -39,8 +39,29 @@
#include "gimpintl.h"
#define PREVIEW_SIZE 128
#define PREVIEW_SIZE 128
#define PREVIEW_BPP 3
static void
gimp_fixme_preview_put_in_frame (GimpFixMePreview* preview)
{
GtkWidget *frame, *abox;
preview->frame = gtk_frame_new (_("Preview"));
gtk_widget_show (preview->frame);
abox = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
gtk_container_set_border_width (GTK_CONTAINER (abox), 4);
gtk_container_add (GTK_CONTAINER (preview->frame), abox);
gtk_widget_show (abox);
frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
gtk_container_add (GTK_CONTAINER (abox), frame);
gtk_widget_show (frame);
gtk_container_add (GTK_CONTAINER (frame), preview->widget);
}
GimpFixMePreview*
gimp_fixme_preview_new (GimpDrawable *drawable,
......@@ -49,29 +70,13 @@ gimp_fixme_preview_new (GimpDrawable *drawable,
GimpFixMePreview *preview = g_new0 (GimpFixMePreview, 1);
preview->widget = gtk_preview_new (GTK_PREVIEW_COLOR);
preview->is_gray = FALSE;
if (drawable)
gimp_fixme_preview_fill_with_thumb (preview, drawable->drawable_id);
if (has_frame)
{
GtkWidget *frame, *abox;
preview->frame = gtk_frame_new (_("Preview"));
gtk_widget_show (preview->frame);
abox = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
gtk_container_set_border_width (GTK_CONTAINER (abox), 4);
gtk_container_add (GTK_CONTAINER (preview->frame), abox);
gtk_widget_show (abox);
frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
gtk_container_add (GTK_CONTAINER (abox), frame);
gtk_widget_show (frame);
gtk_container_add (GTK_CONTAINER (frame), preview->widget);
}
gimp_fixme_preview_put_in_frame (preview);
return preview;
}
......@@ -86,6 +91,107 @@ gimp_fixme_preview_free (GimpFixMePreview *preview)
g_free (preview);
}
GimpFixMePreview*
gimp_fixme_preview_new2 (GimpImageType drawable_type, gboolean has_frame)
{
GimpFixMePreview *preview = g_new0 (GimpFixMePreview, 1);
guchar *buf = NULL;
gint y;
switch (drawable_type)
{
case GIMP_GRAY_IMAGE:
case GIMP_GRAYA_IMAGE:
preview->widget = gtk_preview_new (GTK_PREVIEW_GRAYSCALE);
buf = g_malloc0 (PREVIEW_SIZE);
preview->is_gray = TRUE;
break;
case GIMP_RGB_IMAGE:
case GIMP_RGBA_IMAGE:
preview->widget = gtk_preview_new (GTK_PREVIEW_COLOR);
buf = g_malloc0 (PREVIEW_SIZE * 3);
preview->is_gray = FALSE;
break;
default:
g_assert_not_reached ();
break;
}
gtk_preview_size (GTK_PREVIEW (preview->widget), PREVIEW_SIZE, PREVIEW_SIZE);
for (y = 0; y < PREVIEW_SIZE; y++)
gtk_preview_draw_row (GTK_PREVIEW (preview->widget), buf, 0, y,
PREVIEW_SIZE);
g_free (buf);
if (has_frame)
gimp_fixme_preview_put_in_frame (preview);
preview->buffer = GTK_PREVIEW (preview->widget)->buffer;
preview->width = GTK_PREVIEW (preview->widget)->buffer_width;
preview->height = GTK_PREVIEW (preview->widget)->buffer_height;
preview->rowstride = preview->width * ((preview->is_gray) ? 1 : 3);
return preview;
}
void
gimp_fixme_preview_put_pixel (GimpFixMePreview *preview,
gint x,
gint y,
const guchar *pixel)
{
guchar *dest;
g_assert (x >= 0 && x < PREVIEW_SIZE);
g_assert (y >= 0 && y < PREVIEW_SIZE);
dest = preview->buffer + y * preview->rowstride;
if (preview->is_gray)
{
dest += x;
dest[0] = pixel[0];
}
else
{
dest += x * 3;
dest[0] = pixel[0];
dest[1] = pixel[1];
dest[2] = pixel[2];
}
}
void
gimp_fixme_preview_get_pixel (GimpFixMePreview *preview,
gint x,
gint y,
guchar *pixel)
{
guchar *src;
g_assert (x >= 0 && x < PREVIEW_SIZE);
g_assert (y >= 0 && y < PREVIEW_SIZE);
src = preview->buffer + y * preview->rowstride;
if (preview->is_gray)
{
src += x;
pixel[0] = src[0];
}
else
{
src += x * 3;
pixel[0] = src[0];
pixel[1] = src[1];
pixel[2] = src[2];
}
}
void
gimp_fixme_preview_do_row (GimpFixMePreview *preview,
gint row,
......
......@@ -49,11 +49,12 @@ typedef struct {
gint width;
gint height;
gint rowstride;
gint bpp;
gint bpp; /* bpp of the drawable */
guchar *cmap;
gint ncolors;
gdouble scale_x;
gdouble scale_y;
gboolean is_gray;
} GimpFixMePreview;
typedef void (*GimpFixeMePreviewFunc)(guchar *src, guchar *dest,
......@@ -61,6 +62,8 @@ typedef void (*GimpFixeMePreviewFunc)(guchar *src, guchar *dest,
GimpFixMePreview *gimp_fixme_preview_new (GimpDrawable *drawable,
gboolean has_frame);
GimpFixMePreview *gimp_fixme_preview_new2 (GimpImageType drawable_type,
gboolean has_frame);
void gimp_fixme_preview_free (GimpFixMePreview *preview);
void gimp_fixme_preview_update (GimpFixMePreview *preview,
......@@ -78,6 +81,15 @@ void gimp_fixme_preview_do_row (GimpFixMePreview *preview,
gint width,
guchar *src);
void gimp_fixme_preview_put_pixel (GimpFixMePreview *preview,
gint x,
gint y,
const guchar *pixel);
void gimp_fixme_preview_get_pixel (GimpFixMePreview *preview,
gint x,
gint y,
guchar *pixel);
GList *gimp_plug_in_parse_path (gchar *path_name, const gchar *dir_name);
G_END_DECLS
......
......@@ -59,12 +59,6 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h> /* memcpy */
#ifdef __GNUC__
#warning GTK_DISABLE_DEPRECATED
#endif
#undef GTK_DISABLE_DEPRECATED
#include <gtk/gtk.h>
......@@ -79,7 +73,6 @@
#define ENTRY_WIDTH 75
#define SCALE_WIDTH 128
#define TILE_CACHE_SIZE 32
#define PREVIEW_SIZE 128
typedef struct
{
......@@ -103,7 +96,6 @@ static void run (gchar *name,
gint *nreturn_vals,
GimpParam **return_vals);
static GtkWidget *preview_widget (GimpImageType drawable_type);
static gboolean plasma_dialog (GimpDrawable *drawable,
GimpImageType drawable_type);
static void plasma_ok_callback (GtkWidget *widget,
......@@ -163,8 +155,17 @@ static PlasmaInterface pint =
FALSE /* run */
};
static guchar *work_buffer;
static GtkWidget *preview;
/*
* Some globals to save passing too many paramaters that don't change.
*/
static GimpFixMePreview *preview;
static gint ix1, iy1, ix2, iy2; /* Selected image size. */
static gint bpp, alpha;
static gboolean has_alpha;
static gdouble turbulence;
static glong max_progress, progress;
/***** Functions *****/
......@@ -298,7 +299,6 @@ plasma_dialog (GimpDrawable *drawable,
{
GtkWidget *dlg;
GtkWidget *main_vbox;
GtkWidget *abox;
GtkWidget *frame;
GtkWidget *label;
GtkWidget *table;
......@@ -329,27 +329,12 @@ plasma_dialog (GimpDrawable *drawable,
main_vbox, TRUE, TRUE, 0);
gtk_widget_show (main_vbox);
/* make a nice preview frame */
frame = gtk_frame_new (_("Preview"));
gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
abox = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
gtk_container_set_border_width (GTK_CONTAINER (abox), 4);
gtk_container_add (GTK_CONTAINER (frame), abox);
gtk_widget_show (abox);
frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
gtk_container_add (GTK_CONTAINER (abox), frame);
gtk_widget_show (frame);
preview = preview_widget (drawable_type); /* we are here */
gtk_container_add (GTK_CONTAINER (frame), preview);
preview = gimp_fixme_preview_new2 (drawable_type, TRUE);
gtk_box_pack_start (GTK_BOX (main_vbox), preview->frame, FALSE, FALSE, 0);
plasma (drawable, TRUE); /* preview image */
gtk_widget_show (preview);
gtk_widget_show (preview->widget);
/* parameter settings */
frame = gtk_frame_new (_("Parameter Settings"));
......@@ -412,21 +397,6 @@ plasma_seed_changed_callback (GimpDrawable *drawable,
plasma (drawable, TRUE);
}
#define AVE(n, v1, v2) n[0] = ((gint)v1[0] + (gint)v2[0]) / 2; \
n[1] = ((gint)v1[1] + (gint)v2[1]) / 2; \
n[2] = ((gint)v1[2] + (gint)v2[2]) / 2;
/*
* Some globals to save passing too many paramaters that don't change.
*/
static gint ix1, iy1, ix2, iy2; /* Selected image size. */
static gint bpp, alpha;
static gboolean has_alpha;
static gdouble turbulence;
static glong max_progress, progress;
/*
* The setup function.
*/
......@@ -477,18 +447,13 @@ init_plasma (GimpDrawable *drawable,
if (preview_mode)
{
ix1 = iy1 = 0;
ix2 = GTK_PREVIEW (preview)->buffer_width;
iy2 = GTK_PREVIEW (preview)->buffer_height;
ix2 = preview->width;
iy2 = preview->height;
bpp = GTK_PREVIEW (preview)->bpp;
bpp = (preview->is_gray) ? 1 : 3;
alpha = bpp;
has_alpha = FALSE;
work_buffer = g_malloc (GTK_PREVIEW (preview)->rowstride * iy2);
memcpy (work_buffer,
GTK_PREVIEW (preview)->buffer,
GTK_PREVIEW (preview)->rowstride * iy2);
pft = NULL;
}
else
......@@ -522,15 +487,11 @@ end_plasma (GimpDrawable *drawable,
gimp_drawable_flush (drawable);
gimp_drawable_merge_shadow (drawable->drawable_id, TRUE);
gimp_drawable_update (drawable->drawable_id,
ix1, iy1, (ix2 - ix1), (iy2 - iy1));
ix1, iy1, ix2 - ix1, iy2 - iy1);
}
else
{
memcpy (GTK_PREVIEW (preview)->buffer, work_buffer,
GTK_PREVIEW (preview)->rowstride * iy2);
g_free (work_buffer);
gtk_widget_queue_draw (preview);
gtk_widget_queue_draw (preview->widget);
}
g_rand_free (gr);
......@@ -548,11 +509,7 @@ get_pixel (GimpPixelFetcher *pft,
}
else
{
x = CLAMP (x, ix1, ix2 - 1);
y = CLAMP (y, iy1, iy2 - 1);
memcpy (pixel,
work_buffer + y * GTK_PREVIEW (preview)->rowstride + x * bpp,
bpp);
gimp_fixme_preview_get_pixel (preview, x, y, pixel);
}
}
......@@ -569,10 +526,19 @@ put_pixel (GimpPixelFetcher *pft,
}
else
{
x = CLAMP (x, ix1, ix2 - 1);
y = CLAMP (y, iy1, iy2 - 1);
memcpy (work_buffer + y * GTK_PREVIEW (preview)->rowstride + x * bpp,
pixel, bpp);
gimp_fixme_preview_put_pixel (preview, x, y, pixel);
}
}
static void
average_pixel (guchar *dest,
const guchar *src1,
const guchar *src2,
gint bpp)
{
for (; bpp; bpp--)
{
*dest++ = (*src1++ + *src2++) / 2;
}
}
......@@ -617,7 +583,6 @@ do_plasma (GimpPixelFetcher *pft,
{
guchar tl[4], ml[4], bl[4], mt[4], mm[4], mb[4], tr[4], mr[4], br[4];
guchar tmp[4];
gint ran;
gint xm, ym;
static gint count = 0;
......@@ -642,8 +607,8 @@ do_plasma (GimpPixelFetcher *pft,
put_pixel (pft, x2, (y1 + y2) / 2, mr);
random_rgb (gr, mt);
put_pixel (pft, (x1 + x2) / 2, y1, mt);
random_rgb (gr, ml);
put_pixel (pft, (x1 + x2) / 2, y2, ml);
random_rgb (gr, mb);
put_pixel (pft, (x1 + x2) / 2, y2, mb);
return FALSE;
}
......@@ -654,36 +619,35 @@ do_plasma (GimpPixelFetcher *pft,
*/
if (depth == 0)
{
gdouble rnd;
gint xave, yave;
gint ran;
gint xave, yave;
if (x1 == x2 && y1 == y2)
{
return FALSE;
}
get_pixel (pft, x1, y1, tl);
get_pixel (pft, x1, y2, bl);
get_pixel (pft, x2, y1, tr);
get_pixel (pft, x2, y2, br);
rnd = (256.0 / (2.0 * (gdouble)scale_depth)) * turbulence;
ran = rnd;
ran = (gint) ((256.0 / (2.0 * scale_depth)) * turbulence);
xave = (x1 + x2) / 2;
yave = (y1 + y2) / 2;
if (xave == x1 && xave == x2 && yave == y1 && yave == y2)
{
return FALSE;
}
if (xave != x1 || xave != x2)
{
/* Left. */
AVE (ml, tl, bl);
average_pixel (ml, tl, bl, bpp);
add_random (gr, ml, ran);
put_pixel (pft, x1, yave, ml);
if (x1 != x2)
{
/* Right. */
AVE (mr, tr, br);
average_pixel (mr, tr, br, bpp);
add_random (gr, mr, ran);
put_pixel (pft, x2, yave, mr);
}
......@@ -694,7 +658,7 @@ do_plasma (GimpPixelFetcher *pft,
if (x1 != xave || yave != y2)
{
/* Bottom. */
AVE (mb, bl, br);
average_pixel (mb, bl, br, bpp);
add_random (gr, mb, ran);
put_pixel (pft, xave, y2, mb);
}
......@@ -702,7 +666,7 @@ do_plasma (GimpPixelFetcher *pft,
if (y1 != y2)
{
/* Top. */
AVE (mt, tl, tr);
average_pixel (mt, tl, tr, bpp);
add_random (gr, mt, ran);
put_pixel (pft, xave, y1, mt);
}
......@@ -711,9 +675,9 @@ do_plasma (GimpPixelFetcher *pft,
if (y1 != y2 || x1 != x2)
{
/* Middle pixel. */
AVE (mm, tl, br);
AVE (tmp, bl, tr);
AVE (mm, mm, tmp);
average_pixel (mm, tl, br, bpp);
average_pixel (tmp, bl, tr, bpp);
average_pixel (mm, mm, tmp, bpp);
add_random (gr, mm, ran);
put_pixel (pft, xave, yave, mm);
......@@ -726,12 +690,7 @@ do_plasma (GimpPixelFetcher *pft,
gimp_progress_update ((gdouble) progress / (gdouble) max_progress);
}
if ((x2 - x1) < 3 && (y2 - y1) < 3)
{
return TRUE;
}
return FALSE;
return x2 - x1 < 3 && y2 - y1 < 3;
}
xm = (x1 + x2) >> 1;
......@@ -747,43 +706,3 @@ do_plasma (GimpPixelFetcher *pft,
return do_plasma (pft, xm, ym, x2, y2, depth - 1, scale_depth + 1, gr);
}
/* preview library */
static GtkWidget *
preview_widget (GimpImageType drawable_type)
{
GtkWidget *preview = NULL;
guchar *buf = NULL;
gint y;
switch (drawable_type)
{
case GIMP_GRAY_IMAGE:
case GIMP_GRAYA_IMAGE:
preview = gtk_preview_new (GTK_PREVIEW_GRAYSCALE);
buf = g_malloc0 (PREVIEW_SIZE);
break;
case GIMP_RGB_IMAGE:
case GIMP_RGBA_IMAGE:
preview = gtk_preview_new (GTK_PREVIEW_COLOR);
buf = g_malloc0 (PREVIEW_SIZE * 3);
break;
default:
g_assert_not_reached ();
break;
}
gtk_preview_size (GTK_PREVIEW (preview), PREVIEW_SIZE, PREVIEW_SIZE);
for (y = 0; y < PREVIEW_SIZE; y++)
gtk_preview_draw_row (GTK_PREVIEW (preview), buf, 0, y, PREVIEW_SIZE);
g_free (buf);
return preview;
}
......@@ -929,34 +929,8 @@ dialog_update_preview (void)
guchar *check_ul;
gint check;
guchar outside[4];
GimpRGB background;
gimp_palette_get_background (&background);
switch (img_bpp)
{
case 1:
outside[0] = outside[1] = outside [2] = gimp_rgb_intensity_uchar (&background);
outside[3] = 255;
break;
case 2:
outside[0] = outside[1] = outside [2] = gimp_rgb_intensity_uchar (&background);
outside[3] = 0;
break;
case 3:
gimp_rgb_get_uchar (&background,
&outside[0], &outside[1], &outside[2]);
outside[3] = 255;
break;
case 4:
gimp_rgb_get_uchar (&background,
&outside[0], &outside[1], &outside[2]);
outside[3] = 0;
break;
}
gimp_get_bg_guchar (drawable, TRUE, outside);
left = sel_x1;
right = sel_x2 - 1;
......
......@@ -42,10 +42,7 @@ GENCAT = @GENCAT@
GMSGFMT = @GMSGFMT@
MSGFMT = @MSGFMT@
XGETTEXT = @XGETTEXT@
INTLTOOL_UPDATE = @INTLTOOL_UPDATE@
INTLTOOL_EXTRACT = @INTLTOOL_EXTRACT@
MSGMERGE = INTLTOOL_EXTRACT=$(INTLTOOL_EXTRACT) $(INTLTOOL_UPDATE) --gettext-package $(GETTEXT_PACKAGE) --dist
GENPOT = INTLTOOL_EXTRACT=$(INTLTOOL_EXTRACT) $(INTLTOOL_UPDATE) --gettext-package $(GETTEXT_PACKAGE) --pot
MSGMERGE = msgmerge
DEFS = @DEFS@
CFLAGS = @CFLAGS@
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment