📄 rpfframe.java
字号:
/* New, dks */ public int numOffsetRecs;//ushort public int numParmOffRecs;//ushort public Compression(BinaryFile binFile) { try { algorithm = (int) binFile.readShort(); numOffsetRecs = (int) binFile.readShort(); numParmOffRecs = (int) binFile.readShort(); } catch (IOException e) { Debug.error("Compression: File IO Error!\n" + e); } catch (FormatException f) { Debug.error("Compression: File IO Format error!\n" + f); } } public String toString() { StringBuffer s = new StringBuffer(); s.append("Compression.algorithm: " + algorithm + "\n"); s.append("Compression.numOffsetRecs: " + numOffsetRecs + "\n"); s.append("Compression.numParmOffRecs: " + numParmOffRecs + "\n"); return s.toString(); } } static public class LookupTable { int id; //ushort long records; //uint int values; //ushort int bitLength; //ushort long offset; // uint public LookupTable(BinaryFile binFile) { try { id = (int) binFile.readShort(); records = (long) binFile.readInteger(); values = (int) binFile.readShort(); bitLength = (int) binFile.readShort(); offset = (long) binFile.readInteger(); } catch (IOException e) { Debug.error("Compression: File IO Error!\n" + e); } catch (FormatException f) { Debug.error("Compression: File IO Format error!\n" + f); } } public String toString() { StringBuffer s = new StringBuffer(); s.append("LookupTable.id: " + id + "\n"); s.append("LookupTable.records: " + records + "\n"); s.append("LookupTable.values: " + values + "\n"); s.append("LookupTable.bitLength: " + bitLength + "\n"); s.append("LookupTable.offset: " + offset + "\n"); return s.toString(); } } static public class Image { int spectralGroups; //ushort int subframeTables;//ushort int spectralTables;//ushort int spectralLines;//ushort int horizSubframes, vertSubframes;//ushort long outputColumns, outputRows;//uint public Image(BinaryFile binFile) { try { spectralGroups = (int) binFile.readShort(); subframeTables = (int) binFile.readShort(); spectralTables = (int) binFile.readShort(); spectralLines = (int) binFile.readShort(); horizSubframes = (int) binFile.readShort(); vertSubframes = (int) binFile.readShort(); outputColumns = (long) binFile.readInteger(); outputRows = (long) binFile.readInteger(); } catch (IOException e) { Debug.error("Compression: File IO Error!\n" + e); } catch (FormatException f) { Debug.error("Compression: File IO Format error!\n" + f); } } public String toString() { StringBuffer s = new StringBuffer(); s.append("Image.spectralGroups: " + spectralGroups + "\n"); s.append("Image.subframeTables: " + subframeTables + "\n"); s.append("Image.spectralTables: " + spectralTables + "\n"); s.append("Image.spectralLines: " + spectralLines + "\n"); s.append("Image.horizSubframes: " + horizSubframes + "\n"); s.append("Image.vertSubframes: " + vertSubframes + "\n"); s.append("Image.outputColumns: " + outputColumns + "\n"); s.append("Image.outputRows: " + outputRows + "\n"); return s.toString(); } } /** * Decompress a subframe into a cache entry OMRaster * (RpfSubframe). The RpfSubframe is returned, too, to emphasize * what's happening. * * @param x the x coord for the subframe * @param y the y coord for the subframe * @param subframe the subframe to create the image for. The * resulting image will be loaded into the RpfSubframe. If * null, a new RpfSubframe will be created. * @param colortable the colortable to use with this image. If * null, the colortable from this RpfFrame will be used. * @param viewAttributes our image generation parameters. * @return RpfSubframe containing the image data. */ public RpfSubframe decompressSubframe(int x, int y, RpfSubframe subframe, RpfColortable colortable, RpfViewAttributes viewAttributes) { boolean isDirectColorModel = (viewAttributes.colorModel == OMRasterObject.COLORMODEL_DIRECT); if (subframe == null) { subframe = new RpfSubframe(); } if (viewAttributes != null) { subframe.setColorModel(viewAttributes.colorModel); } if (colortable == null) { colortable = this.colortable; } if (!isDirectColorModel) { if (DEBUG_RPFDETAIL) { Debug.output("RpfFrame: decompress to byte[]"); } byte[] pixels = decompressSubframe(x, y); OMRaster image = subframe.image; image.setBits(pixels); image.setColors(colortable.colors); } else { int[] pixels = decompressSubframe(x, y, colortable); OMRaster image = subframe.image; image.setPixels(pixels); } return subframe; } /** * Decompress a subframe into an array of bytes suitable for in * indexed color model image. * * @param x the x coord for the subframe * @param y the y coord for the subframe */ public byte[] decompressSubframe(int x, int y) { // Convert x,y to the subframe index in the frame - they come // in as // cache subframe indexes x = x % 6; y = y % 6; // used to keep track of location into compressedSubframe // array. int readptr = 0; // and the compressedSubframe array byte[] compressedSubframe = this.compressedSubframe[y][x]; /* * This should never occur since all subframes should be * present */ /* * But if it does occur, just put up black pixels on the * screen */ if ((compressedSubframe == null) || masked[y][x]) { return null; } else { // Normal pixel */ byte[] pixels = new byte[256 * 256]; for (int i = 0; i < 256; i += 4) { for (int j = 0; j < 256; j += 8) { int firstByte = compressedSubframe[readptr++] & 0xff; int secondByte = compressedSubframe[readptr++] & 0xff; int thirdByte = compressedSubframe[readptr++] & 0xff; //because dealing with half-bytes is hard, we //uncompress two 4x4 tiles at the same time. (a //4x4 tile compressed is 12 bits ) /* Get first 12-bit value as index into VQ table */ int val1 = (firstByte << 4) | (secondByte >> 4); /* Get second 12-bit value as index into VQ table */ int val2 = ((secondByte & 0x000F) << 8) | thirdByte; for (int t = 0; t < 4; t++) { for (int e = 0; e < 4; e++) { int tableVal1 = table[t][val1][e] & 0xff; int tableVal2 = table[t][val2][e] & 0xff; if (tableVal1 >= RpfColortable.CADRG_COLORS) { tableVal1 = RpfColortable.CADRG_COLORS - 1; } if (tableVal2 >= RpfColortable.CADRG_COLORS) { tableVal2 = RpfColortable.CADRG_COLORS - 1; } int pixindex = (i + t) * 256 + j + e; pixels[pixindex] = (byte) tableVal1; pixels[pixindex + 4] = (byte) tableVal2; } //for e } //for t } /* for j */ } //for i return pixels; } /* else */ } /** * Decompress a subframe into an array of ints suitable for a * direct color model image. (argb format) * * @param x the x coord for the subframe * @param y the y coord for the subframe * @param colortable the colortable to use with this image. If * null, the RpfColortable from the frame will be used. */ public int[] decompressSubframe(int x, int y, RpfColortable colortable) { // Convert x,y to the subframe index in the frame - they come // in as // cache subframe indexes x = x % 6; y = y % 6; // used to keep track of location into compressedSubframe // array. int readptr = 0; // and the compressedSubframe array byte[] compressedSubframe = this.compressedSubframe[y][x]; if (colortable == null) { colortable = this.colortable; } /* * This should never occur since all subframes should be * present */ /* * But if it does occur, just put up black pixels on the * screen */ if ((compressedSubframe == null) || masked[y][x]) { return null; } else { // Normal pixel */ int[] pixels = new int[256 * 256]; for (int i = 0; i < 256; i += 4) { for (int j = 0; j < 256; j += 8) { int firstByte = compressedSubframe[readptr++] & 0xff; int secondByte = compressedSubframe[readptr++] & 0xff; int thirdByte = compressedSubframe[readptr++] & 0xff; //because dealing with half-bytes is hard, we //uncompress two 4x4 tiles at the same time. (a //4x4 tile compressed is 12 bits ) /* Get first 12-bit value as index into VQ table */ int val1 = (firstByte << 4) | (secondByte >> 4); /* Get second 12-bit value as index into VQ table */ int val2 = ((secondByte & 0x000F) << 8) | thirdByte; for (int t = 0; t < 4; t++) { for (int e = 0; e < 4; e++) { int tableVal1 = table[t][val1][e] & 0xff; int tableVal2 = table[t][val2][e] & 0xff; if (tableVal1 >= RpfColortable.CADRG_COLORS) { tableVal1 = RpfColortable.CADRG_COLORS - 1; } if (tableVal2 >= RpfColortable.CADRG_COLORS) { tableVal2 = RpfColortable.CADRG_COLORS - 1; } int pixindex = (i + t) * 256 + j + e; pixels[pixindex] = colortable.colors[tableVal1].getRGB(); pixels[pixindex + 4] = colortable.colors[tableVal2].getRGB(); } //for e } //for t } /* for j */ } //for i return pixels; } /* else */ } public static void main(String[] argv) { Debug.init(); com.bbn.openmap.util.ArgParser ap = new com.bbn.openmap.util.ArgParser("RpfFrame"); ap.add("attributes", "Only write out the attributes for this frame."); ap.add("view", "Only bring up a window with the frame image."); ap.add("frame", "Path to the frame to view. \"-frame\" only needed if other arguments are used.", 1); if (!ap.parse(argv)) { ap.printUsage(); System.exit(0); } String arg[]; boolean viewAttributes = false; arg = ap.getArgValues("attributes"); if (arg != null) { viewAttributes = true; Debug.put("rpfframe"); Debug.put("rpfdetail"); } boolean viewFrame = false; arg = ap.getArgValues("view"); if (arg != null) { viewFrame = true; } RpfFrame rpfFrame; arg = ap.getArgValues("frame"); if (arg != null) { rpfFrame = new RpfFrame(arg[0]); if (viewFrame) { rpfFrame.view(); } } else { if (viewAttributes == false) { Debug.put("rpfframe"); Debug.put("rpfdetail"); } rpfFrame = new RpfFrame(argv[0]); rpfFrame.view(); } } /** * A quick hack to pop up a window that displays the entire frame * image. */ public void view() { int height = 256; int width = 256; BufferedImage bigImage = new BufferedImage(width * 6, height * 6, BufferedImage.TYPE_INT_RGB); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); Graphics g = ge.createGraphics(bigImage); Toolkit tk = Toolkit.getDefaultToolkit(); for (int x = 0; x < 6; x++) { for (int y = 0; y < 6; y++) { int[] pixels = decompressSubframe(x, y, colortable); java.awt.Image bitmap = tk.createImage(new MemoryImageSource(width, height, pixels, 0, width)); g.drawImage(bitmap, x * 256, y * 256, null); } } JLabel picture = new JLabel(new ImageIcon(bigImage)); JFrame frame = com.bbn.openmap.util.PaletteHelper.getPaletteWindow(picture, "RPF Frame", null); frame.setSize(new Dimension(500, 500)); frame.show(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -