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

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