summaryrefslogtreecommitdiffstats
path: root/src/com/android/gallery3d/exif/ExifTag.java
blob: b2cbe61d7a98a10f49166871801bca53f83ec30a (plain)
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
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
/*
 * Copyright (C) 2012 The Android Open Source Project
 *
 * 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.
 */

package com.android.gallery3d.exif;

import java.lang.reflect.Array;

/**
 * This class stores information of an EXIF tag.
 * @see ExifParser
 * @see ExifReader
 * @see IfdData
 * @see ExifData
 */
public class ExifTag {
    public static interface TIFF_TAG {
        public static final short TAG_IMAGE_WIDTH = 0x100;
        public static final short TAG_IMAGE_HEIGHT = 0x101;
        public static final short TAG_BITS_PER_SAMPLE = 0x102;
        public static final short TAG_COMPRESSION = 0x103;
        public static final short TAG_PHOTOMETRIC_INTERPRETATION = 0x106;
        public static final short TAG_IMAGE_DESCRIPTION = 0x10E;
        public static final short TAG_MAKE = 0x10F;
        public static final short TAG_MODEL = 0x110;
        public static final short TAG_STRIP_OFFSETS = 0x111;
        public static final short TAG_ORIENTATION = 0x112;
        public static final short TAG_SAMPLES_PER_PIXEL = 0x115;
        public static final short TAG_ROWS_PER_STRIP = 0x116;
        public static final short TAG_STRIP_BYTE_COUNTS = 0x117;
        public static final short TAG_X_RESOLUTION = 0x11A;
        public static final short TAG_Y_RESOLUTION = 0x11B;
        public static final short TAG_PLANAR_CONFIGURATION = 0x11C;
        public static final short TAG_RESOLUTION_UNIT = 0x128;
        public static final short TAG_TRANSFER_FUNCTION = 0x12D;
        public static final short TAG_SOFTWARE = 0x131;
        public static final short TAG_DATE_TIME = 0x132;
        public static final short TAG_ARTIST = 0x13B;
        public static final short TAG_WHITE_POINT = 0x13E;
        public static final short TAG_PRIMARY_CHROMATICITIES = 0x13F;
        public static final short TAG_JPEG_INTERCHANGE_FORMAT = 0x201;
        public static final short TAG_JPEG_INTERCHANGE_FORMAT_LENGTH = 0x202;
        public static final short TAG_Y_CB_CR_COEFFICIENTS = 0x211;
        public static final short TAG_Y_CB_CR_SUB_SAMPLING = 0x212;
        public static final short TAG_Y_CB_CR_POSITIONING = 0x213;
        public static final short TAG_REFERENCE_BLACK_WHITE = 0x214;
        public static final short TAG_COPYRIGHT = (short) 0x8298;
        public static final short TAG_EXIF_IFD = (short) 0x8769;
        public static final short TAG_GPS_IFD = (short) 0x8825;

        public static final short ORIENTATION_TOP_LEFT = 1;
        public static final short ORIENTATION_TOP_RIGHT = 2;
        public static final short ORIENTATION_BOTTOM_LEFT = 3;
        public static final short ORIENTATION_BOTTOM_RIGHT = 4;
        public static final short ORIENTATION_LEFT_TOP = 5;
        public static final short ORIENTATION_RIGHT_TOP = 6;
        public static final short ORIENTATION_LEFT_BOTTOM = 7;
        public static final short ORIENTATION_RIGHT_BOTTOM = 8;

        public static final short Y_CB_CR_POSITIONING_CENTERED = 1;
        public static final short Y_CB_CR_POSITIONING_CO_SITED = 2;

        public static final short COMPRESSION_UNCOMPRESSION = 1;
        public static final short COMPRESSION_JPEG = 6;

        public static final short RESOLUTION_UNIT_INCHES = 2;
        public static final short RESOLUTION_UNIT_CENTIMETERS = 3;

        public static final short PHOTOMETRIC_INTERPRETATION_RGB = 2;
        public static final short PHOTOMETRIC_INTERPRETATION_YCBCR = 6;

        public static final short PLANAR_CONFIGURATION_CHUNKY = 1;
        public static final short PLANAR_CONFIGURATION_PLANAR = 2;
    }

    public static interface EXIF_TAG {
        public static final short TAG_EXPOSURE_TIME = (short) 0x829A;
        public static final short TAG_F_NUMBER = (short) 0x829D;
        public static final short TAG_EXPOSURE_PROGRAM = (short) 0x8822;
        public static final short TAG_SPECTRAL_SENSITIVITY = (short) 0x8824;
        public static final short TAG_ISO_SPEED_RATINGS = (short) 0x8827;
        public static final short TAG_OECF = (short) 0x8828;
        public static final short TAG_EXIF_VERSION = (short) 0x9000;
        public static final short TAG_DATE_TIME_ORIGINAL = (short) 0x9003;
        public static final short TAG_DATE_TIME_DIGITIZED = (short) 0x9004;
        public static final short TAG_COMPONENTS_CONFIGURATION = (short) 0x9101;
        public static final short TAG_COMPRESSED_BITS_PER_PIXEL = (short) 0x9102;
        public static final short TAG_SHUTTER_SPEED = (short) 0x9201;
        public static final short TAG_APERTURE_VALUE = (short) 0x9202;
        public static final short TAG_BRIGHTNESS_VALUE = (short) 0x9203;
        public static final short TAG_EXPOSURE_BIAS_VALUE = (short) 0x9204;
        public static final short TAG_MAX_APERTURE_VALUE = (short) 0x9205;
        public static final short TAG_SUBJECT_DISTANCE = (short) 0x9206;
        public static final short TAG_METERING_MODE = (short) 0x9207;
        public static final short TAG_LIGHT_SOURCE = (short) 0x9208;
        public static final short TAG_FLASH = (short) 0x9209;
        public static final short TAG_FOCAL_LENGTH = (short) 0x920A;
        public static final short TAG_SUBJECT_AREA = (short) 0x9214;
        public static final short TAG_MARER_NOTE = (short) 0x927C;
        public static final short TAG_USER_COMMENT = (short) 0x9286;
        public static final short TAG_SUB_SEC_TIME = (short) 0x9290;
        public static final short TAG_SUB_SEC_TIME_ORIGINAL = (short) 0x9291;
        public static final short TAG_SUB_SEC_TIME_DIGITIZED = (short) 0x9292;
        public static final short TAG_FLASHPIX_VERSION = (short) 0xA000;
        public static final short TAG_COLOR_SPACE = (short) 0xA001;
        public static final short TAG_PIXEL_X_DIMENSION = (short) 0xA002;
        public static final short TAG_PIXEL_Y_DIMENSION = (short) 0xA003;
        public static final short TAG_RELATED_SOUND_FILE = (short) 0xA004;
        public static final short TAG_INTEROPERABILITY_IFD = (short) 0xA005;
        public static final short TAG_FLASH_ENERGY = (short) 0xA20B;
        public static final short TAG_SPATIAL_FREQUENCY_REPSONSE = (short) 0xA20C;
        public static final short TAG_FOCAL_PLANE_X_RESOLUTION = (short) 0xA20E;
        public static final short TAG_FOCAL_PLANE_Y_RESOLUTION = (short) 0xA20F;
        public static final short TAG_FOCAL_PLANE_RESOLUTION_UNIT = (short) 0xA210;
        public static final short TAG_SUBJECT_LOCATION = (short) 0xA214;
        public static final short TAG_EXPOSURE_INDEX = (short) 0xA215;
        public static final short TAG_SENSING_METHOD = (short) 0xA217;
        public static final short TAG_FILE_SOURCE = (short) 0xA300;
        public static final short TAG_SCENE_TYPE = (short) 0xA301;
        public static final short TAG_CFA_PATTERN = (short) 0xA302;
        public static final short TAG_CUSTOM_RENDERED = (short) 0xA401;
        public static final short TAG_EXPOSURE_MODE = (short) 0xA402;
        public static final short TAG_WHITH_BALANCE = (short) 0xA403;
        public static final short TAG_DIGITAL_ZOOM_RATIO = (short) 0xA404;
        public static final short TAG_FOCAL_LENGTH_IN_35_MM_FILE = (short) 0xA405;
        public static final short TAG_SCENE_CAPTURE_TYPE = (short) 0xA406;
        public static final short TAG_GAIN_CONTROL = (short) 0xA407;
        public static final short TAG_CONTRAST = (short) 0xA408;
        public static final short TAG_SATURATION = (short) 0xA409;
        public static final short TAG_SHARPNESS = (short) 0xA40A;
        public static final short TAG_DEVICE_SETTING_DESCRIPTION = (short) 0xA40B;
        public static final short TAG_SUBJECT_DISTANCE_RANGE = (short) 0xA40C;
        public static final short TAG_IMAGE_UNIQUE_ID = (short) 0xA420;

        public static final short EXPOSURE_PROGRAM_NOT_DEFINED = 0;
        public static final short EXPOSURE_PROGRAM_MANUAL = 1;
        public static final short EXPOSURE_PROGRAM_NORMAL_PROGRAM = 2;
        public static final short EXPOSURE_PROGRAM_APERTURE_PRIORITY = 3;
        public static final short EXPOSURE_PROGRAM_SHUTTER_PRIORITY = 4;
        public static final short EXPOSURE_PROGRAM_CREATIVE_PROGRAM = 5;
        public static final short EXPOSURE_PROGRAM_ACTION_PROGRAM = 6;
        public static final short EXPOSURE_PROGRAM_PROTRAIT_MODE = 7;
        public static final short EXPOSURE_PROGRAM_LANDSCAPE_MODE = 8;

        public static final short METERING_MODE_UNKNOWN = 0;
        public static final short METERING_MODE_AVERAGE = 1;
        public static final short METERING_MODE_CENTER_WEIGHTED_AVERAGE = 2;
        public static final short METERING_MODE_SPOT = 3;
        public static final short METERING_MODE_MULTISPOT = 4;
        public static final short METERING_MODE_PATTERN = 5;
        public static final short METERING_MODE_PARTAIL = 6;
        public static final short METERING_MODE_OTHER = 255;

        // Flash flag
        // LSB
        public static final short FLASH_DID_NOT_FIRED = 0;
        public static final short FLASH_FIRED = 1;
        // 1~2 bits
        public static final short FLASH_RETURN_NO_STROBE_RETURN_DETECTION_FUNCTION = 0 << 1;
        public static final short FLASH_RETURN_STROBE_RETURN_LIGHT_NOT_DETECTED = 2 << 1;
        public static final short FLASH_RETURN_STROBE_RETURN_LIGHT_DETECTED = 3 << 1;
        // 3~4 bits
        public static final short FLASH_MODE_UNKNOWN = 0 << 3;
        public static final short FLASH_MODE_COMPULSORY_FLASH_FIRING = 1 << 3;
        public static final short FLASH_MODE_COMPULSORY_FLASH_SUPPRESSION = 2 << 3;
        public static final short FLASH_MODE_AUTO_MODE = 3 << 3;
        // 5 bit
        public static final short FLASH_FUNCTION_PRESENT = 0 << 5;
        public static final short FLASH_FUNCTION_NO_FUNCTION = 1 << 5;
        // 6 bit
        public static final short FLASH_RED_EYE_REDUCTION_NO_OR_UNKNOWN = 0 << 6;
        public static final short FLASH_RED_EYE_REDUCTION_SUPPORT = 1 << 6;

        public static final short COLOR_SPACE_SRGB = 1;
        public static final short COLOR_SPACE_UNCALIBRATED = (short) 0xFFFF;

        public static final short EXPOSURE_MODE_AUTO_EXPOSURE = 0;
        public static final short EXPOSURE_MODE_MANUAL_EXPOSURE = 1;
        public static final short EXPOSURE_MODE_AUTO_BRACKET = 2;

        public static final short WHITE_BALACE_MODE_AUTO = 0;
        public static final short WHITE_BALACE_MODE_MANUAL = 1;

        public static final short SCENE_CAPTURE_TYPE_STANDARD = 0;
        public static final short SCENE_CAPTURE_TYPE_LANDSCAPE = 1;
        public static final short SCENE_CAPTURE_TYPE_PROTRAIT = 2;
        public static final short SCENE_CAPTURE_TYPE_NIGHT_SCENE = 3;

        public static final short COMPONENTS_CONFIGURATION_NOT_EXIST = 0;
        public static final short COMPONENTS_CONFIGURATION_Y = 1;
        public static final short COMPONENTS_CONFIGURATION_CB = 2;
        public static final short COMPONENTS_CONFIGURATION_CR = 3;
        public static final short COMPONENTS_CONFIGURATION_R = 4;
        public static final short COMPONENTS_CONFIGURATION_G = 5;
        public static final short COMPONENTS_CONFIGURATION_B = 6;

