+ struct state *st = (struct state *) closure;
+ int this_delay = st->delay;
+ int qwad;
+
+ if (st->img_loader) /* still loading */
+ {
+ st->img_loader = load_image_async_simple (st->img_loader, 0, 0, 0, 0, 0);
+
+ if (!st->img_loader) { /* just finished */
+ st->first_time = 0;
+ st->loaded_p = True;
+ st->qwad = -1;
+ st->start_time = time ((time_t) 0);
+ blitspin_init_2 (st);
+ }
+
+ /* Rotate nothing if the very first image is not yet loaded */
+ if (! st->loaded_p)
+ return this_delay;
+ }
+
+ if (!st->img_loader &&
+ st->load_ext_p &&
+ st->start_time + st->duration < time ((time_t) 0)) {
+ /* Start a new image loading, but keep rotating the old image
+ until the new one arrives. */
+ st->img_loader = load_image_async_simple (0, st->xgwa.screen, st->window,
+ st->bitmap, 0, 0);
+ }
+
+ if (st->qwad == -1)
+ {
+ bitblt(st, st->mask, st->mask, clear,0,0, st->size, st->size, 0,0);
+ bitblt(st, st->mask, st->mask, set, 0,0, st->size>>1, st->size>>1, 0,0);
+ st->qwad = st->size>>1;
+ }
+
+ if (st->first_time)
+ {
+ st->first_time = 0;
+ display (st, st->self);
+ return st->delay2;
+ }
+
+ /* for (st->qwad = st->size>>1; st->qwad > 0; st->qwad>>=1) */
+
+ qwad = st->qwad;
+
+ copy_to (mask, 0, 0, temp, copy); /* 1 */
+ copy_to (mask, 0, qwad, temp, or); /* 2 */
+ copy_to (self, 0, 0, temp, and); /* 3 */
+ copy_to (temp, 0, 0, self, xor); /* 4 */
+ copy_from (temp, qwad, 0, self, xor); /* 5 */
+ copy_from (self, qwad, 0, self, or); /* 6 */
+ copy_to (temp, qwad, 0, self, xor); /* 7 */
+ copy_to (self, 0, 0, temp, copy); /* 8 */
+ copy_from (temp, qwad, qwad, self, xor); /* 9 */
+ copy_to (mask, 0, 0, temp, and); /* A */
+ copy_to (temp, 0, 0, self, xor); /* B */
+ copy_to (temp, qwad, qwad, self, xor); /* C */
+ copy_from (mask, qwad>>1, qwad>>1, mask, and); /* D */
+ copy_to (mask, qwad, 0, mask, or); /* E */
+ copy_to (mask, 0, qwad, mask, or); /* F */
+ display (st, st->self);
+
+ st->qwad >>= 1;
+ if (st->qwad == 0) /* done with this round */
+ {
+ st->qwad = -1;
+ this_delay = st->delay2;
+ }
+
+ return this_delay;
+}
+
+
+static int
+to_pow2(struct state *st, int n, Bool up)
+{
+ int powers_of_2[] = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024,
+ 2048, 4096, 8192, 16384, 32768, 65536 };
+ int i = 0;
+ if (n > 65536) st->size = 65536;
+ while (n >= powers_of_2[i]) i++;
+ if (n == powers_of_2[i-1])
+ return n;
+ else
+ return powers_of_2[up ? i : i-1];
+}
+
+static void *
+blitspin_init (Display *d_arg, Window w_arg)
+{
+ struct state *st = (struct state *) calloc (1, sizeof(*st));