1 7 8 package com.sun.imageio.plugins.jpeg; 9 10 import javax.imageio.metadata.IIOMetadataFormat ; 11 import javax.imageio.metadata.IIOMetadataFormatImpl ; 12 import javax.imageio.ImageTypeSpecifier ; 13 import javax.imageio.plugins.jpeg.JPEGQTable ; 14 import javax.imageio.plugins.jpeg.JPEGHuffmanTable ; 15 16 import java.util.List ; 17 import java.util.ArrayList ; 18 19 abstract class JPEGMetadataFormat extends IIOMetadataFormatImpl { 20 private static final int MAX_JPEG_DATA_SIZE = 65533; 22 23 String resourceBaseName = this.getClass().getName() + "Resources"; 24 25 JPEGMetadataFormat(String formatName, int childPolicy) { 26 super(formatName, childPolicy); 27 setResourceBaseName(resourceBaseName); 28 } 29 30 void addStreamElements(String parentName) { 32 addElement("dqt", parentName, 1, 4); 33 34 addElement("dqtable", "dqt", CHILD_POLICY_EMPTY); 35 36 addAttribute("dqtable", 37 "elementPrecision", 38 DATATYPE_INTEGER, 39 false, 40 "0"); 41 List tabids = new ArrayList (); 42 tabids.add("0"); 43 tabids.add("1"); 44 tabids.add("2"); 45 tabids.add("3"); 46 addAttribute("dqtable", 47 "qtableId", 48 DATATYPE_INTEGER, 49 true, 50 null, 51 tabids); 52 addObjectValue("dqtable", 53 JPEGQTable .class, 54 true, 55 null); 56 57 addElement("dht", parentName, 1, 4); 58 addElement("dhtable", "dht", CHILD_POLICY_EMPTY); 59 List classes = new ArrayList (); 60 classes.add("0"); 61 classes.add("1"); 62 addAttribute("dhtable", 63 "class", 64 DATATYPE_INTEGER, 65 true, 66 null, 67 classes); 68 addAttribute("dhtable", 69 "htableId", 70 DATATYPE_INTEGER, 71 true, 72 null, 73 tabids); 74 addObjectValue("dhtable", 75 JPEGHuffmanTable .class, 76 true, 77 null); 78 79 80 addElement("dri", parentName, CHILD_POLICY_EMPTY); 81 addAttribute("dri", 82 "interval", 83 DATATYPE_INTEGER, 84 true, 85 null, 86 "0", "65535", 87 true, true); 88 89 addElement("com", parentName, CHILD_POLICY_EMPTY); 90 addAttribute("com", 91 "comment", 92 DATATYPE_STRING, 93 false, 94 null); 95 addObjectValue("com", byte[].class, 1, MAX_JPEG_DATA_SIZE); 96 97 addElement("unknown", parentName, CHILD_POLICY_EMPTY); 98 addAttribute("unknown", 99 "MarkerTag", 100 DATATYPE_INTEGER, 101 true, 102 null, 103 "0", "255", 104 true, true); 105 addObjectValue("unknown", byte[].class, 1, MAX_JPEG_DATA_SIZE); 106 } 107 108 public boolean canNodeAppear(String elementName, 109 ImageTypeSpecifier imageType) { 110 if (isInSubtree(elementName, getRootName())){ 112 return true; 113 } 114 return false; 115 } 116 117 125 protected boolean isInSubtree(String elementName, 126 String subtreeName) { 127 if (elementName.equals(subtreeName)) { 128 return true; 129 } 130 String [] children = getChildNames(elementName); 131 for (int i=0; i < children.length; i++) { 132 if (isInSubtree(elementName, children[i])) { 133 return true; 134 } 135 } 136 return false; 137 } 138 139 } 140 | Popular Tags |