source: josm/trunk/src/com/drew/metadata/jpeg/JpegDirectory.java@ 4231

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

add signpost and metadata extractor code to repository directly

File size: 4.4 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 *
15 * Created on Aug 2, 2003.
16 */
17package com.drew.metadata.jpeg;
18
19import com.drew.metadata.Directory;
20import com.drew.metadata.MetadataException;
21
22import java.util.HashMap;
23
24/**
25 * Directory of tags and values for the SOF0 Jpeg segment. This segment holds basic metadata about the image.
26 * @author Darrell Silver http://www.darrellsilver.com and Drew Noakes
27 */
28public class JpegDirectory extends Directory {
29
30 /** This is in bits/sample, usually 8 (12 and 16 not supported by most software). */
31 public static final int TAG_JPEG_DATA_PRECISION = 0;
32 /** The image's height. Necessary for decoding the image, so it should always be there. */
33 public static final int TAG_JPEG_IMAGE_HEIGHT = 1;
34 /** The image's width. Necessary for decoding the image, so it should always be there. */
35 public static final int TAG_JPEG_IMAGE_WIDTH = 3;
36 /** Usually 1 = grey scaled, 3 = color YcbCr or YIQ, 4 = color CMYK
37 * Each component TAG_COMPONENT_DATA_[1-4], has the following meaning:
38 * component Id(1byte)(1 = Y, 2 = Cb, 3 = Cr, 4 = I, 5 = Q),
39 * sampling factors (1byte) (bit 0-3 vertical., 4-7 horizontal.),
40 * quantization table number (1 byte).
41 * <p>
42 * This info is from http://www.funducode.com/freec/Fileformats/format3/format3b.htm
43 */
44 public static final int TAG_JPEG_NUMBER_OF_COMPONENTS = 5;
45
46 // NOTE! Component tag type int values must increment in steps of 1
47
48 /** the first of a possible 4 color components. Number of components specified in TAG_JPEG_NUMBER_OF_COMPONENTS.*/
49 public static final int TAG_JPEG_COMPONENT_DATA_1 = 6;
50 /** the second of a possible 4 color components. Number of components specified in TAG_JPEG_NUMBER_OF_COMPONENTS.*/
51 public static final int TAG_JPEG_COMPONENT_DATA_2 = 7;
52 /** the third of a possible 4 color components. Number of components specified in TAG_JPEG_NUMBER_OF_COMPONENTS.*/
53 public static final int TAG_JPEG_COMPONENT_DATA_3 = 8;
54 /** the fourth of a possible 4 color components. Number of components specified in TAG_JPEG_NUMBER_OF_COMPONENTS.*/
55 public static final int TAG_JPEG_COMPONENT_DATA_4 = 9;
56
57 protected static final HashMap tagNameMap = new HashMap();
58
59 static {
60 tagNameMap.put(new Integer(TAG_JPEG_DATA_PRECISION), "Data Precision");
61 tagNameMap.put(new Integer(TAG_JPEG_IMAGE_WIDTH), "Image Width");
62 tagNameMap.put(new Integer(TAG_JPEG_IMAGE_HEIGHT), "Image Height");
63 tagNameMap.put(new Integer(TAG_JPEG_NUMBER_OF_COMPONENTS), "Number of Components");
64 tagNameMap.put(new Integer(TAG_JPEG_COMPONENT_DATA_1), "Component 1");
65 tagNameMap.put(new Integer(TAG_JPEG_COMPONENT_DATA_2), "Component 2");
66 tagNameMap.put(new Integer(TAG_JPEG_COMPONENT_DATA_3), "Component 3");
67 tagNameMap.put(new Integer(TAG_JPEG_COMPONENT_DATA_4), "Component 4");
68 }
69
70 public JpegDirectory() {
71 this.setDescriptor(new JpegDescriptor(this));
72 }
73
74 public String getName() {
75 return "Jpeg";
76 }
77
78 protected HashMap getTagNameMap() {
79 return tagNameMap;
80 }
81
82 /**
83 *
84 * @param componentNumber The zero-based index of the component. This number is normally between 0 and 3.
85 * Use getNumberOfComponents for bounds-checking.
86 * @return
87 */
88 public JpegComponent getComponent(int componentNumber)
89 {
90 int tagType = JpegDirectory.TAG_JPEG_COMPONENT_DATA_1 + componentNumber;
91
92 JpegComponent component = (JpegComponent)getObject(tagType);
93
94 return component;
95 }
96
97 public int getImageWidth() throws MetadataException
98 {
99 return getInt(JpegDirectory.TAG_JPEG_IMAGE_WIDTH);
100 }
101
102 public int getImageHeight() throws MetadataException
103 {
104 return getInt(JpegDirectory.TAG_JPEG_IMAGE_HEIGHT);
105 }
106
107 public int getNumberOfComponents() throws MetadataException
108 {
109 return getInt(JpegDirectory.TAG_JPEG_NUMBER_OF_COMPONENTS);
110 }
111}
Note: See TracBrowser for help on using the repository browser.