Ignore:
Timestamp:
12/20/11 20:46:24 (8 years ago)
Author:
aivar
Message:

Added a PaletteFix class with static methods to aid in working with 254 and 256 color palettes.

Location:
trunk/projects/slim-plugin/src/main/java/imagej/slim
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/projects/slim-plugin/src/main/java/imagej/slim/fitting/InvalidDouble.java

    r7842 r7844  
    1010 * Note that "double crap = Double.NaN; if (Double.NaN == crap) System.out.println("OK");" 
    1111 * won't print! 
     12 * 
     13 * Just a temporary experimental class that will go away. 
    1214 *  
    1315 * @author aivar 
  • trunk/projects/slim-plugin/src/main/java/imagej/slim/histogram/ColorBarPanel.java

    r7838 r7844  
    139139        } 
    140140    } 
    141      
     141 
     142    /* 
     143     * Builds a full 256 color array of Colors from a LUT. 
     144     * 
     145     * @param lut 
     146     * @return 
     147     */ 
    142148    private Color[] colorsFromLUT(LUT lut) { 
    143149        byte[] bytes = lut.getBytes(); 
     
    154160    } 
    155161 
     162    /* 
     163     * Given a pixel value 0...253 
     164     * @param i 
     165     * @return 
     166     */ 
     167    //TODO this is WRONGO!!!!! 256 color version 
    156168    private Color colorize(int i) { 
    157         Color color = Color.BLACK; 
     169        Color color = _color[0]; 
    158170        // wait till we have initial range 
    159171        if (_min < _max) { 
  • trunk/projects/slim-plugin/src/main/java/imagej/slim/histogram/HistogramTool.java

    r7843 r7844  
    3939 */ 
    4040public class HistogramTool { 
    41     private final static int WIDTH = 256; 
     41    private final static int WIDTH = PaletteFix.getSize(); 
    4242    private final static int INSET = 5; 
    4343    private final static int HISTOGRAM_HEIGHT = 140; 
     
    111111        // range still get displayed with LUT colors.  To work around this, use 
    112112        // only 254 of the LUT colors. 
    113          
    114         // get the RGB colors for this color model 
    115         byte[] reds = new byte[256]; 
    116         byte[] greens = new byte[256]; 
    117         byte[] blues = new byte[256]; 
    118         colorModel.getReds(reds); 
    119         colorModel.getBlues(blues); 
    120         colorModel.getGreens(greens); 
    121  
    122         // make the first entry black and the last white 
    123         reds  [0] = (byte) Color.BLACK.getRed(); 
    124         greens[0] = (byte) Color.BLACK.getGreen(); 
    125         blues [0] = (byte) Color.BLACK.getBlue(); 
    126         reds  [255] = (byte) Color.WHITE.getRed(); 
    127         greens[255] = (byte) Color.WHITE.getGreen(); 
    128         blues [255] = (byte) Color.WHITE.getBlue(); 
    129  
    130         // make a new color model 
    131         colorModel = new IndexColorModel(8, 256, reds, greens, blues);         
    132          
     113 
     114        colorModel = PaletteFix.fixIndexColorModel(colorModel, Color.BLACK, Color.WHITE); 
    133115        return colorModel; 
    134116    } 
     
    160142        _frame.setTitle(histogramData.getTitle()); 
    161143        _histogramPanel.setBins(histogramData.binValues(WIDTH)); 
    162         _histogramData.setListener(new HistogramDataListener()); //TODO a new one? 
     144        _histogramData.setListener(new HistogramDataListener()); //TODO a new one, or reuse existing? 
    163145    } 
    164146 
     
    171153            double min = minMaxView[0]; 
    172154            double max = minMaxView[1]; 
    173             double value = (max - min) / 256; 
     155            double value = (max - min) / PaletteFix.getSize(); 
    174156            return (pixel - INSET) * value; 
    175157        } 
     
    184166            double min = minMaxView[0]; 
    185167            double max = minMaxView[1]; 
    186             int pixel = (int)(256 * (value - min) / (max - min)); 
     168            int pixel = (int)(PaletteFix.getSize() * (value - min) / (max - min)); 
    187169            return pixel; 
    188170        } 
     
    197179            int[] bins = _histogramData.binValues(WIDTH); 
    198180            _histogramPanel.setBins(bins); 
     181            //TODO does this need to be fixed 256->254??? 
    199182            _colorBarPanel.setMinMax(minView, maxView, minLUT, maxLUT); 
    200183        } 
     
    252235        public void dragMinMax(int min, int max) { 
    253236            System.out.println("dragMinMax(" + min + "," + max + ")"); 
    254             if (min < 0 || max > 255) { //TODO express  0/255in a variable or constants 
     237            if (min < 0 || max >= PaletteFix.ADJUSTED_SIZE) { 
    255238                // cursor is out of bounds, set up a periodic task to stretch 
    256239                // the bounds, if not already running 
     
    259242                } 
    260243                else { 
    261                     _dragPixels = max - 255; 
     244                    _dragPixels = max - PaletteFix.ADJUSTED_SIZE + 1; 
    262245                } 
    263246                if (null == _timer) { 
     
    319302                    // get updated histogram data & show it 
    320303                    _histogramData.setMinMaxView(minView, maxView); 
    321                     int[] bins = _histogramData.binValues(256); 
     304                    int[] bins = _histogramData.binValues(PaletteFix.ADJUSTED_SIZE); 
    322305                    _histogramPanel.setBins(bins); 
    323306                    _colorBarPanel.setMinMax(minView, maxView, minLUT, maxLUT); 
Note: See TracChangeset for help on using the changeset viewer.