IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 16, 2020, 1:54:47 PM (6 years ago)
Author:
tdeboer
Message:

revert to working Ohana build

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/cmd.data/roll.c

    r41164 r41340  
    33int roll (int argc, char **argv) {
    44 
     5  int Nbytes, Nextra;
     6  int dX, dx, dy, nx, ny;
    57  Buffer *buf;
    6 
    7   // this function is probably not needed
    8   gprint (GP_ERR, "ERROR: use 'shift' instead of 'roll'\n");
    9   return (FALSE);
    108
    119  if (argc != 4) {
     
    1614  if ((buf = SelectBuffer (argv[1], OLDBUFFER, TRUE)) == NULL) return (FALSE);
    1715
    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;
     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");
    4320  }
    4421
    45   if (dx == 0) {
    46     // moves in just dy can be done row-by-row
     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];
    4727
    48     ALLOCATE_PTR (output, float, Nx*Ny);
     28  dX = abs(dx);
     29  Nbytes = nx * ny * sizeof (float);
     30  Nextra = (nx * ny + dX) * sizeof (float);
    4931
    50     float *input = (float *) buf[0].matrix.buffer;
     32  REALLOCATE (buf[0].matrix.buffer, char, Nextra);
    5133
    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;
     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);
    6738  }
    6839
    69   ALLOCATE_PTR (output, float, Nx*Ny);
    70   float *input = (float *) buf[0].matrix.buffer;
     40  REALLOCATE (buf[0].matrix.buffer, char, Nbytes);
    7141
    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;
     42  return (TRUE);
     43
    8444}
    8545
    86 
Note: See TracChangeset for help on using the changeset viewer.