mirror of
git://projects.qi-hardware.com/ben-scans.git
synced 2024-11-22 09:30:38 +02:00
Some simple optimizations increase drawing speed in overlap by 33%.
- solidify/overlap.c (overlap): added speed testing loop - solidify/overlap.c (zmix): instead of floor/ceil, we just use floor/floor+1. With the ramp() change below, an 18% speed increase results - solidify/overlap.c (ramp): after the above change, w0 and w1 can never be zero, so we don't have to test for this case - solidify/array.h (get_bounded), solidify/array.c: inline get_bounded(), yielding a 13% speed increase
This commit is contained in:
parent
2764155d15
commit
d4a5575599
@ -83,13 +83,3 @@ void set(struct array *a, int x, int y, int z)
|
|||||||
a->data[x-a->min_x+(a->max_x-a->min_x+1)*(y-a->min_y)] = z;
|
a->data[x-a->min_x+(a->max_x-a->min_x+1)*(y-a->min_y)] = z;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int get_bounded(const struct array *a, int x, int y)
|
|
||||||
{
|
|
||||||
if (x < a->min_x || x > a->max_x)
|
|
||||||
return UNDEF;
|
|
||||||
if (y < a->min_y || y > a->max_y)
|
|
||||||
return UNDEF;
|
|
||||||
return get(a, x, y);
|
|
||||||
}
|
|
||||||
|
@ -31,7 +31,6 @@ struct array *new_array(void);
|
|||||||
void free_array(struct array *a);
|
void free_array(struct array *a);
|
||||||
|
|
||||||
void set(struct array *a, int x, int y, int z);
|
void set(struct array *a, int x, int y, int z);
|
||||||
int get_bounded(const struct array *a, int x, int y);
|
|
||||||
|
|
||||||
|
|
||||||
static inline int get(const struct array *a, int x, int y)
|
static inline int get(const struct array *a, int x, int y)
|
||||||
@ -39,4 +38,15 @@ static inline int get(const struct array *a, int x, int y)
|
|||||||
return a->data[(x)-a->min_x+(a->max_x-a->min_x+1)*((y)-a->min_y)];
|
return a->data[(x)-a->min_x+(a->max_x-a->min_x+1)*((y)-a->min_y)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static inline int get_bounded(const struct array *a, int x, int y)
|
||||||
|
{
|
||||||
|
if (x < a->min_x || x > a->max_x)
|
||||||
|
return UNDEF;
|
||||||
|
if (y < a->min_y || y > a->max_y)
|
||||||
|
return UNDEF;
|
||||||
|
return get(a, x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif /* ARRAY_H */
|
#endif /* ARRAY_H */
|
||||||
|
@ -51,7 +51,7 @@ static double r_center(const struct solid *s)
|
|||||||
static double ramp(int z0, double w0, int z1, double w1)
|
static double ramp(int z0, double w0, int z1, double w1)
|
||||||
{
|
{
|
||||||
if (z0 != UNDEF && z1 != UNDEF)
|
if (z0 != UNDEF && z1 != UNDEF)
|
||||||
return w0 == 0 && w1 == 0 ? z0 : z0*w0+z1*w1;
|
return z0*w0+z1*w1;
|
||||||
if (z0 == UNDEF && z0 == UNDEF)
|
if (z0 == UNDEF && z0 == UNDEF)
|
||||||
return UNDEF_F;
|
return UNDEF_F;
|
||||||
if (z0 == UNDEF && w0 < w1)
|
if (z0 == UNDEF && w0 < w1)
|
||||||
@ -68,9 +68,9 @@ static double zmix(struct face *f, double x, double y)
|
|||||||
double zx0, zx1;
|
double zx0, zx1;
|
||||||
|
|
||||||
xa = floor(x);
|
xa = floor(x);
|
||||||
xb = ceil(x);
|
xb = xa+1;
|
||||||
ya = floor(y);
|
ya = floor(y);
|
||||||
yb = ceil(y);
|
yb = ya+1;
|
||||||
|
|
||||||
zx0 = ramp(
|
zx0 = ramp(
|
||||||
get_bounded(f->a, xa, ya), yb-y,
|
get_bounded(f->a, xa, ya), yb-y,
|
||||||
@ -456,4 +456,17 @@ void overlap(GtkWidget *canvas, struct solid *s)
|
|||||||
g_signal_connect(G_OBJECT(darea), "motion-notify-event",
|
g_signal_connect(G_OBJECT(darea), "motion-notify-event",
|
||||||
G_CALLBACK(motion_notify_event), s);
|
G_CALLBACK(motion_notify_event), s);
|
||||||
|
|
||||||
|
if (0) {
|
||||||
|
int i;
|
||||||
|
long t0 = time(NULL);
|
||||||
|
gtk_widget_show_all(canvas);
|
||||||
|
for (i = 0; i != 1000; i++) {
|
||||||
|
rotate(&s->a->m, 100);
|
||||||
|
draw_image(darea, s, 0);
|
||||||
|
while (gtk_events_pending())
|
||||||
|
gtk_main_iteration();
|
||||||
|
}
|
||||||
|
fprintf(stderr, "%lu\n", time(NULL)-t0);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user