| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 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 |
|
| 33 |
|
| 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 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 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 |
} |