Java Code Examples for javax.imageio.metadata.IIOMetadataNode#setAttribute()
The following examples show how to use
javax.imageio.metadata.IIOMetadataNode#setAttribute() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BMPMetadata.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
protected IIOMetadataNode getStandardDataNode() { IIOMetadataNode node = new IIOMetadataNode("Data"); String bits = ""; if (bitsPerPixel == 24) bits = "8 8 8 "; else if (bitsPerPixel == 16 || bitsPerPixel == 32) { bits = "" + countBits(redMask) + " " + countBits(greenMask) + countBits(blueMask) + "" + countBits(alphaMask); } IIOMetadataNode subNode = new IIOMetadataNode("BitsPerSample"); subNode.setAttribute("value", bits); node.appendChild(subNode); return node; }
Example 2
Source File: BMPMetadata.java From Bytecoder with Apache License 2.0 | 6 votes |
protected IIOMetadataNode getStandardChromaNode() { if ((palette != null) && (paletteSize > 0)) { IIOMetadataNode node = new IIOMetadataNode("Chroma"); IIOMetadataNode subNode = new IIOMetadataNode("Palette"); int numComps = palette.length / paletteSize; subNode.setAttribute("value", "" + numComps); for (int i = 0, j = 0; i < paletteSize; i++) { IIOMetadataNode subNode1 = new IIOMetadataNode("PaletteEntry"); subNode1.setAttribute("index", ""+i); subNode1.setAttribute("red", "" + palette[j++]); subNode1.setAttribute("green", "" + palette[j++]); subNode1.setAttribute("blue", "" + palette[j++]); if (numComps == 4 && palette[j] != 0) subNode1.setAttribute("alpha", "" + palette[j++]); subNode.appendChild(subNode1); } node.appendChild(subNode); return node; } return null; }
Example 3
Source File: SOFMarkerSegment.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
IIOMetadataNode getNativeNode() { IIOMetadataNode node = new IIOMetadataNode("sof"); node.setAttribute("process", Integer.toString(tag-JPEG.SOF0)); node.setAttribute("samplePrecision", Integer.toString(samplePrecision)); node.setAttribute("numLines", Integer.toString(numLines)); node.setAttribute("samplesPerLine", Integer.toString(samplesPerLine)); node.setAttribute("numFrameComponents", Integer.toString(componentSpecs.length)); for (int i = 0; i < componentSpecs.length; i++) { node.appendChild(componentSpecs[i].getNativeNode()); } return node; }
Example 4
Source File: BMPMetadata.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
protected IIOMetadataNode getStandardDataNode() { IIOMetadataNode node = new IIOMetadataNode("Data"); String bits = ""; if (bitsPerPixel == 24) bits = "8 8 8 "; else if (bitsPerPixel == 16 || bitsPerPixel == 32) { bits = "" + countBits(redMask) + " " + countBits(greenMask) + countBits(blueMask) + "" + countBits(alphaMask); } IIOMetadataNode subNode = new IIOMetadataNode("BitsPerSample"); subNode.setAttribute("value", bits); node.appendChild(subNode); return node; }
Example 5
Source File: BMPMetadata.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
protected IIOMetadataNode getStandardDataNode() { IIOMetadataNode node = new IIOMetadataNode("Data"); String bits = ""; if (bitsPerPixel == 24) bits = "8 8 8 "; else if (bitsPerPixel == 16 || bitsPerPixel == 32) { bits = "" + countBits(redMask) + " " + countBits(greenMask) + countBits(blueMask) + "" + countBits(alphaMask); } IIOMetadataNode subNode = new IIOMetadataNode("BitsPerSample"); subNode.setAttribute("value", bits); node.appendChild(subNode); return node; }
Example 6
Source File: JFIFMarkerSegment.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Returns a tree of DOM nodes representing this object and any * subordinate JFXX extension or ICC Profile segments. */ IIOMetadataNode getNativeNode() { IIOMetadataNode node = new IIOMetadataNode("app0JFIF"); node.setAttribute("majorVersion", Integer.toString(majorVersion)); node.setAttribute("minorVersion", Integer.toString(minorVersion)); node.setAttribute("resUnits", Integer.toString(resUnits)); node.setAttribute("Xdensity", Integer.toString(Xdensity)); node.setAttribute("Ydensity", Integer.toString(Ydensity)); node.setAttribute("thumbWidth", Integer.toString(thumbWidth)); node.setAttribute("thumbHeight", Integer.toString(thumbHeight)); if (!extSegments.isEmpty()) { IIOMetadataNode JFXXnode = new IIOMetadataNode("JFXX"); node.appendChild(JFXXnode); for (Iterator<JFIFExtensionMarkerSegment> iter = extSegments.iterator(); iter.hasNext();) { JFIFExtensionMarkerSegment seg = iter.next(); JFXXnode.appendChild(seg.getNativeNode()); } } if (iccSegment != null) { node.appendChild(iccSegment.getNativeNode()); } return node; }
Example 7
Source File: BMPMetadata.java From hottub with GNU General Public License v2.0 | 5 votes |
protected IIOMetadataNode getStandardCompressionNode() { IIOMetadataNode node = new IIOMetadataNode("Compression"); // CompressionTypeName IIOMetadataNode subNode = new IIOMetadataNode("CompressionTypeName"); subNode.setAttribute("value", BMPCompressionTypes.getName(compression)); node.appendChild(subNode); return node; }
Example 8
Source File: BMPMetadata.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
protected IIOMetadataNode getStandardCompressionNode() { IIOMetadataNode node = new IIOMetadataNode("Compression"); // CompressionTypeName IIOMetadataNode subNode = new IIOMetadataNode("CompressionTypeName"); subNode.setAttribute("value", BMPCompressionTypes.getName(compression)); node.appendChild(subNode); return node; }
Example 9
Source File: DHTMarkerSegment.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
IIOMetadataNode getNativeNode() { IIOMetadataNode node = new IIOMetadataNode("dhtable"); node.setAttribute("class", Integer.toString(tableClass)); node.setAttribute("htableId", Integer.toString(tableID)); node.setUserObject(new JPEGHuffmanTable(numCodes, values)); return node; }
Example 10
Source File: JPEGMetadata.java From JDKSourceCode1.8 with MIT License | 5 votes |
protected IIOMetadataNode getStandardCompressionNode() { IIOMetadataNode compression = new IIOMetadataNode("Compression"); // CompressionTypeName IIOMetadataNode name = new IIOMetadataNode("CompressionTypeName"); name.setAttribute("value", "JPEG"); compression.appendChild(name); // Lossless - false IIOMetadataNode lossless = new IIOMetadataNode("Lossless"); lossless.setAttribute("value", "FALSE"); compression.appendChild(lossless); // NumProgressiveScans - count sos segments int sosCount = 0; Iterator iter = markerSequence.iterator(); while (iter.hasNext()) { MarkerSegment ms = (MarkerSegment) iter.next(); if (ms.tag == JPEG.SOS) { sosCount++; } } if (sosCount != 0) { IIOMetadataNode prog = new IIOMetadataNode("NumProgressiveScans"); prog.setAttribute("value", Integer.toString(sosCount)); compression.appendChild(prog); } return compression; }
Example 11
Source File: SOSMarkerSegment.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
IIOMetadataNode getNativeNode() { IIOMetadataNode node = new IIOMetadataNode("scanComponentSpec"); node.setAttribute("componentSelector", Integer.toString(componentSelector)); node.setAttribute("dcHuffTable", Integer.toString(dcHuffTable)); node.setAttribute("acHuffTable", Integer.toString(acHuffTable)); return node; }
Example 12
Source File: SOFMarkerSegment.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
IIOMetadataNode getNativeNode() { IIOMetadataNode node = new IIOMetadataNode("componentSpec"); node.setAttribute("componentId", Integer.toString(componentId)); node.setAttribute("HsamplingFactor", Integer.toString(HsamplingFactor)); node.setAttribute("VsamplingFactor", Integer.toString(VsamplingFactor)); node.setAttribute("QtableSelector", Integer.toString(QtableSelector)); return node; }
Example 13
Source File: MarkerSegment.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
IIOMetadataNode getNativeNode() { IIOMetadataNode node = new IIOMetadataNode("unknown"); node.setAttribute("MarkerTag", Integer.toString(tag)); node.setUserObject(data); return node; }
Example 14
Source File: ImageIOHelper.java From tess4j with Apache License 2.0 | 5 votes |
/** * Set DPI using API. * * @param imageMetadata original IIOMetadata * @param dpiX horizontal resolution * @param dpiY vertical resolution * @return modified IIOMetadata * @throws IIOInvalidTreeException */ private static IIOMetadata setDPIViaAPI(IIOMetadata imageMetadata, int dpiX, int dpiY) throws IIOInvalidTreeException { // Derive the TIFFDirectory from the metadata. TIFFDirectory dir = TIFFDirectory.createFromMetadata(imageMetadata); // Get {X,Y}Resolution tags. BaselineTIFFTagSet base = BaselineTIFFTagSet.getInstance(); TIFFTag tagXRes = base.getTag(BaselineTIFFTagSet.TAG_X_RESOLUTION); TIFFTag tagYRes = base.getTag(BaselineTIFFTagSet.TAG_Y_RESOLUTION); // Create {X,Y}Resolution fields. TIFFField fieldXRes = new TIFFField(tagXRes, TIFFTag.TIFF_RATIONAL, 1, new long[][]{{dpiX, 1}}); TIFFField fieldYRes = new TIFFField(tagYRes, TIFFTag.TIFF_RATIONAL, 1, new long[][]{{dpiY, 1}}); // Append {X,Y}Resolution fields to directory. dir.addTIFFField(fieldXRes); dir.addTIFFField(fieldYRes); // Convert to metadata object. IIOMetadata metadata = dir.getAsMetadata(); // Add other metadata. IIOMetadataNode root = new IIOMetadataNode("javax_imageio_1.0"); IIOMetadataNode horiz = new IIOMetadataNode("HorizontalPixelSize"); horiz.setAttribute("value", Double.toString(25.4f / dpiX)); IIOMetadataNode vert = new IIOMetadataNode("VerticalPixelSize"); vert.setAttribute("value", Double.toString(25.4f / dpiY)); IIOMetadataNode dim = new IIOMetadataNode("Dimension"); dim.appendChild(horiz); dim.appendChild(vert); root.appendChild(dim); metadata.mergeTree("javax_imageio_1.0", root); return metadata; }
Example 15
Source File: ITXtTest.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
public IIOMetadataNode getNode() { IIOMetadataNode iTXt = new IIOMetadataNode("iTXt"); IIOMetadataNode iTXtEntry = new IIOMetadataNode("iTXtEntry"); iTXtEntry.setAttribute("keyword", keyword); iTXtEntry.setAttribute("compressionFlag", isCompressed ? "true" : "false"); iTXtEntry.setAttribute("compressionMethod", Integer.toString(compression)); iTXtEntry.setAttribute("languageTag", language); iTXtEntry.setAttribute("translatedKeyword", trasKeyword); iTXtEntry.setAttribute("text", text); iTXt.appendChild(iTXtEntry); return iTXt; }
Example 16
Source File: JFIFMarkerSegment.java From jdk1.8-source-analysis with Apache License 2.0 | 4 votes |
IIOMetadataNode getNativeNode() { IIOMetadataNode node = new IIOMetadataNode(name); node.setAttribute("thumbWidth", Integer.toString(thumbWidth)); node.setAttribute("thumbHeight", Integer.toString(thumbHeight)); return node; }
Example 17
Source File: DRIMarkerSegment.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
IIOMetadataNode getNativeNode() { IIOMetadataNode node = new IIOMetadataNode("dri"); node.setAttribute("interval", Integer.toString(restartInterval)); return node; }
Example 18
Source File: GifSequenceWriter.java From Digital with GNU General Public License v3.0 | 4 votes |
/** * Creates a new GifSequenceWriter * * @param outputStream the ImageOutputStream to be written to * @param imageType one of the imageTypes specified in BufferedImage * @param timeBetweenFramesMS the time between frames in miliseconds * @param loopContinuously wether the gif should loop repeatedly * @throws IOException if no gif ImageWriters are found * @author Elliot Kroo (elliot[at]kroo[dot]net) */ public GifSequenceWriter( ImageOutputStream outputStream, int imageType, int timeBetweenFramesMS, boolean loopContinuously) throws IOException { // my method to create a writer gifWriter = getWriter(); imageWriteParam = gifWriter.getDefaultWriteParam(); ImageTypeSpecifier imageTypeSpecifier = ImageTypeSpecifier.createFromBufferedImageType(imageType); imageMetaData = gifWriter.getDefaultImageMetadata(imageTypeSpecifier, imageWriteParam); String metaFormatName = imageMetaData.getNativeMetadataFormatName(); IIOMetadataNode root = (IIOMetadataNode) imageMetaData.getAsTree(metaFormatName); IIOMetadataNode graphicsControlExtensionNode = getNode( root, "GraphicControlExtension"); graphicsControlExtensionNode.setAttribute("disposalMethod", "none"); graphicsControlExtensionNode.setAttribute("userInputFlag", "FALSE"); graphicsControlExtensionNode.setAttribute( "transparentColorFlag", "FALSE"); graphicsControlExtensionNode.setAttribute( "delayTime", Integer.toString(timeBetweenFramesMS / 10)); graphicsControlExtensionNode.setAttribute( "transparentColorIndex", "0"); IIOMetadataNode commentsNode = getNode(root, "CommentExtensions"); commentsNode.setAttribute("CommentExtension", "Created by MAH"); IIOMetadataNode appEntensionsNode = getNode( root, "ApplicationExtensions"); IIOMetadataNode child = new IIOMetadataNode("ApplicationExtension"); child.setAttribute("applicationID", "NETSCAPE"); child.setAttribute("authenticationCode", "2.0"); int loop = loopContinuously ? 0 : 1; child.setUserObject(new byte[]{0x1, (byte) (loop & 0xFF), (byte) ((loop >> 8) & 0xFF)}); appEntensionsNode.appendChild(child); imageMetaData.setFromTree(metaFormatName, root); gifWriter.setOutput(outputStream); gifWriter.prepareWriteSequence(null); }
Example 19
Source File: DRIMarkerSegment.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
IIOMetadataNode getNativeNode() { IIOMetadataNode node = new IIOMetadataNode("dri"); node.setAttribute("interval", Integer.toString(restartInterval)); return node; }
Example 20
Source File: AnimatedGifExport.java From snap-desktop with GNU General Public License v3.0 | 4 votes |
private static void configure(IIOMetadata meta, String delayTime, int imageIndex) { String metaFormat = meta.getNativeMetadataFormatName(); if (!"javax_imageio_gif_image_1.0".equals(metaFormat)) { throw new IllegalArgumentException( "Unfamiliar gif metadata format: " + metaFormat); } Node root = meta.getAsTree(metaFormat); //find the GraphicControlExtension node Node child = root.getFirstChild(); while (child != null) { if ("GraphicControlExtension".equals(child.getNodeName())) { IIOMetadataNode gce = (IIOMetadataNode) child; gce.setAttribute("userInputFlag", "FALSE"); gce.setAttribute("delayTime", delayTime); break; } child = child.getNextSibling(); } //only the first node needs the ApplicationExtensions node if (imageIndex == 0) { IIOMetadataNode parentNode = new IIOMetadataNode("ApplicationExtensions"); IIOMetadataNode childNode = new IIOMetadataNode("ApplicationExtension"); childNode.setAttribute("applicationID", "NETSCAPE"); childNode.setAttribute("authenticationCode", "2.0"); byte[] userObject = new byte[]{ //last two bytes is an unsigned short (little endian) that //indicates the number of times to loop. //0 means loop forever. 0x1, 0x0, 0x0 }; childNode.setUserObject(userObject); parentNode.appendChild(childNode); root.appendChild(parentNode); } try { meta.setFromTree(metaFormat, root); } catch (IIOInvalidTreeException e) { SnapApp.getDefault().handleError(e.getMessage(), e); } }