Exemple #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;
}
Exemple #2
0
// API: set a sample of an image
int fancy_image_setsample(struct fancy_image *fi, int i, int j, int l, float v)
{
	struct FI *f = (void*)fi;
	if (!f->option_write) return false;

	if (i < 0 || i >= f->w) return false;
	if (j < 0 || j >= f->h) return false;
	if (l < 0 || l >= f->pd) return false;

	if (f->tiffo) {
#ifdef FANCY_TIFF
		float p[f->pd];
		// TODO: remove this silly loop
		for (int k = 0; k < f->pd; k++)
			p[k] = fancy_image_getsample(fi, i, j, k);
		p[l] = v;
		tiff_octaves_setpixel_float(f->t, i, j, p);
		return true;
#else
		assert(false);
#endif
	} else {
		int idx = (j * f->w + i) * f->pd + l;
		f->x[idx] = v;
		return f->x_changed = true;
	}
}
Exemple #3
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);
}
Exemple #4
0
void fancy_image_getpixel(float *out, struct fancy_image *f, int i, int j)
{
	for (int l = 0; l < f->pd; l++)
		out[l] = fancy_image_getsample(f, i, j, l);
}