IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 34579


Ignore:
Timestamp:
Oct 25, 2012, 10:22:17 AM (14 years ago)
Author:
eugene
Message:

rainbow colors should saturate at white

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/kapa2/src/SetColormap.c

    r26891 r34579  
    2424  graphic = GetGraphic();
    2525
     26  int NANValue = graphic[0].Npixels - 1;
     27  int MaxValue = graphic[0].Npixels - 1;
     28
    2629  // the "fullcolor" colormap is uniquely defined for each image;
    2730  // defer to the 'SetColorScale' step
     
    3538  {
    3639      // XXX set pure green for now
    37       graphic[0].cmap[graphic[0].Npixels-1].red = 0;
    38       graphic[0].cmap[graphic[0].Npixels-1].green = 0xffff;
    39       graphic[0].cmap[graphic[0].Npixels-1].blue = 0;
     40      graphic[0].cmap[NANValue].red = 0;
     41      graphic[0].cmap[NANValue].green = 0xffff;
     42      graphic[0].cmap[NANValue].blue = 0;
    4043  } 
    4144
     
    7376
    7477  // red,green,blue are values in range 0x0000 to 0xffff
    75   scale = 0xffff / (graphic[0].Npixels - 2);
     78  scale = 0xffff / (float) (MaxValue - 1);
    7679
    7780  /* greyscale */
    7881  if ((!strcasecmp (name, "grayscale")) || (!strcasecmp (name, "greyscale"))) {
    79     for (i = 0; i < graphic[0].Npixels - 1; i++) { 
     82    for (i = 0; i < MaxValue; i++) { 
    8083      SETVALUE (graphic[0].cmap[i].red,   0xffff - i*scale, 0, 0xffff);
    8184      SETVALUE (graphic[0].cmap[i].green, 0xffff - i*scale, 0, 0xffff);
     
    8790  /* -grayscale */
    8891  if ((!strcasecmp (name, "-grayscale")) || (!strcasecmp (name, "-greyscale"))) {
    89     for (i = 0; i < graphic[0].Npixels - 1; i++) { 
     92    for (i = 0; i < MaxValue; i++) { 
    9093      SETVALUE (graphic[0].cmap[i].red,   i*scale, 0, 0xffff);
    9194      SETVALUE (graphic[0].cmap[i].green, i*scale, 0, 0xffff);
     
    97100  /* heat */
    98101  if (!strcasecmp (name, "Heat")) {
    99     greenRef = 0.25*graphic[0].Npixels*scale*2.0;
    100     blueRef  = 0.50*graphic[0].Npixels*scale*2.0;
    101     for (i = 0; i < (int)(0.25*graphic[0].Npixels); i++) { 
     102    greenRef = 0.25*MaxValue*scale*2.0;
     103    blueRef  = 0.50*MaxValue*scale*2.0;
     104    for (i = 0; i < (int)(0.25*MaxValue); i++) { 
    102105      SETVALUE (graphic[0].cmap[i].red,   2*i*scale, 0, 0xffff);
    103106      graphic[0].cmap[i].green = 0;
     
    105108      graphic[0].cmap[i].flags = DoRed | DoGreen | DoBlue;
    106109    }
    107     for (i = 0.25*graphic[0].Npixels; i < 0.50*graphic[0].Npixels; i++) { 
     110    for (i = 0.25*MaxValue; i < 0.50*MaxValue; i++) { 
    108111      SETVALUE (graphic[0].cmap[i].red,   2*i*scale,            0, 0xffff);
    109112      SETVALUE (graphic[0].cmap[i].green, 2*i*scale - greenRef, 0, 0xffff);
     
    111114      graphic[0].cmap[i].flags = DoRed | DoGreen | DoBlue;
    112115    }
    113     for (i = (int)(0.50*graphic[0].Npixels); i < (int)(0.75*graphic[0].Npixels); i++) { 
     116    for (i = (int)(0.50*MaxValue); i < (int)(0.75*MaxValue); i++) { 
    114117      graphic[0].cmap[i].red = 0xffff;
    115118      SETVALUE (graphic[0].cmap[i].green, 2*i*scale - greenRef, 0, 0xffff);
     
    117120      graphic[0].cmap[i].flags = DoRed | DoGreen | DoBlue;
    118121    }
    119     for (i = (int)(0.75*graphic[0].Npixels); i < graphic[0].Npixels - 1; i++) { 
     122    for (i = (int)(0.75*MaxValue); i < MaxValue; i++) { 
    120123      graphic[0].cmap[i].red   = 0xffff;
    121124      graphic[0].cmap[i].green = 0xffff;
     
    127130  /* rainbow */
    128131  if (!strcasecmp (name, "Rainbow")) {
    129     redRef   = 0.25*graphic[0].Npixels*scale*4.0;
    130     greenRef = 0.50*graphic[0].Npixels*scale*4.0;
    131     blueRef  = 0.50*graphic[0].Npixels*scale*4.0;
    132     for (i = 0; i < (int)(0.25*graphic[0].Npixels); i++) { 
     132    redRef   = 0.25*MaxValue*scale*4.0;
     133    greenRef = 0.50*MaxValue*scale*4.0;
     134    blueRef  = 0.50*MaxValue*scale*4.0;
     135    for (i = 0; i < (int)(0.25*MaxValue); i++) { 
    133136      graphic[0].cmap[i].red   = 0;
    134137      graphic[0].cmap[i].green = 0;
     
    136139      graphic[0].cmap[i].flags = DoRed | DoGreen | DoBlue;
    137140    }
    138     for (i = (int)(0.25*graphic[0].Npixels); i < (int)(0.50*graphic[0].Npixels); i++) { 
     141    for (i = (int)(0.25*MaxValue); i < (int)(0.50*MaxValue); i++) { 
    139142      SETVALUE (graphic[0].cmap[i].red,   4*i*scale - redRef,  0, 0xffff);
    140143      graphic[0].cmap[i].green = 0;
     
    142145      graphic[0].cmap[i].flags = DoRed | DoGreen | DoBlue;
    143146    }
    144     for (i = (int)(0.50*graphic[0].Npixels); i < (int)(0.75*graphic[0].Npixels); i++) { 
     147    for (i = (int)(0.50*MaxValue); i < (int)(0.75*MaxValue); i++) { 
    145148      graphic[0].cmap[i].red  = 0xffff;
    146149      SETVALUE (graphic[0].cmap[i].green,  4*i*scale - greenRef, 0, 0xffff);
     
    148151      graphic[0].cmap[i].flags = DoRed | DoGreen | DoBlue;
    149152    }
    150     blueRef  = 0.75*graphic[0].Npixels*scale*4.0;
    151     for (i = (int)(0.75*graphic[0].Npixels); i < graphic[0].Npixels - 1; i++) { 
     153    // blue = blueScale * i + blueRef
     154    // blue = (0xffff - 0.0)*(i - MinValue) / (MaxValue - MinValue) + 0.0
     155    // blue = i * 0xffff / (MaxValue - MinValue) - 0xffff * MinValue / (MaxValue - MinValue)
     156    float iMin = (int)(0.75*MaxValue);
     157    float iMax = MaxValue - 1;
     158    float dB = 0xffff / (iMax - iMin);
     159    float oB = -0xffff * iMin / (iMax - iMin);
     160    for (i = iMin; i < MaxValue; i++) { 
    152161      graphic[0].cmap[i].red   = 0xffff;
    153162      graphic[0].cmap[i].green = 0xffff;
    154       SETVALUE (graphic[0].cmap[i].blue,  4*i*scale - blueRef, 0, 0xffff);
     163      SETVALUE (graphic[0].cmap[i].blue,  i*dB + oB, 0, 0xffff);
    155164      graphic[0].cmap[i].flags = DoRed | DoGreen | DoBlue;
    156165    }
Note: See TracChangeset for help on using the changeset viewer.