Date:2010-09-24 22:56:55 (8 years 8 months ago)
Author:Werner Almesberger
Commit:d4a5575599a675f344c09d94e42d0eb6c21629d6
Message: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
Files: solidify/array.c (1 diff)
solidify/array.h (2 diffs)
solidify/overlap.c (3 diffs)

Change Details

solidify/array.c
8383        a->data[x-a->min_x+(a->max_x-a->min_x+1)*(y-a->min_y)] = z;
8484    }
8585}
86
87
88int get_bounded(const struct array *a, int x, int y)
89{
90    if (x < a->min_x || x > a->max_x)
91        return UNDEF;
92    if (y < a->min_y || y > a->max_y)
93        return UNDEF;
94    return get(a, x, y);
95}
solidify/array.h
3131void free_array(struct array *a);
3232
3333void set(struct array *a, int x, int y, int z);
34int get_bounded(const struct array *a, int x, int y);
3534
3635
3736static inline int get(const struct array *a, int x, int y)
...... 
3938    return a->data[(x)-a->min_x+(a->max_x-a->min_x+1)*((y)-a->min_y)];
4039}
4140
41
42static inline int get_bounded(const struct array *a, int x, int y)
43{
44    if (x < a->min_x || x > a->max_x)
45        return UNDEF;
46    if (y < a->min_y || y > a->max_y)
47        return UNDEF;
48    return get(a, x, y);
49}
50
51
4252#endif /* ARRAY_H */
solidify/overlap.c
5151static double ramp(int z0, double w0, int z1, double w1)
5252{
5353    if (z0 != UNDEF && z1 != UNDEF)
54        return w0 == 0 && w1 == 0 ? z0 : z0*w0+z1*w1;
54        return z0*w0+z1*w1;
5555    if (z0 == UNDEF && z0 == UNDEF)
5656        return UNDEF_F;
5757    if (z0 == UNDEF && w0 < w1)
...... 
6868    double zx0, zx1;
6969
7070    xa = floor(x);
71    xb = ceil(x);
71    xb = xa+1;
7272    ya = floor(y);
73    yb = ceil(y);
73    yb = ya+1;
7474
7575    zx0 = ramp(
7676        get_bounded(f->a, xa, ya), yb-y,
...... 
456456    g_signal_connect(G_OBJECT(darea), "motion-notify-event",
457457        G_CALLBACK(motion_notify_event), s);
458458
459if (0) {
460int i;
461long t0 = time(NULL);
462gtk_widget_show_all(canvas);
463for (i = 0; i != 1000; i++) {
464    rotate(&s->a->m, 100);
465    draw_image(darea, s, 0);
466    while (gtk_events_pending())
467        gtk_main_iteration();
468}
469fprintf(stderr, "%lu\n", time(NULL)-t0);
470}
471
459472}

Archive Download the corresponding diff file

Branches:
master



interactive