// 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]; } }
// 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; }