Exemple #1
0
/**
 * Instantiate a downloader
 *
 * @v job		Job control interface
 * @v image		Image to fill with downloaded file
 * @v type		Location type to pass to xfer_open()
 * @v ...		Remaining arguments to pass to xfer_open()
 * @ret rc		Return status code
 *
 * Instantiates a downloader object to download the specified URI into
 * the specified image object.
 */
int create_downloader ( struct interface *job, struct image *image,
			int type, ... ) {
	struct downloader *downloader;
	va_list args;
	int rc;

	/* Allocate and initialise structure */
	downloader = zalloc ( sizeof ( *downloader ) );
	if ( ! downloader )
		return -ENOMEM;
	ref_init ( &downloader->refcnt, downloader_free );
	intf_init ( &downloader->job, &downloader_job_desc,
		    &downloader->refcnt );
	intf_init ( &downloader->xfer, &downloader_xfer_desc,
		    &downloader->refcnt );
	downloader->image = image_get ( image );
	va_start ( args, type );

	/* Instantiate child objects and attach to our interfaces */
	if ( ( rc = xfer_vopen ( &downloader->xfer, type, args ) ) != 0 )
		goto err;

	/* Attach parent interface, mortalise self, and return */
	intf_plug_plug ( &downloader->job, job );
	ref_put ( &downloader->refcnt );
	va_end ( args );
	return 0;

 err:
	downloader_finished ( downloader, rc );
	ref_put ( &downloader->refcnt );
	va_end ( args );
	return rc;
}
Exemple #2
0
/**Capture an image, standardize and binarize it, and write it to a file*/
void image_save_binarized(char* filename){
    struct fp_img* img = image_get();
    fp_img_standardize(img);
    struct fp_img* img_binarized = fp_img_binarize(img);
    image_writefile(img_binarized, filename);
    fp_img_free(img); //free it
    fp_img_free(img_binarized);
}
Exemple #3
0
void image_map(image* i, vec4(*f)(vec4)) {
  for (int x = 0; x < i->width; x++)
  for (int y = 0; y < i->height; y++) {
    image_set(i, x, y, f(image_get(i, x, y)));
  }
}
Exemple #4
0
/**Capture an image, standardize it, and write it to a file*/
void image_save(char* filename){
    struct fp_img* img = image_get();
    fp_img_standardize(img);
    image_writefile(img, filename);
    fp_img_free(img); //free it
}