Changeset 41340 for trunk/Ohana/src/opihi/cmd.data/extract.c
- Timestamp:
- Apr 16, 2020, 1:54:47 PM (6 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/opihi/cmd.data/extract.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/cmd.data/extract.c
r41164 r41340 1 1 # include "data.h" 2 3 /* <from> : source image, must exist4 <to> : target image -- if it does not exist, it is created of size (Nx,Ny)5 sx, sy : source starting coordinate -- need not be on a valid image pixel6 nx, ny : number of source pixels -- currently must not go out of bounds -> allow out-of-bounds7 Sx, Sy : target starting coordinate -- need not be on a valid image pixel8 Nx, Ny : redundant information UNLESS <to> does exist (in which case it is required information) -> make Nx,Ny optional if <to> exists?9 */10 2 11 3 int extract (int argc, char **argv) { 12 4 13 int N; 5 int i, j; 6 float *Vin, *Vout; 7 int sx, sy, nx, ny, NX, NY; 8 int Sx, Sy, Nx, Ny; 14 9 Buffer *in, *out; 15 16 float initValue = 0.0;17 int initOutput = FALSE;18 if ((N = get_argument (argc, argv, "-init"))) {19 remove_argument (N, &argc, argv);20 initValue = atof (argv[N]);21 remove_argument (N, &argc, argv);22 initOutput = TRUE;23 }24 10 25 11 if (argc != 11) { … … 29 15 30 16 if ((in = SelectBuffer (argv[1], OLDBUFFER, TRUE)) == NULL) return (FALSE); 31 intNX = in[0].matrix.Naxis[0];32 intNY = in[0].matrix.Naxis[1];17 NX = in[0].matrix.Naxis[0]; 18 NY = in[0].matrix.Naxis[1]; 33 19 34 intsx = atof (argv[3]);35 intsy = atof (argv[4]);36 intnx = atof (argv[5]);37 intny = atof (argv[6]);20 sx = atof (argv[3]); 21 sy = atof (argv[4]); 22 nx = atof (argv[5]); 23 ny = atof (argv[6]); 38 24 39 intSx = atof (argv[7]);40 intSy = atof (argv[8]);41 intNx = atof (argv[9]);42 intNy = atof (argv[10]);25 Sx = atof (argv[7]); 26 Sy = atof (argv[8]); 27 Nx = atof (argv[9]); 28 Ny = atof (argv[10]); 43 29 44 30 if ((Sy + ny > Ny) || (Sx + nx > Nx)) { 45 gprint (GP_ERR, " source pixels extend beyond target pixels\n");31 gprint (GP_ERR, "mismatch between source and dest regions\n"); 46 32 gprint (GP_ERR, "%d + %d > %d or %d + %d > %d\n", Sy, ny, Ny, Sx, nx, Nx); 47 //return (FALSE);33 return (FALSE); 48 34 } 49 50 // XXX : allow source region to fall outside source image51 35 52 36 /* region is not on first image */ … … 55 39 (sy > in[0].matrix.Naxis[1])) { 56 40 gprint (GP_ERR, "region outside of source image\n"); 57 //return (FALSE);41 return (FALSE); 58 42 } 59 43 44 if ((Sx + nx > Nx) || (Sy + ny > Ny)) { 45 gprint (GP_ERR, "source region larger than dest region\n"); 46 return (FALSE); 47 } 60 48 if ((Sx < 0) || (Sy < 0)) { 61 49 gprint (GP_ERR, "dest region out of range\n"); 62 //return (FALSE);50 return (FALSE); 63 51 } 64 52 … … 88 76 } 89 77 90 // (NX,NY) : source image dimensions 91 // (Nx,Ny) : target image dimensions 92 93 // allow (sx, sy), (Sx, Sy) to be off image 94 // allow (sx+nx, sy+ny) to be off image 95 96 // if (sx < 0) { 97 // nx += sx; 98 // sx = 0; 99 // } 100 // if (sx > NX) sx = NX; 101 // 102 // if (Sx < 0) { 103 // Nx += sx; 104 // sx = 0; 105 // } 106 // if (sx > NX) sx = NX; 107 108 float *Vin = (float *)(in[0].matrix.buffer); 109 float *Vout = (float *)(out[0].matrix.buffer); 110 111 if (initOutput) { 112 for (int j = 0; j < Ny; j++) { 113 for (int i = 0; i < Nx; i++) { 114 Vout[i + Nx*j] = initValue; 115 } 116 } 117 } 118 119 int Nps = NX*NY; 120 int Npt = Nx*Ny; 121 122 for (int j = 0; j < ny; j++) { 123 if (j + sy < 0) continue; // not yet on source image 124 if (j + Sy < 0) continue; // not yet on target image 125 if (j + sy >= NY) continue; // past edge of source image 126 if (j + Sy >= Ny) continue; // past edge of target image 127 128 // Vin = (float *)(in[0].matrix.buffer) + (j + sy)*in[0].matrix.Naxis[0] + sx; 129 // Vout = (float *)(out[0].matrix.buffer) + (j + Sy)*out[0].matrix.Naxis[0] + Sx; 130 131 for (int i = 0; i < nx; i++) { 78 for (j = 0; j < ny; j++) { 79 if (j + sy < 0) continue; 80 if (j + sy >= NY) continue; 81 Vin = (float *)(in[0].matrix.buffer) + (j + sy)*in[0].matrix.Naxis[0] + sx; 82 Vout = (float *)(out[0].matrix.buffer) + (j + Sy)*out[0].matrix.Naxis[0] + Sx; 83 for (i = 0; i < nx; i++, Vin++, Vout++) { 132 84 if (i + sx < 0) continue; 133 85 if (i + sx >= NX) continue; 134 if (i + Sx < 0) continue; 135 if (i + Sx >= Nx) continue; 136 137 int ps = i + sx + (j + sy)*NX; 138 int pt = i + Sx + (j + Sy)*Nx; 139 140 myAssert (pt >= 0, "oops 1"); 141 myAssert (pt < Npt, "oops 2"); 142 143 myAssert (ps >= 0, "oops 3"); 144 myAssert (ps < Nps, "oops 4"); 145 146 Vout[pt] = Vin[ps]; 86 *Vout = *Vin; 147 87 } 148 88 } … … 151 91 152 92 } 93
Note:
See TracChangeset
for help on using the changeset viewer.
