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

Last change on this file since 8510 was 8132, checked in by Don-vip, 11 years ago

fix #11162 - update to metadata-extractor 2.7.2

File size: 4.8 KB
Line 
1/*
2 * Copyright 2002-2015 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 * https://drewnoakes.com/code/exif/
19 * https://github.com/drewnoakes/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 https://drewnoakes.com
34 */
35public class JpegDirectory extends Directory
36{
37 public static final int TAG_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_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_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_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_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_NUMBER_OF_COMPONENTS. */
58 public static final int TAG_COMPONENT_DATA_1 = 6;
59 /** the second of a possible 4 color components. Number of components specified in TAG_NUMBER_OF_COMPONENTS. */
60 public static final int TAG_COMPONENT_DATA_2 = 7;
61 /** the third of a possible 4 color components. Number of components specified in TAG_NUMBER_OF_COMPONENTS. */
62 public static final int TAG_COMPONENT_DATA_3 = 8;
63 /** the fourth of a possible 4 color components. Number of components specified in TAG_NUMBER_OF_COMPONENTS. */
64 public static final int TAG_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_COMPRESSION_TYPE, "Compression Type");
71 _tagNameMap.put(TAG_DATA_PRECISION, "Data Precision");
72 _tagNameMap.put(TAG_IMAGE_WIDTH, "Image Width");
73 _tagNameMap.put(TAG_IMAGE_HEIGHT, "Image Height");
74 _tagNameMap.put(TAG_NUMBER_OF_COMPONENTS, "Number of Components");
75 _tagNameMap.put(TAG_COMPONENT_DATA_1, "Component 1");
76 _tagNameMap.put(TAG_COMPONENT_DATA_2, "Component 2");
77 _tagNameMap.put(TAG_COMPONENT_DATA_3, "Component 3");
78 _tagNameMap.put(TAG_COMPONENT_DATA_4, "Component 4");
79 }
80
81 public JpegDirectory()
82 {
83 this.setDescriptor(new JpegDescriptor(this));
84 }
85
86 @Override
87 @NotNull
88 public String getName()
89 {
90 return "JPEG";
91 }
92
93 @Override
94 @NotNull
95 protected HashMap<Integer, String> getTagNameMap()
96 {
97 return _tagNameMap;
98 }
99
100 /**
101 * @param componentNumber The zero-based index of the component. This number is normally between 0 and 3.
102 * Use getNumberOfComponents for bounds-checking.
103 * @return the JpegComponent having the specified number.
104 */
105 @Nullable
106 public JpegComponent getComponent(int componentNumber)
107 {
108 int tagType = JpegDirectory.TAG_COMPONENT_DATA_1 + componentNumber;
109 return (JpegComponent)getObject(tagType);
110 }
111
112 public int getImageWidth() throws MetadataException
113 {
114 return getInt(JpegDirectory.TAG_IMAGE_WIDTH);
115 }
116
117 public int getImageHeight() throws MetadataException
118 {
119 return getInt(JpegDirectory.TAG_IMAGE_HEIGHT);
120 }
121
122 public int getNumberOfComponents() throws MetadataException
123 {
124 return getInt(JpegDirectory.TAG_NUMBER_OF_COMPONENTS);
125 }
126}
Note: See TracBrowser for help on using the repository browser.