IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 16256


Ignore:
Timestamp:
Jan 27, 2008, 1:24:12 PM (18 years ago)
Author:
eugene
Message:

unified zoom and remap functions to include flips and wide-view image

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

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/kapa2/Makefile

    r16039 r16256  
    6161$(SRC)/DrawButton.$(ARCH).o               $(SRC)/DrawBitmap.$(ARCH).o         \
    6262$(SRC)/hh_hms.$(ARCH).o                   $(SRC)/CreateZoom.$(ARCH).o         \
    63 $(SRC)/CreateZoom8.$(ARCH).o              $(SRC)/CreateZoom16.$(ARCH).o       \
    64 $(SRC)/CreateZoom24.$(ARCH).o             $(SRC)/CreateZoom32.$(ARCH).o       \
    6563$(SRC)/CreatePicture.$(ARCH).o            $(SRC)/CreateColorbar.$(ARCH).o     \
    6664$(SRC)/MakeColormap.$(ARCH).o             $(SRC)/SetColormap.$(ARCH).o        \
     
    8179$(SRC)/ColorHistogram.$(ARCH).o           
    8280
     81#$(SRC)/CreateZoom8.$(ARCH).o              $(SRC)/CreateZoom16.$(ARCH).o       \
     82#$(SRC)/CreateZoom24.$(ARCH).o             $(SRC)/CreateZoom32.$(ARCH).o       \
     83
    8384OBJ  =  $(KAPA)
    8485
  • trunk/Ohana/src/kapa2/include/prototypes.h

    r16255 r16256  
    146146int           SetColorScale3D     PROTO((Graphic *graphic, KapaImageWidget *image));
    147147void          Remap               PROTO((Graphic *graphic, KapaImageWidget *image));
    148 void          Remap8              PROTO((Graphic *graphic, KapaImageWidget *image, Matrix *matrix));
    149 void          Remap16             PROTO((Graphic *graphic, KapaImageWidget *image, Matrix *matrix));
    150 void          Remap24             PROTO((Graphic *graphic, KapaImageWidget *image, Matrix *matrix));
    151 void          Remap32             PROTO((Graphic *graphic, KapaImageWidget *image, Matrix *matrix));
     148void          Remap8              PROTO((Graphic *graphic, KapaImageWidget *image, Picture *picture, Matrix *matrix));
     149void          Remap16             PROTO((Graphic *graphic, KapaImageWidget *image, Picture *picture, Matrix *matrix));
     150void          Remap24             PROTO((Graphic *graphic, KapaImageWidget *image, Picture *picture, Matrix *matrix));
     151void          Remap32             PROTO((Graphic *graphic, KapaImageWidget *image, Picture *picture, Matrix *matrix));
    152152int           LoadPicture         PROTO((int sock));
    153153
     
    171171void          PaintTickmarks      PROTO((Graphic *graphic, KapaImageWidget *image));
    172172
     173void          Picture_to_Image    PROTO((double *x1, double *y1, double x2, double y2, Picture *picture));
    173174void          Screen_to_Image     PROTO((double *x1, double *y1, double x2, double y2, Picture *picture));
     175void          Image_to_Picture    PROTO((double *x1, double *y1, double x2, double y2, Picture *picture));
    174176void          Image_to_Screen     PROTO((double *x1, double *y1, double x2, double y2, Picture *picture));
     177void          Picture_Lower       PROTO((int *i_start, int *j_start, Matrix *matrix, Picture *picture));
     178void          Picture_Upper       PROTO((int *i_end, int *j_end, Matrix *matrix, Picture *picture));
    175179
    176180void          DragColorbar        PROTO((Graphic *graphic, KapaImageWidget *image, XButtonEvent *mouse_event));
     
    214218void          CreatePicture (KapaImageWidget *image, Graphic *graphic);
    215219void          CreateColorbar (KapaImageWidget *image, Graphic *graphic);
    216 void          CreateZoom (KapaImageWidget *image, Graphic *graphic, double x, double y);
     220void          CreateZoom (Graphic *graphic, KapaImageWidget *image);
    217221void          UpdateStatusBox (Graphic *graphic, KapaImageWidget *image, double x, double y, double z, int mode);
    218222
    219 void          CreateZoom8  (KapaImageWidget *image, Graphic *graphic, double x, double y);
    220 void          CreateZoom16 (KapaImageWidget *image, Graphic *graphic, double x, double y);
    221 void          CreateZoom24 (KapaImageWidget *image, Graphic *graphic, double x, double y);
    222 void          CreateZoom32 (KapaImageWidget *image, Graphic *graphic, double x, double y);
     223// void               CreateZoom8  (KapaImageWidget *image, Graphic *graphic, double x, double y);
     224// void               CreateZoom16 (KapaImageWidget *image, Graphic *graphic, double x, double y);
     225// void               CreateZoom24 (KapaImageWidget *image, Graphic *graphic, double x, double y);
     226// void               CreateZoom32 (KapaImageWidget *image, Graphic *graphic, double x, double y);
    223227
    224228int           GetActiveSocket ();
  • trunk/Ohana/src/kapa2/include/structures.h

    r16255 r16256  
    9494  int      DX, DY;            // size of displayed picture (must be updated with new images...)
    9595  int      expand;            // zoomscale
    96   double   X,  Y;             // offset of image center
    97   double   Xo, Yo;            // reference image pixel (picture has X - Xo at center)
     96  double   X,  Y;             // center of image in picture
    9897  XImage  *pix;
    9998  char    *data;
  • trunk/Ohana/src/kapa2/src/ButtonFunctions.c

    r16255 r16256  
    1414  SetColorScale (graphic, image);
    1515  Remap (graphic, image);
    16   CreateZoom (image, graphic, 0, 0);
     16  CreateZoom (graphic, image);
    1717  Refresh ();
    1818  XFlush (graphic[0].display);
     
    2525  SetColorScale (graphic, image);
    2626  Remap (graphic, image);
    27   CreateZoom (image, graphic, 0, 0);
     27  CreateZoom (graphic, image);
    2828  Refresh ();
    2929  XFlush (graphic[0].display);
     
    3636  SetColorScale (graphic, image);
    3737  Remap (graphic, image);
    38   CreateZoom (image, graphic, 0, 0);
     38  CreateZoom (graphic, image);
    3939  Refresh ();
    4040  XFlush (graphic[0].display);
     
    4444int Recenter (Graphic *graphic, KapaImageWidget *image) {
    4545
    46   image[0].picture.X = 0;
    47   image[0].picture.Y = 0;
     46  image[0].picture.X = 0.5*image[0].image[0].matrix.Naxis[0];
     47  image[0].picture.Y = 0.5*image[0].image[0].matrix.Naxis[1];
    4848 
    4949  Remap (graphic, image);
     
    6666int RecenterRescale (Graphic *graphic, KapaImageWidget *image) {
    6767
    68   image[0].picture.X = 0;
    69   image[0].picture.Y = 0;
     68  image[0].picture.X = 0.5*image[0].image[0].matrix.Naxis[0];
     69  image[0].picture.Y = 0.5*image[0].image[0].matrix.Naxis[1];
    7070  image[0].picture.expand = 1;
    7171 
  • trunk/Ohana/src/kapa2/src/Center.c

    r16255 r16256  
    1616  if (image == NULL) return (TRUE);
    1717
    18   image[0].picture.Xo = 0.5*image[0].image[0].matrix.Naxis[0] - X;
    19   image[0].picture.Yo = 0.5*image[0].image[0].matrix.Naxis[1] - Y;
     18  image[0].picture.X = X;
     19  image[0].picture.Y = Y;
    2020  if ((zoom != 0) && (zoom != -1)) {
    2121    image[0].picture.expand = zoom;
  • trunk/Ohana/src/kapa2/src/CreatePicture.c

    r13479 r16256  
    5555
    5656  case 32:
    57     REALLOCATE (image[0].picture.data, char, (4*image[0].picture.dx*image[0].picture.dy + 32));
    58     memset (image[0].picture.data, 0xbd, 4*image[0].picture.dx*image[0].picture.dy + 30);
     57    REALLOCATE (image[0].zoom.data,    char, 4*image[0].zoom.dx*image[0].zoom.dy);
     58    REALLOCATE (image[0].picture.data, char, 4*image[0].picture.dx*image[0].picture.dy);
    5959    l = (unsigned int *) image[0].picture.data;
    6060    for (i = 0; i < (image[0].picture.dx*image[0].picture.dy); i++, l++)
  • trunk/Ohana/src/kapa2/src/CreateZoom.c

    r13320 r16256  
    11# include "Ximage.h"
    22
    3 void CreateZoom (KapaImageWidget *image, Graphic *graphic, double x, double y) {
     3void CreateZoom (Graphic *graphic, KapaImageWidget *image) {
    44
    55  switch (graphic[0].Nbits) {
    66  case 8:
    7     CreateZoom8 (image, graphic, x, y);
     7    Remap8  (graphic, image, &image->zoom, &image->image->matrix);
    88    break;
    9 
    109  case 16:
    11     CreateZoom16 (image, graphic, x, y);
     10    Remap16 (graphic, image, &image->zoom, &image->image->matrix);
    1211    break;
    13 
    1412  case 24:
    15     CreateZoom24 (image, graphic, x, y);
     13    Remap24 (graphic, image, &image->zoom, &image->image->matrix);
    1614    break;
    17 
    1815  case 32:
    19     CreateZoom32 (image, graphic, x, y);
     16    Remap32 (graphic, image, &image->zoom, &image->image->matrix);
    2017    break;
    2118  }   
  • trunk/Ohana/src/kapa2/src/CreateZoom16.c

    r16255 r16256  
    11# include "Ximage.h"
    2 # define FRAC(a) ((a) - (int)(a))
    3 
    4 static float slope = 1.0;
    5 static float start = 0.0;
    6 static int MaxValue = 255;
    7 
    8 // XXX inline this if needed
    9 static int PixelLookup(float value) {
    10   int out;
    11   out = MIN (MAX (slope * value - start, 0), MaxValue);
    12   return (out);
    13 }
    142
    153void CreateZoom16 (KapaImageWidget *image, Graphic *graphic, double x, double y) {
  • trunk/Ohana/src/kapa2/src/CreateZoom24.c

    r16255 r16256  
    11# include "Ximage.h"
    2 # define FRAC(a) ((a) - (int)(a))
    3 
    4 static float slope = 1.0;
    5 static float start = 0.0;
    6 static int MaxValue = 255;
    7 
    8 // XXX inline this if needed
    9 static int PixelLookup(float value) {
    10   int out;
    11   out = MIN (MAX (slope * value - start, 0), MaxValue);
    12   return (out);
    13 }
    142
    153void CreateZoom24 (KapaImageWidget *image, Graphic *graphic, double x, double y) {
  • trunk/Ohana/src/kapa2/src/CreateZoom32.c

    r16255 r16256  
    11# include "Ximage.h"
    2 # define FRAC(a) ((a) - (int)(a))
    32
    43void CreateZoom32 (KapaImageWidget *image, Graphic *graphic, double x, double y) {
     
    87  int dropback;  /* this is a bit of a kludge... */
    98  int dx, dy, DX, DY;
    10   double expand, Sx, Sy, Ix, Iy;
     9  double expand, Ix, Iy;
    1110  int expand_in, expand_out;
    1211  unsigned int *out_pix, *out_pix2;
     
    5049  DY = image[0].image[0].matrix.Naxis[1];
    5150 
    52   // Ix, Iy are the image coordinates of the 0,0 screen pixel
    53   Screen_to_Image (&Ix, &Iy, 0.0, 0.0, &image[0].picture);
     51  // x, y are the closest lit screen pixel to 0,0
     52  Picture_Lower (&i_start, &j_start, &image[0].image[0].matrix, &image[0].zoom);
    5453
    55   // Ix, Iy are now limited to valid image coordinates
    56   Ix = MIN (MAX (Ix, 0), DX);
    57   Iy = MIN (MAX (Iy, 0), DY);
     54  // x, y are the closest lit screen pixel to dx, dy
     55  Picture_Upper (&i_end, &j_end, &image[0].image[0].matrix, &image[0].zoom);
    5856
    59   // Sx, Sy are the screen coordinates of the Ix,Iy pixel
    60   Image_to_Screen (&Sx, &Sy, Ix,  Iy,  &image[0].picture);
    61 
    62   // i_start, j_start are now limited to valid screen coordinates
    63   i_start = MIN (MAX (Sx, 0), dx);
    64   j_start = MIN (MAX (Sy, 0), dy);
    65 
    66   // Ix, Iy are the image coordinates of the 0,0 screen pixel
    67   Screen_to_Image (&Ix, &Iy, dx, dy, &image[0].picture);
    68 
    69   // Ix, Iy are now limited to valid image coordinates
    70   Ix = MIN (MAX (Ix, 0), DX);
    71   Iy = MIN (MAX (Iy, 0), DY);
    72 
    73   // Sx, Sy are the screen coordinates of the Ix,Iy pixel
    74   Image_to_Screen (&Sx, &Sy, Ix,  Iy,  &image[0].picture);
    75 
    76   // i_end, j_end are now limited to valid screen coordinates
    77   i_end = MIN (MAX (Sx, 0), dx);
    78   j_end = MIN (MAX (Sy, 0), dy);
     57  // Ix,Iy are the first displayed image pixel
     58  Picture_to_Image (&Ix, &Iy, i_start, j_start, &image[0].zoom);
    7959
    8060  dropback = expand_out - (i_end - i_start) % expand_out;
     
    9272    return;
    9373  }
    94  
    9574
    9675  /**** fill in bottom area ****/
     
    11796      }
    11897    } else {
     98      // equiv to : out_pix += (i_end - i_start) + [expand_out - (i_end - i_start) % expand_out]
    11999      for (i = i_start; i < i_end; i+= expand_out, in_pix2++, out_pix+= expand_out) {
    120100        pixvalue = pixel[*in_pix2];
     
    137117    }
    138118    out_pix += (dx - i_end);
     119    assert (out_pix - (unsigned int *)image[0].zoom.data <= dx*dy);
    139120  }
     121  assert (out_pix - (unsigned int *)image[0].zoom.data <= dx*dy);
    140122 
    141123  if ((j_end - j_start) % expand_out > 0)
    142124    out_pix -= (expand_out - (j_end - j_start) % expand_out);
    143125 
     126  assert (out_pix - (unsigned int *)image[0].zoom.data <= dx*dy);
     127
    144128  /**** fill in top area ****/
    145129  for (j = 0; (j < dx*(dy - j_end)) && (out_pix - (unsigned int *)image[0].zoom.data < dx*dy); j++, out_pix++) {
    146130    *out_pix = back;
    147131  }
     132  assert (out_pix - (unsigned int *)image[0].zoom.data <= dx*dy);
    148133
    149134  image[0].zoom.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0,
  • trunk/Ohana/src/kapa2/src/CreateZoom8.c

    r16255 r16256  
    11# include "Ximage.h"
    2 # define FRAC(a) ((a) - (int)(a))
    3 
    4 static float slope = 1.0;
    5 static float start = 0.0;
    6 static int MaxValue = 255;
    7 
    8 // XXX inline this if needed
    9 static int PixelLookup(float value) {
    10   int out;
    11   out = MIN (MAX (slope * value - start, 0), MaxValue);
    12   return (out);
    13 }
    142
    153void CreateZoom8 (KapaImageWidget *image, Graphic *graphic, double x, double y) {
  • trunk/Ohana/src/kapa2/src/CursorOps.c

    r16255 r16256  
    11# include "Ximage.h"
    22
    3 void Screen_to_Image (double *x1, double *y1, double x2, double y2, Picture *picture) {
     3// input coordinates are relative to the picture bounding box
     4void Picture_to_Image (double *x1, double *y1, double x2, double y2, Picture *picture) {
    45
    5   double xs, ys, expand;
     6  double expand;
    67
    78  expand = 1.0;
     
    1213  }
    1314 
    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;
     15  // picture[0].X,Y is the image coordinate in the center of the picture
     16  *x1 = expand*(x2 - 0.5*picture[0].dx) + picture[0].X;
     17  *y1 = expand*(y2 - 0.5*picture[0].dy) + picture[0].Y;
    2118}
    2219
    23 void Image_to_Screen (double *x1, double *y1, double x2, double y2, Picture *picture) {
     20// input coordinates are relative to the X window
     21void Screen_to_Image (double *x1, double *y1, double x2, double y2, Picture *picture) {
    2422
    25   double xs, ys, expand;
     23  double xp, yp;
     24
     25  // pixel coordinates in picture frame
     26  xp = x2 - picture[0].x;
     27  yp = y2 - picture[0].y;
     28
     29  Picture_to_Image (x1, y1, xp, yp, picture);
     30}
     31
     32void Image_to_Picture (double *x1, double *y1, double x2, double y2, Picture *picture) {
     33
     34  double expand;
    2635
    2736  /* notice that here, expand is the reciprocal of the expand above */
     
    3443 
    3544  // 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;
     45  *x1 = expand*(x2 - picture[0].X) + 0.5*picture[0].dx;
     46  *y1 = expand*(y2 - picture[0].Y) + 0.5*picture[0].dy;
     47}
     48
     49void Image_to_Screen (double *x1, double *y1, double x2, double y2, Picture *picture) {
     50
     51  double xp, yp;
     52
     53  Image_to_Picture (&xp, &yp, x2, y2, picture);
    3854
    3955  // pixel coordinates in screen frame
    40   *x1 = xs + picture[0].x;
    41   *y1 = ys + picture[0].y;
     56  *x1 = xp + picture[0].x;
     57  *y1 = yp + picture[0].y;
    4258}
    4359
     60// input coordinates are relative to the picture bounding box
     61void Picture_Lower (int *i_start, int *j_start, Matrix *matrix, Picture *picture) {
     62
     63  double Ix, Iy, Sx, Sy;
     64
     65  // Ix, Iy are the image coordinates of the specified screen pixel
     66  Picture_to_Image (&Ix, &Iy, 0.0, 0.0, picture);
     67
     68  // Ix, Iy are now limited to valid image coordinates
     69  Ix = MIN (MAX (Ix, 0), matrix[0].Naxis[0]);
     70  Iy = MIN (MAX (Iy, 0), matrix[0].Naxis[1]);
     71
     72  // round up to nearest pixel boundary
     73  if (Ix > (int)(Ix)) Ix = (int)(Ix) + 1;
     74  if (Iy > (int)(Iy)) Iy = (int)(Iy) + 1;
     75
     76  // Sx, Sy are the screen coordinates of the Ix,Iy pixel
     77  Image_to_Picture (&Sx, &Sy, Ix, Iy, picture);
     78
     79  // i_start, j_start are now limited to valid screen coordinates
     80  *i_start = MIN (MAX (Sx, 0), picture[0].dx);
     81  *j_start = MIN (MAX (Sy, 0), picture[0].dy);
     82}
     83 
     84// input coordinates are relative to the picture bounding box
     85void Picture_Upper (int *i_end, int *j_end, Matrix *matrix, Picture *picture) {
     86
     87  double Ix, Iy, Sx, Sy;
     88
     89  // Ix, Iy are the image coordinates of the specified screen pixel
     90  Picture_to_Image (&Ix, &Iy, picture[0].dx, picture[0].dy, picture);
     91
     92  // Ix, Iy are now limited to valid image coordinates
     93  Ix = MIN (MAX (Ix, 0), matrix[0].Naxis[0]);
     94  Iy = MIN (MAX (Iy, 0), matrix[0].Naxis[1]);
     95
     96  // round down to nearest pixel boundary
     97  if (Ix > (int)(Ix)) Ix = (int)(Ix);
     98  if (Iy > (int)(Iy)) Iy = (int)(Iy);
     99
     100  // Sx, Sy are the screen coordinates of the Ix,Iy pixel
     101  Image_to_Picture (&Sx, &Sy, Ix, Iy, picture);
     102
     103  // i_start, j_start are now limited to valid screen coordinates
     104  *i_end = MIN (MAX (Sx, 0), picture[0].dx);
     105  *j_end = MIN (MAX (Sy, 0), picture[0].dy);
     106}
  • trunk/Ohana/src/kapa2/src/Image.c

    r16255 r16256  
    5050  image[0].picture.X      = 0.0;
    5151  image[0].picture.Y      = 0.0;
    52   image[0].picture.Xo     = 0.0;
    53   image[0].picture.Yo     = 0.0;
    5452  image[0].picture.expand = 1;
    5553
    5654  image[0].zoom.X         = 0.0;
    5755  image[0].zoom.Y         = 0.0;
    58   image[0].zoom.Xo        = 0.0;
    59   image[0].zoom.Yo        = 0.0;
    6056  image[0].zoom.expand    = +5;
    6157
    6258  image[0].wide.X         = 0.0;
    6359  image[0].wide.Y         = 0.0;
    64   image[0].wide.Xo        = 0.0;
    65   image[0].wide.Yo        = 0.0;
    6660  image[0].wide.expand    = -5;
    6761
  • trunk/Ohana/src/kapa2/src/InterpretKeys.c

    r16255 r16256  
    118118    case XK_End:
    119119      image[0].picture.expand = 1;
    120       Reorient (graphic, image, 0, 0, 0);
     120      Reorient (graphic, image, 0.5*image[0].image[0].matrix.Naxis[0], 0.5*image[0].image[0].matrix.Naxis[1], 0);
    121121      break;
    122122    case XK_KP_Enter:
    123123    case XK_KP_Begin:
    124124    case XK_Return:
    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;
     125      Screen_to_Image (&X, &Y, event[0].x + 0.5, event[0].y + 0.5, &image[0].picture);
    128126      Reorient (graphic, image, X, Y, 0);
    129127      break;
  • trunk/Ohana/src/kapa2/src/InterpretPresses.c

    r16228 r16256  
    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[0].picture);
     36      Screen_to_Image (&X, &Y, event[0].x + 0.5, event[0].y + 0.5, &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[0].picture);
    104   X = 0.5*image[0].image[0].matrix.Naxis[0] - X;
    105   Y = 0.5*image[0].image[0].matrix.Naxis[1] - Y;
     103  Screen_to_Image (&X, &Y, mouse_event[0].x + 0.5, mouse_event[0].y + 0.5, &image[0].picture);
    106104
    107105  switch (mouse_event[0].button) {
  • trunk/Ohana/src/kapa2/src/JPEGit24.c

    r16255 r16256  
    88// XXX this currently writes out the jpeg for just the active image
    99int JPEGit24 (int sock) {
    10 
    11 # if (0)
    1210
    1311  struct jpeg_compress_struct cinfo;
     
    2624  int quality;
    2725  int expand_in, expand_out;
    28   double expand, Rx, Ry, X, Y;
     26  double expand, Ix, Iy;
    2927  unsigned char *out_pix;
    3028  unsigned short *in_pix, *in_pix_ref;
     
    9593  DY = image[0].image[0].matrix.Naxis[1];
    9694
    97   /* X,Y are the image coordinates of the first image pixel */
    98   X = MAX(0.5*(DX - dx*expand) - image[0].X, 0);
    99   if ((int)X != X)
    100     X = (int) X + 1;
    101   else
    102     X = (int) X;
    103   Y = MAX(0.5*(DY - dy*expand) - image[0].Y, 0);
    104   if ((int)Y != Y)
    105     Y = (int) Y + 1;
    106   else
    107     Y = (int) Y;
    108 
    109   /* Rx,Ry are the screen coordinates of the first image pixel */
    110   Rx = (X + image[0].X - 0.5*DX)/expand + 0.5*dx;
    111   Ry = (Y + image[0].Y - 0.5*DY)/expand + 0.5*dy;
    112 
    113   i_start = MIN (MAX (Rx, 0), dx - expand_out + 1);
    114   j_start = MIN (MAX (Ry, 0), dy - expand_out + 1);
    115  
    116   if (image[0].expand > 0) {
    117     i_end = MAX (MIN (i_start + ((int)(expand*(dx-i_start)))/expand, expand_out*(DX-X) + Rx), 0);
    118     j_end = MAX (MIN (j_start + ((int)(expand*(dy-j_start)))/expand, expand_out*(DY-Y) + Ry), 0);
    119   } else {
    120     i_end = MAX (MIN (dx, (DX-X)/expand + Rx), 0);
    121     j_end = MAX (MIN (dy, (DY-Y)/expand + Ry), 0);
    122   }   
     95  // x, y are the closest lit screen pixel to 0,0
     96  Picture_Lower (&i_start, &j_start, &image[0].image[0].matrix, &image[0].picture);
     97
     98  // x, y are the closest lit screen pixel to dx, dy
     99  Picture_Upper (&i_end, &j_end, &image[0].image[0].matrix, &image[0].picture);
     100
     101  // Ix,Iy are the first displayed image pixel
     102  Picture_to_Image (&Ix, &Iy, i_start, j_start, &image[0].picture);
    123103
    124104  dropback = expand_out - (i_end - i_start) % expand_out;
     
    129109  ALLOCATE (line_buffer, JSAMPLE, 3*dx);
    130110
    131   in_pix_ref  = &image[0].pixmap[DX*(int)MAX(Y,0) + (int)MAX(X,0)];
     111  in_pix_ref  = &image[0].pixmap[DX*(int)MAX(Iy,0) + (int)MAX(Ix,0)];
    132112
    133113  /********** below we do the mapping from buffer pixels (in) to picture pixels (out) **********/
     
    233213  jpeg_destroy_compress (&cinfo);
    234214
    235 
    236 # endif
    237215  return (TRUE);
    238216}
  • trunk/Ohana/src/kapa2/src/LoadPicture.c

    r16228 r16256  
    99  KapaImageWidget *image;
    1010  Graphic *graphic;
     11  double Xoffset, Yoffset;
    1112
    1213  graphic = GetGraphic ();
     
    1920 
    2021  KiiSendMessage (sock, "%d", graphic->Npixels);
     22
     23  // when we load a new picture, use the same orientation as the old picture
     24  Xoffset = 0.0;
     25  Yoffset = 0.0;
     26  if (image[0].image[0].matrix.size) {
     27    Xoffset = image[0].picture.X - 0.5*image[0].image[0].matrix.Naxis[0];
     28    Yoffset = image[0].picture.Y - 0.5*image[0].image[0].matrix.Naxis[1];
     29  }
    2130
    2231  gfits_init_header (&header);
     
    3443
    3544  // 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];
     45  image[0].picture.X = 0.5*header.Naxis[0] + Xoffset;
     46  image[0].picture.Y = 0.5*header.Naxis[1] + Yoffset;
    3847
    3948  fcntl (sock, F_SETFL, O_NONBLOCK); 
  • trunk/Ohana/src/kapa2/src/PSPixmap.c

    r16011 r16256  
    11# include "Ximage.h"
     2
     3// XXX this stuff has been broken by the conversion to the pixmap stuff
    24
    35void PSPixmap8 (Graphic *graphic, KapaImageWidget *image, FILE *f) {
  • trunk/Ohana/src/kapa2/src/Remap.c

    r16011 r16256  
    55  switch (graphic[0].Nbits) {
    66  case 8:
    7     Remap8  (graphic, image, &image->image->matrix);
     7    Remap8  (graphic, image, &image->picture, &image->image->matrix);
    88    break;
    99  case 16:
    10     Remap16 (graphic, image, &image->image->matrix);
     10    Remap16 (graphic, image, &image->picture, &image->image->matrix);
    1111    break;
    1212  case 24:
    13     Remap24 (graphic, image, &image->image->matrix);
     13    Remap24 (graphic, image, &image->picture, &image->image->matrix);
    1414    break;
    1515  case 32:
    16     Remap32 (graphic, image, &image->image->matrix);
     16    Remap32 (graphic, image, &image->picture, &image->image->matrix);
    1717    break;
    1818  }
  • trunk/Ohana/src/kapa2/src/Remap16.c

    r16255 r16256  
    11# include "Ximage.h"
    22
    3 void Remap16 (Graphic *graphic, KapaImageWidget *image, Matrix *matrix) {
     3void Remap16 (Graphic *graphic, KapaImageWidget *image, Picture *picture, Matrix *matrix) {
    44
    5 # if (0)
    65  int i, j, ii, jj;
    76  int i_start, i_end, j_start, j_end;
    8   int dropback;  /* this is a bit of a kludge... */
     7  int dropback;
    98  int dx, dy, DX, DY;
    10   double expand, Sx, Sy, Ix, Iy;
     9  double expand, Ix, Iy;
    1110  int expand_in, expand_out;
    12   unsigned char *out_pix, *out_pix2, *data;
     11  unsigned short *out_pix, *out_pix2, *data;
    1312  unsigned short *in_pix, *in_pix2;
    14   unsigned char *pixel1, *pixel2;
    15   unsigned char pixvalue1, pixvalue2;
    16   unsigned char back1, back2;
     13  unsigned short *pixel, pixvalue;
     14  unsigned short back;
    1715
    18   ALLOCATE (pixel1, unsigned char, graphic[0].Npixels);
    19   ALLOCATE (pixel2, unsigned char, graphic[0].Npixels);
     16  ALLOCATE (pixel, unsigned short, graphic[0].Npixels);
    2017
    2118  // local array for pixel values (is this working??)
    2219  for (i = 0; i < graphic[0].Npixels; i++) { /* set up pixel array */
    23     pixel1[i] = 0x00ff &  graphic[0].cmap[i].pixel;
    24     pixel2[i] = 0x00ff & (graphic[0].cmap[i].pixel >> 8);
     20    pixel[i] = 0xffff &  graphic[0].cmap[i].pixel;
    2521  }
    26   back1 = 0x00ff & (graphic[0].back >> 0);
    27   back2 = 0x00ff & (graphic[0].back >> 8);
    28 
    29   // define the color transform parameters
    30   MaxValue = graphic[0].Npixels - 1;
    31   if (image[0].image[0].range != 0.0) {
    32     slope = graphic[0].Npixels / image[0].image[0].range;
    33     start = graphic[0].Npixels * image[0].image[0].zero / image[0].image[0].range;
    34   } else {
    35     slope = 1.0;
    36     start = image[0].image[0].zero;
    37   }
     22  back = 0xffff & graphic[0].back;
    3823
    3924  // set up expansions
     25  assert ((picture[0].expand >= 1) || (picture[0].expand <= -2));
    4026  expand = expand_in = expand_out = 1.0;
    41   if (image[0].expand == 0) /* set up expansions */
    42     image[0].expand = 1;
    43   if (image[0].expand > 0) {
    44     expand = 1 / (1.0*image[0].expand);
    45     expand_out = image[0].expand;
     27  if (picture[0].expand > 0) {
     28    expand = 1 / (1.0*picture[0].expand);
     29    expand_out = picture[0].expand;
    4630    expand_in  = 1;
    4731  }
    48   if (image[0].expand < 0) {
    49     expand = fabs((double)image[0].expand);
     32  if (picture[0].expand < 0) {
     33    expand = fabs((double)picture[0].expand);
    5034    expand_out = 1;
    51     expand_in  = -image[0].expand;
     35    expand_in  = -picture[0].expand;
    5236  }
    5337
    5438  // define the image boundaries
    55   dx = image[0].picture.dx;
    56   dy = image[0].picture.dy;
     39  dx = picture[0].dx;
     40  dy = picture[0].dy;
    5741  DX = matrix[0].Naxis[0];
    5842  DY = matrix[0].Naxis[1];
    5943
    60   /* X,Y are the image coordinates of the first image pixel */
    61   Ix = MAX(0.5*(DX - dx*expand) - image[0].X, 0);
    62   if ((int)Ix != Ix)
    63     Ix = (int) Ix + 1;
    64   else
    65     Ix = (int) Ix;
    66   Iy = MAX(0.5*(DY - dy*expand) - image[0].Y, 0);
    67   if ((int)Iy != Iy)
    68     Iy = (int) Iy + 1;
    69   else
    70     Iy = (int) Iy;
     44  // x, y are the closest lit screen pixel to 0,0
     45  Picture_Lower (&i_start, &j_start, matrix, picture);
    7146
    72   /* Sx,Sy are the screen coordinates of the first image pixel */
    73   Sx = (Ix + image[0].X - 0.5*DX)/expand + 0.5*dx;
    74   Sy = (Iy + image[0].Y - 0.5*DY)/expand + 0.5*dy;
     47  // x, y are the closest lit screen pixel to dx, dy
     48  Picture_Upper (&i_end, &j_end, matrix, picture);
    7549
    76   i_start = MIN (MAX (Sx, 0), dx - expand_out + 1);
    77   j_start = MIN (MAX (Sy, 0), dy - expand_out + 1);
    78  
    79   if (image[0].expand > 0) {
    80     i_end = MAX (MIN (i_start + ((int)(expand*(dx-i_start)))/expand, expand_out*(DX-Ix) + Sx), 0);
    81     j_end = MAX (MIN (j_start + ((int)(expand*(dy-j_start)))/expand, expand_out*(DY-Iy) + Sy), 0);
    82   } else {
    83     i_end = MAX (MIN (dx, (DX-Ix)/expand + Sx), 0);
    84     j_end = MAX (MIN (dy, (DY-Iy)/expand + Sy), 0);
    85   }   
     50  // Ix,Iy are the first displayed image pixel
     51  Picture_to_Image (&Ix, &Iy, i_start, j_start, picture);
    8652
    8753  dropback = expand_out - (i_end - i_start) % expand_out;
    8854  if ((i_end - i_start) % expand_out == 0) dropback = 0;
    8955
    90   data = out_pix = (unsigned char *) image[0].picture.data;
     56  data = out_pix = (unsigned short *) picture[0].data;
    9157  in_pix  = &image[0].pixmap[DX*(int)MAX(Iy,0) + (int)MAX(Ix,0)];
    9258
     
    9460
    9561  /**** fill in bottom area ****/
    96   for (j = 0; j < j_start; j++) {
    97     for (i = 0; i < dx; i++, out_pix+=2) {
    98       out_pix[0] = back1;
    99       out_pix[1] = back2;
    100     }
     62  for (j = 0; j < dx*j_start; j++, out_pix++) {
     63    *out_pix = back;
    10164  }
    10265 
    10366  for (j = j_start; j < j_end; j+= expand_out, in_pix += expand_in*DX) {
    104     out_pix = &data[2*j*dx];
     67    out_pix = &data[j*dx];
    10568
    10669    /**** fill in area to the left of the picture ****/
    10770    for (jj = 0; (i_start > 0) && (jj < expand_out); jj++) {
    108       out_pix2 = out_pix + 2*jj*dx;
    109       for (i = 0; i < i_start; i++, out_pix2+=2) {
    110         out_pix2[0] = back1;
    111         out_pix2[1] = back2;
     71      out_pix2 = out_pix + jj*dx;
     72      for (i = 0; i < i_start; i++, out_pix2++) {
     73        *out_pix2 = back;
    11274      }
    11375    }
    114     out_pix += 2*i_start;
     76    out_pix += i_start;
    11577   
    11678    /*** fill in the picture region ***/
    11779    in_pix2 = in_pix;
    11880    if (expand_out == 1) {
    119       for (i = i_start; i < i_end; i++, in_pix2+= expand_in, out_pix+=2) {
    120         out_pix[0] = pixel1[*in_pix2];
    121         out_pix[1] = pixel2[*in_pix2];
     81      for (i = i_start; i < i_end; i++, in_pix2+= expand_in, out_pix++) {
     82        *out_pix = pixel[*in_pix2];
    12283      }
    123     }
    124     else {
    125       for (i = i_start; i < i_end; i+= expand_out, in_pix2++, out_pix+= 2*expand_out) {
    126         pixvalue1 = pixel1[*in_pix2];
    127         pixvalue2 = pixel2[*in_pix2];
     84    } else {
     85      for (i = i_start; i < i_end; i+= expand_out, in_pix2++, out_pix+= expand_out) {
     86        pixvalue = pixel[*in_pix2];
    12887        out_pix2 = out_pix;
    129         for (jj = 0; jj < expand_out; jj++, out_pix2+=2*(dx-expand_out)) {
    130           for (ii = 0; ii < expand_out; ii++, out_pix2+=2) {
    131             out_pix2[0] = pixvalue1;
    132             out_pix2[1] = pixvalue2;
     88        for (jj = 0; jj < expand_out; jj++, out_pix2+=(dx-expand_out)) {
     89          for (ii = 0; ii < expand_out; ii++, out_pix2++) {
     90            *out_pix2 = pixvalue;
    13391          }
    13492        }
    13593      }
    13694    }
    137     out_pix -= 2*dropback;
     95    out_pix -= dropback;
    13896   
    13997    /**** fill in area to the right of the picture ****/
    14098    for (jj = 0; jj < expand_out; jj++) {
    141       out_pix2 = out_pix + 2*jj*dx;
    142       for (i = i_end; i < dx; i++, out_pix2+=2) {
    143         out_pix2[0] = back1;
    144         out_pix2[1] = back2;
     99      out_pix2 = out_pix + jj*dx;
     100      for (i = i_end; i < dx; i++, out_pix2++) {
     101        *out_pix2 = back;
    145102      }
    146103    }
    147104  }
    148105 
    149   /*
    150   if ((j_end - j_start) % expand_out > 0)
    151     out_pix -= expand_out - (j_end - j_start) % expand_out;
    152   */
    153  
    154   out_pix = &data[2*j_end*dx];
    155106  /**** fill in top area ****/
     107  out_pix = &data[j_end*dx];
    156108  for (j = 0; j < (dy - j_end); j++) {
    157     for (i = 0; i < dx; i++, out_pix+=2) {
    158       out_pix[0] = back1;
    159       out_pix[1] = back2;
     109    for (i = 0; i < dx; i++, out_pix++) {
     110      *out_pix = back;
    160111    }
    161112  }
    162113
    163   image[0].picture.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0,
    164                                         image[0].picture.data, image[0].picture.dx, image[0].picture.dy, 16, 0);
     114  picture[0].pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0,
     115                                        picture[0].data, picture[0].dx, picture[0].dy, 16, 0);
    165116
    166   free (pixel1);
    167   free (pixel2);
    168 
    169 # endif
     117  free (pixel);
    170118}
    171 
  • trunk/Ohana/src/kapa2/src/Remap24.c

    r16255 r16256  
    11# include "Ximage.h"
    22
    3 void Remap24 (Graphic *graphic, KapaImageWidget *image, Matrix *matrix) {
     3void Remap24 (Graphic *graphic, KapaImageWidget *image, Picture *picture, Matrix *matrix) {
    44
    5 # if (0)
    65  int i, j, ii, jj;
    76  int i_start, i_end, j_start, j_end;
    8   int dropback, extra;  /* this is a bit of a kludge... */
     7  int dropback, extra;
    98  int dx, dy, DX, DY;
    10   double expand, Sx, Sy, Ix, Iy;
     9  double expand, Ix, Iy;
    1110  int expand_in, expand_out;
    1211  unsigned char *out_pix, *out_pix2, *data;
     
    3130
    3231  // set up expansions
     32  assert ((picture[0].expand >= 1) || (picture[0].expand <= -2));
    3333  expand = expand_in = expand_out = 1.0;
    34   if (image[0].expand == 0) /* set up expansions */
    35     image[0].expand = 1;
    36   if (image[0].expand > 0) {
    37     expand = 1 / (1.0*image[0].expand);
    38     expand_out = image[0].expand;
     34  if (picture[0].expand == 0) /* set up expansions */
     35    picture[0].expand = 1;
     36  if (picture[0].expand > 0) {
     37    expand = 1 / (1.0*picture[0].expand);
     38    expand_out = picture[0].expand;
    3939    expand_in  = 1;
    4040  }
    41   if (image[0].expand < 0) {
    42     expand = fabs((double)image[0].expand);
     41  if (picture[0].expand < 0) {
     42    expand = fabs((double)picture[0].expand);
    4343    expand_out = 1;
    44     expand_in  = -image[0].expand;
     44    expand_in  = -picture[0].expand;
    4545  }
    4646
    47   dx = image[0].picture.dx;
    48   dy = image[0].picture.dy;
     47  dx = picture[0].dx;
     48  dy = picture[0].dy;
    4949  DX = matrix[0].Naxis[0];
    5050  DY = matrix[0].Naxis[1];
     51
     52  // each row is padded to a 4-byte word
    5153  extra = 4 - (dx * 3) % 4;
    5254
    53   /* X,Y are the image coordinates of the first image pixel */
    54   Ix = MAX(0.5*(DX - dx*expand) - image[0].X, 0);
    55   if ((int)Ix != Ix)
    56     Ix = (int) Ix + 1;
    57   else
    58     Ix = (int) Ix;
    59   Iy = MAX(0.5*(DY - dy*expand) - image[0].Y, 0);
    60   if ((int)Iy != Iy)
    61     Iy = (int) Iy + 1;
    62   else
    63     Iy = (int) Iy;
     55  // x, y are the closest lit screen pixel to 0,0
     56  Picture_Lower (&i_start, &j_start, matrix, picture);
    6457
    65   /* Sx,Sy are the screen coordinates of the first image pixel */
    66   Sx = (Ix + image[0].X - 0.5*DX)/expand + 0.5*dx;
    67   Sy = (Iy + image[0].Y - 0.5*DY)/expand + 0.5*dy;
     58  // x, y are the closest lit screen pixel to dx, dy
     59  Picture_Upper (&i_end, &j_end, matrix, picture);
    6860
    69   i_start = MIN (MAX (Sx, 0), dx - expand_out + 1);
    70   j_start = MIN (MAX (Sy, 0), dy - expand_out + 1);
    71  
    72   if (image[0].expand > 0) {
    73     i_end = MAX (MIN (i_start + ((int)(expand*(dx-i_start)))/expand, expand_out*(DX-Ix) + Sx), 0);
    74     j_end = MAX (MIN (j_start + ((int)(expand*(dy-j_start)))/expand, expand_out*(DY-Iy) + Sy), 0);
    75   } else {
    76     i_end = MAX (MIN (dx, (DX-Ix)/expand + Sx), 0);
    77     j_end = MAX (MIN (dy, (DY-Iy)/expand + Sy), 0);
    78   }   
     61  // Ix,Iy are the first displayed image pixel
     62  Picture_to_Image (&Ix, &Iy, i_start, j_start, picture);
    7963
    8064  dropback = expand_out - (i_end - i_start) % expand_out;
    8165  if ((i_end - i_start) % expand_out == 0) dropback = 0;
    82 
    83   data = out_pix = (unsigned char *) image[0].picture.data;
     66 
     67  data = out_pix = (unsigned char *) picture[0].data;
    8468  in_pix  = &image[0].pixmap[DX*(int)MAX(Iy,0) + (int)MAX(Ix,0)];
    8569
     
    146130  }
    147131 
    148   /*
    149   if ((j_end - j_start) % expand_out > 0)
    150     out_pix -= expand_out - (j_end - j_start) % expand_out;
    151   */
    152  
     132  /**** fill in top area ****/
    153133  out_pix = &data[j_end*(3*dx+extra)];
    154   /**** fill in top area ****/
    155134  for (j = 0; j < (dy - j_end); j++) {
    156135    for (i = 0; i < dx; i++, out_pix+=3) {
     
    162141  }
    163142
    164   image[0].picture.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0,
    165                                         image[0].picture.data, image[0].picture.dx, image[0].picture.dy, 32, 0);
     143  picture[0].pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0,
     144                                        picture[0].data, picture[0].dx, picture[0].dy, 32, 0);
    166145
    167146  free (pixel1);
    168147  free (pixel2);
    169148  free (pixel3);
    170 
    171 # endif
    172149}
    173 
  • trunk/Ohana/src/kapa2/src/Remap32.c

    r16255 r16256  
    11# include "Ximage.h"
    22
    3 void Remap32 (Graphic *graphic, KapaImageWidget *image, Matrix *matrix) {
     3void Remap32 (Graphic *graphic, KapaImageWidget *image, Picture *picture, Matrix *matrix) {
    44
    55  int i, j, ii, jj;
    66  int i_start, i_end, j_start, j_end;
    7   int dropback;  /* this is a bit of a kludge... */
     7  int dropback;
    88  int dx, dy, DX, DY;
    9   double expand, Sx, Sy, Ix, Iy;
     9  double expand, Ix, Iy;
    1010  int expand_in, expand_out;
    1111  unsigned int *out_pix, *out_pix2;
     
    2323
    2424  // set up expansions
    25   assert ((image[0].picture.expand >= 1) || (image[0].picture.expand <= -2));
     25  assert ((picture[0].expand >= 1) || (picture[0].expand <= -2));
    2626  expand = expand_in = expand_out = 1.0;
    27   if (image[0].picture.expand > 0) {
    28     expand = 1 / (1.0*image[0].picture.expand);
    29     expand_out = image[0].picture.expand;
     27  if (picture[0].expand > 0) {
     28    expand = 1 / (1.0*picture[0].expand);
     29    expand_out = picture[0].expand;
    3030    expand_in  = 1;
    3131  }
    32   if (image[0].picture.expand < 0) {
    33     expand = fabs((double)image[0].picture.expand);
     32  if (picture[0].expand < 0) {
     33    expand = fabs((double)picture[0].expand);
    3434    expand_out = 1;
    35     expand_in  = -image[0].picture.expand;
     35    expand_in  = -picture[0].expand;
    3636  }
    3737
    3838  // define the image sizes
    39   dx = image[0].picture.dx;
    40   dy = image[0].picture.dy;
     39  dx = picture[0].dx;
     40  dy = picture[0].dy;
    4141  DX = matrix[0].Naxis[0];
    4242  DY = matrix[0].Naxis[1];
    4343
    44   // Ix, Iy are the image coordinates of the 0,0 screen pixel
    45   Screen_to_Image (&Ix, &Iy, 0.0, 0.0, &image[0].picture);
     44  // x, y are the closest lit screen pixel to 0,0
     45  Picture_Lower (&i_start, &j_start, matrix, picture);
    4646
    47   // Ix, Iy are now limited to valid image coordinates
    48   Ix = MIN (MAX (Ix, 0), DX);
    49   Iy = MIN (MAX (Iy, 0), DY);
     47  // x, y are the closest lit screen pixel to dx, dy
     48  Picture_Upper (&i_end, &j_end, matrix, picture);
    5049
    51   // Sx, Sy are the screen coordinates of the Ix,Iy pixel
    52   Image_to_Screen (&Sx, &Sy, Ix,  Iy,  &image[0].picture);
    53 
    54   // i_start, j_start are now limited to valid screen coordinates
    55   i_start = MIN (MAX (Sx, 0), dx);
    56   j_start = MIN (MAX (Sy, 0), dy);
    57 
    58   // Ix, Iy are the image coordinates of the 0,0 screen pixel
    59   Screen_to_Image (&Ix, &Iy, dx, dy, &image[0].picture);
    60 
    61   // Ix, Iy are now limited to valid image coordinates
    62   Ix = MIN (MAX (Ix, 0), DX);
    63   Iy = MIN (MAX (Iy, 0), DY);
    64 
    65   // Sx, Sy are the screen coordinates of the Ix,Iy pixel
    66   Image_to_Screen (&Sx, &Sy, Ix,  Iy,  &image[0].picture);
    67 
    68   // i_end, j_end are now limited to valid screen coordinates
    69   i_end = MIN (MAX (Sx, 0), dx);
    70   j_end = MIN (MAX (Sy, 0), dy);
     50  // Ix,Iy are the first displayed image pixel
     51  Picture_to_Image (&Ix, &Iy, i_start, j_start, picture);
    7152
    7253  dropback = expand_out - (i_end - i_start) % expand_out;
    7354  if ((i_end - i_start) % expand_out == 0) dropback = 0;
    7455
    75   out_pix = (unsigned int *) image[0].picture.data;
     56  out_pix = (unsigned int *) picture[0].data;
    7657  in_pix  = &image[0].pixmap[DX*(int)MAX(Iy,0) + (int)MAX(Ix,0)];
    7758
     
    127108 
    128109  /**** fill in top area ****/
    129   for (j = 0; (j < dx*(dy - j_end)) && (out_pix - (unsigned int *)image[0].picture.data < dx*dy); j++, out_pix++) {
     110  for (j = 0; (j < dx*(dy - j_end)) && (out_pix - (unsigned int *)picture[0].data < dx*dy); j++, out_pix++) {
    130111    *out_pix = back;
    131112  }
    132113
    133   image[0].picture.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0,
    134                                         image[0].picture.data, image[0].picture.dx, image[0].picture.dy, 32, 0);
     114  picture[0].pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0,
     115                                        picture[0].data, picture[0].dx, picture[0].dy, 32, 0);
    135116
    136117  free (pixel);
  • trunk/Ohana/src/kapa2/src/Remap8.c

    r16255 r16256  
    11# include "Ximage.h"
    22
    3 void Remap8 (Graphic *graphic, KapaImageWidget *image, Matrix *matrix) {
     3void Remap8 (Graphic *graphic, KapaImageWidget *image, Picture *picture, Matrix *matrix) {
    44
    5 # if (0)
    65  int i, j, ii, jj;
    76  int i_start, i_end, j_start, j_end;
    8   int dropback;  /* this is a bit of a kludge... */
    9   int dx, dy, DX, DY, pixelN;
    10   double expand, Sx, Sy, Ix, Iy;
     7  int dropback;
     8  int dx, dy, DX, DY;
     9  double expand, Ix, Iy;
    1110  int expand_in, expand_out;
    1211  unsigned char *out_pix, *out_pix2;
    1312  unsigned short *in_pix,  *in_pix2;
    14   unsigned long *pixel, pixvalue;
    15   unsigned long back;
     13  unsigned char *pixel, pixvalue;
     14  unsigned char back;
    1615
    17   ALLOCATE (pixel, unsigned long, graphic[0].Npixels);
     16  ALLOCATE (pixel, unsigned char, graphic[0].Npixels);
    1817
    1918  // local array for pixel values
    2019  for (i = 0; i < graphic[0].Npixels; i++) {
    21     pixel[i] = graphic[0].cmap[i].pixel;
     20    pixel[i] = 0xff & graphic[0].cmap[i].pixel;
    2221  }
    23   back = graphic[0].back;
     22  back = 0xff & graphic[0].back;
    2423
    2524  // set up expansions
     25  assert ((picture[0].expand >= 1) || (picture[0].expand <= -2));
    2626  expand = expand_in = expand_out = 1.0;
    27   if (image[0].expand == 0) /* set up expansions */
    28     image[0].expand = 1;
    29   if (image[0].expand > 0) {
    30     expand = 1 / (1.0*image[0].expand);
    31     expand_out = image[0].expand;
     27  if (picture[0].expand == 0) /* set up expansions */
     28    picture[0].expand = 1;
     29  if (picture[0].expand > 0) {
     30    expand = 1 / (1.0*picture[0].expand);
     31    expand_out = picture[0].expand;
    3232    expand_in  = 1;
    3333  }
    34   if (image[0].expand < 0) {
    35     expand = fabs((double)image[0].expand);
     34  if (picture[0].expand < 0) {
     35    expand = fabs((double)picture[0].expand);
    3636    expand_out = 1;
    37     expand_in  = -image[0].expand;
     37    expand_in  = -picture[0].expand;
    3838  }
    3939
    4040  // define the image boundaries
    41   dx = image[0].picture.dx;
    42   dy = image[0].picture.dy;
     41  dx = picture[0].dx;
     42  dy = picture[0].dy;
    4343  DX = matrix[0].Naxis[0];
    4444  DY = matrix[0].Naxis[1];
    4545
    46   /* X,Y are the image coordinates of the first image pixel */
    47   Ix = MAX(0.5*(DX - dx*expand) - image[0].X, 0);
    48   if ((int)Ix != Ix)
    49     Ix = (int) Ix + 1;
    50   else
    51     Ix = (int) Ix;
    52   Iy = MAX(0.5*(DY - dy*expand) - image[0].Y, 0);
    53   if ((int)Iy != Iy)
    54     Iy = (int) Iy + 1;
    55   else
    56     Iy = (int) Iy;
     46  // x, y are the closest lit screen pixel to 0,0
     47  Picture_Lower (&i_start, &j_start, matrix, picture);
    5748
    58   /* Sx,Sy are the screen coordinates of the first image pixel */
    59   Sx = (Ix + image[0].X - 0.5*DX)/expand + 0.5*dx;
    60   Sy = (Iy + image[0].Y - 0.5*DY)/expand + 0.5*dy;
     49  // x, y are the closest lit screen pixel to dx, dy
     50  Picture_Upper (&i_end, &j_end, matrix, picture);
    6151
    62   i_start = MIN (MAX (Sx, 0), dx - expand_out + 1);
    63   j_start = MIN (MAX (Sy, 0), dy - expand_out + 1);
    64  
    65   if (image[0].expand > 0) {
    66     i_end = MAX (MIN (i_start + ((int)(expand*(dx-i_start)))/expand, expand_out*(DX-Ix) + Sx), 0);
    67     j_end = MAX (MIN (j_start + ((int)(expand*(dy-j_start)))/expand, expand_out*(DY-Iy) + Sy), 0);
    68   } else {
    69     i_end = MAX (MIN (dx, (DX-Ix)/expand + Sx), 0);
    70     j_end = MAX (MIN (dy, (DY-Iy)/expand + Sy), 0);
    71   }   
     52  // Ix,Iy are the first displayed image pixel
     53  Picture_to_Image (&Ix, &Iy, i_start, j_start, picture);
    7254
    7355  dropback = expand_out - (i_end - i_start) % expand_out;
    7456  if ((i_end - i_start) % expand_out == 0) dropback = 0;
    7557
    76   out_pix = (unsigned char *) image[0].picture.data;
     58  out_pix = (unsigned char *) picture[0].data;
    7759  in_pix  = &image[0].pixmap[DX*(int)MAX(Iy,0) + (int)MAX(Ix,0)];
    7860
     
    8062
    8163  /**** fill in bottom area ****/
    82   for (j = 0; j < dx*j_start; j++, out_pix++)
     64  for (j = 0; j < dx*j_start; j++, out_pix++) {
    8365    *out_pix = back;
     66  }
    8467 
    8568  for (j = j_start; j < j_end; j+= expand_out, out_pix+=(expand_out-1)*dx, in_pix += expand_in*DX) {
     
    128111 
    129112  /**** fill in top area ****/
    130   for (j = 0; (j < dx*(dy - j_end)) && (out_pix - (unsigned char *)image[0].picture.data < dx*dy); j++, out_pix++) {
     113  for (j = 0; (j < dx*(dy - j_end)) && (out_pix - (unsigned char *)picture[0].data < dx*dy); j++, out_pix++) {
    131114    *out_pix = back;
    132115  }
    133   image[0].picture.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0,
    134                                         image[0].picture.data, image[0].picture.dx, image[0].picture.dy, 8, 0);
    135 
    136 # endif
     116  picture[0].pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0,
     117                                        picture[0].data, picture[0].dx, picture[0].dy, 8, 0);
     118  free (pixel);
    137119}
    138 
  • trunk/Ohana/src/kapa2/src/SetImageData.c

    r16228 r16256  
    125125  image = section->image;
    126126
    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);
     127  Picture_to_Image (&Xmin, &Ymin, 0.0, 0.0, &image[0].picture);
     128  Picture_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/SetImageSize.c

    r16011 r16256  
    319319    CreatePicture (image, graphic);
    320320    CreateColorbar (image, graphic);
    321     CreateZoom (image, graphic, 0, 0);
     321    CreateZoom (graphic, image);
    322322  }
    323323  Remap (graphic, image);
  • trunk/Ohana/src/kapa2/src/StatusBox.c

    r16255 r16256  
    1111    y = 0.5*image[0].image[0].matrix.Naxis[1];
    1212    // z = -1;
    13     image[0].zoom.x = x;
    14     image[0].zoom.y = y;
     13    image[0].zoom.X = x;
     14    image[0].zoom.Y = y;
    1515    // image[0].z = z;
    1616  } else {
    17     x = image[0].zoom.x;
    18     y = image[0].zoom.y;
     17    x = image[0].zoom.X;
     18    y = image[0].zoom.Y;
    1919    // z = image[0].z;
    2020  }
  • trunk/Ohana/src/kapa2/src/UpdatePointer.c

    r16255 r16256  
    1919
    2020    data = (float *) image[0].image[0].matrix.buffer;
    21     Screen_to_Image (&x, &y, (double)event[0].x, (double)event[0].y, &image[0].picture);
     21    Screen_to_Image (&x, &y, event[0].x + 0.5, event[0].y + 0.5, &image[0].picture);
    2222
    2323    z = -1;
     
    3535    XFlush (graphic[0].display);
    3636     
    37     CreateZoom (image, graphic, x, y); 
     37    CreateZoom (graphic, image); 
    3838    XPutImage (graphic[0].display, graphic[0].window, graphic[0].gc,
    3939               image[0].zoom.pix, 0, 0,
Note: See TracChangeset for help on using the changeset viewer.