Пример #1
0
int main(int c, char *v[])
{
	int w, h;
	uint8_t *img_in = iio_read_image_uint8(v[1], &w, &h);
	uint8_t *img_out_raw = xmalloc(3*w*h);
	uint8_t (*img_out)[w][3] = (void*)img_out_raw;
	for (int j = 0; j < h; j++)
		for (int i = 0; i < w; i++)
			for (int l = 0; l < 3; l++)
				img_out[j][i][l] = img_in[w*j+i];
	float p[2];
	while (2 == fscanf(stdin, "%g %g\n", p, p+1)) {
		int iox = p[0];
		int ioy = p[1];
		if (iox <= 0) iox = 1;
		if (ioy <= 0) ioy = 1;
		if (iox >= w-1) iox = w-2;
		if (ioy >= h-1) ioy = h-2;
		img_out[ioy][iox][0] = 255;
		img_out[ioy][iox][1] = 0;
		img_out[ioy][iox][2] = 0;
		if (!OVERCROSS()) continue;
		img_out[ioy-1][iox][0] = 255;
		img_out[ioy-1][iox][1] = 0;
		img_out[ioy-1][iox][2] = 0;
		img_out[ioy+1][iox][0] = 255;
		img_out[ioy+1][iox][1] = 0;
		img_out[ioy+1][iox][2] = 0;
		img_out[ioy][iox+1][0] = 255;
		img_out[ioy][iox+1][1] = 0;
		img_out[ioy][iox+1][2] = 0;
		img_out[ioy][iox-1][0] = 255;
		img_out[ioy][iox-1][1] = 0;
		img_out[ioy][iox-1][2] = 0;
	}
	fprintf(stderr, "ok, saving file\n");
	iio_write_image_uint8_vec("-", img_out_raw, w, h, 3);
	return 0;
}
Пример #2
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;
}