IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 24800


Ignore:
Timestamp:
Jul 15, 2009, 10:01:33 AM (17 years ago)
Author:
eugene
Message:

working on the colormap allocation

Location:
branches/eam_branches/20090715/Ohana/src/kapa2
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/20090715/Ohana/src/kapa2/include/constants.h

    r16011 r24800  
    1111
    1212# define NCHANNELS 3
    13 # define NPIXELS_DYNAMIC 128
     13# define NPIXELS_DYNAMIC 4600
    1414
    1515// XXX for the moment, this is set to match the values in SetColorScale3D_CC
  • branches/eam_branches/20090715/Ohana/src/kapa2/include/structures.h

    r21153 r24800  
    2121  Window         window;
    2222  Visual        *visual;
    23   int            visualclass; // is visual dynamic? (XXX change name?)
     23  int            dynamicColors; // is visual dynamic?
    2424  int            Nbits;       // pixel depth in bits (8, 16, 24, 32)
    2525  GC             gc;
  • branches/eam_branches/20090715/Ohana/src/kapa2/src/CheckVisual.c

    r21153 r24800  
    1010
    1111  int i, Nfound, N;
    12   int isColor, isDefault, isDynamic;
     12  int isColor, isDefault;
    1313  XVisualInfo *visual_list, visual_temp;
    1414  unsigned long planes[3];
     
    3434  }
    3535 
    36 // skip the default and the PseudoColor visuals, go for TrueColor first
    37 # if (0)
    38   /* check default visual first */
    39   for (i = 0; (i < Nfound) && (graphic[0].visual != visual_list[i].visual); i++);
    40   if (i == Nfound) {
    41     fprintf (stderr, "default visual not found??\n");
    42     exit (0);
    43   }
    44 # endif
    45 
    4636  // set these based on selected visual
    47   isColor = isDefault = isDynamic = FALSE;
    48 
    49 # if (0)
    50   // attempt to select the most desirable type of visual: Default as PseudoColor (XXX is it still true?)
    51   if (DEBUG) fprintf (stderr, "default visual class is %d\n", visual_list[i].class);
    52   if (visual_list[i].class == PseudoColor) {
    53     isColor = isDefault = isDynamic = TRUE;
    54     graphic[0].visual = visual_list[i].visual;
    55     graphic[0].visualclass = TRUE;
    56     goto test_pixels;
    57   }
    58 # endif
    59 
    60   // attempt to select the most desirable type of visual: TrueColor (XXX is it still true?)
     37  isColor = isDefault = FALSE;
     38
     39  // attempt to select the most desirable type of visual: DirectColor
     40  for (i = 0; (i < Nfound) && (visual_list[i].class != DirectColor); i++);
     41  if (i != Nfound) {
     42    isColor = TRUE;
     43    if (DEBUG) fprintf (stderr, "visual class is %d\n", visual_list[i].class);
     44    isDefault = (graphic[0].visual == visual_list[i].visual);
     45    graphic[0].visual = visual_list[i].visual;
     46    graphic[0].dynamicColors = TRUE;
     47    if (DEBUG) fprintf (stderr, "got DirectColor visual\n");
     48    goto test_pixels;
     49  }
     50
     51  // attempt to select the most desirable type of visual: TrueColor
    6152  for (i = 0; (i < Nfound) && (visual_list[i].class != TrueColor); i++);
    6253  if (i != Nfound) {
     
    6556    isDefault = (graphic[0].visual == visual_list[i].visual);
    6657    graphic[0].visual = visual_list[i].visual;
    67     graphic[0].visualclass = FALSE;
     58    graphic[0].dynamicColors = FALSE;
     59    if (DEBUG) fprintf (stderr, "got TrueColor visual\n");
    6860    goto test_pixels;
    6961  }
     
    7264  for (i = 0; (i < Nfound) && (visual_list[i].class != PseudoColor); i++);
    7365  if (i != Nfound) {
    74     isColor = isDynamic = TRUE;
     66    isColor = TRUE;
    7567    if (DEBUG) fprintf (stderr, "selected visual class is %d\n", visual_list[i].class);
    7668    isDefault = (graphic[0].visual == visual_list[i].visual);
    7769    graphic[0].visual = visual_list[i].visual;
    78     graphic[0].visualclass = TRUE;
     70    graphic[0].dynamicColors = TRUE;
     71    if (DEBUG) fprintf (stderr, "got PseudoColor visual\n");
    7972    goto test_pixels;
    8073  }
     
    8376  for (i = 0; (i < Nfound) && (visual_list[i].class != GrayScale); i++);
    8477  if (i != Nfound) {
    85     isDynamic = TRUE;
    8678    if (DEBUG) fprintf (stderr, "selected visual class is %d\n", visual_list[i].class);
    8779    isDefault = (graphic[0].visual == visual_list[i].visual);
    8880    graphic[0].visual = visual_list[i].visual;
    89     graphic[0].visualclass = TRUE;
     81    graphic[0].dynamicColors = TRUE;
     82    if (DEBUG) fprintf (stderr, "got GrayScale visual\n");
    9083    goto test_pixels;
    9184  }
     
    9790    isDefault = (graphic[0].visual == visual_list[i].visual);
    9891    graphic[0].visual = visual_list[i].visual;
    99     graphic[0].visualclass = FALSE;
     92    graphic[0].dynamicColors = FALSE;
     93    if (DEBUG) fprintf (stderr, "got StaticColor visual\n");
    10094    goto test_pixels;
    10195  }
     
    107101    isDefault = (graphic[0].visual == visual_list[i].visual);
    108102    graphic[0].visual = visual_list[i].visual;
    109     graphic[0].visualclass = FALSE;
     103    graphic[0].dynamicColors = FALSE;
     104    if (DEBUG) fprintf (stderr, "got StaticGray visual\n");
    110105    goto test_pixels;
    111106  }
     
    115110  /* need to make a colormap if
    116111     1) the selected visual is not the default
     112        XXX not sure if I need to / am allowed to alloc a colormap if I've grabbed the default.
    117113     2) there are not enough colors available */
    118114
     
    125121  }
    126122
    127   // allocate a private colormap, if needed
     123  // dynamic visual classes can accept AllocAll and can use XAllocColorCells while AllocNone must use XAllocColor
     124  // int allocMode = graphic[0].dynamicColors ? AllocAll : AllocNone;
     125  int allocMode = AllocNone;
     126
     127  // allocate a private colormap, if desired or needed
    128128  if (!isDefault) {
    129129    if (DEBUG) fprintf (stderr, "allocated private colormap\n");
    130     graphic[0].colormap = XCreateColormap (graphic[0].display, RootWindow (graphic[0].display, graphic[0].screen), graphic[0].visual, AllocNone);
    131   }
    132 
    133   if (isDynamic) {
     130    graphic[0].colormap = XCreateColormap (graphic[0].display, RootWindow (graphic[0].display, graphic[0].screen), graphic[0].visual, allocMode);
     131  }
     132
     133  if (graphic[0].dynamicColors) {
    134134    Npixels = NPIXELS_DYNAMIC;
    135135    if ((N = get_argument (*argc, argv, "-ncolors"))) {
     
    144144    for (graphic[0].Npixels = Npixels; graphic[0].Npixels >= 16; graphic[0].Npixels -= 4) {
    145145      if (DEBUG) fprintf (stderr, "trying %d colors\n", (int) graphic[0].Npixels);
    146       if (XAllocColorCells (graphic[0].display, graphic[0].colormap, FALSE, planes, 1, graphic[0].pixels, graphic[0].Npixels)) {
     146      if (XAllocColorCells (graphic[0].display, graphic[0].colormap, FALSE, planes, 0, graphic[0].pixels, graphic[0].Npixels)) {
    147147        break;
     148      }
     149      for (i = 0; i < graphic[0].Npixels; i++) {
     150        graphic[0].cmap[i].pixel = graphic[0].pixels[i];
    148151      }
    149152    }
     
    152155    if (graphic[0].Npixels < 16) {
    153156      if (!isDefault) {
     157        // We've already tried to allocate a colormap above...
    154158        fprintf (stderr, "can't allocate enough cells in private colormap\n");
    155159        exit (0);
    156160      }
    157161      if (DEBUG) fprintf (stderr, "can't allocate enough cells, using private colormap\n");
    158       graphic[0].colormap = XCreateColormap (graphic[0].display, RootWindow (graphic[0].display, graphic[0].screen), graphic[0].visual, AllocNone);
     162      graphic[0].colormap = XCreateColormap (graphic[0].display, RootWindow (graphic[0].display, graphic[0].screen), graphic[0].visual, allocMode);
    159163
    160164      for (graphic[0].Npixels = NPIXELS_DYNAMIC; graphic[0].Npixels >= 16; graphic[0].Npixels -= 4) {
     
    163167          break;
    164168        }
    165       }
    166 
     169        for (i = 0; i < graphic[0].Npixels; i++) {
     170          graphic[0].cmap[i].pixel = graphic[0].pixels[i];
     171        }
     172      }
    167173      if ((N = get_argument (*argc, argv, "-colorcount"))) {
    168174        fprintf (stderr, "kapa can grab %d colors\n", graphic[0].Npixels);
  • branches/eam_branches/20090715/Ohana/src/kapa2/src/DragColorbar.c

    r16011 r24800  
    1010  int             xstatus, Npix, center;
    1111
    12   if (!graphic[0].visualclass) return;
     12  if (!graphic[0].dynamicColors) return;
    1313
    1414  X = mouse_event[0].x;
     
    7979  XColor cmap[256];
    8080
    81   if (!graphic[0].visualclass) return;
     81  if (!graphic[0].dynamicColors) return;
    8282
    8383  for (i = 0; i < graphic[0].Npixels; i++) {
     
    8888      cmap[i].blue = graphic[0].cmap[0].blue;
    8989      cmap[i].green = graphic[0].cmap[0].green;
     90      cmap[i].flags = DoRed | DoGreen | DoBlue;
    9091    }
    9192    else {
     
    9495        cmap[i].blue = graphic[0].cmap[graphic[0].Npixels-1].blue;
    9596        cmap[i].green = graphic[0].cmap[graphic[0].Npixels-1].green;
     97        cmap[i].flags = DoRed | DoGreen | DoBlue;
    9698      }
    9799      else {
     
    99101        cmap[i].blue = graphic[0].cmap[j].blue;
    100102        cmap[i].green = graphic[0].cmap[j].green;
     103        cmap[i].flags = DoRed | DoGreen | DoBlue;
    101104      }
    102105    }
  • branches/eam_branches/20090715/Ohana/src/kapa2/src/MakeColormap.c

    r16011 r24800  
    11# include "Ximage.h"
    22
    3 static char default_cmap[] = "grayscale";
     3// static char default_cmap[] = "grayscale";
     4static char default_cmap[] = "heat";
    45
    56void MakeColormap (int argc, char **argv) {
  • branches/eam_branches/20090715/Ohana/src/kapa2/src/SetColorScale.c

    r16061 r24800  
    218218  // store the colors
    219219  if (USE_XWINDOW) {
    220     if (graphic[0].visualclass) {
     220    if (graphic[0].dynamicColors) {
    221221      XStoreColors(graphic[0].display, graphic[0].colormap, graphic[0].cmap, Npixels);
    222222    } else {
  • branches/eam_branches/20090715/Ohana/src/kapa2/src/SetColormap.c

    r16039 r24800  
    146146 store_colors:
    147147  if (!USE_XWINDOW) return (TRUE);
    148   if (graphic[0].visualclass) {
    149     XStoreColors(graphic[0].display, graphic[0].colormap, graphic[0].cmap, graphic[0].Npixels);
     148  if (graphic[0].dynamicColors) {
     149    if (!XStoreColors(graphic[0].display, graphic[0].colormap, graphic[0].cmap, graphic[0].Npixels)) {
     150        fprintf (stderr, "error storing colors\n");
     151    }
    150152  } else {
    151153    for (i = 0; i < graphic[0].Npixels; i++) {
    152       if (XAllocColor (graphic[0].display, graphic[0].colormap, &graphic[0].cmap[i]) == 0) {
     154      if (!XAllocColor (graphic[0].display, graphic[0].colormap, &graphic[0].cmap[i])) {
    153155        fprintf (stderr, "error on %d\n", i);
    154156      }
Note: See TracChangeset for help on using the changeset viewer.