1 7 8 package org.jboss.media.format.image.iio; 9 10 import javax.imageio.metadata.IIOMetadata ; 11 12 18 public class PNGMediaHeader extends IIOMediaHeader 19 { 20 private static final long serialVersionUID = 0L; 22 23 private static final String PNG_METADATA_FORMAT_NAME = 24 "javax_imageio_png_1.0"; 25 26 private static final String [] FIELD_NAMES = 27 { 28 "width", 29 "height", 30 "bitDepth", 31 "colorType", 32 "compressionMethod", 33 "filterMethod", 34 "interlaceMethod" }; 35 36 37 private static final String IHDR = "IHDR"; 38 39 45 public PNGMediaHeader(IIOMetadata imageMetadata) 46 { 47 super(imageMetadata, PNG_METADATA_FORMAT_NAME); 48 } 49 50 53 public String [] getFieldNames() 54 { 55 return FIELD_NAMES; 56 } 57 58 61 public Object getField(String fieldname) 62 { 63 Object field = null; 64 65 if (fieldname.equals("width")) 66 { 67 field = new Integer (getWidth()); 68 } 69 70 if (fieldname.equals("height")) 71 { 72 field = new Integer (getHeight()); 73 } 74 75 if (fieldname.equals("bitDepth")) 76 { 77 field = getBitDepth(); 78 } 79 80 if (fieldname.equals("colorType")) 81 { 82 field = getColorType(); 83 } 84 85 if (fieldname.equals("compressionMethod")) 86 { 87 field = getCompressionMethod(); 88 } 89 90 if (fieldname.equals("filterMethod")) 91 { 92 field = getFilterMethod(); 93 } 94 95 if (fieldname.equals("interlaceMethod")) 96 { 97 field = getInterlaceMethod(); 98 } 99 100 return field; 101 } 102 103 108 public int getWidth() 109 { 110 String width = getAttribute(IHDR, "width"); 111 return Integer.parseInt(width); 112 } 113 114 119 public int getHeight() 120 { 121 String height = getAttribute(IHDR, "height"); 122 return Integer.parseInt(height); 123 } 124 125 130 public String getBitDepth() 131 { 132 return getAttribute(IHDR, "bitDepth"); 133 } 134 135 140 public String getColorType() 141 { 142 return getAttribute(IHDR, "colorType"); 143 } 144 145 150 public String getCompressionMethod() 151 { 152 return getAttribute(IHDR, "compressionMethod"); 153 } 154 155 160 public String getFilterMethod() 161 { 162 return getAttribute(IHDR, "filterMethod"); 163 } 164 165 170 public String getInterlaceMethod() 171 { 172 return getAttribute(IHDR, "interlaceMethod"); 173 } 174 175 180 public int getGamma() 181 { 182 String gamma = getAttribute("gAMA", "value"); 183 return Integer.parseInt(gamma); 184 } 185 186 191 public int getPixelsPerUnitXAxis() 192 { 193 String pixelsPerUnitXAxis = getAttribute("pHYS", "pixelsPerUnitXAxis"); 194 return Integer.parseInt(pixelsPerUnitXAxis); 195 } 196 197 202 public int getPixelsPerUnitYAxis() 203 { 204 String pixelsPerUnitYAxis = getAttribute("pHYS", "pixelsPerUnitYAxis"); 205 return Integer.parseInt(pixelsPerUnitYAxis); 206 } 207 208 213 public String getPixelsPerUnitSpecifier() 214 { 215 return getAttribute("pHYS", "unitSpecifier"); 216 } 217 } 218 | Popular Tags |