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> 2003-02-24 Sven Neumann <sven@gimp.org>
* autogen.sh: prefer automake-1.7 over automake-1.6. * autogen.sh: prefer automake-1.7 over automake-1.6.

View File

@ -260,9 +260,6 @@ struct camera_t
double fov, tilt; 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 GtkWidget *drawarea = NULL;
static guchar img[PREVIEWSIZE * PREVIEWSIZE * 3]; static guchar img[PREVIEWSIZE * PREVIEWSIZE * 3];
@ -298,18 +295,23 @@ struct
} }
settings = { 1, 1, 1 }; 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);
static void drawcolor2 (GtkWidget *widget);
static void render (void);
static void realrender (GimpDrawable *drawable);
static void fileselect (gint);
#define COLORBUTTONWIDTH 30 static inline void vset (vector *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 gdouble turbulence (gdouble *point, gdouble lofreq, gdouble hifreq);
#define COLORBUTTONWIDTH 30
#define COLORBUTTONHEIGHT 20 #define COLORBUTTONHEIGHT 20
static GtkWidget *texturelist = NULL; static GtkWidget *texturelist = NULL;
static GtkObject *scalexscale, *scaleyscale, *scalezscale; static GtkObject *scalexscale, *scaleyscale, *scalezscale;
static GtkObject *rotxscale, *rotyscale, *rotzscale; static GtkObject *rotxscale, *rotyscale, *rotzscale;
static GtkObject *posxscale, *posyscale, *poszscale; static GtkObject *posxscale, *posyscale, *poszscale;
@ -326,10 +328,11 @@ static GtkWidget *texturemenu;
#define B 256 #define B 256
static gint p[B + B + 2]; static gint p[B + B + 2];
static gdouble g[B + B + 2][3]; static gdouble g[B + B + 2][3];
static gint start = 1; static gboolean start = TRUE;
static GRand *gr; static GRand *gr;
static void static void
init (void) init (void)
@ -340,19 +343,19 @@ init (void)
/* Create an array of random gradient vectors uniformly on the unit sphere */ /* Create an array of random gradient vectors uniformly on the unit sphere */
gr = g_rand_new (); gr = g_rand_new ();
g_rand_set_seed (gr, 1); /* Use static seed, to get reproducable results */ g_rand_set_seed (gr, 1); /* Use static seed, to get reproducable results */
for (i = 0; i < B; i++) for (i = 0; i < B; i++)
{ {
do do
{ /* Choose uniformly in a cube */ { /* Choose uniformly in a cube */
for (j = 0; j < 3; j++) for (j = 0; j < 3; j++)
v[j] = g_rand_double_range (gr, -1, 1); v[j] = g_rand_double_range (gr, -1, 1);
s = DOT (v, v); s = DOT (v, v);
} }
while (s > 1.0); /* If not in sphere try again */ while (s > 1.0); /* If not in sphere try again */
s = sqrt (s); s = sqrt (s);
for (j = 0; j < 3; j++) /* Else normalize */ for (j = 0; j < 3; j++) /* Else normalize */
g[i][j] = v[j] / s; g[i][j] = v[j] / s;
} }
@ -367,7 +370,7 @@ init (void)
p[j] = k; 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++) for (i = 0; i < B + 2; i++)
{ {
@ -385,16 +388,16 @@ init (void)
r1 = r0 - 1.; r1 = r0 - 1.;
static double static gdouble
noise3 (gdouble * vec) noise3 (gdouble * vec)
{ {
gint bx0, bx1, by0, by1, bz0, bz1, b00, b10, b01, b11; gint bx0, bx1, by0, by1, bz0, bz1, b00, b10, b01, b11;
gdouble rx0, rx1, ry0, ry1, rz0, rz1, *q, sx, sy, sz, a, b, c, d, t, u, v; gdouble rx0, rx1, ry0, ry1, rz0, rz1, *q, sx, sy, sz, a, b, c, d, t, u, v;
gint i, j; gint i, j;
if (start) if (start)
{ {
start = 0; start = FALSE;
init (); init ();
} }
@ -473,7 +476,7 @@ turbulence (gdouble * point, gdouble lofreq, gdouble hifreq)
} }
struct camera_t camera; struct camera_t camera;
struct world_t world; struct world_t world;
static inline void static inline void
vcopy (vector * a, vector * b) vcopy (vector * a, vector * b)
@ -506,7 +509,7 @@ vdot (vector * a, vector * b)
return s; return s;
} }
static inline double static inline gdouble
vdist (vector * a, vector * b) vdist (vector * a, vector * b)
{ {
gdouble x, y, z; gdouble x, y, z;
@ -518,7 +521,7 @@ vdist (vector * a, vector * b)
return sqrt (x * x + y * y + z * z); return sqrt (x * x + y * y + z * z);
} }
static inline double static inline gdouble
vlen (vector * a) vlen (vector * a)
{ {
gdouble l; gdouble l;
@ -529,7 +532,7 @@ vlen (vector * a)
} }
static inline void static inline void
vnorm (vector * a, double v) vnorm (vector * a, gdouble v)
{ {
gdouble d; gdouble d;
@ -540,27 +543,27 @@ vnorm (vector * a, double v)
} }
static inline void 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 rad = ang / 180.0 * G_PI;
gdouble ax = vector->x; gdouble ax = vector->x;
gdouble ay = vector->y; gdouble ay = vector->y;
gdouble az = vector->z; gdouble az = vector->z;
gdouble x = axis->x; gdouble x = axis->x;
gdouble y = axis->y; gdouble y = axis->y;
gdouble z = axis->z; gdouble z = axis->z;
gdouble c = cos (rad); gdouble c = cos (rad);
gdouble s = sin (rad); gdouble s = sin (rad);
gdouble c1 = 1.0 - c; gdouble c1 = 1.0 - c;
gdouble xx = c1 * x * x; gdouble xx = c1 * x * x;
gdouble yy = c1 * y * y; gdouble yy = c1 * y * y;
gdouble zz = c1 * z * z; gdouble zz = c1 * z * z;
gdouble xy = c1 * x * y; gdouble xy = c1 * x * y;
gdouble xz = c1 * x * z; gdouble xz = c1 * x * z;
gdouble yz = c1 * y * z; gdouble yz = c1 * y * z;
gdouble sx = s * x; gdouble sx = s * x;
gdouble sy = s * y; gdouble sy = s * y;
gdouble sz = s * z; gdouble sz = s * z;
vector->x = (xx + c) * ax + (xy + sz) * ay + (xz - sy) * az; vector->x = (xx + c) * ax + (xy + sz) * ay + (xz - sy) * az;
vector->y = (xy - sz) * ax + (yy + c) * ay + (yz + sx) * az; vector->y = (xy - sz) * ax + (yy + c) * ay + (yz + sx) * az;
@ -794,28 +797,26 @@ checksphere (ray * r, sphere * sphere)
{ {
return solmax; return solmax;
/* /*
*hits = solmax; * hits = solmax;
return 1; * return 1;
*/ */
} }
else else
{ {
return solmin; return solmin;
/* /*
*hits++ = solmin; * hits++ = solmin;
*hits = solmax; * hits = solmax;
return 2; * return 2;
*/ */
} }
} }
static gdouble static gdouble
checkcylinder (ray * r, cylinder * cylinder) checkcylinder (ray * r, cylinder * cylinder)
{ {
/* fixme */ /* FIXME */
return 0; return 0.0;
} }
@ -839,8 +840,8 @@ checkplane (ray * r, plane * plane)
static gdouble static gdouble
checktri (ray * r, triangle * tri) checktri (ray * r, triangle * tri)
{ {
vector ed1, ed2; vector ed1, ed2;
vector tvec, pvec, qvec; vector tvec, pvec, qvec;
gdouble det, idet, t, u, v; gdouble det, idet, t, u, v;
vector *orig, dir; vector *orig, dir;
@ -909,7 +910,7 @@ transformpoint (vector * p, texture * t)
static void static void
checker (vector * q, vector * col, texture * t) checker (vector * q, vector * col, texture * t)
{ {
gint c = 0; gint c = 0;
vector p; vector p;
vcopy (&p, q); vcopy (&p, q);
@ -1133,9 +1134,9 @@ imagepixel (vector * q, vector * col, texture * t)
static void static void
objcolor (vector * col, vector * p, common * obj) objcolor (vector * col, vector * p, common * obj)
{ {
int i; gint i;
texture *t; texture *t;
vector tmpcol; vector tmpcol;
vcset (col, 0, 0, 0, 0); vcset (col, 0, 0, 0, 0);
@ -1204,7 +1205,7 @@ objcolor (vector * col, vector * p, common * obj)
static void static void
objnormal (vector * res, common * obj, vector * p) objnormal (vector * res, common * obj, vector * p)
{ {
int i; gint i;
switch (obj->type) switch (obj->type)
{ {
@ -1232,11 +1233,11 @@ objnormal (vector * res, common * obj, vector * p)
for (i = 0; i < obj->numnormal; i++) for (i = 0; i < obj->numnormal; i++)
{ {
int k; gint k;
vector tmpcol[6]; vector tmpcol[6];
vector q[6], nres; vector q[6], nres;
texture *t = &obj->normal[i]; texture *t = &obj->normal[i];
double nstep = 0.1; gdouble nstep = 0.1;
vset (&nres, 0, 0, 0); vset (&nres, 0, 0, 0);
for (k = 0; k < 6; k++) for (k = 0; k < 6; k++)
@ -1398,13 +1399,13 @@ calclight (vector * col, vector * point, common * obj)
static void static void
calcphong (common * obj, ray * r2, vector * col) calcphong (common * obj, ray * r2, vector * col)
{ {
int i, j, o; gint i, j, o;
ray r; ray r;
double d, b; gdouble d, b;
vector lcol; vector lcol;
vector norm; vector norm;
vector pcol; vector pcol;
double ps; gdouble ps;
vcopy (&pcol, col); vcopy (&pcol, col);
@ -1454,14 +1455,14 @@ calcphong (common * obj, ray * r2, vector * col)
} }
static int static int
traceray (ray * r, vector * col, int level, double imp) traceray (ray * r, vector * col, gint level, gdouble imp)
{ {
int i, b = -1; gint i, b = -1;
double t = -1.0, min = 0.0; gdouble t = -1.0, min = 0.0;
int type = -1; gint type = -1;
common *obj, *bobj = NULL; common *obj, *bobj = NULL;
int hits = 0; gint hits = 0;
vector p; vector p;
if ((level == 0) || (imp < 0.005)) if ((level == 0) || (imp < 0.005))
{ {
@ -1524,7 +1525,7 @@ traceray (ray * r, vector * col, int level, double imp)
if (world.flags & SMARTAMBIENT) if (world.flags & SMARTAMBIENT)
{ {
double ambient = 0.3 * exp (-min / world.smartambient); gdouble ambient = 0.3 * exp (-min / world.smartambient);
vector lcol; vector lcol;
objcolor (&lcol, &p, bobj); objcolor (&lcol, &p, bobj);
vmul (&lcol, ambient); vmul (&lcol, ambient);
@ -1719,7 +1720,7 @@ traceray (ray * r, vector * col, int level, double imp)
vector tmpcol; vector tmpcol;
if (world.atmos[i].type == FOG) if (world.atmos[i].type == FOG)
{ {
double v, pt[3]; gdouble v, pt[3];
pt[0] = p.x; pt[0] = p.x;
pt[1] = p.y; pt[1] = p.y;
pt[2] = p.z; pt[2] = p.z;
@ -1785,10 +1786,11 @@ mklabel (texture * t)
} }
static GtkWidget * static GtkWidget *
currentitem (GtkWidget * list) currentitem (GtkWidget *list)
{ {
GList *h; GList *h;
GtkWidget *tmpw; GtkWidget *tmpw;
h = GTK_LIST (list)->selection; h = GTK_LIST (list)->selection;
if (!h) if (!h)
return NULL; return NULL;
@ -1800,7 +1802,8 @@ static texture *
currenttexture (void) currenttexture (void)
{ {
GtkWidget *tmpw; GtkWidget *tmpw;
texture *t; texture *t;
tmpw = currentitem (texturelist); tmpw = currentitem (texturelist);
if (!tmpw) if (!tmpw)
return NULL; return NULL;
@ -1812,7 +1815,8 @@ static void
relabel (void) relabel (void)
{ {
GtkWidget *tmpw = currentitem (texturelist); GtkWidget *tmpw = currentitem (texturelist);
texture *t = currenttexture (); texture *t = currenttexture ();
if (!tmpw || !t) if (!tmpw || !t)
return; return;
tmpw = GTK_BIN (tmpw)->child; tmpw = GTK_BIN (tmpw)->child;
@ -1871,7 +1875,8 @@ setvals (texture * t)
static void static void
selectitem (GtkWidget * wg, GtkWidget * p) selectitem (GtkWidget *widget,
gpointer data)
{ {
setvals (currenttexture ()); setvals (currenttexture ());
} }
@ -1880,7 +1885,7 @@ static void
addtexture (void) addtexture (void)
{ {
GtkWidget *item; GtkWidget *item;
int n = s.com.numtexture; gint n = s.com.numtexture;
if (n == MAXTEXTUREPEROBJ - 1) if (n == MAXTEXTUREPEROBJ - 1)
return; return;
@ -1902,8 +1907,8 @@ static void
duptexture (void) duptexture (void)
{ {
GtkWidget *item; GtkWidget *item;
texture *t = currenttexture (); texture *t = currenttexture ();
int n = s.com.numtexture; gint n = s.com.numtexture;
if (n == MAXTEXTUREPEROBJ - 1) if (n == MAXTEXTUREPEROBJ - 1)
return; return;
@ -1927,7 +1932,7 @@ static void
rebuildlist (void) rebuildlist (void)
{ {
GtkWidget *item; GtkWidget *item;
gint n; gint n;
for (n = 0; n < s.com.numtexture; n++) for (n = 0; n < s.com.numtexture; n++)
{ {
@ -1976,8 +1981,9 @@ sphere_reset (void)
static void static void
deltexture (void) deltexture (void)
{ {
texture *t; texture *t;
GtkWidget *tmpw; GtkWidget *tmpw;
tmpw = currentitem (texturelist); tmpw = currentitem (texturelist);
if (!tmpw) if (!tmpw)
return; return;
@ -1991,15 +1997,21 @@ deltexture (void)
static void static void
loadit (const gchar * fn) loadit (const gchar * fn)
{ {
FILE *f; FILE *f;
gchar *end; gchar *end;
gchar line[1024]; gchar line[1024];
gint i; gint i;
texture *t; texture *t;
s.com.numtexture = 0; s.com.numtexture = 0;
f = fopen (fn, "rt"); f = fopen (fn, "rt");
if (!f)
{
g_message ("Failed to open '%s': %s", fn, g_strerror (errno));
return;
}
while (!feof (f)) while (!feof (f))
{ {
@ -2055,13 +2067,16 @@ loadit (const gchar * fn)
s.com.numtexture++; s.com.numtexture++;
} }
fclose (f); fclose (f);
} }
static void 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)); const gchar *fn = gtk_file_selection_get_filename (GTK_FILE_SELECTION (fs));
gtk_widget_hide (GTK_WIDGET (fs)); gtk_widget_hide (GTK_WIDGET (fs));
gtk_list_clear_items (GTK_LIST (texturelist), 0, -1); gtk_list_clear_items (GTK_LIST (texturelist), 0, -1);
loadit (fn); loadit (fn);
@ -2070,13 +2085,18 @@ loadpreset_ok (GtkWidget * w, GtkFileSelection * fs)
} }
static void static void
saveit (const gchar * fn) saveit (const gchar *fn)
{ {
gint i; gint i;
FILE *f; FILE *f;
gchar buf[G_ASCII_DTOSTR_BUF_SIZE]; gchar buf[G_ASCII_DTOSTR_BUF_SIZE];
f = fopen (fn, "wt"); 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++) for (i = 0; i < s.com.numtexture; i++)
{ {
@ -2114,7 +2134,8 @@ saveit (const gchar * fn)
} }
static void 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)); const char *fn = gtk_file_selection_get_filename (GTK_FILE_SELECTION (fs));
gtk_widget_hide (GTK_WIDGET (fs)); gtk_widget_hide (GTK_WIDGET (fs));
@ -2134,7 +2155,7 @@ savepreset (void)
} }
static void static void
fileselect (int action) fileselect (gint action)
{ {
static GtkWidget *windows[2] = { NULL, NULL }; static GtkWidget *windows[2] = { NULL, NULL };
@ -2269,7 +2290,8 @@ static void
selecttexture (GtkWidget * wg, gpointer data) selecttexture (GtkWidget * wg, gpointer data)
{ {
texture *t; texture *t;
gint n = GPOINTER_TO_INT (data); gint n = GPOINTER_TO_INT (data);
if (noupdate) if (noupdate)
return; return;
t = currenttexture (); t = currenttexture ();
@ -2284,7 +2306,8 @@ static void
selecttype (GtkWidget * wg, gpointer data) selecttype (GtkWidget * wg, gpointer data)
{ {
texture *t; texture *t;
gint n = GPOINTER_TO_INT (data); gint n = GPOINTER_TO_INT (data);
if (noupdate) if (noupdate)
return; return;
t = currenttexture (); t = currenttexture ();
@ -2296,10 +2319,12 @@ selecttype (GtkWidget * wg, gpointer data)
} }
static void static void
getscales (GtkWidget * wg, gpointer data) getscales (GtkWidget *widget,
gpointer data)
{ {
gdouble f; gdouble f;
texture *t; texture *t;
if (noupdate) if (noupdate)
return; return;
t = currenttexture (); t = currenttexture ();
@ -2325,9 +2350,9 @@ getscales (GtkWidget * wg, gpointer data)
} }
static void static void
mktexturemenu (GtkWidget * texturemenu_menu) mktexturemenu (GtkWidget *texturemenu_menu)
{ {
GtkWidget *item; GtkWidget *item;
struct textures_t *t; struct textures_t *t;
t = textures; t = textures;
@ -2365,9 +2390,10 @@ color2_changed (GimpColorButton *button,
} }
static void static void
drawcolor1 (GtkWidget * w) drawcolor1 (GtkWidget *w)
{ {
static GtkWidget *lastw = NULL; static GtkWidget *lastw = NULL;
texture *t = currenttexture (); texture *t = currenttexture ();
if (w) if (w)
@ -2384,9 +2410,10 @@ drawcolor1 (GtkWidget * w)
} }
static void static void
drawcolor2 (GtkWidget * w) drawcolor2 (GtkWidget *w)
{ {
static GtkWidget *lastw = NULL; static GtkWidget *lastw = NULL;
texture *t = currenttexture (); texture *t = currenttexture ();
if (w) if (w)
@ -2406,7 +2433,8 @@ drawcolor2 (GtkWidget * w)
static gboolean do_run = FALSE; static gboolean do_run = FALSE;
static void static void
sphere_ok (GtkWidget * widget, gpointer data) sphere_ok (GtkWidget *widget,
gpointer data)
{ {
running = -1; running = -1;
do_run = TRUE; do_run = TRUE;
@ -2415,7 +2443,8 @@ sphere_ok (GtkWidget * widget, gpointer data)
} }
static void static void
sphere_cancel (GtkWidget * widget, gpointer data) sphere_cancel (GtkWidget *widget,
gpointer data)
{ {
gtk_widget_hide (GTK_WIDGET (data)); gtk_widget_hide (GTK_WIDGET (data));
gtk_main_quit (); gtk_main_quit ();
@ -2441,12 +2470,19 @@ makewindow (void)
window = gimp_dialog_new (_("Sphere Designer"), "spheredesigner", window = gimp_dialog_new (_("Sphere Designer"), "spheredesigner",
gimp_standard_help_func, gimp_standard_help_func,
"filters/spheredesigner.html", GTK_WIN_POS_MOUSE, "filters/spheredesigner.html",
FALSE, TRUE, FALSE, GIMP_STOCK_RESET, GTK_WIN_POS_MOUSE, FALSE, TRUE, FALSE,
sphere_reset, NULL, NULL, NULL, FALSE, FALSE,
GTK_STOCK_CANCEL, sphere_cancel, NULL, NULL, NULL, GIMP_STOCK_RESET,
FALSE, TRUE, GTK_STOCK_OK, sphere_ok, NULL, NULL, sphere_reset, NULL, NULL, NULL, FALSE, FALSE,
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); table = gtk_table_new (3, 3, FALSE);
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (window)->vbox), table); 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); gimp_pixel_rgn_get_row (&pr, ibuffer, x1, y1 + y, x2 - x1);
for (x = 0; x < (x2 - x1); x++) for (x = 0; x < (x2 - x1); x++)
{ {
int k, dx = x * 4, sx = x * bpp; gint k, dx = x * 4, sx = x * bpp;
float a = buffer[dx + 3] / 255.0; gfloat a = buffer[dx + 3] / 255.0;
for (k = 0; k < bpp; k++) for (k = 0; k < bpp; k++)
{ {
ibuffer[sx + k] = ibuffer[sx + k] =
@ -3025,7 +3062,7 @@ realrender (GimpDrawable * drawable)
} }
} }
gimp_pixel_rgn_set_row (&dpr, ibuffer, x1, y1 + y, x2 - x1); 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 (buffer);
g_free (ibuffer); g_free (ibuffer);