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

Last change on this file since 15217 was 15217, checked in by Don-vip, 5 years ago

see #17848 - update to metadata-extractor 2.12.0

File size: 4.8 KB
Line 
1/*
2 * Copyright 2002-2019 Drew Noakes and contributors
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 */
35@SuppressWarnings("WeakerAccess")
36public class JpegDirectory extends Directory
37{
38 public static final int TAG_COMPRESSION_TYPE = -3;
39 /** This is in bits/sample, usually 8 (12 and 16 not supported by most software). */
40 public static final int TAG_DATA_PRECISION = 0;
41 /** The image's height. Necessary for decoding the image, so it should always be there. */
42 public static final int TAG_IMAGE_HEIGHT = 1;
43 /** The image's width. Necessary for decoding the image, so it should always be there. */
44 public static final int TAG_IMAGE_WIDTH = 3;
45 /**
46 * Usually 1 = grey scaled, 3 = color YcbCr or YIQ, 4 = color CMYK
47 * Each component TAG_COMPONENT_DATA_[1-4], has the following meaning:
48 * component Id(1byte)(1 = Y, 2 = Cb, 3 = Cr, 4 = I, 5 = Q),
49 * sampling factors (1byte) (bit 0-3 vertical., 4-7 horizontal.),
50 * quantization table number (1 byte).
51 * <p>
52 * This info is from http://www.funducode.com/freec/Fileformats/format3/format3b.htm
53 */
54 public static final int TAG_NUMBER_OF_COMPONENTS = 5;
55
56 // NOTE! Component tag type int values must increment in steps of 1
57
58 /** the first of a possible 4 color components. Number of components specified in TAG_NUMBER_OF_COMPONENTS. */
59 public static final int TAG_COMPONENT_DATA_1 = 6;
60 /** the second of a possible 4 color components. Number of components specified in TAG_NUMBER_OF_COMPONENTS. */
61 public static final int TAG_COMPONENT_DATA_2 = 7;
62 /** the third of a possible 4 color components. Number of components specified in TAG_NUMBER_OF_COMPONENTS. */
63 public static final int TAG_COMPONENT_DATA_3 = 8;
64 /** the fourth of a possible 4 color components. Number of components specified in TAG_NUMBER_OF_COMPONENTS. */
65 public static final int TAG_COMPONENT_DATA_4 = 9;
66
67 @NotNull
68 protected static final HashMap<Integer, String> _tagNameMap = new HashMap<Integer, String>();
69
70 static {
71 _tagNameMap.put(TAG_COMPRESSION_TYPE, "Compression Type");
72 _tagNameMap.put(TAG_DATA_PRECISION, "Data Precision");
73 _tagNameMap.put(TAG_IMAGE_WIDTH, "Image Width");
74 _tagNameMap.put(TAG_IMAGE_HEIGHT, "Image Height");
75 _tagNameMap.put(TAG_NUMBER_OF_COMPONENTS, "Number of Components");
76 _tagNameMap.put(TAG_COMPONENT_DATA_1, "Component 1");
77 _tagNameMap.put(TAG_COMPONENT_DATA_2, "Component 2");
78 _tagNameMap.put(TAG_COMPONENT_DATA_3, "Component 3");
79 _tagNameMap.put(TAG_COMPONENT_DATA_4, "Component 4");
80 }
81
82 public JpegDirectory()
83 {
84 this.setDescriptor(new JpegDescriptor(this));
85 }
86
87 @Override
88 @NotNull
89 public String getName()
90 {
91 return "JPEG";
92 }
93
94 @Override
95 @NotNull
96 protected HashMap<Integer, String> getTagNameMap()
97 {
98 return _tagNameMap;
99 }
100
101 /**
102 * @param componentNumber The zero-based index of the component. This number is normally between 0 and 3.
103 * Use getNumberOfComponents for bounds-checking.
104 * @return the JpegComponent having the specified number.
105 */
106 @Nullable
107 public JpegComponent getComponent(int componentNumber)
108 {
109 int tagType = JpegDirectory.TAG_COMPONENT_DATA_1 + componentNumber;
110 return (JpegComponent)getObject(tagType);
111 }
112
113 public int getImageWidth() throws MetadataException
114 {
115 return getInt(JpegDirectory.TAG_IMAGE_WIDTH);
116 }
117
118 public int getImageHeight() throws MetadataException
119 {
120 return getInt(JpegDirectory.TAG_IMAGE_HEIGHT);
121 }
122
123 public int getNumberOfComponents() throws MetadataException
124 {
125 return getInt(JpegDirectory.TAG_NUMBER_OF_COMPONENTS);
126 }
127}
Note: See TracBrowser for help on using the repository browser.