Ejemplo n.º 1
0
static void
grabImage_done (struct state *st)
{
    XWindowAttributes xwa;
    XGetWindowAttributes (st->dpy, st->window, &xwa);

    st->start_time = time ((time_t *) 0);
    if (st->sourceImage) XDestroyImage (st->sourceImage);
    st->sourceImage = XGetImage (st->dpy, st->pm, 0, 0,
                                 st->windowWidth, st->windowHeight,
			     ~0L, ZPixmap);

    if (st->workImage) destroy_xshm_image (st->dpy, st->workImage,
                                           &st->shmInfo);

    st->workImage = create_xshm_image (st->dpy, xwa.visual, xwa.depth,
                                       ZPixmap, &st->shmInfo,
                                       st->windowWidth, st->windowHeight);
}
Ejemplo n.º 2
0
static unsigned long
moire_draw (Display *dpy, Window window, void *closure)
{
  struct state *st = (struct state *) closure;
  XGCValues gcv;
  int chunk_size = 20, ii;

  if (st->draw_y == 0) 
    {
      moire_init_1 (st);

      XGetWindowAttributes (st->dpy, st->window, &st->xgwa);

      st->draw_xo = (random() % st->xgwa.width)  - st->xgwa.width/2;
      st->draw_yo = (random() % st->xgwa.height) - st->xgwa.height/2;
      st->draw_factor = (random() % st->offset) + 1;

      st->depth = visual_depth(DefaultScreenOfDisplay(st->dpy), st->xgwa.visual);

# ifdef HAVE_XSHM_EXTENSION
      if (st->use_shm)
        {
          st->draw_image = create_xshm_image(st->dpy, st->xgwa.visual, 
                                             st->depth, ZPixmap, 0,
                                             &st->shm_info, st->xgwa.width, 1);
          if (!st->draw_image)
            st->use_shm = False;
        }
# endif /* HAVE_XSHM_EXTENSION */

      if (!st->draw_image)
        {
          st->draw_image = XCreateImage (st->dpy, st->xgwa.visual,
                                         st->depth, ZPixmap, 0,	    /* depth, format, offset */
                                         0, st->xgwa.width, 1, 8, 0); /* data, w, h, pad, bpl */
          st->draw_image->data = (char *) calloc(st->draw_image->height, st->draw_image->bytes_per_line);
        }
    }

  /* for (y = 0; y < st->xgwa.height; y++) */
  for (ii = 0; ii < chunk_size; ii++)
    {
      int x;
      for (x = 0; x < st->xgwa.width; x++)
	{
	  double xx = x + st->draw_xo;
	  double yy = st->draw_y + st->draw_yo;
	  double i = ((xx * xx) + (yy * yy)) / (double) st->draw_factor;
	  if (mono_p)
	    gcv.foreground = ((((long) i) & 1) ? st->fg_pixel : st->bg_pixel);
	  else
	    gcv.foreground = st->colors[((long) i) % st->ncolors].pixel;
	  XPutPixel (st->draw_image, x, 0, gcv.foreground);
	}

# ifdef HAVE_XSHM_EXTENSION
      if (st->use_shm)
	XShmPutImage(st->dpy, st->window, st->gc, st->draw_image, 0, 0, 0, st->draw_y, st->xgwa.width, 1, False);
      else
# endif /*  HAVE_XSHM_EXTENSION */
	XPutImage (st->dpy, st->window, st->gc, st->draw_image, 0, 0, 0, st->draw_y, st->xgwa.width, 1);

      st->draw_y++;
      if (st->draw_y >= st->xgwa.height)
        break;
    }


    if (st->draw_y >= st->xgwa.height)
      {
        st->draw_y = 0;

# ifdef HAVE_XSHM_EXTENSION
        if (!st->use_shm)
# endif /*  HAVE_XSHM_EXTENSION */
          if (st->draw_image->data)
            {
              free(st->draw_image->data);
              st->draw_image->data = 0;
            }

# ifdef HAVE_XSHM_EXTENSION
        if (st->use_shm)
          destroy_xshm_image (st->dpy, st->draw_image, &st->shm_info);
        else
# endif /*  HAVE_XSHM_EXTENSION */
          XDestroyImage (st->draw_image);
        st->draw_image = 0;

        return st->delay * 1000000;
      }

  return st->delay * 10000;
}
Ejemplo n.º 3
0
static void
distort_finish_loading (struct state *st)
{
    int i;

    st->start_time = time ((time_t *) 0);

    if (! st->pm) abort();
    XClearWindow (st->dpy, st->window);
    XCopyArea (st->dpy, st->pm, st->window, st->gc, 
               0, 0, st->xgwa.width, st->xgwa.height, 0, 0);
	st->orig_map = XGetImage(st->dpy, st->pm, 0, 0,
                             st->xgwa.width, st->xgwa.height,
                             ~0L, ZPixmap);
	st->buffer_map_cache = malloc(sizeof(unsigned long)*(2*st->radius+st->speed+2)*(2*st->radius+st->speed+2));

	if (st->buffer_map_cache == NULL) {
		perror("distort");
		exit(EXIT_FAILURE);
	}

	st->buffer_map = create_xshm_image(st->dpy, st->xgwa.visual, st->orig_map->depth,
	                                   ZPixmap, &st->shm_info,
	                                   2*st->radius + st->speed + 2,
	                                   2*st->radius + st->speed + 2);

	if ((st->buffer_map->byte_order == st->orig_map->byte_order)
			&& (st->buffer_map->depth == st->orig_map->depth)
			&& (st->buffer_map->format == ZPixmap)
			&& (st->orig_map->format == ZPixmap)
			&& !st->slow) {
		switch (st->orig_map->bits_per_pixel) {
			case 32:
				st->draw_routine = &fast_draw_32;
				st->bpp_size = sizeof(CARD32);
				break;
			case 16:
				st->draw_routine = &fast_draw_16;
				st->bpp_size = sizeof(CARD16);
				break;
			case 8:
				st->draw_routine = &fast_draw_8;
				st->bpp_size = sizeof(CARD8);
				break;
			default:
				st->draw_routine = &generic_draw;
				break;
		}
	} else {
		st->draw_routine = &generic_draw;
	}
	init_round_lense(st);

	for (i = 0; i < st->number; i++) {
		new_rnd_coo(st,i);
		if (st->number != 1)
			st->xy_coo[i].r = (i*st->radius)/(st->number-1); /* "randomize" initial */
		else
			 st->xy_coo[i].r = 0;
		st->xy_coo[i].r_change = st->speed + (i%2)*2*(-st->speed);	/* values a bit */
		st->xy_coo[i].xmove = st->speed + (i%2)*2*(-st->speed);
		st->xy_coo[i].ymove = st->speed + (i%2)*2*(-st->speed);
	}
}
Ejemplo n.º 4
0
static void inter_init(Display* dpy, Window win, struct inter_context* c) 
{
  XWindowAttributes xgwa;
  double H[3], S[3], V[3];
  int i;
  int mono;
  int gray;
  XGCValues val;
  unsigned long valmask = 0;
  Bool dbuf = get_boolean_resource (dpy, "doubleBuffer", "Boolean");

# ifdef HAVE_COCOA	/* Don't second-guess Quartz's double-buffering */
  dbuf = False;
# endif

  memset (c, 0, sizeof(*c));

  c->dpy = dpy;
  c->win = win;

  c->delay = get_integer_resource(dpy, "delay", "Integer");


  XGetWindowAttributes(c->dpy, c->win, &xgwa);
  c->w = xgwa.width;
  c->h = xgwa.height;
  c->cmap = xgwa.colormap;

#ifdef HAVE_XSHM_EXTENSION
  c->use_shm = get_boolean_resource(dpy, "useSHM", "Boolean");
#endif /*  HAVE_XSHM_EXTENSION */

  if (dbuf)
    {
#ifdef HAVE_DOUBLE_BUFFER_EXTENSION
      c->back_buf = xdbe_get_backbuffer (c->dpy, c->win, XdbeUndefined);
#endif /* HAVE_DOUBLE_BUFFER_EXTENSION */

#ifdef HAVE_DOUBLE_BUFFER_EXTENSION
      if (!c->back_buf)
#endif /* HAVE_DOUBLE_BUFFER_EXTENSION */
        c->pix_buf = XCreatePixmap (dpy, win, xgwa.width, xgwa.height,
                                    xgwa.depth);
    }

  val.function = GXcopy;
  c->copy_gc = XCreateGC(c->dpy, TARGET(c), GCFunction, &val);

  c->count = get_integer_resource(dpy, "count", "Integer");
  if(c->count < 1)
    c->count = 1;
  c->grid_size = get_integer_resource(dpy, "gridsize", "Integer");
  if(c->grid_size < 1)
    c->grid_size = 1;
  mono = get_boolean_resource(dpy, "mono", "Boolean");
  if(!mono) {
    c->colors = get_integer_resource(dpy, "ncolors", "Integer");
    if(c->colors < 2)
      c->colors = 2;
  }
  c->hue = get_integer_resource(dpy, "hue", "Float");
  while (c->hue < 0 || c->hue >= 360)
    c->hue = frand(360.0);
  c->speed = get_integer_resource(dpy, "speed", "Integer");
  c->shift = get_float_resource(dpy, "color-shift", "Float");
  while(c->shift >= 360.0)
    c->shift -= 360.0;
  while(c->shift <= -360.0)
    c->shift += 360.0;
  c->radius = get_integer_resource(dpy, "radius", "Integer");;
  if(c->radius < 1)
    c->radius = 1;

#ifdef USE_XIMAGE

  c->ximage = 0;

# ifdef HAVE_XSHM_EXTENSION
  if (c->use_shm)
    {
      c->ximage = create_xshm_image(dpy, xgwa.visual, xgwa.depth,
				    ZPixmap, 0, &c->shm_info,
				    xgwa.width, c->grid_size);
      if (!c->ximage)
	c->use_shm = False;
    }
# endif /* HAVE_XSHM_EXTENSION */

  if (!c->ximage)
    {
      c->ximage =
	XCreateImage (dpy, xgwa.visual,
		      xgwa.depth, ZPixmap, 0, 0, /* depth, fmt, offset, data */
		      xgwa.width, c->grid_size,	 /* width, height */
		      8, 0);			 /* pad, bpl */
      c->ximage->data = (unsigned char *)
	calloc(c->ximage->height, c->ximage->bytes_per_line);
    }
#endif /* USE_XIMAGE */

  if(!mono) {
    c->pal = calloc(c->colors, sizeof(XColor));

    gray = get_boolean_resource(dpy, "gray", "Boolean");
    if(!gray) {
      H[0] = c->hue;
      H[1] = H[0] + c->shift < 360.0 ? H[0]+c->shift : H[0] + c->shift-360.0; 
      H[2] = H[1] + c->shift < 360.0 ? H[1]+c->shift : H[1] + c->shift-360.0; 
      S[0] = S[1] = S[2] = 1.0;
      V[0] = V[1] = V[2] = 1.0;
    } else {
      H[0] = H[1] = H[2] = 0.0;
      S[0] = S[1] = S[2] = 0.0;
      V[0] = 1.0; V[1] = 0.5; V[2] = 0.0;
    }

    make_color_loop(c->dpy, c->cmap, 
		    H[0], S[0], V[0], 
		    H[1], S[1], V[1], 
		    H[2], S[2], V[2], 
		    c->pal, &(c->colors), 
		    True, False);
    if(c->colors < 2) { /* color allocation failure */
      mono = 1;
      free(c->pal);
    }
  }

  if(mono) { /* DON'T else this with the previous if! */
    c->colors = 2;
    c->pal = calloc(2, sizeof(XColor));
    c->pal[0].pixel = BlackPixel(c->dpy, DefaultScreen(c->dpy));
    c->pal[1].pixel = WhitePixel(c->dpy, DefaultScreen(c->dpy));
  }    

  valmask = GCForeground;
  c->gcs = calloc(c->colors, sizeof(GC));
  for(i = 0; i < c->colors; i++) {
    val.foreground = c->pal[i].pixel;    
    c->gcs[i] = XCreateGC(c->dpy, TARGET(c), valmask, &val);
  }

  c->wave_height = calloc(c->radius, sizeof(int));
  for(i = 0; i < c->radius; i++) {
    float max = 
      ((float)c->colors) * 
      ((float)c->radius - (float)i) /
      ((float)c->radius);
    c->wave_height[i] = 
      (int)
      ((max + max*cos((double)i/50.0)) / 2.0);
  }

  c->source = calloc(c->count, sizeof(struct inter_source));
  for(i = 0; i < c->count; i++) {
    c->source[i].x_theta = frand(2.0)*3.14159;
    c->source[i].y_theta = frand(2.0)*3.14159;
  }

}