1 | /*
|
---|
2 | * Copyright 2002-2017 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 | @SuppressWarnings("WeakerAccess")
|
---|
36 | public class JpegDescriptor extends TagDescriptor<JpegDirectory>
|
---|
37 | {
|
---|
38 | public JpegDescriptor(@NotNull JpegDirectory directory)
|
---|
39 | {
|
---|
40 | super(directory);
|
---|
41 | }
|
---|
42 |
|
---|
43 | @Override
|
---|
44 | @Nullable
|
---|
45 | public String getDescription(int tagType)
|
---|
46 | {
|
---|
47 | switch (tagType)
|
---|
48 | {
|
---|
49 | case TAG_COMPRESSION_TYPE:
|
---|
50 | return getImageCompressionTypeDescription();
|
---|
51 | case TAG_COMPONENT_DATA_1:
|
---|
52 | return getComponentDataDescription(0);
|
---|
53 | case TAG_COMPONENT_DATA_2:
|
---|
54 | return getComponentDataDescription(1);
|
---|
55 | case TAG_COMPONENT_DATA_3:
|
---|
56 | return getComponentDataDescription(2);
|
---|
57 | case TAG_COMPONENT_DATA_4:
|
---|
58 | return getComponentDataDescription(3);
|
---|
59 | case TAG_DATA_PRECISION:
|
---|
60 | return getDataPrecisionDescription();
|
---|
61 | case TAG_IMAGE_HEIGHT:
|
---|
62 | return getImageHeightDescription();
|
---|
63 | case TAG_IMAGE_WIDTH:
|
---|
64 | return getImageWidthDescription();
|
---|
65 | default:
|
---|
66 | return super.getDescription(tagType);
|
---|
67 | }
|
---|
68 | }
|
---|
69 |
|
---|
70 | @Nullable
|
---|
71 | public String getImageCompressionTypeDescription()
|
---|
72 | {
|
---|
73 | return getIndexedDescription(TAG_COMPRESSION_TYPE,
|
---|
74 | "Baseline",
|
---|
75 | "Extended sequential, Huffman",
|
---|
76 | "Progressive, Huffman",
|
---|
77 | "Lossless, Huffman",
|
---|
78 | null, // no 4
|
---|
79 | "Differential sequential, Huffman",
|
---|
80 | "Differential progressive, Huffman",
|
---|
81 | "Differential lossless, Huffman",
|
---|
82 | "Reserved for JPEG extensions",
|
---|
83 | "Extended sequential, arithmetic",
|
---|
84 | "Progressive, arithmetic",
|
---|
85 | "Lossless, arithmetic",
|
---|
86 | null, // no 12
|
---|
87 | "Differential sequential, arithmetic",
|
---|
88 | "Differential progressive, arithmetic",
|
---|
89 | "Differential lossless, arithmetic");
|
---|
90 | }
|
---|
91 |
|
---|
92 | @Nullable
|
---|
93 | public String getImageWidthDescription()
|
---|
94 | {
|
---|
95 | final String value = _directory.getString(TAG_IMAGE_WIDTH);
|
---|
96 | if (value==null)
|
---|
97 | return null;
|
---|
98 | return value + " pixels";
|
---|
99 | }
|
---|
100 |
|
---|
101 | @Nullable
|
---|
102 | public String getImageHeightDescription()
|
---|
103 | {
|
---|
104 | final String value = _directory.getString(TAG_IMAGE_HEIGHT);
|
---|
105 | if (value==null)
|
---|
106 | return null;
|
---|
107 | return value + " pixels";
|
---|
108 | }
|
---|
109 |
|
---|
110 | @Nullable
|
---|
111 | public String getDataPrecisionDescription()
|
---|
112 | {
|
---|
113 | final String value = _directory.getString(TAG_DATA_PRECISION);
|
---|
114 | if (value==null)
|
---|
115 | return null;
|
---|
116 | return value + " bits";
|
---|
117 | }
|
---|
118 |
|
---|
119 | @Nullable
|
---|
120 | public String getComponentDataDescription(int componentNumber)
|
---|
121 | {
|
---|
122 | JpegComponent value = _directory.getComponent(componentNumber);
|
---|
123 |
|
---|
124 | if (value==null)
|
---|
125 | return null;
|
---|
126 |
|
---|
127 | return value.getComponentName() + " component: " + value;
|
---|
128 | }
|
---|
129 | }
|
---|