1 | /*
|
---|
2 | * Copyright 2002-2016 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 | */
|
---|
21 | package com.drew.metadata.jpeg;
|
---|
22 |
|
---|
23 | import com.drew.lang.annotations.NotNull;
|
---|
24 | import com.drew.lang.annotations.Nullable;
|
---|
25 | import com.drew.metadata.TagDescriptor;
|
---|
26 |
|
---|
27 | import static com.drew.metadata.jpeg.JpegDirectory.*;
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * Provides human-readable string versions of the tags stored in a JpegDirectory.
|
---|
31 | * Thanks to Darrell Silver (www.darrellsilver.com) for the initial version of this class.
|
---|
32 | *
|
---|
33 | * @author Drew Noakes https://drewnoakes.com
|
---|
34 | */
|
---|
35 | public class JpegDescriptor extends TagDescriptor<JpegDirectory>
|
---|
36 | {
|
---|
37 | public JpegDescriptor(@NotNull JpegDirectory directory)
|
---|
38 | {
|
---|
39 | super(directory);
|
---|
40 | }
|
---|
41 |
|
---|
42 | @Override
|
---|
43 | @Nullable
|
---|
44 | public String getDescription(int tagType)
|
---|
45 | {
|
---|
46 | switch (tagType)
|
---|
47 | {
|
---|
48 | case TAG_COMPRESSION_TYPE:
|
---|
49 | return getImageCompressionTypeDescription();
|
---|
50 | case TAG_COMPONENT_DATA_1:
|
---|
51 | return getComponentDataDescription(0);
|
---|
52 | case TAG_COMPONENT_DATA_2:
|
---|
53 | return getComponentDataDescription(1);
|
---|
54 | case TAG_COMPONENT_DATA_3:
|
---|
55 | return getComponentDataDescription(2);
|
---|
56 | case TAG_COMPONENT_DATA_4:
|
---|
57 | return getComponentDataDescription(3);
|
---|
58 | case TAG_DATA_PRECISION:
|
---|
59 | return getDataPrecisionDescription();
|
---|
60 | case TAG_IMAGE_HEIGHT:
|
---|
61 | return getImageHeightDescription();
|
---|
62 | case TAG_IMAGE_WIDTH:
|
---|
63 | return getImageWidthDescription();
|
---|
64 | default:
|
---|
65 | return super.getDescription(tagType);
|
---|
66 | }
|
---|
67 | }
|
---|
68 |
|
---|
69 | @Nullable
|
---|
70 | public String getImageCompressionTypeDescription()
|
---|
71 | {
|
---|
72 | return getIndexedDescription(TAG_COMPRESSION_TYPE,
|
---|
73 | "Baseline",
|
---|
74 | "Extended sequential, Huffman",
|
---|
75 | "Progressive, Huffman",
|
---|
76 | "Lossless, Huffman",
|
---|
77 | null, // no 4
|
---|
78 | "Differential sequential, Huffman",
|
---|
79 | "Differential progressive, Huffman",
|
---|
80 | "Differential lossless, Huffman",
|
---|
81 | "Reserved for JPEG extensions",
|
---|
82 | "Extended sequential, arithmetic",
|
---|
83 | "Progressive, arithmetic",
|
---|
84 | "Lossless, arithmetic",
|
---|
85 | null, // no 12
|
---|
86 | "Differential sequential, arithmetic",
|
---|
87 | "Differential progressive, arithmetic",
|
---|
88 | "Differential lossless, arithmetic");
|
---|
89 | }
|
---|
90 |
|
---|
91 | @Nullable
|
---|
92 | public String getImageWidthDescription()
|
---|
93 | {
|
---|
94 | final String value = _directory.getString(TAG_IMAGE_WIDTH);
|
---|
95 | if (value==null)
|
---|
96 | return null;
|
---|
97 | return value + " pixels";
|
---|
98 | }
|
---|
99 |
|
---|
100 | @Nullable
|
---|
101 | public String getImageHeightDescription()
|
---|
102 | {
|
---|
103 | final String value = _directory.getString(TAG_IMAGE_HEIGHT);
|
---|
104 | if (value==null)
|
---|
105 | return null;
|
---|
106 | return value + " pixels";
|
---|
107 | }
|
---|
108 |
|
---|
109 | @Nullable
|
---|
110 | public String getDataPrecisionDescription()
|
---|
111 | {
|
---|
112 | final String value = _directory.getString(TAG_DATA_PRECISION);
|
---|
113 | if (value==null)
|
---|
114 | return null;
|
---|
115 | return value + " bits";
|
---|
116 | }
|
---|
117 |
|
---|
118 | @Nullable
|
---|
119 | public String getComponentDataDescription(int componentNumber)
|
---|
120 | {
|
---|
121 | JpegComponent value = _directory.getComponent(componentNumber);
|
---|
122 |
|
---|
123 | if (value==null)
|
---|
124 | return null;
|
---|
125 |
|
---|
126 | return value.getComponentName() + " component: Quantization table " + value.getQuantizationTableNumber()
|
---|
127 | + ", Sampling factors " + value.getHorizontalSamplingFactor()
|
---|
128 | + " horiz/" + value.getVerticalSamplingFactor() + " vert";
|
---|
129 | }
|
---|
130 | }
|
---|