Changeset 40821
- Timestamp:
- Jul 2, 2019, 3:05:52 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ohana.20190329/src/opihi/cmd.data/roll.c
r7917 r40821 3 3 int roll (int argc, char **argv) { 4 4 5 int Nbytes, Nextra;6 int dX, dx, dy, nx, ny;7 5 Buffer *buf; 6 7 // this function is probably not needed 8 gprint (GP_ERR, "ERROR: use 'shift' instead of 'roll'\n"); 9 return (FALSE); 8 10 9 11 if (argc != 4) { … … 14 16 if ((buf = SelectBuffer (argv[1], OLDBUFFER, TRUE)) == NULL) return (FALSE); 15 17 16 dx = atof (argv[2]); 17 dy = atof (argv[3]); 18 if (dy != 0) { 19 gprint (GP_ERR, "only x rolls implemented for now\n"); 18 int dx = atoi (argv[2]); 19 int dy = atoi (argv[3]); 20 21 /* if (dx,dy < 0), we are moving the start position backwards, 22 if (dx,dy > 0), we are moving the start position forward */ 23 24 int Nx = buf[0].matrix.Naxis[0]; 25 int Ny = buf[0].matrix.Naxis[1]; 26 27 if (dy == 0) { 28 // moves in just dx can be done row-by-row 29 30 int dX = abs(dx); 31 int Nbytes = (Nx * Ny - dX) * sizeof (float); 32 int Nextra = dX * sizeof (float); 33 34 if (dx < 0) { 35 memmove (buf[0].matrix.buffer, &buf[0].matrix.buffer[dX*sizeof(float)], Nbytes); 36 memset (&buf[0].matrix.buffer[Nbytes], 0, Nextra); 37 } else { 38 memmove (&buf[0].matrix.buffer[dX*sizeof(float)], buf[0].matrix.buffer, Nbytes); 39 memset (buf[0].matrix.buffer, 0, Nextra); 40 } 41 42 return TRUE; 20 43 } 21 44 22 /* if (dx < 0), we are moving the start position back by dx pixels, 23 if (dx > 0), we are moving the start position forward by dx pixels */ 24 25 nx = buf[0].matrix.Naxis[0]; 26 ny = buf[0].matrix.Naxis[1]; 45 if (dx == 0) { 46 // moves in just dy can be done row-by-row 27 47 28 dX = abs(dx); 29 Nbytes = nx * ny * sizeof (float); 30 Nextra = (nx * ny + dX) * sizeof (float); 48 ALLOCATE_PTR (output, float, Nx*Ny); 31 49 32 REALLOCATE (buf[0].matrix.buffer, char, Nextra);50 float *input = (float *) buf[0].matrix.buffer; 33 51 34 if (dx < 0) { 35 memmove (buf[0].matrix.buffer, &buf[0].matrix.buffer[dX*sizeof(float)], Nbytes); 36 } else { 37 memmove (&buf[0].matrix.buffer[dX*sizeof(float)], buf[0].matrix.buffer, Nbytes); 52 for (int iy = 0; iy < Ny; iy++) { 53 if (iy + dy < 0) continue; 54 if (iy + dy >= Ny) continue; 55 memcpy (&output[iy*Nx], &input[(iy + dy)*Nx], Nx); 56 } 57 if (dy > 0) { 58 memset (output, 0, dy*Nx*sizeof(float)); 59 } else { 60 int Nbytes = Nx * (Ny - abs(dy)) * sizeof (float); 61 int Nextra = abs(dy) * Nx * sizeof (float); 62 memset (&output[Nbytes], 0, Nextra); 63 } 64 free (buf[0].matrix.buffer); 65 buf[0].matrix.buffer = (char *) output; 66 return TRUE; 38 67 } 39 68 40 REALLOCATE (buf[0].matrix.buffer, char, Nbytes); 69 ALLOCATE_PTR (output, float, Nx*Ny); 70 float *input = (float *) buf[0].matrix.buffer; 41 71 42 return (TRUE); 43 72 for (int iy = 0; iy < Ny; iy++) { 73 if (iy + dy < 0) continue; 74 if (iy + dy >= Ny) continue; 75 for (int ix = 0; ix < Nx; ix++) { 76 if (ix + dx < 0) continue; 77 if (ix + dx >= Nx) continue; 78 output[ix + iy*Nx] = input[(ix + dx) + (iy + dy)*Nx]; 79 } 80 } 81 free (buf[0].matrix.buffer); 82 buf[0].matrix.buffer = (char *) output; 83 return TRUE; 44 84 } 45 85 86
Note:
See TracChangeset
for help on using the changeset viewer.
