Commit c7372619 authored by Maurits Rijk's avatar Maurits Rijk

Minor code clean-up. Started implementation of #92635 and #91396.

parent 3a2d973f
2003-03-18 Maurits Rijk <lpeek.mrijk@consunet.nl>
* plug-ins/imagemap/java.xpm
* plug-ins/imagemap/link.xpm
* plug-ins/imagemap/Makefile
* plug-ins/imagemap/imap_stock.[ch]: added 2 new icons.
* plug-ins/imagemap/imap_edit_area_info.c: start at implementing
enhancement #91396 and #92635.
2003-03-18 Michael Natterer <mitch@gimp.org>
* app/core/gimpimage-mask.[ch] (gimp_image_mask_translate)
......@@ -3213,6 +3223,11 @@
* app/text/gimptextlayer.c: changed accordingly.
2003-02-04 Maurits Rijk <lpeek.mrijk@consunet.nl>
* plug-ins/common/max_rgb.c: fixed bug with previewing images
with alpha channel.
2003-02-04 Sven Neumann <sven@gimp.org>
* app/widgets/gimpitemfactory.c (gimp_item_factory_item_key_press):
/* max_rgb.c -- This is a plug-in for the GIMP (1.0's API)
/* max_rgb.c -- This is a plug-in for the GIMP
* Author: Shuji Narazaki <narazaki@InetQ.or.jp>
* Time-stamp: <2000-02-08 16:26:24 yasuhiro>
* Version: 0.35
......@@ -41,7 +41,6 @@
/* Replace them with the right ones */
#define PLUG_IN_NAME "plug_in_max_rgb"
#define SHORT_NAME "max_rgb"
#define PROGRESS_UPDATE_NUM 100
static void query (void);
static void run (gchar *name,
......@@ -76,7 +75,7 @@ enum
typedef struct
{
gint max_p; /* gint, gdouble, and so on */
gint max_p;
} ValueType;
typedef struct
......@@ -212,7 +211,7 @@ max_rgb_func (guchar *src, guchar *dest, gint bpp, gpointer data)
dest[1] = (max_ch & (1 << 1)) ? max : 0;
dest[2] = (max_ch & (1 << 2)) ? max : 0;
if (param->has_alpha)
dest[3] = src[3];
dest[3] = *src;
}
static void
......@@ -223,31 +222,14 @@ main_function (GimpDrawable *drawable,
param.init_value = (pvals.max_p > 0) ? 0 : 255;
param.flag = (0 < pvals.max_p) ? 1 : -1;
param.has_alpha = gimp_drawable_has_alpha (drawable->drawable_id);
if (preview_mode)
{
gint x, y;
gint bpp = preview->bpp;
param.has_alpha = FALSE; /* no alpha on preview */
for (y = 0; y < preview->height; y++)
{
guchar *src = preview->cache + y * preview->rowstride;
guchar *dest = preview->buffer + y * preview->rowstride;
for (x = 0; x < preview->width; x++)
{
max_rgb_func (src, dest, bpp, &param);
dest += bpp;
src += bpp;
}
}
gtk_widget_queue_draw (preview->widget);
gimp_fixme_preview_update (preview, max_rgb_func, &param);
}
else
{ /* normal mode */
param.has_alpha = gimp_drawable_has_alpha (drawable->drawable_id);
gimp_progress_init ( _("Max RGB: Scanning..."));
......
......@@ -30,8 +30,6 @@
* Algorithm fixes, V2.0 compatibility by David Hodson hodsond@ozemail.com.au
*/
/* add any necessary includes */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
......@@ -41,11 +39,6 @@
#include <stdlib.h>
#include <math.h>
#ifdef __GNUC__
#warning GTK_DISABLE_DEPRECATED
#endif
#undef GTK_DISABLE_DEPRECATED
#include <gtk/gtk.h>
#include <libgimp/gimp.h>
......@@ -69,26 +62,11 @@ typedef enum
filter_edge_enhance
} FilterType;
/* preview stuff -- to be removed as soon as we have a real libgimp preview */
typedef struct
{
gint width;
gint height;
gint bpp;
gdouble scale;
guchar *bits;
} mwPreview;
#define PREVIEW_SIZE 100
static gint do_preview = TRUE;
static mwPreview *thePreview;
static GimpFixMePreview *preview;
static GtkWidget * mw_preview_new (GtkWidget *parent,
mwPreview *mwp);
static mwPreview * mw_preview_build (GimpDrawable *drw);
GimpDrawable *drawable);
/* function protos */
......@@ -100,7 +78,8 @@ static void run (gchar *name,
GimpParam **retvals);
static gint pluginCore (piArgs *argp);
static gint pluginCoreIA (piArgs *argp);
static gint pluginCoreIA (piArgs *argp,
GimpDrawable *drawable);
static void nlfilt_do_preview (GtkWidget *preview);
......@@ -177,7 +156,7 @@ run (gchar *name,
switch (param[0].data.d_int32)
{
GimpDrawable *drw;
GimpDrawable *drawable;
case GIMP_RUN_INTERACTIVE:
INIT_I18N_UI();
/* XXX: add code here for interactive running */
......@@ -187,10 +166,9 @@ run (gchar *name,
args.radius = (gdouble) 0.3;
args.filter = 0;
}
drw = gimp_drawable_get (args.drw);
thePreview = mw_preview_build (drw);
drawable = gimp_drawable_get (args.drw);
if (pluginCoreIA (&args) == -1)
if (pluginCoreIA (&args, drawable) == -1)
{
rvals[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
}
......@@ -337,7 +315,7 @@ nlfilt_double_adjustment_update (GtkAdjustment *adjustment,
}
static gint
pluginCoreIA (piArgs *argp)
pluginCoreIA (piArgs *argp, GimpDrawable *drawable)
{
gint retval = -1; /* default to error return */
GtkWidget *dlg;
......@@ -376,7 +354,7 @@ pluginCoreIA (piArgs *argp)
gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0);
gtk_widget_show (hbox);
preview = mw_preview_new (hbox, thePreview);
preview = mw_preview_new (hbox, drawable);
g_object_set_data (G_OBJECT (preview), "piArgs", argp);
nlfilt_do_preview (preview);
......@@ -432,50 +410,39 @@ pluginCoreIA (piArgs *argp)
gtk_main ();
gdk_flush ();
if (run_flag)
{
return pluginCore (argp);
}
else
{
return retval;
}
return (run_flag) ? pluginCore (argp) : retval;
}
static void
nlfilt_do_preview (GtkWidget *w)
{
static GtkWidget *theWidget = NULL;
piArgs *ap;
guchar *dst, *src0, *src1, *src2;
gint y, rowsize, filtno;
if (theWidget == NULL)
{
theWidget = w;
}
ap = g_object_get_data (G_OBJECT (preview->widget), "piArgs");
ap = g_object_get_data (G_OBJECT (theWidget), "piArgs");
rowsize = thePreview->width * thePreview->bpp;
rowsize = preview->width * preview->bpp;
filtno = nlfiltInit (ap->alpha, ap->radius, ap->filter);
src0 = thePreview->bits + thePreview->bpp;
src0 = preview->cache + preview->bpp;
src1 = src0 + rowsize;
src2 = src1 + rowsize;
dst = g_malloc (rowsize);
/* for preview, don't worry about edge effects */
for (y = 1; y < thePreview->height - 1; y++)
for (y = 1; y < preview->height - 1; y++)
{
nlfiltRow (src0, src1, src2, dst + thePreview->bpp,
thePreview->width - 2, thePreview->bpp, filtno);
gtk_preview_draw_row (GTK_PREVIEW (theWidget),
dst + thePreview->bpp, 1, y, thePreview->width - 2);
nlfiltRow (src0, src1, src2, dst + preview->bpp,
preview->width - 2, preview->bpp, filtno);
/*
We should probably fix the edges!
*/
gimp_fixme_preview_do_row (preview, y, preview->width, dst);
src0 = src1; src1 = src2; src2 += rowsize;
}
gtk_widget_queue_draw (theWidget);
gtk_widget_queue_draw (preview->widget);
g_free (dst);
}
......@@ -489,68 +456,9 @@ mw_preview_toggle_callback (GtkWidget *widget,
nlfilt_do_preview (NULL);
}
static mwPreview *
mw_preview_build_virgin (GimpDrawable *drw)
{
mwPreview *mwp;
mwp = g_new (mwPreview, 1);
if (drw->width > drw->height)
{
mwp->scale = (gdouble) drw->width / (gdouble) PREVIEW_SIZE;
mwp->width = PREVIEW_SIZE;
mwp->height = drw->height / mwp->scale;
}
else
{
mwp->scale = (gdouble) drw->height / (gdouble) PREVIEW_SIZE;
mwp->height = PREVIEW_SIZE;
mwp->width = drw->width / mwp->scale;
}
mwp->bpp = 3;
mwp->bits = NULL;
return mwp;
}
static mwPreview *
mw_preview_build (GimpDrawable *drw)
{
mwPreview *mwp;
gint x, y, b;
guchar *bc;
guchar *drwBits;
GimpPixelRgn pr;
mwp = mw_preview_build_virgin (drw);
gimp_pixel_rgn_init (&pr, drw, 0, 0, drw->width, drw->height, FALSE, FALSE);
drwBits = g_new (guchar, drw->width * drw->bpp);
bc = mwp->bits = g_new (guchar, mwp->width * mwp->height * mwp->bpp);
for (y = 0; y < mwp->height; y++)
{
gimp_pixel_rgn_get_row (&pr, drwBits, 0, (int)(y*mwp->scale), drw->width);
for (x = 0; x < mwp->width; x++)
{
for (b = 0; b < mwp->bpp; b++)
*bc++ = *(drwBits +
((gint) (x * mwp->scale) * drw->bpp) + b % drw->bpp);
}
}
g_free (drwBits);
return mwp;
}
static GtkWidget *
mw_preview_new (GtkWidget *parent,
mwPreview *mwp)
mw_preview_new (GtkWidget *parent, GimpDrawable *drawable)
{
GtkWidget *preview;
GtkWidget *frame;
GtkWidget *pframe;
GtkWidget *vbox;
......@@ -570,11 +478,10 @@ mw_preview_new (GtkWidget *parent,
gtk_frame_set_shadow_type (GTK_FRAME(pframe), GTK_SHADOW_IN);
gtk_box_pack_start (GTK_BOX (vbox), pframe, FALSE, FALSE, 0);
gtk_widget_show (pframe);
preview = gtk_preview_new (GTK_PREVIEW_COLOR);
gtk_preview_size (GTK_PREVIEW (preview), mwp->width, mwp->height);
gtk_container_add (GTK_CONTAINER (pframe), preview);
gtk_widget_show (preview);
preview = gimp_fixme_preview_new (drawable, FALSE);
gtk_container_add (GTK_CONTAINER (pframe), preview->widget);
gtk_widget_show (preview->widget);
button = gtk_check_button_new_with_mnemonic (_("_Do Preview"));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), do_preview);
......@@ -585,7 +492,7 @@ mw_preview_new (GtkWidget *parent,
G_CALLBACK (mw_preview_toggle_callback),
&do_preview);
return preview;
return preview->widget;
}
/* pnmnlfilt.c - 4 in 1 (2 non-linear) filter
......@@ -642,11 +549,11 @@ mw_preview_new (GtkWidget *parent,
/* Compute the area of the intersection of a triangle */
/* and a rectangle */
gdouble triang_area(gdouble, gdouble, gdouble, gdouble, gdouble,
gdouble, gdouble, gdouble, gint);
gdouble rectang_area(gdouble, gdouble, gdouble, gdouble,
gdouble, gdouble, gdouble, gdouble);
gdouble hex_area(gdouble, gdouble, gdouble, gdouble, gdouble);
static gdouble triang_area(gdouble, gdouble, gdouble, gdouble, gdouble,
gdouble, gdouble, gdouble, gint);
static gdouble rectang_area(gdouble, gdouble, gdouble, gdouble,
gdouble, gdouble, gdouble, gdouble);
static gdouble hex_area(gdouble, gdouble, gdouble, gdouble, gdouble);
gint atfilt0(gint *p);
gint atfilt1(gint *p);
......@@ -1136,7 +1043,7 @@ atfilt5(gint *p) {
/* compute the area of overlap of a hexagon diameter d, */
/* centered at hx,hy, with a unit square of center sx,sy. */
gdouble
static gdouble
hex_area(gdouble sx, gdouble sy, gdouble hx, gdouble hy, gdouble d) {
gdouble hx0,hx1,hx2,hy0,hy1,hy2,hy3;
gdouble sx0,sx1,sy0,sy1;
......@@ -1163,7 +1070,7 @@ hex_area(gdouble sx, gdouble sy, gdouble hx, gdouble hy, gdouble d) {
triang_area(sx0,sy0,sx1,sy1,hx1,hy0,hx2,hy1,SE);
}
gdouble
static gdouble
triang_area(gdouble rx0, gdouble ry0, gdouble rx1, gdouble ry1, gdouble tx0,
gdouble ty0, gdouble tx1, gdouble ty1, gint tt) {
gdouble a,b,c,d;
......@@ -1240,7 +1147,7 @@ triang_area(gdouble rx0, gdouble ry0, gdouble rx1, gdouble ry1, gdouble tx0,
}
/* Compute rectangle area */
gdouble
static gdouble
rectang_area(gdouble rx0, gdouble ry0, gdouble rx1, gdouble ry1, gdouble tx0,
gdouble ty0, gdouble tx1, gdouble ty1) {
/* Compute overlapping box */
......
......@@ -125,11 +125,6 @@ enum
/* Texture-flags */
#define GRADIENT 0x00000001
typedef struct
{
gdouble x, y, z, w;
} vector;
typedef struct
{
gshort xsize, ysize;
......@@ -138,38 +133,38 @@ typedef struct
typedef struct
{
gshort numcol;
gdouble pos[MAXCOLPERGRADIENT];
vector color[MAXCOLPERGRADIENT];
gshort numcol;
gdouble pos[MAXCOLPERGRADIENT];
GimpVector4 color[MAXCOLPERGRADIENT];
} gradient;
typedef struct
{
gint majtype;
gint type;
gulong flags;
vector color1, color2;
gradient gradient;
vector ambient, diffuse;
gdouble oscale;
vector scale, translate, rotate;
image image;
vector reflection;
vector refraction;
vector transparent;
gdouble ior;
vector phongcolor;
gdouble phongsize;
gdouble amount;
gdouble exp;
vector turbulence;
gint majtype;
gint type;
gulong flags;
GimpVector4 color1, color2;
gradient gradient;
GimpVector4 ambient, diffuse;
gdouble oscale;
GimpVector4 scale, translate, rotate;
image image;
GimpVector4 reflection;
GimpVector4 refraction;
GimpVector4 transparent;
gdouble ior;
GimpVector4 phongcolor;
gdouble phongsize;
gdouble amount;
gdouble exp;
GimpVector4 turbulence;
} texture;
typedef struct
{
gshort type;
gdouble density;
vector color;
GimpVector4 color;
gdouble turbulence;
} atmos;
......@@ -186,48 +181,48 @@ typedef struct
typedef struct
{
common com;
vector a, b, c;
GimpVector4 a, b, c;
} triangle;
typedef struct
{
common com;
vector a;
gdouble b, r;
common com;
GimpVector4 a;
gdouble b, r;
} disc;
typedef struct
{
common com;
vector a;
gdouble r;
common com;
GimpVector4 a;
gdouble r;
} sphere;
typedef struct
{
common com;
vector a, b, c;
common com;
GimpVector4 a, b, c;
} cylinder;
typedef struct
{
common com;
vector a;
gdouble b;
common com;
GimpVector4 a;
gdouble b;
} plane;
typedef struct
{
common com;
vector color;
vector a;
common com;
GimpVector4 color;
GimpVector4 a;
} light;
typedef struct
{
vector v1, v2;
gshort inside;
gdouble ior;
GimpVector4 v1, v2;
gshort inside;
gdouble ior;
} ray;
typedef union
......@@ -258,7 +253,7 @@ struct world_t
struct camera_t
{
vector location, lookat, up, right;
GimpVector4 location, lookat, up, right;
short type;
double fov, tilt;
};
......@@ -299,14 +294,15 @@ struct
settings = { 1, 1, 1 };
static inline void vset (vector *v, gdouble a, gdouble b, gdouble c);
static inline void vset (GimpVector4 *v, gdouble a, gdouble b, gdouble c);
static void restartrender (void);
static void drawcolor1 (GtkWidget *widget);
static void drawcolor2 (GtkWidget *widget);
static void render (void);
static void realrender (GimpDrawable *drawable);
static void fileselect (gint);
static gint traceray (ray * r, vector * col, gint level, gdouble imp);
static gint traceray (ray * r, GimpVector4 * col, gint level,
gdouble imp);
static gdouble turbulence (gdouble *point, gdouble lofreq, gdouble hifreq);
......@@ -482,38 +478,27 @@ struct camera_t camera;
struct world_t world;
static inline void
vcopy (vector * a, vector * b)
vcopy (GimpVector4 *a, GimpVector4 *b)
{
a->x = b->x;
a->y = b->y;
a->z = b->z;
a->w = b->w;
*a = *b;
}
static inline void
vcross (vector * r, vector * a, vector * b)
vcross (GimpVector4 *r, GimpVector4 *a, GimpVector4 *b)
{
vector t;
t.x = a->y * b->z - a->z * b->y;
t.y = -(a->x * b->z - a->z * b->x);
t.z = a->x * b->y - a->y * b->x;
vcopy (r, &t);
r->x = a->y * b->z - a->z * b->y;
r->y = -(a->x * b->z - a->z * b->x);
r->z = a->x * b->y - a->y * b->x;
}
static inline gdouble
vdot (vector * a, vector * b)
vdot (GimpVector4 *a, GimpVector4 *b)
{
gdouble s;
s = a->x * b->x;
s += a->y * b->y;
s += a->z * b->z;
return s;
return a->x * b->x + a->y * b->y + a->z * b->z;
}
static inline gdouble
vdist (vector * a, vector * b)
vdist (GimpVector4 *a, GimpVector4 *b)
{
gdouble x, y, z;
......@@ -525,28 +510,24 @@ vdist (vector * a, vector * b)
}
static inline gdouble
vlen (vector * a)
vlen (GimpVector4 *a)
{
gdouble l;
l = sqrt (a->x * a->x + a->y * a->y + a->z * a->z);
return l;
return sqrt (a->x * a->x + a->y * a->y + a->z * a->z);
}
static inline void
vnorm (vector * a, gdouble v)
vnorm (GimpVector4 *a, gdouble v)
{
gdouble d;
d = sqrt (a->x * a->x + a->y * a->y + a->z * a->z);
d = vlen (a);
a->x *= v / d;
a->y *= v / d;
a->z *= v / d;
}
static inline void
vrotate (vector * axis, gdouble ang, vector * vector)
vrotate (GimpVector4 *axis, gdouble ang, GimpVector4 *vector)
{
gdouble rad = ang / 180.0 * G_PI;
gdouble ax = vector->x;
......@@ -574,7 +555,7 @@ vrotate (vector * axis, gdouble ang, vector * vector)
}
static inline void
vset (vector * v, gdouble a, gdouble b, gdouble c)
vset (GimpVector4 *v, gdouble a, gdouble b, gdouble c)
{
v->x = a;
v->y = b;
......@@ -583,7 +564,7 @@ vset (vector * v, gdouble a, gdouble b, gdouble c)
}
static inline void
vcset (vector * v, gdouble a, gdouble b, gdouble c, gdouble d)
vcset (GimpVector4 *v, gdouble a, gdouble b, gdouble c, gdouble d)
{
v->x = a;
v->y = b;
......@@ -592,9 +573,9 @@ vcset (vector * v, gdouble a, gdouble b, gdouble c, gdouble d)
}
static inline void
vvrotate (vector * p, vector * rot)
vvrotate (GimpVector4 *p, GimpVector4 *rot)
{
vector axis;
GimpVector4 axis;
if (rot->x != 0.0)
{
......@@ -614,7 +595,7 @@ vvrotate (vector * p, vector * rot)
}
static inline void
vsub (vector * a, vector * b)
vsub (GimpVector4 *a, GimpVector4 *b)
{
a->x -= b->x;
a->y -= b->y;
......@@ -623,7 +604,7 @@ vsub (vector * a, vector * b)
}
static inline void
vadd (vector * a, vector * b)
vadd (GimpVector4 *a, GimpVector4 *b)
{
a->x += b->x;
a->y += b->y;
......@@ -632,7 +613,7 @@ vadd (vector * a, vector * b)
}
static inline void
vneg (vector * a)
vneg (GimpVector4 *a)
{
a->x = -a->x;
a->y = -a->y;
......@@ -641,7 +622,7 @@ vneg (vector * a)
}
static inline void
vmul (vector * v, gdouble a)
vmul (GimpVector4 *v, gdouble a)
{
v->x *= a;
v->y *= a;
......@@ -650,7 +631,7 @@ vmul (vector * v, gdouble a)
}
static inline void
vvmul (vector * a, vector * b)
vvmul (GimpVector4 *a, GimpVector4 *b)
{
a->x *= b->x;
a->y *= b->y;
......@@ -659,7 +640,7 @@ vvmul (vector * a, vector * b)
}
static inline void
vvdiv (vector * a, vector * b)
vvdiv (GimpVector4 *a, GimpVector4 *b)
{
a->x /= b->x;
a->y /= b->y;
......@@ -667,7 +648,7 @@ vvdiv (vector * a, vector * b)
}
static void
vmix (vector * r, vector * a, vector * b, gdouble v)
vmix (GimpVector4 *r, GimpVector4 *a, GimpVector4 *b, gdouble v)
{
gdouble i = 1.0 - v;
......@@ -678,7 +659,7 @@ vmix (vector * r, vector * a, vector * b, gdouble v)
}
static double
vmax (vector * a)
vmax (GimpVector4 *a)
{
gdouble max = fabs (a->x);
......@@ -694,7 +675,7 @@ vmax (vector * a)
#if 0
static void
vavg (vector * a)
vavg (GimpVector4 * a)
{