Revision 6336 org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster/org.gvsig.raster.gdal/org.gvsig.raster.gdal.provider.legend/src/main/java/org/gvsig/raster/gdal/provider/legend/RasterGdalGetColorInterpretation.java

View differences:

RasterGdalGetColorInterpretation.java
1 1
package org.gvsig.raster.gdal.provider.legend;
2 2

  
3
import java.awt.Color;
4
import java.awt.image.ColorModel;
5
import java.awt.image.DirectColorModel;
6
import java.awt.image.IndexColorModel;
7

  
8 3
import org.gdal.gdal.Band;
9
import org.gdal.gdal.ColorTable;
10 4
import org.gdal.gdal.Dataset;
11 5
import org.gdal.gdal.gdal;
12
import org.gdal.gdalconst.gdalconst;
13
import org.gdal.gdalconst.gdalconstConstants;
14
import org.gdal.gdalconst.gdalconstJNI;
15 6
import org.gvsig.fmap.dal.raster.api.RasterStore;
16
import org.gvsig.raster.gdal.provider.RasterGdalStoreProvider;
7
import org.gvsig.raster.gdal.provider.AbstractRasterGdalStoreProvider;
17 8
import org.gvsig.raster.lib.legend.api.ColorInterpretation;
18 9
import org.gvsig.raster.lib.legend.api.RasterLegendLocator;
19 10
import org.gvsig.raster.lib.legend.api.RasterLegendManager;
......
61 52
        throws DynMethodException {
62 53
        ColorInterpretation colorInterpretation = null;
63 54

  
64
        RasterGdalStoreProvider rasterGdalProvider =
65
            (RasterGdalStoreProvider) self;
55
        AbstractRasterGdalStoreProvider rasterGdalProvider =
56
            (AbstractRasterGdalStoreProvider) self;
66 57

  
67 58
        RasterLegendManager legendManager =
68 59
            RasterLegendLocator.getRasterLegendManager();
......
78 69
                colorInterpretationFromGdal(gdalBand.GetColorInterpretation());
79 70
            bandColorInterpretations[i] = bandColorInterpretion;
80 71
        }
72
        //FIXME:Intenta suponer cual es la forma correcta de interpretar los colores en funcion del numero de bandas
73
        //Seguramente haya que arreglarlo cuando haya GUI para que el usuario pueda especificar la forma correcta.
74
        guessingColorInterpretation(bandColorInterpretations);
75

  
81 76
        colorInterpretation =
82 77
            legendManager.createColorInterpretation(bandColorInterpretations);
83 78

  
84 79
        return colorInterpretation;
85 80
    }
86 81

  
82
    private void guessingColorInterpretation(String[] bandColorInterpretations){
83
        //FIXME:Intenta suponer cual es la forma correcta de interpretar los colores en funcion del numero de bandas
84
        //Seguramente haya que arreglarlo cuando haya GUI para que el usuario pueda especificar la forma correcta.
85
        if (bandColorInterpretations.length==1){
86
            if (bandColorInterpretations[0].equals(ColorInterpretation.UNDEFINED_BAND)){
87
                bandColorInterpretations[0]=ColorInterpretation.PALETTE_BAND;
88
            }
89
        }
90
        if (bandColorInterpretations.length==3 || bandColorInterpretations.length>4){
91
            if (bandColorInterpretations[0].equals(ColorInterpretation.UNDEFINED_BAND)  &&
92
                bandColorInterpretations[1].equals(ColorInterpretation.UNDEFINED_BAND) &&
93
                bandColorInterpretations[2].equals(ColorInterpretation.UNDEFINED_BAND) ){
94

  
95
                bandColorInterpretations[0]=ColorInterpretation.RED_BAND;
96
                bandColorInterpretations[1]=ColorInterpretation.GREEN_BAND;
97
                bandColorInterpretations[2]=ColorInterpretation.BLUE_BAND;
98
            }
99
        }
100
        if (bandColorInterpretations.length==4){
101
            if (bandColorInterpretations[0].equals(ColorInterpretation.UNDEFINED_BAND)  &&
102
                bandColorInterpretations[1].equals(ColorInterpretation.UNDEFINED_BAND) &&
103
                bandColorInterpretations[2].equals(ColorInterpretation.UNDEFINED_BAND) &&
104
                bandColorInterpretations[3].equals(ColorInterpretation.UNDEFINED_BAND) ){
105

  
106
                bandColorInterpretations[0]=ColorInterpretation.RED_BAND;
107
                bandColorInterpretations[1]=ColorInterpretation.GREEN_BAND;
108
                bandColorInterpretations[2]=ColorInterpretation.BLUE_BAND;
109
                bandColorInterpretations[3]=ColorInterpretation.ALPHA_BAND;
110
            }
111
        }
112
    }
113

  
87 114
    /**
88 115
     * Obtiene la cadena que representa el tipo de banda de color. Los tipos posibles son:
89 116
     * <UL>
......
112 139

  
113 140
        switch (gdalNameCI) {
114 141
        case "Undefined" :
115
            return ColorInterpretation.PALETTE_BAND;
142
            return ColorInterpretation.UNDEFINED_BAND;
116 143
        case "Gray" :
117 144
            return ColorInterpretation.GRAY_BAND;
118 145
        case "Palette" :

Also available in: Unified diff