Skip to content
Commits on Source (5)
......@@ -72,7 +72,7 @@
<component name="ProjectResources">
<default-html-doctype>http://www.w3.org/1999/xhtml</default-html-doctype>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="false" project-jdk-name="9" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="false" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="SvnBranchConfigurationManager">
......@@ -115,7 +115,6 @@
</map>
</option>
<option name="myVersion" value="124" />
<option name="mySupportsUserInfoFilter" value="true" />
</component>
<component name="WebServicesPlugin" addRequiredLibraries="true" />
</project>
\ No newline at end of file
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="RulesTest" type="Application" factoryName="Application">
<option name="MAIN_CLASS_NAME" value="main.RulesTest" />
<module name="mkgmap" />
<option name="PROGRAM_PARAMETERS" value="--max-rules 10000 --errors --stop-on-fail --arr" />
<option name="VM_PARAMETERS" value="-ea -Xmx1000m" />
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$" />
<method />
</configuration>
</component>
\ No newline at end of file
mkgmap (0.0.0+svn4143-2) UNRELEASED; urgency=medium
mkgmap (0.0.0+svn4183-1) unstable; urgency=medium
* New upstream SVN snapshot.
* Bump Standards-Version to 4.1.4, no changes.
* Add openjdk-10 to JAVA_CMDS list.
-- Bas Couwenberg <sebastic@debian.org> Wed, 18 Apr 2018 20:23:57 +0200
-- Bas Couwenberg <sebastic@debian.org> Wed, 02 May 2018 14:32:03 +0200
mkgmap (0.0.0+svn4143-1) unstable; urgency=medium
......
......@@ -9,6 +9,7 @@ ALTERNATIVE_JDK="`readlink -n -f /etc/alternatives/java`"
ARCH="`dpkg --print-architecture`"
JAVA_CMDS="$JAVA_HOME/bin/java"
JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-10-openjdk-$ARCH/bin/java"
JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-9-openjdk-$ARCH/bin/java"
JAVA_CMDS="${JAVA_CMDS} /usr/lib/jvm/java-8-openjdk-$ARCH/bin/java"
JAVA_CMDS="${JAVA_CMDS} /usr/bin/java"
......
svn.version: 4143
build.timestamp: 2018-03-31T08:04:30+0100
svn.version: 4183
build.timestamp: 2018-04-28T08:17:17+0100
......@@ -48,6 +48,8 @@ public class BufferedImgFileReader implements ImgFileReader {
public BufferedImgFileReader(ImgChannel chan) {
this.chan = chan;
// buf.order(ByteOrder.LITTLE_ENDIAN);
// could use getShort/getChar/getInt if sure buffer loaded
}
/**
......@@ -80,7 +82,7 @@ public class BufferedImgFileReader implements ImgFileReader {
/**
* Read in a single byte from the current position.
*
* Should not be used for reading numbers, use get1s/u instead.
* @return The byte that was read.
*/
public byte get() throws ReadFailedException {
......@@ -90,73 +92,110 @@ public class BufferedImgFileReader implements ImgFileReader {
int pos = (int) (position - bufStart);
if (pos >= bufSize)
return 0; // XXX do something else
// doing following makes test/func/files/GmapsuppTest.java test fail
// throw new MapFailedException("buffered input unavailable");
position++;
return buf.get(pos);
}
/**
* Read in a single byte from the current position.
* @return int sign-extended value that was read.
*/
public int get1s() throws ReadFailedException {
return get();
}
/**
* Read in two bytes. Done in the correct byte order.
*
* @return The 2 byte integer that was read.
* @return int sign-extended value that was read.
*/
public char getChar() throws ReadFailedException {
// Slow but sure implementation
public int get2s() throws ReadFailedException {
byte b1 = get();
byte b2 = get();
return (char) (((b2 & 0xff) << 8) + (b1 & 0xff));
return (b1 & 0xff)
| (b2 << 8)
;
}
/**
* Read a three byte signed quantity.
* @return The read value.
* @return int sign-extended value that was read.
* @throws ReadFailedException
*/
public int get3() throws ReadFailedException {
public int get3s() throws ReadFailedException {
// Slow but sure implementation
byte b1 = get();
byte b2 = get();
byte b3 = get();
return (b1 & 0xff)
| ((b2 & 0xff) << 8)
| (b3 << 16)
;
}
public int getu3() throws ReadFailedException {
return get3() & 0xffffff;
public int get1u() throws ReadFailedException {
return get() & 0xff;
}
/**
* Read in a 4 byte value.
* Read in two bytes. Done in the correct byte order.
*
* @return A 4 byte integer.
* @return The 2 byte integer that was read.
*/
public int getInt() throws ReadFailedException {
public int get2u() throws ReadFailedException {
byte b1 = get();
byte b2 = get();
return (b1 & 0xff)
| ((b2 & 0xff) << 8)
;
}
/**
* Read a three byte signed quantity.
* @return The read value.
* @throws ReadFailedException
*/
public int get3u() throws ReadFailedException {
// Slow but sure implementation
byte b1 = get();
byte b2 = get();
byte b3 = get();
byte b4 = get();
return (b1 & 0xff)
| ((b2 & 0xff) << 8)
| ((b3 & 0xff) << 16)
| ((b4 & 0xff) << 24)
;
}
public int getUint(int n) throws ReadFailedException {
switch (n) {
case 1: return get() & 0xff;
case 2: return getChar();
case 3: return getu3();
case 4: return getInt();
public int getNu(int nBytes) throws ReadFailedException {
switch (nBytes) {
case 1: return get1u();
case 2: return get2u();
case 3: return get3u();
case 4: return get4();
default: // this is a programming error so exit
throw new MapFailedException("bad integer size " + n);
throw new MapFailedException("bad integer size " + nBytes);
}
}
/**
* Read in a 4 byte signed value.
*
* @return A 4 byte integer.
*/
public int get4() throws ReadFailedException {
byte b1 = get();
byte b2 = get();
byte b3 = get();
byte b4 = get();
return (b1 & 0xff)
| ((b2 & 0xff) << 8)
| ((b3 & 0xff) << 16)
| (b4 << 24)
;
}
/**
* Read in an arbitrary length sequence of bytes.
*
......
......@@ -106,6 +106,7 @@ public class BufferedImgFileWriter implements ImgFileWriter, Sized {
/**
* Write out a single byte.
* Should not be used for writing numbers, use put1s/u instead.
*
* @param b The byte to write.
*/
......@@ -115,74 +116,86 @@ public class BufferedImgFileWriter implements ImgFileWriter, Sized {
}
/**
* Write out two bytes. Done in the correct byte order.
*
* @param c The value to write.
* Write out int in range -128..127 as single byte.
* @param val The byte to write.
*/
public void put1s(int val) {
assert val >= -128 && val <= 127 : val;
ensureSize(1);
buf.put((byte)val);
}
/**
* Write out int in range -32768..32767 as two bytes in little endian byte order.
* @param val The value to write.
*/
public void putChar(char c) {
public void put2s(int val) {
assert val >= -32768 && val <= 32767 : val;
ensureSize(2);
buf.putChar(c);
buf.putShort((short)val);
}
/**
* Write out int in range -0x800000..0x7fffff in little endian byte order.
* @param val The value to write.
*/
public void put3s(int val) {
assert val >= -0x800000 && val <= 0x7fffff : val;
ensureSize(3);
buf.put((byte)val);
buf.putShort((short)(val >> 8));
}
/**
* Write out int in range 0..255 as single byte.
* Use instead of put() for unsigned for clarity.
* @param val The value to write.
*/
public void put1(int val) {
public void put1u(int val) {
assert val >= 0 && val <= 255 : val;
ensureSize(1);
buf.put((byte)val);
}
/**
* Write out int in range 0..65535 as two bytes in correct byte order.
* Use instead of putChar() for unsigned for clarity.
* Write out int in range 0..65535 as two bytes in little endian byte order.
* @param val The value to write.
*/
public void put2(int val) {
public void put2u(int val) {
assert val >= 0 && val <= 65535 : val;
ensureSize(2);
buf.putShort((short)val);
buf.putChar((char)val);
}
/**
* Write out a 3 byte value in the correct byte order etc.
*
* Write out int in range 0..0xffffff as three bytes in little endian byte order.
* @param val The value to write.
*/
public void put3(int val) {
public void put3u(int val) {
assert val >= 0 && val <= 0xffffff : val;
ensureSize(3);
buf.put((byte) (val & 0xff));
buf.put((byte)val);
buf.putChar((char)(val >> 8));
}
/**
* Write out 4 byte value.
*
* @param val The value to write.
*/
public void putInt(int val) {
ensureSize(4);
buf.putInt(val);
}
/**
* Write out 1-4 bytes. Done in the correct byte order.
* Write out int as 1-4 bytes in little endian byte order.
*
* @param nBytes The number of bytes to write.
* @param val The value to write.
* @param val The value to write. Unsigned
*/
public void putN(int nBytes, int val) {
public void putNu(int nBytes, int val) {
ensureSize(nBytes);
switch (nBytes) {
case 1:
buf.put((byte)val);
assert val >= 0 && val <= 255 : val;
put((byte)val);
break;
case 2:
assert val >= 0 && val <= 65535 : val;
buf.putShort((short)val);
break;
case 3:
assert val >= 0 && val <= 0xffffff : val;
buf.put((byte)val);
buf.putShort((short)(val >> 8));
break;
......@@ -194,6 +207,16 @@ public class BufferedImgFileWriter implements ImgFileWriter, Sized {
}
}
/**
* Write out int (signed or unsigned) as 4 bytes.
*
* @param val The value to write.
*/
public void put4(int val) {
ensureSize(4);
buf.putInt(val);
}
/**
* Write out an arbitrary length sequence of bytes.
*
......
......@@ -61,11 +61,11 @@ public abstract class CommonHeader {
writer.position(0);
writer.putChar((char) headerLength);
writer.put2u(headerLength);
writer.put(Utils.toBytes(type, TYPE_LEN, (byte) 0));
writer.put((byte) 1); // unknown
writer.put((byte) 0); // not locked
writer.put1u(1); // unknown
writer.put1u(0); // not locked
byte[] date = Utils.makeCreationTime(new Date());
writer.put(date);
......@@ -79,7 +79,7 @@ public abstract class CommonHeader {
*/
public final void readHeader(ImgFileReader reader) throws ReadFailedException {
reader.position(0);
headerLength = reader.getChar();
headerLength = reader.get2u();
byte[] bytes = reader.get(TYPE_LEN);
try {
type = new String(bytes, "ascii");
......
......@@ -49,7 +49,7 @@ public class FileBackedImgFileWriter implements ImgFileWriter, Sized {
tmpChannel = out.getChannel();
file = new BufferedOutputStream(out, 16*1024);
} catch (IOException e) {
throw new MapFailedException("Could not create mdr temporary file");
throw new MapFailedException("Could not create temporary file");
}
if (chan instanceof FileLink) {
......@@ -70,7 +70,7 @@ public class FileBackedImgFileWriter implements ImgFileWriter, Sized {
channel.transferTo(0, channel.size(), outputChan);
} finally {
if (!tmpFile.delete())
System.err.println("Could not delete mdr img temporary file");
System.err.println("could not delete temporary file " + tmpFile.getPath());
}
}
......@@ -99,7 +99,7 @@ public class FileBackedImgFileWriter implements ImgFileWriter, Sized {
file.flush();
tmpChannel.position(pos);
} catch (IOException e) {
throw new MapFailedException("Could not set position in mdr tmp file");
throw new MapFailedException("could not set position in temporary file " + tmpFile.getPath());
}
}
......@@ -117,101 +117,131 @@ public class FileBackedImgFileWriter implements ImgFileWriter, Sized {
}
/**
* Write out two bytes. Can't use writeChar() since need to reverse the byte
* order.
*
* @param c The value to write.
* Write out int in range -128..127 as single byte.
* @param val The byte to write.
*/
public void putChar(char c) {
public void put1s(int val) {
assert val >= -128 && val <= 127 : val;
try {
file.write(c);
file.write(c >> 8);
file.write(val);
} catch (IOException e) {
throw new MapFailedException("could not write char to mdr tmp file");
throw new MapFailedException("could not write to temporary file " + tmpFile.getPath());
}
}
/**
* Write out int in range -32768..32767 as two bytes in little endian byte order.
* @param val The value to write.
*/
public void put2s(int val) {
assert val >= -32768 && val <= 32767 : val;
try {
file.write(val);
file.write(val >> 8);
} catch (IOException e) {
throw new MapFailedException("could not write to temporary file " + tmpFile.getPath());
}
}
/**
* Write out int in range -0x800000..0x7fffff in little endian byte order.
* @param val The value to write.
*/
public void put3s(int val) {
assert val >= -0x800000 && val <= 0x7fffff : val;
try {
file.write(val);
file.write(val >> 8);
file.write(val >> 16);
} catch (IOException e) {
throw new MapFailedException("could not write to temporary file " + tmpFile.getPath());
}
}
/**
* Write out int in range 0..255 as single byte.
* Use instead of put() for unsigned for clarity.
* @param val The value to write.
*/
public void put1(int val) {
public void put1u(int val) {
assert val >= 0 && val <= 255 : val;
try {
file.write(val);
} catch (IOException e) {
throw new MapFailedException("could not write byte to mdr tmp file");
throw new MapFailedException("could not write to temporary file " + tmpFile.getPath());
}
}
/**
* Write out int in range 0..65535 as two bytes in correct byte order.
* Use instead of putChar() for unsigned for clarity.
* Write out int in range 0..65535 as two bytes in little endian byte order.
* @param val The value to write.
*/
public void put2(int val) {
public void put2u(int val) {
assert val >= 0 && val <= 65535 : val;
try {
file.write(val);
file.write(val >> 8);
} catch (IOException e) {
throw new MapFailedException("could not write 2 bytes to mdr tmp file");
throw new MapFailedException("could not write to temporary file " + tmpFile.getPath());
}
}
/**
* Write out three bytes. Done in the little endian byte order.
*
* @param val The value to write, only the bottom three bytes will be written.
* Write out int in range 0..0xffffff as three bytes in little endian byte order.
* @param val The value to write.
*/
public void put3(int val) {
public void put3u(int val) {
assert val >= 0 && val <= 0xffffff : val;
try {
file.write(val);
file.write(val >> 8);
file.write(val >> 16);
} catch (IOException e) {
throw new MapFailedException("could not write3 to mdr tmp file");
throw new MapFailedException("could not write to temporary file " + tmpFile.getPath());
}
}
/**
* Write out 1-4 bytes. Done in the correct byte order.
* Write out int as 1-4 bytes in little endian byte order.
*
* @param nBytes The number of bytes to write.
* @param val The value to write.
* @param val The value to write. Unsigned
*/
public void putN(int nBytes, int val) {
public void putNu(int nBytes, int val) {
try {
file.write(val);
if (nBytes <= 1)
if (nBytes <= 1) {
assert val >= 0 && val <= 255 : val;
return;
}
file.write(val >> 8);
if (nBytes <= 2)
if (nBytes <= 2) {
assert val >= 0 && val <= 65535 : val;
return;
}
file.write(val >> 16);
if (nBytes <= 3)
if (nBytes <= 3) {
assert val >= 0 && val <= 0xffffff : val;
return;
}
file.write(val >> 24);
} catch (IOException e) {
throw new MapFailedException("could not write put3 to mdr tmp file");
throw new MapFailedException("could not write to temporary file " + tmpFile.getPath());
}
}
/**
* Write out 4 byte value.
* Write out 4 byte (signed or unsigned) value.
*
* @param val The value to write.
*/
public void putInt(int val) {
public void put4(int val) {
try {
file.write(val);
file.write(val >> 8);
file.write(val >> 16);
file.write(val >> 24);
} catch (IOException e) {
throw new MapFailedException("could not write int to mdr tmp file");
throw new MapFailedException("could not write to temporary file " + tmpFile.getPath());
}
}
......@@ -224,7 +254,7 @@ public class FileBackedImgFileWriter implements ImgFileWriter, Sized {
try {
file.write(val);
} catch (IOException e) {
throw new MapFailedException("could not write bytes to mdr tmp file");
throw new MapFailedException("could not write to temporary file " + tmpFile.getPath());
}
}
......@@ -239,7 +269,7 @@ public class FileBackedImgFileWriter implements ImgFileWriter, Sized {
try {
file.write(src, start, length);
} catch (IOException e) {
throw new MapFailedException("could not write bytes to mdr tmp file");
throw new MapFailedException("could not write to temporary file " + tmpFile.getPath());
}
}
......@@ -253,7 +283,7 @@ public class FileBackedImgFileWriter implements ImgFileWriter, Sized {
file.flush();
tmpChannel.write(src);
} catch (IOException e) {
throw new MapFailedException("could not write buffer to mdr tmp file");
throw new MapFailedException("could not write to temporary file " + tmpFile.getPath());
}
}
......@@ -270,13 +300,13 @@ public class FileBackedImgFileWriter implements ImgFileWriter, Sized {
file.flush();
return tmpChannel.size();
} catch (IOException e) {
throw new MapFailedException("could not get size of mdr tmp file");
throw new MapFailedException("could not get size of temporary file " + tmpFile.getPath());
}
}
/**
* Closes this stream and releases any system resources associated with it. If the stream is already closed then
* invoking this method has no effect.
* Closes this stream with the result that the contents of the temporary file are written to the
* real output.
*
* @throws IOException if an I/O error occurs
*/
......
......@@ -40,49 +40,51 @@ public interface ImgFileReader extends Closeable {
* Set the position of the file.
* @param pos The new position in the file.
*/
void position(long pos);
public void position(long pos);
/**
* Read in a single byte.
* Should not be used for reading numbers, use get1s/u instead.
* @return The byte that was read.
*/
public byte get() throws ReadFailedException;
/**
* Read in two bytes. Done in the correct byte order.
* @return The 2 byte integer that was read.
* Read in a single byte.
* @return int sign-extended value that was read.
*/
public char getChar() throws ReadFailedException;
public int get1s() throws ReadFailedException;
/**
* Get a 3byte signed quantity.
*
* @return The value read.
* @throws ReadFailedException When the file cannot be read.
* Read in two bytes in little endian byte order.
* @return int sign-extended value that was read.
*/
public int get3() throws ReadFailedException;
public int get2s() throws ReadFailedException;
/**
* Get a 3byte unsigned quantity.
*
* @return The value read.
* @throws ReadFailedException When the file cannot be read.
* Read in three bytes in little endian byte order.
* @return int sign-extended value that was read.
*/
public int getu3() throws ReadFailedException;
public int get3s() throws ReadFailedException;
public int get1u() throws ReadFailedException;
public int get2u() throws ReadFailedException;
public int get3u() throws ReadFailedException;
/**
* Read in a 4 byte value.
* @return A 4 byte integer.
* Read a variable sized integer. The size is given.
* @param nBytes The size of the integer to read. Must be 1 to 4.
* @return The integer which will not be sign extended.
*/
public int getInt() throws ReadFailedException;
public int getNu(int nBytes) throws ReadFailedException;
/**
* Read a variable sized integer. The size is given.
* @param n The size of the integer to read. Must be 1 to 4.
* @return The integer which will not be sign extended if it is less
* than 4 bytes long.
* Read in a 4 byte signed value.
* @return A 4 byte integer.
*/
public int getUint(int n) throws ReadFailedException;
public int get4() throws ReadFailedException;
/**
* Read in an arbitrary length sequence of bytes.
......
......@@ -53,51 +53,64 @@ public interface ImgFileWriter extends Closeable {
/**
* Write out a single byte.
*
* @param b The byte to write.
*/
public void put(byte b);
/**
* Write out two bytes. Done in the correct byte order.
* @param c The value to write.
* Write out int in range -128..127 as single byte.
* @param val The byte to write.
*/
public void put1s(int val);
/**
* Write out int in range -32768..32767 as two bytes in little endian byte order.
* @param val The value to write.
*/
public void put2s(int val);
/**
* Write out int in range -0x800000..0x7fffff in little endian byte order.
* @param val The value to write.
*/
public void putChar(char c);
public void put3s(int val);
// don't think needed:
// public void putNs(int nBytes, int val);
/**
* Write out int in range 0..255 as single byte.
* Use instead of put() for unsigned for clarity.
* @param val The value to write.
*/
public void put1(int val);
public void put1u(int val);
/**
* Write out int in range 0..65535 as two bytes in correct byte order.
* Use instead of putChar() for unsigned for clarity.
* Write out int in range 0..65535 as two bytes in little endian byte order.
* @param val The value to write.
*/
public void put2(int val);
public void put2u(int val);
/**
* Write out three bytes. Done in the correct byte order.
*
* @param val The value to write, only the bottom three bytes will be
* written.
* Write out int in range 0..0xffffff as three bytes in little endian byte order.
* @param val The value to write.
*/
public void put3(int val);
public void put3u(int val);
/**
* Write out 1-4 bytes. Done in the correct byte order.
* Write out int as 1-4 bytes in little endian byte order.
* verifies that fits OK as unsigned.
*
* @param nBytes The number of bytes to write.
* @param val The value to write.
*/
public void putN(int nBytes, int val);
public void putNu(int nBytes, int val);
/**
* Write out 4 byte value.
* Write out 4 byte value in.
* @param val The value to write.
*/
public void putInt(int val);
public void put4(int val);
/**
* Write out an arbitrary length sequence of bytes.
......
......@@ -23,7 +23,7 @@ import java.io.IOException;
* total size of the section.
*/
public class Section {
private char itemSize;
private int itemSize;
private int size;
private int position;
private Section link;
......@@ -32,11 +32,11 @@ public class Section {
public Section() {
}
public Section(char itemSize) {
public Section(int itemSize) {
this.itemSize = itemSize;
}
public Section(Section link, char itemSize) {
public Section(Section link, int itemSize) {
this.itemSize = itemSize;
this.link = link;
}
......@@ -49,11 +49,11 @@ public class Section {
size += itemSize;
}
public char getItemSize() {
public int getItemSize() {
return itemSize;
}
public void setItemSize(char itemSize) {
public void setItemSize(int itemSize) {
this.itemSize = itemSize;
}
......@@ -105,7 +105,7 @@ public class Section {
if (itemSize == 0)
return 0;
return size/ (int) itemSize;
return size/itemSize;
}
protected int getExtraValue() {
......@@ -117,10 +117,10 @@ public class Section {
}
public void readSectionInfo(ImgFileReader reader, boolean withItemSize) {
setPosition(reader.getInt());
setSize(reader.getInt());
setPosition(reader.get4());
setSize(reader.get4());
if (withItemSize)
setItemSize(reader.getChar());
setItemSize(reader.get2u());
}
public SectionWriter makeSectionWriter(ImgFileWriter writer) {
......@@ -137,19 +137,19 @@ public class Section {
}
public void writeSectionInfo(ImgFileWriter writer, boolean withItemSize, boolean withExtraValue) {
writer.putInt(getPosition());
writer.putInt(getSize());
writer.put4(getPosition());
writer.put4(getSize());
if (withItemSize || getItemSize() > 0)
writer.putChar(getItemSize());
writer.put2u(getItemSize());
if (withExtraValue)
writer.putInt(getExtraValue());
writer.put4(getExtraValue());
}
public static void close(ImgFileWriter writer) {
assert writer instanceof SectionWriter;
try {
writer.close();
} catch (IOException e) {
} catch (IOException ignore) {
// ignore as this is only for section writers.
}
}
......
......@@ -62,28 +62,36 @@ public class SectionWriter implements ImgFileWriter {
writer.put(b);
}
public void putChar(char c) {
writer.putChar(c);
public void put1s(int val) {
writer.put1s(val);
}
public void put1(int val) {
writer.put1(val);
};
public void put2s(int val) {
writer.put2s(val);
}
public void put3s(int val) {
writer.put3s(val);
}
public void put2(int val) {
writer.put2(val);
};
public void put1u(int val) {
writer.put1u(val);
}
public void put2u(int val) {
writer.put2u(val);
}
public void put3(int val) {
writer.put3(val);
public void put3u(int val) {
writer.put3u(val);
}
public void putN(int nBytes, int val) {
writer.putN(nBytes, val);
public void putNu(int nBytes, int val) {
writer.putNu(nBytes, val);
}
public void putInt(int val) {
writer.putInt(val);
public void put4(int val) {
writer.put4(val);
}
public void put(byte[] val) {
......
......@@ -55,12 +55,12 @@ public class DEMHeader extends CommonHeader {
}
writer.position(pos);
writer.putInt(0); // 0: elevation in metres, 1: foot
writer.put2(zoomLevels.size());
writer.putInt(0); // unknown
writer.put2(60); // size of zoom level record
writer.putInt(offset); // offset to first DemSection header (they appear at the end of the file!)
writer.putInt(1); // unknown, 0 and 1 spotted
writer.put4(0); // 0: elevation in metres, 1: foot
writer.put2u(zoomLevels.size());
writer.put4(0); // unknown
writer.put2u(60); // size of zoom level record
writer.put4(offset); // offset to first DemSection header (they appear at the end of the file!)
writer.put4(1); // unknown, 0 and 1 spotted
}
......
......@@ -23,7 +23,7 @@ import uk.me.parabola.mkgmap.reader.hgt.HGTConverter;
public class DEMSection {
private static final Logger log = Logger.getLogger(DEMSection.class);
private static final int STD_DIM = 64;
private byte unknown1 = 0;
private int unknown1 = 0;
private final int zoomLevel;
private final boolean lastLevel;
private final int pointsPerLat = STD_DIM;
......@@ -183,28 +183,26 @@ public class DEMSection {
}
public void writeHeader(ImgFileWriter writer) {
writer.put(unknown1); //0x00
writer.put1(zoomLevel); //0x01
writer.putInt(pointsPerLat); //0x02
writer.putInt(pointsPerLon); //0x06
writer.putInt(nonStdHeight - 1); //0x0A
writer.putInt(nonStdWidth - 1); //0x0E
writer.put2(flags1); //0x12
writer.putInt(tilesLon - 1); //0x14
writer.putInt(tilesLat - 1); //0x18
writer.put2(recordDesc); //0x1c
writer.put2(tileDescSize); //0x1e
writer.putInt(dataOffset); //0x20
writer.putInt(dataOffset2); //0x24
writer.putInt(left); //0x28
writer.putInt(top); //0x2c
writer.putInt(pointsDistanceLat); //0x30
writer.putInt(pointsDistanceLon); //0x34
assert minHeight >= Short.MIN_VALUE && minHeight <= Short.MAX_VALUE;
writer.putChar((char) minHeight); //0x38
assert maxHeight >= Short.MIN_VALUE && maxHeight <= Short.MAX_VALUE;
writer.putChar((char) maxHeight); //0x3a
writer.put1u(unknown1); //0x00
writer.put1u(zoomLevel); //0x01
writer.put4(pointsPerLat); //0x02
writer.put4(pointsPerLon); //0x06
writer.put4(nonStdHeight - 1); //0x0A
writer.put4(nonStdWidth - 1); //0x0E
writer.put2u(flags1); //0x12
writer.put4(tilesLon - 1); //0x14
writer.put4(tilesLat - 1); //0x18
writer.put2u(recordDesc); //0x1c
writer.put2u(tileDescSize); //0x1e
writer.put4(dataOffset); //0x20
writer.put4(dataOffset2); //0x24
writer.put4(left); //0x28
writer.put4(top); //0x2c
writer.put4(pointsDistanceLat); //0x30
writer.put4(pointsDistanceLon); //0x34
writer.put2s(minHeight); //0x38
writer.put2s(maxHeight); //0x3a
}
public void writeRest(ImgFileWriter writer) {
......
......@@ -41,7 +41,7 @@ public class DEMTile {
private int offset; // offset from section.dataOffset2
private final int baseHeight; // base or minimum height in this tile
private final int maxDeltaHeight; // delta between max height and base height
private final byte encodingType; // determines how the highest values are displayed
private final int encodingType; // determines how the highest values are displayed
private final boolean hasData; // not all voids
private int bitPos;
......@@ -310,7 +310,7 @@ public class DEMTile {
* Write an unsigned binary value with the given number of bits, MSB first.
* @param val
* @param hunit
* @param type
* @param maxZeroBits
* @return
*/
private boolean writeValHybrid(int val, int hunit, int maxZeroBits) {
......@@ -395,26 +395,14 @@ public class DEMTile {
int baseSize = ((recordDesc & 0x4) >> 2) + 1;
int deltaSize = ((recordDesc & 0x8) >> 3) + 1;
boolean hasExtra = (recordDesc & 0x10) != 0;
switch (offsetSize) {
case 1:
writer.put1(offset);
break;
case 2:
writer.put2(offset);
break;
case 3:
writer.put3(offset);
break;
default:
writer.putInt(offset);
}
writer.putNu(offsetSize, offset);
if (baseSize == 1)
writer.put((byte) baseHeight);
writer.put1s(baseHeight);
else
writer.putChar((char) baseHeight);
writer.putN(deltaSize, maxDeltaHeight);
writer.put2s(baseHeight);
writer.putNu(deltaSize, maxDeltaHeight);
if (hasExtra)
writer.put(encodingType);
writer.put1u(encodingType);
}
public void writeBitStreamData(ImgFileWriter writer) {
......
......@@ -42,7 +42,7 @@ public class City {
// The location of the city. These could both be zero if we are using a
// label instead.
private Subdivision subdivision;
private byte pointIndex;
private int pointIndex;
// You can have either a label or a subdivision and point. This will be
......@@ -63,21 +63,21 @@ public class City {
//writer.put3()
if (pointRef) {
// System.err.println("City point = " + (int)pointIndex + " div = " + subdivision.getNumber());
writer.put(pointIndex);
writer.putChar((char)subdivision.getNumber());
writer.put1u(pointIndex);
writer.put2u(subdivision.getNumber());
} else {
writer.put3(label.getOffset());
writer.put3u(label.getOffset());
}
char info;
int info;
if(region != null)
info = (char) (region.getIndex() & 0x3fff);
info = region.getIndex() & 0x3fff;
else
info = (char) (REGION_IS_COUNTRY | (country.getIndex() & 0x3fff));
info = REGION_IS_COUNTRY | (country.getIndex() & 0x3fff);
if (pointRef)
info |= POINT_REF;
writer.putChar(info);
writer.put2u(info);
}
public int getIndex() {
......@@ -95,7 +95,7 @@ public class City {
this.label = label;
}
public void setPointIndex(byte pointIndex) {
public void setPointIndex(int pointIndex) {
pointRef = true;
this.pointIndex = pointIndex;
}
......
......@@ -26,7 +26,7 @@ import uk.me.parabola.imgfmt.app.ImgFileWriter;
*/
public class Country {
// The country number. This is not recorded in the file
private char index;
private int index;
private Label label;
public Country(int index) {
......@@ -34,10 +34,10 @@ public class Country {
}
void write(ImgFileWriter writer) {
writer.put3(label.getOffset());
writer.put3u(label.getOffset());
}
public char getIndex() {
public int getIndex() {
return index;
}
......@@ -50,6 +50,6 @@ public class Country {
}
public void setIndex(int index) {
this.index = (char) index;
this.index = index;
}
}
......@@ -51,9 +51,8 @@ public class ExitFacility {
word |= type << 24; // 24:27 = 4 bit type
// 28 = unknown
word |= direction << 29; // 29:31 = 3 bit direction
writer.putChar((char)word);
writer.putChar((char)(word >> 16));
writer.put((byte)facilities);
writer.put4(word);
writer.put1u(facilities);
}
public int getIndex() {
......
......@@ -33,9 +33,9 @@ public class Highway {
class ExitPoint implements Comparable<ExitPoint> {
final String name;
final byte index;
final int index;
final Subdivision div;
public ExitPoint(String name, byte index, Subdivision div) {
public ExitPoint(String name, int index, Subdivision div) {
this.name = name;
this.index = index;
this.div = div;
......@@ -63,19 +63,19 @@ public class Highway {
void write(ImgFileWriter writer, boolean extraData) {
if(extraData) {
writer.put((byte)0);
writer.putChar(region == null? 0 : region.getIndex());
writer.put1u(0);
writer.put2u(region == null? 0 : region.getIndex());
Collections.sort(exits);
for(ExitPoint ep : exits) {
writer.put(ep.index);
writer.putChar((char)ep.div.getNumber());
writer.put1u(ep.index);
writer.put2u(ep.div.getNumber());
}
}
else {
assert extraDataOffset != 0;
writer.put3(label.getOffset());
writer.putChar((char)extraDataOffset);
writer.put((byte)0); // unknown (setting any of 0x3f stops exits being found)
writer.put3u(label.getOffset());
writer.put2u(extraDataOffset);
writer.put1u(0); // unknown (setting any of 0x3f stops exits being found)
}
}
......@@ -96,6 +96,6 @@ public class Highway {
}
public void addExitPoint(String name, int index, Subdivision div) {
exits.add(new ExitPoint(name, (byte)index, div));
exits.add(new ExitPoint(name, index, div));
}
}