Revision 2308 org.gvsig.raster/branches/org.gvsig.raster_dataaccess_refactoring/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/src/main/java/org/gvsig/raster/impl/store/properties/DataStoreColorInterpretation.java
DataStoreColorInterpretation.java | ||
---|---|---|
51 | 51 |
} |
52 | 52 |
|
53 | 53 |
/** |
54 |
* Creates an object of this class from a bands renderer array. |
|
55 |
*/ |
|
56 |
public DataStoreColorInterpretation(int[] renderBands) { |
|
57 |
if(renderBands == null || renderBands.length == 0) { |
|
58 |
this.colorInterpretation = new String[0]; |
|
59 |
return; |
|
60 |
} |
|
61 |
|
|
62 |
this.colorInterpretation = new String[renderBands.length]; |
|
63 |
for (int i = 0; i < renderBands.length; i++) { |
|
64 |
switch (renderBands[i]) { |
|
65 |
case 0: |
|
66 |
colorInterpretation[i] = RED_BAND; |
|
67 |
break; |
|
68 |
case 1: |
|
69 |
colorInterpretation[i] = GREEN_BAND; |
|
70 |
break; |
|
71 |
case 2: |
|
72 |
colorInterpretation[i] = BLUE_BAND; |
|
73 |
break; |
|
74 |
case 3: |
|
75 |
colorInterpretation[i] = ALPHA_BAND; |
|
76 |
break; |
|
77 |
} |
|
78 |
} |
|
79 |
for (int i = 0; i < colorInterpretation.length; i++) { |
|
80 |
if(colorInterpretation[i] == null) |
|
81 |
colorInterpretation[i] = UNDEF_BAND; |
|
82 |
} |
|
83 |
} |
|
84 |
|
|
85 |
/** |
|
54 | 86 |
* Constructor que asigna los valores de interpretaci?n de color |
55 | 87 |
*/ |
56 | 88 |
public DataStoreColorInterpretation(String[] colorInterp) { |
... | ... | |
128 | 160 |
public boolean isRGB() { |
129 | 161 |
if(colorInterpretation != null) { |
130 | 162 |
if (colorInterpretation.length == 3 && |
131 |
colorInterpretation[0] == RED_BAND &&
|
|
132 |
colorInterpretation[1] == GREEN_BAND &&
|
|
133 |
colorInterpretation[2] == BLUE_BAND)
|
|
163 |
isColorInterpretation(0) &&
|
|
164 |
isColorInterpretation(1) &&
|
|
165 |
isColorInterpretation(2))
|
|
134 | 166 |
return true; |
135 | 167 |
} |
136 | 168 |
return false; |
... | ... | |
139 | 171 |
public boolean isARGB() { |
140 | 172 |
if(colorInterpretation != null) { |
141 | 173 |
if (colorInterpretation.length == 4 && |
142 |
colorInterpretation[0] == RED_BAND &&
|
|
143 |
colorInterpretation[1] == BLUE_BAND &&
|
|
144 |
colorInterpretation[2] == GREEN_BAND &&
|
|
145 |
colorInterpretation[3] == ALPHA_BAND)
|
|
174 |
isInterpretationDefinedAsColor(0) &&
|
|
175 |
isInterpretationDefinedAsColor(1) &&
|
|
176 |
isInterpretationDefinedAsColor(2) &&
|
|
177 |
isAlphaInterpretation(3))
|
|
146 | 178 |
return true; |
147 | 179 |
} |
148 | 180 |
return false; |
149 | 181 |
} |
150 | 182 |
|
183 |
public boolean isPalette() { |
|
184 |
if(colorInterpretation != null && |
|
185 |
colorInterpretation[0].length() >= 1 && |
|
186 |
colorInterpretation[0].equals(PAL_BAND)) |
|
187 |
return true; |
|
188 |
return false; |
|
189 |
} |
|
190 |
|
|
191 |
private boolean isInterpretationDefinedAsColor(int band) { |
|
192 |
return isColorInterpretation(band) || isGrayInterpretation(band); |
|
193 |
} |
|
194 |
|
|
195 |
public boolean isGrayInterpretation(int band) { |
|
196 |
return colorInterpretation[band].equals(GRAY_BAND); |
|
197 |
} |
|
198 |
|
|
199 |
public boolean isColorInterpretation(int band) { |
|
200 |
return colorInterpretation[band].equals(RED_BAND) || colorInterpretation[band].equals(GREEN_BAND) || colorInterpretation[band].equals(BLUE_BAND); |
|
201 |
} |
|
202 |
|
|
203 |
public boolean isAlphaInterpretation(int band) { |
|
204 |
return colorInterpretation[band].equals(ALPHA_BAND); |
|
205 |
} |
|
206 |
|
|
151 | 207 |
public int getAlphaBand() { |
152 | 208 |
String[] values = getValues(); |
153 | 209 |
for (int i = 0; i < values.length; i++) { |
154 |
if(values[i] != null && values[i].equals("Alpha"))
|
|
210 |
if(values[i] != null && values[i].equals(ALPHA_BAND))
|
|
155 | 211 |
return i; |
156 | 212 |
} |
157 | 213 |
return -1; |
... | ... | |
171 | 227 |
|
172 | 228 |
public void setColorInterpValue(int band, String value) { |
173 | 229 |
try{ |
174 |
colorInterpretation[band] = value; |
|
230 |
//Si ya existia el valor se elimina |
|
231 |
for (int i = 0; i < colorInterpretation.length; i++) { |
|
232 |
if(colorInterpretation[i] != null && colorInterpretation[i].equals(value)) |
|
233 |
colorInterpretation[i] = UNDEF_BAND; |
|
234 |
} |
|
235 |
|
|
236 |
//Se asigna el valor en su entrada. Si excede la longitud se construye uno nuevo m?s largo |
|
237 |
//que en las celdas existentes es copia del anterior |
|
238 |
if(band >= 0 && band < colorInterpretation.length) |
|
239 |
colorInterpretation[band] = value; |
|
240 |
else if(band >= colorInterpretation.length) { |
|
241 |
ColorInterpretation copyCI = new DataStoreColorInterpretation(band + 1); |
|
242 |
for (int i = 0; i < colorInterpretation.length; i++) { |
|
243 |
copyCI.setColorInterpValue(i, colorInterpretation[i]); |
|
244 |
} |
|
245 |
colorInterpretation = copyCI.getValues(); |
|
246 |
} |
|
175 | 247 |
}catch(ArrayIndexOutOfBoundsException ex) { |
176 | 248 |
//No asignamos el elemento |
177 | 249 |
} |
Also available in: Unified diff