aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormucek4 <tomaz@gorenc.org>2013-01-10 14:24:32 +0100
committermucek4 <tomaz@gorenc.org>2013-01-11 09:49:35 +0100
commit9aa114f3ea8b8e88816f98f1534972766a134021 (patch)
tree5023cb5e808cd8ab14ffb9823a3bc50bffe3bbfb
parentc09cf3a866b5a60d53e561184cbff9806885769d (diff)
downloadcgeo-9aa114f3ea8b8e88816f98f1534972766a134021.zip
cgeo-9aa114f3ea8b8e88816f98f1534972766a134021.tar.gz
cgeo-9aa114f3ea8b8e88816f98f1534972766a134021.tar.bz2
Improved PNG parsing
-rw-r--r--main/src/cgeo/geocaching/connector/gc/IconDecoder.java715
-rw-r--r--tests/src/cgeo/geocaching/connector/gc/IconDecoderTest.java2
2 files changed, 322 insertions, 395 deletions
diff --git a/main/src/cgeo/geocaching/connector/gc/IconDecoder.java b/main/src/cgeo/geocaching/connector/gc/IconDecoder.java
index a1bb9d7..9c28048 100644
--- a/main/src/cgeo/geocaching/connector/gc/IconDecoder.java
+++ b/main/src/cgeo/geocaching/connector/gc/IconDecoder.java
@@ -10,42 +10,21 @@ import android.graphics.Bitmap;
*
*/
public abstract class IconDecoder {
+ private static final int CT_TRADITIONAL = 0;
+ private static final int CT_MULTI = 1;
+ private static final int CT_MYSTERY = 2;
+ private static final int CT_EVENT = 3;
+ private static final int CT_EARTH = 4;
+ private static final int CT_FOUND = 5;
+ private static final int CT_OWN = 6;
+ private static final int CT_MEGAEVENT = 7;
+ private static final int CT_CITO = 8;
+ private static final int CT_WEBCAM = 9;
+ private static final int CT_WHEREIGO = 10;
+ private static final int CT_VIRTUAL = 11;
+ private static final int CT_LETTERBOX = 12;
public static boolean parseMapPNG(final cgCache cache, Bitmap bitmap, UTFGridPosition xy, int zoomlevel) {
- if (zoomlevel >= 14) {
- return parseMapPNG14(cache, bitmap, xy);
- }
- if (zoomlevel <= 11) {
- return parseMapPNG11(cache, bitmap, xy);
- }
- return parseMapPNG13(cache, bitmap, xy);
- }
-
- public static int CT_TRADITIONAL = 0;
- public static int CT_MULTI = 1;
- public static int CT_MYSTERY = 2;
- public static int CT_EVENT = 3;
- public static int CT_VIRTUAL = 4;
- public static int CT_FOUND = 5;
- public static int CT_OWN = 6;
- public static int CT_MEGAEVENT = 7;
- public static int CT_CITO = 8;
- public static int CT_WEBCAM = 9;
- public static int CT_WHEREIGO = 10;
- public static int CT_EARTH = 11;
- public static int CT_LETTERBOX = 12;
-
- /**
- * The icon decoder over all 16 pixels of image . It should not be invoked on any part of image that might overlay
- * with other caches.
- * Is uses decision tree to determine right type.
- *
- * @param cache
- * @param bitmap
- * @param xy
- * @return true if parsing was successful
- */
- private static boolean parseMapPNG13(final cgCache cache, Bitmap bitmap, UTFGridPosition xy) {
final int topX = xy.getX() * 4;
final int topY = xy.getY() * 4;
final int bitmapWidth = bitmap.getWidth();
@@ -55,92 +34,19 @@ public abstract class IconDecoder {
return false; //out of image position
}
- int[] pngType = new int[7];
- for (int x = topX; x < topX + 4; x++) {
- for (int y = topY; y < topY + 4; y++) {
- int color = bitmap.getPixel(x, y);
-
- if ((color & 0xFFFFFF) == 0x5f5f5f) {
- continue; //Border in every icon is the same and therefore no use to us
- }
- if ((color >>> 24) != 255) {
- continue; //transparent pixels (or semi_transparent) are only shadows of border
- }
-
- int red = (color & 0xFF0000) >> 16;
- int green = (color & 0xFF00) >> 8;
- int blue = color & 0xFF;
-
- int type = getCacheTypeFromPixel13(red, green, blue);
- pngType[type]++;
- }
- }
-
- int type = -1;
- int count = 0;
-
- for (int x = 0; x < 7; x++)
- {
- if (pngType[x] > count) {
- count = pngType[x];
- type = x;
- }
- }
-
- if (count > 1) { // 2 pixels need to detect same type and we say good to go
- switch (type) {
- case 0:
- cache.setType(CacheType.TRADITIONAL);
- return true;
- case 1:
- cache.setType(CacheType.MULTI);
- return true;
- case 2:
- cache.setType(CacheType.MYSTERY); //mystery, whereigo, groundspeak HQ and mystery is most common
- return true;
- case 3:
- cache.setType(CacheType.EVENT); //event, cito, mega-event and event is most common
- return true;
- case 4:
- cache.setType(CacheType.EARTH); //It's an image of ghost (webcam, earth, virtual) and earth in most common
- return true;
- case 5:
- cache.setFound(true);
- return true;
- case 6:
- cache.setOwn(true);
- return true;
- }
+ int numberOfDetections = 7; //for level 12 and 13;
+ if (zoomlevel < 12) {
+ numberOfDetections = 5;
}
- return false;
- }
-
- /**
- * The icon decoder over all 16 pixels of image . It should not be invoked on any part of image that might overlay
- * with other caches.
- * Is uses decision tree to determine right type.
- *
- * @param cache
- * @param bitmap
- * @param xy
- * @return true if parsing was successful
- */
- private static boolean parseMapPNG11(final cgCache cache, Bitmap bitmap, UTFGridPosition xy) {
- final int topX = xy.getX() * 4;
- final int topY = xy.getY() * 4;
- final int bitmapWidth = bitmap.getWidth();
- final int bitmapHeight = bitmap.getHeight();
-
- if ((topX < 0) || (topY < 0) || (topX + 4 > bitmapWidth) || (topY + 4 > bitmapHeight)) {
- return false; //out of image position
+ if (zoomlevel > 13) {
+ numberOfDetections = 13;
}
- int[] pngType = new int[5];
+ int[] pngType = new int[numberOfDetections];
for (int x = topX; x < topX + 4; x++) {
for (int y = topY; y < topY + 4; y++) {
int color = bitmap.getPixel(x, y);
-
if ((color >>> 24) != 255) {
continue; //transparent pixels (or semi_transparent) are only shadows of border
}
@@ -149,114 +55,20 @@ public abstract class IconDecoder {
int g = (color & 0xFF00) >> 8;
int b = color & 0xFF;
- //Duplicate colors does not add any value
- if (((r == 52) && (g == 52) && (b == 52)) ||
- ((r == 69) && (g == 69) && (b == 69)) ||
- ((r == 90) && (g == 90) && (b == 90)) ||
- ((r == 233) && (g == 233) && (b == 234)) ||
- ((r == 255) && (g == 255) && (b == 255))) {
+ if (isPixelDuplicated(r, g, b, zoomlevel)) {
continue;
}
- int type = getCacheTypeFromPixel11(r, g, b);
- pngType[type]++;
- }
- }
-
- int type = -1;
- int count = 0;
-
- for (int x = 0; x < 5; x++)
- {
- if (pngType[x] > count) {
- count = pngType[x];
- type = x;
- }
- }
-
- if (count > 1) { // 2 pixels need to detect same type and we say good to go
- switch (type) {
- case 0:
- cache.setType(CacheType.TRADITIONAL);
- return true;
- case 1:
- cache.setType(CacheType.MULTI);
- return true;
- case 2:
- cache.setType(CacheType.MYSTERY); //mystery, whereigo, groundspeak HQ and mystery is most common
- return true;
- case 3:
- cache.setType(CacheType.EVENT); //event, cito, mega-event and event is most common
- return true;
- case 4:
- cache.setType(CacheType.EARTH); //webcam, earth, virtual and earth in most common
- return true;
- }
- }
- return false;
- }
-
- /**
- * For level 14 find the borders of the icons and then use a single pixel and color to match.
- *
- * @param cache
- * @param bitmap
- * @param xy
- */
- private static boolean parseMapPNG14(cgCache cache, Bitmap bitmap, UTFGridPosition xy) {
- final int topX = xy.getX() * 4;
- final int topY = xy.getY() * 4;
- final int bitmapWidth = bitmap.getWidth();
- final int bitmapHeight = bitmap.getHeight();
-
- if ((topX < 0) || (topY < 0) || (topX + 4 > bitmapWidth) || (topY + 4 > bitmapHeight)) {
- return false; //out of image position
- }
-
- int[] pngType = new int[13];
- for (int x = topX; x < topX + 4; x++) {
- for (int y = topY; y < topY + 4; y++) {
- int color = bitmap.getPixel(x, y);
-
- if ((color & 0xFFFFFF) == 0x5f5f5f) {
- continue; //Border in every icon is the same and therefore no use to us
- }
- if ((color >>> 24) != 255) {
- continue; //transparent pixels (or semi_transparent) are only shadows of border
- }
-
- int r = (color & 0xFF0000) >> 16;
- int g = (color & 0xFF00) >> 8;
- int b = color & 0xFF;
-
- //Duplicate colors does not add any value
- if (((r == 216) && (g == 216) && (b == 216)) ||
- ((r == 23) && (g == 23) && (b == 23)) ||
- ((r == 240) && (g == 240) && (b == 240)) ||
- ((r == 44) && (g == 44) && (b == 44)) ||
- ((r == 228) && (g == 228) && (b == 228)) ||
- ((r == 225) && (g == 225) && (b == 225)) ||
- ((r == 199) && (g == 199) && (b == 199)) ||
- ((r == 161) && (g == 161) && (b == 161)) ||
- ((r == 8) && (g == 8) && (b == 8)) ||
- ((r == 200) && (g == 200) && (b == 200)) ||
- ((r == 255) && (g == 255) && (b == 255)) ||
- ((r == 250) && (g == 250) && (b == 250)) ||
- ((r == 95) && (g == 95) && (b == 95)) ||
- ((r == 236) && (g == 236) && (b == 236)) ||
- ((r == 215) && (g == 215) && (b == 215)) ||
- ((r == 232) && (g == 232) && (b == 232)) ||
- ((r == 217) && (g == 217) && (b == 217)) ||
- ((r == 0) && (g == 0) && (b == 0)) ||
- ((r == 167) && (g == 167) && (b == 167)) ||
- ((r == 247) && (g == 247) && (b == 247)) ||
- ((r == 144) && (g == 144) && (b == 144)) ||
- ((r == 231) && (g == 231) && (b == 231)) ||
- ((r == 248) && (g == 248) && (b == 248))) {
- continue;
+ int type;
+ if (zoomlevel < 12) {
+ type = getCacheTypeFromPixel11(r, g, b);
+ } else {
+ if (zoomlevel > 13) {
+ type = getCacheTypeFromPixel14(r, g, b);
+ } else {
+ type = getCacheTypeFromPixel13(r, g, b);
+ }
}
-
- int type = getCacheTypeFromPixel14(r, g, b);
pngType[type]++;
}
}
@@ -264,66 +76,109 @@ public abstract class IconDecoder {
int type = -1;
int count = 0;
- for (int x = 0; x < 7; x++)
+ for (int x = 0; x < pngType.length; x++)
{
if (pngType[x] > count) {
count = pngType[x];
type = x;
}
}
- /*
- * public static int CT_MEGAEVENT = 7;
- * public static int CT_CITO = 8;
- * public static int CT_WEBCAM = 9;
- * public static int CT_WHEREIGO = 10;
- * public static int CT_EARTH = 11;
- * public static int CT_LETTERBOX = 12;
- */
+
if (count > 1) { // 2 pixels need to detect same type and we say good to go
switch (type) {
- case 0:
+ case CT_TRADITIONAL:
cache.setType(CacheType.TRADITIONAL);
return true;
- case 1:
+ case CT_MULTI:
cache.setType(CacheType.MULTI);
return true;
- case 2:
+ case CT_MYSTERY:
cache.setType(CacheType.MYSTERY);
return true;
- case 3:
+ case CT_EVENT:
cache.setType(CacheType.EVENT);
return true;
- case 4:
- cache.setType(CacheType.VIRTUAL);
+ case CT_EARTH:
+ cache.setType(CacheType.EARTH);
return true;
- case 5:
+ case CT_FOUND:
cache.setFound(true);
return true;
- case 6:
+ case CT_OWN:
cache.setOwn(true);
return true;
- case 7:
+ case CT_MEGAEVENT:
cache.setType(CacheType.MEGA_EVENT);
return true;
- case 8:
+ case CT_CITO:
cache.setType(CacheType.CITO);
return true;
- case 9:
+ case CT_WEBCAM:
cache.setType(CacheType.WEBCAM);
return true;
- case 10:
+ case CT_WHEREIGO:
cache.setType(CacheType.WHERIGO);
return true;
- case 11:
- cache.setType(CacheType.EARTH);
+ case CT_VIRTUAL:
+ cache.setType(CacheType.VIRTUAL);
return true;
- case 12:
+ case CT_LETTERBOX:
cache.setType(CacheType.LETTERBOX);
return true;
}
}
return false;
+ }
+ /**
+ * A method that returns true if pixel color appears on more then one cache type and shall be excluded from parsing
+ *
+ * @param r
+ * red value
+ * @param g
+ * green value
+ * @param b
+ * blue value
+ * @param zoomlevel
+ * zoom level of map
+ * @return true if parsing should not be performed
+ */
+ private static boolean isPixelDuplicated(int r, int g, int b, int zoomlevel) {
+ if (zoomlevel < 12) {
+ if (((r == g) && (g == b)) || ((r == 233) && (g == 233) && (b == 234))) {
+ return true;
+ }
+ return false;
+ }
+ if (zoomlevel > 13) {
+ if ((r == g) && (g == b)) {
+ if ((r == 119) || (r == 231) || (r == 5) || (r == 230) || (r == 244) || (r == 93) || (r == 238) || (r == 73) || (r == 9) || (r == 225) || (r == 162) || (r == 153) || (r == 32) ||
+ (r == 50) || (r == 20) || (r == 232) || (r == 224) || (r == 192) || (r == 248) || (r == 152) || (r == 128) || (r == 176) || (r == 184) || (r == 200)) {
+ return false;
+ }
+ return true;
+ }
+ if ((r == 44) && (b == 44) && (g == 17) ||
+ (r == 228) && (b == 228) && (g == 255) ||
+ (r == 236) && (b == 236) && (g == 255) ||
+ (r == 252) && (b == 225) && (g == 83) ||
+ (r == 252) && (b == 221) && (g == 81) ||
+ (r == 252) && (b == 216) && (g == 79) ||
+ (r == 252) && (b == 211) && (g == 77) ||
+ (r == 251) && (b == 206) && (g == 75) ||
+ (r == 251) && (b == 201) && (g == 73) ||
+ (r == 251) && (b == 196) && (g == 71) ||
+ (r == 251) && (b == 191) && (g == 69) ||
+ (r == 243) && (b == 153) && (g == 36)) {
+ return true;
+ }
+ return false;
+ }
+ //zoom level 12, 13
+ if ((r == 95) && (g == 95) && (b == 95)) {
+ return true;
+ }
+ return false;
}
/**
@@ -340,37 +195,52 @@ public abstract class IconDecoder {
* @return Value from 0 to 6 representing detected type or state of the cache.
*/
private static int getCacheTypeFromPixel13(int r, int g, int b) {
- if (g < 110) {
- if (r > 87) {
- return ((g > 73) && (b < 63)) ? CT_FOUND : CT_EVENT;
+ if (b < 130) {
+ if (r < 41) {
+ return CT_MYSTERY;
}
- return CT_MYSTERY;
- }
- if (b > 137) {
- if ((r < 184) && (g > 190)) {
+ if (g < 74) {
+ return CT_EVENT;
+ }
+ if (r < 130) {
return CT_TRADITIONAL;
}
- if ((r < 184) && (g < 191) && (r < 136)) {
- return CT_MYSTERY;
+ if (b < 31) {
+ return CT_MULTI;
}
- return CT_VIRTUAL;
- }
- if (r < 158) {
- return ((r > 129) && (r < 153)) ? CT_FOUND : CT_TRADITIONAL;
- }
- if (b > 33) {
- if (b > 57) {
- if (b > 100) {
- return (r > 229) ? CT_MULTI : CT_EVENT;
+ if (b < 101) {
+ if (g < 99) {
+ return r < 178 ? CT_FOUND : CT_EVENT;
}
- return ((r > 254) && (g < 236)) ? CT_MULTI : CT_FOUND;
- }
- if ((g > 173) && ((g < 224))) {
- return ((r < 243) && (r > 223)) ? CT_FOUND : CT_OWN;
+ if (b < 58) {
+ if (g < 174) {
+ return CT_FOUND;
+ }
+ if (r < 224) {
+ return CT_OWN;
+ }
+ if (b < 49) {
+ return g < 210 ? CT_FOUND : CT_OWN;
+ }
+ if (g < 205) {
+ return g < 202 ? CT_FOUND : CT_OWN;
+ }
+ return CT_FOUND;
+ }
+ if (r < 255) {
+ return CT_FOUND;
+ }
+ return g < 236 ? CT_MULTI : CT_FOUND;
}
- return CT_FOUND;
+ return g < 182 ? CT_EVENT : CT_MULTI;
+ }
+ if (r < 136) {
+ return CT_MYSTERY;
+ }
+ if (b < 168) {
+ return g < 174 ? CT_EARTH : CT_TRADITIONAL;
}
- return CT_MULTI;
+ return CT_EARTH;
}
/**
@@ -387,160 +257,223 @@ public abstract class IconDecoder {
* @return Value from 0 to 6 representing detected type or state of the cache.
*/
private static int getCacheTypeFromPixel14(int r, int g, int b) {
- if (b < 140) {
- if (r > 155) {
- if (g < 159) {
- if (r < 173) {
- return (r > 161) ? CT_MEGAEVENT : CT_OWN;
+ if (b < 128) {
+ if (r < 214) {
+ if (b < 37) {
+ if (g < 50) {
+ if (b < 19) {
+ if (g < 16) {
+ if (b < 4) {
+ return CT_FOUND;
+ }
+ return r < 8 ? CT_VIRTUAL : CT_WEBCAM;
+ }
+ return CT_FOUND;
+ }
+ return CT_WEBCAM;
}
- if (r < 206) {
- if (b > 49) {
- return (b > 83) ? CT_EVENT : CT_FOUND;
+ if (b < 24) {
+ if (b < 18) {
+ return CT_EARTH;
}
- return (b < 31) ? CT_EARTH : CT_FOUND;
+ return r < 127 ? CT_TRADITIONAL : CT_EARTH;
}
- return (r < 221) ? CT_FOUND : CT_MULTI;
+ return CT_FOUND;
}
- if (r > 210) {
- if (g < 188) {
- return CT_FOUND;
- }
- if (r < 246) {
- return CT_OWN;
- }
- if (r < 254) {
- return CT_FOUND;
- }
- if (r < 255) {
- return CT_EVENT;
- }
- if (g < 208) {
- return CT_EARTH;
- }
- if (g > 225) {
- return CT_EARTH;
+ if (r < 142) {
+ if (r < 63) {
+ if (r < 26) {
+ return CT_CITO;
+ }
+ return r < 51 ? CT_WEBCAM : CT_CITO;
}
- return (b < 36) ? CT_MULTI : CT_OWN;
+ return g < 107 ? CT_WEBCAM : CT_MULTI;
+ }
+ if (g < 138) {
+ return r < 178 ? CT_MEGAEVENT : CT_EVENT;
}
- return (b < 66) ? CT_OWN : CT_EARTH;
+ return b < 71 ? CT_FOUND : CT_EARTH;
}
- if (r < 63) {
- if (b > 26) {
- if (b < 29) {
- return CT_WEBCAM;
+ if (b < 77) {
+ if (g < 166) {
+ if (r < 238) {
+ return g < 120 ? CT_MULTI : CT_OWN;
}
- if (g > 102) {
- return CT_CITO;
+ if (b < 57) {
+ if (r < 254) {
+ if (b < 39) {
+ if (r < 239) {
+ return CT_OWN;
+ }
+ if (b < 36) {
+ if (g < 150) {
+ if (b < 24) {
+ return b < 22 ? CT_FOUND : CT_OWN;
+ }
+ if (g < 138) {
+ return b < 25 ? CT_FOUND : CT_OWN;
+ }
+ return CT_FOUND;
+ }
+ return CT_OWN;
+ }
+ if (b < 38) {
+ if (b < 37) {
+ if (g < 153) {
+ return r < 242 ? CT_OWN : CT_FOUND;
+ }
+ return CT_OWN;
+ }
+ return CT_FOUND;
+ }
+ return CT_OWN;
+ }
+ if (g < 148) {
+ return CT_OWN;
+ }
+ if (r < 244) {
+ return CT_FOUND;
+ }
+ if (b < 45) {
+ if (b < 42) {
+ return CT_FOUND;
+ }
+ if (g < 162) {
+ return r < 245 ? CT_OWN : CT_FOUND;
+ }
+ return CT_OWN;
+ }
+ return CT_FOUND;
+ }
+ return g < 3 ? CT_FOUND : CT_VIRTUAL;
}
- return (r < 26) ? CT_CITO : CT_WEBCAM;
- }
- if (g < 38) {
- return CT_WEBCAM;
+ return CT_OWN;
}
- return (r < 41) ? CT_EARTH : CT_TRADITIONAL;
- }
- if (b < 119) {
- if (g < 81) {
- return CT_WEBCAM;
+ if (b < 51) {
+ if (r < 251) {
+ return CT_OWN;
+ }
+ return g < 208 ? CT_EARTH : CT_MULTI;
}
- if (b < 90) {
- return CT_OWN;
+ if (b < 63) {
+ if (r < 247) {
+ return CT_FOUND;
+ }
+ if (r < 250) {
+ if (g < 169) {
+ return CT_FOUND;
+ }
+ if (g < 192) {
+ if (b < 54) {
+ return CT_OWN;
+ }
+ if (r < 248) {
+ return g < 180 ? CT_FOUND : CT_OWN;
+ }
+ return CT_OWN;
+ }
+ return g < 193 ? CT_FOUND : CT_OWN;
+ }
+ return CT_FOUND;
}
- return (r < 104) ? CT_WEBCAM : CT_OWN;
+ return CT_FOUND;
}
- if (r < 132) {
- return (b < 124) ? CT_MULTI : CT_WHEREIGO;
+ if (g < 177) {
+ return CT_OWN;
}
- if (g > 164) {
- return CT_TRADITIONAL;
+ if (r < 239) {
+ return CT_FOUND;
}
- if (b < 134) {
+ if (g < 207) {
return CT_OWN;
}
- return (b > 137) ? CT_OWN : CT_WHEREIGO;
+ return r < 254 ? CT_FOUND : CT_EARTH;
}
- if (b < 245) {
- if (r < 180) {
- if (b < 218) {
+ if (r < 203) {
+ if (b < 218) {
+ if (g < 158) {
if (g < 71) {
return CT_MYSTERY;
}
- if (r < 96) {
- return CT_WHEREIGO;
- }
- if (b > 165) {
- return CT_WHEREIGO;
- }
- if (r < 153) {
- return CT_WHEREIGO;
- }
- if (r < 160) {
- return CT_WEBCAM;
- }
- return (r < 162) ? CT_WHEREIGO : CT_WEBCAM;
+ return r < 153 ? CT_WHEREIGO : CT_WEBCAM;
}
- return (r < 158) ? CT_MEGAEVENT : CT_EARTH;
+ if (b < 167) {
+ return r < 157 ? CT_TRADITIONAL : CT_WEBCAM;
+ }
+ return CT_WHEREIGO;
}
- if (g > 232) {
- if (g > 247) {
- return CT_CITO;
+ if (g < 199) {
+ if (r < 142) {
+ return CT_LETTERBOX;
}
- if (r < 237) {
- return CT_OWN;
+ return r < 175 ? CT_CITO : CT_LETTERBOX;
+ }
+ if (g < 207) {
+ return r < 167 ? CT_MEGAEVENT : CT_CITO;
+ }
+ return CT_EARTH;
+ }
+ if (b < 224) {
+ if (g < 235) {
+ if (b < 163) {
+ if (r < 249) {
+ return b < 133 ? CT_FOUND : CT_OWN;
+ }
+ return CT_FOUND;
}
- if (g < 238) {
- return CT_OWN;
+ if (r < 235) {
+ if (r < 213) {
+ if (r < 207) {
+ return CT_FOUND;
+ }
+ if (g < 206) {
+ return CT_OWN;
+ }
+ return g < 207 ? CT_FOUND : CT_OWN;
+ }
+ return g < 194 ? CT_OWN : CT_FOUND;
}
- if (r > 243) {
- return CT_WEBCAM;
+ if (g < 230) {
+ return CT_OWN;
}
- return (g > 238) ? CT_OWN : CT_WEBCAM;
+ return b < 205 ? CT_FOUND : CT_OWN;
}
- if (r < 228) {
- if (b > 238) {
- return CT_MYSTERY;
- }
- if (r < 193) {
- if (r < 184) {
- return CT_OWN;
- }
- if (g < 186) {
+ if (r < 238) {
+ return CT_CITO;
+ }
+ return b < 170 ? CT_EVENT : CT_FOUND;
+ }
+ if (r < 251) {
+ if (r < 210) {
+ return CT_MYSTERY;
+ }
+ if (b < 252) {
+ if (r < 243) {
+ if (r < 225) {
return CT_WHEREIGO;
}
- return (r > 189) ? CT_WHEREIGO : CT_OWN;
- }
- if (g < 223) {
- if (r > 216) {
- return CT_OWN;
+ if (b < 232) {
+ if (g < 228) {
+ return CT_WEBCAM;
+ }
+ return r < 231 ? CT_VIRTUAL : CT_TRADITIONAL;
}
- if (g > 217) {
+ if (r < 236) {
return CT_WHEREIGO;
}
- if (b > 211) {
- return CT_WEBCAM;
- }
- if (b < 196) {
- return CT_WEBCAM;
- }
- if (r > 210) {
- return CT_OWN;
- }
- return (g > 206) ? CT_WHEREIGO : CT_OWN;
+ return r < 240 ? CT_WEBCAM : CT_WHEREIGO;
}
- if (g < 224) {
- return CT_OWN;
+ if (g < 247) {
+ return r < 245 ? CT_WEBCAM : CT_FOUND;
}
- return (r < 226) ? CT_WHEREIGO : CT_OWN;
+ return CT_WHEREIGO;
}
- return (b < 216) ? CT_FOUND : CT_OWN;
+ return CT_LETTERBOX;
}
- if (r < 238) {
- if (r > 141) {
- return (r > 185) ? CT_LETTERBOX : CT_CITO;
- }
- return (r < 41) ? CT_EARTH : CT_LETTERBOX;
+ if (r < 255) {
+ return CT_OWN;
}
- return (r < 243) ? CT_WHEREIGO : CT_OWN;
+ return g < 254 ? CT_FOUND : CT_OWN;
}
/**
@@ -557,22 +490,16 @@ public abstract class IconDecoder {
* @return Value from 0 to 4 representing detected type or state of the cache.
*/
private static int getCacheTypeFromPixel11(int r, int g, int b) {
- if (b < 139) {
- if (g > 104) {
- if (r < 173) {
- return CT_TRADITIONAL;
- }
- return (r > 225) ? CT_MULTI : CT_EVENT;
- }
- if (b < 25) {
- return CT_EVENT;
+ if (g < 136) {
+ if (r < 90) {
+ return g < 111 ? CT_MYSTERY : CT_TRADITIONAL;
}
- return (r < 87) ? CT_MYSTERY : CT_EVENT;
+ return b < 176 ? CT_EVENT : CT_MYSTERY;
}
- if (r > 140) {
- return (r < 197) ? CT_TRADITIONAL : CT_VIRTUAL;
+ if (r < 197) {
+ return CT_TRADITIONAL;
}
- return CT_MYSTERY;
+ return b < 155 ? CT_MULTI : CT_EARTH;
}
}
diff --git a/tests/src/cgeo/geocaching/connector/gc/IconDecoderTest.java b/tests/src/cgeo/geocaching/connector/gc/IconDecoderTest.java
index 46e64ef..35886d4 100644
--- a/tests/src/cgeo/geocaching/connector/gc/IconDecoderTest.java
+++ b/tests/src/cgeo/geocaching/connector/gc/IconDecoderTest.java
@@ -58,7 +58,7 @@ public class IconDecoderTest extends AbstractResourceInstrumentationTestCase {
int mystery = 0;
mystery = parseMapPNG(bitmap, 37, 25, 12).getType() == CacheType.MYSTERY ? mystery + 1 : mystery;
mystery = parseMapPNG(bitmap, 49, 183, 12).getType() == CacheType.MYSTERY ? mystery + 1 : mystery;
- mystery = parseMapPNG(bitmap, 183, 181, 12).getType() == CacheType.MYSTERY ? mystery + 1 : mystery;
+ mystery = parseMapPNG(bitmap, 184, 181, 12).getType() == CacheType.MYSTERY ? mystery + 1 : mystery;
mystery = parseMapPNG(bitmap, 176, 94, 12).getType() == CacheType.MYSTERY ? mystery + 1 : mystery;
mystery = parseMapPNG(bitmap, 161, 124, 12).getType() == CacheType.MYSTERY ? mystery + 1 : mystery;
mystery = parseMapPNG(bitmap, 168, 118, 12).getType() == CacheType.MYSTERY ? mystery + 1 : mystery;