/** * The Paeth predictor routine used in PNG encoding. This routine * is included as a convenience to subclasses that override the * <code>filterRow</code> method. */ public static final int paethPredictor(int a, int b, int c) { int p = a + b - c; int pa = abs(p - a); int pb = abs(p - b); int pc = abs(p - c); if ((pa <= pb) && (pa <= pc)) { return a; } else if (pb <= pc) { return b; } else { return c; } }
private void writeCHRM() throws IOException { if (param.isChromaticitySet() || param.isSRGBIntentSet()) { ChunkStream cs = new ChunkStream("cHRM"); float[] chroma; if (!param.isSRGBIntentSet()) { chroma = param.getChromaticity(); } else { chroma = srgbChroma; // SRGB chromaticities } for (int i = 0; i < 8; i++) { cs.writeInt((int) (chroma[i] * 100000)); } cs.writeToStream(dataOutput); cs.close(); } }
private void writeGAMA() throws IOException { if (param.isGammaSet() || param.isSRGBIntentSet()) { ChunkStream cs = new ChunkStream("gAMA"); float gamma; if (!param.isSRGBIntentSet()) { gamma = param.getGamma(); } else { gamma = 1.0F / 2.2F; // SRGB gamma } // TD should include the .5 but causes regard to say // everything is different. cs.writeInt((int) (gamma * 100000/*+0.5*/)); cs.writeToStream(dataOutput); cs.close(); } }
/** * Remove all private chunks associated with this parameter instance * whose 'safe-to-copy' bit is not set. This may be advisable when * transcoding PNG images. */ public synchronized void removeUnsafeToCopyPrivateChunks() { List<String> newChunkType = new ArrayList<String>(); List<byte[]> newChunkData = new ArrayList<byte[]>(); int len = getNumPrivateChunks(); for (int i = 0; i < len; i++) { String type = getPrivateChunkType(i); char lastChar = type.charAt(3); if (lastChar >= 'a' && lastChar <= 'z') { newChunkType.add(type); newChunkData.add(getPrivateChunkData(i)); } } chunkType = newChunkType; chunkData = newChunkData; }
private void writeICCP() throws IOException { if (param.isICCProfileDataSet()) { ChunkStream cs = new ChunkStream("iCCP"); byte[] ICCProfileData = param.getICCProfileData(); cs.write(ICCProfileData); cs.writeToStream(dataOutput); cs.close(); } }
private void writeZTXT() throws IOException { if (param.isCompressedTextSet()) { String[] text = param.getCompressedText(); for (int i = 0; i < text.length / 2; i++) { byte[] keyword = text[2 * i].getBytes(); byte[] value = text[2 * i + 1].getBytes(); ChunkStream cs = new ChunkStream("zTXt"); cs.write(keyword, 0, Math.min(keyword.length, 79)); cs.write(0); cs.write(0); DeflaterOutputStream dos = new DeflaterOutputStream(cs, new Deflater(Deflater.BEST_COMPRESSION, true)); dos.write(value); dos.finish(); cs.writeToStream(dataOutput); cs.close(); } } }
private void writeTIME() throws IOException { if (param.isModificationTimeSet()) { ChunkStream cs = new ChunkStream("tIME"); Date date = param.getModificationTime(); TimeZone gmt = TimeZone.getTimeZone("GMT"); GregorianCalendar cal = new GregorianCalendar(gmt); cal.setTime(date); int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH); int day = cal.get(Calendar.DAY_OF_MONTH); int hour = cal.get(Calendar.HOUR_OF_DAY); int minute = cal.get(Calendar.MINUTE); int second = cal.get(Calendar.SECOND); cs.writeShort(year); cs.writeByte(month + 1); cs.writeByte(day); cs.writeByte(hour); cs.writeByte(minute); cs.writeByte(second); cs.writeToStream(dataOutput); cs.close(); } }
/** * Saves XML+PNG format. * @param frame */ protected void saveXmlPng(TrackSchemeFrame frame, String filename, Color bg) throws IOException { final mxGraphComponent graphComponent = trackScheme.getGUI().graphComponent; final mxGraph graph = trackScheme.getGraph(); // Creates the image for the PNG file BufferedImage image = mxCellRenderer.createBufferedImage(graph, null, 1, bg, graphComponent.isAntiAlias(), null, graphComponent.getCanvas()); // Creates the URL-encoded XML data mxCodec codec = new mxCodec(); String xml = URLEncoder.encode(mxXmlUtils.getXml(codec.encode(graph.getModel())), "UTF-8"); mxPngEncodeParam param = mxPngEncodeParam.getDefaultEncodeParam(image); param.setCompressedText(new String[] { "mxGraphModel", xml }); // Saves as a PNG file try (FileOutputStream outputStream = new FileOutputStream( new File( filename ) )) { mxPngImageEncoder encoder = new mxPngImageEncoder( outputStream, param ); if ( image != null ) encoder.encode( image ); else JOptionPane.showMessageDialog( graphComponent, "No Image Data" ); } }
if (param.isTransparencySet()) if (param.isTransparencySet()) interlace = param.getInterlacing();
mxPngEncodeParam param = mxPngEncodeParam.getDefaultEncodeParam(image);
int filterType = param.filterRow(currRow, prevRow, filteredRows, bytesPerRow, bpp);
/** * Remove all private chunks associated with this parameter instance * whose 'safe-to-copy' bit is not set. This may be advisable when * transcoding PNG images. */ public synchronized void removeUnsafeToCopyPrivateChunks() { List<String> newChunkType = new ArrayList<String>(); List<byte[]> newChunkData = new ArrayList<byte[]>(); int len = getNumPrivateChunks(); for (int i = 0; i < len; i++) { String type = getPrivateChunkType(i); char lastChar = type.charAt(3); if (lastChar >= 'a' && lastChar <= 'z') { newChunkType.add(type); newChunkData.add(getPrivateChunkData(i)); } } chunkType = newChunkType; chunkData = newChunkData; }
private void writeICCP() throws IOException { if (param.isICCProfileDataSet()) { ChunkStream cs = new ChunkStream("iCCP"); byte[] ICCProfileData = param.getICCProfileData(); cs.write(ICCProfileData); cs.writeToStream(dataOutput); cs.close(); } }
private void writeZTXT() throws IOException { if (param.isCompressedTextSet()) { String[] text = param.getCompressedText(); for (int i = 0; i < text.length / 2; i++) { byte[] keyword = text[2 * i].getBytes(); byte[] value = text[2 * i + 1].getBytes(); ChunkStream cs = new ChunkStream("zTXt"); cs.write(keyword, 0, Math.min(keyword.length, 79)); cs.write(0); cs.write(0); DeflaterOutputStream dos = new DeflaterOutputStream(cs, new Deflater(Deflater.BEST_COMPRESSION, true)); dos.write(value); dos.finish(); cs.writeToStream(dataOutput); cs.close(); } } }
private void writeTIME() throws IOException { if (param.isModificationTimeSet()) { ChunkStream cs = new ChunkStream("tIME"); Date date = param.getModificationTime(); TimeZone gmt = TimeZone.getTimeZone("GMT"); GregorianCalendar cal = new GregorianCalendar(gmt); cal.setTime(date); int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH); int day = cal.get(Calendar.DAY_OF_MONTH); int hour = cal.get(Calendar.HOUR_OF_DAY); int minute = cal.get(Calendar.MINUTE); int second = cal.get(Calendar.SECOND); cs.writeShort(year); cs.writeByte(month + 1); cs.writeByte(day); cs.writeByte(hour); cs.writeByte(minute); cs.writeByte(second); cs.writeToStream(dataOutput); cs.close(); } }
/** * Saves XML+PNG format. * @param frame */ protected void saveXmlPng(TrackSchemeFrame frame, String filename, Color bg) throws IOException { final mxGraphComponent graphComponent = trackScheme.getGUI().graphComponent; final mxGraph graph = trackScheme.getGraph(); // Creates the image for the PNG file BufferedImage image = mxCellRenderer.createBufferedImage(graph, null, 1, bg, graphComponent.isAntiAlias(), null, graphComponent.getCanvas()); // Creates the URL-encoded XML data mxCodec codec = new mxCodec(); String xml = URLEncoder.encode(mxXmlUtils.getXml(codec.encode(graph.getModel())), "UTF-8"); mxPngEncodeParam param = mxPngEncodeParam.getDefaultEncodeParam(image); param.setCompressedText(new String[] { "mxGraphModel", xml }); // Saves as a PNG file try (FileOutputStream outputStream = new FileOutputStream( new File( filename ) )) { mxPngImageEncoder encoder = new mxPngImageEncoder( outputStream, param ); if ( image != null ) encoder.encode( image ); else JOptionPane.showMessageDialog( graphComponent, "No Image Data" ); } }
if (param.isTransparencySet()) if (param.isTransparencySet()) interlace = param.getInterlacing();
mxPngEncodeParam param = mxPngEncodeParam.getDefaultEncodeParam(image);
int filterType = param.filterRow(currRow, prevRow, filteredRows, bytesPerRow, bpp);
private void writePrivateChunks() throws IOException { int numChunks = param.getNumPrivateChunks(); for (int i = 0; i < numChunks; i++) { String type = param.getPrivateChunkType(i); byte[] data = param.getPrivateChunkData(i); ChunkStream cs = new ChunkStream(type); cs.write(data); cs.writeToStream(dataOutput); cs.close(); } }