1. /*
  2. * @(#)GIFStreamMetadataFormat.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 GIFStreamMetadataFormat extends IIOMetadataFormatImpl {
  13. private static IIOMetadataFormat instance = null;
  14. private GIFStreamMetadataFormat() {
  15. super(GIFStreamMetadata.nativeMetadataFormatName,
  16. CHILD_POLICY_SOME);
  17. // root -> Version
  18. addElement("Version", GIFStreamMetadata.nativeMetadataFormatName,
  19. CHILD_POLICY_EMPTY);
  20. addAttribute("Version", "value",
  21. DATATYPE_STRING, true, null,
  22. Arrays.asList(GIFStreamMetadata.versionStrings));
  23. // root -> LogicalScreenDescriptor
  24. addElement("LogicalScreenDescriptor",
  25. GIFStreamMetadata.nativeMetadataFormatName,
  26. CHILD_POLICY_EMPTY);
  27. addAttribute("LogicalScreenDescriptor", "logicalScreenWidth",
  28. DATATYPE_INTEGER, true, null,
  29. "1", "65535", true, true);
  30. addAttribute("LogicalScreenDescriptor", "logicalScreenHeight",
  31. DATATYPE_INTEGER, true, null,
  32. "1", "65535", true, true);
  33. addAttribute("LogicalScreenDescriptor", "colorResolution",
  34. DATATYPE_INTEGER, true, null,
  35. "1", "8", true, true);
  36. addAttribute("LogicalScreenDescriptor", "pixelAspectRatio",
  37. DATATYPE_INTEGER, true, null,
  38. "0", "255", true, true);
  39. // root -> GlobalColorTable
  40. addElement("GlobalColorTable",
  41. GIFStreamMetadata.nativeMetadataFormatName,
  42. 2, 256);
  43. addAttribute("GlobalColorTable", "sizeOfGlobalColorTable",
  44. DATATYPE_INTEGER, true, null,
  45. Arrays.asList(GIFStreamMetadata.colorTableSizes));
  46. addAttribute("GlobalColorTable", "backgroundColorIndex",
  47. DATATYPE_INTEGER, true, null,
  48. "0", "255", true, true);
  49. addBooleanAttribute("GlobalColorTable", "sortFlag",
  50. false, false);
  51. // root -> GlobalColorTable -> ColorTableEntry
  52. addElement("ColorTableEntry", "GlobalColorTable",
  53. CHILD_POLICY_EMPTY);
  54. addAttribute("ColorTableEntry", "index",
  55. DATATYPE_INTEGER, true, null,
  56. "0", "255", true, true);
  57. addAttribute("ColorTableEntry", "red",
  58. DATATYPE_INTEGER, true, null,
  59. "0", "255", true, true);
  60. addAttribute("ColorTableEntry", "green",
  61. DATATYPE_INTEGER, true, null,
  62. "0", "255", true, true);
  63. addAttribute("ColorTableEntry", "blue",
  64. DATATYPE_INTEGER, true, null,
  65. "0", "255", true, true);
  66. }
  67. public boolean canNodeAppear(String elementName,
  68. ImageTypeSpecifier imageType) {
  69. return true;
  70. }
  71. public static synchronized IIOMetadataFormat getInstance() {
  72. if (instance == null) {
  73. instance = new GIFStreamMetadataFormat();
  74. }
  75. return instance;
  76. }
  77. }