| 1 | /*
|
|---|
| 2 | * Copyright 2002-2012 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 | * http://drewnoakes.com/code/exif/
|
|---|
| 19 | * http://code.google.com/p/metadata-extractor/
|
|---|
| 20 | */
|
|---|
| 21 | package com.drew.metadata.jpeg;
|
|---|
| 22 |
|
|---|
| 23 | import com.drew.lang.annotations.Nullable;
|
|---|
| 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 http://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 | @Nullable
|
|---|
| 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 | }
|
|---|
| 73 | return null;
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | public int getQuantizationTableNumber()
|
|---|
| 77 | {
|
|---|
| 78 | return _quantizationTableNumber;
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | public int getHorizontalSamplingFactor()
|
|---|
| 82 | {
|
|---|
| 83 | return _samplingFactorByte & 0x0F;
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | public int getVerticalSamplingFactor()
|
|---|
| 87 | {
|
|---|
| 88 | return (_samplingFactorByte>>4) & 0x0F;
|
|---|
| 89 | }
|
|---|
| 90 | }
|
|---|