Debian Codegraph @

src/com/drew/metadata/bmp/BmpHeaderDescriptor.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.bmp;
22
23 import com.drew.lang.annotations.NotNull;
24 import com.drew.lang.annotations.Nullable;
25 import com.drew.metadata.TagDescriptor;
26
27 import java.text.DecimalFormat;
28
29 import static com.drew.metadata.bmp.BmpHeaderDirectory.*;
30
31 /**
32 * @author Drew Noakes https://drewnoakes.com
33 * @author Nadahar
34 */
35 @SuppressWarnings("WeakerAccess")
36 public class BmpHeaderDescriptor extends TagDescriptor<BmpHeaderDirectory>
37 {
38 public BmpHeaderDescriptor(@NotNull BmpHeaderDirectory directory)
39 {
40 super(directory);
41 }
42
43 @Override
44 public String getDescription(int tagType)
45 {
46 switch (tagType) {
47 case TAG_BITMAP_TYPE:
48 return getBitmapTypeDescription();
49 case TAG_COMPRESSION:
50 return getCompressionDescription();
51 case TAG_RENDERING:
52 return getRenderingDescription();
53 case TAG_COLOR_ENCODING:
54 return getColorEncodingDescription();
55 case TAG_RED_MASK:
56 case TAG_GREEN_MASK:
57 case TAG_BLUE_MASK:
58 case TAG_ALPHA_MASK:
59 return formatHex(_directory.getLongObject(tagType), 8);
60 case TAG_COLOR_SPACE_TYPE:
61 return getColorSpaceTypeDescription();
62 case TAG_GAMMA_RED:
63 case TAG_GAMMA_GREEN:
64 case TAG_GAMMA_BLUE:
65 return formatFixed1616(_directory.getLongObject(tagType));
66 case TAG_INTENT:
67 return getRenderingIntentDescription();
68 default:
69 return super.getDescription(tagType);
70 }
71 }
72
73 @Nullable
74 public String getBitmapTypeDescription()
75 {
76 BitmapType bitmapType = _directory.getBitmapType();
77 return bitmapType == null ? null : bitmapType.toString();
78 }
79
80 @Nullable
81 public String getCompressionDescription()
82 {
83 // 0 = None
84 // 1 = RLE 8-bit/pixel
85 // 2 = RLE 4-bit/pixel
86 // 3 = Bit fields (or Huffman 1D if OS22XBITMAPHEADER (size 64))
87 // 4 = JPEG (or RLE 24-bit/pixel if OS22XBITMAPHEADER (size 64))
88 // 5 = PNG
89 // 11 = CMYK
90 // 12 = CMYK RLE-8
91 // 13 = CMYK RLE-4
92
93 Compression compression = _directory.getCompression();
94 if (compression != null) {
95 return compression.toString();
96 }
97 Integer value = _directory.getInteger(TAG_COMPRESSION);
98 return value == null ? null : "Illegal value 0x" + Integer.toHexString(value.intValue());
99 }
100
101 @Nullable
102 public String getRenderingDescription()
103 {
104 RenderingHalftoningAlgorithm renderingHalftoningAlgorithm = _directory.getRendering();
105 return renderingHalftoningAlgorithm == null ? null : renderingHalftoningAlgorithm.toString();
106 }
107
108 @Nullable
109 public String getColorEncodingDescription()
110 {
111 ColorEncoding colorEncoding = _directory.getColorEncoding();
112 return colorEncoding == null ? null : colorEncoding.toString();
113 }
114
115 @Nullable
116 public String getColorSpaceTypeDescription()
117 {
118 ColorSpaceType colorSpaceType = _directory.getColorSpaceType();
119 return colorSpaceType == null ? null : colorSpaceType.toString();
120 }
121
122 @Nullable
123 public String getRenderingIntentDescription()
124 {
125 RenderingIntent renderingIntent = _directory.getRenderingIntent();
126 return renderingIntent == null ? null : renderingIntent.toString();
127 }
128
129 @Nullable
130 public static String formatHex(@Nullable Integer value, int digits) {
131 return value == null ? null : formatHex(value.intValue() & 0xFFFFFFFFL, digits);
132 }
133
134 @NotNull
135 public static String formatHex(int value, int digits) {
136 return formatHex(value & 0xFFFFFFFFL, digits);
137 }
138
139 @Nullable
140 public static String formatHex(@Nullable Long value, int digits) {
141 return value == null ? null : formatHex(value.longValue(), digits);
142 }
143
144 @NotNull
145 public static String formatHex(long value, int digits) {
146 return String.format("0x%0"+ digits + "X", value);
147 }
148
149 @Nullable
150 public static String formatFixed1616(Integer value) {
151 return value == null ? null : formatFixed1616(value.intValue() & 0xFFFFFFFFL);
152 }
153
154 @NotNull
155 public static String formatFixed1616(int value) {
156 return formatFixed1616(value & 0xFFFFFFFFL);
157 }
158
159 @Nullable
160 public static String formatFixed1616(Long value) {
161 return value == null ? null : formatFixed1616(value.longValue());
162 }
163
164 @NotNull
165 public static String formatFixed1616(long value) {
166 Double d = (double) value / 0x10000;
167 DecimalFormat format = new DecimalFormat("0.###");
168 return format.format(d);
169 }
170 }