Hi Gerd
Sorry - I did do "ant test", but this doesn't detect the missing
methods unless attempt made to call then.
New patch attached - I noticed that some of the new method comments
where not quite correct so I've improved these.
Regards
Ticker
On Thu, 2017-08-03 at 05:15 +0000, Gerd Petermann wrote:
> Hi Ticker,
>
> sounds good, but I cannot compile:
> ant clean test
> gives
> build-test:
> [mkdir] Created dir: D:\mkgmap\build\test
> [javac] Compiling 73 source files to D:\mkgmap\build\test
> [javac] D:\mkgmap\test\func\lib\ArrayImgWriter.java:26: error:
> ArrayImgWriter is not abstract and does not override abstract method
> putN(int,int) in ImgFileWriter
> [javac] public class ArrayImgWriter implements ImgFileWriter {
> [javac] ^
> [javac] 1 error
>
> ciao,
> Gerd
> ________________________________________
> Von: mkgmap-dev <[email protected]> im Auftrag
> von Ticker Berkin <[email protected]>
> Gesendet: Dienstag, 1. August 2017 14:31:57
> An: [email protected]
> Betreff: Re: [mkgmap-dev] Find Address - No cities
>
> Hi Gerd
>
> I decided to both fix the code and put out a warning message if there
> are structures that switch to 3 byte pointers (zips, highways and
> exit
> facilities as well as cities)
>
> Address search now works when there are > 65535 cities.
>
> The code is a lot tidier - I've done it properly and it gets rid of
> lots of messy bits of in-line testing against sizes > 255 etc.
>
> Ticker
>
>
> On Mon, 2017-07-31 at 13:12 +0000, Gerd Petermann wrote:
> > Hi Tcker,
> >
> > yes, good enough. I also thought about this alternative.
> >
> > Gerd
> >
> >
> > ________________________________________
> > Von: mkgmap-dev <[email protected]> im Auftrag
> > von Ticker Berkin <[email protected]>
> > Gesendet: Montag, 31. Juli 2017 13:09:49
> > An: [email protected]
> > Betreff: Re: [mkgmap-dev] Find Address - No cities
> >
> > Hi Gerd
> >
> > I started fixing all the places where there is an assumption about
> > the
> > number of cities (and zips) being < 65535 and I'm only part way
> > through
> > my list of suspect files and have make a lot of changes so far.
> >
> > I'm thinking it is not worth while because:
> >
> > The overall MDR size jumps because all city entries change to 3
> > bytes.
> > I get a smaller GMAPSUPP by increasing the splitting so that it
> > stays
> > in the 2 byte limit.
> >
> > I might miss some subtle coding of the header flags and/or the
> > input/output.
> >
> > It might not work anyway after I've made all the changes.
> >
> > The changes are a bit messy because I've just hacked each problem
> > area
> > with a fix. Really there should be some utility functions,
> > enhancements
> > to the readers/writers and pointerSize variables in the relevant
> > classes.
> >
> > I propose just to signal an error in individual maps when the
> > exceed
> > the limit
> >
> > What do you think?
> >
> > Regards
> > Ticker
> >
> > On Sun, 2017-07-30 at 10:16 +0100, Ticker Berkin wrote:
> > > Hi Gerd
> > >
> > > I'll just done a bit more investigation and see what seems to be
> > > the
> > > the same assumption in imgfmt/app/net/RoadDef.java around line
> > > 296
> > > if(numCities > 255)
> > >
> > > writer.putChar(cityIndex);
> > > else
> > >
> > > writer.put((byte)cityIndex);
> > >
> > > I'll fix and test tomorrow and if there are still have problems
> > > I'll
> > > assemble the problem map, style etc for you
> > >
> > > Thanks
> > > Ticker
> > >
> > > On Sun, 2017-07-30 at 06:33 +0000, Gerd Petermann wrote:
> > > > Hi Ticker,
> > > >
> > > > hmm, I think the patch looks good and I have no idea why the
> > > > search
> > > > doesn't work
> > > > for you. Yesterday I thought the patch handles the overall
> > > > number
> > > > of
> > > > cities in the gmapsupp,
> > > > but it is about the number of cities in a single map tile.
> > > > Maybe there is another problem caused by the high number of
> > > > cities.
> > > > Maybe you can post a link to the tile with
> > > > that high number?
> > > >
> > > > Gerd
> > > >
> > > > ________________________________________
> > > > Von: mkgmap-dev <[email protected]> im
> > > > Auftrag
> > > > von Ticker Berkin <[email protected]>
> > > > Gesendet: Samstag, 29. Juli 2017 21:12:27
> > > > An: [email protected]
> > > > Betreff: Re: [mkgmap-dev] Find Address - No cities
> > > >
> > > > Hi Gerd
> > > >
> > > > Quite possibly, or maybe there are limits in the device.
> > > >
> > > > More testing reveals that although my lists of cities and
> > > > streets
> > > > within them appear correctly in Find>Address, it doesn't find
> > > > anything.
> > > >
> > > > Ticker
> > > >
> > > > On Sat, 2017-07-29 at 17:22 +0000, Gerd Petermann wrote:
> > > > > Hi Tcker,
> > > > >
> > > > > thanks for the patch. I seem to remember that the number of
> > > > > entries
> > > > > in mdr5 is also used
> > > > > elsewhere. Will have a closer look tomorrow.
> > > > >
> > > > > Gerd
> > > > > ________________________________________
> > > > > Von: mkgmap-dev <[email protected]> im
> > > > > Auftrag
> > > > > von Ticker Berkin <[email protected]>
> > > > > Gesendet: Samstag, 29. Juli 2017 19:14:02
> > > > > An: [email protected]
> > > > > Betreff: Re: [mkgmap-dev] Find Address - No cities
> > > > >
> > > > > Hi Gerd
> > > > >
> > > > > It looks as if can simply write 1/2/3 bytes as have indicated
> > > > > in
> > > > > the
> > > > > magic field in the MDR header and I've changed it to do this.
> > > > > All
> > > > > seems
> > > > > OK.
> > > > >
> > > > > Yes - I do misuse a City POI. But now, after having worked
> > > > > out
> > > > > how
> > > > > the
> > > > > MDR20 index works, I might be able to do what I want in a
> > > > > better
> > > > > way.
> > > > >
> > > > > Attached is patch to write the correct number of bytes.
> > > > >
> > > > > Regards
> > > > > Ticker
> > > > >
> > > > > On Sat, 2017-07-29 at 16:37 +0000, Gerd Petermann wrote:
> > > > > > Hi Ticker,
> > > > > >
> > > > > > yes, sounds plausible. The comment seems to say that we
> > > > > > don't
> > > > > > know
> > > > > > how to handle so many cities.
> > > > > > Why do you have so many cities. Do you "abuse" the
> > > > > > corresponding
> > > > > > POI
> > > > > > for something?
> > > > > >
> > > > > > Gerd
> > > > > > ________________________________________
> > > > > > Von: mkgmap-dev <[email protected]> im
> > > > > > Auftrag
> > > > > > von Ticker Berkin <[email protected]>
> > > > > > Gesendet: Samstag, 29. Juli 2017 18:13:20
> > > > > > An: [email protected]
> > > > > > Betreff: Re: [mkgmap-dev] Find Address - No cities
> > > > > >
> > > > > > Hi Gerd
> > > > > >
> > > > > > I think I've found the problem:
> > > > > >
> > > > > > /src/uk/me/parabola/imgfmt/app/mdr/Mdr5.java line 227
> > > > > >
> > > > > > private void putLocalCityIndex(ImgFileWriter
> > > > > > writer,
> > > > > > int
> > > > > > cityIndex) {
> > > > > > if (localCitySize == 2)
> > > > > > // 3 probably not possible in actual maps.
> > > > > > writer.putChar((char) cityIndex);
> > > > > > else
> > > > > > writer.put((byte) cityIndex);
> > > > > > }
> > > > > >
> > > > > > There were more than 63335 cities in the failing map.
> > > > > >
> > > > > > Ticker
> > > > > >
> > > > > >
> > > > > > On Sat, 2017-07-29 at 16:09 +0100, Ticker Berkin wrote:
> > > > > > > Hi Gerd
> > > > > > >
> > > > > > > I've done a bit of investigation and debugging. It seems
> > > > > > > to
> > > > > > > be
> > > > > > > building
> > > > > > > the indexes with enough cities and streets. MDR20 is the
> > > > > > > suspect
> > > > > > > index.
> > > > > > >
> > > > > > > I'm now experimenting with mkgmap / Display
> > > > > > >
> > > > > > > With just the suspect map built in gmapsupp:
> > > > > > >
> > > > > > > $ ... test.ExtractFile gmapsupp.img
> > > > > > > filter[]
> > > > > > > Copying . 65024
> > > > > > > Copying MAKEGMAP.MPS 78
> > > > > > > Copying 74440044.RGN 4154927
> > > > > > > Copying 74440044.TRE 18772
> > > > > > > Copying 74440044.LBL 2174485
> > > > > > > Copying 74440044.NET 1626350
> > > > > > > Copying 74440044.NOD 3566829
> > > > > > > Copying 00007444.MDR 2979295
> > > > > > > Copying 00007444.SRT 912
> > > > > > >
> > > > > > > $ ... test.display.MdrSummary 00007444.MDR
> > > > > > > initial values 7 2 e
> > > > > > > MDR 1 NR=1 (000001) RS=4 magic=0x0
> > > > > > > MDR 4 NR=101 (000065) RS=3 magic=0x0
> > > > > > > MDR 5 NR=54456 (00d4b8) RS=9 magic=0x152
> > > > > > > MDR 6 NR=4039 (000fc7) RS=3 magic=0x1
> > > > > > > MDR 7 NR=17674 (00450a) RS=6 magic=0x66
> > > > > > > MDR 9 NR=11 (00000b) RS=4 magic=0x0
> > > > > > > MDR 10 DataSize=427616 (00068660) magic=0x0
> > > > > > > MDR 11 NR=106904(01a198) RS=10 magic=0x95
> > > > > > > MDR 12 NR=11 (00000b) RS=7 magic=0x40a
> > > > > > > MDR 17 DataSize=111036 (0001b1bc) magic=0x0
> > > > > > > MDR 18 NR=102 (000066) RS=5 magic=0x6
> > > > > > > MDR 19 NR=106904(01a198) RS=3 magic=0x2
> > > > > > > MDR 20 NR=20389 (004fa5) RS=6 magic=0xe
> > > > > > > MDR 22 NR=18117 (0046c5) RS=6 magic=0xc000e
> > > > > > > MDR 24 NR=2 (000002) RS=6 magic=0x0
> > > > > > > MDR 25 NR=70016 (011180) RS=3 magic=0x0
> > > > > > > MDR 29 NR=2 (000002) RS=8 magic=0x26
> > > > > > >
> > > > > > > seems fine but
> > > > > > >
> > > > > > > $ ... test.display.MdrCheck 00007444.MDR
> > > > > > > ---------- 00007444.MDR --------------------
> > > > > > > EXTRA
> > > > > > > remaining {}
> > > > > > > # reading 74440044
> > > > > > > mdr5 check
> > > > > > > Exception in thread "main"
> > > > > > > java.lang.IndexOutOfBoundsException:
> > > > > > > Index:
> > > > > > > 308736, Size: 70018
> > > > > > > at
> > > > > > > java.util.ArrayList.rangeCheck(ArrayList.java:653)
> > > > > > > at java.util.ArrayList.get(ArrayList.java:429)
> > > > > > > at
> > > > > > > test.display.check.MapDetails.getCity(MapDetails.java:188
> > > > > > > )
> > > > > > > at
> > > > > > > test.display.MdrCheck.check5(MdrCheck.java:282)
> > > > > > > at test.display.MdrCheck.print(MdrCheck.java:87)
> > > > > > > at
> > > > > > > test.display.CommonDisplay.display(CommonDisplay.java:171
> > > > > > > )
> > > > > > > at
> > > > > > > test.display.CommonDisplay.display(CommonDisplay.java:196
> > > > > > > )
> > > > > > > at
> > > > > > > test.check.CommonCheck.runMain(CommonCheck.java:145)
> > > > > > > at test.display.MdrCheck.main(MdrCheck.java:1789)
> > > > > > > + exit
> > > > > > >
> > > > > > > On another map from the split this runs OK, producing
> > > > > > > masses
> > > > > > > of
> > > > > > > output:
> > > > > > >
> > > > > > > $ ... test.display.MdrCheck 00007429.MDR
> > > > > > > ---------- 00007429.MDR --------------------
> > > > > > > EXTRA
> > > > > > > remaining {}
> > > > > > > # reading 74290047
> > > > > > > ERROR: map 1: city 1: no name; index 1
> > > > > > > mdr5 check
> > > > > > > 1 map1; ABBEY WOOD mapCity=2 reg=0 (LONDON) country=0
> > > > > > > (UNITED
> > > > > > > KINGDOM^]GBR) ind20=0 rep=false
> > > > > > > 2 map1; ABRIDGE mapCity=3 reg=0 (ESSEX) country=0 (UNITED
> > > > > > > KINGDOM^]GBR)
> > > > > > > ind20=0 rep=false
> > > > > > > ... 87000 more lines ...
> > > > > > >
> > > > > > >
> > > > > > > Do you think mkgmap:Display is finding a real problem and
> > > > > > > I
> > > > > > > should
> > > > > > > pursue this line, or could it be unreliable and this
> > > > > > > exception
> > > > > > > is
> > > > > > > due
> > > > > > > to it rather than the format of the index?
> > > > > > >
> > > > > > > Thanks
> > > > > > > Ticker
> > > > > > >
> > > > > > > On Wed, 2017-07-26 at 23:42 -0700, Gerd Petermann wrote:
> > > > > > > > Ticker Berkin wrote
> > > > > > > > > With a particular split of 'british-isles', one map
> > > > > > > > > from
> > > > > > > > > the
> > > > > > > > > split
> > > > > > > > > causes the list of cities in the Find>Address
> > > > > > > > > function
> > > > > > > > > to
> > > > > > > > > be
> > > > > > > > > empty.
> > > > > > > >
> > > > > > > > Maybe you have the same problem here which I described
> > > > > > > > for
> > > > > > > > road
> > > > > > > > name search when road names contain special characters.
> > > > > > > > In
> > > > > > > > your
> > > > > > > > case
> > > > > > > > this would mean special characters in the citiy names.
> > > > > > > > I suggest to add debug code in
> > > > > > > > uk.me.parabola.imgfmt.app.mdr.Mdr5.writeSectData(ImgFil
> > > > > > > > eW
> > > > > > > > ri
> > > > > > > > te
> > > > > > > > r
> > > > > > > > writer)
> > > > > > > > to print all city names which are written to the global
> > > > > > > > index.
> > > > > > > >
> > > > > > > > Gerd
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > --
> > > > > > > > View this message in context:
> > > > > > > > http://gis.19327.n8.nabble.com/Find-Add
> > > > > > > > ress-No-cities-tp5899775p5899880.html
> > > > > > > > Sent from the Mkgmap Development mailing list archive
> > > > > > > > at
> > > > > > > > Nabble.com.
> > > > > > > > _______________________________________________
> > > > > > > > mkgmap-dev mailing list
> > > > > > > > [email protected]
> > > > > > > > http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev
> > > > > > > _______________________________________________
> > > > > > > mkgmap-dev mailing list
> > > > > > > [email protected]
> > > > > > > http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev
> > > > > > _______________________________________________
> > > > > > mkgmap-dev mailing list
> > > > > > [email protected]
> > > > > > http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev
> > > > > > _______________________________________________
> > > > > > mkgmap-dev mailing list
> > > > > > [email protected]
> > > > > > http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev
> > > > > _______________________________________________
> > > > > mkgmap-dev mailing list
> > > > > [email protected]
> > > > > http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev
> > > > _______________________________________________
> > > > mkgmap-dev mailing list
> > > > [email protected]
> > > > http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev
> > > > _______________________________________________
> > > > mkgmap-dev mailing list
> > > > [email protected]
> > > > http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev
> > > _______________________________________________
> > > mkgmap-dev mailing list
> > > [email protected]
> > > http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev
> > _______________________________________________
> > mkgmap-dev mailing list
> > [email protected]
> > http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev
> > _______________________________________________
> > mkgmap-dev mailing list
> > [email protected]
> > http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev
> _______________________________________________
> mkgmap-dev mailing list
> [email protected]
> http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-devIndex: src/uk/me/parabola/imgfmt/Utils.java
===================================================================
--- src/uk/me/parabola/imgfmt/Utils.java (revision 3977)
+++ src/uk/me/parabola/imgfmt/Utils.java (working copy)
@@ -425,5 +425,17 @@
return true;
}
+
+ public static int numberToPointerSize(int n) {
+ // moved from imgfmt/app/mdr/MdrSection.java and app/typ/TYPFile.java
+ if (n <= 0xff)
+ return 1;
+ else if (n <= 0xffff)
+ return 2;
+ else if (n <= 0xffffff)
+ return 3;
+ else
+ return 4;
+ }
+
}
-
Index: src/uk/me/parabola/imgfmt/app/BufferedImgFileWriter.java
===================================================================
--- src/uk/me/parabola/imgfmt/app/BufferedImgFileWriter.java (revision 3977)
+++ src/uk/me/parabola/imgfmt/app/BufferedImgFileWriter.java (working copy)
@@ -119,6 +119,28 @@
}
/**
+ * 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) {
+ 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.
+ * @param val The value to write.
+ */
+ public void put2(int val) {
+ assert val >= 0 && val <= 65535 : val;
+ ensureSize(2);
+ buf.putShort((short)val);
+ }
+
+ /**
* Write out a 3 byte value in the correct byte order etc.
*
* @param val The value to write.
@@ -130,6 +152,33 @@
}
/**
+ * Write out 1-4 bytes. Done in the correct byte order.
+ *
+ * @param nBytes The number of bytes to write.
+ * @param val The value to write.
+ */
+ public void putN(int nBytes, int val) {
+ ensureSize(nBytes);
+ switch (nBytes) {
+ case 1:
+ buf.put((byte)val);
+ break;
+ case 2:
+ buf.putShort((short)val);
+ break;
+ case 3:
+ buf.put((byte)val);
+ buf.putShort((short)(val >> 8));
+ break;
+ case 4:
+ buf.putInt(val);
+ break;
+ default:
+ assert false : nBytes;
+ }
+ }
+
+ /**
* Write out 4 byte value.
*
* @param val The value to write.
Index: src/uk/me/parabola/imgfmt/app/FileBackedImgFileWriter.java
===================================================================
--- src/uk/me/parabola/imgfmt/app/FileBackedImgFileWriter.java (revision 3977)
+++ src/uk/me/parabola/imgfmt/app/FileBackedImgFileWriter.java (working copy)
@@ -130,6 +130,36 @@
}
/**
+ * 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) {
+ assert val >= 0 && val <= 255 : val;
+ try {
+ file.write(val);
+ } catch (IOException e) {
+ throw new MapFailedException("could not write byte to mdr tmp file");
+ }
+ }
+
+ /**
+ * Write out int in range 0..65535 as two bytes in correct byte order.
+ * Use instead of putChar() for unsigned for clarity.
+ * @param val The value to write.
+ */
+ public void put2(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");
+ }
+
+ }
+
+ /**
* 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.
@@ -145,6 +175,29 @@
}
/**
+ * Write out 1-4 bytes. Done in the correct byte order.
+ *
+ * @param nBytes The number of bytes to write.
+ * @param val The value to write.
+ */
+ public void putN(int nBytes, int val) {
+ try {
+ file.write(val);
+ if (nBytes <= 1)
+ return;
+ file.write(val >> 8);
+ if (nBytes <= 2)
+ return;
+ file.write(val >> 16);
+ if (nBytes <= 3)
+ return;
+ file.write(val >> 24);
+ } catch (IOException e) {
+ throw new MapFailedException("could not write put3 to mdr tmp file");
+ }
+ }
+
+ /**
* Write out 4 byte value.
*
* @param val The value to write.
Index: src/uk/me/parabola/imgfmt/app/ImgFileWriter.java
===================================================================
--- src/uk/me/parabola/imgfmt/app/ImgFileWriter.java (revision 3977)
+++ src/uk/me/parabola/imgfmt/app/ImgFileWriter.java (working copy)
@@ -64,6 +64,20 @@
public void putChar(char c);
/**
+ * 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);
+
+ /**
+ * Write out int in range 0..65535 as two bytes in correct byte order.
+ * Use instead of putChar() for unsigned for clarity.
+ * @param val The value to write.
+ */
+ public void put2(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
@@ -72,6 +86,14 @@
public void put3(int val);
/**
+ * Write out 1-4 bytes. Done in the correct byte order.
+ *
+ * @param nBytes The number of bytes to write.
+ * @param val The value to write.
+ */
+ public void putN(int nBytes, int val);
+
+ /**
* Write out 4 byte value.
* @param val The value to write.
*/
Index: src/uk/me/parabola/imgfmt/app/SectionWriter.java
===================================================================
--- src/uk/me/parabola/imgfmt/app/SectionWriter.java (revision 3977)
+++ src/uk/me/parabola/imgfmt/app/SectionWriter.java (working copy)
@@ -66,10 +66,22 @@
writer.putChar(c);
}
+ public void put1(int val) {
+ writer.put1(val);
+ };
+
+ public void put2(int val) {
+ writer.put2(val);
+ };
+
public void put3(int val) {
writer.put3(val);
}
+ public void putN(int nBytes, int val) {
+ writer.putN(nBytes, val);
+ }
+
public void putInt(int val) {
writer.putInt(val);
}
Index: src/uk/me/parabola/imgfmt/app/lbl/LBLFile.java
===================================================================
--- src/uk/me/parabola/imgfmt/app/lbl/LBLFile.java (revision 3977)
+++ src/uk/me/parabola/imgfmt/app/lbl/LBLFile.java (working copy)
@@ -226,6 +226,14 @@
return places.numZips();
}
+ public int numHighways() {
+ return places.numHighways();
+ }
+
+ public int numExitFacilities() {
+ return places.numExitFacilities();
+ }
+
public int getCodePage() {
return lblHeader.getCodePage();
}
Index: src/uk/me/parabola/imgfmt/app/lbl/LBLFileReader.java
===================================================================
--- src/uk/me/parabola/imgfmt/app/lbl/LBLFileReader.java (revision 3977)
+++ src/uk/me/parabola/imgfmt/app/lbl/LBLFileReader.java (working copy)
@@ -19,6 +19,7 @@
import java.util.Map;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
+import uk.me.parabola.imgfmt.Utils;
import uk.me.parabola.imgfmt.app.BufferedImgFileReader;
import uk.me.parabola.imgfmt.app.ImgFile;
import uk.me.parabola.imgfmt.app.ImgFileReader;
@@ -404,22 +405,12 @@
}
if (hasCity) {
- int cityIndex;
-
- if (placeHeader.getNumCities() > 0xFF)
- cityIndex = reader.getChar();
- else
- cityIndex = reader.get() & 0xff;
-
+ int cityIndex = reader.getUint(Utils.numberToPointerSize(placeHeader.getNumCities()));
poi.setCity(cities.get(cityIndex-1));
}
if (hasZip) {
- int zipIndex;
- if (placeHeader.getNumZips() > 0xff)
- zipIndex = reader.getChar();
- else
- zipIndex = reader.get() & 0xff;
+ int zipIndex = reader.getUint(Utils.numberToPointerSize(placeHeader.getNumZips()));
poi.setZip(zips.get(zipIndex-1));
}
@@ -442,12 +433,9 @@
boolean indexed = (lblinfo & 0x800000) != 0;
boolean overnightParking = (lblinfo & 0x400000) != 0;
- int highwayIndex = (placeHeader.getNumHighways() > 255)
- ? reader.getChar() : reader.get();
+ int highwayIndex = reader.getUint(Utils.numberToPointerSize(placeHeader.getNumHighways()));
if (indexed) {
- int eidx = (placeHeader.getNumExits() > 255) ?
- reader.getChar() :
- reader.get();
+ int eidx = reader.getUint(Utils.numberToPointerSize(placeHeader.getNumExits()));
}
}
Index: src/uk/me/parabola/imgfmt/app/lbl/POIRecord.java
===================================================================
--- src/uk/me/parabola/imgfmt/app/lbl/POIRecord.java (revision 3977)
+++ src/uk/me/parabola/imgfmt/app/lbl/POIRecord.java (working copy)
@@ -18,6 +18,7 @@
import java.util.List;
+import uk.me.parabola.imgfmt.Utils;
import uk.me.parabola.imgfmt.app.Exit;
import uk.me.parabola.imgfmt.app.ImgFileWriter;
import uk.me.parabola.imgfmt.app.Label;
@@ -130,18 +131,12 @@
if (city != null)
{
char cityIndex = (char) city.getIndex();
- if(numCities > 255)
- writer.putChar(cityIndex);
- else
- writer.put((byte)cityIndex);
+ writer.putN(Utils.numberToPointerSize((int)numCities), cityIndex);
}
if (zip != null) {
char zipIndex = (char) zip.getIndex();
- if(numZips > 255)
- writer.putChar(zipIndex);
- else
- writer.put((byte) zipIndex);
+ writer.putN(Utils.numberToPointerSize((int)numZips), zipIndex);
}
if (complexPhoneNumber != null)
@@ -171,17 +166,11 @@
writer.put3(val);
char highwayIndex = (char)exit.getHighway().getIndex();
- if(numHighways > 255)
- writer.putChar(highwayIndex);
- else
- writer.put((byte)highwayIndex);
-
+ writer.putN(Utils.numberToPointerSize((int)numHighways), highwayIndex);
+
if(ef != null) {
char exitFacilityIndex = (char)ef.getIndex();
- if(numExitFacilities > 255)
- writer.putChar(exitFacilityIndex);
- else
- writer.put((byte)exitFacilityIndex);
+ writer.putN(Utils.numberToPointerSize((int)numExitFacilities), exitFacilityIndex);
}
}
}
@@ -242,9 +231,9 @@
int size = 3;
if (exit != null) {
size += 3;
- size += (numHighways > 255)? 2 : 1;
+ size += Utils.numberToPointerSize((int)numHighways);
if(!exit.getFacilities().isEmpty())
- size += (numExitFacilities > 255)? 2 : 1;
+ size += Utils.numberToPointerSize((int)numExitFacilities);
}
if (POIGlobalFlags != getPOIFlags())
size += 1;
@@ -262,20 +251,13 @@
{
/*
depending on how many cities are in the LBL block we have
- to write one or two bytes
+ to write one to three bytes
*/
-
- if(numCities > 255)
- size += 2;
- else
- size += 1;
+ size += Utils.numberToPointerSize((int)numCities);
}
if (zip != null) {
- // depending on how many zips are in the LBL block we have to write one or two bytes
- if(numZips > 255)
- size += 2;
- else
- size += 1;
+ // depending on how many zips are in the LBL block we have to write one to three bytes
+ size += Utils.numberToPointerSize((int)numZips);
}
return size;
}
Index: src/uk/me/parabola/imgfmt/app/lbl/PlacesFile.java
===================================================================
--- src/uk/me/parabola/imgfmt/app/lbl/PlacesFile.java (revision 3977)
+++ src/uk/me/parabola/imgfmt/app/lbl/PlacesFile.java (working copy)
@@ -419,6 +419,14 @@
return postalCodes.size();
}
+ public int numHighways() {
+ return highways.size();
+ }
+
+ public int numExitFacilities() {
+ return exitFacilities.size();
+ }
+
public void setSort(Sort sort) {
this.sort = sort;
}
Index: src/uk/me/parabola/imgfmt/app/mdr/Mdr15.java
===================================================================
--- src/uk/me/parabola/imgfmt/app/mdr/Mdr15.java (revision 3977)
+++ src/uk/me/parabola/imgfmt/app/mdr/Mdr15.java (working copy)
@@ -132,7 +132,7 @@
* for this.
*/
public int getSizeForRecord() {
- return numberToPointerSize(nextOffset);
+ return Utils.numberToPointerSize(nextOffset);
}
/**
Index: src/uk/me/parabola/imgfmt/app/mdr/Mdr17.java
===================================================================
--- src/uk/me/parabola/imgfmt/app/mdr/Mdr17.java (revision 3977)
+++ src/uk/me/parabola/imgfmt/app/mdr/Mdr17.java (working copy)
@@ -64,7 +64,7 @@
len <<= 1;
count++;
}
- putN(writer, count, len);
+ writer.putN(count, len);
// Calculate the header. This code is unlikely to survive the finding of another example!
// Have no idea what the real thinking behind this is.
Index: src/uk/me/parabola/imgfmt/app/mdr/Mdr18.java
===================================================================
--- src/uk/me/parabola/imgfmt/app/mdr/Mdr18.java (revision 3977)
+++ src/uk/me/parabola/imgfmt/app/mdr/Mdr18.java (working copy)
@@ -35,7 +35,7 @@
int poiSize = getSizes().getSize(19);
for (Mdr18Record pt : poiTypes) {
writer.putChar((char) (pt.getType() | 0x4000));
- putN(writer, poiSize, pt.getRecord());
+ writer.putN(poiSize, pt.getRecord());
}
}
Index: src/uk/me/parabola/imgfmt/app/mdr/Mdr19.java
===================================================================
--- src/uk/me/parabola/imgfmt/app/mdr/Mdr19.java (revision 3977)
+++ src/uk/me/parabola/imgfmt/app/mdr/Mdr19.java (working copy)
@@ -69,7 +69,7 @@
index |= flag;
lastName = name;
}
- putN(writer, n, index);
+ writer.putN(n, index);
int type = MdrUtils.fullTypeToNaturalType(p.getType());
if (type != lastType) {
Index: src/uk/me/parabola/imgfmt/app/mdr/Mdr1MapIndex.java
===================================================================
--- src/uk/me/parabola/imgfmt/app/mdr/Mdr1MapIndex.java (revision 3977)
+++ src/uk/me/parabola/imgfmt/app/mdr/Mdr1MapIndex.java (working copy)
@@ -44,22 +44,7 @@
}
public void addPointer(int recordNumber) {
- switch (pointerSize) {
- case 4:
- subWriter.putInt(recordNumber);
- break;
- case 3:
- subWriter.put3(recordNumber);
- break;
- case 2:
- subWriter.putChar((char) recordNumber);
- break;
- case 1:
- subWriter.put((byte) recordNumber);
- break;
- default:
- assert false;
- }
+ subWriter.putN(pointerSize, recordNumber);
}
private int sectionToSubsection(int n) {
Index: src/uk/me/parabola/imgfmt/app/mdr/Mdr25.java
===================================================================
--- src/uk/me/parabola/imgfmt/app/mdr/Mdr25.java (revision 3977)
+++ src/uk/me/parabola/imgfmt/app/mdr/Mdr25.java (working copy)
@@ -81,7 +81,7 @@
public void writeSectData(ImgFileWriter writer) {
int size = getItemSize();
for (Mdr5Record city : cities) {
- putN(writer, size, city.getGlobalCityIndex());
+ writer.putN(size, city.getGlobalCityIndex());
}
}
Index: src/uk/me/parabola/imgfmt/app/mdr/Mdr26.java
===================================================================
--- src/uk/me/parabola/imgfmt/app/mdr/Mdr26.java (revision 3977)
+++ src/uk/me/parabola/imgfmt/app/mdr/Mdr26.java (working copy)
@@ -74,7 +74,7 @@
public void writeSectData(ImgFileWriter writer) {
int size = getSizes().getSize(28);
for (Mdr28Record record : index) {
- putN(writer, size, record.getIndex());
+ writer.putN(size, record.getIndex());
}
}
Index: src/uk/me/parabola/imgfmt/app/mdr/Mdr27.java
===================================================================
--- src/uk/me/parabola/imgfmt/app/mdr/Mdr27.java (revision 3977)
+++ src/uk/me/parabola/imgfmt/app/mdr/Mdr27.java (working copy)
@@ -76,7 +76,7 @@
public void writeSectData(ImgFileWriter writer) {
int size = getItemSize();
for (Mdr5Record city : cities) {
- putN(writer, size, city.getGlobalCityIndex());
+ writer.putN(size, city.getGlobalCityIndex());
}
}
Index: src/uk/me/parabola/imgfmt/app/mdr/Mdr28.java
===================================================================
--- src/uk/me/parabola/imgfmt/app/mdr/Mdr28.java (revision 3977)
+++ src/uk/me/parabola/imgfmt/app/mdr/Mdr28.java (working copy)
@@ -73,10 +73,10 @@
int size27 = sizes.getSize(27);
for (Mdr28Record mdr28 : index) {
- putN(writer, size23, mdr28.getMdr23());
+ writer.putN(size23, mdr28.getMdr23());
putStringOffset(writer, mdr28.getStrOffset());
- putN(writer, size21, mdr28.getMdr21());
- putN(writer, size27, mdr28.getMdr27());
+ writer.putN(size21, mdr28.getMdr21());
+ writer.putN(size27, mdr28.getMdr27());
}
}
Index: src/uk/me/parabola/imgfmt/app/mdr/Mdr29.java
===================================================================
--- src/uk/me/parabola/imgfmt/app/mdr/Mdr29.java (revision 3977)
+++ src/uk/me/parabola/imgfmt/app/mdr/Mdr29.java (working copy)
@@ -15,6 +15,7 @@
import java.util.ArrayList;
import java.util.List;
+import uk.me.parabola.imgfmt.Utils;
import uk.me.parabola.imgfmt.app.ImgFileWriter;
import uk.me.parabola.imgfmt.app.srt.Sort;
import uk.me.parabola.imgfmt.app.srt.SortKey;
@@ -82,17 +83,17 @@
int size22 = sizes.getSize(22);
int size25 = sizes.getSize(5); // NB appears to be size of 5 (cities), not 25 (cities with country).
int size26 = has26? sizes.getSize(26): 0;
- int size17 = numberToPointerSize(max17);
+ int size17 = Utils.numberToPointerSize(max17);
for (Mdr29Record record : index) {
- putN(writer, size24, record.getMdr24());
+ writer.putN(size24, record.getMdr24());
if (hasString)
putStringOffset(writer, record.getStrOffset());
- putN(writer, size22, record.getMdr22());
- putN(writer, size25, record.getMdr25());
+ writer.putN(size22, record.getMdr22());
+ writer.putN(size25, record.getMdr25());
if (has26)
- putN(writer, size26, record.getMdr26());
+ writer.putN(size26, record.getMdr26());
if (has17)
- putN(writer, size17, record.getMdr17());
+ writer.putN(size17, record.getMdr17());
}
}
@@ -111,7 +112,7 @@
;
if (isForDevice()) {
if (!getConfig().getSort().isMulti())
- size += numberToPointerSize(max17);
+ size += Utils.numberToPointerSize(max17);
} else {
size += sizes.getStrOffSize();
size += sizes.getSize(26);
@@ -138,7 +139,7 @@
if (isForDevice()) {
int magic = 0x6; // 22 and 25
if (!getConfig().getSort().isMulti())
- magic |= numberToPointerSize(max17) << 4;
+ magic |= Utils.numberToPointerSize(max17) << 4;
return magic; // +17, -26, -strings
}
else
Index: src/uk/me/parabola/imgfmt/app/mdr/Mdr2x.java
===================================================================
--- src/uk/me/parabola/imgfmt/app/mdr/Mdr2x.java (revision 3977)
+++ src/uk/me/parabola/imgfmt/app/mdr/Mdr2x.java (working copy)
@@ -70,7 +70,7 @@
int trailingFlags = ((rr & 1) == 0) ? 1 : 0;
// trailingFlags |= s.getB() << 1;
// trailingFlags |= s.getS() << (1 + partialBShift);
- putN(writer, partialInfoSize, trailingFlags);
+ writer.putN(partialInfoSize, trailingFlags);
}
} else {
int rr = street.checkFullRepeat(prev, collator);
@@ -78,7 +78,7 @@
repeat = 0;
int index = street.getIndex();
- putN(writer, size, (index << 1) | repeat);
+ writer.putN(size, (index << 1) | repeat);
}
prev = street;
Index: src/uk/me/parabola/imgfmt/app/mdr/Mdr5.java
===================================================================
--- src/uk/me/parabola/imgfmt/app/mdr/Mdr5.java (revision 3977)
+++ src/uk/me/parabola/imgfmt/app/mdr/Mdr5.java (working copy)
@@ -17,6 +17,7 @@
import java.util.Collections;
import java.util.List;
+import uk.me.parabola.imgfmt.Utils;
import uk.me.parabola.imgfmt.app.ImgFileWriter;
import uk.me.parabola.imgfmt.app.srt.MultiSortKey;
import uk.me.parabola.imgfmt.app.srt.Sort;
@@ -51,7 +52,7 @@
* Called after all cities to sort and number them.
*/
public void preWriteImpl() {
- localCitySize = numberToPointerSize(maxCityIndex + 1);
+ localCitySize = Utils.numberToPointerSize(maxCityIndex + 1);
List<SortKey<Mdr5Record>> sortKeys = new ArrayList<>(allCities.size());
Sort sort = getConfig().getSort();
@@ -216,7 +217,7 @@
writer.putChar((char) region);
if (hasString)
putStringOffset(writer, city.getStringOffset());
- putN(writer, size20, city.getMdr20());
+ writer.putN(size20, city.getMdr20());
}
}
@@ -225,10 +226,7 @@
* and not the global city index used in mdr11.
*/
private void putLocalCityIndex(ImgFileWriter writer, int cityIndex) {
- if (localCitySize == 2) // 3 probably not possible in actual maps.
- writer.putChar((char) cityIndex);
- else
- writer.put((byte) cityIndex);
+ writer.putN(localCitySize, cityIndex);
}
/**
Index: src/uk/me/parabola/imgfmt/app/mdr/Mdr6.java
===================================================================
--- src/uk/me/parabola/imgfmt/app/mdr/Mdr6.java (revision 3977)
+++ src/uk/me/parabola/imgfmt/app/mdr/Mdr6.java (working copy)
@@ -56,7 +56,7 @@
addIndexPointer(z.getMapIndex(), record++);
putMapIndex(writer, z.getMapIndex());
- putN(writer, zipSize, z.getZipIndex());
+ writer.putN(zipSize, z.getZipIndex());
if (hasString)
putStringOffset(writer, z.getStringOffset());
}
Index: src/uk/me/parabola/imgfmt/app/mdr/Mdr7.java
===================================================================
--- src/uk/me/parabola/imgfmt/app/mdr/Mdr7.java (revision 3977)
+++ src/uk/me/parabola/imgfmt/app/mdr/Mdr7.java (working copy)
@@ -367,7 +367,7 @@
int trailingFlags = ((rr & 1) == 0) ? 1 : 0;
// trailingFlags |= s.getB() << 1;
// trailingFlags |= s.getS() << (1 + partialBShift);
- putN(writer, partialInfoSize, trailingFlags);
+ writer.putN(partialInfoSize, trailingFlags);
}
last = s;
}
Index: src/uk/me/parabola/imgfmt/app/mdr/Mdr8.java
===================================================================
--- src/uk/me/parabola/imgfmt/app/mdr/Mdr8.java (revision 3977)
+++ src/uk/me/parabola/imgfmt/app/mdr/Mdr8.java (working copy)
@@ -44,7 +44,7 @@
for (int i = 0; i< STRING_WIDTH; i++) {
writer.put((byte) s.getPrefix()[i]);
}
- putN(writer, size, s.getRecordNumber());
+ writer.putN(size, s.getRecordNumber());
}
}
Index: src/uk/me/parabola/imgfmt/app/mdr/Mdr9.java
===================================================================
--- src/uk/me/parabola/imgfmt/app/mdr/Mdr9.java (revision 3977)
+++ src/uk/me/parabola/imgfmt/app/mdr/Mdr9.java (working copy)
@@ -36,7 +36,7 @@
for (Map.Entry<Integer, Integer> ent : index.entrySet()) {
int group = ent.getKey();
writer.put((byte) group);
- putN(writer, poiSize, ent.getValue());
+ writer.putN(poiSize, ent.getValue());
}
}
Index: src/uk/me/parabola/imgfmt/app/mdr/MdrMapSection.java
===================================================================
--- src/uk/me/parabola/imgfmt/app/mdr/MdrMapSection.java (revision 3977)
+++ src/uk/me/parabola/imgfmt/app/mdr/MdrMapSection.java (working copy)
@@ -12,6 +12,7 @@
*/
package uk.me.parabola.imgfmt.app.mdr;
+import uk.me.parabola.imgfmt.Utils;
import uk.me.parabola.imgfmt.app.ImgFileWriter;
/**
@@ -37,7 +38,7 @@
// There are no flags or minimums required here, unlike in setPointerSize()
// which does a similar thing.
int n = getNumberOfItems();
- index.setPointerSize(sectionNumber, numberToPointerSize(n));
+ index.setPointerSize(sectionNumber, Utils.numberToPointerSize(n));
}
/**
@@ -52,18 +53,18 @@
protected void putCityIndex(ImgFileWriter writer, int cityIndex, boolean isNew) {
int flag = (isNew && cityIndex > 0)? getSizes().getCityFlag(): 0;
- putN(writer, getSizes().getCitySizeFlagged(), cityIndex | flag);
+ writer.putN(getSizes().getCitySizeFlagged(), cityIndex | flag);
}
protected void putRegionIndex(ImgFileWriter writer, int region) {
// This is only called when putCityIndex might also be called and so has to be
// the same size (probably ;)
- putN(writer, getSizes().getCitySizeFlagged(), region);
+ writer.putN(getSizes().getCitySizeFlagged(), region);
}
protected void putPoiIndex(ImgFileWriter writer, int poiIndex, boolean isNew) {
int flag = isNew? getSizes().getPoiFlag(): 0;
- putN(writer, getSizes().getPoiSizeFlagged(), poiIndex | flag);
+ writer.putN(getSizes().getPoiSizeFlagged(), poiIndex | flag);
}
protected boolean hasFlag(int val) {
Index: src/uk/me/parabola/imgfmt/app/mdr/MdrSection.java
===================================================================
--- src/uk/me/parabola/imgfmt/app/mdr/MdrSection.java (revision 3977)
+++ src/uk/me/parabola/imgfmt/app/mdr/MdrSection.java (working copy)
@@ -12,6 +12,7 @@
*/
package uk.me.parabola.imgfmt.app.mdr;
+import uk.me.parabola.imgfmt.Utils;
import uk.me.parabola.imgfmt.app.ImgFileWriter;
/**
@@ -48,44 +49,13 @@
}
protected void putMapIndex(ImgFileWriter writer, int mapIndex) {
- putN(writer, sizes.getMapSize(), mapIndex);
+ writer.putN(sizes.getMapSize(), mapIndex);
}
protected void putStringOffset(ImgFileWriter writer, int strOff) {
- putN(writer, sizes.getStrOffSize(), strOff);
+ writer.putN(sizes.getStrOffSize(), strOff);
}
- protected void putN(ImgFileWriter writer, int n, int value) {
- switch (n) {
- case 1:
- writer.put((byte) value);
- break;
- case 2:
- writer.putChar((char) value);
- break;
- case 3:
- writer.put3(value);
- break;
- case 4:
- writer.putInt(value);
- break;
- default: // Don't write anything.
- assert false;
- break;
- }
- }
-
- protected static int numberToPointerSize(int n) {
- if (n > 0xffffff)
- return 4;
- else if (n > 0xffff)
- return 3;
- else if (n > 0xff)
- return 2;
- else
- return 1;
- }
-
/**
* The number of records in this section.
* @return The number of items in the section.
@@ -113,7 +83,7 @@
* to store the largest record number in this section.
*/
public int getSizeForRecord() {
- return numberToPointerSize(getNumberOfItems());
+ return Utils.numberToPointerSize(getNumberOfItems());
}
/**
@@ -178,7 +148,7 @@
* one bit flag.
*/
public int getCitySizeFlagged() {
- return Math.max(2, numberToPointerSize(sections[5].getNumberOfItems() << 1));
+ return Math.max(2, Utils.numberToPointerSize(sections[5].getNumberOfItems() << 1));
}
public int getCityFlag() {
@@ -190,7 +160,7 @@
}
public int getStreetSizeFlagged() {
- return numberToPointerSize(sections[7].getNumberOfItems() << 1);
+ return Utils.numberToPointerSize(sections[7].getNumberOfItems() << 1);
}
public int getPoiSize() {
@@ -207,7 +177,7 @@
* and a flag bit.
*/
public int getPoiSizeFlagged() {
- return numberToPointerSize(sections[11].getNumberOfItems() << 1);
+ return Utils.numberToPointerSize(sections[11].getNumberOfItems() << 1);
}
public int getPoiFlag() {
Index: src/uk/me/parabola/imgfmt/app/mdr/PrefixIndex.java
===================================================================
--- src/uk/me/parabola/imgfmt/app/mdr/PrefixIndex.java (revision 3977)
+++ src/uk/me/parabola/imgfmt/app/mdr/PrefixIndex.java (working copy)
@@ -16,6 +16,7 @@
import java.util.ArrayList;
import java.util.List;
+import uk.me.parabola.imgfmt.Utils;
import uk.me.parabola.imgfmt.app.ImgFileWriter;
import uk.me.parabola.imgfmt.app.srt.Sort;
import uk.me.parabola.imgfmt.app.srt.Sort.SrtCollator;
@@ -114,17 +115,17 @@
* Write the section or subsection.
*/
public void writeSectData(ImgFileWriter writer) {
- int size = numberToPointerSize(maxIndex);
+ int size = Utils.numberToPointerSize(maxIndex);
for (Mdr8Record s : index) {
for (int i = 0; i< prefixLength; i++) {
writer.put((byte) s.getPrefix()[i]);
}
- putN(writer, size, s.getRecordNumber());
+ writer.putN(size, s.getRecordNumber());
}
}
public int getItemSize() {
- return prefixLength + numberToPointerSize(maxIndex);
+ return prefixLength + Utils.numberToPointerSize(maxIndex);
}
protected int numberOfItems() {
Index: src/uk/me/parabola/imgfmt/app/net/NETFileReader.java
===================================================================
--- src/uk/me/parabola/imgfmt/app/net/NETFileReader.java (revision 3977)
+++ src/uk/me/parabola/imgfmt/app/net/NETFileReader.java (working copy)
@@ -22,6 +22,7 @@
import java.util.Map;
import java.util.Set;
+import uk.me.parabola.imgfmt.Utils;
import uk.me.parabola.imgfmt.app.BufferedImgFileReader;
import uk.me.parabola.imgfmt.app.ImgFile;
import uk.me.parabola.imgfmt.app.ImgFileReader;
@@ -152,7 +153,7 @@
indexes.clear();
if (flag == 2) {
// fetch city/zip index
- int ind = (size == 2)? reader.getChar(): (reader.get() & 0xff);
+ int ind = reader.getUint(size);
if (ind != 0)
indexes.add(ind-1);
} else if (flag == 3) {
@@ -209,15 +210,7 @@
assert false : "ERRROR overflow";
return 0;
}
- int cnum;
- if (size == 1)
- cnum = reader.get() & 0xff;
- else if (size == 2)
- cnum = reader.getChar();
- else {
- assert false : "unexpected size value" + size;
- return 0;
- }
+ int cnum = reader.getUint(size);
return cnum;
}
@@ -300,12 +293,12 @@
public void setCities(List<City> cities) {
this.cities = cities;
- this.citySize = cities.size() > 255? 2: 1;
+ this.citySize = Utils.numberToPointerSize(cities.size());
}
public void setZips(List<Zip> zips) {
this.zips = zips;
- this.zipSize = zips.size() > 255? 2: 1;
+ this.zipSize = Utils.numberToPointerSize(zips.size());
}
public void setLabels(LBLFileReader labels) {
Index: src/uk/me/parabola/imgfmt/app/net/NumberPreparer.java
===================================================================
--- src/uk/me/parabola/imgfmt/app/net/NumberPreparer.java (revision 3977)
+++ src/uk/me/parabola/imgfmt/app/net/NumberPreparer.java (working copy)
@@ -17,6 +17,7 @@
import java.util.Iterator;
import java.util.List;
+import uk.me.parabola.imgfmt.Utils;
import uk.me.parabola.imgfmt.app.BitWriter;
import uk.me.parabola.imgfmt.app.lbl.City;
import uk.me.parabola.imgfmt.app.lbl.Zip;
@@ -998,12 +999,14 @@
void writeIndex(int val){
if (val <= 0)
return;
- if (numItems > 255){
- buf.write((byte) val & 0xff);
- buf.write((byte) (val >> 8));
- }
- else
- buf.write((byte) val);
+ int ptrSize = Utils.numberToPointerSize(numItems);
+ buf.write(val);
+ if (ptrSize <= 1)
+ return;
+ buf.write(val >> 8);
+ if (ptrSize <= 2)
+ return;
+ buf.write(val >> 16);
}
}
Index: src/uk/me/parabola/imgfmt/app/net/RoadDef.java
===================================================================
--- src/uk/me/parabola/imgfmt/app/net/RoadDef.java (revision 3977)
+++ src/uk/me/parabola/imgfmt/app/net/RoadDef.java (working copy)
@@ -27,6 +27,7 @@
import java.util.TreeMap;
import uk.me.parabola.imgfmt.MapFailedException;
+import uk.me.parabola.imgfmt.Utils;
import uk.me.parabola.imgfmt.app.BitWriter;
import uk.me.parabola.imgfmt.app.ImgFileWriter;
import uk.me.parabola.imgfmt.app.Label;
@@ -243,7 +244,7 @@
len = (numbers == null) ? 0: numbers.zipWriter.getBuffer().size();
if (len > 0){
zipBuf = numbers.zipWriter.getBuffer();
- flag = (len > 255) ? 1 : 0;
+ flag = Utils.numberToPointerSize(len) - 1;
} else
flag = (zip == null) ? 3 : 2;
code |= flag << 2;
@@ -251,7 +252,7 @@
len = (numbers == null) ? 0: numbers.cityWriter.getBuffer().size();
if (len > 0){
cityBuf = numbers.cityWriter.getBuffer();
- flag = (len > 255) ? 1 : 0;
+ flag = Utils.numberToPointerSize(len) - 1;
} else
flag = (city == null) ? 3 : 2;
code |= flag << 4;
@@ -258,7 +259,7 @@
len = (numbers == null) ? 0 : numbers.fetchBitStream().getLength();
if (len > 0){
- flag = (len > 255) ? 1 : 0;
+ flag = Utils.numberToPointerSize(len) - 1;
} else
flag = 3;
code |= flag << 6;
@@ -268,42 +269,27 @@
if (zipBuf != null){
len = zipBuf.size();
- if (len > 255)
- writer.putChar((char) len);
- else
- writer.put((byte) len);
+ writer.putN(Utils.numberToPointerSize(len), len);
writer.put(zipBuf.toByteArray());
} else {
if(zip != null) {
char zipIndex = (char)zip.getIndex();
- if(numZips > 255)
- writer.putChar(zipIndex);
- else
- writer.put((byte)zipIndex);
+ writer.putN(Utils.numberToPointerSize(numZips), zipIndex);
}
}
if (cityBuf != null){
len = cityBuf.size();
- if (len > 255)
- writer.putChar((char) len);
- else
- writer.put((byte) len);
+ writer.putN(Utils.numberToPointerSize(len), len);
writer.put(cityBuf.toByteArray());
} else {
if(city != null) {
char cityIndex = (char)city.getIndex();
- if(numCities > 255)
- writer.putChar(cityIndex);
- else
- writer.put((byte)cityIndex);
+ writer.putN(Utils.numberToPointerSize(numCities), cityIndex);
}
}
if (numbers != null) {
BitWriter bw = numbers.fetchBitStream();
- if (bw.getLength() > 255)
- writer.putChar((char) bw.getLength());
- else
- writer.put((byte) bw.getLength());
+ writer.putN(Utils.numberToPointerSize(bw.getLength()), bw.getLength());
writer.put(bw.getBytes(), 0, bw.getLength());
}
}
Index: src/uk/me/parabola/imgfmt/app/typ/TYPFile.java
===================================================================
--- src/uk/me/parabola/imgfmt/app/typ/TYPFile.java (revision 3977)
+++ src/uk/me/parabola/imgfmt/app/typ/TYPFile.java (working copy)
@@ -135,12 +135,12 @@
private void writeStrIndex(ImgFileWriter in) {
SectionWriter writer = header.getStringIndex().makeSectionWriter(in);
- int psize = ptrSize(header.getLabels().getSize());
+ int psize = Utils.numberToPointerSize(header.getLabels().getSize());
header.getStringIndex().setItemSize((char) (3 + psize));
for (Map.Entry<Integer, Integer> ent : strToType.entrySet()) {
- putN(writer, psize, ent.getKey());
- putN(writer, 3, ent.getValue());
+ writer.putN(psize, ent.getKey());
+ writer.put3(ent.getValue());
}
Utils.closeFile(writer);
}
@@ -147,12 +147,12 @@
private void writerTypeIndex(ImgFileWriter in) {
SectionWriter writer = header.getTypeIndex().makeSectionWriter(in);
- int psize = ptrSize(header.getLabels().getSize());
+ int psize = Utils.numberToPointerSize(header.getLabels().getSize());
header.getTypeIndex().setItemSize((char) (3 + psize));
for (Map.Entry<Integer, Integer> ent : typeToStr.entrySet()) {
- putN(writer, 3, ent.getKey());
- putN(writer, psize, ent.getValue());
+ writer.put3(ent.getKey());
+ writer.putN(psize, ent.getValue());
}
Utils.closeFile(writer);
}
@@ -170,7 +170,7 @@
int size = dataSection.getSize();
int typeSize = indexSection.getItemSize();
- int psize = ptrSize(size);
+ int psize = Utils.numberToPointerSize(size);
indexSection.setItemSize((char) (typeSize + psize));
@@ -178,8 +178,8 @@
for (TypElement elem : elementData) {
int offset = elem.getOffset();
int type = elem.getTypeForFile();
- putN(subWriter, typeSize, type);
- putN(subWriter, psize, offset);
+ subWriter.putN(typeSize, type);
+ subWriter.putN(psize, offset);
}
Utils.closeFile(subWriter);
@@ -195,37 +195,6 @@
}
}
- private int ptrSize(int size) {
- int psize = 1;
- if (size > 0xffffff)
- psize = 4;
- else if (size > 0xffff)
- psize = 3;
- else if (size > 0xff)
- psize = 2;
- return psize;
- }
-
- protected void putN(ImgFileWriter writer, int n, int value) {
- switch (n) {
- case 1:
- writer.put((byte) value);
- break;
- case 2:
- writer.putChar((char) value);
- break;
- case 3:
- writer.put3(value);
- break;
- case 4:
- writer.putInt(value);
- break;
- default: // Don't write anything.
- assert false;
- break;
- }
- }
-
public void setData(TypData data) {
this.data = data;
TypParam param = data.getParam();
Index: src/uk/me/parabola/mkgmap/build/MapBuilder.java
===================================================================
--- src/uk/me/parabola/mkgmap/build/MapBuilder.java (revision 3977)
+++ src/uk/me/parabola/mkgmap/build/MapBuilder.java (working copy)
@@ -267,8 +267,26 @@
}
netFile.writePost(rgnFile.getWriter());
}
+ warnAbout3ByteImgRefs();
}
-
+
+ private void warnAbout3ByteImgRefs() {
+ String infoMsg = "- more than 65535 might cause indexing problems and excess size. Suggest splitter with lower --max-nodes";
+ int itemCount;
+ itemCount = lblFile.numCities();
+ if (itemCount > 0xffff)
+ log.error("Map contains", itemCount, "Cities", infoMsg);
+ itemCount = lblFile.numZips();
+ if (itemCount > 0xffff)
+ log.error("Map contains", itemCount, "Zips", infoMsg);
+ itemCount = lblFile.numHighways();
+ if (itemCount > 0xffff)
+ log.error("Map contains", itemCount, "Highways", infoMsg);
+ itemCount = lblFile.numExitFacilities();
+ if (itemCount > 0xffff)
+ log.error("Map contains", itemCount, "Exit facilities", infoMsg);
+ } // warnAbout3ByteImgRefs
+
private Country getDefaultCountry() {
if (defaultCountry == null && lblFile != null) {
defaultCountry = lblFile.createCountry(countryName, countryAbbr);
Index: test/func/lib/ArrayImgWriter.java
===================================================================
--- test/func/lib/ArrayImgWriter.java (revision 3977)
+++ test/func/lib/ArrayImgWriter.java (working copy)
@@ -46,6 +46,15 @@
out.write((c >> 8) & 0xff);
}
+ public void put1(int val) {
+ out.write(val & 0xff);
+ }
+
+ public void put2(int val) {
+ out.write(val & 0xff);
+ out.write((val >> 8) & 0xff);
+ }
+
public void put3(int val) {
out.write(val & 0xff);
out.write((val >> 8) & 0xff);
@@ -52,6 +61,19 @@
out.write((val >> 16) & 0xff);
}
+ public void putN(int nBytes, int val) {
+ out.write(val & 0xff);
+ if (nBytes <= 1)
+ return;
+ out.write((val >> 8) & 0xff);
+ if (nBytes <= 2)
+ return;
+ out.write((val >> 16) & 0xff);
+ if (nBytes <= 3)
+ return;
+ out.write((val >> 24) & 0xff);
+ }
+
public void putInt(int val) {
out.write(val & 0xff);
out.write((val >> 8) & 0xff);
_______________________________________________
mkgmap-dev mailing list
[email protected]
http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev