File: BmpHeaderDirectory.java

package info (click to toggle)
libmetadata-extractor-java 2.11.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, forky, sid, trixie
  • size: 6,416 kB
  • sloc: java: 35,343; xml: 200; sh: 11; makefile: 2
file content (487 lines) | stat: -rw-r--r-- 15,139 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
/*
 * Copyright 2002-2017 Drew Noakes
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 *
 * More information about this project is available at:
 *
 *    https://drewnoakes.com/code/exif/
 *    https://github.com/drewnoakes/metadata-extractor
 */
package com.drew.metadata.bmp;

import com.drew.lang.annotations.NotNull;
import com.drew.lang.annotations.Nullable;
import com.drew.metadata.Directory;

import java.util.HashMap;

/**
 * @author Drew Noakes https://drewnoakes.com
 * @author Nadahar
 */
@SuppressWarnings("WeakerAccess")
public class BmpHeaderDirectory extends Directory
{
    public static final int TAG_BITMAP_TYPE = -2;
    public static final int TAG_HEADER_SIZE = -1;

    public static final int TAG_IMAGE_HEIGHT = 1;
    public static final int TAG_IMAGE_WIDTH = 2;
    public static final int TAG_COLOUR_PLANES = 3;
    public static final int TAG_BITS_PER_PIXEL = 4;
    public static final int TAG_COMPRESSION = 5;
    public static final int TAG_X_PIXELS_PER_METER = 6;
    public static final int TAG_Y_PIXELS_PER_METER = 7;
    public static final int TAG_PALETTE_COLOUR_COUNT = 8;
    public static final int TAG_IMPORTANT_COLOUR_COUNT = 9;
    public static final int TAG_RENDERING = 10;
    public static final int TAG_COLOR_ENCODING = 11;
    public static final int TAG_RED_MASK = 12;
    public static final int TAG_GREEN_MASK = 13;
    public static final int TAG_BLUE_MASK = 14;
    public static final int TAG_ALPHA_MASK = 15;
    public static final int TAG_COLOR_SPACE_TYPE = 16;
    public static final int TAG_GAMMA_RED = 17;
    public static final int TAG_GAMMA_GREEN = 18;
    public static final int TAG_GAMMA_BLUE = 19;
    public static final int TAG_INTENT = 20;
    public static final int TAG_LINKED_PROFILE = 21;

    @NotNull
    protected static final HashMap<Integer, String> _tagNameMap = new HashMap<Integer, String>();

    static {
        _tagNameMap.put(TAG_BITMAP_TYPE, "Bitmap type");
        _tagNameMap.put(TAG_HEADER_SIZE, "Header Size");

        _tagNameMap.put(TAG_IMAGE_HEIGHT, "Image Height");
        _tagNameMap.put(TAG_IMAGE_WIDTH, "Image Width");
        _tagNameMap.put(TAG_COLOUR_PLANES, "Planes");
        _tagNameMap.put(TAG_BITS_PER_PIXEL, "Bits Per Pixel");
        _tagNameMap.put(TAG_COMPRESSION, "Compression");
        _tagNameMap.put(TAG_X_PIXELS_PER_METER, "X Pixels per Meter");
        _tagNameMap.put(TAG_Y_PIXELS_PER_METER, "Y Pixels per Meter");
        _tagNameMap.put(TAG_PALETTE_COLOUR_COUNT, "Palette Colour Count");
        _tagNameMap.put(TAG_IMPORTANT_COLOUR_COUNT, "Important Colour Count");
        _tagNameMap.put(TAG_RENDERING, "Rendering");
        _tagNameMap.put(TAG_COLOR_ENCODING, "Color Encoding");
        _tagNameMap.put(TAG_RED_MASK, "Red Mask");
        _tagNameMap.put(TAG_GREEN_MASK, "Green Mask");
        _tagNameMap.put(TAG_BLUE_MASK, "Blue Mask");
        _tagNameMap.put(TAG_ALPHA_MASK, "Alpha Mask");
        _tagNameMap.put(TAG_COLOR_SPACE_TYPE, "Color Space Type");
        _tagNameMap.put(TAG_GAMMA_RED, "Red Gamma Curve");
        _tagNameMap.put(TAG_GAMMA_GREEN, "Green Gamma Curve");
        _tagNameMap.put(TAG_GAMMA_BLUE, "Blue Gamma Curve");
        _tagNameMap.put(TAG_INTENT, "Rendering Intent");
        _tagNameMap.put(TAG_LINKED_PROFILE, "Linked Profile File Name");
    }

    public BmpHeaderDirectory()
    {
        this.setDescriptor(new BmpHeaderDescriptor(this));
    }

    @Nullable
    public BitmapType getBitmapType() {
        Integer value = getInteger(TAG_BITMAP_TYPE);
        return value == null ? null : BitmapType.typeOf(value.intValue());
    }

    @Nullable
    public Compression getCompression() {
        return Compression.typeOf(this);
    }

    @Nullable
    public RenderingHalftoningAlgorithm getRendering() {
        Integer value = getInteger(TAG_RENDERING);
        return value == null ? null : RenderingHalftoningAlgorithm.typeOf(value.intValue());
    }

