| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package uk.me.parabola.imgfmt.app.trergn; |
| 18 |
|
| 19 |
import uk.me.parabola.imgfmt.app.ImgFileWriter; |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
public abstract class Overview implements Comparable<Overview> { |
| 31 |
public static final int POINT_KIND = 1; |
| 32 |
public static final int LINE_KIND = 2; |
| 33 |
public static final int SHAPE_KIND = 3; |
| 34 |
|
| 35 |
private final int kind; |
| 36 |
private final int extType; |
| 37 |
private final int type; |
| 38 |
private final int subType; |
| 39 |
private final int minResolution; |
| 40 |
private final int size; |
| 41 |
|
| 42 |
private int maxLevel; |
| 43 |
|
| 44 |
protected Overview(int kind, int fullType, int minres) { |
| 45 |
this.kind = kind; |
| 46 |
|
| 47 |
this.extType = fullType >> 16; |
| 48 |
this.type = (fullType >> 8) & 0xff; |
| 49 |
this.subType = fullType & 0xff; |
| 50 |
this.minResolution = minres; |
| 51 |
|
| 52 |
if (kind == POINT_KIND) |
| 53 |
size = 3; |
| 54 |
else |
| 55 |
size = 2; |
| 56 |
} |
| 57 |
|
| 58 |
public void write(ImgFileWriter file) { |
| 59 |
if (extType == 0) { |
| 60 |
file.put1u(type); |
| 61 |
file.put1u(maxLevel); |
| 62 |
if (size > 2) |
| 63 |
file.put1u(subType); |
| 64 |
} else { |
| 65 |
file.put1u(type); |
| 66 |
file.put1u(maxLevel); |
| 67 |
file.put1u(subType); |
| 68 |
file.put1u(0); |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
public int hashCode() { |
| 79 |
return (kind << 7) + (type << 3) + subType; |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
public boolean equals(Object obj) { |
| 91 |
if (!(obj instanceof Overview)) |
| 92 |
return false; |
| 93 |
|
| 94 |
Overview ov = (Overview) obj; |
| 95 |
return (ov.kind == kind && |
| 96 |
ov.extType == extType && |
| 97 |
ov.type == type && |
| 98 |
ov.subType == subType); |
| 99 |
} |
| 100 |
|
| 101 |
public int getKind() { |
| 102 |
return kind; |
| 103 |
} |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
public int compareTo(Overview ov) { |
| 117 |
if (kind != ov.kind) { |
| 118 |
return kind > ov.kind ? 1 : -1; |
| 119 |
} |
| 120 |
|
| 121 |
if(extType != ov.extType) { |
| 122 |
return extType > ov.extType? 1: -1; |
| 123 |
} |
| 124 |
|
| 125 |
int res; |
| 126 |
if (type == ov.type) { |
| 127 |
if (subType == ov.subType) |
| 128 |
res = 0; |
| 129 |
else if (subType > ov.subType) |
| 130 |
res = 1; |
| 131 |
else |
| 132 |
res = -1; |
| 133 |
} else { |
| 134 |
if (type == ov.type) |
| 135 |
res = 0; |
| 136 |
else if (type > ov.type) |
| 137 |
res = 1; |
| 138 |
else |
| 139 |
res = -1; |
| 140 |
} |
| 141 |
return res; |
| 142 |
} |
| 143 |
|
| 144 |
public void setMaxLevel(int maxLevel) { |
| 145 |
this.maxLevel = maxLevel; |
| 146 |
} |
| 147 |
|
| 148 |
public int getMinResolution() { |
| 149 |
return minResolution; |
| 150 |
} |
| 151 |
|
| 152 |
public boolean hasExtType() { |
| 153 |
return extType != 0; |
| 154 |
} |
| 155 |
} |