📄 rpfframe.java
字号:
// **********************************************************************// // <copyright>// // BBN Technologies// 10 Moulton Street// Cambridge, MA 02138// (617) 873-8000// // Copyright (C) BBNT Solutions LLC. All rights reserved.// // </copyright>// **********************************************************************// // $Source: /cvs/distapps/openmap/src/openmap/com/bbn/openmap/layer/rpf/RpfFrame.java,v $// $RCSfile: RpfFrame.java,v $// $Revision: 1.3.2.5 $// $Date: 2005/08/09 21:17:56 $// $Author: dietrick $// // **********************************************************************/* * Some of the ideas for this code is based on source code provided by * The MITRE Corporation, through the browse application source code. * Many thanks to Nancy Markuson who provided BBN with the software, * to Theron Tock, who wrote the software, and Daniel Scholten, who * revised it - (c) 1994 The MITRE Corporation for those parts, and * used/distributed with permission. Namely, the frame file reading * mechanism is the part that has been modified. */package com.bbn.openmap.layer.rpf;import java.awt.Color;import java.awt.Dimension;import java.awt.Graphics;import java.awt.GraphicsEnvironment;import java.awt.Toolkit;import java.awt.image.BufferedImage;import java.awt.image.MemoryImageSource;import java.io.FileNotFoundException;import java.io.IOException;import javax.swing.ImageIcon;import javax.swing.JFrame;import javax.swing.JLabel;import com.bbn.openmap.io.BinaryBufferedFile;import com.bbn.openmap.io.BinaryFile;import com.bbn.openmap.io.FormatException;import com.bbn.openmap.layer.nitf.NitfHeader;import com.bbn.openmap.omGraphics.OMRaster;import com.bbn.openmap.omGraphics.OMRasterObject;import com.bbn.openmap.util.Debug;/** * The object that organizes the information found within the RPF * frame file. The RpfFrame handles reading through the different * sections, and holds on to the compressed subframe data. The cache * handler gets the compressed subframe data and decompresses it * before storing the uncompressed subframe in the cache. */public class RpfFrame { boolean valid = false; protected NitfHeader nitfHeader; protected RpfHeader header; protected RpfFileSections fileSections; protected RpfAttributes attributes; protected RpfFileSections.RpfCoverageSection coverage; protected RpfColortable colortable; String report; byte[][][] compressedSubframe = new byte[6][6][]; byte[][][] table = new byte[4][4096][4]; /* DKS NEW for CHUMMED subfr info. [y][x] */ boolean[][] chummed = new boolean[6][6]; /* DKS NEW for masked subfr info: WAS EXTERNAL. */ boolean[][] masked = new boolean[6][6]; /** Want to bother with Dchum? */ boolean Dchum = false; int chumVersion; /* Chum version: 2,3,etc. */ int numCharsInDesc; // ushort, # chars in DCHUM descriptor string // */ int descCount; /* # descriptors */ /** Array of descriptor strings */ String[] descriptors; // char // desc_str[MAX_NUM_DESC][MAX_DESC_LEN]; /** Array of descriptor dates */ String[] descriptorDates; // char desc_date[MAX_NUM_DESC][9]; protected boolean DEBUG_RPFDETAIL = false; protected boolean DEBUG_RPFFRAME = false; /** Loads the RpfFrame, given a complete path to the file. */ public RpfFrame(String framePath) { DEBUG_RPFDETAIL = Debug.debugging("rpfdetail"); DEBUG_RPFFRAME = Debug.debugging("rpfframe"); initFile(framePath); } /** * Loads the RpfFrame, given the RpfFrameEntry that the * RpfCacheHandler got from the RpfTocHandler. */ public RpfFrame(RpfFrameEntry rfe) { this(rfe.framePath); if (!isValid() && rfe.exists && rfe.rpfdir != null) { // Check lower case, if we think it exists and the rpf dir // is not null. If it is null, then the path we tried is // a complete file path (not a relative one) and should be // right. String lowerCaseFramePath = rfe.directory + rfe.filename; lowerCaseFramePath = lowerCaseFramePath.toLowerCase(); if (DEBUG_RPFFRAME) { Debug.output("RpfFrame " + rfe.framePath + " not found, checking " + rfe.rpfdir + lowerCaseFramePath); } if (initFile(rfe.rpfdir + lowerCaseFramePath)) { // Update it for the next time we check rfe.framePath = rfe.rpfdir + lowerCaseFramePath; } else { // Update check so we don't keep looking again. rfe.exists = false; } } Dchum = true; chumVersion = Character.digit(rfe.filename.charAt(6), 10); } // public void finalize() { // Debug.message("gc", "RpfFrame: getting GC'd"); // } protected boolean initFile(String framePath) { try { BinaryFile binFile = new BinaryBufferedFile(framePath); read(binFile); binFile.close(); } catch (FileNotFoundException e) { Debug.error("RpfFrame: file " + framePath + " not found"); valid = false; } catch (IOException ioe) { Debug.error("RpfFrame: File IO Error while handling NITF header:\n" + ioe); valid = false; } catch (NullPointerException npe) { Debug.error("RpfFrame: File IO Error NPE:\n" + npe); npe.printStackTrace(); valid = false; } return valid; } public boolean isValid() { return valid; } /** * Create the screen text used on a subframe. The internal string * is set. * * @param Cib whether the frame is a Cib frame. The report is * different if it is. */ protected void setReport(boolean Cib) { if (attributes != null) { StringBuffer s = new StringBuffer(); s.append("\nRPF Currency Date: " + attributes.currencyDate); s.append("\nRPF Production Date: " + attributes.productionDate); s.append("\nSource Significant Date: " + attributes.significantDate); if (Cib) { s.append("\nMap Source: " + attributes.dataSource); } else { s.append("\nMap Designation: " + attributes.mapDesignationCode); s.append("\nMap Series: " + attributes.chartSeriesCode); s.append("\nMap Edition: " + attributes.edition); } report = s.toString(); } } /** * Get the attribute text to display on the screen. This goes to * the RpfSubframe object. The RpfCacheHandler knows about the * four variables. * * @param x subframe index within the array from the TocEntry. * @param y subframe index within the array from the TocEntry * @param entry the RpfFrameEntry describing the frame. * @param Cib whether the frame is an imagery frame. */ public String getReport(int x, int y, RpfFrameEntry entry, boolean Cib) { StringBuffer s = new StringBuffer(); x = x % 6; y = y % 6; s.append("Subframe " + x + ", " + y + "\n"); if (entry != null) { s.append("\nFrame Name: "); s.append(entry.filename); } else { s.append("\nFrame Name: Unavailable."); } if (report == null) setReport(Cib); // preset the attribute part of the info. if (report != null) s.append(report); s.append("\nFrom Frame Dir: "); String actualFilePath = entry.rpfdir + entry.directory; if (actualFilePath.length() > 20) { int start = 0; int index = actualFilePath.indexOf("/", 15); while (index != -1) { s.append(actualFilePath.substring(start, index)); s.append("/\n "); start = index + 1; index = actualFilePath.indexOf("/", start + 15); } s.append(actualFilePath.substring(start)); } else s.append(actualFilePath); return s.toString().trim(); } /** * Get the NitfFile header. */ public NitfHeader getNitfHeader() { return nitfHeader; } /** * Get the RpfFrame header. */ public RpfHeader getHeader() { return header; } /** * Get the different file sections. */ public RpfFileSections getFileSections() { return fileSections; } /** * Get the attributes for the RpfFrame. */ public RpfAttributes getAttributes() { return attributes; } /** * Get the coverage section. */ public RpfFileSections.RpfCoverageSection getCoverage() { return coverage; } /** * The only reason to call this is to read the colortable that is * within the frame file, and set the colors that you will be * using for all the frames accordingly. The RpfColortable is * passed in so you can set the opaqueness, number of colors, and * other colortable variables inside your own colortable object, * and then read the color conversion tables as they apply (inside * the frame file). Since the frame file is read when the RpfFrame * is created, the fileSections object will (should) be valid. */ public Color[] getColors(BinaryFile binFile, RpfColortable ct) { fileSections.parseColorSection(binFile, ct); return ct.colors; } /** * Load the colortable with the colors from a particular frame * file. Not needed, really, since the frame file is now loading * it's own colortable at loadtime. */ public static Color[] getColors(String framePath, RpfColortable ct) { BinaryFile binFile = null; try { binFile = new BinaryBufferedFile(framePath); // binFile = new BinaryFile(framePath); RpfFileSections rfs = new RpfFileSections(); RpfHeader head = new RpfHeader(); head.read(binFile); binFile.seek(head.locationSectionLocation); rfs.parse(binFile); Color[] ret = rfs.parseColorSection(binFile, ct); binFile.close(); return ret; } catch (FileNotFoundException e) { Debug.error("RpfFrame: getColortable(): file " + framePath + " not found"); } catch (IOException ioe) { Debug.error("RpfFrame: getColortable(); File IO Error!\n" + ioe); } return null; } /** * Get the colortable stored inside this RpfFrame. * * @return RpfColortable */ public RpfColortable getColortable() { return colortable; } /** Read the RPF frame. */ public boolean read(BinaryFile binFile) { Compression compression; LookupTable[] lookupTable = new LookupTable[4]; Image image; int[][] indices = new int[6][6]; //ushort int i, j; /* bool (uchar) */ /* all subframes present indicator */ boolean allSubframes; long currentPos; // uint long lookupOffsetTableOffset; // uint int lookupTableOffsetRecLen; //ushort long subframeMaskTableOffset; //uint /* subframe offset (mask section) */ long[][] subframeOffset = new long[6][6];//uint[][] /* for DCHUM */ long fsave; /* saved file loc */ int chummedSubframe; //uint int attributeId; // ushort int attributeParamId; //uchar long attributeRecOffset; //uint int numAttributeOffsetRecs; //ushort int numSubframesChummed; //ushort if (DEBUG_RPFDETAIL) { Debug.output("ENTER RPFFRAME.READ"); } try { // Let's start at the beginning, shall we?
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -