Debian Codegraph @

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

raw symbols SCIP
1 /*
2 * Copyright (C) 2009.
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 package uk.me.parabola.imgfmt.app.mdr;
14
15 import uk.me.parabola.imgfmt.app.ImgFileWriter;
16 import uk.me.parabola.imgfmt.app.Section;
17
18 /**
19 * A header for the map index, pointed to from MDR 1.
20 * There is one of these for each map.
21 *
22 * @author Steve Ratcliffe
23 */
24 public class Mdr1SubHeader {
25 // The number of subsections, this starts at 1. Larger numbers are possible
26 // for larger MDR header sizes.
27 private static final int MAX_SECTION = 9;
28
29 // Each sub header requires 8 bytes apart from sub2 which only needs 4.
30 private static final int HEADER_SIZE = 70;
31
32 private final Section[] sections = new Section[MAX_SECTION+1];
33
34 public Mdr1SubHeader() {
35 // Initialise the sections.
36 for (int n = 1; n <= MAX_SECTION; n++) {
37 Section prev = sections[n - 1];
38 sections[n] = new Section(prev);
39 }
40
41 sections[1].setPosition(HEADER_SIZE);
42 }
43
44 protected void writeFileHeader(ImgFileWriter writer) {
45 writer.put2u(HEADER_SIZE);
46 for (int n = 1; n <= MAX_SECTION; n++) {
47 Section section = sections[n];
48
49 // The second subsection does not have a length, because it always
50 // has the same length as subsection 1.
51 if (n == 2)
52 writer.put4(section.getPosition());
53 else {
54 writer.put4(section.getPosition());
55 writer.put4(section.getNumItems());
56 }
57 }
58 }
59
60 public void setEndSubsection(int sub, int pos) {
61 sections[sub].setSize(pos - sections[sub].getPosition());
62 }
63
64 public long getHeaderLen() {
65 return HEADER_SIZE;
66 }
67
68 public void setItemSize(int sectionNumber, int itemSize) {
69 sections[sectionNumber].setItemSize((char) itemSize);
70 }
71 }