-/* tessellimage, Copyright (c) 2014 Jamie Zawinski <jwz@jwz.org>
+/* tessellimage, Copyright (c) 2014-2018 Jamie Zawinski <jwz@jwz.org>
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
#undef DO_VORONOI
-#ifndef HAVE_COCOA
+#ifndef HAVE_JWXYZ
# define XK_MISCELLANY
# include <X11/keysymdef.h>
#endif
int delay;
Bool outline_p, cache_p, fill_p;
double duration, duration2;
- int max_depth;
+ int max_depth, max_resolution;
double start_time, start_time2;
XImage *img, *delta;
tessellimage_init (Display *dpy, Window window)
{
struct state *st = (struct state *) calloc (1, sizeof(*st));
- Colormap cmap;
st->dpy = dpy;
st->window = window;
XGetWindowAttributes (st->dpy, st->window, &st->xgwa);
- cmap = st->xgwa.colormap;
st->delay = get_integer_resource (st->dpy, "delay", "Integer");
if (st->delay < 1) st->delay = 1;
st->max_depth = get_integer_resource (st->dpy, "maxDepth", "MaxDepth");
if (st->max_depth < 100) st->max_depth = 100;
+ st->max_resolution = get_integer_resource (st->dpy,
+ "maxResolution", "MaxResolution");
+ if (st->max_resolution < 0) st->max_resolution = 0;
+
st->duration = get_float_resource (st->dpy, "duration", "Seconds");
if (st->duration < 1) st->duration = 1;
static unsigned long
-pixel_distance (Visual *v, unsigned long p1, unsigned long p2)
+pixel_distance (Screen *s, Visual *v, unsigned long p1, unsigned long p2)
{
static int initted_p = 0;
- static unsigned int rmsk=0, gmsk=0, bmsk=0;
+ static unsigned long rmsk=0, gmsk=0, bmsk=0;
static unsigned int rpos=0, gpos=0, bpos=0;
static unsigned int rsiz=0, gsiz=0, bsiz=0;
if (!p1 && !p2) return 0;
if (! initted_p) {
- rmsk = v->red_mask;
- gmsk = v->green_mask;
- bmsk = v->blue_mask;
+ visual_rgb_masks (s, v, &rmsk, &gmsk, &bmsk);
decode_mask (rmsk, &rpos, &rsiz);
decode_mask (gmsk, &gpos, &gsiz);
decode_mask (bmsk, &bpos, &bsiz);
pixels[i++] = (x > 0 && y < h-1 ? XGetPixel (st->img, x-1, y+1) : 0);
for (i = 1; i < countof(pixels); i++)
- distance += pixel_distance (st->xgwa.visual, pixels[0], pixels[i]);
+ distance += pixel_distance (st->xgwa.screen, st->xgwa.visual,
+ pixels[0], pixels[i]);
distance /= countof(pixels)-1;
XPutPixel (st->delta, x, y, distance);
}
st->pgc = XCreateGC(st->dpy, st->image, GCFunction, &gcv);
}
+ if (! st->nthreshes) return;
+
+
/* If duration2 has expired, switch to the next threshold. */
if (! st->button_down_p)
XCopyArea (st->dpy,
st->cache[st->thresh],
st->output, st->pgc,
- 0, 0, st->delta->width, st->delta->height,
+ 0, 0, st->xgwa.width, st->xgwa.height,
0, 0);
}
else if (ticked_p)
int nv = 0;
int ntri = 0;
int x, y, i;
+ double wscale = st->xgwa.width / (double) st->delta->width;
#if 0
fprintf(stderr, "%s: thresh %d/%d = %d=%d\n",
if (st->output)
XFreePixmap (st->dpy, st->output);
st->output = XCreatePixmap (st->dpy, st->window,
- st->delta->width, st->delta->height,
+ st->xgwa.width, st->xgwa.height,
st->xgwa.depth);
XFillRectangle (st->dpy, st->output, st->pgc,
- 0, 0, st->delta->width, st->delta->height);
+ 0, 0, st->xgwa.width, st->xgwa.height);
#ifdef DO_VORONOI
{
XPoint xp[3];
unsigned long color;
- xp[0].x = p[v[i].p1].x; xp[0].y = p[v[i].p1].y;
- xp[1].x = p[v[i].p2].x; xp[1].y = p[v[i].p2].y;
- xp[2].x = p[v[i].p3].x; xp[2].y = p[v[i].p3].y;
+ xp[0].x = p[v[i].p1].x * wscale; xp[0].y = p[v[i].p1].y * wscale;
+ xp[1].x = p[v[i].p2].x * wscale; xp[1].y = p[v[i].p2].y * wscale;
+ xp[2].x = p[v[i].p3].x * wscale; xp[2].y = p[v[i].p3].y * wscale;
/* Set the color of this triangle to the pixel at its midpoint. */
color = XGetPixel (st->img,
- (xp[0].x + xp[1].x + xp[2].x) / 3,
- (xp[0].y + xp[1].y + xp[2].y) / 3);
+ (xp[0].x + xp[1].x + xp[2].x) / (3 * wscale),
+ (xp[0].y + xp[1].y + xp[2].y) / (3 * wscale));
XSetForeground (st->dpy, st->pgc, color);
XFillPolygon (st->dpy, st->output, st->pgc, xp, countof(xp),
{
st->cache[st->thresh] =
XCreatePixmap (st->dpy, st->window,
- st->delta->width, st->delta->height,
+ st->xgwa.width, st->xgwa.height,
st->xgwa.depth);
if (! st->cache[st->thresh])
{
st->output,
st->cache[st->thresh],
st->pgc,
- 0, 0, st->delta->width, st->delta->height,
+ 0, 0, st->xgwa.width, st->xgwa.height,
0, 0);
}
}
get_deltap (struct state *st)
{
int x, y;
- int w = st->delta->width;
- int h = st->delta->height;
+ int w = st->xgwa.width;
+ int h = st->xgwa.height;
+ double wscale = st->xgwa.width / (double) st->delta->width;
XImage *dimg;
Visual *v = st->xgwa.visual;
- unsigned int rmsk=0, gmsk=0, bmsk=0;
+ unsigned long rmsk=0, gmsk=0, bmsk=0;
unsigned int rpos=0, gpos=0, bpos=0;
unsigned int rsiz=0, gsiz=0, bsiz=0;
if (st->deltap) return st->deltap;
- rmsk = v->red_mask;
- gmsk = v->green_mask;
- bmsk = v->blue_mask;
+ visual_rgb_masks (st->xgwa.screen, v, &rmsk, &gmsk, &bmsk);
decode_mask (rmsk, &rpos, &rsiz);
decode_mask (gmsk, &gpos, &gsiz);
decode_mask (bmsk, &bpos, &bsiz);
for (y = 0; y < h; y++)
for (x = 0; x < w; x++)
{
- unsigned long v = XGetPixel (st->delta, x, y) << 5;
+ unsigned long v = XGetPixel (st->delta, x / wscale, y / wscale) << 5;
unsigned long p = (((v << rpos) & rmsk) |
((v << gpos) & gmsk) |
((v << bpos) & bmsk));
if (!st->img_loader &&
st->start_time + st->duration < double_time()) {
+ int w = st->xgwa.width;
+ int h = st->xgwa.height;
+
+ /* Analysing a full-resolution image on a Retina display is too slow,
+ so scale down the source at image-load time. */
+ if (st->max_resolution > 10)
+ {
+ if (w > h && w > st->max_resolution)
+ h = st->max_resolution * h / w, w = st->max_resolution;
+ else if (h > st->max_resolution)
+ w = st->max_resolution * w / h, h = st->max_resolution;
+ }
+ /* fprintf(stderr,"%s: loading %d x %d\n", progname, w, h); */
+
XClearWindow (st->dpy, st->window);
if (st->image) XFreePixmap (dpy, st->image);
- st->image = XCreatePixmap (st->dpy, st->window,
- st->xgwa.width, st->xgwa.height,
- st->xgwa.depth);
+ st->image = XCreatePixmap (st->dpy, st->window, w, h, st->xgwa.depth);
st->img_loader = load_image_async_simple (0, st->xgwa.screen, st->window,
st->image, 0, &st->geom);
goto DONE;
XCopyArea (st->dpy,
(st->button_down_p ? get_deltap (st) : st->output),
st->window, st->wgc,
- 0, 0, st->delta->width, st->delta->height,
- (st->xgwa.width - st->delta->width) / 2,
- (st->xgwa.height - st->delta->height) / 2);
+ 0, 0, st->xgwa.width, st->xgwa.height, 0, 0);
+ else if (!st->nthreshes)
+ XCopyArea (st->dpy,
+ st->image,
+ st->window, st->wgc,
+ 0, 0, st->xgwa.width, st->xgwa.height, 0, 0);
+
DONE:
return st->delay;
st->button_down_p = False;
return True;
}
- else if (event->xany.type == KeyPress)
+ else if (screenhack_event_helper (dpy, window, event))
{
- KeySym keysym = 0;
- char c = 0;
- if (event->xany.type == KeyPress || event->xany.type == KeyRelease)
- XLookupString (&event->xkey, &c, 1, &keysym, 0);
-
- switch (keysym) {
- case XK_Left:
- case XK_Right:
- case XK_Down:
- case XK_Up:
- st->start_time = 0; /* load next image */
- return True;
- }
-
- switch (c) {
- case '\r':
- case '\n':
- case '+':
- case '=':
- st->start_time = 0;
- return True;
- }
+ st->start_time = 0; /* load next image */
+ return True;
}
return False;
static const char *tessellimage_defaults [] = {
".background: black",
".foreground: white",
+ ".lowrez: True",
"*dontClearRoot: True",
"*fpsSolid: true",
"*delay: 30000",
"*duration: 120",
"*duration2: 0.4",
"*maxDepth: 30000",
+ "*maxResolution: 1024",
"*outline: True",
"*fillScreen: True",
"*cache: True",
-#ifdef USE_IPHONE
+#ifdef HAVE_MOBILE
"*ignoreRotation: True",
+ "*rotateImages: True",
#endif
0
};
{ "-duration", ".duration", XrmoptionSepArg, 0 },
{ "-duration2", ".duration2", XrmoptionSepArg, 0 },
{ "-max-depth", ".maxDepth", XrmoptionSepArg, 0 },
+ { "-max-resolution", ".maxResolution", XrmoptionSepArg, 0 },
{ "-outline", ".outline", XrmoptionNoArg, "True" },
{ "-no-outline", ".outline", XrmoptionNoArg, "False" },
{ "-fill-screen", ".fillScreen", XrmoptionNoArg, "True" },