        public static final short LIGHT_SOURCE_UNKNOWN = 0;
        public static final short LIGHT_SOURCE_DAYLIGHT = 1;
        public static final short LIGHT_SOURCE_FLUORESCENT = 2;
        public static final short LIGHT_SOURCE_TUNGSTEN = 3;
        public static final short LIGHT_SOURCE_FLASH = 4;
        public static final short LIGHT_SOURCE_FINE_WEATHER = 9;
        public static final short LIGHT_SOURCE_CLOUDY_WEATHER = 10;
        public static final short LIGHT_SOURCE_SHADE = 11;
        public static final short LIGHT_SOURCE_DAYLIGHT_FLUORESCENT = 12;
        public static final short LIGHT_SOURCE_DAY_WHITE_FLUORESCENT = 13;
        public static final short LIGHT_SOURCE_COOL_WHITE_FLUORESCENT = 14;
        public static final short LIGHT_SOURCE_WHITE_FLUORESCENT = 15;
        public static final short LIGHT_SOURCE_STANDARD_LIGHT_A = 17;
        public static final short LIGHT_SOURCE_STANDARD_LIGHT_B = 18;
        public static final short LIGHT_SOURCE_STANDARD_LIGHT_C = 19;
        public static final short LIGHT_SOURCE_D55 = 20;
        public static final short LIGHT_SOURCE_D65 = 21;
        public static final short LIGHT_SOURCE_D75 = 22;
        public static final short LIGHT_SOURCE_D50 = 23;
        public static final short LIGHT_SOURCE_ISO_STUDIO_TUNGSTEN = 24;
        public static final short LIGHT_SOURCE_OTHER = 255;

        public static final short SENSING_METHOD_NOT_DEFINED = 1;
        public static final short SENSING_METHOD_ONE_CHIP_COLOR = 2;
        public static final short SENSING_METHOD_TWO_CHIP_COLOR = 3;
        public static final short SENSING_METHOD_THREE_CHIP_COLOR = 4;
        public static final short SENSING_METHOD_COLOR_SEQUENTIAL_AREA = 5;
        public static final short SENSING_METHOD_TRILINEAR = 7;
        public static final short SENSING_METHOD_COLOR_SEQUENTIAL_LINEAR = 8;

        public static final short FILE_SOURCE_DSC = 3;

        public static final short SCENE_TYPE_DIRECT_PHOTOGRAPHED = 1;

        public static final short GAIN_CONTROL_NONE = 0;
        public static final short GAIN_CONTROL_LOW_UP = 1;
        public static final short GAIN_CONTROL_HIGH_UP = 2;
        public static final short GAIN_CONTROL_LOW_DOWN = 3;
        public static final short GAIN_CONTROL_HIGH_DOWN = 4;

        public static final short CONTRAST_NORMAL = 0;
        public static final short CONTRAST_SOFT = 1;
        public static final short CONTRAST_HARD = 2;

        public static final short SATURATION_NORMAL = 0;
        public static final short SATURATION_LOW = 1;
        public static final short SATURATION_HIGH = 2;

        public static final short SHARPNESS_NORMAL = 0;
        public static final short SHARPNESS_SOFT = 1;
        public static final short SHARPNESS_HARD = 2;

        public static final short SUBJECT_DISTANCE_RANGE_UNKNOWN = 0;
        public static final short SUBJECT_DISTANCE_RANGE_MACRO = 1;
        public static final short SUBJECT_DISTANCE_RANGE_CLOSE_VIEW = 2;
        public static final short SUBJECT_DISTANCE_RANGE_DISTANT_VIEW = 3;
    }

    public static interface GPS_TAG {
        public static final short GPS_VERSION_ID = 0;
        public static final short GPS_LATITUDE_REF = 1;
        public static final short GPS_LATITUDE = 2;
        public static final short GPS_LONGITUDE_REF = 3;
        public static final short GPS_LONGITUDE = 4;
        public static final short GPS_ALTITUDE_REF = 5;
        public static final short GPS_ALTITUDE = 6;
        public static final short GPS_TIME_STAMP = 7;
        public static final short GPS_SATTELLITES = 8;
        public static final short GPS_STATUS = 9;
        public static final short GPS_MEASURE_MODE = 10;
        public static final short GPS_DOP = 11;
        public static final short GPS_SPEED_REF = 12;
        public static final short GPS_SPEED = 13;
        public static final short GPS_TRACK_REF = 14;
        public static final short GPS_TRACK = 15;
        public static final short GPS_IMG_DIRECTION_REF = 16;
        public static final short GPS_IMG_DIRECTION = 17;
        public static final short GPS_MAP_DATUM = 18;
        public static final short GPS_DEST_LATITUDE_REF = 19;
        public static final short GPS_DEST_LATITUDE = 20;
        public static final short GPS_DEST_LONGITUDE_REF = 21;
        public static final short GPS_DEST_LONGITUDE = 22;
        public static final short GPS_DEST_BEARING_REF = 23;
        public static final short GPS_DEST_BEARING = 24;
        public static final short GPS_DEST_DISTANCE_REF = 25;
        public static final short GPS_DEST_DISTANCE = 26;
        public static final short GPS_PROCESSING_METHOD = 27;
        public static final short GPS_AREA_INFORMATION = 28;
        public static final short GPS_DATA_STAMP = 29;
        public static final short GPS_DIFFERENTIAL = 30;

        public static final String GPS_REF_NORTH = "N";
        public static final String GPS_REF_SOUTH = "S";

        public static final String GPS_REF_EAST = "E";
        public static final String GPS_REF_WEST = "W";

        public static final short GPS_ALTITUDE_REF_SEA_LEVEL = 0;
        public static final short GPS_ALTITUDE_REF_SEA_LEVEL_NEGATIVE = 1;

        public static final String GPS_STATUS_IN_PROGRESS = "A";
        public static final String GPS_STATUS_INTEROPERABILITY = "V";

        public static final String GPS_MEASURE_MODE_2_DIMENSIONAL = "2";
        public static final String GPS_MEASURE_MODE_3_DIMENSIONAL = "3";

        public static final String GPS_REF_KILOMETERS = "K";
        public static final String GPS_REF_MILES = "M";
        public static final String GPS_REF_KNOTS = "N";

        public static final String GPS_REF_TRUE_DIRECTION = "T";
        public static final String GPS_REF_MAGNETIC_DIRECTION = "M";
    }

    public static interface INTEROPERABILITY_TAG {
        public static final short INTEROPERABILITY_INDEX = 1;
    }

    public static final short TYPE_UNSIGNED_BYTE = 1;
    public static final short TYPE_ASCII = 2;
    public static final short TYPE_UNSIGNED_SHORT = 3;
    public static final short TYPE_UNSIGNED_INT = 4;
    public static final short TYPE_UNSIGNED_RATIONAL = 5;
    public static final short TYPE_UNDEFINED = 7;
    public static final short TYPE_INT = 9;
    public static final short TYPE_RATIONAL = 10;

    private static final int TYPE_TO_SIZE_MAP[] = new int[11];
    static {
        TYPE_TO_SIZE_MAP[TYPE_UNSIGNED_BYTE] = 1;
        TYPE_TO_SIZE_MAP[TYPE_ASCII] = 1;
        TYPE_TO_SIZE_MAP[TYPE_UNSIGNED_SHORT] = 2;
        TYPE_TO_SIZE_MAP[TYPE_UNSIGNED_INT] = 4;
        TYPE_TO_SIZE_MAP[TYPE_UNSIGNED_RATIONAL] = 8;
        TYPE_TO_SIZE_MAP[TYPE_UNDEFINED] = 1;
        TYPE_TO_SIZE_MAP[TYPE_INT] = 4;
        TYPE_TO_SIZE_MAP[TYPE_RATIONAL] = 8;
    }

    /**
     * Gets the element size of the given data type.
     *
     * @see #TYPE_ASCII
     * @see #TYPE_INT
     * @see #TYPE_RATIONAL
     * @see #TYPE_UNDEFINED
     * @see #TYPE_UNSIGNED_BYTE
     * @see #TYPE_UNSIGNED_INT
     * @see #TYPE_UNSIGNED_RATIONAL
     * @see #TYPE_UNSIGNED_SHORT
     */
    public static int getElementSize(short type) {
        return TYPE_TO_SIZE_MAP[type];
    }

    private final short mTagId;
    private final short mDataType;
    private final int mIfd;
    private int mComponentCount;
    private Object mValue;
    private int mOffset;

    ExifTag(short tagId, short type, int componentCount, int ifd) {
        mTagId = tagId;
        mDataType = type;
        mComponentCount = componentCount;
        mIfd = ifd;
    }

    /**
     * Returns the ID of the IFD this tag belongs to.
     *
     * @see IfdId#TYPE_IFD_0
     * @see IfdId#TYPE_IFD_1
     * @see IfdId#TYPE_IFD_EXIF
     * @see IfdId#TYPE_IFD_GPS
     * @see IfdId#TYPE_IFD_INTEROPERABILITY
     */
    public int getIfd() {
        return mIfd;
    }

    /**
     * Gets the ID of this tag.
     */
    public short getTagId() {
        return mTagId;
    }

    /**
     * Gets the data type of this tag
     *
     * @see #TYPE_ASCII
     * @see #TYPE_INT
     * @see #TYPE_RATIONAL
     * @see #TYPE_UNDEFINED
     * @see #TYPE_UNSIGNED_BYTE
     * @see #TYPE_UNSIGNED_INT
     * @see #TYPE_UNSIGNED_RATIONAL
     * @see #TYPE_UNSIGNED_SHORT
     */
    public short getDataType() {
        return mDataType;
    }

    /**
     * Gets the total data size in bytes of the value of this tag.
     */
    public int getDataSize() {
        return getComponentCount() * getElementSize(getDataType());
    }

    /**
     * Gets the component count of this tag.
     */
    public int getComponentCount() {
        return mComponentCount;
    }

    /**
     * Returns true if this ExifTag contains value; otherwise, this tag will contain an offset value
     * that links to the area where the actual value is located.
     *
     * @see #getOffset()
     */
    public boolean hasValue() {
        return mValue != null;
    }

    /**
     * Gets the offset of this tag. This is only valid if this data size > 4 and contains an offset
     * to the location of the actual value.
     */
    public int getOffset() {
        return mOffset;
    }

    /**
     * Sets the offset of this tag.
     */
    void setOffset(int offset) {
        mOffset = offset;
    }

    /**
     * Sets integer values into this tag. This is useful when we want to modify the tags
     * and write it back to the JPEG file. The component count will be set to the length.
     */
    public void setValue(int[] value) {
        long[] data = new long[value.length];
        for (int i = 0; i < value.length; i++) {
            data[i] = value[i];
        }
        mValue = data;
        mComponentCount = value.length;
    }

    /**
     * Sets integer value into this tag. This is useful when we want to modify the tags
     * and write it back to the JPEG file. The component count will be set to 1.
     */
    public void setValue(int value) {
        mValue = new long[] {value};
        mComponentCount = 1;
    }

    /**
     * Sets short values into this tag. This is useful when we want to modify the tags
     * and write it back to the JPEG file. The component count will be set to the length.
     */
    public void setValue(short[] value) {
        long[] data = new long[value.length];
        for (int i = 0; i < value.length; i++) {
            data[i] = value[i];
        }
        mValue = data;
        mComponentCount = value.length;
    }

    /**
     * Sets short value into this tag. This is useful when we want to modify the tags
     * and write it back to the JPEG file. The component count will be set to 1.
     */
    public void setValue(short value) {
        mValue = new long[] {value};
        mComponentCount = 1;
    }

    /**
     * Sets long values into this tag. This is useful when we want to modify the tags
     * and write it back to the JPEG file. The component count will be set to the length.
     */
    public void setValue(long[] value) {
        long[] data = new long[value.length];
        System.arraycopy(value, 0, data, 0, value.length);
        mValue = data;
        mComponentCount = value.length;
    }

    /**
     * Sets long value into this tag. This is useful when we want to modify the tags
     * and write it back to the JPEG file. The component count will be set to 1.
     */
    public void setValue(long value) {
        mValue = new long[] {value};
        mComponentCount = 1;
    }

    /**
     * Sets String value into this tag. This is useful when we want to modify the tags
     * and write it back to the JPEG file. The component count will be set to
     * value.length() + 1.
     */
    public void setValue(String value) {
        mComponentCount = value.length() + 1;
        mValue = value;
    }

    /**
     * Sets Rational values into this tag. This is useful when we want to modify the tags
     * and write it back to the JPEG file. The component count will be set to the length.
     */
    public void setValue(Rational[] value) {
        mValue = new Rational[value.length];
        System.arraycopy(value, 0, mValue, 0, value.length);
        mComponentCount = value.length;
    }

    /**
     * Sets Rational value into this tag. This is useful when we want to modify the tags
     * and write it back to the JPEG file. The component count will be set to 1.
     */
    public void setValue(Rational value) {
        mValue = new Rational[] {value};
        mComponentCount = 1;
    }

    /**
     * Sets byte values into this tag. This is useful when we want to modify the tags
     * and write it back to the JPEG file. The component count will be set to the length.
     */
    public void setValue(byte[] value, int offset, int length) {
        long[] data = new long[length];
        for (int i = 0; i < length; i++) {
            data[i] = value[i + offset];
        }
        mValue = data;
        mComponentCount = length;
    }

    /**
     * Sets the byte array as the value of this tag.
     * This is equivalent to setValue(value, 0, value.length).
     */
    public void setValue(byte[] value) {
        setValue(value, 0, value.length);
    }

    public short getShort(int index) {
        if (mValue instanceof long[]) {
            return (short) (((long[]) mValue) [index]);
        } else {
            throw new RuntimeException("There is numerical value in this tag");
        }
    }

    public int getUnsignedShort(int index) {
        if (mValue instanceof long[]) {
            return (int) (((long[]) mValue) [index]);
        } else {
            throw new RuntimeException("There is numerical value in this tag");
        }
    }

    public int getInt(int index) {
        if (mValue instanceof long[]) {
            return (int) (((long[]) mValue) [index]);
        } else {
            throw new RuntimeException("There is numerical value in this tag");
        }
    }

    public long getUnsignedInt(int index) {
        if (mValue instanceof long[]) {
            return ((long[]) mValue) [index];
        } else {
            throw new RuntimeException("There is numerical value in this tag");
        }
    }

    public String getString() {
        return (String) mValue;
    }

    public Rational getRational(int index) {
        Object value = Array.get(mValue, index);
        if (value instanceof Rational) {
            return (Rational) value;
        } else {
            throw new RuntimeException("There is no Rational value in this tag");
        }
    }

    public void getBytes(byte[] buf) {
        getBytes(buf, 0, buf.length);
    }

    public void getBytes(byte[] buf, int offset, int length) {
        if (!(mValue instanceof long[])) {
            throw new RuntimeException("There is no byte value in this tag");
        }
        long[] data = (long[]) mValue;
        for(int i = 0; i < length; i++) {
            buf[offset + i] = (byte) data[i];
        }
    }

    /**
     * Returns a string representation of the value of this tag.
     */
    public String valueToString() {
        StringBuilder sbuilder = new StringBuilder();
        switch(getDataType()) {
            case ExifTag.TYPE_UNDEFINED:
            case ExifTag.TYPE_UNSIGNED_BYTE:
                byte buf[] = new byte[getComponentCount()];
                getBytes(buf);
                for(int i = 0, n = getComponentCount(); i < n; i++) {
                    if(i != 0) sbuilder.append(" ");
                    sbuilder.append(String.format("%02x", buf[i]));
                }
                break;
            case ExifTag.TYPE_ASCII:
                // trim the string for comparison between xml
                sbuilder.append(getString().trim());
                break;
            case ExifTag.TYPE_UNSIGNED_INT:
                for(int i = 0, n = getComponentCount(); i < n; i++) {
                    if(i != 0) sbuilder.append(" ");
                    sbuilder.append(getUnsignedInt(i));
                }
                break;
            case ExifTag.TYPE_RATIONAL:
            case ExifTag.TYPE_UNSIGNED_RATIONAL:
                for(int i = 0, n = getComponentCount(); i < n; i++) {
                    Rational r = getRational(i);
                    if(i != 0) sbuilder.append(" ");
                    sbuilder.append(r.getNominator()).append("/").append(r.getDenominator());
                }
                break;
            case ExifTag.TYPE_UNSIGNED_SHORT:
                for(int i = 0, n = getComponentCount(); i < n; i++) {
                    if(i != 0) sbuilder.append(" ");
                    sbuilder.append(getUnsignedShort(i));
                }
                break;
            case ExifTag.TYPE_INT:
                for(int i = 0, n = getComponentCount(); i < n; i++) {
                    if(i != 0) sbuilder.append(" ");
                    sbuilder.append(getInt(i));
                }
                break;
        }
        return sbuilder.toString();
    }
}