static void osx_load_image_file_async (Screen *screen, Window xwindow, Drawable drawable, const char *dir, void (*callback) (Screen *, Window, Drawable, const char *name, XRectangle *geom, void *closure), void *closure) { # if 0 /* do it synchronously */ FILE *pipe = open_image_name_pipe (dir); char buf[10240]; *buf = 0; fgets (buf, sizeof(buf)-1, pipe); pclose (pipe); /* strip trailing newline */ int L = strlen(buf); while (L > 0 && (buf[L-1] == '\r' || buf[L-1] == '\n')) buf[--L] = 0; XRectangle geom; if (! osx_load_image_file (screen, xwindow, drawable, buf, &geom)) { /* draw colorbars */ abort(); } callback (screen, xwindow, drawable, buf, &geom, closure); # else /* do it asynchronously */ struct pipe_closure *clo2 = (struct pipe_closure *) calloc (1, sizeof(*clo2)); clo2->screen = screen; clo2->xwindow = xwindow; clo2->drawable = drawable; clo2->callback = callback; clo2->closure = closure; # ifndef USE_IPHONE clo2->directory = strdup (dir); clo2->pipe = open_image_name_pipe (dir); clo2->id = XtAppAddInput (XtDisplayToApplicationContext ( DisplayOfScreen (screen)), fileno (clo2->pipe), (XtPointer) (XtInputReadMask | XtInputExceptMask), pipe_cb, (XtPointer) clo2); # else /* USE_IPHONE */ ios_load_random_image (ios_load_random_image_cb, clo2); # endif /* USE_IPHONE */ # endif }
static void osx_load_image_file_async (Screen *screen, Window xwindow, Drawable drawable, const char *dir, void (*callback) (Screen *, Window, Drawable, const char *name, XRectangle *geom, void *closure), void *closure) { xscreensaver_getimage_data *clo2 = (xscreensaver_getimage_data *) calloc (1, sizeof(*clo2)); clo2->screen = screen; clo2->window = xwindow; clo2->drawable = drawable; clo2->callback = callback; clo2->closure = closure; # ifndef USE_IPHONE /* Desktop OSX */ clo2->directory = strdup (dir); clo2->pipe = open_image_name_pipe (dir); clo2->pipe_id = XtAppAddInput (XtDisplayToApplicationContext ( DisplayOfScreen (screen)), fileno (clo2->pipe), (XtPointer) (XtInputReadMask | XtInputExceptMask), xscreensaver_getimage_file_cb, (XtPointer) clo2); # else /* USE_IPHONE */ ios_load_random_image (ios_load_random_image_cb, clo2); # endif /* USE_IPHONE */ }
static unsigned long glitchpeg_draw (Display *dpy, Window window, void *closure) { struct state *st = (struct state *) closure; if ((!st->image_data || time((time_t *) 0) >= st->start_time + st->duration) && !st->pipe) { /* Time to reload */ st->pipe = open_image_name_pipe(); st->pipe_id = XtAppAddInput (XtDisplayToApplicationContext (dpy), fileno (st->pipe), (XtPointer) (XtInputReadMask | XtInputExceptMask), xscreensaver_getimage_file_cb, (XtPointer) st); } if (st->image_data && !st->button_down_p) { int n; XImage *image; unsigned char *glitched = malloc (st->image_size); int nn = random() % st->count; if (nn <= 0) nn = 1; memcpy (glitched, st->image_data, st->image_size); for (n = 0; n < nn; n++) { int start = 255; int end = st->image_size - 255; int size = end - start; Bool byte_p = True; /* random() % 100; */ if (size <= 100) break; if (byte_p) { int i = start + (random() % size); if (!(random() % 10)) /* Take one random byte and randomize it. */ glitched[i] = random() % 0xFF; else /* Take one random byte and add 5% to it. */ glitched[i] += (1 + (random() % 0x0C)) * ((random() & 1) ? 1 : -1); } else { /* Take two randomly-sized chunks of the file and swap them. This tends to just destroy the image. Doesn't look good. */ int s2 = 2 + size * 0.05; char *swap = malloc (s2); int start1 = start + (random() % (size - s2)); int start2 = start + (random() % (size - s2)); memcpy (glitched + start1, swap, s2); memmove (glitched + start2, glitched + start1, s2); memcpy (swap, glitched + start2, s2); free (swap); } } image = image_data_to_ximage (dpy, st->xgwa.visual, glitched, st->image_size); free (glitched); if (image) /* Might be null if decode fails */ { draw_image (dpy, window, st->xgwa.visual, st->gc, st->xgwa.width, st->xgwa.height, st->xgwa.depth, image); XDestroyImage (image); } } return st->delay; }