| 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.NotNull;
|
|---|
| 24 | import com.drew.lang.annotations.Nullable;
|
|---|
| 25 | import com.drew.metadata.TagDescriptor;
|
|---|
| 26 |
|
|---|
| 27 | /**
|
|---|
| 28 | * Provides human-readable string versions of the tags stored in a JpegDirectory.
|
|---|
| 29 | * Thanks to Darrell Silver (www.darrellsilver.com) for the initial version of this class.
|
|---|
| 30 | *
|
|---|
| 31 | * @author Drew Noakes http://drewnoakes.com
|
|---|
| 32 | */
|
|---|
| 33 | public class JpegDescriptor extends TagDescriptor<JpegDirectory>
|
|---|
| 34 | {
|
|---|
| 35 | public JpegDescriptor(@NotNull JpegDirectory directory)
|
|---|
| 36 | {
|
|---|
| 37 | super(directory);
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | @Nullable
|
|---|
| 41 | public String getDescription(int tagType)
|
|---|
| 42 | {
|
|---|
| 43 | switch (tagType)
|
|---|
| 44 | {
|
|---|
| 45 | case JpegDirectory.TAG_JPEG_COMPRESSION_TYPE:
|
|---|
| 46 | return getImageCompressionTypeDescription();
|
|---|
| 47 | case JpegDirectory.TAG_JPEG_COMPONENT_DATA_1:
|
|---|
| 48 | return getComponentDataDescription(0);
|
|---|
| 49 | case JpegDirectory.TAG_JPEG_COMPONENT_DATA_2:
|
|---|
| 50 | return getComponentDataDescription(1);
|
|---|
| 51 | case JpegDirectory.TAG_JPEG_COMPONENT_DATA_3:
|
|---|
| 52 | return getComponentDataDescription(2);
|
|---|
| 53 | case JpegDirectory.TAG_JPEG_COMPONENT_DATA_4:
|
|---|
| 54 | return getComponentDataDescription(3);
|
|---|
| 55 | case JpegDirectory.TAG_JPEG_DATA_PRECISION:
|
|---|
| 56 | return getDataPrecisionDescription();
|
|---|
| 57 | case JpegDirectory.TAG_JPEG_IMAGE_HEIGHT:
|
|---|
| 58 | return getImageHeightDescription();
|
|---|
| 59 | case JpegDirectory.TAG_JPEG_IMAGE_WIDTH:
|
|---|
| 60 | return getImageWidthDescription();
|
|---|
| 61 | default:
|
|---|
| 62 | return super.getDescription(tagType);
|
|---|
| 63 | }
|
|---|
| 64 | }
|
|---|
| 65 |
|
|---|
| 66 | @Nullable
|
|---|
| 67 | public String getImageCompressionTypeDescription()
|
|---|
| 68 | {
|
|---|
| 69 | Integer value = _directory.getInteger(JpegDirectory.TAG_JPEG_COMPRESSION_TYPE);
|
|---|
| 70 | if (value==null)
|
|---|
| 71 | return null;
|
|---|
| 72 | // Note there is no 2 or 12
|
|---|
| 73 | switch (value) {
|
|---|
| 74 | case 0: return "Baseline";
|
|---|
| 75 | case 1: return "Extended sequential, Huffman";
|
|---|
| 76 | case 2: return "Progressive, Huffman";
|
|---|
| 77 | case 3: return "Lossless, Huffman";
|
|---|
| 78 | case 5: return "Differential sequential, Huffman";
|
|---|
| 79 | case 6: return "Differential progressive, Huffman";
|
|---|
| 80 | case 7: return "Differential lossless, Huffman";
|
|---|
| 81 | case 8: return "Reserved for JPEG extensions";
|
|---|
| 82 | case 9: return "Extended sequential, arithmetic";
|
|---|
| 83 | case 10: return "Progressive, arithmetic";
|
|---|
| 84 | case 11: return "Lossless, arithmetic";
|
|---|
| 85 | case 13: return "Differential sequential, arithmetic";
|
|---|
| 86 | case 14: return "Differential progressive, arithmetic";
|
|---|
| 87 | case 15: return "Differential lossless, arithmetic";
|
|---|
| 88 | default:
|
|---|
| 89 | return "Unknown type: "+ value;
|
|---|
| 90 | }
|
|---|
| 91 | }
|
|---|
| 92 | @Nullable
|
|---|
| 93 | public String getImageWidthDescription()
|
|---|
| 94 | {
|
|---|
| 95 | final String value = _directory.getString(JpegDirectory.TAG_JPEG_IMAGE_WIDTH);
|
|---|
| 96 | if (value==null)
|
|---|
| 97 | return null;
|
|---|
| 98 | return value + " pixels";
|
|---|
| 99 | }
|
|---|
| 100 |
|
|---|
| 101 | @Nullable
|
|---|
| 102 | public String getImageHeightDescription()
|
|---|
| 103 | {
|
|---|
| 104 | final String value = _directory.getString(JpegDirectory.TAG_JPEG_IMAGE_HEIGHT);
|
|---|
| 105 | if (value==null)
|
|---|
| 106 | return null;
|
|---|
| 107 | return value + " pixels";
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 | @Nullable
|
|---|
| 111 | public String getDataPrecisionDescription()
|
|---|
| 112 | {
|
|---|
| 113 | final String value = _directory.getString(JpegDirectory.TAG_JPEG_DATA_PRECISION);
|
|---|
| 114 | if (value==null)
|
|---|
| 115 | return null;
|
|---|
| 116 | return value + " bits";
|
|---|
| 117 | }
|
|---|
| 118 |
|
|---|
| 119 | @Nullable
|
|---|
| 120 | public String getComponentDataDescription(int componentNumber)
|
|---|
| 121 | {
|
|---|
| 122 | JpegComponent value = _directory.getComponent(componentNumber);
|
|---|
| 123 |
|
|---|
| 124 | if (value==null)
|
|---|
| 125 | return null;
|
|---|
| 126 |
|
|---|
| 127 | StringBuilder sb = new StringBuilder();
|
|---|
| 128 | sb.append(value.getComponentName());
|
|---|
| 129 | sb.append(" component: Quantization table ");
|
|---|
| 130 | sb.append(value.getQuantizationTableNumber());
|
|---|
| 131 | sb.append(", Sampling factors ");
|
|---|
| 132 | sb.append(value.getHorizontalSamplingFactor());
|
|---|
| 133 | sb.append(" horiz/");
|
|---|
| 134 | sb.append(value.getVerticalSamplingFactor());
|
|---|
| 135 | sb.append(" vert");
|
|---|
| 136 | return sb.toString();
|
|---|
| 137 | }
|
|---|
| 138 | }
|
|---|