📄 exifdescriptor.java
字号:
/*
* ExifDescriptor.java
*
* This is public domain software - that is, you can do whatever you want
* with it, and include it software that is licensed under the GNU or the
* BSD license, or whatever other licence you choose, including proprietary
* closed source licenses. I do ask that you leave this header in tact.
*
* If you make modifications to this code that you think would benefit the
* wider community, please send me a copy and I'll post it on my site.
*
* If you make use of this code, I'd appreciate hearing about it.
* drew@drewnoakes.com
* Latest version of this software kept at
* http://drewnoakes.com/
*
* Created by dnoakes on 12-Nov-2002 22:27:15 using IntelliJ IDEA.
*/
package com.drew.metadata.exif;
import com.drew.imaging.PhotographicConversions;
import com.drew.lang.Rational;
import com.drew.metadata.Directory;
import com.drew.metadata.MetadataException;
import com.drew.metadata.TagDescriptor;
import java.io.UnsupportedEncodingException;
import java.text.DecimalFormat;
/**
* Contains all logic for the presentation of raw Exif data, as stored in ExifDirectory. Use
* this class to provide human-readable descriptions of tag values.
*/
public class ExifDescriptor extends TagDescriptor
{
/**
* Dictates whether rational values will be represented in decimal format in instances
* where decimal notation is elegant (such as 1/2 -> 0.5, but not 1/3).
*/
private boolean _allowDecimalRepresentationOfRationals = true;
private static final java.text.DecimalFormat SimpleDecimalFormatter = new DecimalFormat("0.#");
public ExifDescriptor(Directory directory)
{
super(directory);
}
// Note for the potential addition of brightness presentation in eV:
// Brightness of taken subject. To calculate Exposure(Ev) from BrigtnessValue(Bv),
// you must add SensitivityValue(Sv).
// Ev=BV+Sv Sv=log2(ISOSpeedRating/3.125)
// ISO100:Sv=5, ISO200:Sv=6, ISO400:Sv=7, ISO125:Sv=5.32.
/**
* Returns a descriptive value of the the specified tag for this image.
* Where possible, known values will be substituted here in place of the raw
* tokens actually kept in the Exif segment. If no substitution is
* available, the value provided by getString(int) will be returned.
* @param tagType the tag to find a description for
* @return a description of the image's value for the specified tag, or
* <code>null</code> if the tag hasn't been defined.
*/
public String getDescription(int tagType) throws MetadataException
{
switch (tagType) {
case ExifDirectory.TAG_ORIENTATION:
return getOrientationDescription();
case ExifDirectory.TAG_NEW_SUBFILE_TYPE:
return getNewSubfileTypeDescription();
case ExifDirectory.TAG_SUBFILE_TYPE:
return getSubfileTypeDescription();
case ExifDirectory.TAG_THRESHOLDING:
return getThresholdingDescription();
case ExifDirectory.TAG_FILL_ORDER:
return getFillOrderDescription();
case ExifDirectory.TAG_RESOLUTION_UNIT:
return getResolutionDescription();
case ExifDirectory.TAG_YCBCR_POSITIONING:
return getYCbCrPositioningDescription();
case ExifDirectory.TAG_EXPOSURE_TIME:
return getExposureTimeDescription();
case ExifDirectory.TAG_SHUTTER_SPEED:
return getShutterSpeedDescription();
case ExifDirectory.TAG_FNUMBER:
return getFNumberDescription();
case ExifDirectory.TAG_X_RESOLUTION:
return getXResolutionDescription();
case ExifDirectory.TAG_Y_RESOLUTION:
return getYResolutionDescription();
case ExifDirectory.TAG_THUMBNAIL_OFFSET:
return getThumbnailOffsetDescription();
case ExifDirectory.TAG_THUMBNAIL_LENGTH:
return getThumbnailLengthDescription();
case ExifDirectory.TAG_COMPRESSION_LEVEL:
return getCompressionLevelDescription();
case ExifDirectory.TAG_SUBJECT_DISTANCE:
return getSubjectDistanceDescription();
case ExifDirectory.TAG_METERING_MODE:
return getMeteringModeDescription();
case ExifDirectory.TAG_WHITE_BALANCE:
return getWhiteBalanceDescription();
case ExifDirectory.TAG_FLASH:
return getFlashDescription();
case ExifDirectory.TAG_FOCAL_LENGTH:
return getFocalLengthDescription();
case ExifDirectory.TAG_COLOR_SPACE:
return getColorSpaceDescription();
case ExifDirectory.TAG_EXIF_IMAGE_WIDTH:
return getExifImageWidthDescription();
case ExifDirectory.TAG_EXIF_IMAGE_HEIGHT:
return getExifImageHeightDescription();
case ExifDirectory.TAG_FOCAL_PLANE_UNIT:
return getFocalPlaneResolutionUnitDescription();
case ExifDirectory.TAG_FOCAL_PLANE_X_RES:
return getFocalPlaneXResolutionDescription();
case ExifDirectory.TAG_FOCAL_PLANE_Y_RES:
return getFocalPlaneYResolutionDescription();
case ExifDirectory.TAG_THUMBNAIL_IMAGE_WIDTH:
return getThumbnailImageWidthDescription();
case ExifDirectory.TAG_THUMBNAIL_IMAGE_HEIGHT:
return getThumbnailImageHeightDescription();
case ExifDirectory.TAG_BITS_PER_SAMPLE:
return getBitsPerSampleDescription();
case ExifDirectory.TAG_COMPRESSION:
return getCompressionDescription();
case ExifDirectory.TAG_PHOTOMETRIC_INTERPRETATION:
return getPhotometricInterpretationDescription();
case ExifDirectory.TAG_ROWS_PER_STRIP:
return getRowsPerStripDescription();
case ExifDirectory.TAG_STRIP_BYTE_COUNTS:
return getStripByteCountsDescription();
case ExifDirectory.TAG_SAMPLES_PER_PIXEL:
return getSamplesPerPixelDescription();
case ExifDirectory.TAG_PLANAR_CONFIGURATION:
return getPlanarConfigurationDescription();
case ExifDirectory.TAG_YCBCR_SUBSAMPLING:
return getYCbCrSubsamplingDescription();
case ExifDirectory.TAG_EXPOSURE_PROGRAM:
return getExposureProgramDescription();
case ExifDirectory.TAG_APERTURE:
return getApertureValueDescription();
case ExifDirectory.TAG_MAX_APERTURE:
return getMaxApertureValueDescription();
case ExifDirectory.TAG_SENSING_METHOD:
return getSensingMethodDescription();
case ExifDirectory.TAG_EXPOSURE_BIAS:
return getExposureBiasDescription();
case ExifDirectory.TAG_FILE_SOURCE:
return getFileSourceDescription();
case ExifDirectory.TAG_SCENE_TYPE:
return getSceneTypeDescription();
case ExifDirectory.TAG_COMPONENTS_CONFIGURATION:
return getComponentConfigurationDescription();
case ExifDirectory.TAG_EXIF_VERSION:
return getExifVersionDescription();
case ExifDirectory.TAG_FLASHPIX_VERSION:
return getFlashPixVersionDescription();
case ExifDirectory.TAG_REFERENCE_BLACK_WHITE:
return getReferenceBlackWhiteDescription();
case ExifDirectory.TAG_ISO_EQUIVALENT:
return getIsoEquivalentDescription();
case ExifDirectory.TAG_THUMBNAIL_DATA:
return getThumbnailDescription();
case ExifDirectory.TAG_USER_COMMENT:
return getUserCommentDescription();
case ExifDirectory.TAG_CUSTOM_RENDERED:
return getCustomRenderedDescription();
case ExifDirectory.TAG_EXPOSURE_MODE:
return getExposureModeDescription();
case ExifDirectory.TAG_WHITE_BALANCE_MODE:
return getWhiteBalanceModeDescription();
case ExifDirectory.TAG_DIGITAL_ZOOM_RATIO:
return getDigitalZoomRatioDescription();
case ExifDirectory.TAG_35MM_FILM_EQUIV_FOCAL_LENGTH:
return get35mmFilmEquivFocalLengthDescription();
case ExifDirectory.TAG_SCENE_CAPTURE_TYPE:
return getSceneCaptureTypeDescription();
case ExifDirectory.TAG_GAIN_CONTROL:
return getGainControlDescription();
case ExifDirectory.TAG_CONTRAST:
return getContrastDescription();
case ExifDirectory.TAG_SATURATION:
return getSaturationDescription();
case ExifDirectory.TAG_SHARPNESS:
return getSharpnessDescription();
case ExifDirectory.TAG_SUBJECT_DISTANCE_RANGE:
return getSubjectDistanceRangeDescription();
case ExifDirectory.TAG_WIN_AUTHOR:
return getWindowsAuthorDescription();
case ExifDirectory.TAG_WIN_COMMENT:
return getWindowsCommentDescription();
case ExifDirectory.TAG_WIN_KEYWORDS:
return getWindowsKeywordsDescription();
case ExifDirectory.TAG_WIN_SUBJECT:
return getWindowsSubjectDescription();
case ExifDirectory.TAG_WIN_TITLE:
return getWindowsTitleDescription();
default:
return _directory.getString(tagType);
}
}
public String getNewSubfileTypeDescription() throws MetadataException
{
if (!_directory.containsTag(ExifDirectory.TAG_NEW_SUBFILE_TYPE)) return null;
switch (_directory.getInt(ExifDirectory.TAG_NEW_SUBFILE_TYPE)) {
case 1: return "Full-resolution image";
case 2: return "Reduced-resolution image";
case 3: return "Single page of multi-page reduced-resolution image";
case 4: return "Transparency mask";
case 5: return "Transparency mask of reduced-resolution image";
case 6: return "Transparency mask of multi-page image";
case 7: return "Transparency mask of reduced-resolution multi-page image";
default:
return "Unknown (" + _directory.getInt(ExifDirectory.TAG_NEW_SUBFILE_TYPE) + ")";
}
}
public String getSubfileTypeDescription() throws MetadataException
{
if (!_directory.containsTag(ExifDirectory.TAG_SUBFILE_TYPE)) return null;
switch (_directory.getInt(ExifDirectory.TAG_SUBFILE_TYPE)) {
case 1: return "Full-resolution image";
case 2: return "Reduced-resolution image";
case 3: return "Single page of multi-page image";
default:
return "Unknown (" + _directory.getInt(ExifDirectory.TAG_SUBFILE_TYPE) + ")";
}
}
public String getThresholdingDescription() throws MetadataException
{
if (!_directory.containsTag(ExifDirectory.TAG_THRESHOLDING)) return null;
switch (_directory.getInt(ExifDirectory.TAG_THRESHOLDING)) {
case 1: return "No dithering or halftoning";
case 2: return "Ordered dither or halftone";
case 3: return "Randomized dither";
default:
return "Unknown (" + _directory.getInt(ExifDirectory.TAG_THRESHOLDING) + ")";
}
}
public String getFillOrderDescription() throws MetadataException
{
if (!_directory.containsTag(ExifDirectory.TAG_FILL_ORDER)) return null;
switch (_directory.getInt(ExifDirectory.TAG_FILL_ORDER)) {
case 1: return "Normal";
case 2: return "Reversed";
default:
return "Unknown (" + _directory.getInt(ExifDirectory.TAG_FILL_ORDER) + ")";
}
}
public String getSubjectDistanceRangeDescription() throws MetadataException
{
if (!_directory.containsTag(ExifDirectory.TAG_SUBJECT_DISTANCE_RANGE)) return null;
switch (_directory.getInt(ExifDirectory.TAG_SUBJECT_DISTANCE_RANGE)) {
case 0:
return "Unknown";
case 1:
return "Macro";
case 2:
return "Close view";
case 3:
return "Distant view";
default:
return "Unknown (" + _directory.getInt(ExifDirectory.TAG_SUBJECT_DISTANCE_RANGE) + ")";
}
}
public String getSharpnessDescription() throws MetadataException
{
if (!_directory.containsTag(ExifDirectory.TAG_SHARPNESS)) return null;
switch (_directory.getInt(ExifDirectory.TAG_SHARPNESS)) {
case 0:
return "None";
case 1:
return "Low";
case 2:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -