Revision 13022 trunk/libraries/libRaster/src/org/gvsig/raster/datastruct/ColorTable.java
ColorTable.java | ||
---|---|---|
102 | 102 |
*/ |
103 | 103 |
protected String filePath = null; |
104 | 104 |
|
105 |
private int errorColor = 8; |
|
106 |
|
|
105 | 107 |
/** |
106 | 108 |
* Constructor vac?o. |
107 | 109 |
* @param name |
... | ... | |
175 | 177 |
applyPalette(colorItems); |
176 | 178 |
} |
177 | 179 |
|
178 |
private int error = 8; |
|
179 |
private boolean isEqualColor(Color c1, Color c2) { |
|
180 |
if (c2.getRed() < (c1.getRed() - error)) return false; |
|
181 |
if (c2.getGreen() < (c1.getGreen() - error)) return false; |
|
182 |
if (c2.getBlue() < (c1.getBlue() - error)) return false; |
|
183 |
if (c2.getAlpha() < (c1.getAlpha() - error)) return false; |
|
180 |
private boolean isEqualColor(Color c1, Color c2, int error) { |
|
181 |
if ((c2 == null) && (c1 != null)) |
|
182 |
return false; |
|
183 |
if ((c1 == null) && (c2 != null)) |
|
184 |
return false; |
|
185 |
if (c2.getRed() < (c1.getRed() - error)) |
|
186 |
return false; |
|
187 |
if (c2.getGreen() < (c1.getGreen() - error)) |
|
188 |
return false; |
|
189 |
if (c2.getBlue() < (c1.getBlue() - error)) |
|
190 |
return false; |
|
191 |
if (c2.getAlpha() < (c1.getAlpha() - error)) |
|
192 |
return false; |
|
184 | 193 |
|
185 |
if (c2.getRed() > (c1.getRed() + error)) return false; |
|
186 |
if (c2.getGreen() > (c1.getGreen() + error)) return false; |
|
187 |
if (c2.getBlue() > (c1.getBlue() + error)) return false; |
|
188 |
if (c2.getAlpha() > (c1.getAlpha() + error)) return false; |
|
194 |
if (c2.getRed() > (c1.getRed() + error)) |
|
195 |
return false; |
|
196 |
if (c2.getGreen() > (c1.getGreen() + error)) |
|
197 |
return false; |
|
198 |
if (c2.getBlue() > (c1.getBlue() + error)) |
|
199 |
return false; |
|
200 |
if (c2.getAlpha() > (c1.getAlpha() + error)) |
|
201 |
return false; |
|
189 | 202 |
|
190 | 203 |
return true; |
191 | 204 |
} |
... | ... | |
210 | 223 |
int a = c1.getColor().getAlpha() + (int) (((c2.getColor().getAlpha() - c1.getColor().getAlpha()) * (c3.getValue() - c1.getValue())) / max); |
211 | 224 |
Color aux = new Color(r & 0xff, g & 0xff, b & 0xff, a & 0xff); |
212 | 225 |
|
213 |
return isEqualColor(c3.getColor(), aux); |
|
226 |
return isEqualColor(c3.getColor(), aux, errorColor);
|
|
214 | 227 |
} |
215 | 228 |
|
216 | 229 |
private boolean canDelete(int first, int last) { |
... | ... | |
224 | 237 |
} |
225 | 238 |
|
226 | 239 |
public void compressPalette() { |
240 |
System.out.println("Antes: " + colorItems.size()); |
|
227 | 241 |
compressPalette(colorItems); |
242 |
System.out.println("Despues: " + colorItems.size()); |
|
228 | 243 |
} |
229 | 244 |
|
230 | 245 |
public boolean isCompressible() { |
... | ... | |
450 | 465 |
(item2.getColor().getAlpha() + item1.getColor().getAlpha()) >> 1); |
451 | 466 |
|
452 | 467 |
Color color1, color2; |
453 |
int perc1, perc2;
|
|
468 |
double perc1, perc2;
|
|
454 | 469 |
|
455 |
if (percValue > item1.getInterpolated()) {
|
|
470 |
if (percValue > item2.getInterpolated()) {
|
|
456 | 471 |
color1 = halfColor; |
457 | 472 |
color2 = item2.getColor(); |
458 |
perc1 = item1.getInterpolated();
|
|
473 |
perc1 = item2.getInterpolated();
|
|
459 | 474 |
perc2 = 100; |
460 | 475 |
} else { |
461 | 476 |
color1 = item1.getColor(); |
462 | 477 |
color2 = halfColor; |
463 | 478 |
perc1 = 0; |
464 |
perc2 = item1.getInterpolated();
|
|
479 |
perc2 = item2.getInterpolated();
|
|
465 | 480 |
} |
466 | 481 |
|
467 | 482 |
double percNew = (percValue - perc1) / (perc2 - perc1); |
... | ... | |
575 | 590 |
color = ((ColorItem) colorItems.get(pos)).getColor(); |
576 | 591 |
} |
577 | 592 |
|
578 |
if (!color.equals(colorOld)) {
|
|
593 |
if (!isEqualColor(color, colorOld, 0)) {
|
|
579 | 594 |
ColorItem colorItem = new ColorItem(); |
580 | 595 |
colorItem.setNameClass(""); |
581 | 596 |
colorItem.setValue(value); |
... | ... | |
650 | 665 |
final int PRIME = 31; |
651 | 666 |
int result = 1; |
652 | 667 |
result = PRIME * result + ((colorItems == null) ? 0 : colorItems.hashCode()); |
653 |
result = PRIME * result + error; |
|
668 |
result = PRIME * result + errorColor;
|
|
654 | 669 |
result = PRIME * result + ((filePath == null) ? 0 : filePath.hashCode()); |
655 | 670 |
result = PRIME * result + (interpolated ? 1231 : 1237); |
656 | 671 |
result = PRIME * result + ((name == null) ? 0 : name.hashCode()); |
... | ... | |
687 | 702 |
} |
688 | 703 |
} |
689 | 704 |
|
690 |
if (error != other.error) |
|
691 |
return false; |
|
692 | 705 |
if (filePath == null) { |
693 | 706 |
if (other.filePath != null) |
694 | 707 |
return false; |
... | ... | |
699 | 712 |
return false; |
700 | 713 |
} else if (!name.equals(other.name)) |
701 | 714 |
return false; |
702 |
if (!Arrays.equals(nameClass, other.nameClass)) |
|
703 |
return false; |
|
704 | 715 |
|
716 |
if (nameClass != null) { |
|
717 |
if (nameClass.length != other.nameClass.length) |
|
718 |
return false; |
|
719 |
|
|
720 |
for (int i = 0; i < nameClass.length; i++) { |
|
721 |
if (!nameClass[i].equals(other.nameClass[i])) |
|
722 |
return false; |
|
723 |
} |
|
724 |
} |
|
725 |
|
|
705 | 726 |
if ( ((paletteByBand == null) && (other.paletteByBand != null)) || |
706 | 727 |
((paletteByBand != null) && (other.paletteByBand == null)) ) |
707 | 728 |
return false; |
Also available in: Unified diff