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

Last change on this file since 5601 was 4231, checked in by stoecker, 14 years ago

add signpost and metadata extractor code to repository directly

File size: 3.3 KB
Line 
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.
6 *
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.
9 *
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/
14 */
15package com.drew.metadata.jpeg;
16
17import com.drew.metadata.Directory;
18import com.drew.metadata.MetadataException;
19import com.drew.metadata.TagDescriptor;
20
21/**
22 * Provides human-readable string versions of the tags stored in a JpegDirectory.
23 * Thanks to Darrell Silver (www.darrellsilver.com) for the initial version of this class.
24 */
25public class JpegDescriptor extends TagDescriptor
26{
27 public JpegDescriptor(Directory directory)
28 {
29 super(directory);
30 }
31
32 public String getDescription(int tagType) throws MetadataException
33 {
34 switch (tagType)
35 {
36 case JpegDirectory.TAG_JPEG_COMPONENT_DATA_1:
37 return getComponentDataDescription(0);
38 case JpegDirectory.TAG_JPEG_COMPONENT_DATA_2:
39 return getComponentDataDescription(1);
40 case JpegDirectory.TAG_JPEG_COMPONENT_DATA_3:
41 return getComponentDataDescription(2);
42 case JpegDirectory.TAG_JPEG_COMPONENT_DATA_4:
43 return getComponentDataDescription(3);
44 case JpegDirectory.TAG_JPEG_DATA_PRECISION:
45 return getDataPrecisionDescription();
46 case JpegDirectory.TAG_JPEG_IMAGE_HEIGHT:
47 return getImageHeightDescription();
48 case JpegDirectory.TAG_JPEG_IMAGE_WIDTH:
49 return getImageWidthDescription();
50 }
51
52 return _directory.getString(tagType);
53 }
54
55 public String getImageWidthDescription()
56 {
57 return _directory.getString(JpegDirectory.TAG_JPEG_IMAGE_WIDTH) + " pixels";
58 }
59
60 public String getImageHeightDescription()
61 {
62 return _directory.getString(JpegDirectory.TAG_JPEG_IMAGE_HEIGHT) + " pixels";
63 }
64
65 public String getDataPrecisionDescription()
66 {
67 return _directory.getString(JpegDirectory.TAG_JPEG_DATA_PRECISION) + " bits";
68 }
69
70 public String getComponentDataDescription(int componentNumber) throws MetadataException
71 {
72 JpegComponent component = ((JpegDirectory)_directory).getComponent(componentNumber);
73
74 if (component==null)
75 throw new MetadataException("No Jpeg component exists with number " + componentNumber);
76
77 StringBuffer sb = new StringBuffer();
78 sb.append(component.getComponentName());
79 sb.append(" component: Quantization table ");
80 sb.append(component.getQuantizationTableNumber());
81 sb.append(", Sampling factors ");
82 sb.append(component.getHorizontalSamplingFactor());
83 sb.append(" horiz/");
84 sb.append(component.getVerticalSamplingFactor());
85 sb.append(" vert");
86 return sb.toString();
87 }
88}
Note: See TracBrowser for help on using the repository browser.