// API: load a rectangle of data int fancy_image_getrectangle_oct(float *out, struct fancy_image *fi, int octave, int x0, int y0, int xf, int yf) { struct FI *f = (void*)fi; if (f->megabytes > 0) // if we have our own cache, we use it { for (int j = x0; j <= xf; j++) for (int i = x0; i <= xf; i++) for (int l = 0; l < f->pd; l++) *out++ = fancy_image_getsample_oct(fi, octave, i, j, l); return true; } return false; }
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; }
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; }
// API: get a sample from an image float fancy_image_getsample(struct fancy_image *fi, int i, int j, int l) { return fancy_image_getsample_oct(fi, 0, i, j, l); }
void fancy_image_getpixel_oct(float *out, struct fancy_image *f, int o, int i, int j) { for (int l = 0; l < f->pd; l++) out[l] = fancy_image_getsample_oct(f, o, i, j, l); }