Debian Codegraph @

src/uk/me/parabola/imgfmt/app/mdr/Mdr6.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2011.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 or
6 * version 2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 */
13
14 package uk.me.parabola.imgfmt.app.mdr;
15
16 import java.util.ArrayList;
17 import java.util.List;
18
19 import uk.me.parabola.imgfmt.app.ImgFileWriter;
20 import uk.me.parabola.imgfmt.app.lbl.Zip;
21 import uk.me.parabola.imgfmt.app.srt.SortKey;
22
23 /**
24 * Section containing zip codes.
25 *
26 * We need: map number, zip index in map, pointer into MDR 15 for the string name.
27 *
28 * @author WanMil
29 */
30 public class Mdr6 extends MdrMapSection {
31
32 private final List<Mdr6Record> zips = new ArrayList<>();
33
34
35 public Mdr6(MdrConfig config) {
36 setConfig(config);
37 }
38
39 public void addZip(int mapIndex, Zip zip, int strOff) {
40 Mdr6Record record = new Mdr6Record(zip);
41 record.setMapIndex(mapIndex);
42 record.setStringOffset(strOff);
43 zips.add(record);
44 }
45
46
47 public void writeSectData(ImgFileWriter writer) {
48 int zipSize = getSizes().getZipSize();
49
50 List<SortKey<Mdr6Record>> sortKeys = MdrUtils.sortList(getConfig().getSort(), zips);
51
52 boolean hasString = hasFlag(0x4);
53 int record = 1;
54 for (SortKey<Mdr6Record> key : sortKeys) {
55 Mdr6Record z = key.getObject();
56 addIndexPointer(z.getMapIndex(), record++);
57
58 putMapIndex(writer, z.getMapIndex());
59 writer.putNu(zipSize, z.getZipIndex());
60 if (hasString)
61 putStringOffset(writer, z.getStringOffset());
62 }
63 }
64
65 /**
66 * Enough bytes to represent the map number
67 * and the zip index and the string offset.
68 * @return The size of a record in this section.
69 */
70 public int getItemSize() {
71 PointerSizes sizes = getSizes();
72 int size = sizes.getMapSize() + sizes.getZipSize();
73 if (hasFlag(0x4))
74 size += sizes.getStrOffSize();
75 return size;
76 }
77
78 protected int numberOfItems() {
79 return zips.size();
80 }
81
82 /**
83 * Known structure:
84 * bits 0-1: size of local zip index - 1 (all values appear to work)
85 * bits 2: if MDR 15 available
86 * @return The value to be placed in the header.
87 */
88 public int getExtraValue() {
89 return ((getSizes().getZipSize()-1)&0x03) | (isForDevice() ? 0 : 0x04);
90 }
91 }