IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 16228


Ignore:
Timestamp:
Jan 24, 2008, 5:45:18 PM (18 years ago)
Author:
eugene
Message:

cleaning up the image/screen relationships and remap functions

Location:
trunk/Ohana/src/kapa2
Files:
20 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/kapa2/include/structures.h

    r16039 r16228  
    9090
    9191typedef struct {
    92   int      dx, dy, x, y;
     92  int      x, y;              // location of picture in graphic
     93  int      dx, dy;            // size of picture
     94  int      DX, DY;            // size of displayed picture (must be updated with new images...)
     95  int      expand;            // zoomscale
     96  double   Xo, Yo;            // image pixel at screen center
    9397  XImage  *pix;
    9498  char    *data;
     
    183187  int      DecimalDegrees;
    184188
    185   double   X, Y;           /* image pixel at screen center */
    186   int      expand;         /* zoomscale */
    187   double   x, y, z;        /* last pointer coords */
     189  // double   X, Y;           /* image pixel at screen center */
     190  // double   x, y, z;        /* last pointer coords */
    188191
    189192  Overlay  overlay[NOVERLAYS];
  • trunk/Ohana/src/kapa2/src/ButtonFunctions.c

    r16039 r16228  
    5656int Rescale (Graphic *graphic, KapaImageWidget *image) {
    5757
    58   image[0].expand = 1;
     58  image[0].picture.expand = 1;
    5959  Remap (graphic, image);
    6060  Refresh ();
     
    6666int RecenterRescale (Graphic *graphic, KapaImageWidget *image) {
    6767
    68   image[0].X = 0;
    69   image[0].Y = 0;
    70   image[0].expand = 1;
     68  image[0].picture.X = 0;
     69  image[0].picture.Y = 0;
     70  image[0].picture.expand = 1;
    7171 
    7272  Remap (graphic, image);
  • trunk/Ohana/src/kapa2/src/Center.c

    r16011 r16228  
    1616  if (image == NULL) return (TRUE);
    1717
    18   image[0].X = 0.5*image[0].image[0].matrix.Naxis[0] - X;
    19   image[0].Y = 0.5*image[0].image[0].matrix.Naxis[1] - Y;
     18  image[0].picture.X = 0.5*image[0].image[0].matrix.Naxis[0] - X;
     19  image[0].picture.Y = 0.5*image[0].image[0].matrix.Naxis[1] - Y;
    2020  if ((zoom != 0) && (zoom != -1)) {
    21     image[0].expand = zoom;
     21    image[0].picture.expand = zoom;
    2222  }
    2323
  • trunk/Ohana/src/kapa2/src/CreateZoom32.c

    r16061 r16228  
    88  int dropback;  /* this is a bit of a kludge... */
    99  int dx, dy, DX, DY;
    10   double expand, zoomscale, Rx, Ry;
     10  double expand, zoomscale, Ix, Iy;
    1111  int expand_in, expand_out;
    1212  unsigned int *out_pix, *out_pix2;
     
    4040  DY = image[0].image[0].matrix.Naxis[1];
    4141 
    42   /* Rx,Ry are the screen coordinates of the first image pixel */
    43   Rx = x - expand*(int)(0.5*(dx + 1)) + 1;
    44   Ry = y - expand*(int)(0.5*(dy + 1)) + 1;
     42  /* Ix,Iy are the image coordinates of the first image pixel */
     43  // x,y is the image coordinate of the zoombox center
     44  Ix = x - expand*(int)(0.5*(dx + 1)) + 1;
     45  Iy = y - expand*(int)(0.5*(dy + 1)) + 1;
    4546
    46   i_start = MIN (MAX (-Rx / expand, (1 - FRAC(Rx)) / expand), dx - expand_out + 1);
    47   j_start = MIN (MAX (-Ry / expand, (1 - FRAC(Ry)) / expand), dy - expand_out + 1);
    48   i_end   = MAX (MIN ((DX-Rx) / expand, dx - expand_out + 1), 0);
    49   j_end   = MAX (MIN ((DY-Ry) / expand, dy - expand_out + 1), 0);
     47  i_start = MIN (MAX (-Ix / expand, (1 - FRAC(Ix)) / expand), dx - expand_out + 1);
     48  j_start = MIN (MAX (-Iy / expand, (1 - FRAC(Iy)) / expand), dy - expand_out + 1);
     49  i_end   = MAX (MIN ((DX-Ix) / expand, dx - expand_out + 1), 0);
     50  j_end   = MAX (MIN ((DY-Iy) / expand, dy - expand_out + 1), 0);
    5051
    5152  dropback = expand_out - (i_end - i_start) % expand_out;
     
    5354
    5455  out_pix = (unsigned int *) image[0].zoom.data;
    55   in_pix  = &image[0].pixmap[DX*(int)MAX(Ry,0) + (int)MAX(Rx,0)];
     56  in_pix  = &image[0].pixmap[DX*(int)MAX(Iy,0) + (int)MAX(Ix,0)];
    5657
    5758  /********** below we do the mapping from buffer pixels (in) to picture pixels (out) **********/
  • trunk/Ohana/src/kapa2/src/CrossHairs.c

    r13320 r16228  
    77  double zoomscale;
    88
    9   zoomscale = MAX (5, image[0].expand + 5);
     9  zoomscale = image[0].zoom;
    1010  x0 = (zoomscale) * (0.5 * (ZOOM_X + 1) / zoomscale - 2.5) + image[0].zoom.x;
    1111  x5 = (zoomscale) * (0.5 * (ZOOM_X + 1) / zoomscale - 0.5) + image[0].zoom.x;
  • trunk/Ohana/src/kapa2/src/CursorOps.c

    r16011 r16228  
    11# include "Ximage.h"
    22
    3 void Screen_to_Image (double *x1, double *y1, double x2, double y2, KapaImageWidget *image) {
     3void Screen_to_Image (double *x1, double *y1, double x2, double y2, Picture *picture) {
    44
    55  double expand;
    66
    77  expand = 1.0;
    8   if (image[0].expand > 0) {
    9     expand = 1 / (1.0*image[0].expand);
    10   }
    11   if (image[0].expand < 0) {
    12     expand = fabs((double)image[0].expand);
     8  if (picture[0].expand > 0) {
     9    expand = 1 / (1.0*picture[0].expand);
     10  } else {
     11    expand = fabs((double)picture[0].expand);
    1312  }
    1413 
    15   *x1 = expand*(x2 - image[0].picture.x - 0.5*image[0].picture.dx) + 0.5*image[0].image[0].matrix.Naxis[0] - image[0].X;
    16   *y1 = expand*(y2 - image[0].picture.y - 0.5*image[0].picture.dy) + 0.5*image[0].image[0].matrix.Naxis[1] - image[0].Y;
    17  
     14  // pixel coordinates in picture frame
     15  xs = x2 - picture[0].x;
     16  ys = y2 - picture[0].y;
     17
     18  // picture[0].X,Y is the offset relative to picture[0].Xo,Yo
     19  *x1 = expand*(xs - 0.5*picture[0].dx) + picture[0].Xo - picture[0].X;
     20  *y1 = expand*(ys - 0.5*picture[0].dy) + picture[0].Yo - picture[0].Y;
    1821}
    1922
    20 void Image_to_Screen (double *x1, double *y1, double x2, double y2, KapaImageWidget *image) {
     23void Image_to_Screen (double *x1, double *y1, double x2, double y2, Picture *picture) {
    2124
    2225  double expand;
     
    2427  /* notice that here, expand is the reciprocal of the expand above */
    2528  expand = 1.0;
    26   if (image[0].expand > 0) {
    27     expand = abs(image[0].expand);
    28   }
    29   if (image[0].expand < 0) {
    30     expand = 1 / ((double)abs(image[0].expand));
     29  if (picture[0].expand > 0) {
     30    expand = picture[0].expand;
     31  } else {
     32    expand = 1 / fabs((double)image[0].expand);
    3133  }
    3234 
    33   *x1 = (x2 - 0.5*image[0].image[0].matrix.Naxis[0] + image[0].X) * expand + image[0].picture.x + 0.5*image[0].picture.dx;
    34   *y1 = (y2 - 0.5*image[0].image[0].matrix.Naxis[1] + image[0].Y) * expand + image[0].picture.y + 0.5*image[0].picture.dy;
    35  
     35  // pixel coordinates in picture frame
     36  xs = expand*(x2 - picture[0].Xo + picture[0].X) + 0.5*picture[0].dx;
     37  ys = expand*(y2 - picture[0].Yo + picture[0].Y) + 0.5*picture[0].dy;
     38
     39  // pixel coordinates in screen frame
     40  *x1 = xs + picture[0].x;
     41  *y1 = ys + picture[0].y;
    3642}
    3743
  • trunk/Ohana/src/kapa2/src/Image.c

    r16011 r16228  
    4747  }
    4848
    49   image[0].X = 0.0;
    50   image[0].Y = 0.0;
    51   image[0].expand = 1;
     49  // set the center and expansion for the pictures:
     50  image[0].picture.X      = 0.0;
     51  image[0].picture.Y      = 0.0;
     52  image[0].picture.expand = 1;
     53
     54  image[0].zoom.X         = 0.0;
     55  image[0].zoom.Y         = 0.0;
     56  image[0].zoom.expand    = +5;
     57
     58  image[0].wide.X         = 0.0;
     59  image[0].wide.Y         = 0.0;
     60  image[0].wide.expand    = -5;
     61
    5262  image[0].location = 4;
    5363
  • trunk/Ohana/src/kapa2/src/InterpretKeys.c

    r16039 r16228  
    6060      if (event[0].x > image[0].picture.x + image[0].picture.dx) goto skip_cursor;
    6161      if (event[0].y > image[0].picture.y + image[0].picture.dy) goto skip_cursor;
    62       Screen_to_Image (&X, &Y, (double)event[0].x, (double)event[0].y, image);
     62      Screen_to_Image (&X, &Y, (double)event[0].x, (double)event[0].y, &image[0].picture);
    6363      XY_to_RD (&R, &D, X, Y, &image[0].image[0].coords);
    6464
     
    123123    case XK_KP_Begin:
    124124    case XK_Return:
    125       Screen_to_Image (&X, &Y, (double)event[0].x, (double)event[0].y, image);
    126       X = 0.5*image[0].image[0].matrix.Naxis[0] - X;
    127       Y = 0.5*image[0].image[0].matrix.Naxis[1] - Y;
     125      Screen_to_Image (&X, &Y, (double)event[0].x, (double)event[0].y, &image[0].picture);
     126      X = 0.5*image[0].picture.DX - X;
     127      Y = 0.5*image[0].picture.DY - Y;
    128128      Reorient (graphic, image, X, Y, 0);
    129129      break;
  • trunk/Ohana/src/kapa2/src/InterpretPresses.c

    r16011 r16228  
    3434      if (event[0].x > image[0].picture.x + image[0].picture.dx) goto skip_cursor;
    3535      if (event[0].y > image[0].picture.y + image[0].picture.dy) goto skip_cursor;
    36       Screen_to_Image (&X, &Y, (double)event[0].x, (double)event[0].y, image);
     36      Screen_to_Image (&X, &Y, (double)event[0].x, (double)event[0].y, &image[0].picture);
    3737
    3838      XY_to_RD (&R, &D, X, Y, &image[0].image[0].coords);
     
    101101  double X, Y;
    102102
    103   Screen_to_Image (&X, &Y, (double)mouse_event[0].x, (double)mouse_event[0].y, image);
     103  Screen_to_Image (&X, &Y, (double)mouse_event[0].x, (double)mouse_event[0].y, &image[0].picture);
    104104  X = 0.5*image[0].image[0].matrix.Naxis[0] - X;
    105105  Y = 0.5*image[0].image[0].matrix.Naxis[1] - Y;
  • trunk/Ohana/src/kapa2/src/LoadPicture.c

    r16011 r16228  
    3232  gfits_free_matrix (&image[0].image[0].matrix);
    3333  gfits_create_matrix (&header, &image[0].image[0].matrix);
     34
     35  // reference point for image is the center pixel
     36  image[0].picture.Xo = 0.5*header.Naxis[0];
     37  image[0].picture.Yo = 0.5*header.Naxis[1];
    3438
    3539  fcntl (sock, F_SETFL, O_NONBLOCK); 
  • trunk/Ohana/src/kapa2/src/PSOverlay.c

    r15620 r16228  
    1616  }
    1717
    18   Image_to_Screen (&X0, &Y0, 0.0, 0.0, image);
     18  Image_to_Screen (&X0, &Y0, 0.0, 0.0, &image[0].picture);
    1919  X0 -= image[0].picture.x;
    2020  Y0 -= image[0].picture.y;
  • trunk/Ohana/src/kapa2/src/PaintOverlay.c

    r15620 r16228  
    1818  }
    1919
    20   Image_to_Screen (&X0, &Y0, 0.0, 0.0, image);
     20  Image_to_Screen (&X0, &Y0, 0.0, 0.0, &image[0].picture);
    2121
    2222  Xmin = image[0].picture.x;
  • trunk/Ohana/src/kapa2/src/Remap16.c

    r16011 r16228  
    11# include "Ximage.h"
    2 
    3 static float slope = 1.0;
    4 static float start = 0.0;
    5 static int MaxValue = 255;
    6 
    7 // XXX inline this if needed
    8 static int PixelLookup(float value) {
    9   int out;
    10   out = MIN (MAX (slope * value - start, 0), MaxValue);
    11   return (out);
    12 }
    132
    143void Remap16 (Graphic *graphic, KapaImageWidget *image, Matrix *matrix) {
     
    176  int i_start, i_end, j_start, j_end;
    187  int dropback;  /* this is a bit of a kludge... */
    19   int dx, dy, DX, DY, pixelN;
    20   double expand, Rx, Ry, X, Y;
     8  int dx, dy, DX, DY;
     9  double expand, Sx, Sy, Ix, Iy;
    2110  int expand_in, expand_out;
    2211  unsigned char *out_pix, *out_pix2, *data;
    23   float *imdata, *in_pix, *in_pix2;
    24   unsigned char pixel1[256], pixel2[256];
     12  unsigned short *in_pix, *in_pix2;
     13  unsigned char *pixel1, *pixel2;
    2514  unsigned char pixvalue1, pixvalue2;
    26   unsigned long back;
    2715  unsigned char back1, back2;
    2816
     17  ALLOCATE (pixel1, unsigned char, graphic[0].Npixels);
     18  ALLOCATE (pixel2, unsigned char, graphic[0].Npixels);
     19
    2920  // local array for pixel values (is this working??)
    30   for (i = 0; i < 256; i++) { /* set up pixel array */
     21  for (i = 0; i < graphic[0].Npixels; i++) { /* set up pixel array */
    3122    pixel1[i] = 0x00ff &  graphic[0].cmap[i].pixel;
    3223    pixel2[i] = 0x00ff & (graphic[0].cmap[i].pixel >> 8);
    3324  }
    34   back = graphic[0].back;
    35   back1 = 0x00ff & back;
    36   back2 = 0x00ff & (back >> 8);
     25  back1 = 0x00ff & (graphic[0].back >> 0);
     26  back2 = 0x00ff & (graphic[0].back >> 8);
    3727
    3828  // define the color transform parameters
     
    6858
    6959  /* X,Y are the image coordinates of the first image pixel */
    70   X = MAX(0.5*(DX - dx*expand) - image[0].X, 0);
    71   if ((int)X != X)
    72     X = (int) X + 1;
     60  Ix = MAX(0.5*(DX - dx*expand) - image[0].X, 0);
     61  if ((int)Ix != Ix)
     62    Ix = (int) Ix + 1;
    7363  else
    74     X = (int) X;
    75   Y = MAX(0.5*(DY - dy*expand) - image[0].Y, 0);
    76   if ((int)Y != Y)
    77     Y = (int) Y + 1;
     64    Ix = (int) Ix;
     65  Iy = MAX(0.5*(DY - dy*expand) - image[0].Y, 0);
     66  if ((int)Iy != Iy)
     67    Iy = (int) Iy + 1;
    7868  else
    79     Y = (int) Y;
     69    Iy = (int) Iy;
    8070
    81   /* Rx,Ry are the screen coordinates of the first image pixel */
    82   Rx = (X + image[0].X - 0.5*DX)/expand + 0.5*dx;
    83   Ry = (Y + image[0].Y - 0.5*DY)/expand + 0.5*dy;
     71  /* Sx,Sy are the screen coordinates of the first image pixel */
     72  Sx = (Ix + image[0].X - 0.5*DX)/expand + 0.5*dx;
     73  Sy = (Iy + image[0].Y - 0.5*DY)/expand + 0.5*dy;
    8474
    85   i_start = MIN (MAX (Rx, 0), dx - expand_out + 1);
    86   j_start = MIN (MAX (Ry, 0), dy - expand_out + 1);
     75  i_start = MIN (MAX (Sx, 0), dx - expand_out + 1);
     76  j_start = MIN (MAX (Sy, 0), dy - expand_out + 1);
    8777 
    8878  if (image[0].expand > 0) {
    89     i_end = MAX (MIN (i_start + ((int)(expand*(dx-i_start)))/expand, expand_out*(DX-X) + Rx), 0);
    90     j_end = MAX (MIN (j_start + ((int)(expand*(dy-j_start)))/expand, expand_out*(DY-Y) + Ry), 0);
     79    i_end = MAX (MIN (i_start + ((int)(expand*(dx-i_start)))/expand, expand_out*(DX-Ix) + Sx), 0);
     80    j_end = MAX (MIN (j_start + ((int)(expand*(dy-j_start)))/expand, expand_out*(DY-Iy) + Sy), 0);
    9181  } else {
    92     i_end = MAX (MIN (dx, (DX-X)/expand + Rx), 0);
    93     j_end = MAX (MIN (dy, (DY-Y)/expand + Ry), 0);
     82    i_end = MAX (MIN (dx, (DX-Ix)/expand + Sx), 0);
     83    j_end = MAX (MIN (dy, (DY-Iy)/expand + Sy), 0);
    9484  }   
    9585
     
    9888
    9989  data = out_pix = (unsigned char *) image[0].picture.data;
    100   imdata  = (float *) matrix[0].buffer;
    101   in_pix  = &imdata[DX*(int)MAX(Y,0) + (int)MAX(X,0)];
     90  in_pix  = &image[0].pixmap[DX*(int)MAX(Iy,0) + (int)MAX(Ix,0)];
    10291
    10392  /********** below we do the mapping from buffer pixels (in) to picture pixels (out) **********/
     
    128117    if (expand_out == 1) {
    129118      for (i = i_start; i < i_end; i++, in_pix2+= expand_in, out_pix+=2) {
    130         pixelN = PixelLookup(*in_pix2);
    131         out_pix[0] = pixel1[pixelN];
    132         out_pix[1] = pixel2[pixelN];
     119        out_pix[0] = pixel1[*in_pix2];
     120        out_pix[1] = pixel2[*in_pix2];
    133121      }
    134122    }
    135123    else {
    136124      for (i = i_start; i < i_end; i+= expand_out, in_pix2++, out_pix+= 2*expand_out) {
    137         pixelN    = PixelLookup(*in_pix2);
    138         pixvalue1 = pixel1[pixelN];
    139         pixvalue2 = pixel2[pixelN];
     125        pixvalue1 = pixel1[*in_pix2];
     126        pixvalue2 = pixel2[*in_pix2];
    140127        out_pix2 = out_pix;
    141128        for (jj = 0; jj < expand_out; jj++, out_pix2+=2*(dx-expand_out)) {
     
    175162  image[0].picture.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0,
    176163                                        image[0].picture.data, image[0].picture.dx, image[0].picture.dy, 16, 0);
     164
     165  free (pixel1);
     166  free (pixel2);
    177167}
    178168
  • trunk/Ohana/src/kapa2/src/Remap24.c

    r16011 r16228  
    11# include "Ximage.h"
    2 
    3 static float slope = 1.0;
    4 static float start = 0.0;
    5 static int MaxValue = 255;
    6 
    7 // XXX inline this if needed
    8 static int PixelLookup(float value) {
    9   int out;
    10   out = MIN (MAX (slope * value - start, 0), MaxValue);
    11   return (out);
    12 }
    132
    143void Remap24 (Graphic *graphic, KapaImageWidget *image, Matrix *matrix) {
     
    176  int i_start, i_end, j_start, j_end;
    187  int dropback, extra;  /* this is a bit of a kludge... */
    19   int dx, dy, DX, DY, pixelN;
    20   double expand, Rx, Ry, X, Y;
     8  int dx, dy, DX, DY;
     9  double expand, Sx, Sy, Ix, Iy;
    2110  int expand_in, expand_out;
    2211  unsigned char *out_pix, *out_pix2, *data;
    23   float *imdata, *in_pix, *in_pix2;
    24   unsigned char pixel1[256], pixel2[256], pixel3[256];
     12  unsigned short *in_pix, *in_pix2;
     13  unsigned char *pixel1, *pixel2, *pixel3;
    2514  unsigned char pixvalue1, pixvalue2, pixvalue3;
    26   unsigned long back;
    2715  unsigned char back1, back2, back3;
    2816
     17  ALLOCATE (pixel1, unsigned char, graphic[0].Npixels);
     18  ALLOCATE (pixel2, unsigned char, graphic[0].Npixels);
     19  ALLOCATE (pixel3, unsigned char, graphic[0].Npixels);
     20
    2921  // local arrays for pixel values
    30   for (i = 0; i < 256; i++) { /* set up pixel array */
     22  for (i = 0; i < graphic[0].Npixels; i++) { /* set up pixel array */
    3123    pixel1[i] = 0x0000ff &  graphic[0].cmap[i].pixel;
    3224    pixel2[i] = 0x0000ff & (graphic[0].cmap[i].pixel >> 8);
    3325    pixel3[i] = 0x0000ff & (graphic[0].cmap[i].pixel >> 16);
    3426  }
    35   back = graphic[0].back;
    36   back1 = 0x0000ff & back;
    37   back2 = 0x0000ff & (back >> 8);
    38   back3 = 0x0000ff & (back >> 16);
    39 
    40   // define the color transform parameters
    41   MaxValue = graphic[0].Npixels - 1;
    42   if (image[0].image[0].range != 0.0) {
    43     slope = graphic[0].Npixels / image[0].image[0].range;
    44     start = graphic[0].Npixels * image[0].image[0].zero / image[0].image[0].range;
    45   } else {
    46     slope = 1.0;
    47     start = image[0].image[0].zero;
    48   }
     27  back1 = 0x0000ff & (graphic[0].back >>  0);
     28  back2 = 0x0000ff & (graphic[0].back >>  8);
     29  back3 = 0x0000ff & (graphic[0].back >> 16);
    4930
    5031  // set up expansions
     
    7051
    7152  /* X,Y are the image coordinates of the first image pixel */
    72   X = MAX(0.5*(DX - dx*expand) - image[0].X, 0);
    73   if ((int)X != X)
    74     X = (int) X + 1;
     53  Ix = MAX(0.5*(DX - dx*expand) - image[0].X, 0);
     54  if ((int)Ix != Ix)
     55    Ix = (int) Ix + 1;
    7556  else
    76     X = (int) X;
    77   Y = MAX(0.5*(DY - dy*expand) - image[0].Y, 0);
    78   if ((int)Y != Y)
    79     Y = (int) Y + 1;
     57    Ix = (int) Ix;
     58  Iy = MAX(0.5*(DY - dy*expand) - image[0].Y, 0);
     59  if ((int)Iy != Iy)
     60    Iy = (int) Iy + 1;
    8061  else
    81     Y = (int) Y;
     62    Iy = (int) Iy;
    8263
    83   /* Rx,Ry are the screen coordinates of the first image pixel */
    84   Rx = (X + image[0].X - 0.5*DX)/expand + 0.5*dx;
    85   Ry = (Y + image[0].Y - 0.5*DY)/expand + 0.5*dy;
     64  /* Sx,Sy are the screen coordinates of the first image pixel */
     65  Sx = (Ix + image[0].X - 0.5*DX)/expand + 0.5*dx;
     66  Sy = (Iy + image[0].Y - 0.5*DY)/expand + 0.5*dy;
    8667
    87   i_start = MIN (MAX (Rx, 0), dx - expand_out + 1);
    88   j_start = MIN (MAX (Ry, 0), dy - expand_out + 1);
     68  i_start = MIN (MAX (Sx, 0), dx - expand_out + 1);
     69  j_start = MIN (MAX (Sy, 0), dy - expand_out + 1);
    8970 
    9071  if (image[0].expand > 0) {
    91     i_end = MAX (MIN (i_start + ((int)(expand*(dx-i_start)))/expand, expand_out*(DX-X) + Rx), 0);
    92     j_end = MAX (MIN (j_start + ((int)(expand*(dy-j_start)))/expand, expand_out*(DY-Y) + Ry), 0);
     72    i_end = MAX (MIN (i_start + ((int)(expand*(dx-i_start)))/expand, expand_out*(DX-Ix) + Sx), 0);
     73    j_end = MAX (MIN (j_start + ((int)(expand*(dy-j_start)))/expand, expand_out*(DY-Iy) + Sy), 0);
    9374  } else {
    94     i_end = MAX (MIN (dx, (DX-X)/expand + Rx), 0);
    95     j_end = MAX (MIN (dy, (DY-Y)/expand + Ry), 0);
     75    i_end = MAX (MIN (dx, (DX-Ix)/expand + Sx), 0);
     76    j_end = MAX (MIN (dy, (DY-Iy)/expand + Sy), 0);
    9677  }   
    9778
     
    10081
    10182  data = out_pix = (unsigned char *) image[0].picture.data;
    102   imdata  = (float *) matrix[0].buffer;
    103   in_pix  = &imdata[DX*(int)MAX(Y,0) + (int)MAX(X,0)];
     83  in_pix  = &image[0].pixmap[DX*(int)MAX(Iy,0) + (int)MAX(Ix,0)];
    10484
    10585  /********** below we do the mapping from buffer pixels (in) to picture pixels (out) **********/
     
    133113    if (expand_out == 1) {
    134114      for (i = i_start; i < i_end; i++, in_pix2+= expand_in, out_pix+=3) {
    135         pixelN = PixelLookup(*in_pix2);
    136         out_pix[0] = pixel1[pixelN];
    137         out_pix[1] = pixel2[pixelN];
    138         out_pix[2] = pixel3[pixelN];
     115        out_pix[0] = pixel1[*in_pix2];
     116        out_pix[1] = pixel2[*in_pix2];
     117        out_pix[2] = pixel3[*in_pix2];
    139118      }
    140119    } else {
    141120      for (i = i_start; i < i_end; i+= expand_out, in_pix2++, out_pix+= 3*expand_out) {
    142         pixelN = PixelLookup(*in_pix2);
    143         pixvalue1 = pixel1[pixelN];
    144         pixvalue2 = pixel2[pixelN];
    145         pixvalue3 = pixel3[pixelN];
     121        pixvalue1 = pixel1[*in_pix2];
     122        pixvalue2 = pixel2[*in_pix2];
     123        pixvalue3 = pixel3[*in_pix2];
    146124        out_pix2 = out_pix;
    147125        for (jj = 0; jj < expand_out; jj++, out_pix2+=3*(dx-expand_out)+extra) {
     
    185163  image[0].picture.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0,
    186164                                        image[0].picture.data, image[0].picture.dx, image[0].picture.dy, 32, 0);
     165
     166  free (pixel1);
     167  free (pixel2);
     168  free (pixel3);
    187169}
    188170
  • trunk/Ohana/src/kapa2/src/Remap32.c

    r16061 r16228  
    77  int dropback;  /* this is a bit of a kludge... */
    88  int dx, dy, DX, DY;
    9   double expand, Rx, Ry, X, Y;
     9  double expand, Sx, Sy, Ix, Iy;
    1010  int expand_in, expand_out;
    1111  unsigned int *out_pix, *out_pix2;
     
    4343  DY = matrix[0].Naxis[1];
    4444
    45   /* X,Y are the image coordinates of the first image pixel */
    46   X = MAX(0.5*(DX - dx*expand) - image[0].X, 0);
    47   if ((int)X != X)
    48     X = (int) X + 1;
    49   else
    50     X = (int) X;
    51   Y = MAX(0.5*(DY - dy*expand) - image[0].Y, 0);
    52   if ((int)Y != Y)
    53     Y = (int) Y + 1;
    54   else
    55     Y = (int) Y;
     45  // Ix, Iy are the image coordinates of the 0,0 screen pixel
     46  Screen_to_Image (&Ix, &Iy, 0.0, 0.0, &image[0].picture);
    5647
    57   /* Rx,Ry are the screen coordinates of the first image pixel */
    58   Rx = (X + image[0].X - 0.5*DX)/expand + 0.5*dx;
    59   Ry = (Y + image[0].Y - 0.5*DY)/expand + 0.5*dy;
     48  // Ix, Iy are now limited to valid image coordinates
     49  Ix = MIN (MAX (Ix, 0), DX);
     50  Iy = MIN (MAX (Iy, 0), DY);
    6051
    61   i_start = MIN (MAX (Rx, 0), dx - expand_out + 1);
    62   j_start = MIN (MAX (Ry, 0), dy - expand_out + 1);
    63  
    64   if (image[0].expand > 0) {
    65     i_end = MAX (MIN (i_start + ((int)(expand*(dx-i_start)))/expand, expand_out*(DX-X) + Rx), 0);
    66     j_end = MAX (MIN (j_start + ((int)(expand*(dy-j_start)))/expand, expand_out*(DY-Y) + Ry), 0);
    67   } else {
    68     i_end = MAX (MIN (dx, (DX-X)/expand + Rx), 0);
    69     j_end = MAX (MIN (dy, (DY-Y)/expand + Ry), 0);
    70   }   
     52  // Sx, Sy are the screen coordinates of the Ix,Iy pixel
     53  Image_to_Screen (&Sx, &Sy, Ix,  Iy,  &image[0].picture);
     54
     55  // i_start, j_start are now limited to valid screen coordinates
     56  i_start = MIN (MAX (Sx, 0), dx);
     57  j_start = MIN (MAX (Sy, 0), dy);
     58
     59  // Ix, Iy are the image coordinates of the 0,0 screen pixel
     60  Screen_to_Image (&Ix, &Iy, dx, dy, &image[0].picture);
     61
     62  // Ix, Iy are now limited to valid image coordinates
     63  Ix = MIN (MAX (Ix, 0), DX);
     64  Iy = MIN (MAX (Iy, 0), DY);
     65
     66  // Sx, Sy are the screen coordinates of the Ix,Iy pixel
     67  Image_to_Screen (&Sx, &Sy, Ix,  Iy,  &image[0].picture);
     68
     69  // i_end, j_end are now limited to valid screen coordinates
     70  i_end = MIN (MAX (Sx, 0), dx);
     71  j_end = MIN (MAX (Sy, 0), dy);
    7172
    7273  dropback = expand_out - (i_end - i_start) % expand_out;
     
    7475
    7576  out_pix = (unsigned int *) image[0].picture.data;
    76   in_pix  = &image[0].pixmap[DX*(int)MAX(Y,0) + (int)MAX(X,0)];
     77  in_pix  = &image[0].pixmap[DX*(int)MAX(Iy,0) + (int)MAX(Ix,0)];
    7778
    7879  /********** below we do the mapping from buffer pixels (in) to picture pixels (out) **********/
  • trunk/Ohana/src/kapa2/src/Remap8.c

    r16011 r16228  
    11# include "Ximage.h"
    2 
    3 static float slope = 1.0;
    4 static float start = 0.0;
    5 static int MaxValue = 255;
    6 
    7 // XXX inline this if needed
    8 static int PixelLookup(float value) {
    9   int out;
    10   out = MIN (MAX (slope * value - start, 0), MaxValue);
    11   return (out);
    12 }
    132
    143void Remap8 (Graphic *graphic, KapaImageWidget *image, Matrix *matrix) {
     
    187  int dropback;  /* this is a bit of a kludge... */
    198  int dx, dy, DX, DY, pixelN;
    20   double expand, Rx, Ry, X, Y;
     9  double expand, Sx, Sy, Ix, Iy;
    2110  int expand_in, expand_out;
    2211  unsigned char *out_pix, *out_pix2;
    23   float *imdata, *in_pix,  *in_pix2;
    24   unsigned long pixel[256], pixvalue;
     12  unsigned short *in_pix,  *in_pix2;
     13  unsigned long *pixel, pixvalue;
    2514  unsigned long back;
    2615
     16  ALLOCATE (pixel, unsigned long, graphic[0].Npixels);
     17
    2718  // local array for pixel values
    28   for (i = 0; i < 256; i++) {
     19  for (i = 0; i < graphic[0].Npixels; i++) {
    2920    pixel[i] = graphic[0].cmap[i].pixel;
    3021  }
    3122  back = graphic[0].back;
    32 
    33   // define the color transform parameters
    34   MaxValue = graphic[0].Npixels - 1;
    35   if (image[0].image[0].range != 0.0) {
    36     slope = graphic[0].Npixels / image[0].image[0].range;
    37     start = graphic[0].Npixels * image[0].image[0].zero / image[0].image[0].range;
    38   } else {
    39     slope = 1.0;
    40     start = image[0].image[0].zero;
    41   }
    4223
    4324  // set up expansions
     
    6344
    6445  /* X,Y are the image coordinates of the first image pixel */
    65   X = MAX(0.5*(DX - dx*expand) - image[0].X, 0);
    66   if ((int)X != X)
    67     X = (int) X + 1;
     46  Ix = MAX(0.5*(DX - dx*expand) - image[0].X, 0);
     47  if ((int)Ix != Ix)
     48    Ix = (int) Ix + 1;
    6849  else
    69     X = (int) X;
    70   Y = MAX(0.5*(DY - dy*expand) - image[0].Y, 0);
    71   if ((int)Y != Y)
    72     Y = (int) Y + 1;
     50    Ix = (int) Ix;
     51  Iy = MAX(0.5*(DY - dy*expand) - image[0].Y, 0);
     52  if ((int)Iy != Iy)
     53    Iy = (int) Iy + 1;
    7354  else
    74     Y = (int) Y;
     55    Iy = (int) Iy;
    7556
    76   /* Rx,Ry are the screen coordinates of the first image pixel */
    77   Rx = (X + image[0].X - 0.5*DX)/expand + 0.5*dx;
    78   Ry = (Y + image[0].Y - 0.5*DY)/expand + 0.5*dy;
     57  /* Sx,Sy are the screen coordinates of the first image pixel */
     58  Sx = (Ix + image[0].X - 0.5*DX)/expand + 0.5*dx;
     59  Sy = (Iy + image[0].Y - 0.5*DY)/expand + 0.5*dy;
    7960
    80   i_start = MIN (MAX (Rx, 0), dx - expand_out + 1);
    81   j_start = MIN (MAX (Ry, 0), dy - expand_out + 1);
     61  i_start = MIN (MAX (Sx, 0), dx - expand_out + 1);
     62  j_start = MIN (MAX (Sy, 0), dy - expand_out + 1);
    8263 
    8364  if (image[0].expand > 0) {
    84     i_end = MAX (MIN (i_start + ((int)(expand*(dx-i_start)))/expand, expand_out*(DX-X) + Rx), 0);
    85     j_end = MAX (MIN (j_start + ((int)(expand*(dy-j_start)))/expand, expand_out*(DY-Y) + Ry), 0);
     65    i_end = MAX (MIN (i_start + ((int)(expand*(dx-i_start)))/expand, expand_out*(DX-Ix) + Sx), 0);
     66    j_end = MAX (MIN (j_start + ((int)(expand*(dy-j_start)))/expand, expand_out*(DY-Iy) + Sy), 0);
    8667  } else {
    87     i_end = MAX (MIN (dx, (DX-X)/expand + Rx), 0);
    88     j_end = MAX (MIN (dy, (DY-Y)/expand + Ry), 0);
     68    i_end = MAX (MIN (dx, (DX-Ix)/expand + Sx), 0);
     69    j_end = MAX (MIN (dy, (DY-Iy)/expand + Sy), 0);
    8970  }   
    9071
     
    9374
    9475  out_pix = (unsigned char *) image[0].picture.data;
    95   imdata  = (float *) matrix[0].buffer;
    96   in_pix  = &imdata[(int)(DX*(int)MAX(Y,0) + (int)MAX(X,0))];
     76  in_pix  = &image[0].pixmap[DX*(int)MAX(Iy,0) + (int)MAX(Ix,0)];
    9777
    9878  /********** below we do the mapping from buffer pixels (in) to picture pixels (out) **********/
     
    11797    if (expand_out == 1) {
    11898      for (i = i_start; i < i_end; i++, in_pix2+= expand_in, out_pix++) {
    119         pixelN = PixelLookup(*in_pix2);
    120         *out_pix = pixel[pixelN];
     99        *out_pix = pixel[*in_pix2];
    121100      }
    122101    } else {
    123102      for (i = i_start; i < i_end; i+= expand_out, in_pix2++, out_pix+= expand_out) {
    124         pixelN   = PixelLookup(*in_pix2);
    125         pixvalue = pixel[pixelN];
     103        pixvalue = pixel[*in_pix2];
    126104        out_pix2 = out_pix;
    127105        for (jj = 0; jj < expand_out; jj++, out_pix2+=(dx-expand_out)) {
  • trunk/Ohana/src/kapa2/src/Reorient.c

    r16011 r16228  
    33void Reorient (Graphic *graphic, KapaImageWidget *image, double X, double Y, int mode) {
    44
    5   if (image[0].expand == 0) image[0].expand = 1;
     5  Picture *picture;
    66
    7   if ((image[0].X == X) && (image[0].Y == Y) && (mode == 0)) {
     7  picture = &image[0].picture;
     8
     9  if (picture[0].expand == 0) picture[0].expand = 1;
     10
     11  if ((picture[0].X == X) && (picture[0].Y == Y) && (mode == 0)) {
    812    Refresh ();
    913    XFlush (graphic[0].display);
     
    1317  switch (mode) {
    1418  case 0:
    15     if ((image[0].X != X) || (image[0].Y != Y)) {
    16       image[0].X = X;
    17       image[0].Y = Y;
     19    if ((picture[0].X != X) || (picture[0].Y != Y)) {
     20      picture[0].X = X;
     21      picture[0].Y = Y;
    1822    }
    1923    break;
    2024  case -1:
    21     image[0].expand--;
    22     if ((image[0].expand == 0) || (image[0].expand == -1))
    23       image[0].expand = -2;
    24     if (image[0].expand < -30) {
    25       fprintf (stderr, "can't get smaller!\n");
    26       image[0].expand = -30;
    27       return;
    28     }
    29     image[0].X = X;
    30     image[0].Y = Y;
     25    picture[0].expand--;
     26    if ((picture[0].expand == 0) || (picture[0].expand == -1)) picture[0].expand = -2;
     27    picture[0].X = X;
     28    picture[0].Y = Y;
    3129    break;
    3230  case +1:
    33     image[0].expand++;
    34     if ((image[0].expand == 0) || (image[0].expand == -1))
    35       image[0].expand = 1;
    36     if (image[0].expand > 30) {
    37       fprintf (stderr, "can't get bigger!\n");
    38       image[0].expand = 30;
    39       return;
    40     }
    41     image[0].X = X;
    42     image[0].Y = Y;
     31    picture[0].expand++;
     32    if ((picture[0].expand == 0) || (picture[0].expand == -1)) picture[0].expand = 1;
     33    picture[0].X = X;
     34    picture[0].Y = Y;
    4335    break;
    4436  }
     
    4941  XFlush (graphic[0].display);
    5042}
    51 
    52 # if (0) /* the "warp" function seems to be a problem on SUNs for some reason */
    53   XQueryPointer (graphic[0].display, graphic[0].window, &dummy1, &dummy1, &dummy2, &dummy2, &x, &y, &dummy3);
    54   if ((x > image[0].picture.x) && (x < image[0].picture.x + image[0].picture.dx) &&
    55       (y > image[0].picture.y) && (y < image[0].picture.y + image[0].picture.dy) &&
    56       ((mouse_event[0].button == 2) || (mouse_event[0].button == 3))) {
    57     XWarpPointer (graphic[0].display, None, graphic[0].window, 0, 0, 0, 0,
    58                   image[0].picture.x + 0.5*image[0].picture.dx,
    59                   image[0].picture.y + 0.5*image[0].picture.dy);
    60   }
    61 # endif
    62 
  • trunk/Ohana/src/kapa2/src/SetImageData.c

    r16011 r16228  
    125125  image = section->image;
    126126
    127   Screen_to_Image (&Xmin, &Ymin, 0.0, 0.0, image);
    128   Screen_to_Image (&Xmax, &Ymax, image[0].picture.dx, image[0].picture.dy, image);
     127  Screen_to_Image (&Xmin, &Ymin, 0.0, 0.0, &image[0].picture);
     128  Screen_to_Image (&Xmax, &Ymax, image[0].picture.dx, image[0].picture.dy, &image[0].picture);
    129129
    130130  KiiSendMessage (sock, "%g %g %g %g", Xmin, Xmax, Ymin, Ymax);
  • trunk/Ohana/src/kapa2/src/UpdatePointer.c

    r16011 r16228  
    11# include "Ximage.h"
    2 # define FRAC(a) ((a) - (int)(a))
    32
    43int UpdatePointer (Graphic *graphic, XMotionEvent *event) {
     
    2019
    2120    data = (float *) image[0].image[0].matrix.buffer;
    22     Screen_to_Image (&x, &y, (double)event[0].x, (double)event[0].y, image);
     21    Screen_to_Image (&x, &y, (double)event[0].x, (double)event[0].y, &image[0].picture);
    2322
    2423    z = -1;
     
    3029
    3130  skip:
    32     image[0].x = x;
    33     image[0].y = y;
    34     image[0].z = z;
     31    image[0].zoom.X = x;
     32    image[0].zoom.Y = Y;
    3533   
    3634    UpdateStatusBox (graphic, image, x, y, z, 0);
  • trunk/Ohana/src/kapa2/src/bDrawOverlay.c

    r15620 r16228  
    2424  }
    2525
    26   Image_to_Screen (&X0, &Y0, 0.0, 0.0, image);
     26  Image_to_Screen (&X0, &Y0, 0.0, 0.0, &image[0].picture);
    2727  X0 -= image[0].picture.x;
    2828  Y0 -= image[0].picture.y;
Note: See TracChangeset for help on using the changeset viewer.