Debian Codegraph @

src/com/drew/metadata/gif/GifControlDirectory.java

raw symbols SCIP
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 */
21 package com.drew.metadata.gif;
22
23 import com.drew.lang.annotations.NotNull;
24 import com.drew.metadata.Directory;
25
26 import java.util.HashMap;
27
28 /**
29 * @author Drew Noakes https://drewnoakes.com
30 * @author Kevin Mott https://github.com/kwhopper
31 */
32 @SuppressWarnings("WeakerAccess")
33 public class GifControlDirectory extends Directory
34 {
35 public static final int TAG_DELAY = 1;
36 public static final int TAG_DISPOSAL_METHOD = 2;
37 public static final int TAG_USER_INPUT_FLAG = 3;
38 public static final int TAG_TRANSPARENT_COLOR_FLAG = 4;
39 public static final int TAG_TRANSPARENT_COLOR_INDEX = 5;
40
41 @NotNull
42 private static final HashMap<Integer, String> _tagNameMap = new HashMap<Integer, String>();
43
44 static
45 {
46 _tagNameMap.put(TAG_DELAY, "Delay");
47 _tagNameMap.put(TAG_DISPOSAL_METHOD, "Disposal Method");
48 _tagNameMap.put(TAG_USER_INPUT_FLAG, "User Input Flag");
49 _tagNameMap.put(TAG_TRANSPARENT_COLOR_FLAG, "Transparent Color Flag");
50 _tagNameMap.put(TAG_TRANSPARENT_COLOR_INDEX, "Transparent Color Index");
51 }
52
53 public GifControlDirectory()
54 {
55 this.setDescriptor(new GifControlDescriptor(this));
56 }
57
58 @Override
59 @NotNull
60 public String getName()
61 {
62 return "GIF Control";
63 }
64
65 /**
66 * @return The {@link DisposalMethod}.
67 */
68 @NotNull
69 public DisposalMethod getDisposalMethod() {
70 return (DisposalMethod) getObject(TAG_DISPOSAL_METHOD);
71 }
72
73 /**
74 * @return Whether the GIF has transparency.
75 */
76 public boolean isTransparent() {
77 Boolean transparent = getBooleanObject(TAG_TRANSPARENT_COLOR_FLAG);
78 return transparent != null && transparent;
79 }
80
81 @Override
82 @NotNull
83 protected HashMap<Integer, String> getTagNameMap()
84 {
85 return _tagNameMap;
86 }
87
88 /**
89 * Disposal method indicates the way in which the graphic is to be treated
90 * after being displayed.
91 */
92 public enum DisposalMethod {
93 NOT_SPECIFIED,
94 DO_NOT_DISPOSE,
95 RESTORE_TO_BACKGROUND_COLOR,
96 RESTORE_TO_PREVIOUS,
97 TO_BE_DEFINED,
98 INVALID;
99
100 public static DisposalMethod typeOf(int value) {
101 switch (value) {
102 case 0: return NOT_SPECIFIED;
103 case 1: return DO_NOT_DISPOSE;
104 case 2: return RESTORE_TO_BACKGROUND_COLOR;
105 case 3: return RESTORE_TO_PREVIOUS;
106 case 4:
107 case 5:
108 case 6:
109 case 7: return TO_BE_DEFINED;
110 default: return INVALID;
111 }
112 }
113
114 @Override
115 public String toString() {
116 switch (this) {
117 case DO_NOT_DISPOSE:
118 return "Don't Dispose";
119 case INVALID:
120 return "Invalid value";
121 case NOT_SPECIFIED:
122 return "Not Specified";
123 case RESTORE_TO_BACKGROUND_COLOR:
124 return "Restore to Background Color";
125 case RESTORE_TO_PREVIOUS:
126 return "Restore to Previous";
127 case TO_BE_DEFINED:
128 return "To Be Defined";
129 default:
130 return super.toString();
131 }
132 }
133 }
134 }