Пример #1
0
/*
 * Notify callback function for `button1'.
 */
void
go_func(Panel_item item, Event *event)
{
	int i;
	int ht,wd;
	time_t now = time(0) - (time(0) % 86400);

	static ImlibData *imdata = NULL;
	ImlibImage *image;
	FILE *outfile = NULL;
	char pathname[1024];

	cclock_window1_objects *ip = (cclock_window1_objects *) xv_get(item, XV_KEY_DATA, INSTANCE);

	ht = xv_get(Cclock_window1->canvas1,XV_HEIGHT);
	wd = xv_get(Cclock_window1->canvas1,XV_WIDTH);

	if( imdata == NULL) imdata = Imlib_init(dpy);

	for(i=0; i < 720; i++) {


	    XFillRectangle(dpy,can_xid,b_gc,0,0,wd,ht);
	    XUDRdraw_clock(dpy,can_xid,w_gc,(wd/2),(ht/2),(ht/2)-2,now + (i * 60),0);
		XFlush(dpy);

		sprintf(pathname,"CLK_%03d.png",i);
		  image =  Imlib_create_image_from_drawable (imdata, can_xid, can_xid, 0, 0, wd, ht);
		 Imlib_save_image (imdata, image, pathname, NULL);
		 Imlib_destroy_image (imdata, image);

		/* 
		usleep(100000);
		 */
	}
}
Пример #2
0
static int __doSaveImage(Image *image, char *filename, CSOUND *csound)
{
#ifdef USE_LIBPNG

    png_structp png_ptr;
    png_infop info_ptr;
    png_bytepp row_pointers;
    unsigned rowbytes;
    int i;

    FILE *fp;
    void *fd;

    fd = csound->FileOpen2(csound, &fp, CSFILE_STD, filename, "wb",
                           "", CSFTYPE_IMAGE_PNG, 0);
    if (UNLIKELY(fd == NULL)) {
      return
        csound->InitError(csound,
                          Str("imageload: cannot open image %s for writing.\n"),
                          filename);
    }

    png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);

    if (UNLIKELY(!png_ptr)){
      csound->FileClose(csound, fd);
      return csound->InitError(csound, Str("imageload: out of memory.\n"));
    }

    info_ptr = png_create_info_struct(png_ptr);
    if (UNLIKELY(!info_ptr)) {
      png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
      csound->FileClose(csound, fd);
      return csound->InitError(csound, Str("imageload: out of memory.\n"));
    }

    png_init_io(png_ptr, fp);
    png_set_IHDR(png_ptr, info_ptr, image->w, image->h,
                 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE,
                 PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);

    png_write_info(png_ptr, info_ptr);

    row_pointers = (png_bytepp)malloc(image->h*sizeof(png_bytep));
    if (UNLIKELY(row_pointers == NULL)) {
      png_destroy_write_struct(&png_ptr, &info_ptr);
      return csound->InitError(csound, Str("imageload: out of memory.\n"));
    }

    rowbytes = png_get_rowbytes(png_ptr, info_ptr);

    for (i = 0; i < image->h; i++)
      row_pointers[i] = image->imageData + i*rowbytes;

    png_write_image(png_ptr, row_pointers);
    png_write_end(png_ptr, info_ptr);

    free(row_pointers);
    png_destroy_write_struct(&png_ptr, &info_ptr);
    csound->FileClose(csound, fd);

    return OK;
#else
    Display *disp;
    ImlibData *id;
    ImlibImage *im;

    disp=XOpenDisplay(NULL);
    id=Imlib_init(disp);

    im = Imlib_create_image_from_data(id, image->imageData,
                                      NULL, image->w, image->h);
    Imlib_save_image(id, im, filename, NULL);
    Imlib_kill_image(id, im);

    return OK;
#endif
}