IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 16011


Ignore:
Timestamp:
Jan 6, 2008, 1:41:58 PM (18 years ago)
Author:
eugene
Message:

updates from eam_branch_20071222 : new 3D color map and multiple channels

Location:
trunk/Ohana/src/kapa2
Files:
6 added
41 edited

Legend:

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

    r13484 r16011  
    7777$(SRC)/bDrawOverlay.$(ARCH).o             $(SRC)/ButtonFunctions.$(ARCH).o    \
    7878$(SRC)/PSimage.$(ARCH).o                  $(SRC)/PSPixmap.$(ARCH).o           \
    79 $(SRC)/PSOverlay.$(ARCH).o
     79$(SRC)/PSOverlay.$(ARCH).o                $(SRC)/SetChannel.$(ARCH).o         \
     80$(SRC)/SetColorScale.$(ARCH).o            $(SRC)/ColorCube.$(ARCH).o          \
     81$(SRC)/ColorHistogram.$(ARCH).o           $(SRC)/sort.$(ARCH).o
    8082
    8183OBJ  =  $(KAPA)
  • trunk/Ohana/src/kapa2/include/buttons.h

    r13320 r16011  
    4747   0x80, 0xef, 0x03, 0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    4848   0x00, 0x00, 0x00, 0x00};
    49 #define puns_width 25
    50 #define puns_height 25
    51 static char puns_bits[] = {
     49#define heat_width 25
     50#define heat_height 25
     51static char heat_bits[] = {
    5252   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x07, 0xd8, 0x01,
    5353   0x00, 0x0c, 0x37, 0x00, 0xf8, 0xc9, 0x6f, 0x00, 0x0c, 0xde, 0xf0, 0x00,
  • trunk/Ohana/src/kapa2/include/constants.h

    r13479 r16011  
    99 | StructureNotifyMask \
    1010 | PointerMotionMask)
     11
     12# define NCHANNELS 3
     13# define NPIXELS_DYNAMIC 128
     14
     15// XXX for the moment, this is set to match the values in SetColorScale3D_CC
     16# define NPIXELS_STATIC 4600
    1117
    1218# define PAD1  3
     
    2733# define LABEL_MAXLEN 128
    2834
     35typedef enum {
     36    KAPA_SCALE_1D,
     37    KAPA_SCALE_3D_RUFF,
     38    KAPA_SCALE_3D_FULL
     39} KapaColorScaleMode;
     40
    2941/* label names */
    30 # define LABELX0 0
    31 # define LABELY0 1
    32 # define LABELX1 2
    33 # define LABELY1 3
    34 # define LABELUL 4
    35 # define LABELUR 5
    36 # define LABELLL 6
    37 # define LABELLR 7
     42typedef enum {
     43  LABELX0,
     44  LABELY0,
     45  LABELX1,
     46  LABELY1,
     47  LABELUL,
     48  LABELUR,
     49  LABELLL,
     50  LABELLR
     51} KapaLabelMode;
     52
     53typedef enum {
     54  KAPA_CHANNEL_RED,
     55  KAPA_CHANNEL_GREEN,
     56  KAPA_CHANNEL_BLUE,
     57} KapaChannels;
     58
     59// use an enum to identify the 3 dimensions:
     60typedef enum {
     61  CC_X,
     62  CC_Y,
     63  CC_Z,
     64} CCDimen;
    3865
    3966/* EVENT_MASK consists of:
  • trunk/Ohana/src/kapa2/include/prototypes.h

    r14590 r16011  
    7171int           GetImageCoords      PROTO((int sock));
    7272int           GetImageRange       PROTO((int sock));
     73int           SetChannel (int sock);
     74int           SetColormapFromPipe (int sock);
    7375
    7476int           LoadVectorData      PROTO((int sock, KapaGraphWidget *graph, int N, char *type));
     
    140142
    141143int           Center              PROTO(());
    142 void          Remap               PROTO((Graphic *graphic, KapaImageWidget *image, Matrix *matrix));
     144void          SetColorScale       PROTO((Graphic *graphic, KapaImageWidget *image));
     145void          SetColorScale1D     PROTO((Graphic *graphic, KapaImageWidget *image));
     146int           SetColorScale3D     PROTO((Graphic *graphic, KapaImageWidget *image));
     147void          Remap               PROTO((Graphic *graphic, KapaImageWidget *image));
    143148void          Remap8              PROTO((Graphic *graphic, KapaImageWidget *image, Matrix *matrix));
    144149void          Remap16             PROTO((Graphic *graphic, KapaImageWidget *image, Matrix *matrix));
     
    147152int           LoadPicture         PROTO((int sock));
    148153
    149 KapaImageWidget *InitImage        PROTO(());
     154KapaImageWidget *InitImageWidget  PROTO(());
     155int           InitImageChannel    PROTO((KapaImageChannel *channel));
    150156void          FreeImage           PROTO((KapaImageWidget *image));
    151157void          SetImageSize        PROTO((Section *section));
     
    179185/* Button Functions */
    180186int           greycolors          PROTO((Graphic *graphic, KapaImageWidget *image));
    181 int           puns                PROTO((Graphic *graphic, KapaImageWidget *image));
     187int           heat                PROTO((Graphic *graphic, KapaImageWidget *image));
    182188int           rainbow             PROTO((Graphic *graphic, KapaImageWidget *image));
    183189int           Recenter            PROTO((Graphic *graphic, KapaImageWidget *image));
     
    219225void InvertButton (Graphic *graphic, Button *button);
    220226void bDrawOverlay (KapaImageWidget *image, int N);
     227
     228/* color cube tools */
     229CCNode *CCNodeAlloc ();
     230CCNode *CCFindChild (CCNode *node, float x, float y, float z);
     231int CCSplitNode (CCNode *node);
     232int CCSplitNodeIterate (CCNode *node, int current, int max);
     233void CCNodeFree (CCNode *node);
     234CCNode *CCFindBottom (CCNode *top, float x, float y, float z);
     235int CCNodeExtractCounts (CCNode *node, float **values, int *nvalues, int *NVALUES);
     236int CCNodeDivideLimit (CCNode *node, float minValue);
     237int CCNodeInitCounts (CCNode *node, float value);
     238
     239/* 3D color histogram */
     240void ColorHistogram (KapaImageWidget *image, CCNode *cube);
     241void CCNodeSetColorPixels (KapaImageWidget *image, CCNode *cube);
     242int CCNodeSetColorMap (CCNode *node, XColor *cmap, int Npixels, int *current);
     243
     244int SetColorScale3D_CC (Graphic *graphic, KapaImageWidget *image);
     245
     246void sort (float *value, int N);
  • trunk/Ohana/src/kapa2/include/structures.h

    r14590 r16011  
    22/**************** Graphic carries X info around ****************/
    33typedef struct {
    4   Display       *display;
    5   int            screen;
     4  Display       *display;     // X display pointer
     5  int            screen;      // X screen number
    66  int            depth;
    77  Window         window;
    88  Visual        *visual;
    9   int            visualclass;
    10   int            Nbits;
     9  int            visualclass; // is visual dynamic? (XXX change name?)
     10  int            Nbits;       // pixel depth in bits (8, 16, 24, 32)
    1111  GC             gc;
    1212  XFontStruct   *font;
     
    1414  int            x,  y;
    1515  unsigned int   dx, dy;
    16   XColor         cmap[256];
     16  XColor        *cmap;
    1717  Colormap       colormap;
    18   unsigned long  fore;
    19   unsigned long  back;
    20   unsigned long  *color;
    21   unsigned long  pixels[256];
    22   unsigned long  overlay_color[NOVERLAYS];
    23   int Npixels;
    24   int Ncolors;
     18  unsigned long *color;      // graph plotting colors
     19  int            Ncolors;
     20
     21  unsigned long *pixels;      // image pixel colors
     22  int Npixels;                // number of pixels
     23
     24  int            ColorScaleMode; // single colormap for all images??
     25  int nRed;
     26  int nBlue;
     27  int nGreen;
     28
     29  unsigned long  fore;        // basic foreground color
     30  unsigned long  back;        // basic background color
     31
     32  unsigned long  overlay_color[NOVERLAYS]; // image plotting colors
    2533} Graphic;
    2634
     
    5866} TextBox;
    5967
     68/*** 3C color cube histogram tree thingy ***/
     69typedef struct CCNode {
     70  // for the moment, this structure is specific to the color-histogram analysis.  if
     71  // this were a void *pointer and we defined some additional apis, we could use this
     72  // structure to track any 3D space
     73  int count;   
     74  int pixel;
     75  char bottom;
     76  float min[3]; // min value for each of the 3 dimensions for this node
     77  float mid[3]; // mid-point for each of the 3 dimensions for this node
     78  float max[3]; // max value for each of the 3 dimensions for this node
     79  struct CCNode *sub[2][2][2];
     80} CCNode;
     81
    6082/**************** general structures ****************/
    6183typedef struct {
     
    125147} KapaGraphWidget;
    126148
     149typedef struct {
     150  // data associated with this image element
     151  Matrix   matrix;         /* data for picture */
     152  double   zero, range;    /* zero, range for picture to cmap */
     153  double   max, min;       /* zero, range for data to z-value */
     154  double   start, slope;   /* zero, range for cmap to pixels */
     155  Coords   coords;
     156  char     file[1024];     /* name of file */
     157  char     name[1024];     /* name of buffer */
     158} KapaImageChannel;
     159
    127160// a single image in the display window
    128161typedef struct {
     
    139172  Button   grey_button;
    140173  Button   rainbow_button;
    141   Button    puns_button;
     174  Button   heat_button;
    142175  Button   overlay_button[NOVERLAYS];
    143176
     
    149182  int      DecimalDegrees;
    150183
    151   // data associated with this image element
     184  double   X, Y;           /* image pixel at screen center */
     185  int      expand;         /* zoomscale */
     186  double   x, y, z;        /* last pointer coords */
     187
    152188  Overlay  overlay[NOVERLAYS];
    153189  Overlay  tickmarks;
    154   Matrix   matrix;         /* data for picture */
    155   double   X, Y;           /* image pixel at screen center */
    156   int      expand;         /* zoomscale */
    157   double   zero, range;    /* zero, range for picture to cmap */
    158   double   max, min;       /* zero, range for data to z-value */
    159   double   start, slope;   /* zero, range for cmap to pixels */
    160   double   x, y, z;        /* last pointer coords */
    161   Coords   coords;
    162   char     file[1024];     /* name of file */
    163   char     name[1024];  /* name of buffer */
     190
     191  unsigned short   *pixmap;   // lookup table for image pixel value to pixel index
     192  int      nPixels;
     193 
     194  KapaImageChannel *image;
     195  KapaImageChannel channel[NCHANNELS];
    164196} KapaImageWidget;
    165197
  • trunk/Ohana/src/kapa2/src/ButtonFunctions.c

    r13331 r16011  
    22
    33static char *GREY = "greyscale";
    4 static char *PUNS = "Puns";
     4static char *HEAT = "Heat";
    55static char *RAINBOW = "Rainbow";
    66
     
    1818  SetColormap (name);
    1919  CreateColorbar (image, graphic);
    20   Remap (graphic, image, &image[0].matrix);
     20  SetColorScale (graphic, image);
     21  Remap (graphic, image);
    2122  CreateZoom (image, graphic, 0, 0);
    2223  Refresh ();
     
    2526}
    2627
    27 int puns (Graphic *graphic, KapaImageWidget *image) {
     28int heat (Graphic *graphic, KapaImageWidget *image) {
    2829  char *name;
    29   name = PUNS;
    30   SetColormap (name);
     30  name = HEAT;
     31  SetColormap ("ruffcolor");
    3132  CreateColorbar (image, graphic);
    32   Remap (graphic, image, &image[0].matrix);
     33  SetColorScale (graphic, image);
     34  Remap (graphic, image);
    3335  CreateZoom (image, graphic, 0, 0);
    3436  Refresh ();
     
    4042  char *name;
    4143  name = RAINBOW;
    42   SetColormap (name);
     44  SetColormap ("fullcolor");
    4345  CreateColorbar (image, graphic);
    44   Remap (graphic, image, &image[0].matrix);
     46  SetColorScale (graphic, image);
     47  Remap (graphic, image);
    4548  CreateZoom (image, graphic, 0, 0);
    4649  Refresh ();
     
    5457  image[0].Y = 0;
    5558 
    56   Remap (graphic, image, &image[0].matrix);
     59  Remap (graphic, image);
    5760  Refresh ();
    5861  FlushDisplay (graphic[0].display);
     
    6467
    6568  image[0].expand = 1;
    66   Remap (graphic, image, &image[0].matrix);
     69  Remap (graphic, image);
    6770  Refresh ();
    6871  FlushDisplay (graphic[0].display);
     
    7780  image[0].expand = 1;
    7881 
    79   Remap (graphic, image, &image[0].matrix);
     82  Remap (graphic, image);
    8083  Refresh ();
    8184  FlushDisplay (graphic[0].display);
  • trunk/Ohana/src/kapa2/src/CSaveOverlay.c

    r13479 r16011  
    2424  for (i = 0; i < image[0].overlay[N].Nobjects; i++) {
    2525    if (image[0].overlay[N].objects[i].type == KII_OVERLAY_LINE) {
    26       XY_to_RD (&ra, &dec, image[0].overlay[N].objects[i].x, image[0].overlay[N].objects[i].y, &image[0].coords);
     26      XY_to_RD (&ra, &dec, image[0].overlay[N].objects[i].x, image[0].overlay[N].objects[i].y, &image[0].image[0].coords);
    2727      x1 = image[0].overlay[N].objects[i].x + image[0].overlay[N].objects[i].dx;
    2828      y1 = image[0].overlay[N].objects[i].y + image[0].overlay[N].objects[i].dy;
    29       XY_to_RD (&ra1, &dec1, x1, y1, &image[0].coords);
     29      XY_to_RD (&ra1, &dec1, x1, y1, &image[0].image[0].coords);
    3030      dra = (ra1 - ra);
    3131      ddec = (dec1 - dec);
    3232    } else {
    33       XY_to_RD (&ra, &dec, image[0].overlay[N].objects[i].x, image[0].overlay[N].objects[i].y, &image[0].coords);
     33      XY_to_RD (&ra, &dec, image[0].overlay[N].objects[i].x, image[0].overlay[N].objects[i].y, &image[0].image[0].coords);
    3434      x1 = image[0].overlay[N].objects[i].x;
    3535      y1 = image[0].overlay[N].objects[i].y + image[0].overlay[N].objects[i].dy;
    36       XY_to_RD (&ra1, &dec1, x1, y1, &image[0].coords);
     36      XY_to_RD (&ra1, &dec1, x1, y1, &image[0].image[0].coords);
    3737      ddec = fabs (dec1 - dec);
    3838      x1 = image[0].overlay[N].objects[i].x + image[0].overlay[N].objects[i].dx;
    3939      y1 = image[0].overlay[N].objects[i].y;
    40       XY_to_RD (&ra1, &dec1, x1, y1, &image[0].coords);
     40      XY_to_RD (&ra1, &dec1, x1, y1, &image[0].image[0].coords);
    4141      dra = cos (dec*RAD_DEG) * fabs (ra1 - ra);
    4242    }
  • trunk/Ohana/src/kapa2/src/Center.c

    r13479 r16011  
    1616  if (image == NULL) return (TRUE);
    1717
    18   image[0].X = 0.5*image[0].matrix.Naxis[0] - X;
    19   image[0].Y = 0.5*image[0].matrix.Naxis[1] - Y;
     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;
    2020  if ((zoom != 0) && (zoom != -1)) {
    2121    image[0].expand = zoom;
     
    2323
    2424  if (USE_XWINDOW) {
    25     Remap (graphic, image, &image[0].matrix);
     25    Remap (graphic, image);
    2626    Refresh ();
    2727    XFlush (graphic[0].display);
  • trunk/Ohana/src/kapa2/src/CheckButtons.c

    r13320 r16011  
    11# include "Ximage.h"
    2 # define PAD_X 10
    3 # define PAD_Y 10
    4 # define NPLANES 1
    5 # define NPIXELS 255
    62
    73/******** Here we test the Buttons specific to this program  *******/
     
    2117    button = &image[0].rainbow_button;
    2218
    23   if (InButton (event, &image[0].puns_button))
    24     button = &image[0].puns_button;
     19  if (InButton (event, &image[0].heat_button))
     20    button = &image[0].heat_button;
    2521
    2622  if (InButton (event, &image[0].PS_button))
     
    3935}
    4036
    41 
    4237/* To define a button, you must:
    4338
  • trunk/Ohana/src/kapa2/src/CheckPipe.c

    r14590 r16011  
    268268  }
    269269
     270  if (!strcmp (word, "CHAN")) {
     271    status = SetChannel (sock);
     272    KiiSendCommand (sock, 4, "DONE");
     273    FINISHED (status);
     274  }
     275
     276  if (!strcmp (word, "CMAP")) {
     277    status = SetColormapFromPipe (sock);
     278    KiiSendCommand (sock, 4, "DONE");
     279    FINISHED (status);
     280  }
     281
    270282  if (!strcmp (word, "SAVE")) {
    271283    status = SaveOverlay (sock);
  • trunk/Ohana/src/kapa2/src/CheckVisual.c

    r13479 r16011  
    11# include "Ximage.h"
    2 # define NPIXELS 64
    32
    43/* DirectColor doesn't seem to work, even though it is available:
     
    1110
    1211  int i, Nfound, N;
    13   int col, def, dyn;
     12  int isColor, isDefault, isDynamic;
    1413  XVisualInfo *visual_list, visual_temp;
    1514  unsigned long planes[3];
     
    2019    fprintf (stderr, "DirectColor: %d\n", DirectColor);
    2120    fprintf (stderr, "PseudoColor: %d\n", PseudoColor);
    22     fprintf (stderr, "TrueColor: %d\n", TrueColor);
    23     fprintf (stderr, "GrayScale: %d\n", GrayScale);
     21    fprintf (stderr, "TrueColor:   %d\n", TrueColor);
     22    fprintf (stderr, "GrayScale:   %d\n", GrayScale);
    2423    fprintf (stderr, "StaticColor: %d\n", StaticColor);
    25     fprintf (stderr, "StaticGray: %d\n", StaticGray);
     24    fprintf (stderr, "StaticGray:  %d\n", StaticGray);
    2625  }
    2726
     
    4241  }
    4342
    44   col = def = dyn = FALSE;
     43  // set these based on selected visual
     44  isColor = isDefault = isDynamic = FALSE;
     45
     46  // attempt to select the most desirable type of visual: Default as PseudoColor (XXX is it still true?)
    4547  if (DEBUG) fprintf (stderr, "default visual class is %d\n", visual_list[i].class);
    46   switch (visual_list[i].class) {
    47   case PseudoColor:
    48     col = def = dyn = TRUE;
     48  if (visual_list[i].class == PseudoColor) {
     49    isColor = isDefault = isDynamic = TRUE;
    4950    graphic[0].visual = visual_list[i].visual;
    5051    graphic[0].visualclass = TRUE;
    5152    goto test_pixels;
    52     break;
    53   default:
    54     break;
    5553  }
    5654
    57   for (i = 0; i < Nfound; i++) {
    58     switch (visual_list[i].class) {
    59     case PseudoColor:
    60       if (DEBUG) fprintf (stderr, "selected visual class is %d\n", visual_list[i].class);
    61       col = dyn = TRUE;
    62       if (graphic[0].visual == visual_list[i].visual) {
    63         def = TRUE;
    64       } else {
    65         graphic[0].visual = visual_list[i].visual;
    66       }
    67       graphic[0].visualclass = TRUE;
    68       goto test_pixels;
    69       break;
    70     default:
    71       break;
    72     }
     55  // attempt to select the most desirable type of visual: PseudoColor (XXX is it still true?)
     56  for (i = 0; (i < Nfound) && (visual_list[i].class != PseudoColor); i++);
     57  if (i != Nfound) {
     58    isColor = isDynamic = TRUE;
     59    if (DEBUG) fprintf (stderr, "selected visual class is %d\n", visual_list[i].class);
     60    isDefault = (graphic[0].visual == visual_list[i].visual);
     61    graphic[0].visual = visual_list[i].visual;
     62    graphic[0].visualclass = TRUE;
     63    goto test_pixels;
    7364  }
    7465
    75   for (i = 0; i < Nfound; i++) {
    76     switch (visual_list[i].class) {
    77     case GrayScale:
    78       if (DEBUG) fprintf (stderr, "selected visual class is %d\n", visual_list[i].class);
    79       dyn = TRUE;
    80       if (graphic[0].visual == visual_list[i].visual) {
    81         def = TRUE;
    82       } else {
    83         graphic[0].visual = visual_list[i].visual;
    84       }
    85       graphic[0].visualclass = TRUE;
    86       goto test_pixels;
    87       break;
    88     default:
    89       break;
    90     }
     66  // attempt to select the most desirable type of visual: GrayScale (XXX is it still true?)
     67  for (i = 0; (i < Nfound) && (visual_list[i].class != GrayScale); i++);
     68  if (i != Nfound) {
     69    isDynamic = TRUE;
     70    if (DEBUG) fprintf (stderr, "selected visual class is %d\n", visual_list[i].class);
     71    isDefault = (graphic[0].visual == visual_list[i].visual);
     72    graphic[0].visual = visual_list[i].visual;
     73    graphic[0].visualclass = TRUE;
     74    goto test_pixels;
    9175  }
    9276
     77  // attempt to select the most desirable type of visual: TrueColor (XXX is it still true?)
    9378  for (i = 0; (i < Nfound) && (visual_list[i].class != TrueColor); i++);
    9479  if (i != Nfound) {
    95     col = TRUE;
     80    isColor = TRUE;
    9681    if (DEBUG) fprintf (stderr, "visual class is %d\n", visual_list[i].class);
    97     if (graphic[0].visual == visual_list[i].visual) {
    98       def = TRUE;
    99     } else {
    100       graphic[0].visual = visual_list[i].visual;
    101     }
     82    isDefault = (graphic[0].visual == visual_list[i].visual);
     83    graphic[0].visual = visual_list[i].visual;
    10284    graphic[0].visualclass = FALSE;
    10385    goto test_pixels;
    10486  }
    10587
     88  // attempt to select the most desirable type of visual: TrueColor (XXX is it still true?)
    10689  for (i = 0; (i < Nfound) && (visual_list[i].class != StaticColor); i++);
    10790  if (i != Nfound) {
    10891    if (DEBUG) fprintf (stderr, "visual class is %d\n", visual_list[i].class);
    109     if (graphic[0].visual == visual_list[i].visual) {
    110       def = TRUE;
    111     } else {
    112       graphic[0].visual = visual_list[i].visual;
    113     }
     92    isDefault = (graphic[0].visual == visual_list[i].visual);
     93    graphic[0].visual = visual_list[i].visual;
    11494    graphic[0].visualclass = FALSE;
    11595    goto test_pixels;
    11696  }
    11797
     98  // attempt to select the most desirable type of visual: TrueColor (XXX is it still true?)
    11899  for (i = 0; (i < Nfound) && (visual_list[i].class != StaticGray); i++);
    119100  if (i != Nfound) {
    120101    if (DEBUG) fprintf (stderr, "visual class is %d\n", visual_list[i].class);
    121     if (graphic[0].visual == visual_list[i].visual) {
    122       def = TRUE;
    123     } else {
    124       graphic[0].visual = visual_list[i].visual;
    125     }
     102    isDefault = (graphic[0].visual == visual_list[i].visual);
     103    graphic[0].visual = visual_list[i].visual;
    126104    graphic[0].visualclass = FALSE;
    127105    goto test_pixels;
     
    136114  /* NEED TO ADD A COUPLE LINES DEFINING THE VARIOUS HARD COLORS (BLACK, WHITE, AND THE OVERLAYS) */
    137115
     116  // allow user to force a private colormap
    138117  if ((N = get_argument (*argc, argv, "-private"))) {
    139118    remove_argument(N, argc, argv);
    140     def = FALSE;
     119    isDefault = FALSE;
    141120  }
    142121
    143   if (!def) {
     122  // allocate a private colormap, if needed
     123  if (!isDefault) {
    144124    if (DEBUG) fprintf (stderr, "allocated private colormap\n");
    145125    graphic[0].colormap = XCreateColormap (graphic[0].display, RootWindow (graphic[0].display, graphic[0].screen), graphic[0].visual, AllocNone);
    146126  }
    147127
    148   if (dyn) {
    149     /* allocate color cells  */
    150     for (graphic[0].Npixels = NPIXELS;
    151          ((graphic[0].Npixels >= 16) &&
    152           !XAllocColorCells (graphic[0].display, graphic[0].colormap, FALSE, planes, 1, graphic[0].pixels, graphic[0].Npixels));
    153          graphic[0].Npixels -= 4) {
     128  if (isDynamic) {
     129    /* allocate color cells */
     130    ALLOCATE (graphic[0].pixels, unsigned long, NPIXELS_DYNAMIC);
     131    ALLOCATE (graphic[0].cmap,   XColor,        NPIXELS_DYNAMIC);
     132    for (graphic[0].Npixels = NPIXELS_DYNAMIC; graphic[0].Npixels >= 16; graphic[0].Npixels -= 4) {
    154133      if (DEBUG) fprintf (stderr, "trying %d colors\n", (int) graphic[0].Npixels);
     134      if (XAllocColorCells (graphic[0].display, graphic[0].colormap, FALSE, planes, 1, graphic[0].pixels, graphic[0].Npixels)) {
     135        break;
     136      }
    155137    }
    156138
     139    /* insufficient cells, can we make a private colormap? */
     140    if (graphic[0].Npixels < 16) {
     141      if (!isDefault) {
     142        fprintf (stderr, "can't allocate enough cells in private colormap\n");
     143        exit (0);
     144      }
     145      if (DEBUG) fprintf (stderr, "can't allocate enough cells, using private colormap\n");
     146      graphic[0].colormap = XCreateColormap (graphic[0].display, RootWindow (graphic[0].display, graphic[0].screen), graphic[0].visual, AllocNone);
    157147
    158     /* make private colormap  */
    159     if (graphic[0].Npixels < 16) {
    160       // fprintf (stderr, "can't allocate enough cells, using private colormap\n");
    161       graphic[0].colormap = XCreateColormap (graphic[0].display, RootWindow (graphic[0].display, graphic[0].screen), graphic[0].visual, AllocNone);
    162       for (graphic[0].Npixels = NPIXELS;
    163            ((graphic[0].Npixels >= 16) &&
    164             !XAllocColorCells (graphic[0].display, graphic[0].colormap, FALSE, planes, 1, graphic[0].pixels, graphic[0].Npixels));
    165            graphic[0].Npixels -= 4);
     148      for (graphic[0].Npixels = NPIXELS_DYNAMIC; graphic[0].Npixels >= 16; graphic[0].Npixels -= 4) {
     149        if (DEBUG) fprintf (stderr, "trying %d colors\n", (int) graphic[0].Npixels);
     150        if (XAllocColorCells (graphic[0].display, graphic[0].colormap, FALSE, planes, 1, graphic[0].pixels, graphic[0].Npixels)) {
     151          break;
     152        }
     153      }
    166154
    167155      if ((N = get_argument (*argc, argv, "-colorcount"))) {
    168         fprintf (stderr, "kii can grab %d colors\n", (int) graphic[0].Npixels);
     156        fprintf (stderr, "kapa can grab %d colors\n", graphic[0].Npixels);
    169157        exit (0);
    170158      }
     
    174162      }
    175163    }
    176   }
    177 
    178   if (!dyn) {
    179     graphic[0].Npixels = 256;
    180     // fprintf (stderr, "can't use dynamic colors, color scrollbar inactive\n");
    181     // fprintf (stderr, " this can be avoided by using a dynamic visual class\n");
    182     // fprintf (stderr, " (see Kii help page for details)\n");
     164  } else {
     165    // XXX allocate the unsigned long *pixels here and above
     166    ALLOCATE (graphic[0].pixels, unsigned long, NPIXELS_STATIC);
     167    ALLOCATE (graphic[0].cmap,   XColor,        NPIXELS_STATIC);
     168    graphic[0].Npixels = NPIXELS_STATIC;
    183169  }
    184170
    185171  if ((N = get_argument (*argc, argv, "-colorcount"))) {
    186     fprintf (stderr, "kii can grab %d colors\n", (int) graphic[0].Npixels);
     172    fprintf (stderr, "kii can grab %d colors\n", graphic[0].Npixels);
    187173    exit (0);
    188174  }
  • trunk/Ohana/src/kapa2/src/CreateZoom16.c

    r13479 r16011  
    3131  dy = image[0].zoom.dy;
    3232
    33   if (image[0].matrix.size == 0) {  /* create a test pattern */
     33  if (image[0].image[0].matrix.size == 0) {  /* create a test pattern */
    3434    REALLOCATE (image[0].zoom.data, char, 2*dy*dx);
    3535    bzero (image[0].zoom.data, image[0].zoom.dx*image[0].zoom.dy);
     
    4848  // define the color transform parameters
    4949  MaxValue = graphic[0].Npixels - 1;
    50   if (image[0].range != 0.0) {
    51     slope = graphic[0].Npixels / image[0].range;
    52     start = graphic[0].Npixels * image[0].zero / image[0].range;
     50  if (image[0].image[0].range != 0.0) {
     51    slope = graphic[0].Npixels / image[0].image[0].range;
     52    start = graphic[0].Npixels * image[0].image[0].zero / image[0].image[0].range;
    5353  } else {
    5454    slope = 1.0;
    55     start = image[0].zero;
     55    start = image[0].image[0].zero;
    5656  }
    5757
     
    6161  expand_in  = 1;
    6262
    63   DX = image[0].matrix.Naxis[0];
    64   DY = image[0].matrix.Naxis[1];
     63  DX = image[0].image[0].matrix.Naxis[0];
     64  DY = image[0].image[0].matrix.Naxis[1];
    6565  Rx = x - expand*(int)(0.5*(dx + 1)) + 1;
    6666  Ry = y - expand*(int)(0.5*(dy + 1)) + 1;
     
    7474
    7575  data = out_pix = (unsigned char *) image[0].zoom.data;
    76   imdata  = (float *) image[0].matrix.buffer;
     76  imdata  = (float *) image[0].image[0].matrix.buffer;
    7777  in_pix  = &imdata[DX*(int)MAX(Ry,0) + (int)MAX(Rx,0)];
    7878
  • trunk/Ohana/src/kapa2/src/CreateZoom24.c

    r13479 r16011  
    3232  extra = 4 - (dx * 3) % 4;
    3333
    34   if (image[0].matrix.size == 0) {  /* create a test pattern */
     34  if (image[0].image[0].matrix.size == 0) {  /* create a test pattern */
    3535    REALLOCATE (image[0].zoom.data, char, dy*(3*dx+extra));
    3636    bzero (image[0].zoom.data, image[0].zoom.dx*image[0].zoom.dy);
     
    5252  // define the color transform parameters
    5353  MaxValue = graphic[0].Npixels - 1;
    54   if (image[0].range != 0.0) {
    55     slope = graphic[0].Npixels / image[0].range;
    56     start = graphic[0].Npixels * image[0].zero / image[0].range;
     54  if (image[0].image[0].range != 0.0) {
     55    slope = graphic[0].Npixels / image[0].image[0].range;
     56    start = graphic[0].Npixels * image[0].image[0].zero / image[0].image[0].range;
    5757  } else {
    5858    slope = 1.0;
    59     start = image[0].zero;
     59    start = image[0].image[0].zero;
    6060  }
    6161
     
    6565  expand_in  = 1;
    6666
    67   DX = image[0].matrix.Naxis[0];
    68   DY = image[0].matrix.Naxis[1];
     67  DX = image[0].image[0].matrix.Naxis[0];
     68  DY = image[0].image[0].matrix.Naxis[1];
    6969  Rx = x - expand*(int)(0.5*(dx + 1)) + 1;
    7070  Ry = y - expand*(int)(0.5*(dy + 1)) + 1;
     
    7878
    7979  data = out_pix = (unsigned char *) image[0].zoom.data;
    80   imdata  = (float *) image[0].matrix.buffer;
     80  imdata  = (float *) image[0].image[0].matrix.buffer;
    8181  in_pix  = &imdata[DX*(int)MAX(Ry,0) + (int)MAX(Rx,0)];
    8282
  • trunk/Ohana/src/kapa2/src/CreateZoom32.c

    r13479 r16011  
    11# include "Ximage.h"
    22# 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 }
    143
    154void CreateZoom32 (KapaImageWidget *image, Graphic *graphic, double x, double y) {
     
    2211  int expand_in, expand_out;
    2312  unsigned int *out_pix, *out_pix2;
    24   float *imdata, *in_pix, *in_pix2;
    25   unsigned long pixel[256], pixvalue;
     13  unsigned short *in_pix, *in_pix2;
     14  unsigned long *pixel, pixvalue;
    2615  unsigned long back;
    2716
    28   if (image[0].matrix.size == 0) {  /* create a test pattern */
     17  if (image[0].image[0].matrix.size == 0) {  /* create a test pattern */
    2918    REALLOCATE (image[0].zoom.data, char, 4*image[0].zoom.dx*image[0].zoom.dy);
    3019    image[0].zoom.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0,
     
    3322  }
    3423
    35   for (i = 0; i < 256; i++) { /* set up pixel array */
     24  ALLOCATE (pixel, unsigned long, graphic[0].Npixels);
     25
     26  // local array for pixel values
     27  for (i = 0; i < graphic[0].Npixels; i++) {
    3628    pixel[i] = graphic[0].cmap[i].pixel;
    3729  }
    3830  back = graphic[0].back;
    39 
    40   // define the color transform parameters
    41   MaxValue = graphic[0].Npixels - 1;
    42   if (image[0].range != 0.0) {
    43     slope = graphic[0].Npixels / image[0].range;
    44     start = graphic[0].Npixels * image[0].zero / image[0].range;
    45   } else {
    46     slope = 1.0;
    47     start = image[0].zero;
    48   }
    4931
    5032  zoomscale = MAX (5, image[0].expand + 5);
     
    5537  dx = image[0].zoom.dx;
    5638  dy = image[0].zoom.dy;
    57   DX = image[0].matrix.Naxis[0];
    58   DY = image[0].matrix.Naxis[1];
     39  DX = image[0].image[0].matrix.Naxis[0];
     40  DY = image[0].image[0].matrix.Naxis[1];
     41 
     42  /* Rx,Ry are the screen coordinates of the first image pixel */
    5943  Rx = x - expand*(int)(0.5*(dx + 1)) + 1;
    6044  Ry = y - expand*(int)(0.5*(dy + 1)) + 1;
     
    6448  i_end   = MAX (MIN ((DX-Rx) / expand, dx - expand_out + 1), 0);
    6549  j_end   = MAX (MIN ((DY-Ry) / expand, dy - expand_out + 1), 0);
     50
    6651  dropback = expand_out - (i_end - i_start) % expand_out;
    6752  if ((i_end - i_start) % expand_out == 0) dropback = 0;
    6853
    6954  out_pix = (unsigned int *) image[0].zoom.data;
    70   imdata  = (float *) image[0].matrix.buffer;
    71   in_pix  = &imdata[DX*(int)MAX(Ry,0) + (int)MAX(Rx,0)];
     55  in_pix  = &image[0].pixmap[DX*(int)MAX(Ry,0) + (int)MAX(Rx,0)];
    7256
    7357  /********** below we do the mapping from buffer pixels (in) to picture pixels (out) **********/
     
    7862    return;
    7963  }
    80   
     64 
    8165
    8266  /**** fill in bottom area ****/
    8367  for (j = 0; j < dx*j_start; j++, out_pix++) {
    84     out_pix[0] = back;
     68    *out_pix = back;
    8569  }
    8670
     
    8872
    8973    /**** fill in area to the left of the picture ****/
    90     for (jj = 0; jj < expand_out; jj++) {
     74    for (jj = 0; (i_start > 0) && (jj < expand_out); jj++) {
    9175      out_pix2 = out_pix + jj*dx;
    9276      for (i = 0; i < i_start; i++, out_pix2++) {
    93         out_pix[0] = back;
     77        *out_pix2 = back;
    9478      }
    9579    }
     
    10084    if (expand_out == 1) {
    10185      for (i = i_start; i < i_end; i++, in_pix2+= expand_in, out_pix++) {
    102         pixelN = PixelLookup(*in_pix2);
    103         out_pix[0] = pixel[pixelN];
     86        *out_pix = pixel[*in_pix2];
    10487      }
    105     }
    106     else {
     88    } else {
    10789      for (i = i_start; i < i_end; i+= expand_out, in_pix2++, out_pix+= expand_out) {
    108         pixelN   = PixelLookup(*in_pix2);
    109         pixvalue = pixel[pixelN];
     90        pixvalue = pixel[*in_pix2];
    11091        out_pix2 = out_pix;
    11192        for (jj = 0; jj < expand_out; jj++, out_pix2+=(dx-expand_out)) {
    11293          for (ii = 0; ii < expand_out; ii++, out_pix2++) {
    113             out_pix2[0] = pixvalue;
     94            *out_pix2 = pixvalue;
    11495          }
    11596        }
     
    11798    }
    11899    out_pix -= dropback;
    119 
    120100   
    121101    /**** fill in area to the right of the picture ****/
     
    123103      out_pix2 = out_pix + jj*dx;
    124104      for (i = i_end; i < dx; i++, out_pix2++) {
    125         out_pix2[0] = back;
     105        *out_pix2 = back;
    126106      }
    127107    }
     
    134114  /**** fill in top area ****/
    135115  for (j = 0; (j < dx*(dy - j_end)) && (out_pix - (unsigned int *)image[0].zoom.data < dx*dy); j++, out_pix++) {
    136     out_pix[0] = back;
     116    *out_pix = back;
    137117  }
    138118
    139   out_pix = (unsigned int *)image[0].zoom.data;
    140119  image[0].zoom.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0,
    141120                                        image[0].zoom.data, image[0].zoom.dx, image[0].zoom.dy, 32, 0);
    142121 
     122  free (pixel);
    143123}
  • trunk/Ohana/src/kapa2/src/CreateZoom8.c

    r14590 r16011  
    2626  unsigned long back;
    2727
    28   if (image[0].matrix.size == 0) {  /* create a test pattern */
     28  if (image[0].image[0].matrix.size == 0) {  /* create a test pattern */
    2929    REALLOCATE (image[0].zoom.data, char, image[0].zoom.dx*image[0].zoom.dy);
    3030    bzero (image[0].zoom.data, image[0].zoom.dx*image[0].zoom.dy);
     
    4141  // define the color transform parameters
    4242  MaxValue = graphic[0].Npixels - 1;
    43   if (image[0].range != 0.0) {
    44     slope = graphic[0].Npixels / image[0].range;
    45     start = graphic[0].Npixels * image[0].zero / image[0].range;
     43  if (image[0].image[0].range != 0.0) {
     44    slope = graphic[0].Npixels / image[0].image[0].range;
     45    start = graphic[0].Npixels * image[0].image[0].zero / image[0].image[0].range;
    4646  } else {
    4747    slope = 1.0;
    48     start = image[0].zero;
     48    start = image[0].image[0].zero;
    4949  }
    5050
     
    5656  dx = image[0].zoom.dx;
    5757  dy = image[0].zoom.dy;
    58   DX = image[0].matrix.Naxis[0];
    59   DY = image[0].matrix.Naxis[1];
     58  DX = image[0].image[0].matrix.Naxis[0];
     59  DY = image[0].image[0].matrix.Naxis[1];
    6060  Rx = x - expand*(int)(0.5*(dx + 1)) + 1;
    6161  Ry = y - expand*(int)(0.5*(dy + 1)) + 1;
     
    6969
    7070  out_pix = (unsigned char *) image[0].zoom.data;
    71   imdata  = (float *) image[0].matrix.buffer;
     71  imdata  = (float *) image[0].image[0].matrix.buffer;
    7272  in_pix  = &imdata[DX*(int)MAX(Ry,0) + (int)MAX(Rx,0)];
    7373
  • trunk/Ohana/src/kapa2/src/CursorOps.c

    r13320 r16011  
    1313  }
    1414 
    15   *x1 = expand*(x2 - image[0].picture.x - 0.5*image[0].picture.dx) + 0.5*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].matrix.Naxis[1] - image[0].Y;
     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;
    1717 
    1818}
     
    3131  }
    3232 
    33   *x1 = (x2 - 0.5*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].matrix.Naxis[1] + image[0].Y) * expand + image[0].picture.y + 0.5*image[0].picture.dy;
     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;
    3535 
    3636}
  • trunk/Ohana/src/kapa2/src/DragColorbar.c

    r13320 r16011  
    1515  Y = mouse_event[0].y;
    1616  Npix = graphic[0].Npixels;
    17   slope = image[0].slope;
    18   start = image[0].start;
     17  slope = image[0].image[0].slope;
     18  start = image[0].image[0].start;
    1919  oldfrac_x = oldfrac_y = 10;
    2020 
     
    6363      case ButtonPress:
    6464      case ButtonRelease:
    65         image[0].start = start;
    66         image[0].slope = slope;
     65        image[0].image[0].start = start;       
     66        image[0].image[0].slope = slope;
    6767        return;
    6868        break;
  • trunk/Ohana/src/kapa2/src/Image.c

    r13479 r16011  
    22# include "buttons.h"
    33
     4int InitImageChannel (KapaImageChannel *channel) {
     5
     6  /** set up a bunch of default things **/
     7  channel->zero = 0;
     8  channel->range = 1;
     9  channel->start = 0;
     10  channel->slope = 1;
     11
     12  channel->coords.Npolyterms = 0;
     13  channel->matrix.size = 0; /* a flag to show there is no data in the matrix */
     14  ALLOCATE (channel->matrix.buffer, char, 1);  /* allocate so later free will not crash! */
     15
     16  return (TRUE);
     17}
     18
    419/* initialization for things not specific to X */
    5 KapaImageWidget *InitImage () {
     20KapaImageWidget *InitImageWidget () {
    621
    722  int i;
     
    1429  memset (image, 0, sizeof(KapaImageWidget));
    1530
    16   /** set up a bunch of default things **/
    17   image[0].X = image[0].Y = 0;
    18   image[0].expand = 1;
    19   image[0].zero = 0;
    20   image[0].range = 1;
    21   image[0].start = 0;
    22   image[0].slope = 1;
    23   image[0].location = 4;
     31  for (i = 0; i < NCHANNELS; i++) {
     32    InitImageChannel (&image[0].channel[i]);
     33  }
     34  image[0].image = &image[0].channel[0];
    2435
    25   image[0].coords.Npolyterms = 0;
     36  image[0].nPixels = 0;
     37  ALLOCATE (image[0].pixmap, unsigned short, 1);  /* allocate so later free will not crash! */
     38
     39  // XXXX this has been moved to graphic, which may be wrong
     40  // image[0].ColorScaleMode = KAPA_SCALE_1D;
     41
    2642  for (i = 0; i < NOVERLAYS; i++) {
    2743    image[0].overlay[i].Nobjects = 0;
     
    3046    image[0].overlay[i].color = graphic[0].overlay_color[i];
    3147  }
    32   image[0].matrix.size = 0; /* a flag to show there is no data in the matrix */
     48
     49  image[0].X = 0.0;
     50  image[0].Y = 0.0;
     51  image[0].expand = 1;
     52  image[0].location = 4;
    3353
    3454  image[0].MovePointer = TRUE;
    3555  image[0].DecimalDegrees  = TRUE;
    36   ALLOCATE (image[0].matrix.buffer, char, 1);  /* allocate so later free will not crash! */
    3756  ALLOCATE (image[0].picture.data, char, 1);   /* allocate so later free will not crash! */
    3857  ALLOCATE (image[0].cmapbar.data, char, 1);   /* allocate so later free will not crash! */
     
    4867  InitButtonFunc (&image[0].rainbow_button, rainbow);
    4968
    50   InitButtonSize (&image[0].puns_button, puns_width, puns_height, puns_bits);
    51   InitButtonFunc (&image[0].puns_button, puns);
     69  InitButtonSize (&image[0].heat_button, heat_width, heat_height, heat_bits);
     70  InitButtonFunc (&image[0].heat_button, heat);
    5271
    5372  InitButtonSize (&image[0].recenter_button, recenter_width, recenter_height, recenter_bits);
     
    131150    DrawButton (graphic, &image[0].grey_button);
    132151    DrawButton (graphic, &image[0].rainbow_button);
    133     DrawButton (graphic, &image[0].puns_button);
     152    DrawButton (graphic, &image[0].heat_button);
    134153    DrawButton (graphic, &image[0].hms_button);
    135154
     
    152171    free (image[0].overlay[i].objects);
    153172  }
    154   free (image[0].matrix.buffer);
     173  for (i = 0; i < NCHANNELS; i++) {
     174    free (image[0].channel[i].matrix.buffer);
     175  }
     176  free (image[0].pixmap);
    155177  free (image[0].picture.data);
    156178  free (image[0].cmapbar.data);
  • trunk/Ohana/src/kapa2/src/InterpretKeys.c

    r14590 r16011  
    6161      if (event[0].y > image[0].picture.y + image[0].picture.dy) goto skip_cursor;
    6262      Screen_to_Image (&X, &Y, (double)event[0].x, (double)event[0].y, image);
    63       XY_to_RD (&R, &D, X, Y, &image[0].coords);
     63      XY_to_RD (&R, &D, X, Y, &image[0].image[0].coords);
    6464
    65       DX = image[0].matrix.Naxis[0];
    66       DY = image[0].matrix.Naxis[1];
     65      DX = image[0].image[0].matrix.Naxis[0];
     66      DY = image[0].image[0].matrix.Naxis[1];
    6767
    6868      if (X < 0) goto off_image;
     
    7070      if (X >= DX) goto off_image;
    7171      if (Y >= DY) goto off_image;
    72       imdata = (float *) image[0].matrix.buffer;
     72      imdata = (float *) image[0].image[0].matrix.buffer;
    7373      Z      = imdata[DX*(int)(Y) + (int)(X)];
    7474    }
     
    8989  switch (keysym) {
    9090
     91    case XK_F1:
     92      image[0].image = &image[0].channel[0];
     93      Reorient (graphic, image, image[0].X, image[0].Y, 0);
     94      break;
     95
     96    case XK_F2:
     97      image[0].image = &image[0].channel[1];
     98      Reorient (graphic, image, image[0].X, image[0].Y, 0);
     99      break;
     100
     101    case XK_F3:
     102      image[0].image = &image[0].channel[2];
     103      Reorient (graphic, image, image[0].X, image[0].Y, 0);
     104      break;
     105
    91106    case XK_KP_Home:
    92107    case XK_Home:
     
    103118    case XK_Return:
    104119      Screen_to_Image (&X, &Y, (double)event[0].x, (double)event[0].y, image);
    105       X = 0.5*image[0].matrix.Naxis[0] - X;
    106       Y = 0.5*image[0].matrix.Naxis[1] - Y;
     120      X = 0.5*image[0].image[0].matrix.Naxis[0] - X;
     121      Y = 0.5*image[0].image[0].matrix.Naxis[1] - Y;
    107122      Reorient (graphic, image, X, Y, 0);
    108123      break;
     
    132147      break;
    133148
     149    case XK_KP_Add:
     150      image[0].image[0].zero += 0.1*image[0].image[0].range;
     151      Reorient (graphic, image, image[0].X, image[0].Y, 0);
     152      break;
     153    case XK_KP_Subtract:
     154      image[0].image[0].zero -= 0.1*image[0].image[0].range;
     155      Reorient (graphic, image, image[0].X, image[0].Y, 0);
     156      break;
     157
    134158    case XK_Tab:
    135159      image[0].MovePointer = image[0].MovePointer ^ TRUE;
  • trunk/Ohana/src/kapa2/src/InterpretPresses.c

    r14590 r16011  
    3636      Screen_to_Image (&X, &Y, (double)event[0].x, (double)event[0].y, image);
    3737
    38       XY_to_RD (&R, &D, X, Y, &image[0].coords);
     38      XY_to_RD (&R, &D, X, Y, &image[0].image[0].coords);
    3939
    40       DX = image[0].matrix.Naxis[0];
    41       DY = image[0].matrix.Naxis[1];
     40      DX = image[0].image[0].matrix.Naxis[0];
     41      DY = image[0].image[0].matrix.Naxis[1];
    4242
    4343      if (X < 0) goto off_image;
     
    4545      if (X >= DX) goto off_image;
    4646      if (Y >= DY) goto off_image;
    47       imdata = (float *) image[0].matrix.buffer;
     47      imdata = (float *) image[0].image[0].matrix.buffer;
    4848      Z      = imdata[DX*(int)(Y) + (int)(X)];
    4949    }
     
    102102
    103103  Screen_to_Image (&X, &Y, (double)mouse_event[0].x, (double)mouse_event[0].y, image);
    104   X = 0.5*image[0].matrix.Naxis[0] - X;
    105   Y = 0.5*image[0].matrix.Naxis[1] - Y;
     104  X = 0.5*image[0].image[0].matrix.Naxis[0] - X;
     105  Y = 0.5*image[0].image[0].matrix.Naxis[1] - Y;
    106106
    107107  switch (mouse_event[0].button) {
  • trunk/Ohana/src/kapa2/src/JPEGit24.c

    r14590 r16011  
    3737  double expand, Rx, Ry, X, Y;
    3838  unsigned char *out_pix;
    39   float *imdata, *in_pix, *in_pix_ref;
    40   unsigned char pixel1[256], pixel2[256], pixel3[256];
     39  unsigned short *in_pix, *in_pix_ref;
     40  unsigned char *pixel1, *pixel2, *pixel3;
    4141  char filename[1024];
    4242  FILE *f;
     
    7575  jpeg_start_compress (&cinfo, TRUE);
    7676
     77  ALLOCATE (pixel1, unsigned char, graphic[0].Npixels);
     78  ALLOCATE (pixel2, unsigned char, graphic[0].Npixels);
     79  ALLOCATE (pixel3, unsigned char, graphic[0].Npixels);
     80
    7781  /** cmap[i].pixel must be defined even if X is not used **/
    78   for (i = 0; i < 256; i++) { /* set up pixel array */
     82  for (i = 0; i < graphic[0].Npixels; i++) { /* set up pixel array */
    7983    pixel1[i] = graphic[0].cmap[i].red >> 8;
    8084    pixel2[i] = graphic[0].cmap[i].green >> 8;
    8185    pixel3[i] = graphic[0].cmap[i].blue >> 8;
    82   }
    83 
    84   // define the color transform parameters
    85   MaxValue = graphic[0].Npixels - 1;
    86   if (image[0].range != 0.0) {
    87     slope = graphic[0].Npixels / image[0].range;
    88     start = graphic[0].Npixels * image[0].zero / image[0].range;
    89   } else {
    90     slope = 1.0;
    91     start = image[0].zero;
    9286  }
    9387
     
    108102  dx = image[0].picture.dx;
    109103  dy = image[0].picture.dy;
    110   DX = image[0].matrix.Naxis[0];
    111   DY = image[0].matrix.Naxis[1];
     104  DX = image[0].image[0].matrix.Naxis[0];
     105  DY = image[0].image[0].matrix.Naxis[1];
    112106
    113107  /* X,Y are the image coordinates of the first image pixel */
     
    145139  ALLOCATE (line_buffer, JSAMPLE, 3*dx);
    146140
    147   imdata = (float *) image[0].matrix.buffer;
    148   in_pix_ref = &imdata[DX*(int)MAX(Y,0) + (int)MAX(X,0)];
     141  in_pix_ref  = &image[0].pixmap[DX*(int)MAX(Y,0) + (int)MAX(X,0)];
    149142
    150143  /********** below we do the mapping from buffer pixels (in) to picture pixels (out) **********/
     
    177170    /*** fill in the picture region ***/
    178171    for (i = i_start; i < i_end; i+=expand_out, in_pix+=expand_in) {
    179       pixelN = PixelLookup(*in_pix);
    180172      for (ii = 0; ii < expand_out; ii++, out_pix+=3) {
    181         out_pix[0] = pixel1[pixelN];
    182         out_pix[1] = pixel2[pixelN];
    183         out_pix[2] = pixel3[pixelN];
     173        out_pix[0] = pixel1[*in_pix];
     174        out_pix[1] = pixel2[*in_pix];
     175        out_pix[2] = pixel3[*in_pix];
    184176      }
    185177    }
  • trunk/Ohana/src/kapa2/src/LoadOverlay.c

    r15620 r16011  
    1414  section = GetActiveSection();
    1515  if (section->image == NULL) {
    16     section->image = InitImage ();
     16    section->image = InitImageWidget ();
    1717    SetSectionSizes (section);
    1818  }
  • trunk/Ohana/src/kapa2/src/LoadPicture.c

    r15589 r16011  
    1313  section = GetActiveSection();
    1414  if (section->image == NULL) {
    15     section->image = InitImage ();
     15    section->image = InitImageWidget ();
    1616    SetSectionSizes (section);
    1717  }
     
    2424  KiiScanMessage (sock, "%d %d %d %d %lf %lf", &header.Naxis[0], &header.Naxis[1]);
    2525  KiiScanMessage (sock, "%d %d %d %d %lf %lf", &header.bitpix, &header.unsign, &header.bzero, &header.bscale);
    26   KiiScanMessage (sock, "%lf %lf %s %s",  &image[0].zero, &image[0].range, image[0].name, image[0].file);
    27   KiiScanMessage (sock, "%lf %lf %d", &image[0].min,  &image[0].max, &header.size);
    28   KiiScanMessage (sock, "%lf %f %f %f %f", &image[0].coords.crval1, &image[0].coords.crpix1, &image[0].coords.cdelt1, &image[0].coords.pc1_1, &image[0].coords.pc1_2);
    29   KiiScanMessage (sock, "%lf %f %f %f %f", &image[0].coords.crval2, &image[0].coords.crpix2, &image[0].coords.cdelt2, &image[0].coords.pc2_1, &image[0].coords.pc2_2);
    30   KiiScanMessage (sock, "%s", image[0].coords.ctype);
     26  KiiScanMessage (sock, "%lf %lf %s %s",  &image[0].image[0].zero, &image[0].image[0].range, image[0].image[0].name, image[0].image[0].file);
     27  KiiScanMessage (sock, "%lf %lf %d", &image[0].image[0].min,  &image[0].image[0].max, &header.size);
     28  KiiScanMessage (sock, "%lf %f %f %f %f", &image[0].image[0].coords.crval1, &image[0].image[0].coords.crpix1, &image[0].image[0].coords.cdelt1, &image[0].image[0].coords.pc1_1, &image[0].image[0].coords.pc1_2);
     29  KiiScanMessage (sock, "%lf %f %f %f %f", &image[0].image[0].coords.crval2, &image[0].image[0].coords.crpix2, &image[0].image[0].coords.cdelt2, &image[0].image[0].coords.pc2_1, &image[0].image[0].coords.pc2_2);
     30  KiiScanMessage (sock, "%s", image[0].image[0].coords.ctype);
    3131
    32   gfits_free_matrix (&image[0].matrix);
    33   gfits_create_matrix (&header, &image[0].matrix);
     32  gfits_free_matrix (&image[0].image[0].matrix);
     33  gfits_create_matrix (&header, &image[0].image[0].matrix);
    3434
    3535  fcntl (sock, F_SETFL, O_NONBLOCK); 
    3636
    3737  status = 1;
    38   buff = image[0].matrix.buffer;
     38  buff = image[0].image[0].matrix.buffer;
    3939  bytes_left = header.size;
    40   image[0].matrix.size = 0;
     40  image[0].image[0].matrix.size = 0;
    4141  while (bytes_left > 0) {
    4242    status = read (sock, buff, bytes_left);
     
    4646    }
    4747    if (status != -1) { /* pipe has data */
    48       image[0].matrix.size += status;
     48      image[0].image[0].matrix.size += status;
    4949      bytes_left -= status;
    5050      buff = (char *)(buff + status);
     
    5454  fcntl (sock, F_SETFL, !O_NONBLOCK); 
    5555
    56   if (DEBUG) fprintf (stderr, "read %d bytes\n", image[0].matrix.size);
     56  if (DEBUG) fprintf (stderr, "read %d bytes\n", image[0].image[0].matrix.size);
    5757  /* it it not obvious this condition should kill kii, but ... */
    58   if (image[0].matrix.size != header.size) { 
    59     fprintf (stderr, "error: expected %d bytes, but got only %d\n", header.size, image[0].matrix.size);
     58  if (image[0].image[0].matrix.size != header.size) { 
     59    fprintf (stderr, "error: expected %d bytes, but got only %d\n", header.size, image[0].image[0].matrix.size);
    6060    return (FALSE);
    6161  }
     
    6363  if (!USE_XWINDOW) return (TRUE);
    6464
    65   Remap (graphic, image, &image[0].matrix);
     65  SetColorScale (graphic, image);
     66  Remap (graphic, image);
    6667  if (DEBUG) fprintf (stderr, "remapped image\n");
    6768  Refresh ();
  • trunk/Ohana/src/kapa2/src/LoadTickmarks.c

    r13479 r16011  
    1111  section = GetActiveSection();
    1212  if (section->image == NULL) {
    13     section->image = InitImage ();
     13    section->image = InitImageWidget ();
    1414    SetSectionSizes (section);
    1515  }
  • trunk/Ohana/src/kapa2/src/MakeColormap.c

    r13320 r16011  
    11# include "Ximage.h"
    2 # define NPIXELS 64
    32
    43static char default_cmap[] = "grayscale";
  • trunk/Ohana/src/kapa2/src/PSPixmap.c

    r13331 r16011  
    1313  /* start at the last line, print lines in decending order */
    1414  buff = (unsigned char *)image[0].picture.data + image[0].picture.dx*(image[0].picture.dy - 1);
    15   slope = image[0].slope;
    16   start = image[0].start;
     15  slope = image[0].image[0].slope;
     16  start = image[0].image[0].start;
    1717  back  = graphic[0].back;
    1818
     
    4646  /* start at the last line, print lines in decending order */
    4747  buff = (unsigned short *)image[0].picture.data + image[0].picture.dx*(image[0].picture.dy - 1);
    48   slope = image[0].slope;
    49   start = image[0].start;
     48  slope = image[0].image[0].slope;
     49  start = image[0].image[0].start;
    5050  back  = graphic[0].back;
    5151
     
    8383  /* start at the last line, print lines in decending order */
    8484  buff = (unsigned char *)&image[0].picture.data[(dy - 1)*(3*dx + extra)];
    85   slope = image[0].slope;
    86   start = image[0].start;
     85  slope = image[0].image[0].slope;
     86  start = image[0].image[0].start;
    8787  back  = graphic[0].back;
    8888
     
    123123  /* start at the last line, print lines in decending order */
    124124  buff = (unsigned int *)image[0].picture.data + image[0].picture.dx*(image[0].picture.dy - 1);
    125   slope = image[0].slope;
    126   start = image[0].start;
     125  slope = image[0].image[0].slope;
     126  start = image[0].image[0].start;
    127127  back  = graphic[0].back;
    128128
     
    143143  return;
    144144}
     145
     146# if (0)
     147// XXX needs work!
     148void PSPixmap32_RGB (Graphic *graphic, KapaImageWidget *image, FILE *f) {
     149
     150  int i, k, m, val;
     151  double Nchar, Npix, start, slope, frac;
     152  unsigned int *buff;
     153  unsigned long back;
     154  unsigned char
     155
     156  ALLOCATE (pixelR, unsigned char, graphic[0].Npixels);
     157  ALLOCATE (pixelG, unsigned char, graphic[0].Npixels);
     158  ALLOCATE (pixelB, unsigned char, graphic[0].Npixels);
     159
     160  /** cmap[i].pixel must be defined even if X is not used **/
     161  for (i = 0; i < graphic[0].Npixels; i++) { /* set up pixel array */
     162    pixelR[i] = graphic[0].cmap[i].red >> 8;
     163    pixelG[i] = graphic[0].cmap[i].green >> 8;
     164    pixelB[i] = graphic[0].cmap[i].blue >> 8;
     165  }
     166
     167  for (i = 0; i < image[0].picture.dy; i++) {
     168    for (k = 0; k < image[0].picture.dx; k++, buff++) {
     169      if (*buff == back)
     170        val = Nchar;
     171      else {
     172        for (m = 0; (graphic[0].cmap[m].pixel != *buff) && (m < Npix); m++);
     173        val = Nchar - frac * MIN (MAX (start + m * slope, 0), Npix);
     174      }
     175      fprintf (f, "%02x", val);
     176      if (!((k+1) % 40)) fprintf (f, "\n");
     177    }
     178    fprintf (f, "\n");
     179    buff -= 2*image[0].picture.dx;
     180  }
     181  return;
     182}
     183# endif
  • trunk/Ohana/src/kapa2/src/Remap.c

    r13320 r16011  
    11# include "Ximage.h"
    22
    3 void Remap (Graphic *graphic, KapaImageWidget *image, Matrix *matrix) {
     3void Remap (Graphic *graphic, KapaImageWidget *image) {
    44
    55  switch (graphic[0].Nbits) {
    66  case 8:
    7     Remap8 (graphic, image, matrix);
     7    Remap8  (graphic, image, &image->image->matrix);
    88    break;
    99  case 16:
    10     Remap16 (graphic, image, matrix);
     10    Remap16 (graphic, image, &image->image->matrix);
    1111    break;
    1212  case 24:
    13     Remap24 (graphic, image, matrix);
     13    Remap24 (graphic, image, &image->image->matrix);
    1414    break;
    1515  case 32:
    16     Remap32 (graphic, image, matrix);
     16    Remap32 (graphic, image, &image->image->matrix);
    1717    break;
    1818  }
  • trunk/Ohana/src/kapa2/src/Remap16.c

    r13479 r16011  
    3838  // define the color transform parameters
    3939  MaxValue = graphic[0].Npixels - 1;
    40   if (image[0].range != 0.0) {
    41     slope = graphic[0].Npixels / image[0].range;
    42     start = graphic[0].Npixels * image[0].zero / image[0].range;
     40  if (image[0].image[0].range != 0.0) {
     41    slope = graphic[0].Npixels / image[0].image[0].range;
     42    start = graphic[0].Npixels * image[0].image[0].zero / image[0].image[0].range;
    4343  } else {
    4444    slope = 1.0;
    45     start = image[0].zero;
     45    start = image[0].image[0].zero;
    4646  }
    4747
  • trunk/Ohana/src/kapa2/src/Remap24.c

    r13479 r16011  
    4040  // define the color transform parameters
    4141  MaxValue = graphic[0].Npixels - 1;
    42   if (image[0].range != 0.0) {
    43     slope = graphic[0].Npixels / image[0].range;
    44     start = graphic[0].Npixels * image[0].zero / image[0].range;
     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;
    4545  } else {
    4646    slope = 1.0;
    47     start = image[0].zero;
     47    start = image[0].image[0].zero;
    4848  }
    4949
  • trunk/Ohana/src/kapa2/src/Remap32.c

    r13479 r16011  
    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 Remap32 (Graphic *graphic, KapaImageWidget *image, Matrix *matrix) {
     
    2110  int expand_in, expand_out;
    2211  unsigned int *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].range != 0.0) {
    36     slope = graphic[0].Npixels / image[0].range;
    37     start = graphic[0].Npixels * image[0].zero / image[0].range;
    38   } else {
    39     slope = 1.0;
    40     start = image[0].zero;
    41   }
    4223
    4324  // set up expansions
     
    6142  DX = matrix[0].Naxis[0];
    6243  DY = matrix[0].Naxis[1];
     44
    6345  /* X,Y are the image coordinates of the first image pixel */
    6446  X = MAX(0.5*(DX - dx*expand) - image[0].X, 0);
     
    9274
    9375  out_pix = (unsigned int *) image[0].picture.data;
    94   imdata  = (float *) matrix[0].buffer;
    95   in_pix  = &imdata[DX*(int)MAX(Y,0) + (int)MAX(X,0)];
     76  in_pix  = &image[0].pixmap[DX*(int)MAX(Y,0) + (int)MAX(X,0)];
    9677
    9778  /********** below we do the mapping from buffer pixels (in) to picture pixels (out) **********/
    9879
    9980  /**** fill in bottom area ****/
    100   for (j = 0; j < dx*j_start; j++, out_pix++)
     81  for (j = 0; j < dx*j_start; j++, out_pix++) {
    10182    *out_pix = back;
     83  }
    10284 
    10385  for (j = j_start; j < j_end; j+= expand_out, out_pix+=(expand_out-1)*dx, in_pix += expand_in*DX) {
     
    11698    if (expand_out == 1) {
    11799      for (i = i_start; i < i_end; i++, in_pix2+= expand_in, out_pix++) {
    118         pixelN = PixelLookup(*in_pix2);
    119         *out_pix = pixel[pixelN];
     100        *out_pix = pixel[*in_pix2];
    120101      }
    121     }
    122     else {
     102    } else {
    123103      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];
     104        pixvalue = pixel[*in_pix2];
    126105        out_pix2 = out_pix;
    127106        for (jj = 0; jj < expand_out; jj++, out_pix2+=(dx-expand_out)) {
     
    142121    }
    143122    out_pix += (dx - i_end);
    144    
    145123  }
    146124 
     
    152130    *out_pix = back;
    153131  }
     132
    154133  image[0].picture.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0,
    155134                                        image[0].picture.data, image[0].picture.dx, image[0].picture.dy, 32, 0);
     135
     136  free (pixel);
    156137}
    157 
  • trunk/Ohana/src/kapa2/src/Remap8.c

    r13479 r16011  
    3333  // define the color transform parameters
    3434  MaxValue = graphic[0].Npixels - 1;
    35   if (image[0].range != 0.0) {
    36     slope = graphic[0].Npixels / image[0].range;
    37     start = graphic[0].Npixels * image[0].zero / image[0].range;
     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;
    3838  } else {
    3939    slope = 1.0;
    40     start = image[0].zero;
     40    start = image[0].image[0].zero;
    4141  }
    4242
  • trunk/Ohana/src/kapa2/src/Reorient.c

    r13320 r16011  
    44
    55  if (image[0].expand == 0) image[0].expand = 1;
     6
     7  if ((image[0].X == X) && (image[0].Y == Y) && (mode == 0)) {
     8    Refresh ();
     9    XFlush (graphic[0].display);
     10    return;
     11  }
    612
    713  switch (mode) {
     
    3844  }
    3945
    40   Remap (graphic, image, &image[0].matrix);
     46  Remap (graphic, image);
    4147  Refresh ();
    4248 
  • trunk/Ohana/src/kapa2/src/SetColormap.c

    r13320 r16011  
    11# include "Ximage.h"
    22
    3 /*** this function uses only private colormaps.  it should try the standard colormap
    4      first to get better control over the smooth greyscales ***/
     3# define SETVALUE(VAR,VALUE,MINVAL,MAXVAL) { \
     4  float tmp = (VALUE); \
     5  if (tmp < MINVAL) { \
     6    VAR = MINVAL; \
     7  } else if (tmp > MAXVAL) { \
     8    VAR = MAXVAL; \
     9  } else { \
     10    VAR = tmp; \
     11  } }   
    512
    613int SetColormap (char *name) {
    714
    8   int i;
     15  int i, red, blue, green;
     16  float scale, blueRef, redRef, greenRef;
    917  Graphic *graphic;
    1018
    1119  graphic = GetGraphic();
    1220
     21  // the "fullcolor" colormap is uniquely defined for each image;
     22  // defer to the 'SetColorScale' step
     23  if (!strcasecmp (name, "fullcolor")) {
     24    graphic[0].ColorScaleMode = KAPA_SCALE_3D_FULL;
     25    return TRUE;
     26  }
     27
     28  // very simple color model: evenly spaced cube
     29  if (!strcasecmp (name, "ruffcolor")) {
     30      graphic[0].nRed  = pow (graphic[0].Npixels, 0.333);
     31      graphic[0].nBlue = pow (graphic[0].Npixels, 0.333);
     32      graphic[0].nGreen = graphic[0].Npixels / (graphic[0].nRed * graphic[0].nBlue);
     33
     34      // red,green,blue are values in range 0x0000 to 0xffff
     35      float redScale = 0xffff / (graphic[0].nRed - 1);
     36      float blueScale = 0xffff / (graphic[0].nBlue - 1);
     37      float greenScale = 0xffff / (graphic[0].nGreen - 1);
     38
     39      i = 0;
     40      for (red = 0; red < graphic[0].nRed; red++) { 
     41          for (blue = 0; blue < graphic[0].nBlue; blue++) { 
     42              for (green = 0; green < graphic[0].nGreen; green++, i++) { 
     43                  SETVALUE (graphic[0].cmap[i].red,   red*redScale, 0, 0xffff);
     44                  SETVALUE (graphic[0].cmap[i].blue,  blue*blueScale, 0, 0xffff);
     45                  SETVALUE (graphic[0].cmap[i].green, green*greenScale, 0, 0xffff);
     46                  graphic[0].cmap[i].flags = DoRed | DoGreen | DoBlue;
     47              }
     48          }
     49      }
     50
     51      // all other modes are 1D: set the flag:
     52      graphic[0].ColorScaleMode = KAPA_SCALE_3D_RUFF;
     53      goto store_colors;
     54  }
     55
     56  // all other modes are 1D: set the flag:
     57  graphic[0].ColorScaleMode = KAPA_SCALE_1D;
     58
     59  // red,green,blue are values in range 0x0000 to 0xffff
     60  scale = 0xffff / (graphic[0].Npixels - 1);
     61
    1362  /* greyscale */
    14   if ((!strcmp (name, "grayscale")) || (!strcmp (name, "greyscale"))) {
     63  if ((!strcasecmp (name, "grayscale")) || (!strcasecmp (name, "greyscale"))) {
    1564    for (i = 0; i < graphic[0].Npixels; i++) { 
    16       graphic[0].cmap[i].red = 256*(255 - 255*i/graphic[0].Npixels);
    17       graphic[0].cmap[i].green = 256*(255 - 255*i/graphic[0].Npixels);
    18       graphic[0].cmap[i].blue = 256*(255 - 255*i/graphic[0].Npixels);
     65      SETVALUE (graphic[0].cmap[i].red,   0xffff - i*scale, 0, 0xffff);
     66      SETVALUE (graphic[0].cmap[i].green, 0xffff - i*scale, 0, 0xffff);
     67      SETVALUE (graphic[0].cmap[i].blue,  0xffff - i*scale, 0, 0xffff);
     68      graphic[0].cmap[i].flags = DoRed | DoGreen | DoBlue;
     69    }
     70    goto store_colors;
     71  }
     72  /* -grayscale */
     73  if ((!strcasecmp (name, "-grayscale")) || (!strcasecmp (name, "-greyscale"))) {
     74    for (i = 0; i < graphic[0].Npixels; i++) { 
     75      SETVALUE (graphic[0].cmap[i].red,   i*scale, 0, 0xffff);
     76      SETVALUE (graphic[0].cmap[i].green, i*scale, 0, 0xffff);
     77      SETVALUE (graphic[0].cmap[i].blue,  i*scale, 0, 0xffff);
    1978      graphic[0].cmap[i].flags = DoRed | DoGreen | DoBlue;
    2079    }
     
    2281  }
    2382  /* heat */
    24   if (!strcmp (name, "Puns")) {
     83  if (!strcasecmp (name, "Heat")) {
     84    greenRef = 0.25*graphic[0].Npixels*scale*2.0;
     85    blueRef  = 0.50*graphic[0].Npixels*scale*2.0;
    2586    for (i = 0; i < (int)(0.25*graphic[0].Npixels); i++) { 
     87      SETVALUE (graphic[0].cmap[i].red,   2*i*scale, 0, 0xffff);
    2688      graphic[0].cmap[i].green = 0;
    27       graphic[0].cmap[i].blue = 0;
    28       graphic[0].cmap[i].red = MIN (256*255, 256*255*2*i/(1.0*graphic[0].Npixels)); 
     89      graphic[0].cmap[i].blue  = 0;
    2990      graphic[0].cmap[i].flags = DoRed | DoGreen | DoBlue;
    3091    }
    31     for (i = (int)(0.25*graphic[0].Npixels); i < (int)(0.50*graphic[0].Npixels); i++) { 
    32       graphic[0].cmap[i].red = MIN (256*255, 256*255*2*i/(1.0*graphic[0].Npixels));
    33       graphic[0].cmap[i].green = MIN (256*255, 256*255*2*(i/(1.0*graphic[0].Npixels) - 0.25));
     92    for (i = 0.25*graphic[0].Npixels; i < 0.50*graphic[0].Npixels; i++) { 
     93      SETVALUE (graphic[0].cmap[i].red,   2*i*scale,            0, 0xffff);
     94      SETVALUE (graphic[0].cmap[i].green, 2*i*scale - greenRef, 0, 0xffff);
    3495      graphic[0].cmap[i].blue = 0;
    3596      graphic[0].cmap[i].flags = DoRed | DoGreen | DoBlue;
    3697    }
    3798    for (i = (int)(0.50*graphic[0].Npixels); i < (int)(0.75*graphic[0].Npixels); i++) { 
    38       graphic[0].cmap[i].red = 256*255;
    39       graphic[0].cmap[i].green = MIN (256*255, 256*255*2*(i/(1.0*graphic[0].Npixels) - 0.25));
    40       graphic[0].cmap[i].blue = MIN (256*255, 256*255*2*(i/(1.0*graphic[0].Npixels) - 0.50));
     99      graphic[0].cmap[i].red = 0xffff;
     100      SETVALUE (graphic[0].cmap[i].green, 2*i*scale - greenRef, 0, 0xffff);
     101      SETVALUE (graphic[0].cmap[i].blue,  2*i*scale - blueRef,  0, 0xffff);
    41102      graphic[0].cmap[i].flags = DoRed | DoGreen | DoBlue;
    42103    }
    43104    for (i = (int)(0.75*graphic[0].Npixels); i < graphic[0].Npixels; i++) { 
    44       graphic[0].cmap[i].red = 256*255;
    45       graphic[0].cmap[i].green = 256*255;
    46       graphic[0].cmap[i].blue = MIN (256*255, 256*255*2*(i/(1.0*graphic[0].Npixels) - 0.50));
    47       graphic[0].cmap[i].flags = DoRed | DoGreen | DoBlue;
    48     }
    49     goto store_colors;
    50   }
    51   /* -grayscale */
    52   if ((!strcmp (name, "-grayscale")) || (!strcmp (name, "-greyscale"))) {
    53     for (i = 0; i < graphic[0].Npixels; i++) { 
    54       graphic[0].cmap[i].red = 256*(255*i/graphic[0].Npixels);
    55       graphic[0].cmap[i].green = 256*(255*i/graphic[0].Npixels);
    56       graphic[0].cmap[i].blue = 256*(255*i/graphic[0].Npixels);
     105      graphic[0].cmap[i].red   = 0xffff;
     106      graphic[0].cmap[i].green = 0xffff;
     107      SETVALUE (graphic[0].cmap[i].blue,  2*i*scale - blueRef,  0, 0xffff);
    57108      graphic[0].cmap[i].flags = DoRed | DoGreen | DoBlue;
    58109    }
     
    60111  }
    61112  /* rainbow */
    62   if (!strcmp (name, "Rainbow")) {
     113  if (!strcasecmp (name, "Rainbow")) {
     114    redRef   = 0.25*graphic[0].Npixels*scale*4.0;
     115    greenRef = 0.50*graphic[0].Npixels*scale*4.0;
     116    blueRef  = 0.50*graphic[0].Npixels*scale*4.0;
    63117    for (i = 0; i < (int)(0.25*graphic[0].Npixels); i++) { 
    64       graphic[0].cmap[i].red = 0;
     118      graphic[0].cmap[i].red   = 0;
    65119      graphic[0].cmap[i].green = 0;
    66       graphic[0].cmap[i].blue = 256*(255*4*(i/(1.0*graphic[0].Npixels))); 
     120      SETVALUE (graphic[0].cmap[i].blue,  4*i*scale,           0, 0xffff);
    67121      graphic[0].cmap[i].flags = DoRed | DoGreen | DoBlue;
    68122    }
    69123    for (i = (int)(0.25*graphic[0].Npixels); i < (int)(0.50*graphic[0].Npixels); i++) { 
    70       graphic[0].cmap[i].red = 256*(255*4*((i/(1.0*graphic[0].Npixels)) - 0.25));
     124      SETVALUE (graphic[0].cmap[i].red,   4*i*scale - redRef,  0, 0xffff);
    71125      graphic[0].cmap[i].green = 0;
    72       graphic[0].cmap[i].blue = 256*(255*4*(0.50 - (i/(1.0*graphic[0].Npixels))));
     126      SETVALUE (graphic[0].cmap[i].blue,  blueRef - 4*i*scale, 0, 0xffff);
    73127      graphic[0].cmap[i].flags = DoRed | DoGreen | DoBlue;
    74128    }
    75129    for (i = (int)(0.50*graphic[0].Npixels); i < (int)(0.75*graphic[0].Npixels); i++) { 
    76       graphic[0].cmap[i].red = 256*255;
    77       graphic[0].cmap[i].green = 256*(255*4*((i/(1.0*graphic[0].Npixels)) - 0.50));
     130      graphic[0].cmap[i].red  = 0xffff;
     131      SETVALUE (graphic[0].cmap[i].green,  4*i*scale - greenRef, 0, 0xffff);
    78132      graphic[0].cmap[i].blue = 0;
    79133      graphic[0].cmap[i].flags = DoRed | DoGreen | DoBlue;
    80134    }
     135    blueRef  = 0.75*graphic[0].Npixels*scale*4.0;
    81136    for (i = (int)(0.75*graphic[0].Npixels); i < graphic[0].Npixels; i++) { 
    82       graphic[0].cmap[i].red = 256*255;
    83       graphic[0].cmap[i].green = 256*255;
    84       graphic[0].cmap[i].blue = 256*(255*4*((i/(1.0*graphic[0].Npixels)) - 0.75));
     137      graphic[0].cmap[i].red   = 0xffff;
     138      graphic[0].cmap[i].green = 0xffff;
     139      SETVALUE (graphic[0].cmap[i].blue,  4*i*scale - blueRef, 0, 0xffff);
    85140      graphic[0].cmap[i].flags = DoRed | DoGreen | DoBlue;
    86141    }
  • trunk/Ohana/src/kapa2/src/SetGraphSize.c

    r13479 r16011  
    4141  // if we are tied to an image, make mods as needed
    4242  if (section->image) {
    43     textpad = graphic[0].font[0].ascent;
     43    textpad = USE_XWINDOW ? graphic[0].font[0].ascent : 10;
    4444    textdY = 6*textpad + 7*PAD1;
    4545    WdY = MAX (ZOOM_Y, textdY + 2*BUTTON_HEIGHT + PAD1);
  • trunk/Ohana/src/kapa2/src/SetImageData.c

    r14590 r16011  
    1111  section = GetActiveSection();
    1212  if (section->image == NULL) {
    13     section->image = InitImage ();
     13    section->image = InitImageWidget ();
    1414    SetSectionSizes (section);
    1515  }
     
    1818  // get image data from client
    1919  KiiScanMessage (sock, "%lf %lf %s",
    20                   &image[0].zero,
    21                   &image[0].range,
    22                   image[0].name,
    23                   image[0].file);
     20                  &image[0].image[0].zero,
     21                  &image[0].image[0].range,
     22                  image[0].image[0].name,
     23                  image[0].image[0].file);
    2424
    2525  // XXX when we go to 32bit, this should remap the image
     
    3737  section = GetActiveSection();
    3838  if (section->image == NULL) {
    39     section->image = InitImage ();
     39    section->image = InitImageWidget ();
    4040    SetSectionSizes (section);
    4141  }
     
    4343
    4444  KiiSendMessage (sock, "%g %g %s %s",
    45                   image[0].zero,
    46                   image[0].range,
    47                   image[0].name,
    48                   image[0].file);
     45                  image[0].image[0].zero,
     46                  image[0].image[0].range,
     47                  image[0].image[0].name,
     48                  image[0].image[0].file);
    4949
    5050  return (TRUE);
     
    6161  section = GetActiveSection();
    6262  if (section->image == NULL) {
    63     section->image = InitImage ();
     63    section->image = InitImageWidget ();
    6464    SetSectionSizes (section);
    6565  }
     
    6767 
    6868  KiiScanMessage (sock, "%f %f %f %f",
    69                   &image[0].coords.pc1_1, &image[0].coords.pc2_2,
    70                   &image[0].coords.pc1_2, &image[0].coords.pc2_1);
     69                  &image[0].image[0].coords.pc1_1, &image[0].image[0].coords.pc2_2,
     70                  &image[0].image[0].coords.pc1_2, &image[0].image[0].coords.pc2_1);
    7171
    72   KiiScanMessage (sock, "%s", image[0].coords.ctype);
     72  KiiScanMessage (sock, "%s", image[0].image[0].coords.ctype);
    7373
    7474  KiiScanMessage (sock, "%lf %lf %f %f %f %f",
    75                   &image[0].coords.crval1,
    76                   &image[0].coords.crval2,
    77                   &image[0].coords.crpix1,
    78                   &image[0].coords.crpix2,
    79                   &image[0].coords.cdelt1,
    80                   &image[0].coords.cdelt2);
     75                  &image[0].image[0].coords.crval1,
     76                  &image[0].image[0].coords.crval2,
     77                  &image[0].image[0].coords.crpix1,
     78                  &image[0].image[0].coords.crpix2,
     79                  &image[0].image[0].coords.cdelt1,
     80                  &image[0].image[0].coords.cdelt2);
    8181
    8282  return (TRUE); 
     
    9090  section = GetActiveSection();
    9191  if (section->image == NULL) {
    92     section->image = InitImage ();
     92    section->image = InitImageWidget ();
    9393    SetSectionSizes (section);
    9494  }
     
    9696
    9797  KiiSendMessage (sock, "%g %g %g %g",
    98                   image[0].coords.pc1_1, image[0].coords.pc2_2,
    99                   image[0].coords.pc1_2, image[0].coords.pc2_1);
     98                  image[0].image[0].coords.pc1_1, image[0].image[0].coords.pc2_2,
     99                  image[0].image[0].coords.pc1_2, image[0].image[0].coords.pc2_1);
    100100
    101   KiiSendMessage (sock, "%s", image[0].coords.ctype);
     101  KiiSendMessage (sock, "%s", image[0].image[0].coords.ctype);
    102102
    103103  KiiSendMessage (sock, "%g %g %g %g %g %g",
    104                   image[0].coords.crval1,
    105                   image[0].coords.crval2,
    106                   image[0].coords.crpix1,
    107                   image[0].coords.crpix2,
    108                   image[0].coords.cdelt1,
    109                   image[0].coords.cdelt2);
     104                  image[0].image[0].coords.crval1,
     105                  image[0].image[0].coords.crval2,
     106                  image[0].image[0].coords.crpix1,
     107                  image[0].image[0].coords.crpix2,
     108                  image[0].image[0].coords.cdelt1,
     109                  image[0].image[0].coords.cdelt2);
    110110
    111111  return (TRUE);
     
    120120  section = GetActiveSection();
    121121  if (section->image == NULL) {
    122     section->image = InitImage ();
     122    section->image = InitImageWidget ();
    123123    SetSectionSizes (section);
    124124  }
  • trunk/Ohana/src/kapa2/src/SetImageSize.c

    r14590 r16011  
    4040      }
    4141      if (USE_XWINDOW) CreatePicture (image, graphic);
    42       Remap (graphic, image, &image[0].matrix);
     42      Remap (graphic, image);
    4343      return;
    4444
    4545    case 1:
    46       textpad = graphic[0].font[0].ascent;
     46      textpad = USE_XWINDOW ? graphic[0].font[0].ascent : 10;
    4747      textdY = 6*textpad + 7*PAD1;
    4848      WdY = MAX (ZOOM_Y, textdY + 2*BUTTON_HEIGHT + PAD1);
     
    104104      image[0].rainbow_button.y = image[0].PS_button.y;
    105105
    106       image[0].puns_button.x = image[0].rainbow_button.x + image[0].rainbow_button.dx + PAD1;
    107       image[0].puns_button.y = image[0].PS_button.y;
    108 
    109       image[0].recenter_button.x = image[0].puns_button.x + image[0].puns_button.dx + PAD1;
     106      image[0].heat_button.x = image[0].rainbow_button.x + image[0].rainbow_button.dx + PAD1;
     107      image[0].heat_button.y = image[0].PS_button.y;
     108
     109      image[0].recenter_button.x = image[0].heat_button.x + image[0].heat_button.dx + PAD1;
    110110      image[0].recenter_button.y = image[0].PS_button.y;
    111111      break;
    112112
    113113    case 3:
    114       textpad = graphic[0].font[0].ascent;
     114      textpad = USE_XWINDOW ? graphic[0].font[0].ascent : 10;
    115115      textdY = 6*textpad + 7*PAD1;
    116116      WdY = MAX (ZOOM_Y, textdY + 2*BUTTON_HEIGHT + PAD1);
     
    172172      image[0].rainbow_button.y = image[0].PS_button.y;
    173173
    174       image[0].puns_button.x = image[0].rainbow_button.x + image[0].rainbow_button.dx + PAD1;
    175       image[0].puns_button.y = image[0].PS_button.y;
    176 
    177       image[0].recenter_button.x = image[0].puns_button.x + image[0].puns_button.dx + PAD1;
     174      image[0].heat_button.x = image[0].rainbow_button.x + image[0].rainbow_button.dx + PAD1;
     175      image[0].heat_button.y = image[0].PS_button.y;
     176
     177      image[0].recenter_button.x = image[0].heat_button.x + image[0].heat_button.dx + PAD1;
    178178      image[0].recenter_button.y = image[0].PS_button.y;
    179179      break;
     
    206206
    207207      /** everything below is tied in x-dir to the zoom box **/
    208       textpad = graphic[0].font[0].ascent;
     208      textpad = USE_XWINDOW ? graphic[0].font[0].ascent : 10;
    209209      image[0].text_x = image[0].zoom.x;
    210210      image[0].text_y = image[0].zoom.y + image[0].zoom.dy + PAD1;
     
    238238      image[0].rainbow_button.y = image[0].PS_button.y;
    239239
    240       image[0].puns_button.x = image[0].rainbow_button.x + image[0].rainbow_button.dx + PAD1;
    241       image[0].puns_button.y = image[0].PS_button.y;
    242 
    243       image[0].recenter_button.x = image[0].puns_button.x + image[0].puns_button.dx + PAD1;
     240      image[0].heat_button.x = image[0].rainbow_button.x + image[0].rainbow_button.dx + PAD1;
     241      image[0].heat_button.y = image[0].PS_button.y;
     242
     243      image[0].recenter_button.x = image[0].heat_button.x + image[0].heat_button.dx + PAD1;
    244244      image[0].recenter_button.y = image[0].PS_button.y;
    245245      break;
     
    272272
    273273      /** everything below is tied in x-dir to the zoom box **/
    274       textpad = graphic[0].font[0].ascent;
     274      textpad = USE_XWINDOW ? graphic[0].font[0].ascent : 10;
    275275      image[0].text_x = image[0].zoom.x;
    276276      image[0].text_y = image[0].zoom.y + image[0].zoom.dy + PAD1;
     
    304304      image[0].rainbow_button.y = image[0].PS_button.y;
    305305
    306       image[0].puns_button.x = image[0].rainbow_button.x + image[0].rainbow_button.dx + PAD1;
    307       image[0].puns_button.y = image[0].PS_button.y;
    308 
    309       image[0].recenter_button.x = image[0].puns_button.x + image[0].puns_button.dx + PAD1;
     306      image[0].heat_button.x = image[0].rainbow_button.x + image[0].rainbow_button.dx + PAD1;
     307      image[0].heat_button.y = image[0].PS_button.y;
     308
     309      image[0].recenter_button.x = image[0].heat_button.x + image[0].heat_button.dx + PAD1;
    310310      image[0].recenter_button.y = image[0].PS_button.y;
    311311      break;
     
    321321    CreateZoom (image, graphic, 0, 0);
    322322  }
    323   Remap (graphic, image, &image[0].matrix);
     323  Remap (graphic, image);
    324324
    325325  return;
  • trunk/Ohana/src/kapa2/src/SetToolbox.c

    r13479 r16011  
    1717  section = GetActiveSection();
    1818  if (section->image == NULL) {
    19     section->image = InitImage ();
     19    section->image = InitImageWidget ();
    2020  }
    2121  section->image->location = location;
     
    2424  if (!USE_XWINDOW) return;
    2525
    26   Remap (graphic, section->image, &section->image->matrix);
     26  Remap (graphic, section->image);
    2727  if (DEBUG) fprintf (stderr, "remapped image\n");
    2828  Refresh ();
  • trunk/Ohana/src/kapa2/src/SetUpGraphic.c

    r13320 r16011  
    1717  graphic->dy = 512;
    1818
    19   if (!USE_XWINDOW) return;
     19  if (!USE_XWINDOW) {
     20    ALLOCATE (graphic[0].pixels, unsigned long, NPIXELS_STATIC);
     21    ALLOCATE (graphic[0].cmap,   XColor,        NPIXELS_STATIC);
     22    graphic[0].Npixels = NPIXELS_STATIC;
     23    return;
     24  }
    2025
    2126  name = CheckDisplayName (argc, argv);
  • trunk/Ohana/src/kapa2/src/StatusBox.c

    r13320 r16011  
    66
    77  if (image[0].MovePointer) {
    8     x = 0.5*image[0].matrix.Naxis[0];
    9     y = 0.5*image[0].matrix.Naxis[1];
     8    x = 0.5*image[0].image[0].matrix.Naxis[0];
     9    y = 0.5*image[0].image[0].matrix.Naxis[1];
    1010    z = -1;
    1111    image[0].x = x;
  • trunk/Ohana/src/kapa2/src/UpdatePointer.c

    r13479 r16011  
    1919  if (image[0].MovePointer && InPicture ((XButtonEvent *)event, &image[0].picture)) {
    2020
    21     data = (float *) image[0].matrix.buffer;
     21    data = (float *) image[0].image[0].matrix.buffer;
    2222    Screen_to_Image (&x, &y, (double)event[0].x, (double)event[0].y, image);
    2323
    2424    z = -1;
    2525    if (x < 0) goto skip;
    26     if (x >= image[0].matrix.Naxis[0]) goto skip;
     26    if (x >= image[0].image[0].matrix.Naxis[0]) goto skip;
    2727    if (y < 0) goto skip;
    28     if (y >= image[0].matrix.Naxis[1]) goto skip;
    29     z = data[(int)(y)*image[0].matrix.Naxis[0] + (int)(x)];
     28    if (y >= image[0].image[0].matrix.Naxis[1]) goto skip;
     29    z = data[(int)(y)*image[0].image[0].matrix.Naxis[0] + (int)(x)];
    3030
    3131  skip:
     
    4747 
    4848  if (InPicture ((XButtonEvent *)event, &image[0].cmapbar)) {
    49     z = image[0].zero  + image[0].range * (event[0].x - image[0].cmapbar.x) / image[0].cmapbar.dx;
     49    z = image[0].image[0].zero  + image[0].image[0].range * (event[0].x - image[0].cmapbar.x) / image[0].cmapbar.dx;
    5050    textpad = graphic[0].font[0].ascent;
    5151    XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].back);
  • trunk/Ohana/src/kapa2/src/UpdateStatusBox.c

    r14498 r16011  
    77  char line[100];
    88
    9   XY_to_RD (&ra, &dec, x, y, &image[0].coords);
     9  XY_to_RD (&ra, &dec, x, y, &image[0].image[0].coords);
    1010
    1111  textpad = graphic[0].font[0].ascent;
     
    2626   
    2727    bzero (line, 100);
    28     sprintf (line, "%-25s", image[0].file);
     28    sprintf (line, "%-25s", image[0].image[0].file);
    2929    XDrawString (graphic[0].display, graphic[0].window, graphic[0].gc,
    3030                 image[0].text_x + PAD1, image[0].text_y + 5*textpad + 5*PAD1, line, strlen(line));
    3131   
    3232    bzero (line, 100);
    33     sprintf (line, "(%s)                                          ", image[0].name);
     33    sprintf (line, "(%s)                                          ", image[0].image[0].name);
    3434    XDrawString (graphic[0].display, graphic[0].window, graphic[0].gc,
    3535                 image[0].text_x + PAD1, image[0].text_y + 6*textpad + 6*PAD1, line, 25);
Note: See TracChangeset for help on using the changeset viewer.