1 7 8 package org.jboss.media.format.image.iio; 9 10 import javax.imageio.metadata.IIOMetadata ; 11 12 import org.w3c.dom.Node ; 13 14 21 public class StandardMediaHeader extends IIOMediaHeader 22 { 23 private static final long serialVersionUID = 0L; 25 26 private static final String STANDARD_METADATA_FORMAT_NAME = 27 "javax_imageio_1.0"; 28 29 private static final String [] FIELD_NAMES = 30 { 31 "colorSpaceType", 32 "numChannels", 33 "gamma", 34 "blackIsZero", 35 "compressionTypeName", 36 "lossless", 37 "numProgressiveScans", 38 "bitRate", 39 "planarConfiguration", 40 "sampleFormat", 41 "bitsPerSample", 42 "significantBitsPerSample", 43 "sampleMSB", 44 "pixelAspectRatio", 45 "imageOrientation", 46 "horizontalPixelSize", 47 "verticalPixelSize", 48 "horizontalPhysicalPixelSpacing", 49 "verticalPhysicalPixelSpacing", 50 "horizontalPosition", 51 "verticalPosition", 52 "horizontalPixelOffset", 53 "verticalPixelOffset", 54 "horizontalScreenSize", 55 "verticalScreenSize", 56 "formatVersion", 57 "subimageInterpretation", 58 "imageCreationYear" }; 59 60 66 public StandardMediaHeader(IIOMetadata imageMetadata) 67 { 68 super(imageMetadata, STANDARD_METADATA_FORMAT_NAME); 69 } 70 71 74 public String [] getFieldNames() 75 { 76 return FIELD_NAMES; 77 } 78 79 82 public Object getField(String fieldname) 83 { 84 Object field = null; 85 86 if (fieldname.equals("colorSpaceType")) 87 { 88 field = getColorSpaceType(); 89 } 90 91 if (fieldname.equals("numChannels")) 92 { 93 field = getNumChannels(); 94 } 95 96 if (fieldname.equals("gamma")) 97 { 98 field = new Float (getGamma()); 99 } 100 101 if (fieldname.equals("blackIsZero")) 102 { 103 field = getBlackIsZero(); 104 } 105 106 if (fieldname.equals("compressionTypeName")) 107 { 108 field = getCompressionTypeName(); 109 } 110 111 if (fieldname.equals("lossless")) 112 { 113 field = getLossless(); 114 } 115 116 if (fieldname.equals("numProgressiveScans")) 117 { 118 field = new Integer (getNumProgressiveScans()); 119 } 120 121 if (fieldname.equals("bitRate")) 122 { 123 field = new Float (getBitRate()); 124 } 125 126 if (fieldname.equals("planarConfiguration")) 127 { 128 field = getPlanarConfiguration(); 129 } 130 131 if (fieldname.equals("sampleFormat")) 132 { 133 field = getSampleFormat(); 134 } 135 136 if (fieldname.equals("bitsPerSample")) 137 { 138 field = getBitsPerSample(); 139 } 140 141 if (fieldname.equals("significantBitsPerSample")) 142 { 143 field = getSignificantBitsPerSample(); 144 } 145 146 if (fieldname.equals("sampleMSB")) 147 { 148 field = getSampleMSB(); 149 } 150 151 if (fieldname.equals("pixelAspectRatio")) 152 { 153 field = new Float (getPixelAspectRatio()); 154 } 155 156 if (fieldname.equals("imageOrientation")) 157 { 158 field = getImageOrientation(); 159 } 160 161 if (fieldname.equals("horizontalPixelSize")) 162 { 163 field = new Float (getHorizontalPixelSize()); 164 } 165 166 if (fieldname.equals("verticalPixelSize")) 167 { 168 field = new Float (getVerticalPixelSize()); 169 } 170 171 if (fieldname.equals("horizontalPhysicalPixelSpacing")) 172 { 173 field = new Float (getHorizontalPhysicalPixelSpacing()); 174 } 175 176 if (fieldname.equals("verticalPhysicalPixelSpacing")) 177 { 178 field = new Float (getVerticalPhysicalPixelSpacing()); 179 } 180 181 if (fieldname.equals("horizontalPosition")) 182 { 183 field = new Float (getHorizontalPosition()); 184 } 185 186 if (fieldname.equals("verticalPosition")) 187 { 188 field = new Float (getVerticalPosition()); 189 } 190 191 if (fieldname.equals("horizontalPixelOffset")) 192 { 193 field = new Integer (getHorizontalPixelOffset()); 194 } 195 196 if (fieldname.equals("verticalPixelOffset")) 197 { 198 field = new Integer (getVerticalPixelOffset()); 199 } 200 201 if (fieldname.equals("horizontalScreenSize")) 202 { 203 field = new Integer (getHorizontalScreenSize()); 204 } 205 206 if (fieldname.equals("verticalScreenSize")) 207 { 208 field = new Integer (getVerticalScreenSize()); 209 } 210 211 if (fieldname.equals("formatVersion")) 212 { 213 field = getFormatVersion(); 214 } 215 216 if (fieldname.equals("subimageInterpretation")) 217 { 218 field = getSubimageInterpretation(); 219 } 220 221 if (fieldname.equals("imageCreationYear")) 222 { 223 field = new Integer (getImageCreationYear()); 224 } 225 226 return field; 227 } 228 229 237 public String getColorSpaceType() 238 { 239 Node chroma = getChromaNode(); 240 Node colorSpaceType = getNode(chroma, "ColorSpaceType"); 241 return getAttribute(colorSpaceType, "name"); 242 } 243 244 249 public String getNumChannels() 250 { 251 Node chroma = getChromaNode(); 252 Node numChannels = getNode(chroma, "NumChannels"); 253 return getAttribute(numChannels, "value"); 254 } 255 256 261 public float getGamma() 262 { 263 Node chroma = getChromaNode(); 264 Node gamma = getNode(chroma, "Gamma"); 265 String value = getAttribute(gamma, "value"); 266 return Float.parseFloat(value); 267 } 268 269 274 public String getBlackIsZero() 275 { 276 Node chroma = getChromaNode(); 277 Node blackIsZero = getNode(chroma, "BlackIsZero"); 278 return getAttribute(blackIsZero, "value"); 279 } 280 281 286 public String getCompressionTypeName() 287 { 288 Node compression = getCompressionNode(); 289 Node compressionTypeName = getNode(compression, "CompressionTypeName"); 290 return getAttribute(compressionTypeName, "value"); 291 } 292 293 298 public String getLossless() 299 { 300 Node compression = getCompressionNode(); 301 Node lossless = getNode(compression, "Lossless"); 302 return getAttribute(lossless, "value"); 303 } 304 305 310 public int getNumProgressiveScans() 311 { 312 Node compression = getCompressionNode(); 313 Node numProgressiveScans = getNode(compression, "NumProgressiveScans"); 314 String value = getAttribute(numProgressiveScans, "value"); 315 return Integer.parseInt(value); 316 } 317 318 323 public float getBitRate() 324 { 325 Node compression = getCompressionNode(); 326 Node bitRate = getNode(compression, "BitRate"); 327 String value = getAttribute(bitRate, "value"); 328 return value == null ? 0 : Float.parseFloat(value); 329 } 330 331 337 public String getPlanarConfiguration() 338 { 339 Node data = getDataNode(); 340 Node planarConfiguration = getNode(data, "PlanarConfiguration"); 341 return getAttribute(planarConfiguration, "value"); 342 } 343 344 349 public String getSampleFormat() 350 { 351 Node data = getDataNode(); 352 Node sampleFormat = getNode(data, "SampleFormat"); 353 return getAttribute(sampleFormat, "value"); 354 } 355 356 361 public String getBitsPerSample() 362 { 363 Node data = getDataNode(); 364 Node bitsPerSample = getNode(data, "BitsPerSample"); 365 return getAttribute(bitsPerSample, "value"); 366 } 367 368 373 public String getSignificantBitsPerSample() 374 { 375 Node data = getDataNode(); 376 Node significantBitsPerSample = getNode(data, "SignificantBitsPerSample"); 377 return getAttribute(significantBitsPerSample, "value"); 378 } 379 380 385 public String getSampleMSB() 386 { 387 Node data = getDataNode(); 388 Node sampleMSB = getNode(data, "SampleMSB"); 389 return getAttribute(sampleMSB, "value"); 390 } 391 392 397 public float getPixelAspectRatio() 398 { 399 Node dimension = getDimensionNode(); 400 Node pixelAspectRatio = getNode(dimension, "PixelAspectRatio"); 401 String value = getAttribute(pixelAspectRatio, "value"); 402 return Float.parseFloat(value); 403 } 404 405 411 public String getImageOrientation() 412 { 413 Node dimension = getDimensionNode(); 414 Node imageOrientation = getNode(dimension, "ImageOrientation"); 415 return getAttribute(imageOrientation, "value"); 416 } 417 418 423 public float getHorizontalPixelSize() 424 { 425 Node dimension = getDimensionNode(); 426 Node horizontalPixelSize = getNode(dimension, "HorizontalPixelSize"); 427 String value = getAttribute(horizontalPixelSize, "value"); 428 return Float.parseFloat(value); 429 } 430 431 436 public float getVerticalPixelSize() 437 { 438 Node dimension = getDimensionNode(); 439 Node verticalPixelSize = getNode(dimension, "VerticalPixelSize"); 440 String value = getAttribute(verticalPixelSize, "value"); 441 return Float.parseFloat(value); 442 } 443 444 450 public float getHorizontalPhysicalPixelSpacing() 451 { 452 Node dimension = getDimensionNode(); 453 Node horizontalPhysicalPixelSpacing = 454 getNode(dimension, "HorizontalPhysicalPixelSpacing"); 455 String value = getAttribute(horizontalPhysicalPixelSpacing, "value"); 456 return value == null ? 0 : Float.parseFloat(value); 457 } 458 459 465 public float getVerticalPhysicalPixelSpacing() 466 { 467 Node dimension = getDimensionNode(); 468 Node verticalPhysicalPixelSpacing = 469 getNode(dimension, "VerticalPhysicalPixelSpacing"); 470 String value = getAttribute(verticalPhysicalPixelSpacing, "value"); 471 return value == null ? 0 : Float.parseFloat(value); 472 } 473 474 480 public float getHorizontalPosition() 481 { 482 Node dimension = getDimensionNode(); 483 Node horizontalPosition = getNode(dimension, "HorizontalPosition"); 484 String value = getAttribute(horizontalPosition, "value"); 485 return value == null ? 0 : Float.parseFloat(value); 486 } 487 488 494 public float getVerticalPosition() 495 { 496 Node dimension = getDimensionNode(); 497 Node verticalPosition = getNode(dimension, "VerticalPosition"); 498 String value = getAttribute(verticalPosition, "value"); 499 return value == null ? 0 : Float.parseFloat(value); 500 } 501 502 508 public int getHorizontalPixelOffset() 509 { 510 Node dimension = getDimensionNode(); 511 Node horizontalPixelOffset = getNode(dimension, "HorizontalPixelOffset"); 512 String value = getAttribute(horizontalPixelOffset, "value"); 513 return value == null ? 0 : Integer.parseInt(value); 514 } 515 516 522 public int getVerticalPixelOffset() 523 { 524 Node dimension = getDimensionNode(); 525 Node verticalPixelOffset = getNode(dimension, "VerticalPixelOffset"); 526 String value = getAttribute(verticalPixelOffset, "value"); 527 return value == null ? 0 : Integer.parseInt(value); 528 } 529 530 536 public int getHorizontalScreenSize() 537 { 538 Node dimension = getDimensionNode(); 539 Node horizontalScreenSize = getNode(dimension, "HorizontalScreenSize"); 540 String value = getAttribute(horizontalScreenSize, "value"); 541 return value == null ? 0 : Integer.parseInt(value); 542 } 543 544 550 public int getVerticalScreenSize() 551 { 552 Node dimension = getDimensionNode(); 553 Node verticalScreenSize = getNode(dimension, "VerticalScreenSize"); 554 String value = getAttribute(verticalScreenSize, "value"); 555 return value == null ? 0 : Integer.parseInt(value); 556 } 557 558 563 public String getFormatVersion() 564 { 565 Node document = getDocumentNode(); 566 Node formatVersion = getNode(document, "FormatVersion"); 567 return getAttribute(formatVersion, "value"); 568 } 569 570 579 public String getSubimageInterpretation() 580 { 581 Node document = getDocumentNode(); 582 Node subimageInterpretation = getNode(document, "SubimageInterpretation"); 583 return getAttribute(subimageInterpretation, "value"); 584 } 585 586 591 public int getImageCreationYear() 592 { 593 Node document = getDocumentNode(); 594 Node formatVersion = getNode(document, "ImageCreationTime"); 595 String value = getAttribute(formatVersion, "year"); 596 return value == null ? 0 : Integer.parseInt(value); 597 } 598 599 private Node getChromaNode() 601 { 602 return getNode("Chroma"); 603 } 604 605 private Node getCompressionNode() 606 { 607 return getNode("Compression"); 608 } 609 610 private Node getDataNode() 611 { 612 return getNode("Data"); 613 } 614 615 private Node getDimensionNode() 616 { 617 return getNode("Dimension"); 618 } 619 620 private Node getDocumentNode() 621 { 622 return getNode("Document"); 623 } 624 625 692 } 693 | Popular Tags |