Updated to worldwind release 20070817
[worldwind-tracker.git] / gov / nasa / worldwind / formats / rpf / RpfFrameFileComponents.java
blobc9df4bb6ff536b4b1544e46ba36436bd62786a86
1 package gov.nasa.worldwind.formats.rpf;
3 import gov.nasa.worldwind.formats.nitfs.*;
4 import gov.nasa.worldwind.geom.*;
6 import java.nio.*;
7 /*
8 Copyright (C) 2001, 2007 United States Government
9 as represented by the Administrator of the
10 National Aeronautics and Space Administration.
11 All Rights Reserved.
14 /**
15 * @author lado
16 * @version $Id: RpfFrameFileComponents Mar 31, 2007 10:06:22 PM
18 public class RpfFrameFileComponents
20 public static final String DATA_TAG = "RPFIMG";
22 // [ rpf location section ]
23 public RpfLocationSection componentLocationTable;
25 // [ rpf coverage section ]
26 public LatLon nwUpperLeft, swLowerleft, neUpperRight, seLowerRight;
27 public double verticalResolutionNorthSouth;
28 public double horizontalResolutionEastWest;
29 public double verticalIntervalLatitude;
30 public double horizontalIntervalLongitude;
32 // [ color / grayscale section ]
33 public RpfColorMap[] rpfColorMaps;
35 // [ rpf color / grayscale section ]
36 public short numOfColorGrayscaleOffsetRecords;
37 public short numOfColorConverterOffsetRecords;
38 public String externalColorGrayscaleFilename;
39 // [ rpf colormap subsection ]
40 public long colormapOffsetTableOffset;
41 public int colormapGrayscaleOffsetRecordLength;
43 // [ rpf color converter subsection ]
45 // [ rpf image description subheader ]
46 public int numOfSpectralGroups;
47 public int numOfSubframeTables;
48 public int numOfSpectralBandTables;
49 public int numOfSpectralBandLinesPerImageRow;
50 public int numOfSubframesInEastWestDirection;
51 public int numOfSubframesInNorthSouthDirection;
52 public long numOfOutputColumnsPerSubframe;
53 public long numOfOutputRowsPerSubframe;
54 public long subframeMaskTableOffset;
55 public long transparencyMaskTableOffset;
57 // [ rpf related images section ]
58 public RelatedImagesSection relatedImagesSection = null;
60 public RpfFrameFileComponents(java.nio.ByteBuffer buffer)
62 this.componentLocationTable = new RpfLocationSection(buffer);
64 if (0 < this.componentLocationTable.getCoverageSectionSubheaderLength())
65 this.parseRpfCoverageSection(buffer);
67 if (0 < this.componentLocationTable.getColorGrayscaleSectionSubheaderLength())
68 this.parseColorGrayscaleSection(buffer);
70 if (0 < this.componentLocationTable.getColormapSubsectionLength())
71 this.parseColormapSubSection(buffer);
73 if (0 < this.componentLocationTable.getColorConverterSubsectionLength())
74 this.parseColorConverterSubsection(buffer);
76 if (0 < this.componentLocationTable.getImageDescriptionSubheaderLength())
78 buffer.position(this.componentLocationTable.getImageDescriptionSubheaderLocation());
79 this.parseImageDescriptionSubheader(buffer);
81 if (0 < this.componentLocationTable.getRelatedImagesSectionSubheaderLength())
83 buffer.position(this.componentLocationTable.getRelatedImagesSectionSubheaderLocation());
84 this.relatedImagesSection = new RelatedImagesSection(buffer);
88 private void parseImageDescriptionSubheader(java.nio.ByteBuffer buffer)
90 this.numOfSpectralGroups = NitfsUtil.getUShort(buffer);
91 this.numOfSubframeTables = NitfsUtil.getUShort(buffer);
92 this.numOfSpectralBandTables = NitfsUtil.getUShort(buffer);
93 this.numOfSpectralBandLinesPerImageRow = NitfsUtil.getUShort(buffer);
94 this.numOfSubframesInEastWestDirection = NitfsUtil.getUShort(buffer);
95 this.numOfSubframesInNorthSouthDirection = NitfsUtil.getUShort(buffer);
96 this.numOfOutputColumnsPerSubframe = NitfsUtil.getUInt(buffer);
97 this.numOfOutputRowsPerSubframe = NitfsUtil.getUInt(buffer);
98 this.subframeMaskTableOffset = NitfsUtil.getUInt(buffer);
99 this.transparencyMaskTableOffset = NitfsUtil.getUInt(buffer);
102 private void parseColorConverterSubsection(java.nio.ByteBuffer buffer)
104 buffer.position(this.componentLocationTable.getColorConverterSubsectionLocation());
105 // if (0 < this.numOfColorConverterOffsetRecords)
106 // throw new NitfsRuntimeException("NitfsReader.NotImplemented.ColorConvertorSubsectionReader");
109 private void parseColormapSubSection(java.nio.ByteBuffer buffer)
111 buffer.position(this.componentLocationTable.getColormapSubsectionLocation());
113 this.colormapOffsetTableOffset = NitfsUtil.getUInt(buffer);
114 this.colormapGrayscaleOffsetRecordLength = NitfsUtil.getUShort(buffer);
115 // read color / grayscale AND histogram records; builds a ColorMap (LUT)
116 if (0 < this.numOfColorGrayscaleOffsetRecords)
118 rpfColorMaps = new RpfColorMap[this.numOfColorGrayscaleOffsetRecords];
119 for (int i = 0; i < this.numOfColorGrayscaleOffsetRecords; i++)
121 rpfColorMaps[i] = new RpfColorMap(buffer, this.componentLocationTable.getColormapSubsectionLocation());
124 else
125 throw new NitfsRuntimeException("NitfsReader.InvalidNumberOfRpfColorGrayscaleRecords");
128 private void parseColorGrayscaleSection(java.nio.ByteBuffer buffer)
130 buffer.position(this.componentLocationTable.getColorGrayscaleSectionSubheaderLocation());
132 this.numOfColorGrayscaleOffsetRecords = NitfsUtil.getByteAsShort(buffer);
133 this.numOfColorConverterOffsetRecords = NitfsUtil.getByteAsShort(buffer);
134 this.externalColorGrayscaleFilename = NitfsUtil.getString(buffer, 12);
137 private void parseRpfCoverageSection(java.nio.ByteBuffer buffer)
139 buffer.position(this.componentLocationTable.getCoverageSectionSubheaderLocation());
141 this.nwUpperLeft = LatLon.fromDegrees(buffer.getDouble(), buffer.getDouble());
142 this.swLowerleft = LatLon.fromDegrees(buffer.getDouble(), buffer.getDouble());
143 this.neUpperRight = LatLon.fromDegrees(buffer.getDouble(), buffer.getDouble());
144 this.seLowerRight = LatLon.fromDegrees(buffer.getDouble(), buffer.getDouble());
146 this.verticalResolutionNorthSouth = buffer.getDouble();
147 this.horizontalResolutionEastWest = buffer.getDouble();
148 this.verticalIntervalLatitude = buffer.getDouble();
149 this.horizontalIntervalLongitude = buffer.getDouble();
152 public class RelatedImagesSection
154 // [ rpf related images section subheader ]
155 public long relatedImageDescriptionTableOffset;
156 public int numOfRelatedImageDescriptionRecords;
157 public int relatedImageDescriptionRecordLength;
159 public RelatedImagesSection(java.nio.ByteBuffer buffer)
161 this.relatedImageDescriptionTableOffset = NitfsUtil.getUInt(buffer);
162 this.numOfRelatedImageDescriptionRecords = NitfsUtil.getUShort(buffer);
163 this.relatedImageDescriptionRecordLength = NitfsUtil.getUShort(buffer);