예제 #1
0
// API: get a sample from an image, at the requested octave
float fancy_image_getsample_oct(struct fancy_image *fi,
		int octave, int i,int j, int l)
{
	struct FI *f = (void*)fi;

	if (octave < 0 || octave >= f->no)
		return NAN;
	if (l < 0) l = 0;
	if (l >= f->pd) l = f->pd - 1;

	if (f->tiffo) {
		uint8_t *p_pixel = tiff_octaves_getpixel(f->t, octave, i, j);
		if (!p_pixel) return NAN;
		uint8_t *p_sample = p_pixel + (l * f->t->i->bps) / 8;
		return convert_sample_to_float(f->t->i, p_sample);
	} else {
		float *x = f->pyr_x[octave];
		int    w = f->pyr_w[octave];
		int    h = f->pyr_h[octave];
		if (i < 0 || j < 0 || i >= w || j >= h)
			return NAN;
		int  idx = (j * w + i) * f->pd + l;
		return x[idx];
	}
}
예제 #2
0
파일: fpantiff.c 프로젝트: mnhrdt/imscript
// evaluate the value a position (p,q) in image coordinates
static void pixel(float *out, struct pan_state *e, double p, double q)
{
	if (p < 0 || q < 0 || p > e->t->i->w-1 || q > e->t->i->h-1) {
		int ip = p-256;
		int iq = q-256;
		int pip = mod(ip/256, 2);
		int piq = mod(iq/256, 2);
		int val = mod(pip+piq,2);
		out[0] = out[1] = out[2] = 127+val*64;
		return;
	}

	//double factor;// = 1.0 << e->octave;
	//if (e->octave >= 0)
	//	factor = 1 << e->octave;
	//else
	//	factor = 1.0 / ( 1 << - e->octave );


	int fmt = e->t->i->fmt;
	int bps = e->t->i->bps;
	int spp = e->t->i->spp;
	int ss = bps / 8;

	double factor = 1.0/e->zoom_factor;
	int o = e->octave;
	if (o < 0) { o = 0; factor = 1; }
	char *pix = tiff_octaves_getpixel(e->t, o, p/factor, q/factor);

	out[0] = from_sample_to_double(pix, fmt, bps);
	if (spp >= 3) {
		out[1] = from_sample_to_double(pix + ss,   fmt, bps);
		out[2] = from_sample_to_double(pix + 2*ss, fmt, bps);
		if (spp == 4 && e->infrared) {
			double o4 = from_sample_to_double(pix + 3*ss, fmt, bps);
			out[1] = 0.9*out[1] + 0.1 * o4;
		}
	} else if (spp == 2) {
		out[1] = from_sample_to_double(pix + ss, fmt, bps);
		if (e->infrared) {
			out[0] = hypot(out[0], out[1]);
			out[1] = out[2] = out[0];
		} else {
			out[2] = out[1];
		}
	} else
		out[1] = out[2] = out[0];
	if (e->slog)
		for (int i = 0; i < 3; i++)
			out[i] = slog(out[i]);
}
예제 #3
0
// API: get a sample from an image, at the requested octave
float fancy_image_getsample_oct(struct fancy_image *fi,
		int octave, int i,int j, int l)
{
	struct FI *f = (void*)fi;

	if (octave < 0 || octave >= f->no)
		return NAN;
	if (l < 0) l = 0;
	if (l >= f->pd) l = f->pd - 1;


	if (f->tiffo) {
#ifdef FANCY_TIFF
		uint8_t *p_pixel = tiff_octaves_getpixel(f->t, octave, i, j);
		if (!p_pixel) return NAN;
		uint8_t *p_sample = p_pixel + (l * f->t->i->bps) / 8;
		return convert_sample_to_float(f->t->i, p_sample);
#else
		assert(false);
#endif
	} else if (f->gdal) {
#ifdef FANCY_GDAL
		if (octave != 0) return NAN;
		static float *roi = NULL;
		if (!roi) roi = CPLMalloc(1*1*sizeof*roi);
		GDALRasterBandH img = f->gdal_band[l];
		int r = GDALRasterIO(img, GF_Read, i,j,1, 1, roi,1,1,
				GDT_Float32, 0,0);
		return roi[0*0+0];
#else
		assert(false);
#endif
	} else {
		float *x = f->pyr_x[octave];
		int    w = f->pyr_w[octave];
		int    h = f->pyr_h[octave];
		if (i < 0 || j < 0 || i >= w || j >= h)
			return NAN;
		int  idx = (j * w + i) * f->pd + l;
		return x[idx];
	}
	return NAN;
}