Changeset 6127 in josm for trunk/src/com/drew/metadata/jpeg/JpegDescriptor.java
- Timestamp:
- 2013-08-09T18:05:11+02:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/com/drew/metadata/jpeg/JpegDescriptor.java
r4231 r6127 1 1 /* 2 * This is public domain software - that is, you can do whatever you want 3 * with it, and include it software that is licensed under the GNU or the 4 * BSD license, or whatever other licence you choose, including proprietary 5 * closed source licenses. I do ask that you leave this header in tact. 2 * Copyright 2002-2012 Drew Noakes 6 3 * 7 * If you make modifications to this code that you think would benefit the 8 * wider community, please send me a copy and I'll post it on my site. 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 9 7 * 10 * If you make use of this code, I'd appreciate hearing about it. 11 * drew@drewnoakes.com 12 * Latest version of this software kept at 13 * http://drewnoakes.com/ 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 * 16 * More information about this project is available at: 17 * 18 * http://drewnoakes.com/code/exif/ 19 * http://code.google.com/p/metadata-extractor/ 14 20 */ 15 21 package com.drew.metadata.jpeg; 16 22 17 import com.drew. metadata.Directory;18 import com.drew. metadata.MetadataException;23 import com.drew.lang.annotations.NotNull; 24 import com.drew.lang.annotations.Nullable; 19 25 import com.drew.metadata.TagDescriptor; 20 26 … … 22 28 * Provides human-readable string versions of the tags stored in a JpegDirectory. 23 29 * Thanks to Darrell Silver (www.darrellsilver.com) for the initial version of this class. 30 * 31 * @author Drew Noakes http://drewnoakes.com 24 32 */ 25 public class JpegDescriptor extends TagDescriptor 33 public class JpegDescriptor extends TagDescriptor<JpegDirectory> 26 34 { 27 public JpegDescriptor(Directory directory) 35 public JpegDescriptor(@NotNull JpegDirectory directory) 28 36 { 29 37 super(directory); 30 38 } 31 39 32 public String getDescription(int tagType) throws MetadataException 40 @Nullable 41 public String getDescription(int tagType) 33 42 { 34 43 switch (tagType) 35 44 { 45 case JpegDirectory.TAG_JPEG_COMPRESSION_TYPE: 46 return getImageCompressionTypeDescription(); 36 47 case JpegDirectory.TAG_JPEG_COMPONENT_DATA_1: 37 48 return getComponentDataDescription(0); … … 48 59 case JpegDirectory.TAG_JPEG_IMAGE_WIDTH: 49 60 return getImageWidthDescription(); 61 default: 62 return super.getDescription(tagType); 50 63 } 51 52 return _directory.getString(tagType);53 64 } 54 65 66 @Nullable 67 public String getImageCompressionTypeDescription() 68 { 69 Integer value = _directory.getInteger(JpegDirectory.TAG_JPEG_COMPRESSION_TYPE); 70 if (value==null) 71 return null; 72 // Note there is no 2 or 12 73 switch (value) { 74 case 0: return "Baseline"; 75 case 1: return "Extended sequential, Huffman"; 76 case 2: return "Progressive, Huffman"; 77 case 3: return "Lossless, Huffman"; 78 case 5: return "Differential sequential, Huffman"; 79 case 6: return "Differential progressive, Huffman"; 80 case 7: return "Differential lossless, Huffman"; 81 case 8: return "Reserved for JPEG extensions"; 82 case 9: return "Extended sequential, arithmetic"; 83 case 10: return "Progressive, arithmetic"; 84 case 11: return "Lossless, arithmetic"; 85 case 13: return "Differential sequential, arithmetic"; 86 case 14: return "Differential progressive, arithmetic"; 87 case 15: return "Differential lossless, arithmetic"; 88 default: 89 return "Unknown type: "+ value; 90 } 91 } 92 @Nullable 55 93 public String getImageWidthDescription() 56 94 { 57 return _directory.getString(JpegDirectory.TAG_JPEG_IMAGE_WIDTH) + " pixels"; 95 final String value = _directory.getString(JpegDirectory.TAG_JPEG_IMAGE_WIDTH); 96 if (value==null) 97 return null; 98 return value + " pixels"; 58 99 } 59 100 101 @Nullable 60 102 public String getImageHeightDescription() 61 103 { 62 return _directory.getString(JpegDirectory.TAG_JPEG_IMAGE_HEIGHT) + " pixels"; 104 final String value = _directory.getString(JpegDirectory.TAG_JPEG_IMAGE_HEIGHT); 105 if (value==null) 106 return null; 107 return value + " pixels"; 63 108 } 64 109 110 @Nullable 65 111 public String getDataPrecisionDescription() 66 112 { 67 return _directory.getString(JpegDirectory.TAG_JPEG_DATA_PRECISION) + " bits"; 113 final String value = _directory.getString(JpegDirectory.TAG_JPEG_DATA_PRECISION); 114 if (value==null) 115 return null; 116 return value + " bits"; 68 117 } 69 118 70 public String getComponentDataDescription(int componentNumber) throws MetadataException 119 @Nullable 120 public String getComponentDataDescription(int componentNumber) 71 121 { 72 JpegComponent component = ((JpegDirectory)_directory).getComponent(componentNumber);122 JpegComponent value = _directory.getComponent(componentNumber); 73 123 74 if ( component==null)75 throw new MetadataException("No Jpeg component exists with number " + componentNumber);124 if (value==null) 125 return null; 76 126 77 StringBu ffer sb = new StringBuffer();78 sb.append( component.getComponentName());127 StringBuilder sb = new StringBuilder(); 128 sb.append(value.getComponentName()); 79 129 sb.append(" component: Quantization table "); 80 sb.append( component.getQuantizationTableNumber());130 sb.append(value.getQuantizationTableNumber()); 81 131 sb.append(", Sampling factors "); 82 sb.append( component.getHorizontalSamplingFactor());132 sb.append(value.getHorizontalSamplingFactor()); 83 133 sb.append(" horiz/"); 84 sb.append( component.getVerticalSamplingFactor());134 sb.append(value.getVerticalSamplingFactor()); 85 135 sb.append(" vert"); 86 136 return sb.toString();
Note:
See TracChangeset
for help on using the changeset viewer.