Changeset 34579
- Timestamp:
- Oct 25, 2012, 10:22:17 AM (14 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/kapa2/src/SetColormap.c (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/kapa2/src/SetColormap.c
r26891 r34579 24 24 graphic = GetGraphic(); 25 25 26 int NANValue = graphic[0].Npixels - 1; 27 int MaxValue = graphic[0].Npixels - 1; 28 26 29 // the "fullcolor" colormap is uniquely defined for each image; 27 30 // defer to the 'SetColorScale' step … … 35 38 { 36 39 // 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; 40 43 } 41 44 … … 73 76 74 77 // red,green,blue are values in range 0x0000 to 0xffff 75 scale = 0xffff / ( graphic[0].Npixels - 2);78 scale = 0xffff / (float) (MaxValue - 1); 76 79 77 80 /* greyscale */ 78 81 if ((!strcasecmp (name, "grayscale")) || (!strcasecmp (name, "greyscale"))) { 79 for (i = 0; i < graphic[0].Npixels - 1; i++) {82 for (i = 0; i < MaxValue; i++) { 80 83 SETVALUE (graphic[0].cmap[i].red, 0xffff - i*scale, 0, 0xffff); 81 84 SETVALUE (graphic[0].cmap[i].green, 0xffff - i*scale, 0, 0xffff); … … 87 90 /* -grayscale */ 88 91 if ((!strcasecmp (name, "-grayscale")) || (!strcasecmp (name, "-greyscale"))) { 89 for (i = 0; i < graphic[0].Npixels - 1; i++) {92 for (i = 0; i < MaxValue; i++) { 90 93 SETVALUE (graphic[0].cmap[i].red, i*scale, 0, 0xffff); 91 94 SETVALUE (graphic[0].cmap[i].green, i*scale, 0, 0xffff); … … 97 100 /* heat */ 98 101 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++) { 102 105 SETVALUE (graphic[0].cmap[i].red, 2*i*scale, 0, 0xffff); 103 106 graphic[0].cmap[i].green = 0; … … 105 108 graphic[0].cmap[i].flags = DoRed | DoGreen | DoBlue; 106 109 } 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++) { 108 111 SETVALUE (graphic[0].cmap[i].red, 2*i*scale, 0, 0xffff); 109 112 SETVALUE (graphic[0].cmap[i].green, 2*i*scale - greenRef, 0, 0xffff); … … 111 114 graphic[0].cmap[i].flags = DoRed | DoGreen | DoBlue; 112 115 } 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++) { 114 117 graphic[0].cmap[i].red = 0xffff; 115 118 SETVALUE (graphic[0].cmap[i].green, 2*i*scale - greenRef, 0, 0xffff); … … 117 120 graphic[0].cmap[i].flags = DoRed | DoGreen | DoBlue; 118 121 } 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++) { 120 123 graphic[0].cmap[i].red = 0xffff; 121 124 graphic[0].cmap[i].green = 0xffff; … … 127 130 /* rainbow */ 128 131 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++) { 133 136 graphic[0].cmap[i].red = 0; 134 137 graphic[0].cmap[i].green = 0; … … 136 139 graphic[0].cmap[i].flags = DoRed | DoGreen | DoBlue; 137 140 } 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++) { 139 142 SETVALUE (graphic[0].cmap[i].red, 4*i*scale - redRef, 0, 0xffff); 140 143 graphic[0].cmap[i].green = 0; … … 142 145 graphic[0].cmap[i].flags = DoRed | DoGreen | DoBlue; 143 146 } 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++) { 145 148 graphic[0].cmap[i].red = 0xffff; 146 149 SETVALUE (graphic[0].cmap[i].green, 4*i*scale - greenRef, 0, 0xffff); … … 148 151 graphic[0].cmap[i].flags = DoRed | DoGreen | DoBlue; 149 152 } 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++) { 152 161 graphic[0].cmap[i].red = 0xffff; 153 162 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); 155 164 graphic[0].cmap[i].flags = DoRed | DoGreen | DoBlue; 156 165 }
Note:
See TracChangeset
for help on using the changeset viewer.