    @Nullable
    public ColorEncoding getColorEncoding() {
        Integer value = getInteger(TAG_COLOR_ENCODING);
        return value == null ? null : ColorEncoding.typeOf(value.intValue());
    }

    @Nullable
    public ColorSpaceType getColorSpaceType() {
        Long value = getLongObject(TAG_COLOR_SPACE_TYPE);
        return value == null ? null : ColorSpaceType.typeOf(value.longValue());
    }

    @Nullable
    public RenderingIntent getRenderingIntent() {
        Integer value = getInteger(TAG_INTENT);
        return value == null ? null : RenderingIntent.typeOf(value.intValue());
    }

    @Override
    @NotNull
    public String getName()
    {
        return "BMP Header";
    }

    @Override
    @NotNull
    protected HashMap<Integer, String> getTagNameMap()
    {
        return _tagNameMap;
    }

    public enum BitmapType {

           /** "BM" - Windows or OS/2 bitmap */
        BITMAP(0x4D42),

        /** "BA" - OS/2 Bitmap array (multiple bitmaps) */
        OS2_BITMAP_ARRAY(0x4142),

            /** "IC" - OS/2 Icon */
        OS2_ICON(0x4349),

            /** "CI" - OS/2 Color icon */
        OS2_COLOR_ICON(0x4943),

        /** "CP" - OS/2 Color pointer */
        OS2_COLOR_POINTER(0x5043),

            /** "PT" - OS/2 Pointer */
        OS2_POINTER(0x5450);

        private final int value;

        private BitmapType(int value) {
            this.value = value;
        }

        public int getValue() {
            return value;
        }

        @Nullable
        public static BitmapType typeOf(int value) {
            for (BitmapType bitmapType : BitmapType.values())
            {
                if (bitmapType.value == value)
                {
                    return bitmapType;
                }
            }
            return null;
        }

        @Override
        @NotNull
        public String toString() {
            switch (this) {
                case BITMAP: return "Standard";
                case OS2_BITMAP_ARRAY: return "Bitmap Array";
                case OS2_COLOR_ICON: return "Color Icon";
                case OS2_COLOR_POINTER: return "Color Pointer";
                case OS2_ICON: return "Monochrome Icon";
                case OS2_POINTER: return "Monochrome Pointer";
                default:
                    throw new IllegalStateException("Unimplemented bitmap type " + super.toString());
            }
        }
    }

    public enum Compression {

        /** 0 = None */
        BI_RGB(0),

        /** 1 = RLE 8-bit/pixel */
        BI_RLE8(1),

        /** 2 = RLE 4-bit/pixel */
        BI_RLE4(2),

        /** 3 = Bit fields (not OS22XBITMAPHEADER (size 64)) */
        BI_BITFIELDS(3),

        /** 3 = Huffman 1D (if OS22XBITMAPHEADER (size 64)) */
        BI_HUFFMAN_1D(3),

        /** 4 = JPEG (not OS22XBITMAPHEADER (size 64)) */
        BI_JPEG(4),

        /** 4 = RLE 24-bit/pixel (if OS22XBITMAPHEADER (size 64)) */
        BI_RLE24(4),

        /** 5 = PNG */
        BI_PNG(5),

        /** 6 = RGBA bit fields */
        BI_ALPHABITFIELDS(6),

        /** 11 = CMYK */
        BI_CMYK(11),

        /** 12 = CMYK RLE-8 */
        BI_CMYKRLE8(12),

        /** 13 = CMYK RLE-4 */
        BI_CMYKRLE4(13);

        private final int value;

        private Compression(int value) {
            this.value = value;
        }

        public int getValue() {
            return value;
        }

        @Nullable
        public static Compression typeOf(@NotNull BmpHeaderDirectory directory) {
            Integer value = directory.getInteger(TAG_COMPRESSION);
            if (value == null)
                return null;
            Integer headerSize = directory.getInteger(TAG_HEADER_SIZE);
            if (headerSize == null)
                return null;

            return typeOf(value, headerSize);
        }

        @Nullable
        public static Compression typeOf(int value, int headerSize) {
            switch (value) {
                case 0:  return BI_RGB;
                case 1:  return BI_RLE8;
                case 2:  return BI_RLE4;
                case 3:  return headerSize == 64 ? BI_HUFFMAN_1D : BI_BITFIELDS;
                case 4:  return headerSize == 64 ? BI_RLE24 : BI_JPEG;
                case 5:  return BI_PNG;
                case 6:  return BI_ALPHABITFIELDS;
                case 11: return BI_CMYK;
                case 12: return BI_CMYKRLE8;
                case 13: return BI_CMYKRLE4;
                default: return null;
            }
        }

        @Override
        @NotNull
        public String toString() {
            switch (this) {
                case BI_RGB:            return "None";
                case BI_RLE8:           return "RLE 8-bit/pixel";
                case BI_RLE4:           return "RLE 4-bit/pixel";
                case BI_BITFIELDS:      return "Bit Fields";
                case BI_HUFFMAN_1D:     return "Huffman 1D";
                case BI_JPEG:           return "JPEG";
                case BI_RLE24:          return "RLE 24-bit/pixel";
                case BI_PNG:            return "PNG";
                case BI_ALPHABITFIELDS: return "RGBA Bit Fields";
                case BI_CMYK:           return "CMYK Uncompressed";
                case BI_CMYKRLE8:       return "CMYK RLE-8";
                case BI_CMYKRLE4:       return "CMYK RLE-4";
                default:
                    throw new IllegalStateException("Unimplemented compression type " + super.toString());
            }
        }
    }

    public enum RenderingHalftoningAlgorithm {

        /** No halftoning algorithm */
        NONE(0),

        /** Error Diffusion Halftoning */
        ERROR_DIFFUSION(1),

        /** Processing Algorithm for Noncoded Document Acquisition */
        PANDA(2),

        /** Super-circle Halftoning */
        SUPER_CIRCLE(3);

        private final int value;

        private RenderingHalftoningAlgorithm(int value) {
            this.value = value;
        }

        public int getValue() {
            return value;
        }

        @Nullable
        public static RenderingHalftoningAlgorithm typeOf(int value) {
            for (RenderingHalftoningAlgorithm renderingHalftoningAlgorithm : RenderingHalftoningAlgorithm.values())
            {
                if (renderingHalftoningAlgorithm.value == value)
                {
                    return renderingHalftoningAlgorithm;
                }
            }
            return null;
        }

        @Override
        @NotNull
        public String toString() {
            switch (this) {
                case NONE:
                    return "No Halftoning Algorithm";
                case ERROR_DIFFUSION:
                    return "Error Diffusion Halftoning";
                case PANDA:
                    return "Processing Algorithm for Noncoded Document Acquisition";
                case SUPER_CIRCLE:
                    return "Super-circle Halftoning";
                default:
                    throw new IllegalStateException("Unimplemented rendering halftoning algorithm type " + super.toString());
            }
        }
    }

    public enum ColorEncoding {
        RGB(0);

        private final int value;

        private ColorEncoding(int value) {
            this.value = value;
        }

        public int getValue() {
            return value;
        }

        @Nullable
        public static ColorEncoding typeOf(int value) {
            return value == 0 ? RGB : null;
        }
    }

    public enum ColorSpaceType {

        /** 0 = Calibrated RGB */
        LCS_CALIBRATED_RGB(0L),

        /** "sRGB" = sRGB Color Space */
        LCS_sRGB(0x73524742L),

        /** "Win " = System Default Color Space, sRGB */
        LCS_WINDOWS_COLOR_SPACE(0x57696E20L),

        /** "LINK" = Linked Profile */
        PROFILE_LINKED(0x4C494E4BL),

        /** "MBED" = Embedded Profile */
        PROFILE_EMBEDDED(0x4D424544L);

        private final long value;

        private ColorSpaceType(long value) {
            this.value = value;
        }

        public long getValue() {
            return value;
        }

        @Nullable
        public static ColorSpaceType typeOf(long value) {
            for (ColorSpaceType colorSpaceType : ColorSpaceType.values())
            {
                if (colorSpaceType.value == value)
                {
                    return colorSpaceType;
                }
            }
            return null;
        }

        @Override
        @NotNull
        public String toString() {
            switch (this) {
                case LCS_CALIBRATED_RGB:
                    return "Calibrated RGB";
                case LCS_sRGB:
                    return "sRGB Color Space";
                case LCS_WINDOWS_COLOR_SPACE:
                    return "System Default Color Space, sRGB";
                case PROFILE_LINKED:
                    return "Linked Profile";
                case PROFILE_EMBEDDED:
                    return "Embedded Profile";
                default:
                    throw new IllegalStateException("Unimplemented color space type " + super.toString());
            }
        }
    }

    public enum RenderingIntent {

        /** Graphic, Saturation */
        LCS_GM_BUSINESS(1),

        /** Proof, Relative Colorimetric */
        LCS_GM_GRAPHICS(2),

        /** Picture, Perceptual */
        LCS_GM_IMAGES(4),

        /** Match, Absolute Colorimetric */
        LCS_GM_ABS_COLORIMETRIC(8);

        private final int value;

        private RenderingIntent(int value) {
            this.value = value;
        }

        public int getValue() {
            return value;
        }

        @Nullable
        public static RenderingIntent typeOf(long value) {
            for (RenderingIntent renderingIntent : RenderingIntent.values())
            {
                if (renderingIntent.value == value)
                {
                    return renderingIntent;
                }
            }
            return null;
        }

        @Override
        @NotNull
        public String toString() {
            switch (this) {
                case LCS_GM_BUSINESS:
                    return "Graphic, Saturation";
                case LCS_GM_GRAPHICS:
                    return "Proof, Relative Colorimetric";
                case LCS_GM_IMAGES:
                    return "Picture, Perceptual";
                case LCS_GM_ABS_COLORIMETRIC:
                    return "Match, Absolute Colorimetric";
                default:
                    throw new IllegalStateException("Unimplemented rendering intent " + super.toString());
            }
        }
    }
}