| 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.Directory; |
| 26 |
|
| 27 |
import java.util.HashMap; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
@SuppressWarnings("WeakerAccess") |
| 34 |
public class BmpHeaderDirectory extends Directory |
| 35 |
{ |
| 36 |
public static final int TAG_BITMAP_TYPE = -2; |
| 37 |
public static final int TAG_HEADER_SIZE = -1; |
| 38 |
|
| 39 |
public static final int TAG_IMAGE_HEIGHT = 1; |
| 40 |
public static final int TAG_IMAGE_WIDTH = 2; |
| 41 |
public static final int TAG_COLOUR_PLANES = 3; |
| 42 |
public static final int TAG_BITS_PER_PIXEL = 4; |
| 43 |
public static final int TAG_COMPRESSION = 5; |
| 44 |
public static final int TAG_X_PIXELS_PER_METER = 6; |
| 45 |
public static final int TAG_Y_PIXELS_PER_METER = 7; |
| 46 |
public static final int TAG_PALETTE_COLOUR_COUNT = 8; |
| 47 |
public static final int TAG_IMPORTANT_COLOUR_COUNT = 9; |
| 48 |
public static final int TAG_RENDERING = 10; |
| 49 |
public static final int TAG_COLOR_ENCODING = 11; |
| 50 |
public static final int TAG_RED_MASK = 12; |
| 51 |
public static final int TAG_GREEN_MASK = 13; |
| 52 |
public static final int TAG_BLUE_MASK = 14; |
| 53 |
public static final int TAG_ALPHA_MASK = 15; |
| 54 |
public static final int TAG_COLOR_SPACE_TYPE = 16; |
| 55 |
public static final int TAG_GAMMA_RED = 17; |
| 56 |
public static final int TAG_GAMMA_GREEN = 18; |
| 57 |
public static final int TAG_GAMMA_BLUE = 19; |
| 58 |
public static final int TAG_INTENT = 20; |
| 59 |
public static final int TAG_LINKED_PROFILE = 21; |
| 60 |
|
| 61 |
@NotNull |
| 62 |
private static final HashMap<Integer, String> _tagNameMap = new HashMap<Integer, String>(); |
| 63 |
|
| 64 |
static { |
| 65 |
_tagNameMap.put(TAG_BITMAP_TYPE, "Bitmap type"); |
| 66 |
_tagNameMap.put(TAG_HEADER_SIZE, "Header Size"); |
| 67 |
|
| 68 |
_tagNameMap.put(TAG_IMAGE_HEIGHT, "Image Height"); |
| 69 |
_tagNameMap.put(TAG_IMAGE_WIDTH, "Image Width"); |
| 70 |
_tagNameMap.put(TAG_COLOUR_PLANES, "Planes"); |
| 71 |
_tagNameMap.put(TAG_BITS_PER_PIXEL, "Bits Per Pixel"); |
| 72 |
_tagNameMap.put(TAG_COMPRESSION, "Compression"); |
| 73 |
_tagNameMap.put(TAG_X_PIXELS_PER_METER, "X Pixels per Meter"); |
| 74 |
_tagNameMap.put(TAG_Y_PIXELS_PER_METER, "Y Pixels per Meter"); |
| 75 |
_tagNameMap.put(TAG_PALETTE_COLOUR_COUNT, "Palette Colour Count"); |
| 76 |
_tagNameMap.put(TAG_IMPORTANT_COLOUR_COUNT, "Important Colour Count"); |
| 77 |
_tagNameMap.put(TAG_RENDERING, "Rendering"); |
| 78 |
_tagNameMap.put(TAG_COLOR_ENCODING, "Color Encoding"); |
| 79 |
_tagNameMap.put(TAG_RED_MASK, "Red Mask"); |
| 80 |
_tagNameMap.put(TAG_GREEN_MASK, "Green Mask"); |
| 81 |
_tagNameMap.put(TAG_BLUE_MASK, "Blue Mask"); |
| 82 |
_tagNameMap.put(TAG_ALPHA_MASK, "Alpha Mask"); |
| 83 |
_tagNameMap.put(TAG_COLOR_SPACE_TYPE, "Color Space Type"); |
| 84 |
_tagNameMap.put(TAG_GAMMA_RED, "Red Gamma Curve"); |
| 85 |
_tagNameMap.put(TAG_GAMMA_GREEN, "Green Gamma Curve"); |
| 86 |
_tagNameMap.put(TAG_GAMMA_BLUE, "Blue Gamma Curve"); |
| 87 |
_tagNameMap.put(TAG_INTENT, "Rendering Intent"); |
| 88 |
_tagNameMap.put(TAG_LINKED_PROFILE, "Linked Profile File Name"); |
| 89 |
} |
| 90 |
|
| 91 |
public BmpHeaderDirectory() |
| 92 |
{ |
| 93 |
this.setDescriptor(new BmpHeaderDescriptor(this)); |
| 94 |
} |
| 95 |
|
| 96 |
@Nullable |
| 97 |
public BitmapType getBitmapType() { |
| 98 |
Integer value = getInteger(TAG_BITMAP_TYPE); |
| 99 |
return value == null ? null : BitmapType.typeOf(value.intValue()); |
| 100 |
} |
| 101 |
|
| 102 |
@Nullable |
| 103 |
public Compression getCompression() { |
| 104 |
return Compression.typeOf(this); |
| 105 |
} |
| 106 |
|
| 107 |
@Nullable |
| 108 |
public RenderingHalftoningAlgorithm getRendering() { |
| 109 |
Integer value = getInteger(TAG_RENDERING); |
| 110 |
return value == null ? null : RenderingHalftoningAlgorithm.typeOf(value.intValue()); |
| 111 |
} |
| 112 |
|
| 113 |
@Nullable |
| 114 |
public ColorEncoding getColorEncoding() { |
| 115 |
Integer value = getInteger(TAG_COLOR_ENCODING); |
| 116 |
return value == null ? null : ColorEncoding.typeOf(value.intValue()); |
| 117 |
} |
| 118 |
|
| 119 |
@Nullable |
| 120 |
public ColorSpaceType getColorSpaceType() { |
| 121 |
Long value = getLongObject(TAG_COLOR_SPACE_TYPE); |
| 122 |
return value == null ? null : ColorSpaceType.typeOf(value.longValue()); |
| 123 |
} |
| 124 |
|
| 125 |
@Nullable |
| 126 |
public RenderingIntent getRenderingIntent() { |
| 127 |
Integer value = getInteger(TAG_INTENT); |
| 128 |
return value == null ? null : RenderingIntent.typeOf(value.intValue()); |
| 129 |
} |
| 130 |
|
| 131 |
@Override |
| 132 |
@NotNull |
| 133 |
public String getName() |
| 134 |
{ |
| 135 |
return "BMP Header"; |
| 136 |
} |
| 137 |
|
| 138 |
@Override |
| 139 |
@NotNull |
| 140 |
protected HashMap<Integer, String> getTagNameMap() |
| 141 |
{ |
| 142 |
return _tagNameMap; |
| 143 |
} |
| 144 |
|
| 145 |
public enum BitmapType { |
| 146 |
|
| 147 |
|
| 148 |
BITMAP(0x4D42), |
| 149 |
|
| 150 |
|
| 151 |
OS2_BITMAP_ARRAY(0x4142), |
| 152 |
|
| 153 |
|
| 154 |
OS2_ICON(0x4349), |
| 155 |
|
| 156 |
|
| 157 |
OS2_COLOR_ICON(0x4943), |
| 158 |
|
| 159 |
|
| 160 |
OS2_COLOR_POINTER(0x5043), |
| 161 |
|
| 162 |
|
| 163 |
OS2_POINTER(0x5450); |
| 164 |
|
| 165 |
private final int value; |
| 166 |
|
| 167 |
private BitmapType(int value) { |
| 168 |
this.value = value; |
| 169 |
} |
| 170 |
|
| 171 |
public int getValue() { |
| 172 |
return value; |
| 173 |
} |
| 174 |
|
| 175 |
@Nullable |
| 176 |
public static BitmapType typeOf(int value) { |
| 177 |
for (BitmapType bitmapType : BitmapType.values()) |
| 178 |
{ |
| 179 |
if (bitmapType.value == value) |
| 180 |
{ |
| 181 |
return bitmapType; |
| 182 |
} |
| 183 |
} |
| 184 |
return null; |
| 185 |
} |
| 186 |
|
| 187 |
@Override |
| 188 |
@NotNull |
| 189 |
public String toString() { |
| 190 |
switch (this) { |
| 191 |
case BITMAP: return "Standard"; |
| 192 |
case OS2_BITMAP_ARRAY: return "Bitmap Array"; |
| 193 |
case OS2_COLOR_ICON: return "Color Icon"; |
| 194 |
case OS2_COLOR_POINTER: return "Color Pointer"; |
| 195 |
case OS2_ICON: return "Monochrome Icon"; |
| 196 |
case OS2_POINTER: return "Monochrome Pointer"; |
| 197 |
default: |
| 198 |
throw new IllegalStateException("Unimplemented bitmap type " + super.toString()); |
| 199 |
} |
| 200 |
} |
| 201 |
} |
| 202 |
|
| 203 |
public enum Compression { |
| 204 |
|
| 205 |
|
| 206 |
BI_RGB(0), |
| 207 |
|
| 208 |
|
| 209 |
BI_RLE8(1), |
| 210 |
|
| 211 |
|
| 212 |
BI_RLE4(2), |
| 213 |
|
| 214 |
|
| 215 |
BI_BITFIELDS(3), |
| 216 |
|
| 217 |
|
| 218 |
BI_HUFFMAN_1D(3), |
| 219 |
|
| 220 |
|
| 221 |
BI_JPEG(4), |
| 222 |
|
| 223 |
|
| 224 |
BI_RLE24(4), |
| 225 |
|
| 226 |
|
| 227 |
BI_PNG(5), |
| 228 |
|
| 229 |
|
| 230 |
BI_ALPHABITFIELDS(6), |
| 231 |
|
| 232 |
|
| 233 |
BI_CMYK(11), |
| 234 |
|
| 235 |
|
| 236 |
BI_CMYKRLE8(12), |
| 237 |
|
| 238 |
|
| 239 |
BI_CMYKRLE4(13); |
| 240 |
|
| 241 |
private final int value; |
| 242 |
|
| 243 |
private Compression(int value) { |
| 244 |
this.value = value; |
| 245 |
} |
| 246 |
|
| 247 |
public int getValue() { |
| 248 |
return value; |
| 249 |
} |
| 250 |
|
| 251 |
@Nullable |
| 252 |
public static Compression typeOf(@NotNull BmpHeaderDirectory directory) { |
| 253 |
Integer value = directory.getInteger(TAG_COMPRESSION); |
| 254 |
if (value == null) |
| 255 |
return null; |
| 256 |
Integer headerSize = directory.getInteger(TAG_HEADER_SIZE); |
| 257 |
if (headerSize == null) |
| 258 |
return null; |
| 259 |
|
| 260 |
return typeOf(value, headerSize); |
| 261 |
} |
| 262 |
|
| 263 |
@Nullable |
| 264 |
public static Compression typeOf(int value, int headerSize) { |
| 265 |
switch (value) { |
| 266 |
case 0: return BI_RGB; |
| 267 |
case 1: return BI_RLE8; |
| 268 |
case 2: return BI_RLE4; |
| 269 |
case 3: return headerSize == 64 ? BI_HUFFMAN_1D : BI_BITFIELDS; |
| 270 |
case 4: return headerSize == 64 ? BI_RLE24 : BI_JPEG; |
| 271 |
case 5: return BI_PNG; |
| 272 |
case 6: return BI_ALPHABITFIELDS; |
| 273 |
case 11: return BI_CMYK; |
| 274 |
case 12: return BI_CMYKRLE8; |
| 275 |
case 13: return BI_CMYKRLE4; |
| 276 |
default: return null; |
| 277 |
} |
| 278 |
} |
| 279 |
|
| 280 |
@Override |
| 281 |
@NotNull |
| 282 |
public String toString() { |
| 283 |
switch (this) { |
| 284 |
case BI_RGB: return "None"; |
| 285 |
case BI_RLE8: return "RLE 8-bit/pixel"; |
| 286 |
case BI_RLE4: return "RLE 4-bit/pixel"; |
| 287 |
case BI_BITFIELDS: return "Bit Fields"; |
| 288 |
case BI_HUFFMAN_1D: return "Huffman 1D"; |
| 289 |
case BI_JPEG: return "JPEG"; |
| 290 |
case BI_RLE24: return "RLE 24-bit/pixel"; |
| 291 |
case BI_PNG: return "PNG"; |
| 292 |
case BI_ALPHABITFIELDS: return "RGBA Bit Fields"; |
| 293 |
case BI_CMYK: return "CMYK Uncompressed"; |
| 294 |
case BI_CMYKRLE8: return "CMYK RLE-8"; |
| 295 |
case BI_CMYKRLE4: return "CMYK RLE-4"; |
| 296 |
default: |
| 297 |
throw new IllegalStateException("Unimplemented compression type " + super.toString()); |
| 298 |
} |
| 299 |
} |
| 300 |
} |
| 301 |
|
| 302 |
public enum RenderingHalftoningAlgorithm { |
| 303 |
|
| 304 |
|
| 305 |
NONE(0), |
| 306 |
|
| 307 |
|
| 308 |
ERROR_DIFFUSION(1), |
| 309 |
|
| 310 |
|
| 311 |
PANDA(2), |
| 312 |
|
| 313 |
|
| 314 |
SUPER_CIRCLE(3); |
| 315 |
|
| 316 |
private final int value; |
| 317 |
|
| 318 |
private RenderingHalftoningAlgorithm(int value) { |
| 319 |
this.value = value; |
| 320 |
} |
| 321 |
|
| 322 |
public int getValue() { |
| 323 |
return value; |
| 324 |
} |
| 325 |
|
| 326 |
@Nullable |
| 327 |
public static RenderingHalftoningAlgorithm typeOf(int value) { |
| 328 |
for (RenderingHalftoningAlgorithm renderingHalftoningAlgorithm : RenderingHalftoningAlgorithm.values()) |
| 329 |
{ |
| 330 |
if (renderingHalftoningAlgorithm.value == value) |
| 331 |
{ |
| 332 |
return renderingHalftoningAlgorithm; |
| 333 |
} |
| 334 |
} |
| 335 |
return null; |
| 336 |
} |
| 337 |
|
| 338 |
@Override |
| 339 |
@NotNull |
| 340 |
public String toString() { |
| 341 |
switch (this) { |
| 342 |
case NONE: |
| 343 |
return "No Halftoning Algorithm"; |
| 344 |
case ERROR_DIFFUSION: |
| 345 |
return "Error Diffusion Halftoning"; |
| 346 |
case PANDA: |
| 347 |
return "Processing Algorithm for Noncoded Document Acquisition"; |
| 348 |
case SUPER_CIRCLE: |
| 349 |
return "Super-circle Halftoning"; |
| 350 |
default: |
| 351 |
throw new IllegalStateException("Unimplemented rendering halftoning algorithm type " + super.toString()); |
| 352 |
} |
| 353 |
} |
| 354 |
} |
| 355 |
|
| 356 |
public enum ColorEncoding { |
| 357 |
RGB(0); |
| 358 |
|
| 359 |
private final int value; |
| 360 |
|
| 361 |
private ColorEncoding(int value) { |
| 362 |
this.value = value; |
| 363 |
} |
| 364 |
|
| 365 |
public int getValue() { |
| 366 |
return value; |
| 367 |
} |
| 368 |
|
| 369 |
@Nullable |
| 370 |
public static ColorEncoding typeOf(int value) { |
| 371 |
return value == 0 ? RGB : null; |
| 372 |
} |
| 373 |
} |
| 374 |
|
| 375 |
public enum ColorSpaceType { |
| 376 |
|
| 377 |
|
| 378 |
LCS_CALIBRATED_RGB(0L), |
| 379 |
|
| 380 |
|
| 381 |
LCS_sRGB(0x73524742L), |
| 382 |
|
| 383 |
|
| 384 |
LCS_WINDOWS_COLOR_SPACE(0x57696E20L), |
| 385 |
|
| 386 |
|
| 387 |
PROFILE_LINKED(0x4C494E4BL), |
| 388 |
|
| 389 |
|
| 390 |
PROFILE_EMBEDDED(0x4D424544L); |
| 391 |
|
| 392 |
private final long value; |
| 393 |
|
| 394 |
private ColorSpaceType(long value) { |
| 395 |
this.value = value; |
| 396 |
} |
| 397 |
|
| 398 |
public long getValue() { |
| 399 |
return value; |
| 400 |
} |
| 401 |
|
| 402 |
@Nullable |
| 403 |
public static ColorSpaceType typeOf(long value) { |
| 404 |
for (ColorSpaceType colorSpaceType : ColorSpaceType.values()) |
| 405 |
{ |
| 406 |
if (colorSpaceType.value == value) |
| 407 |
{ |
| 408 |
return colorSpaceType; |
| 409 |
} |
| 410 |
} |
| 411 |
return null; |
| 412 |
} |
| 413 |
|
| 414 |
@Override |
| 415 |
@NotNull |
| 416 |
public String toString() { |
| 417 |
switch (this) { |
| 418 |
case LCS_CALIBRATED_RGB: |
| 419 |
return "Calibrated RGB"; |
| 420 |
case LCS_sRGB: |
| 421 |
return "sRGB Color Space"; |
| 422 |
case LCS_WINDOWS_COLOR_SPACE: |
| 423 |
return "System Default Color Space, sRGB"; |
| 424 |
case PROFILE_LINKED: |
| 425 |
return "Linked Profile"; |
| 426 |
case PROFILE_EMBEDDED: |
| 427 |
return "Embedded Profile"; |
| 428 |
default: |
| 429 |
throw new IllegalStateException("Unimplemented color space type " + super.toString()); |
| 430 |
} |
| 431 |
} |
| 432 |
} |
| 433 |
|
| 434 |
public enum RenderingIntent { |
| 435 |
|
| 436 |
|
| 437 |
LCS_GM_BUSINESS(1), |
| 438 |
|
| 439 |
|
| 440 |
LCS_GM_GRAPHICS(2), |
| 441 |
|
| 442 |
|
| 443 |
LCS_GM_IMAGES(4), |
| 444 |
|
| 445 |
|
| 446 |
LCS_GM_ABS_COLORIMETRIC(8); |
| 447 |
|
| 448 |
private final int value; |
| 449 |
|
| 450 |
private RenderingIntent(int value) { |
| 451 |
this.value = value; |
| 452 |
} |
| 453 |
|
| 454 |
public int getValue() { |
| 455 |
return value; |
| 456 |
} |
| 457 |
|
| 458 |
@Nullable |
| 459 |
public static RenderingIntent typeOf(long value) { |
| 460 |
for (RenderingIntent renderingIntent : RenderingIntent.values()) |
| 461 |
{ |
| 462 |
if (renderingIntent.value == value) |
| 463 |
{ |
| 464 |
return renderingIntent; |
| 465 |
} |
| 466 |
} |
| 467 |
return null; |
| 468 |
} |
| 469 |
|
| 470 |
@Override |
| 471 |
@NotNull |
| 472 |
public String toString() { |
| 473 |
switch (this) { |
| 474 |
case LCS_GM_BUSINESS: |
| 475 |
return "Graphic, Saturation"; |
| 476 |
case LCS_GM_GRAPHICS: |
| 477 |
return "Proof, Relative Colorimetric"; |
| 478 |
case LCS_GM_IMAGES: |
| 479 |
return "Picture, Perceptual"; |
| 480 |
case LCS_GM_ABS_COLORIMETRIC: |
| 481 |
return "Match, Absolute Colorimetric"; |
| 482 |
default: |
| 483 |
throw new IllegalStateException("Unimplemented rendering intent " + super.toString()); |
| 484 |
} |
| 485 |
} |
| 486 |
} |
| 487 |
} |