Example #1
0
int main_times(int c, char *v[])
{
	// process input arguments
	if (c != 3) {
		fprintf(stderr, "usage:\n\t%s file.tiff factor\n", *v);
		//                          0 1         2
		return 1;
	}
	char *filename = v[1];
	double factor = atof(v[2]);

	// open image
	struct fancy_image *f = fancy_image_open(filename, "rw,megabytes=33");

	// process data
	for (int j = 0; j < f->h; j++)
	for (int i = 0; i < f->w; i++)
	for (int l = 0; l < f->pd; l++)
	{
		double x = fancy_image_getsample(f, i, j, l);
		x = x * factor;
		fancy_image_setsample(f, i, j, l, x);
	}

	// close image (and save remaining updated tiles)
	fancy_image_close(f);

	// exit
	return 0;
}
Example #2
0
static void fancy_zoom_out_by_factor_two(char *fname_out, char *fname_in, int m)
{
	// open input image
	struct fancy_image *a = fancy_image_open(fname_in, "r");

	// read information from input image
	int tw = 0, th = 0, fmt = 0, bps = 0;
	int tiffo = fancy_image_leak_tiff_info(&tw, &th, &fmt, &bps, a);

	// create output image of the appropriate size and options
	int pw = ceil(a->w / 2.0);
	int ph = ceil(a->h / 2.0);
	struct fancy_image *b = fancy_image_create(fname_out,
			"w=%d,h=%d,pd=%d,bps=%d,fmt=%d,tw=%d,th=%d",
			pw, ph, a->pd, bps, fmt, tw, th);

	// fill-in the zoomed-out image
	for (int j = 0; j < b->h; j++)
	for (int i = 0; i < b->w; i++)
	for (int l = 0; l < b->pd; l++)
	{
		int ii = 2 * i;
		int jj = 2 * j;
		double v[4] = {
			fancy_image_getsample(a, ii + 0, jj + 0, l),
			fancy_image_getsample(a, ii + 1, jj + 0, l),
			fancy_image_getsample(a, ii + 0, jj + 1, l),
			fancy_image_getsample(a, ii + 1, jj + 1, l)
		};
		double r = combine_4doubles(v, m);
		fancy_image_setsample(b, i, j, l, r);
	}

	// close both images
	fancy_image_close(b);
	fancy_image_close(a);
}
Example #3
0
int main_cpu(int c, char *v[])
{
	// extract named options
	char *window_title = pick_option(&c, &v, "t", "cpu");

	// process input arguments
	if (c != 2 && c != 1) {
		fprintf(stderr, "usage:\n\t%s [image]\n", *v);
		//                          0  1
		return 1;
	}
	char *filename_in = c > 1 ? v[1] : "-";

	// read image
	struct pan_state e[1];
	e->i = fancy_image_open(filename_in, "r");
	e->w = e->i->w;
	e->h = e->i->h;

	// setup fonts (TODO, integrate these calls into fontu's caching stuff)
	e->font[0] = reformat_font(*xfont_4x6, UNPACKED);
	e->font[1] = reformat_font(*xfont_6x12, UNPACKED);
	e->font[2] = reformat_font(*xfont_7x13, UNPACKED);
	e->font[3] = reformat_font(*xfont_9x15, UNPACKED);
	e->font[4] = reformat_font(*xfont_10x20, UNPACKED);
	//e->font[0] = reformat_font(*xfont_5x7, UNPACKED);

	// open window
	struct FTR f = ftr_new_window(BAD_MIN(e->w,1000), BAD_MIN(e->h,800));
	ftr_change_title(&f, window_title);
	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);

	// cleanup and exit (optional)
	for (int i = 0; i < 5; i++) free(e->font[i].data);
	ftr_close(&f);
	fancy_image_close(e->i);
	return r - 1;
}
Example #4
0
int main_setsample(int c, char *v[])
{
	if (c != 7) {
		fprintf(stderr, "usage:\n\t"
				"%s inout.tiff opts i j l v\n",*v);
		//                0 1          2    3 4 5 6
		return 1;
	}
	char *filename = v[1];
	char *opts = v[2];
	int arg_i = atoi(v[3]);
	int arg_j = atoi(v[4]);
	int arg_l = atoi(v[5]);
	float arg_v = atof(v[6]);

	struct fancy_image *f = fancy_image_open(filename, opts);
	fancy_image_setsample(f, arg_i, arg_j, arg_l, arg_v);
	fancy_image_close(f);

	return 0;
}
Example #5
0
int main_example(int c, char *v[])
{
	// process input arguments
	if (c != 7) {
		fprintf(stderr, "usage:\n\t%s image opts o i j l\n", *v);
		//                          0 1     2    3 4 5 6
		return 1;
	}
	char *filename = v[1];
	char *opts  = v[2];
	int arg_o = atoi(v[3]);
	int arg_i = atoi(v[4]);
	int arg_j = atoi(v[5]);
	int arg_l = atoi(v[6]);

	// do stuff
	struct fancy_image *f = fancy_image_open(filename, opts);
	printf("image \"%s\"\n", filename);
	printf("\tw  = %d\n", f->w);
	printf("\th  = %d\n", f->h);
	printf("\tpd = %d\n", f->pd);
	printf("\tno = %d\n", f->no);

	float s = fancy_image_getsample_oct(f, arg_o, arg_i, arg_j, arg_l);
	printf("\t (%d)[%d,%d]{%d} = %g\n", arg_o, arg_i, arg_j, arg_l, s);

	//int x = 1;
	//float s;
	//do {
	//	s = fancy_image_getsample(&f, x, x, 0);
	//	printf("\tsample(%d,%d,0) = %g\n", x, x, s);
	//	x *= 10;
	//} while(isfinite(s));
	fancy_image_close(f);

	// exit
	return 0;
}
Example #6
0
int main_croparound(int c, char *v[])
{
	// process input arguments
	if (c != 8) {
		fprintf(stderr, "usage:\n\t"
				"%s in.tiff opts o cx cy ww out.png\n",*v);
		//                0 1       2    3 4  5  6  7
		return 1;
	}
	char *filename_in = v[1];
	char *opts   = v[2];
	int octave = atoi(v[3]);
	int cent_x = atoi(v[4]);
	int cent_y = atoi(v[5]);
	int diamet = atoi(v[6]);
	char *filename_out = v[7];

	struct fancy_image *f = fancy_image_open(filename_in, opts);
	if (!f->pd) return 2;
	//if (octave < 0) octave = 0;
	//if (octave >= f.no) octave = f.no - 1;
	float *x = xmalloc(diamet * diamet * f->pd * sizeof*x);
	for (int j = 0; j < diamet; j++)
	for (int i = 0; i < diamet; i++)
	for (int l = 0; l < f->pd; l++)
	{
		int ii = cent_x - diamet/2 + i;
		int jj = cent_y - diamet/2 + j;
		int idx_o = (j * diamet + i) * f->pd + l;
		x[idx_o] = fancy_image_getsample_oct(f, octave, ii, jj, l);
	}
	fancy_image_close(f);
	iio_save_image_float_vec(filename_out, x, diamet, diamet, f->pd);
	free(x);
	return 0;
}