1 | /*
|
---|
2 | * Copyright 2002-2017 Drew Noakes
|
---|
3 | *
|
---|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
---|
5 | * you may not use this file except in compliance with the License.
|
---|
6 | * You may obtain a copy of the License at
|
---|
7 | *
|
---|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
9 | *
|
---|
10 | * Unless required by applicable law or agreed to in writing, software
|
---|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
---|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
13 | * See the License for the specific language governing permissions and
|
---|
14 | * limitations under the License.
|
---|
15 | *
|
---|
16 | * More information about this project is available at:
|
---|
17 | *
|
---|
18 | * https://drewnoakes.com/code/exif/
|
---|
19 | * https://github.com/drewnoakes/metadata-extractor
|
---|
20 | */
|
---|
21 | package com.drew.metadata.jpeg;
|
---|
22 |
|
---|
23 | import com.drew.lang.annotations.NotNull;
|
---|
24 |
|
---|
25 | import java.io.Serializable;
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * Stores information about a JPEG image component such as the component id, horiz/vert sampling factor and
|
---|
29 | * quantization table number.
|
---|
30 | *
|
---|
31 | * @author Drew Noakes https://drewnoakes.com
|
---|
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 | * Returns the component name (one of: Y, Cb, Cr, I, or Q)
|
---|
55 | * @return the component name
|
---|
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 | }
|
---|