code cosmetics.

2003-02-25  Sven Neumann  <sven@gimp.org>

	* plug-ins/common/spheredesigner.c: code cosmetics.
This commit is contained in:
Sven Neumann
2003-02-24 23:44:18 +00:00
committed by Sven Neumann
parent aa4460fbd6
commit 6af1f58b96
2 changed files with 162 additions and 121 deletions

View File

@ -1,3 +1,7 @@
2003-02-25 Sven Neumann <sven@gimp.org>
* plug-ins/common/spheredesigner.c: code cosmetics.
2003-02-24 Sven Neumann <sven@gimp.org>
* autogen.sh: prefer automake-1.7 over automake-1.6.

View File

@ -260,9 +260,6 @@ struct camera_t
double fov, tilt;
};
static gint traceray (ray * r, vector * col, int level, double imp);
static gdouble turbulence (gdouble *point, gdouble lofreq, gdouble hifreq);
static GtkWidget *drawarea = NULL;
static guchar img[PREVIEWSIZE * PREVIEWSIZE * 3];
@ -298,6 +295,7 @@ struct
}
settings = { 1, 1, 1 };
static inline void vset (vector *v, gdouble a, gdouble b, gdouble c);
static void restartrender (void);
static void drawcolor1 (GtkWidget *widget);
@ -305,11 +303,15 @@ 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 gdouble turbulence (gdouble *point, gdouble lofreq, gdouble hifreq);
#define COLORBUTTONWIDTH 30
#define COLORBUTTONHEIGHT 20
static GtkWidget *texturelist = NULL;
static GtkObject *scalexscale, *scaleyscale, *scalezscale;
static GtkObject *rotxscale, *rotyscale, *rotzscale;
static GtkObject *posxscale, *posyscale, *poszscale;
@ -328,9 +330,10 @@ static GtkWidget *texturemenu;
static gint p[B + B + 2];
static gdouble g[B + B + 2][3];
static gint start = 1;
static gboolean start = TRUE;
static GRand *gr;
static void
init (void)
{
@ -367,7 +370,7 @@ init (void)
p[j] = k;
}
/* Extend g and p arrays to allow for faster indexing */
/* Extend g and p arrays to allow for faster indexing */
for (i = 0; i < B + 2; i++)
{
@ -385,7 +388,7 @@ init (void)
r1 = r0 - 1.;
static double
static gdouble
noise3 (gdouble * vec)
{
gint bx0, bx1, by0, by1, bz0, bz1, b00, b10, b01, b11;
@ -394,7 +397,7 @@ noise3 (gdouble * vec)
if (start)
{
start = 0;
start = FALSE;
init ();
}
@ -506,7 +509,7 @@ vdot (vector * a, vector * b)
return s;
}
static inline double
static inline gdouble
vdist (vector * a, vector * b)
{
gdouble x, y, z;
@ -518,7 +521,7 @@ vdist (vector * a, vector * b)
return sqrt (x * x + y * y + z * z);
}
static inline double
static inline gdouble
vlen (vector * a)
{
gdouble l;
@ -529,7 +532,7 @@ vlen (vector * a)
}
static inline void
vnorm (vector * a, double v)
vnorm (vector * a, gdouble v)
{
gdouble d;
@ -540,7 +543,7 @@ vnorm (vector * a, double v)
}
static inline void
vrotate (vector * axis, double ang, vector * vector)
vrotate (vector * axis, gdouble ang, vector * vector)
{
gdouble rad = ang / 180.0 * G_PI;
gdouble ax = vector->x;
@ -794,28 +797,26 @@ checksphere (ray * r, sphere * sphere)
{
return solmax;
/*
*hits = solmax;
return 1;
* hits = solmax;
* return 1;
*/
}
else
{
return solmin;
/*
*hits++ = solmin;
*hits = solmax;
return 2;
* hits++ = solmin;
* hits = solmax;
* return 2;
*/
}
}
static gdouble
checkcylinder (ray * r, cylinder * cylinder)
{
/* fixme */
return 0;
/* FIXME */
return 0.0;
}
@ -1133,7 +1134,7 @@ imagepixel (vector * q, vector * col, texture * t)
static void
objcolor (vector * col, vector * p, common * obj)
{
int i;
gint i;
texture *t;
vector tmpcol;
@ -1204,7 +1205,7 @@ objcolor (vector * col, vector * p, common * obj)
static void
objnormal (vector * res, common * obj, vector * p)
{
int i;
gint i;
switch (obj->type)
{
@ -1232,11 +1233,11 @@ objnormal (vector * res, common * obj, vector * p)
for (i = 0; i < obj->numnormal; i++)
{
int k;
gint k;
vector tmpcol[6];
vector q[6], nres;
texture *t = &obj->normal[i];
double nstep = 0.1;
gdouble nstep = 0.1;
vset (&nres, 0, 0, 0);
for (k = 0; k < 6; k++)
@ -1398,13 +1399,13 @@ calclight (vector * col, vector * point, common * obj)
static void
calcphong (common * obj, ray * r2, vector * col)
{
int i, j, o;
gint i, j, o;
ray r;
double d, b;
gdouble d, b;
vector lcol;
vector norm;
vector pcol;
double ps;
gdouble ps;
vcopy (&pcol, col);
@ -1454,13 +1455,13 @@ calcphong (common * obj, ray * r2, vector * col)
}
static int
traceray (ray * r, vector * col, int level, double imp)
traceray (ray * r, vector * col, gint level, gdouble imp)
{
int i, b = -1;
double t = -1.0, min = 0.0;
int type = -1;
gint i, b = -1;
gdouble t = -1.0, min = 0.0;
gint type = -1;
common *obj, *bobj = NULL;
int hits = 0;
gint hits = 0;
vector p;
if ((level == 0) || (imp < 0.005))
@ -1524,7 +1525,7 @@ traceray (ray * r, vector * col, int level, double imp)
if (world.flags & SMARTAMBIENT)
{
double ambient = 0.3 * exp (-min / world.smartambient);
gdouble ambient = 0.3 * exp (-min / world.smartambient);
vector lcol;
objcolor (&lcol, &p, bobj);
vmul (&lcol, ambient);
@ -1719,7 +1720,7 @@ traceray (ray * r, vector * col, int level, double imp)
vector tmpcol;
if (world.atmos[i].type == FOG)
{
double v, pt[3];
gdouble v, pt[3];
pt[0] = p.x;
pt[1] = p.y;
pt[2] = p.z;
@ -1785,10 +1786,11 @@ mklabel (texture * t)
}
static GtkWidget *
currentitem (GtkWidget * list)
currentitem (GtkWidget *list)
{
GList *h;
GtkWidget *tmpw;
h = GTK_LIST (list)->selection;
if (!h)
return NULL;
@ -1801,6 +1803,7 @@ currenttexture (void)
{
GtkWidget *tmpw;
texture *t;
tmpw = currentitem (texturelist);
if (!tmpw)
return NULL;
@ -1813,6 +1816,7 @@ relabel (void)
{
GtkWidget *tmpw = currentitem (texturelist);
texture *t = currenttexture ();
if (!tmpw || !t)
return;
tmpw = GTK_BIN (tmpw)->child;
@ -1871,7 +1875,8 @@ setvals (texture * t)
static void
selectitem (GtkWidget * wg, GtkWidget * p)
selectitem (GtkWidget *widget,
gpointer data)
{
setvals (currenttexture ());
}
@ -1880,7 +1885,7 @@ static void
addtexture (void)
{
GtkWidget *item;
int n = s.com.numtexture;
gint n = s.com.numtexture;
if (n == MAXTEXTUREPEROBJ - 1)
return;
@ -1903,7 +1908,7 @@ duptexture (void)
{
GtkWidget *item;
texture *t = currenttexture ();
int n = s.com.numtexture;
gint n = s.com.numtexture;
if (n == MAXTEXTUREPEROBJ - 1)
return;
@ -1978,6 +1983,7 @@ deltexture (void)
{
texture *t;
GtkWidget *tmpw;
tmpw = currentitem (texturelist);
if (!tmpw)
return;
@ -2000,6 +2006,12 @@ loadit (const gchar * fn)
s.com.numtexture = 0;
f = fopen (fn, "rt");
if (!f)
{
g_message ("Failed to open '%s': %s", fn, g_strerror (errno));
return;
}
while (!feof (f))
{
@ -2055,13 +2067,16 @@ loadit (const gchar * fn)
s.com.numtexture++;
}
fclose (f);
}
static void
loadpreset_ok (GtkWidget * w, GtkFileSelection * fs)
loadpreset_ok (GtkWidget *widget,
GtkFileSelection *fs)
{
const gchar *fn = gtk_file_selection_get_filename (GTK_FILE_SELECTION (fs));
gtk_widget_hide (GTK_WIDGET (fs));
gtk_list_clear_items (GTK_LIST (texturelist), 0, -1);
loadit (fn);
@ -2070,13 +2085,18 @@ loadpreset_ok (GtkWidget * w, GtkFileSelection * fs)
}
static void
saveit (const gchar * fn)
saveit (const gchar *fn)
{
gint i;
FILE *f;
gchar buf[G_ASCII_DTOSTR_BUF_SIZE];
f = fopen (fn, "wt");
if (!f)
{
g_message ("Failed to open '%s': %s", fn, g_strerror (errno));
return;
}
for (i = 0; i < s.com.numtexture; i++)
{
@ -2114,7 +2134,8 @@ saveit (const gchar * fn)
}
static void
savepreset_ok (GtkWidget * w, GtkFileSelection * fs)
savepreset_ok (GtkWidget *widget,
GtkFileSelection *fs)
{
const char *fn = gtk_file_selection_get_filename (GTK_FILE_SELECTION (fs));
gtk_widget_hide (GTK_WIDGET (fs));
@ -2134,7 +2155,7 @@ savepreset (void)
}
static void
fileselect (int action)
fileselect (gint action)
{
static GtkWidget *windows[2] = { NULL, NULL };
@ -2270,6 +2291,7 @@ selecttexture (GtkWidget * wg, gpointer data)
{
texture *t;
gint n = GPOINTER_TO_INT (data);
if (noupdate)
return;
t = currenttexture ();
@ -2285,6 +2307,7 @@ selecttype (GtkWidget * wg, gpointer data)
{
texture *t;
gint n = GPOINTER_TO_INT (data);
if (noupdate)
return;
t = currenttexture ();
@ -2296,10 +2319,12 @@ selecttype (GtkWidget * wg, gpointer data)
}
static void
getscales (GtkWidget * wg, gpointer data)
getscales (GtkWidget *widget,
gpointer data)
{
gdouble f;
texture *t;
if (noupdate)
return;
t = currenttexture ();
@ -2325,7 +2350,7 @@ getscales (GtkWidget * wg, gpointer data)
}
static void
mktexturemenu (GtkWidget * texturemenu_menu)
mktexturemenu (GtkWidget *texturemenu_menu)
{
GtkWidget *item;
struct textures_t *t;
@ -2365,9 +2390,10 @@ color2_changed (GimpColorButton *button,
}
static void
drawcolor1 (GtkWidget * w)
drawcolor1 (GtkWidget *w)
{
static GtkWidget *lastw = NULL;
texture *t = currenttexture ();
if (w)
@ -2384,9 +2410,10 @@ drawcolor1 (GtkWidget * w)
}
static void
drawcolor2 (GtkWidget * w)
drawcolor2 (GtkWidget *w)
{
static GtkWidget *lastw = NULL;
texture *t = currenttexture ();
if (w)
@ -2406,7 +2433,8 @@ drawcolor2 (GtkWidget * w)
static gboolean do_run = FALSE;
static void
sphere_ok (GtkWidget * widget, gpointer data)
sphere_ok (GtkWidget *widget,
gpointer data)
{
running = -1;
do_run = TRUE;
@ -2415,7 +2443,8 @@ sphere_ok (GtkWidget * widget, gpointer data)
}
static void
sphere_cancel (GtkWidget * widget, gpointer data)
sphere_cancel (GtkWidget *widget,
gpointer data)
{
gtk_widget_hide (GTK_WIDGET (data));
gtk_main_quit ();
@ -2441,12 +2470,19 @@ makewindow (void)
window = gimp_dialog_new (_("Sphere Designer"), "spheredesigner",
gimp_standard_help_func,
"filters/spheredesigner.html", GTK_WIN_POS_MOUSE,
FALSE, TRUE, FALSE, GIMP_STOCK_RESET,
"filters/spheredesigner.html",
GTK_WIN_POS_MOUSE, FALSE, TRUE, FALSE,
GIMP_STOCK_RESET,
sphere_reset, NULL, NULL, NULL, FALSE, FALSE,
GTK_STOCK_CANCEL, sphere_cancel, NULL, NULL, NULL,
FALSE, TRUE, GTK_STOCK_OK, sphere_ok, NULL, NULL,
NULL, TRUE, FALSE, NULL);
GTK_STOCK_CANCEL,
sphere_cancel, NULL, NULL, NULL, FALSE, TRUE,
GTK_STOCK_OK,
sphere_ok, NULL, NULL, NULL, TRUE, FALSE,
NULL);
table = gtk_table_new (3, 3, FALSE);
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (window)->vbox), table);
@ -3016,8 +3052,9 @@ realrender (GimpDrawable * drawable)
gimp_pixel_rgn_get_row (&pr, ibuffer, x1, y1 + y, x2 - x1);
for (x = 0; x < (x2 - x1); x++)
{
int k, dx = x * 4, sx = x * bpp;
float a = buffer[dx + 3] / 255.0;
gint k, dx = x * 4, sx = x * bpp;
gfloat a = buffer[dx + 3] / 255.0;
for (k = 0; k < bpp; k++)
{
ibuffer[sx + k] =
@ -3025,7 +3062,7 @@ realrender (GimpDrawable * drawable)
}
}
gimp_pixel_rgn_set_row (&dpr, ibuffer, x1, y1 + y, x2 - x1);
gimp_progress_update ((double) y / (double) ty);
gimp_progress_update ((gdouble) y / (gdouble) ty);
}
g_free (buffer);
g_free (ibuffer);