1 7 8 package com.sun.imageio.plugins.png; 9 10 import java.util.ArrayList ; 11 import java.util.Arrays ; 12 import java.util.List ; 13 import java.util.ListResourceBundle ; 14 import javax.imageio.ImageTypeSpecifier ; 15 import javax.imageio.metadata.IIOMetadataFormat ; 16 import javax.imageio.metadata.IIOMetadataFormatImpl ; 17 18 public class PNGMetadataFormat extends IIOMetadataFormatImpl { 19 20 private static IIOMetadataFormat instance = null; 21 22 private static String VALUE_0 = "0"; 23 private static String VALUE_1 = "1"; 24 private static String VALUE_12 = "12"; 25 private static String VALUE_23 = "23"; 26 private static String VALUE_31 = "31"; 27 private static String VALUE_59 = "59"; 28 private static String VALUE_60 = "60"; 29 private static String VALUE_255 = "255"; 30 private static String VALUE_MAX_16 = "65535"; private static String VALUE_MAX_32 = "2147483647"; 33 private PNGMetadataFormat() { 34 super(PNGMetadata.nativeMetadataFormatName, 35 CHILD_POLICY_SOME); 36 37 addElement("IHDR", PNGMetadata.nativeMetadataFormatName, 39 CHILD_POLICY_EMPTY); 40 41 addAttribute("IHDR", "width", 42 DATATYPE_INTEGER, true, null, 43 VALUE_1, VALUE_MAX_32, true, true); 44 45 addAttribute("IHDR", "height", 46 DATATYPE_INTEGER, true, null, 47 VALUE_1, VALUE_MAX_32, true, true); 48 49 addAttribute("IHDR", "bitDepth", 50 DATATYPE_INTEGER, true, null, 51 Arrays.asList(PNGMetadata.IHDR_bitDepths)); 52 53 String [] colorTypes = { 54 "Grayscale", "RGB", "Palette", "GrayAlpha", "RGBAlpha" 55 }; 56 addAttribute("IHDR", "colorType", 57 DATATYPE_STRING, true, null, 58 Arrays.asList(colorTypes)); 59 60 addAttribute("IHDR", "compressionMethod", 61 DATATYPE_STRING, true, null, 62 Arrays.asList(PNGMetadata.IHDR_compressionMethodNames)); 63 64 addAttribute("IHDR", "filterMethod", 65 DATATYPE_STRING, true, null, 66 Arrays.asList(PNGMetadata.IHDR_filterMethodNames)); 67 68 addAttribute("IHDR", "interlaceMethod", 69 DATATYPE_STRING, true, null, 70 Arrays.asList(PNGMetadata.IHDR_interlaceMethodNames)); 71 72 addElement("PLTE", PNGMetadata.nativeMetadataFormatName, 74 1, 256); 75 76 addElement("PLTEEntry", "PLTE", 78 CHILD_POLICY_EMPTY); 79 80 addAttribute("PLTEEntry", "index", 81 DATATYPE_INTEGER, true, null, 82 VALUE_0, VALUE_255, true, true); 83 84 addAttribute("PLTEEntry", "red", 85 DATATYPE_INTEGER, true, null, 86 VALUE_0, VALUE_255, true, true); 87 88 addAttribute("PLTEEntry", "green", 89 DATATYPE_INTEGER, true, null, 90 VALUE_0, VALUE_255, true, true); 91 92 addAttribute("PLTEEntry", "blue", 93 DATATYPE_INTEGER, true, null, 94 VALUE_0, VALUE_255, true, true); 95 96 addElement("bKGD", PNGMetadata.nativeMetadataFormatName, 98 CHILD_POLICY_CHOICE); 99 100 addElement("bKGD_Grayscale", "bKGD", 102 CHILD_POLICY_EMPTY); 103 104 addAttribute("bKGD_Grayscale", "gray", 105 DATATYPE_INTEGER, true, null, 106 VALUE_0, VALUE_MAX_16, true, true); 107 108 addElement("bKGD_RGB", "bKGD", 110 CHILD_POLICY_EMPTY); 111 112 addAttribute("bKGD_RGB", "red", 113 DATATYPE_INTEGER, true, null, 114 VALUE_0, VALUE_MAX_16, true, true); 115 116 addAttribute("bKGD_RGB", "green", 117 DATATYPE_INTEGER, true, null, 118 VALUE_0, VALUE_MAX_16, true, true); 119 120 addAttribute("bKGD_RGB", "blue", 121 DATATYPE_INTEGER, true, null, 122 VALUE_0, VALUE_MAX_16, true, true); 123 124 addElement("bKGD_Palette", "bKGD", 126 CHILD_POLICY_EMPTY); 127 128 addAttribute("bKGD_Palette", "index", 129 DATATYPE_INTEGER, true, null, 130 VALUE_0, VALUE_255, true, true); 131 132 addElement("cHRM", PNGMetadata.nativeMetadataFormatName, 134 CHILD_POLICY_EMPTY); 135 136 addAttribute("cHRM", "whitePointX", 137 DATATYPE_INTEGER, true, null, 138 VALUE_0, VALUE_MAX_16, true, true); 139 140 addAttribute("cHRM", "whitePointY", 141 DATATYPE_INTEGER, true, null, 142 VALUE_0, VALUE_MAX_16, true, true); 143 144 addAttribute("cHRM", "redX", 145 DATATYPE_INTEGER, true, null, 146 VALUE_0, VALUE_MAX_16, true, true); 147 148 addAttribute("cHRM", "redY", 149 DATATYPE_INTEGER, true, null, 150 VALUE_0, VALUE_MAX_16, true, true); 151 152 addAttribute("cHRM", "greenX", 153 DATATYPE_INTEGER, true, null, 154 VALUE_0, VALUE_MAX_16, true, true); 155 156 addAttribute("cHRM", "greenY", 157 DATATYPE_INTEGER, true, null, 158 VALUE_0, VALUE_MAX_16, true, true); 159 160 addAttribute("cHRM", "blueX", 161 DATATYPE_INTEGER, true, null, 162 VALUE_0, VALUE_MAX_16, true, true); 163 164 addAttribute("cHRM", "blueY", 165 DATATYPE_INTEGER, true, null, 166 VALUE_0, VALUE_MAX_16, true, true); 167 168 addElement("gAMA", PNGMetadata.nativeMetadataFormatName, 170 CHILD_POLICY_EMPTY); 171 172 addAttribute("gAMA", "value", 173 DATATYPE_INTEGER, true, null, 174 VALUE_0, VALUE_MAX_32, true, true); 175 176 addElement("hIST", PNGMetadata.nativeMetadataFormatName, 178 1, 256); 179 180 addElement("hISTEntry", "hIST", 182 CHILD_POLICY_EMPTY); 183 184 addAttribute("hISTEntry", "index", 185 DATATYPE_INTEGER, true, null, 186 VALUE_0, VALUE_255, true, true); 187 188 addAttribute("hISTEntry", "value", 189 DATATYPE_INTEGER, true, null, 190 VALUE_0, VALUE_MAX_16, true, true); 191 192 addElement("iCCP", PNGMetadata.nativeMetadataFormatName, 194 CHILD_POLICY_EMPTY); 195 196 addAttribute("iCCP", "profileName", 197 DATATYPE_STRING, true, null); 198 199 addAttribute("iCCP", "compressionMethod", 200 DATATYPE_STRING, true, null, 201 Arrays.asList(PNGMetadata.iCCP_compressionMethodNames)); 202 203 addObjectValue("iCCP", byte.class, 0, Integer.MAX_VALUE); 204 205 addElement("iTXt", PNGMetadata.nativeMetadataFormatName, 207 1, Integer.MAX_VALUE); 208 209 addElement("iTXtEntry", "iTXt", 211 CHILD_POLICY_EMPTY); 212 213 addAttribute("iTXtEntry", "keyword", 214 DATATYPE_STRING, true, null); 215 216 addBooleanAttribute("iTXtEntry", "compressionFlag", 217 false, false); 218 219 addAttribute("iTXtEntry", "compressionMethod", 220 DATATYPE_STRING, true, null); 221 222 addAttribute("iTXtEntry", "languageTag", 223 DATATYPE_STRING, true, null); 224 225 addAttribute("iTXtEntry", "translatedKeyword", 226 DATATYPE_STRING, true, null); 227 228 addAttribute("iTXtEntry", "text", 229 DATATYPE_STRING, true, null); 230 231 addElement("pHYS", PNGMetadata.nativeMetadataFormatName, 233 CHILD_POLICY_EMPTY); 234 235 addAttribute("pHYS", "pixelsPerUnitXAxis", 236 DATATYPE_INTEGER, true, null, 237 VALUE_0, VALUE_MAX_32, true, true); 238 addAttribute("pHYS", "pixelsPerUnitYAxis", 239 DATATYPE_INTEGER, true, null, 240 VALUE_0, VALUE_MAX_32, true, true); 241 addAttribute("pHYS", "unitSpecifier", 242 DATATYPE_STRING, true, null, 243 Arrays.asList(PNGMetadata.unitSpecifierNames)); 244 245 addElement("sBIT", PNGMetadata.nativeMetadataFormatName, 247 CHILD_POLICY_CHOICE); 248 249 addElement("sBIT_Grayscale", "sBIT", 251 CHILD_POLICY_EMPTY); 252 253 addAttribute("sBIT_Grayscale", "gray", 254 DATATYPE_INTEGER, true, null, 255 VALUE_0, VALUE_255, true, true); 256 257 addElement("sBIT_GrayAlpha", "sBIT", 259 CHILD_POLICY_EMPTY); 260 261 addAttribute("sBIT_GrayAlpha", "gray", 262 DATATYPE_INTEGER, true, null, 263 VALUE_0, VALUE_255, true, true); 264 265 addAttribute("sBIT_GrayAlpha", "alpha", 266 DATATYPE_INTEGER, true, null, 267 VALUE_0, VALUE_255, true, true); 268 269 addElement("sBIT_RGB", "sBIT", 271 CHILD_POLICY_EMPTY); 272 273 addAttribute("sBIT_RGB", "red", 274 DATATYPE_INTEGER, true, null, 275 VALUE_0, VALUE_255, true, true); 276 277 addAttribute("sBIT_RGB", "green", 278 DATATYPE_INTEGER, true, null, 279 VALUE_0, VALUE_255, true, true); 280 281 addAttribute("sBIT_RGB", "blue", 282 DATATYPE_INTEGER, true, null, 283 VALUE_0, VALUE_255, true, true); 284 285 addElement("sBIT_RGBAlpha", "sBIT", 287 CHILD_POLICY_EMPTY); 288 289 addAttribute("sBIT_RGBAlpha", "red", 290 DATATYPE_INTEGER, true, null, 291 VALUE_0, VALUE_255, true, true); 292 293 addAttribute("sBIT_RGBAlpha", "green", 294 DATATYPE_INTEGER, true, null, 295 VALUE_0, VALUE_255, true, true); 296 297 addAttribute("sBIT_RGBAlpha", "blue", 298 DATATYPE_INTEGER, true, null, 299 VALUE_0, VALUE_255, true, true); 300 301 addAttribute("sBIT_RGBAlpha", "alpha", 302 DATATYPE_INTEGER, true, null, 303 VALUE_0, VALUE_255, true, true); 304 305 addElement("sBIT_Palette", "sBIT", 307 CHILD_POLICY_EMPTY); 308 309 addAttribute("sBIT_Palette", "red", 310 DATATYPE_INTEGER, true, null, 311 VALUE_0, VALUE_255, true, true); 312 313 addAttribute("sBIT_Palette", "green", 314 DATATYPE_INTEGER, true, null, 315 VALUE_0, VALUE_255, true, true); 316 317 addAttribute("sBIT_Palette", "blue", 318 DATATYPE_INTEGER, true, null, 319 VALUE_0, VALUE_255, true, true); 320 321 addElement("sPLT", PNGMetadata.nativeMetadataFormatName, 323 1, 256); 324 325 addElement("sPLTEntry", "sPLT", 327 CHILD_POLICY_EMPTY); 328 329 addAttribute("sPLTEntry", "index", 330 DATATYPE_INTEGER, true, null, 331 VALUE_0, VALUE_255, true, true); 332 333 addAttribute("sPLTEntry", "red", 334 DATATYPE_INTEGER, true, null, 335 VALUE_0, VALUE_255, true, true); 336 337 addAttribute("sPLTEntry", "green", 338 DATATYPE_INTEGER, true, null, 339 VALUE_0, VALUE_255, true, true); 340 341 addAttribute("sPLTEntry", "blue", 342 DATATYPE_INTEGER, true, null, 343 VALUE_0, VALUE_255, true, true); 344 345 addAttribute("sPLTEntry", "alpha", 346 DATATYPE_INTEGER, true, null, 347 VALUE_0, VALUE_255, true, true); 348 349 addElement("sRGB", PNGMetadata.nativeMetadataFormatName, 351 CHILD_POLICY_EMPTY); 352 353 addAttribute("sRGB", "renderingIntent", 354 DATATYPE_STRING, true, null, 355 Arrays.asList(PNGMetadata.renderingIntentNames)); 356 357 addElement("tEXt", PNGMetadata.nativeMetadataFormatName, 359 1, Integer.MAX_VALUE); 360 361 addElement("tEXtEntry", "tEXt", 363 CHILD_POLICY_EMPTY); 364 365 addAttribute("tEXtEntry", "keyword", 366 DATATYPE_STRING, true, null); 367 368 addAttribute("tEXtEntry", "value", 369 DATATYPE_STRING, true, null); 370 371 addElement("tIME", PNGMetadata.nativeMetadataFormatName, 373 CHILD_POLICY_EMPTY); 374 375 addAttribute("tIME", "year", 376 DATATYPE_INTEGER, true, null, 377 VALUE_0, VALUE_MAX_16, true, true); 378 379 addAttribute("tIME", "month", 380 DATATYPE_INTEGER, true, null, 381 VALUE_1, VALUE_12, true, true); 382 383 addAttribute("tIME", "day", 384 DATATYPE_INTEGER, true, null, 385 VALUE_1, VALUE_31, true, true); 386 387 addAttribute("tIME", "hour", 388 DATATYPE_INTEGER, true, null, 389 VALUE_0, VALUE_23, true, true); 390 391 addAttribute("tIME", "minute", 392 DATATYPE_INTEGER, true, null, 393 VALUE_0, VALUE_59, true, true); 394 395 addAttribute("tIME", "second", 396 DATATYPE_INTEGER, true, null, 397 VALUE_0, VALUE_60, true, true); 398 399 addElement("tRNS", PNGMetadata.nativeMetadataFormatName, 401 CHILD_POLICY_CHOICE); 402 403 addElement("tRNS_Grayscale", "tRNS", 405 CHILD_POLICY_EMPTY); 406 407 addAttribute("tRNS_Grayscale", "gray", 408 DATATYPE_INTEGER, true, null, 409 VALUE_0, VALUE_MAX_16, true, true); 410 411 addElement("tRNS_RGB", "tRNS", 413 CHILD_POLICY_EMPTY); 414 415 addAttribute("tRNS_RGB", "red", 416 DATATYPE_INTEGER, true, null, 417 VALUE_0, VALUE_MAX_16, true, true); 418 419 addAttribute("tRNS_RGB", "green", 420 DATATYPE_INTEGER, true, null, 421 VALUE_0, VALUE_MAX_16, true, true); 422 423 addAttribute("tRNS_RGB", "blue", 424 DATATYPE_INTEGER, true, null, 425 VALUE_0, VALUE_MAX_16, true, true); 426 427 addElement("tRNS_Palette", "tRNS", 429 CHILD_POLICY_EMPTY); 430 431 addAttribute("tRNS_Palette", "index", 432 DATATYPE_INTEGER, true, null, 433 VALUE_0, VALUE_255, true, true); 434 435 addAttribute("tRNS_Palette", "alpha", 436 DATATYPE_INTEGER, true, null, 437 VALUE_0, VALUE_255, true, true); 438 439 addElement("zTXt", PNGMetadata.nativeMetadataFormatName, 441 1, Integer.MAX_VALUE); 442 443 addElement("zTXtEntry", "zTXt", 445 CHILD_POLICY_EMPTY); 446 447 addAttribute("zTXtEntry", "keyword", 448 DATATYPE_STRING, true, null); 449 450 addAttribute("zTXtEntry", "compressionMethod", 451 DATATYPE_STRING, true, null, 452 Arrays.asList(PNGMetadata.zTXt_compressionMethodNames)); 453 454 addAttribute("zTXtEntry", "text", 455 DATATYPE_STRING, true, null); 456 457 addElement("UnknownChunks", PNGMetadata.nativeMetadataFormatName, 459 1, Integer.MAX_VALUE); 460 461 addElement("UnknownChunk", "UnknownChunks", 463 CHILD_POLICY_EMPTY); 464 465 addAttribute("UnknownChunk", "type", 466 DATATYPE_STRING, true, null); 467 468 addObjectValue("UnknownChunk", byte.class, 0, Integer.MAX_VALUE); 469 } 470 471 public boolean canNodeAppear(String elementName, 472 ImageTypeSpecifier imageType) { 473 return true; 474 } 475 476 public static synchronized IIOMetadataFormat getInstance() { 477 if (instance == null) { 478 instance = new PNGMetadataFormat(); 479 } 480 return instance; 481 } 482 } 483 | Popular Tags |