1. /*
  2. * @(#)GIFImageMetadataFormat.java 1.5 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package com.sun.imageio.plugins.gif;
  8. import java.util.Arrays;
  9. import javax.imageio.ImageTypeSpecifier;
  10. import javax.imageio.metadata.IIOMetadataFormat;
  11. import javax.imageio.metadata.IIOMetadataFormatImpl;
  12. class GIFImageMetadataFormat extends IIOMetadataFormatImpl {
  13. private static IIOMetadataFormat instance = null;
  14. private GIFImageMetadataFormat() {
  15. super(GIFImageMetadata.nativeMetadataFormatName,
  16. CHILD_POLICY_SOME);
  17. // root -> ImageDescriptor
  18. addElement("ImageDescriptor",
  19. GIFImageMetadata.nativeMetadataFormatName,
  20. CHILD_POLICY_EMPTY);
  21. addAttribute("ImageDescriptor", "imageLeftPosition",
  22. DATATYPE_INTEGER, true, null,
  23. "0", "65535", true, true);
  24. addAttribute("ImageDescriptor", "imageTopPosition",
  25. DATATYPE_INTEGER, true, null,
  26. "0", "65535", true, true);
  27. addAttribute("ImageDescriptor", "imageWidth",
  28. DATATYPE_INTEGER, true, null,
  29. "1", "65535", true, true);
  30. addAttribute("ImageDescriptor", "imageHeight",
  31. DATATYPE_INTEGER, true, null,
  32. "1", "65535", true, true);
  33. addBooleanAttribute("ImageDescriptor", "interlaceFlag",
  34. false, false);
  35. // root -> LocalColorTable
  36. addElement("LocalColorTable",
  37. GIFImageMetadata.nativeMetadataFormatName,
  38. 2, 256);
  39. addAttribute("LocalColorTable", "sizeOfLocalColorTable",
  40. DATATYPE_INTEGER, true, null,
  41. Arrays.asList(GIFStreamMetadata.colorTableSizes));
  42. addBooleanAttribute("LocalColorTable", "sortFlag",
  43. false, false);
  44. // root -> LocalColorTable -> ColorTableEntry
  45. addElement("ColorTableEntry", "LocalColorTable",
  46. CHILD_POLICY_EMPTY);
  47. addAttribute("ColorTableEntry", "index",
  48. DATATYPE_INTEGER, true, null,
  49. "0", "255", true, true);
  50. addAttribute("ColorTableEntry", "red",
  51. DATATYPE_INTEGER, true, null,
  52. "0", "255", true, true);
  53. addAttribute("ColorTableEntry", "green",
  54. DATATYPE_INTEGER, true, null,
  55. "0", "255", true, true);
  56. addAttribute("ColorTableEntry", "blue",
  57. DATATYPE_INTEGER, true, null,
  58. "0", "255", true, true);
  59. // root -> GraphicControlExtension
  60. addElement("GraphicControlExtension",
  61. GIFImageMetadata.nativeMetadataFormatName,
  62. CHILD_POLICY_EMPTY);
  63. addAttribute("GraphicControlExtension", "disposalMethod",
  64. DATATYPE_STRING, true, null,
  65. Arrays.asList(GIFImageMetadata.disposalMethodNames));
  66. addBooleanAttribute("GraphicControlExtension", "userInputFlag",
  67. false, false);
  68. addBooleanAttribute("GraphicControlExtension", "transparentColorFlag",
  69. false, false);
  70. addAttribute("GraphicControlExtension", "delayTime",
  71. DATATYPE_INTEGER, true, null,
  72. "0", "65535", true, true);
  73. addAttribute("GraphicControlExtension", "transparentColorIndex",
  74. DATATYPE_INTEGER, true, null,
  75. "0", "255", true, true);
  76. // root -> PlainTextExtension
  77. addElement("PlainTextExtension",
  78. GIFImageMetadata.nativeMetadataFormatName,
  79. CHILD_POLICY_EMPTY);
  80. addAttribute("PlainTextExtension", "textGridLeft",
  81. DATATYPE_INTEGER, true, null,
  82. "0", "65535", true, true);
  83. addAttribute("PlainTextExtension", "textGridTop",
  84. DATATYPE_INTEGER, true, null,
  85. "0", "65535", true, true);
  86. addAttribute("PlainTextExtension", "textGridWidth",
  87. DATATYPE_INTEGER, true, null,
  88. "1", "65535", true, true);
  89. addAttribute("PlainTextExtension", "textGridHeight",
  90. DATATYPE_INTEGER, true, null,
  91. "1", "65535", true, true);
  92. addAttribute("PlainTextExtension", "characterCellWidth",
  93. DATATYPE_INTEGER, true, null,
  94. "1", "65535", true, true);
  95. addAttribute("PlainTextExtension", "characterCellHeight",
  96. DATATYPE_INTEGER, true, null,
  97. "1", "65535", true, true);
  98. addAttribute("PlainTextExtension", "textForegroundColor",
  99. DATATYPE_INTEGER, true, null,
  100. "0", "255", true, true);
  101. addAttribute("PlainTextExtension", "textBackgroundColor",
  102. DATATYPE_INTEGER, true, null,
  103. "0", "255", true, true);
  104. // root -> ApplicationExtensions
  105. addElement("ApplicationExtensions",
  106. GIFImageMetadata.nativeMetadataFormatName,
  107. 1, Integer.MAX_VALUE);
  108. // root -> ApplicationExtensions -> ApplicationExtension
  109. addElement("ApplicationExtension", "ApplicationExtensions",
  110. CHILD_POLICY_EMPTY);
  111. addAttribute("ApplicationExtension", "applicationID",
  112. DATATYPE_STRING, true, null);
  113. addAttribute("ApplicationExtension", "authenticationCode",
  114. DATATYPE_STRING, true, null);
  115. addObjectValue("ApplicationExtension", byte.class,
  116. 0, Integer.MAX_VALUE);
  117. // root -> CommentExtensions
  118. addElement("CommentExtensions",
  119. GIFImageMetadata.nativeMetadataFormatName,
  120. 1, Integer.MAX_VALUE);
  121. // root -> CommentExtensions -> CommentExtension
  122. addElement("CommentExtension", "CommentExtensions",
  123. CHILD_POLICY_EMPTY);
  124. addAttribute("CommentExtension", "value",
  125. DATATYPE_STRING, true, null);
  126. }
  127. public boolean canNodeAppear(String elementName,
  128. ImageTypeSpecifier imageType) {
  129. return true;
  130. }
  131. public static synchronized IIOMetadataFormat getInstance() {
  132. if (instance == null) {
  133. instance = new GIFImageMetadataFormat();
  134. }
  135. return instance;
  136. }
  137. }