001/* 002 * $RCSfile: GIFImageMetadataFormat.java,v $ 003 * 004 * 005 * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved. 006 * 007 * Redistribution and use in source and binary forms, with or without 008 * modification, are permitted provided that the following conditions 009 * are met: 010 * 011 * - Redistribution of source code must retain the above copyright 012 * notice, this list of conditions and the following disclaimer. 013 * 014 * - Redistribution in binary form must reproduce the above copyright 015 * notice, this list of conditions and the following disclaimer in 016 * the documentation and/or other materials provided with the 017 * distribution. 018 * 019 * Neither the name of Sun Microsystems, Inc. or the names of 020 * contributors may be used to endorse or promote products derived 021 * from this software without specific prior written permission. 022 * 023 * This software is provided "AS IS," without a warranty of any 024 * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND 025 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, 026 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY 027 * EXCLUDED. SUN MIDROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL 028 * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF 029 * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS 030 * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR 031 * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, 032 * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND 033 * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR 034 * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE 035 * POSSIBILITY OF SUCH DAMAGES. 036 * 037 * You acknowledge that this software is not designed or intended for 038 * use in the design, construction, operation or maintenance of any 039 * nuclear facility. 040 * 041 * $Revision: 1.1 $ 042 * $Date: 2006/03/24 22:30:10 $ 043 * $State: Exp $ 044 */ 045 046package com.github.jaiimageio.impl.plugins.gif; 047 048import java.util.Arrays; 049import javax.imageio.ImageTypeSpecifier; 050import javax.imageio.metadata.IIOMetadataFormat; 051import javax.imageio.metadata.IIOMetadataFormatImpl; 052 053public class GIFImageMetadataFormat extends IIOMetadataFormatImpl { 054 055 private static IIOMetadataFormat instance = null; 056 057 private GIFImageMetadataFormat() { 058 super(GIFImageMetadata.nativeMetadataFormatName, 059 CHILD_POLICY_SOME); 060 061 // root -> ImageDescriptor 062 addElement("ImageDescriptor", 063 GIFImageMetadata.nativeMetadataFormatName, 064 CHILD_POLICY_EMPTY); 065 addAttribute("ImageDescriptor", "imageLeftPosition", 066 DATATYPE_INTEGER, true, null, 067 "0", "65535", true, true); 068 addAttribute("ImageDescriptor", "imageTopPosition", 069 DATATYPE_INTEGER, true, null, 070 "0", "65535", true, true); 071 addAttribute("ImageDescriptor", "imageWidth", 072 DATATYPE_INTEGER, true, null, 073 "1", "65535", true, true); 074 addAttribute("ImageDescriptor", "imageHeight", 075 DATATYPE_INTEGER, true, null, 076 "1", "65535", true, true); 077 addBooleanAttribute("ImageDescriptor", "interlaceFlag", 078 false, false); 079 080 // root -> LocalColorTable 081 addElement("LocalColorTable", 082 GIFImageMetadata.nativeMetadataFormatName, 083 2, 256); 084 addAttribute("LocalColorTable", "sizeOfLocalColorTable", 085 DATATYPE_INTEGER, true, null, 086 Arrays.asList(GIFStreamMetadata.colorTableSizes)); 087 addBooleanAttribute("LocalColorTable", "sortFlag", 088 false, false); 089 090 // root -> LocalColorTable -> ColorTableEntry 091 addElement("ColorTableEntry", "LocalColorTable", 092 CHILD_POLICY_EMPTY); 093 addAttribute("ColorTableEntry", "index", 094 DATATYPE_INTEGER, true, null, 095 "0", "255", true, true); 096 addAttribute("ColorTableEntry", "red", 097 DATATYPE_INTEGER, true, null, 098 "0", "255", true, true); 099 addAttribute("ColorTableEntry", "green", 100 DATATYPE_INTEGER, true, null, 101 "0", "255", true, true); 102 addAttribute("ColorTableEntry", "blue", 103 DATATYPE_INTEGER, true, null, 104 "0", "255", true, true); 105 106 // root -> GraphicControlExtension 107 addElement("GraphicControlExtension", 108 GIFImageMetadata.nativeMetadataFormatName, 109 CHILD_POLICY_EMPTY); 110 addAttribute("GraphicControlExtension", "disposalMethod", 111 DATATYPE_STRING, true, null, 112 Arrays.asList(GIFImageMetadata.disposalMethodNames)); 113 addBooleanAttribute("GraphicControlExtension", "userInputFlag", 114 false, false); 115 addBooleanAttribute("GraphicControlExtension", "transparentColorFlag", 116 false, false); 117 addAttribute("GraphicControlExtension", "delayTime", 118 DATATYPE_INTEGER, true, null, 119 "0", "65535", true, true); 120 addAttribute("GraphicControlExtension", "transparentColorIndex", 121 DATATYPE_INTEGER, true, null, 122 "0", "255", true, true); 123 124 // root -> PlainTextExtension 125 addElement("PlainTextExtension", 126 GIFImageMetadata.nativeMetadataFormatName, 127 CHILD_POLICY_EMPTY); 128 addAttribute("PlainTextExtension", "textGridLeft", 129 DATATYPE_INTEGER, true, null, 130 "0", "65535", true, true); 131 addAttribute("PlainTextExtension", "textGridTop", 132 DATATYPE_INTEGER, true, null, 133 "0", "65535", true, true); 134 addAttribute("PlainTextExtension", "textGridWidth", 135 DATATYPE_INTEGER, true, null, 136 "1", "65535", true, true); 137 addAttribute("PlainTextExtension", "textGridHeight", 138 DATATYPE_INTEGER, true, null, 139 "1", "65535", true, true); 140 addAttribute("PlainTextExtension", "characterCellWidth", 141 DATATYPE_INTEGER, true, null, 142 "1", "65535", true, true); 143 addAttribute("PlainTextExtension", "characterCellHeight", 144 DATATYPE_INTEGER, true, null, 145 "1", "65535", true, true); 146 addAttribute("PlainTextExtension", "textForegroundColor", 147 DATATYPE_INTEGER, true, null, 148 "0", "255", true, true); 149 addAttribute("PlainTextExtension", "textBackgroundColor", 150 DATATYPE_INTEGER, true, null, 151 "0", "255", true, true); 152 153 // root -> ApplicationExtensions 154 addElement("ApplicationExtensions", 155 GIFImageMetadata.nativeMetadataFormatName, 156 1, Integer.MAX_VALUE); 157 158 // root -> ApplicationExtensions -> ApplicationExtension 159 addElement("ApplicationExtension", "ApplicationExtensions", 160 CHILD_POLICY_EMPTY); 161 addAttribute("ApplicationExtension", "applicationID", 162 DATATYPE_STRING, true, null); 163 addAttribute("ApplicationExtension", "authenticationCode", 164 DATATYPE_STRING, true, null); 165 addObjectValue("ApplicationExtension", byte.class, 166 0, Integer.MAX_VALUE); 167 168 // root -> CommentExtensions 169 addElement("CommentExtensions", 170 GIFImageMetadata.nativeMetadataFormatName, 171 1, Integer.MAX_VALUE); 172 173 // root -> CommentExtensions -> CommentExtension 174 addElement("CommentExtension", "CommentExtensions", 175 CHILD_POLICY_EMPTY); 176 addAttribute("CommentExtension", "value", 177 DATATYPE_STRING, true, null); 178 } 179 180 public boolean canNodeAppear(String elementName, 181 ImageTypeSpecifier imageType) { 182 return true; 183 } 184 185 public static synchronized IIOMetadataFormat getInstance() { 186 if (instance == null) { 187 instance = new GIFImageMetadataFormat(); 188 } 189 return instance; 190 } 191}