Revision 6900 org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster/org.gvsig.fmap.dal.file.jimi.legend/src/main/java/org/gvsig/fmap/dal/file/jimi/legend/JimiGetColorInterpretation.java
JimiGetColorInterpretation.java | ||
---|---|---|
1 | 1 |
package org.gvsig.fmap.dal.file.jimi.legend; |
2 | 2 |
|
3 |
import java.awt.Color; |
|
3 | 4 |
import java.awt.image.ColorModel; |
4 | 5 |
import java.awt.image.DirectColorModel; |
5 | 6 |
import java.awt.image.IndexColorModel; |
7 |
import java.util.ArrayList; |
|
8 |
import java.util.List; |
|
6 | 9 |
|
7 | 10 |
import org.gvsig.fmap.dal.file.jimi.JimiRasterStoreProvider; |
8 | 11 |
import org.gvsig.fmap.dal.file.jimi.MemoryImage; |
9 | 12 |
import org.gvsig.fmap.dal.raster.api.RasterStore; |
10 |
import org.gvsig.raster.lib.legend.api.ColorInterpretation; |
|
11 | 13 |
import org.gvsig.raster.lib.legend.api.RasterLegendLocator; |
12 | 14 |
import org.gvsig.raster.lib.legend.api.RasterLegendManager; |
15 |
import org.gvsig.raster.lib.legend.api.colorinterpretation.ColorInterpretation; |
|
16 |
import org.gvsig.raster.lib.legend.api.colortable.ColorTable; |
|
17 |
import org.gvsig.raster.lib.legend.api.colortable.colortableclass.ColorTableClass; |
|
13 | 18 |
import org.gvsig.tools.ToolsLocator; |
14 | 19 |
import org.gvsig.tools.dynobject.DynClass; |
15 | 20 |
import org.gvsig.tools.dynobject.DynMethod; |
... | ... | |
50 | 55 |
} |
51 | 56 |
|
52 | 57 |
@Override |
53 |
public Object invoke(DynObject self, Object[] args) |
|
54 |
throws DynMethodException { |
|
55 |
ColorInterpretation colorInterpretation=null; |
|
56 |
// try { |
|
57 |
JimiRasterStoreProvider jimiProvider=(JimiRasterStoreProvider)self; |
|
58 |
public Object invoke(DynObject self, Object[] args) throws DynMethodException { |
|
59 |
ColorInterpretation colorInterpretation = null; |
|
60 |
// try { |
|
61 |
JimiRasterStoreProvider jimiProvider = (JimiRasterStoreProvider) self; |
|
58 | 62 |
|
59 |
RasterLegendManager legendManager=RasterLegendLocator.getRasterLegendManager();
|
|
60 |
MemoryImage image=jimiProvider.getMemoryImage();
|
|
63 |
RasterLegendManager legendManager = RasterLegendLocator.getRasterLegendManager();
|
|
64 |
MemoryImage image = jimiProvider.getMemoryImage();
|
|
61 | 65 |
|
62 |
ColorModel colorModel=image.colorModel; |
|
63 |
if (colorModel instanceof DirectColorModel){ |
|
64 |
if (image.bands==3){ |
|
65 |
colorInterpretation = |
|
66 |
legendManager.createColorInterpretation(ColorInterpretation.RGB); |
|
67 |
} else if (image.bands==4){ |
|
68 |
colorInterpretation = |
|
69 |
legendManager.createColorInterpretation(ColorInterpretation.ARGB); |
|
70 |
} |
|
71 |
}else if(colorModel instanceof IndexColorModel){ |
|
72 |
colorInterpretation = |
|
73 |
legendManager.createColorInterpretation(ColorInterpretation.PALETTE); |
|
74 |
} |
|
66 |
ColorModel colorModel = image.colorModel; |
|
67 |
if (colorModel instanceof DirectColorModel) { |
|
68 |
if (image.bands == 3) { |
|
69 |
colorInterpretation = legendManager.createColorInterpretation(ColorInterpretation.RGB); |
|
70 |
} else if (image.bands == 4) { |
|
71 |
colorInterpretation = legendManager.createColorInterpretation(ColorInterpretation.ARGB); |
|
72 |
} |
|
73 |
} else if (colorModel instanceof IndexColorModel) { |
|
74 |
colorInterpretation = legendManager.createColorInterpretation(ColorInterpretation.PALETTE); |
|
75 | 75 |
|
76 |
// } catch (DynMethodNotSupportedException e) { |
|
77 |
// //FIXME |
|
78 |
// throw new RuntimeException(e); |
|
79 |
// } |
|
76 |
ColorTable colorTable = null; |
|
77 |
IndexColorModel indexColorModel = (IndexColorModel) colorModel; |
|
78 |
int[] rgbs = new int[indexColorModel.getMapSize()]; |
|
79 |
boolean hasalpha = indexColorModel.hasAlpha(); |
|
80 |
indexColorModel.getRGBs(rgbs); |
|
81 |
|
|
82 |
List<ColorTableClass> colorTableClasses = new ArrayList<ColorTableClass>(); |
|
83 |
|
|
84 |
for (int i = 0; i < rgbs.length; i++) { |
|
85 |
String className = i + ""; |
|
86 |
double value = ((byte) i); |
|
87 |
double interpolation = 50.0; |
|
88 |
Color color = new Color(rgbs[i], hasalpha); |
|
89 |
ColorTableClass colorTableClass = |
|
90 |
legendManager.createColorTableClass(className, value, interpolation, color); |
|
91 |
colorTableClasses.add(colorTableClass); |
|
92 |
} |
|
93 |
String colorTableName = jimiProvider.getName() + "_color_table"; |
|
94 |
colorTable = legendManager.createColorTable(colorTableName, colorTableClasses, true); |
|
95 |
|
|
96 |
colorInterpretation.setPalette(colorTable); |
|
97 |
colorInterpretation.setPaletteBand(0); |
|
98 |
|
|
99 |
} |
|
100 |
|
|
80 | 101 |
return colorInterpretation; |
81 | 102 |
} |
82 | 103 |
|
Also available in: Unified diff