📄 rpfframecachehandler.java
字号:
// scale, and then considering // coverage. // NOTE: // Changed < to <=, because < // gives // higher priority to whatever is // first in the // list. I.e. if 2 boxes had the // same // scale difference but the second // one actually // had better coverage, it would // have gotten // discarded. if (scaleDifference(proj, currentCoverage) <= scaleDifference(proj, rcb) && currentCoverage.percentCoverage >= rcb.percentCoverage) { coverageBoxes.addElement(currentCoverage); addedCurrent = true; if (currentCoverage.scale == rcb.scale) { coverageBoxes.addElement(rcb); } else { // if these scales don't // match, none of the // subsequent rcbs will // either. We're done. break; } } else { // rcb percent coverage // is better coverageBoxes.addElement(rcb); } } else { // j!= 0 if (currentCoverage.percentCoverage >= rcb.percentCoverage) { if (((RpfCoverageBox) coverageBoxes.get(0)).scale == currentCoverage.scale) { coverageBoxes.add(currentCoverage); addedCurrent = true; } else { okToAddCurrent = false; } coverageBoxes.add(rcb); } else { // rcb percent coverage // is better // we already know that scale // matches since it was // added previously coverageBoxes.add(rcb); } } } else { // currentCoverage already added; // all we need to do is add current // rcb if scale matches if (((RpfCoverageBox) coverageBoxes.get(0)).scale == rcb.scale) { coverageBoxes.add(rcb); } else { } } } // Add current if not added already and if // scale matches. // It's possible that we performed this check // already -- // i.e. if currentCoverage had better % // coverage // than someone else but wasn't added because // of the scale. // If that happened, then okToAddCurrent is // false. if (!addedCurrent && okToAddCurrent) { if (((RpfCoverageBox) coverageBoxes.get(0)).scale == currentCoverage.scale) { coverageBoxes.add(currentCoverage); } else { } } } // } } else { if (Debug.debugging("rpftoc")) { System.out.println("RFCH: Toc " + i + " did NOT return an entry"); } } } } return coverageBoxes; } /** * Given the indexes to a certain RpfTocEntry within a certain A.TOC, find * the frame and return the attribute information. The tocNumber and * entryNumber are given within the RpfCoverageBox received from a * getCoverage call. * * @param tocNumber the toc id for a RpfTocHandler for a particular frame * provider. * @param entryNumber the RpfTocEntry id for a RpfTocHandler for a * particular frame provider. * @param x the horizontal subframe index, from the left side of a boundary * rectangle of the entry. * @param y the vertical subframe index, from the top side of a boundary * rectangle of the entry. * @see #getCoverage * @return string. */ public String getSubframeAttributes(int tocNumber, int entryNumber, int x, int y) { if (!tocs[tocNumber].isValid()) return null; RpfTocEntry entry = tocs[tocNumber].entries[entryNumber]; /* If beyond the image boundary, forget it */ if (y < 0 || x < 0 || entry == null || y >= entry.vertFrames * 6 || x >= entry.horizFrames * 6) { return null; } RpfFrameEntry frameEntry = entry.frames[y / 6][x / 6]; /* Get the right frame from the frame cache */ RpfFrame frame = (RpfFrame) get(frameEntry); if (frame == null) return null; /* * This should never fail, since all subframes should be present */ return frame.getReport(x, y, frameEntry, entry.Cib); } /** * Given the indexes to a certain RpfTocEntry within a certain A.TOC, find * the frame/subframe data, decompress it, and return image pixels. The * tocNumber and entryNumber are given within the RpfCoverageBox received * from a getCoverage call. * * @param tocNumber the toc id for a RpfTocHandler for a particular frame * provider. * @param entryNumber the RpfTocEntry id for a RpfTocHandler for a * particular frame provider. * @param x the horizontal subframe index, from the left side of a boundary * rectangle of the entry. * @param y the vertical subframe index, from the top side of a boundary * rectangle of the entry. * @see #getCoverage * @return integer pixel data. */ public int[] getSubframeData(int tocNumber, int entryNumber, int x, int y) { if (!tocs[tocNumber].isValid()) { return null; } RpfTocEntry entry = tocs[tocNumber].entries[entryNumber]; /* If beyond the image boundary, forget it */ if (y < 0 || x < 0 || entry == null || y >= entry.vertFrames * 6 || x >= entry.horizFrames * 6) { return null; } RpfFrameEntry frameEntry = entry.frames[y / 6][x / 6]; /* Get the right frame from the frame cache */ RpfFrame frame = (RpfFrame) get(frameEntry); if (frame == null) { return null; } checkColortable(frame, frameEntry, entry, tocNumber, entryNumber); /* * This should never fail, since all subframes should be present */ return frame.decompressSubframe(x, y, colortable); } public RpfIndexedImageData getRawSubframeData(int tocNumber, int entryNumber, int x, int y) { if (!tocs[tocNumber].isValid()) { return null; } RpfTocEntry entry = tocs[tocNumber].entries[entryNumber]; /* If beyond the image boundary, forget it */ if (y < 0 || x < 0 || entry == null || y >= entry.vertFrames * 6 || x >= entry.horizFrames * 6) { return null; } RpfFrameEntry frameEntry = entry.frames[y / 6][x / 6]; /* Get the right frame from the frame cache */ RpfFrame frame = (RpfFrame) get(frameEntry); if (frame == null) return null; checkColortable(frame, frameEntry, entry, tocNumber, entryNumber); RpfIndexedImageData riid = new RpfIndexedImageData(); riid.imageData = frame.decompressSubframe(x, y); riid.colortable = colortable.colors; return riid; } /** * Take a bunch of stuff that has already been calculated, and then figure * out if a new colortable is needed. If it is, load it up with info. Called * from two different places, which is why it exists. * * It's been determined that, for each subframe, the colortable from it's * parent frame should be used. Although RPF was designed and specified that * the colortable should be constant across zones, that's not always the * case. */ protected void checkColortable(RpfFrame frame, RpfFrameEntry frameEntry, RpfTocEntry entry, int tocNumber, int entryNumber) { // Colortables are constant across chart types and zones. If // the current chart type and zone don't match the colortable, // read the proper one from the frame. All the frames inside // an entry, which is a boundary box, will certainly share a // colortable. // if (colortable.colors == null || // !colortable.isSameATOCIndexes(tocNumber, entryNumber)) { // You know, we don't need to make the check - we should just // do this every time - the colortable is already created for // the frame, so we might as well use what we know to be good // for each subframe. if (true) { if (Debug.debugging("rpf")) { Debug.output("RpfFrameCacheHandler: getting new colors"); Debug.output("RpfFrameCacheHandler: getting CIB colors = " + entry.Cib); } colortable.setCib(entry.Cib); colortable.setATOCIndexes(tocNumber, entryNumber); // Seems like there ought to be a better way to do this, as this // kills the colortable settings read in from the properties file // and replaces them with the defaults created from the RpfFrames // colortable creation. You loose numberColors, for instance. colortable = frame.getColortable(); colortable.zone = entry.zone; colortable.seriesCode = entry.info.seriesCode; } if (viewAttributes != null) { // this is useless... // colortable.setNumColors(viewAttributes.numberOfColors); colortable.setOpaqueness(viewAttributes.opaqueness); } } /** * Set up the A.TOC files, to find out what coverage there is. * * @param RpfPaths the paths to the RPF directories. * @return the RpfTocHandlers for the A.TOCs. */ public static RpfTocHandler[] createTocHandlers(String[] RpfPaths) { RpfTocHandler[] tocs = new RpfTocHandler[(RpfPaths != null ? RpfPaths.length : 0)]; for (int i = 0; i < tocs.length; i++) { tocs[i] = new RpfTocHandler(RpfPaths[i], i); } return tocs; } /** Cachehandler method. */ public CacheObject load(String RpfFramePath) { RpfFrame frame = new RpfFrame(RpfFramePath); if (frame.isValid()) { CacheObject obj = new CacheObject(RpfFramePath, frame); return obj; } return null; } /** * A customized way to retrieve a frame from the cache, using a * RpfFrameEntry. A RpfFrameEntry is the way to get the Dchum capability * kicked off in the frame. If you don't care about Dchum, use the other get * method. CacheHandler method. */ public Object get(RpfFrameEntry rfe) { CacheObject ret = searchCache(rfe.framePath); if (ret != null) return ret.obj; ret = load(rfe); if (ret == null) return null; if (Debug.debugging("rpfdetail")) { System.out.println(rfe); } replaceLeastUsed(ret); return ret.obj; } /** Cachehandler method. */ public CacheObject load(RpfFrameEntry rfe) { if (!rfe.exists) { if (Debug.debugging("rpf")) { System.out.println("RpfFrameCacheHandler: Frame doesn't exist!: " + rfe.framePath); } return null; } if (Debug.debugging("rpf")) { Debug.output("RpfFrameCacheHandler: Loading Frame " + rfe.framePath); } RpfFrame frame = new RpfFrame(rfe); if (frame.isValid()) { CacheObject obj = new CacheObject(rfe.framePath, frame); return obj; } else { if (Debug.debugging("rpf")) { Debug.error("RpfFrameCacheHandler: Couldn't find frame /" + rfe.framePath + "/ (" + rfe.framePath.length() + " chars)"); } rfe.exists = false; } return null; } /** * Cachehandler method. */ public void resizeCache(int max_size) { resetCache(max_size); } /** * CacheHandler method. Need to clear memory, get gc moving, and ready for * new objects */ public void resetCache() { super.resetCache(); Debug.message("rpf", "RpfFrameCacheHandler: reset frame cache."); } public static float scaleDifference(CADRG proj, RpfCoverageBox box) { return (float) (Math.abs(proj.getScale() - box.scale)); } public RpfColortable getColortable() { return colortable; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -