| 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.jpeg; |
| 22 |
|
| 23 |
import com.drew.lang.annotations.NotNull; |
| 24 |
|
| 25 |
import java.io.Serializable; |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
public class JpegComponent implements Serializable |
| 34 |
{ |
| 35 |
private static final long serialVersionUID = 61121257899091914L; |
| 36 |
|
| 37 |
private final int _componentId; |
| 38 |
private final int _samplingFactorByte; |
| 39 |
private final int _quantizationTableNumber; |
| 40 |
|
| 41 |
public JpegComponent(int componentId, int samplingFactorByte, int quantizationTableNumber) |
| 42 |
{ |
| 43 |
_componentId = componentId; |
| 44 |
_samplingFactorByte = samplingFactorByte; |
| 45 |
_quantizationTableNumber = quantizationTableNumber; |
| 46 |
} |
| 47 |
|
| 48 |
public int getComponentId() |
| 49 |
{ |
| 50 |
return _componentId; |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
@NotNull |
| 58 |
public String getComponentName() |
| 59 |
{ |
| 60 |
switch (_componentId) |
| 61 |
{ |
| 62 |
case 1: |
| 63 |
return "Y"; |
| 64 |
case 2: |
| 65 |
return "Cb"; |
| 66 |
case 3: |
| 67 |
return "Cr"; |
| 68 |
case 4: |
| 69 |
return "I"; |
| 70 |
case 5: |
| 71 |
return "Q"; |
| 72 |
default: |
| 73 |
return String.format("Unknown (%s)", _componentId); |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
public int getQuantizationTableNumber() |
| 78 |
{ |
| 79 |
return _quantizationTableNumber; |
| 80 |
} |
| 81 |
|
| 82 |
public int getHorizontalSamplingFactor() |
| 83 |
{ |
| 84 |
return (_samplingFactorByte>>4) & 0x0F; |
| 85 |
} |
| 86 |
|
| 87 |
public int getVerticalSamplingFactor() |
| 88 |
{ |
| 89 |
return _samplingFactorByte & 0x0F; |
| 90 |
} |
| 91 |
|
| 92 |
@NotNull |
| 93 |
@Override |
| 94 |
public String toString() { |
| 95 |
return String.format( |
| 96 |
"Quantization table %d, Sampling factors %d horiz/%d vert", |
| 97 |
_quantizationTableNumber, |
| 98 |
getHorizontalSamplingFactor(), |
| 99 |
getVerticalSamplingFactor() |
| 100 |
); |
| 101 |
} |
| 102 |
} |