source: josm/trunk/src/com/drew/metadata/jpeg/JpegDescriptor.java@ 7828

Last change on this file since 7828 was 6127, checked in by bastiK, 12 years ago

applied #8895 - Upgrade metadata-extractor to v. 2.6.4 (patch by ebourg)

File size: 5.0 KB
RevLine 
[4231]1/*
[6127]2 * Copyright 2002-2012 Drew Noakes
[4231]3 *
[6127]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
[4231]7 *
[6127]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/
[4231]20 */
21package com.drew.metadata.jpeg;
22
[6127]23import com.drew.lang.annotations.NotNull;
24import com.drew.lang.annotations.Nullable;
[4231]25import com.drew.metadata.TagDescriptor;
26
27/**
28 * Provides human-readable string versions of the tags stored in a JpegDirectory.
29 * Thanks to Darrell Silver (www.darrellsilver.com) for the initial version of this class.
[6127]30 *
31 * @author Drew Noakes http://drewnoakes.com
[4231]32 */
[6127]33public class JpegDescriptor extends TagDescriptor<JpegDirectory>
[4231]34{
[6127]35 public JpegDescriptor(@NotNull JpegDirectory directory)
[4231]36 {
37 super(directory);
38 }
39
[6127]40 @Nullable
41 public String getDescription(int tagType)
[4231]42 {
43 switch (tagType)
44 {
[6127]45 case JpegDirectory.TAG_JPEG_COMPRESSION_TYPE:
46 return getImageCompressionTypeDescription();
[4231]47 case JpegDirectory.TAG_JPEG_COMPONENT_DATA_1:
48 return getComponentDataDescription(0);
49 case JpegDirectory.TAG_JPEG_COMPONENT_DATA_2:
50 return getComponentDataDescription(1);
51 case JpegDirectory.TAG_JPEG_COMPONENT_DATA_3:
52 return getComponentDataDescription(2);
53 case JpegDirectory.TAG_JPEG_COMPONENT_DATA_4:
54 return getComponentDataDescription(3);
55 case JpegDirectory.TAG_JPEG_DATA_PRECISION:
56 return getDataPrecisionDescription();
57 case JpegDirectory.TAG_JPEG_IMAGE_HEIGHT:
58 return getImageHeightDescription();
59 case JpegDirectory.TAG_JPEG_IMAGE_WIDTH:
60 return getImageWidthDescription();
[6127]61 default:
62 return super.getDescription(tagType);
[4231]63 }
[6127]64 }
[4231]65
[6127]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 }
[4231]91 }
[6127]92 @Nullable
[4231]93 public String getImageWidthDescription()
94 {
[6127]95 final String value = _directory.getString(JpegDirectory.TAG_JPEG_IMAGE_WIDTH);
96 if (value==null)
97 return null;
98 return value + " pixels";
[4231]99 }
100
[6127]101 @Nullable
[4231]102 public String getImageHeightDescription()
103 {
[6127]104 final String value = _directory.getString(JpegDirectory.TAG_JPEG_IMAGE_HEIGHT);
105 if (value==null)
106 return null;
107 return value + " pixels";
[4231]108 }
109
[6127]110 @Nullable
[4231]111 public String getDataPrecisionDescription()
112 {
[6127]113 final String value = _directory.getString(JpegDirectory.TAG_JPEG_DATA_PRECISION);
114 if (value==null)
115 return null;
116 return value + " bits";
[4231]117 }
118
[6127]119 @Nullable
120 public String getComponentDataDescription(int componentNumber)
[4231]121 {
[6127]122 JpegComponent value = _directory.getComponent(componentNumber);
[4231]123
[6127]124 if (value==null)
125 return null;
[4231]126
[6127]127 StringBuilder sb = new StringBuilder();
128 sb.append(value.getComponentName());
[4231]129 sb.append(" component: Quantization table ");
[6127]130 sb.append(value.getQuantizationTableNumber());
[4231]131 sb.append(", Sampling factors ");
[6127]132 sb.append(value.getHorizontalSamplingFactor());
[4231]133 sb.append(" horiz/");
[6127]134 sb.append(value.getVerticalSamplingFactor());
[4231]135 sb.append(" vert");
136 return sb.toString();
137 }
138}
Note: See TracBrowser for help on using the repository browser.