Rev 531 |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
/*
* Copyright (C) 2011.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*/
package test.display.check;
import test.display.Section;
import uk.me.parabola.imgfmt.app.ImgFileReader;
import static test.display.check.Log.error;
/**
* @author Steve Ratcliffe
*/
public class SubsectionList {
//private List<Subsection> subSections = new ArrayList<Subsection>();
private Subsection[][] subsections;
private int[] sizes = new int[10];
private int[] maxNumbers = new int[10];
private final int numberOfMaps;
public SubsectionList(int numberOfMaps) {
this.numberOfMaps = numberOfMaps;
subsections = new Subsection[numberOfMaps+1][];
}
public void read(ImgFileReader reader, int map, int offset) {
reader.position(offset);
int headLen = reader.get2u();
// sect 2 does not have a length
int nsect = 3 + (headLen - 12) / 8;
Subsection[] subsection = new Subsection[nsect+1];
subsections[map] = subsection;
for (int n = 1; n <= nsect; n++) {
Subsection sub = new Subsection();
sub.setStart(offset);
subsection[n] = sub;
sub.setOffset(reader.get4());
if (n != 2)
sub.setLength(reader.get4());
}
subsection[2].setLength(subsection[1].getLength());
}
public int totalForSection(int n) {
int total = 0;
for (int m = 1; m <= numberOfMaps; m++) {
total += subsections[m][n].getLength();
}
return total;
}
public void setMax(int s, int expected) {
maxNumbers[s] = expected;
sizes[s] = Section.numberOfBytes(expected);
}
public int getOffset(int m, int s) {
return subsections[m][s].getOffset();
}
public int getLength(int m, int s) {
return subsections[m][s].getLength();
}
public int getSize(int ss) {
return sizes[ss];
}
public void checkValue(int m, int ss, int val) {
int maxNumber = maxNumbers[ss];
if (val > maxNumber) {
error("mdr1 map%d sub%d value too large %d, max %d",
m, ss, val, maxNumber);
}
}
public int getMax(int ss) {
return maxNumbers[ss];
}
}