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;
049
050import javax.imageio.ImageTypeSpecifier;
051import javax.imageio.metadata.IIOMetadataFormat;
052import javax.imageio.metadata.IIOMetadataFormatImpl;
053
054public class GIFImageMetadataFormat extends IIOMetadataFormatImpl {
055
056    private static IIOMetadataFormat instance = null;
057
058    private GIFImageMetadataFormat() {
059        super(GIFImageMetadata.nativeMetadataFormatName,
060              CHILD_POLICY_SOME);
061
062        // root -> ImageDescriptor
063        addElement("ImageDescriptor",
064                   GIFImageMetadata.nativeMetadataFormatName,
065                   CHILD_POLICY_EMPTY);
066        addAttribute("ImageDescriptor", "imageLeftPosition",
067                     DATATYPE_INTEGER, true, null,
068                     "0", "65535", true, true); 
069        addAttribute("ImageDescriptor", "imageTopPosition",
070                     DATATYPE_INTEGER, true, null,
071                     "0", "65535", true, true); 
072        addAttribute("ImageDescriptor", "imageWidth",
073                     DATATYPE_INTEGER, true, null,
074                     "1", "65535", true, true); 
075        addAttribute("ImageDescriptor", "imageHeight",
076                     DATATYPE_INTEGER, true, null,
077                     "1", "65535", true, true); 
078        addBooleanAttribute("ImageDescriptor", "interlaceFlag",
079                            false, false);
080
081        // root -> LocalColorTable
082        addElement("LocalColorTable",
083                   GIFImageMetadata.nativeMetadataFormatName,
084                   2, 256);
085        addAttribute("LocalColorTable", "sizeOfLocalColorTable",
086                     DATATYPE_INTEGER, true, null,
087                     Arrays.asList(GIFStreamMetadata.colorTableSizes));
088        addBooleanAttribute("LocalColorTable", "sortFlag",
089                            false, false);
090
091        // root -> LocalColorTable -> ColorTableEntry
092        addElement("ColorTableEntry", "LocalColorTable",
093                   CHILD_POLICY_EMPTY);
094        addAttribute("ColorTableEntry", "index",
095                     DATATYPE_INTEGER, true, null,
096                     "0", "255", true, true);
097        addAttribute("ColorTableEntry", "red",
098                     DATATYPE_INTEGER, true, null,
099                     "0", "255", true, true);
100        addAttribute("ColorTableEntry", "green",
101                     DATATYPE_INTEGER, true, null,
102                     "0", "255", true, true);
103        addAttribute("ColorTableEntry", "blue",
104                     DATATYPE_INTEGER, true, null,
105                     "0", "255", true, true);
106
107        // root -> GraphicControlExtension
108        addElement("GraphicControlExtension",
109                   GIFImageMetadata.nativeMetadataFormatName,
110                   CHILD_POLICY_EMPTY);
111        addAttribute("GraphicControlExtension", "disposalMethod",
112                     DATATYPE_STRING, true, null,
113                     Arrays.asList(GIFImageMetadata.disposalMethodNames));
114        addBooleanAttribute("GraphicControlExtension", "userInputFlag",
115                            false, false);
116        addBooleanAttribute("GraphicControlExtension", "transparentColorFlag",
117                            false, false);
118        addAttribute("GraphicControlExtension", "delayTime",
119                     DATATYPE_INTEGER, true, null,
120                     "0", "65535", true, true);
121        addAttribute("GraphicControlExtension", "transparentColorIndex",
122                     DATATYPE_INTEGER, true, null,
123                     "0", "255", true, true);
124
125        // root -> PlainTextExtension
126        addElement("PlainTextExtension",
127                   GIFImageMetadata.nativeMetadataFormatName,
128                   CHILD_POLICY_EMPTY);
129        addAttribute("PlainTextExtension", "textGridLeft",
130                     DATATYPE_INTEGER, true, null,
131                     "0", "65535", true, true);
132        addAttribute("PlainTextExtension", "textGridTop",
133                     DATATYPE_INTEGER, true, null,
134                     "0", "65535", true, true);
135        addAttribute("PlainTextExtension", "textGridWidth",
136                     DATATYPE_INTEGER, true, null,
137                     "1", "65535", true, true);
138        addAttribute("PlainTextExtension", "textGridHeight",
139                     DATATYPE_INTEGER, true, null,
140                     "1", "65535", true, true);
141        addAttribute("PlainTextExtension", "characterCellWidth",
142                     DATATYPE_INTEGER, true, null,
143                     "1", "65535", true, true);
144        addAttribute("PlainTextExtension", "characterCellHeight",
145                     DATATYPE_INTEGER, true, null,
146                     "1", "65535", true, true);
147        addAttribute("PlainTextExtension", "textForegroundColor",
148                     DATATYPE_INTEGER, true, null,
149                     "0", "255", true, true);
150        addAttribute("PlainTextExtension", "textBackgroundColor",
151                     DATATYPE_INTEGER, true, null,
152                     "0", "255", true, true);
153        
154        // root -> ApplicationExtensions
155        addElement("ApplicationExtensions",
156                   GIFImageMetadata.nativeMetadataFormatName,
157                   1, Integer.MAX_VALUE);
158
159        // root -> ApplicationExtensions -> ApplicationExtension
160        addElement("ApplicationExtension", "ApplicationExtensions",
161                   CHILD_POLICY_EMPTY);
162        addAttribute("ApplicationExtension", "applicationID",
163                     DATATYPE_STRING, true, null);
164        addAttribute("ApplicationExtension", "authenticationCode",
165                     DATATYPE_STRING, true, null);
166        addObjectValue("ApplicationExtension", byte.class,
167                       0, Integer.MAX_VALUE);
168
169        // root -> CommentExtensions
170        addElement("CommentExtensions",
171                   GIFImageMetadata.nativeMetadataFormatName,
172                   1, Integer.MAX_VALUE);
173
174        // root -> CommentExtensions -> CommentExtension
175        addElement("CommentExtension", "CommentExtensions",
176                   CHILD_POLICY_EMPTY);
177        addAttribute("CommentExtension", "value",
178                     DATATYPE_STRING, true, null);
179    }
180
181    public boolean canNodeAppear(String elementName,
182                                 ImageTypeSpecifier imageType) {
183        return true;
184    }
185
186    public static synchronized IIOMetadataFormat getInstance() {
187        if (instance == null) {
188            instance = new GIFImageMetadataFormat();
189        }
190        return instance;
191    }
192}