Beispiel #1
0
void create_iio_file(char *filename, int w, int h, int spp)
{
	int n = w * h * spp;
	char *buf = xmalloc(n);
	memset(buf, 0, n);
	iio_save_image_uint8_vec(filename, buf, w, h, spp);
	free(buf);
}
Beispiel #2
0
// read an image in any format from STDIN and write a ppm to STDOUT
int main(int c, char *v[])
{
	int w, h, pixeldim;
	uint8_t *x = iio_read_image_uint8_vec("-", &w, &h, &pixeldim);
	fprintf(stderr, "got a %dx%d image with %d channels\n", w, h, pixeldim);
	iio_save_image_uint8_vec("-", x, w, h, pixeldim);
	free(x);
	return 0;
}
Beispiel #3
0
int main_pan(int c, char *v[])
{
	// process input arguments
	char *imask_option = pick_option(&c, &v, "m", "");
	if (c > 4) {
		fprintf(stderr, "usage:\n\t"
				"%s [in.fft [out.fft [out.mask]]]\n", *v);
		//                0  1       2        3
		return c;
	}
	char *filename_in   = c > 1 ? v[1] : "-";
	char *filename_out  = c > 2 ? v[2] : "-";
	char *filename_mask = c > 3 ? v[3] : NULL;
	char *filename_imask = *imask_option ? imask_option : NULL;


	// read image
	struct pan_state e[1];
	int pd;
	e->fft = (void*)iio_read_image_float_vec(filename_in, &e->w, &e->h,&pd);
	if (pd != 2 && pd != 6)
		return fprintf(stderr, "input must be a fft (got pd=%d)\n", pd);
	e->pd = pd / 2;
	create_pyramid(e);
	if (filename_imask) {
		int mw, mh;
		e->mask = iio_read_image_uint8(filename_imask,&mw,&mh);
		if (mw != e->w || mh != e->h)
			return fprintf(stderr, "input mask bad size\n");
		fprintf(stderr, "using input mask from file \"%s\"\n",
				filename_imask);
	} else {
		e->mask = malloc(e->w * e->h);
		memset(e->mask, 1, e->w * e->h);
	}

	// open window
	struct FTR f = ftr_new_window(BAD_MIN(e->w,512), BAD_MIN(e->h,512));
	f.userdata = e;
	action_reset_zoom_and_position(&f);
	ftr_set_handler(&f, "expose", pan_exposer);
	ftr_set_handler(&f, "motion", pan_motion_handler);
	ftr_set_handler(&f, "button", pan_button_handler);
	ftr_set_handler(&f, "key"   , pan_key_handler);
	int r = ftr_loop_run(&f);

	// apply computed mask
	for (int i = 0; i < e->w * e->h; i++)
		if (!e->mask[i])
			for (int l = 0; l < e->pd; l++)
				e->fft[i*e->pd+l] = 0;

	// save output images
	iio_save_image_float_vec(filename_out, (void*)e->fft, e->w,e->h, pd);
	if (filename_mask)
		iio_save_image_uint8_vec(filename_mask, e->mask, e->w, e->h, 1);

	// cleanup and exit (optional)
	ftr_close(&f);
	return r;
}