| 1 | /*
|
|---|
| 2 | * Copyright 2002-2019 Drew Noakes and contributors
|
|---|
| 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 |
|
|---|
| 22 | package com.drew.metadata.photoshop;
|
|---|
| 23 |
|
|---|
| 24 | import com.drew.lang.annotations.NotNull;
|
|---|
| 25 | import com.drew.lang.annotations.Nullable;
|
|---|
| 26 | import com.drew.metadata.Directory;
|
|---|
| 27 |
|
|---|
| 28 | import java.util.HashMap;
|
|---|
| 29 |
|
|---|
| 30 | /**
|
|---|
| 31 | * Holds the metadata found in the APPD segment of a JPEG file saved by Photoshop.
|
|---|
| 32 | *
|
|---|
| 33 | * @author Drew Noakes https://drewnoakes.com
|
|---|
| 34 | * @author Yuri Binev
|
|---|
| 35 | * @author Payton Garland
|
|---|
| 36 | */
|
|---|
| 37 | @SuppressWarnings("WeakerAccess")
|
|---|
| 38 | public class PhotoshopDirectory extends Directory
|
|---|
| 39 | {
|
|---|
| 40 | public static final int TAG_CHANNELS_ROWS_COLUMNS_DEPTH_MODE = 0x03E8;
|
|---|
| 41 | public static final int TAG_MAC_PRINT_INFO = 0x03E9;
|
|---|
| 42 | public static final int TAG_XML = 0x03EA;
|
|---|
| 43 | public static final int TAG_INDEXED_COLOR_TABLE = 0x03EB;
|
|---|
| 44 | public static final int TAG_RESOLUTION_INFO = 0x03ED;
|
|---|
| 45 | public static final int TAG_ALPHA_CHANNELS = 0x03EE;
|
|---|
| 46 | public static final int TAG_DISPLAY_INFO_OBSOLETE = 0x03EF;
|
|---|
| 47 | public static final int TAG_CAPTION = 0x03F0;
|
|---|
| 48 | public static final int TAG_BORDER_INFORMATION = 0x03F1;
|
|---|
| 49 | public static final int TAG_BACKGROUND_COLOR = 0x03F2;
|
|---|
| 50 | public static final int TAG_PRINT_FLAGS = 0x03F3;
|
|---|
| 51 | public static final int TAG_GRAYSCALE_AND_MULTICHANNEL_HALFTONING_INFORMATION = 0x03F4;
|
|---|
| 52 | public static final int TAG_COLOR_HALFTONING_INFORMATION = 0x03F5;
|
|---|
| 53 | public static final int TAG_DUOTONE_HALFTONING_INFORMATION = 0x03F6;
|
|---|
| 54 | public static final int TAG_GRAYSCALE_AND_MULTICHANNEL_TRANSFER_FUNCTION = 0x03F7;
|
|---|
| 55 | public static final int TAG_COLOR_TRANSFER_FUNCTIONS = 0x03F8;
|
|---|
| 56 | public static final int TAG_DUOTONE_TRANSFER_FUNCTIONS = 0x03F9;
|
|---|
| 57 | public static final int TAG_DUOTONE_IMAGE_INFORMATION = 0x03FA;
|
|---|
| 58 | public static final int TAG_EFFECTIVE_BLACK_AND_WHITE_VALUES = 0x03FB;
|
|---|
| 59 | // OBSOLETE 0x03FC
|
|---|
| 60 | public static final int TAG_EPS_OPTIONS = 0x03FD;
|
|---|
| 61 | public static final int TAG_QUICK_MASK_INFORMATION = 0x03FE;
|
|---|
| 62 | // OBSOLETE 0x03FF
|
|---|
| 63 | public static final int TAG_LAYER_STATE_INFORMATION = 0x0400;
|
|---|
| 64 | // Working path (not saved) 0x0401
|
|---|
| 65 | public static final int TAG_LAYERS_GROUP_INFORMATION = 0x0402;
|
|---|
| 66 | // OBSOLETE 0x0403
|
|---|
| 67 | public static final int TAG_IPTC = 0x0404;
|
|---|
| 68 | public static final int TAG_IMAGE_MODE_FOR_RAW_FORMAT_FILES = 0x0405;
|
|---|
| 69 | public static final int TAG_JPEG_QUALITY = 0x0406;
|
|---|
| 70 | public static final int TAG_GRID_AND_GUIDES_INFORMATION = 0x0408;
|
|---|
| 71 | public static final int TAG_THUMBNAIL_OLD = 0x0409;
|
|---|
| 72 | public static final int TAG_COPYRIGHT = 0x040A;
|
|---|
| 73 | public static final int TAG_URL = 0x040B;
|
|---|
| 74 | public static final int TAG_THUMBNAIL = 0x040C;
|
|---|
| 75 | public static final int TAG_GLOBAL_ANGLE = 0x040D;
|
|---|
| 76 | // OBSOLETE 0x040E
|
|---|
| 77 | public static final int TAG_ICC_PROFILE_BYTES = 0x040F;
|
|---|
| 78 | public static final int TAG_WATERMARK = 0x0410;
|
|---|
| 79 | public static final int TAG_ICC_UNTAGGED_PROFILE = 0x0411;
|
|---|
| 80 | public static final int TAG_EFFECTS_VISIBLE = 0x0412;
|
|---|
| 81 | public static final int TAG_SPOT_HALFTONE = 0x0413;
|
|---|
| 82 | public static final int TAG_SEED_NUMBER = 0x0414;
|
|---|
| 83 | public static final int TAG_UNICODE_ALPHA_NAMES = 0x0415;
|
|---|
| 84 | public static final int TAG_INDEXED_COLOR_TABLE_COUNT = 0x0416;
|
|---|
| 85 | public static final int TAG_TRANSPARENCY_INDEX = 0x0417;
|
|---|
| 86 | public static final int TAG_GLOBAL_ALTITUDE = 0x0419;
|
|---|
| 87 | public static final int TAG_SLICES = 0x041A;
|
|---|
| 88 | public static final int TAG_WORKFLOW_URL = 0x041B;
|
|---|
| 89 | public static final int TAG_JUMP_TO_XPEP = 0x041C;
|
|---|
| 90 | public static final int TAG_ALPHA_IDENTIFIERS = 0x041D;
|
|---|
| 91 | public static final int TAG_URL_LIST = 0x041E;
|
|---|
| 92 | public static final int TAG_VERSION = 0x0421;
|
|---|
| 93 | public static final int TAG_EXIF_DATA_1 = 0x0422;
|
|---|
| 94 | public static final int TAG_EXIF_DATA_3 = 0x0423;
|
|---|
| 95 | public static final int TAG_XMP_DATA = 0x0424;
|
|---|
| 96 | public static final int TAG_CAPTION_DIGEST = 0x0425;
|
|---|
| 97 | public static final int TAG_PRINT_SCALE = 0x0426;
|
|---|
| 98 | public static final int TAG_PIXEL_ASPECT_RATIO = 0x0428;
|
|---|
| 99 | public static final int TAG_LAYER_COMPS = 0x0429;
|
|---|
| 100 | public static final int TAG_ALTERNATE_DUOTONE_COLORS = 0x042A;
|
|---|
| 101 | public static final int TAG_ALTERNATE_SPOT_COLORS = 0x042B;
|
|---|
| 102 | public static final int TAG_LAYER_SELECTION_IDS = 0x042D;
|
|---|
| 103 | public static final int TAG_HDR_TONING_INFO = 0x042E;
|
|---|
| 104 | public static final int TAG_PRINT_INFO = 0x042F;
|
|---|
| 105 | public static final int TAG_LAYER_GROUPS_ENABLED_ID = 0x0430;
|
|---|
| 106 | public static final int TAG_COLOR_SAMPLERS = 0x0431;
|
|---|
| 107 | public static final int TAG_MEASUREMENT_SCALE = 0x0432;
|
|---|
| 108 | public static final int TAG_TIMELINE_INFORMATION = 0x0433;
|
|---|
| 109 | public static final int TAG_SHEET_DISCLOSURE = 0x0434;
|
|---|
| 110 | public static final int TAG_DISPLAY_INFO = 0x0435;
|
|---|
| 111 | public static final int TAG_ONION_SKINS = 0x0436;
|
|---|
| 112 | public static final int TAG_COUNT_INFORMATION = 0x0438;
|
|---|
| 113 | public static final int TAG_PRINT_INFO_2 = 0x043A;
|
|---|
| 114 | public static final int TAG_PRINT_STYLE = 0x043B;
|
|---|
| 115 | public static final int TAG_MAC_NSPRINTINFO = 0x043C;
|
|---|
| 116 | public static final int TAG_WIN_DEVMODE = 0x043D;
|
|---|
| 117 | public static final int TAG_AUTO_SAVE_FILE_PATH = 0x043E;
|
|---|
| 118 | public static final int TAG_AUTO_SAVE_FORMAT = 0x043F;
|
|---|
| 119 | public static final int TAG_PATH_SELECTION_STATE = 0x0440;
|
|---|
| 120 | // PATH INFO 0x07D0 -> 0x0BB6
|
|---|
| 121 | public static final int TAG_CLIPPING_PATH_NAME = 0x0BB7;
|
|---|
| 122 | public static final int TAG_ORIGIN_PATH_INFO = 0x0BB8;
|
|---|
| 123 | // PLUG IN RESOURCES 0x0FA0 -> 0x1387
|
|---|
| 124 | public static final int TAG_IMAGE_READY_VARIABLES_XML = 0x1B58;
|
|---|
| 125 | public static final int TAG_IMAGE_READY_DATA_SETS = 0x1B59;
|
|---|
| 126 | public static final int TAG_IMAGE_READY_SELECTED_STATE = 0x1B5A;
|
|---|
| 127 | public static final int TAG_IMAGE_READY_7_ROLLOVER = 0x1B5B;
|
|---|
| 128 | public static final int TAG_IMAGE_READY_ROLLOVER = 0x1B5C;
|
|---|
| 129 | public static final int TAG_IMAGE_READY_SAVE_LAYER_SETTINGS = 0x1B5D;
|
|---|
| 130 | public static final int TAG_IMAGE_READY_VERSION = 0x1B5E;
|
|---|
| 131 | public static final int TAG_LIGHTROOM_WORKFLOW = 0x1F40;
|
|---|
| 132 | public static final int TAG_PRINT_FLAGS_INFO = 0x2710;
|
|---|
| 133 |
|
|---|
| 134 | @NotNull
|
|---|
| 135 | protected static final HashMap<Integer, String> _tagNameMap = new HashMap<Integer, String>();
|
|---|
| 136 |
|
|---|
| 137 | static {
|
|---|
| 138 | _tagNameMap.put(TAG_CHANNELS_ROWS_COLUMNS_DEPTH_MODE, "Channels, Rows, Columns, Depth, Mode");
|
|---|
| 139 | _tagNameMap.put(TAG_MAC_PRINT_INFO, "Mac Print Info");
|
|---|
| 140 | _tagNameMap.put(TAG_XML, "XML Data");
|
|---|
| 141 | _tagNameMap.put(TAG_INDEXED_COLOR_TABLE, "Indexed Color Table");
|
|---|
| 142 | _tagNameMap.put(TAG_RESOLUTION_INFO, "Resolution Info");
|
|---|
| 143 | _tagNameMap.put(TAG_ALPHA_CHANNELS, "Alpha Channels");
|
|---|
| 144 | _tagNameMap.put(TAG_DISPLAY_INFO_OBSOLETE, "Display Info (Obsolete)");
|
|---|
| 145 | _tagNameMap.put(TAG_CAPTION, "Caption");
|
|---|
| 146 | _tagNameMap.put(TAG_BORDER_INFORMATION, "Border Information");
|
|---|
| 147 | _tagNameMap.put(TAG_BACKGROUND_COLOR, "Background Color");
|
|---|
| 148 | _tagNameMap.put(TAG_PRINT_FLAGS, "Print Flags");
|
|---|
| 149 | _tagNameMap.put(TAG_GRAYSCALE_AND_MULTICHANNEL_HALFTONING_INFORMATION, "Grayscale and Multichannel Halftoning Information");
|
|---|
| 150 | _tagNameMap.put(TAG_COLOR_HALFTONING_INFORMATION, "Color Halftoning Information");
|
|---|
| 151 | _tagNameMap.put(TAG_DUOTONE_HALFTONING_INFORMATION, "Duotone Halftoning Information");
|
|---|
| 152 | _tagNameMap.put(TAG_GRAYSCALE_AND_MULTICHANNEL_TRANSFER_FUNCTION, "Grayscale and Multichannel Transfer Function");
|
|---|
| 153 | _tagNameMap.put(TAG_COLOR_TRANSFER_FUNCTIONS, "Color Transfer Functions");
|
|---|
| 154 | _tagNameMap.put(TAG_DUOTONE_TRANSFER_FUNCTIONS, "Duotone Transfer Functions");
|
|---|
| 155 | _tagNameMap.put(TAG_DUOTONE_IMAGE_INFORMATION, "Duotone Image Information");
|
|---|
| 156 | _tagNameMap.put(TAG_EFFECTIVE_BLACK_AND_WHITE_VALUES, "Effective Black and White Values");
|
|---|
| 157 | _tagNameMap.put(TAG_EPS_OPTIONS, "EPS Options");
|
|---|
| 158 | _tagNameMap.put(TAG_QUICK_MASK_INFORMATION, "Quick Mask Information");
|
|---|
| 159 | _tagNameMap.put(TAG_LAYER_STATE_INFORMATION, "Layer State Information");
|
|---|
| 160 | _tagNameMap.put(TAG_LAYERS_GROUP_INFORMATION, "Layers Group Information");
|
|---|
| 161 | _tagNameMap.put(TAG_IPTC, "IPTC-NAA Record");
|
|---|
| 162 | _tagNameMap.put(TAG_IMAGE_MODE_FOR_RAW_FORMAT_FILES, "Image Mode for Raw Format Files");
|
|---|
| 163 | _tagNameMap.put(TAG_JPEG_QUALITY, "JPEG Quality");
|
|---|
| 164 | _tagNameMap.put(TAG_GRID_AND_GUIDES_INFORMATION, "Grid and Guides Information");
|
|---|
| 165 | _tagNameMap.put(TAG_THUMBNAIL_OLD, "Photoshop 4.0 Thumbnail");
|
|---|
| 166 | _tagNameMap.put(TAG_COPYRIGHT, "Copyright Flag");
|
|---|
| 167 | _tagNameMap.put(TAG_URL, "URL");
|
|---|
| 168 | _tagNameMap.put(TAG_THUMBNAIL, "Thumbnail Data");
|
|---|
| 169 | _tagNameMap.put(TAG_GLOBAL_ANGLE, "Global Angle");
|
|---|
| 170 | _tagNameMap.put(TAG_ICC_PROFILE_BYTES, "ICC Profile Bytes");
|
|---|
| 171 | _tagNameMap.put(TAG_WATERMARK, "Watermark");
|
|---|
| 172 | _tagNameMap.put(TAG_ICC_UNTAGGED_PROFILE, "ICC Untagged Profile");
|
|---|
| 173 | _tagNameMap.put(TAG_EFFECTS_VISIBLE, "Effects Visible");
|
|---|
| 174 | _tagNameMap.put(TAG_SPOT_HALFTONE, "Spot Halftone");
|
|---|
| 175 | _tagNameMap.put(TAG_SEED_NUMBER, "Seed Number");
|
|---|
| 176 | _tagNameMap.put(TAG_UNICODE_ALPHA_NAMES, "Unicode Alpha Names");
|
|---|
| 177 | _tagNameMap.put(TAG_INDEXED_COLOR_TABLE_COUNT, "Indexed Color Table Count");
|
|---|
| 178 | _tagNameMap.put(TAG_TRANSPARENCY_INDEX, "Transparency Index");
|
|---|
| 179 | _tagNameMap.put(TAG_GLOBAL_ALTITUDE, "Global Altitude");
|
|---|
| 180 | _tagNameMap.put(TAG_SLICES, "Slices");
|
|---|
| 181 | _tagNameMap.put(TAG_WORKFLOW_URL, "Workflow URL");
|
|---|
| 182 | _tagNameMap.put(TAG_JUMP_TO_XPEP, "Jump To XPEP");
|
|---|
| 183 | _tagNameMap.put(TAG_ALPHA_IDENTIFIERS, "Alpha Identifiers");
|
|---|
| 184 | _tagNameMap.put(TAG_URL_LIST, "URL List");
|
|---|
| 185 | _tagNameMap.put(TAG_VERSION, "Version Info");
|
|---|
| 186 | _tagNameMap.put(TAG_EXIF_DATA_1, "EXIF Data 1");
|
|---|
| 187 | _tagNameMap.put(TAG_EXIF_DATA_3, "EXIF Data 3");
|
|---|
| 188 | _tagNameMap.put(TAG_XMP_DATA, "XMP Data");
|
|---|
| 189 | _tagNameMap.put(TAG_CAPTION_DIGEST, "Caption Digest");
|
|---|
| 190 | _tagNameMap.put(TAG_PRINT_SCALE, "Print Scale");
|
|---|
| 191 | _tagNameMap.put(TAG_PIXEL_ASPECT_RATIO, "Pixel Aspect Ratio");
|
|---|
| 192 | _tagNameMap.put(TAG_LAYER_COMPS, "Layer Comps");
|
|---|
| 193 | _tagNameMap.put(TAG_ALTERNATE_DUOTONE_COLORS, "Alternate Duotone Colors");
|
|---|
| 194 | _tagNameMap.put(TAG_ALTERNATE_SPOT_COLORS, "Alternate Spot Colors");
|
|---|
| 195 | _tagNameMap.put(TAG_LAYER_SELECTION_IDS, "Layer Selection IDs");
|
|---|
| 196 | _tagNameMap.put(TAG_HDR_TONING_INFO, "HDR Toning Info");
|
|---|
| 197 | _tagNameMap.put(TAG_PRINT_INFO, "Print Info");
|
|---|
| 198 | _tagNameMap.put(TAG_LAYER_GROUPS_ENABLED_ID, "Layer Groups Enabled ID");
|
|---|
| 199 | _tagNameMap.put(TAG_COLOR_SAMPLERS, "Color Samplers");
|
|---|
| 200 | _tagNameMap.put(TAG_MEASUREMENT_SCALE, "Measurement Scale");
|
|---|
| 201 | _tagNameMap.put(TAG_TIMELINE_INFORMATION, "Timeline Information");
|
|---|
| 202 | _tagNameMap.put(TAG_SHEET_DISCLOSURE, "Sheet Disclosure");
|
|---|
| 203 | _tagNameMap.put(TAG_DISPLAY_INFO, "Display Info");
|
|---|
| 204 | _tagNameMap.put(TAG_ONION_SKINS, "Onion Skins");
|
|---|
| 205 | _tagNameMap.put(TAG_COUNT_INFORMATION, "Count information");
|
|---|
| 206 | _tagNameMap.put(TAG_PRINT_INFO_2, "Print Info 2");
|
|---|
| 207 | _tagNameMap.put(TAG_PRINT_STYLE, "Print Style");
|
|---|
| 208 | _tagNameMap.put(TAG_MAC_NSPRINTINFO, "Mac NSPrintInfo");
|
|---|
| 209 | _tagNameMap.put(TAG_WIN_DEVMODE, "Win DEVMODE");
|
|---|
| 210 | _tagNameMap.put(TAG_AUTO_SAVE_FILE_PATH, "Auto Save File Subpath");
|
|---|
| 211 | _tagNameMap.put(TAG_AUTO_SAVE_FORMAT, "Auto Save Format");
|
|---|
| 212 | _tagNameMap.put(TAG_PATH_SELECTION_STATE, "Subpath Selection State");
|
|---|
| 213 |
|
|---|
| 214 | _tagNameMap.put(TAG_CLIPPING_PATH_NAME, "Clipping Path Name");
|
|---|
| 215 | _tagNameMap.put(TAG_ORIGIN_PATH_INFO, "Origin Subpath Info");
|
|---|
| 216 | _tagNameMap.put(TAG_IMAGE_READY_VARIABLES_XML, "Image Ready Variables XML");
|
|---|
| 217 | _tagNameMap.put(TAG_IMAGE_READY_DATA_SETS, "Image Ready Data Sets");
|
|---|
| 218 | _tagNameMap.put(TAG_IMAGE_READY_SELECTED_STATE, "Image Ready Selected State");
|
|---|
| 219 | _tagNameMap.put(TAG_IMAGE_READY_7_ROLLOVER, "Image Ready 7 Rollover Expanded State");
|
|---|
| 220 | _tagNameMap.put(TAG_IMAGE_READY_ROLLOVER, "Image Ready Rollover Expanded State");
|
|---|
| 221 | _tagNameMap.put(TAG_IMAGE_READY_SAVE_LAYER_SETTINGS, "Image Ready Save Layer Settings");
|
|---|
| 222 | _tagNameMap.put(TAG_IMAGE_READY_VERSION, "Image Ready Version");
|
|---|
| 223 | _tagNameMap.put(TAG_LIGHTROOM_WORKFLOW, "Lightroom Workflow");
|
|---|
| 224 | _tagNameMap.put(TAG_PRINT_FLAGS_INFO, "Print Flags Information");
|
|---|
| 225 | }
|
|---|
| 226 |
|
|---|
| 227 | public PhotoshopDirectory()
|
|---|
| 228 | {
|
|---|
| 229 | this.setDescriptor(new PhotoshopDescriptor(this));
|
|---|
| 230 | }
|
|---|
| 231 |
|
|---|
| 232 | @Override
|
|---|
| 233 | @NotNull
|
|---|
| 234 | public String getName()
|
|---|
| 235 | {
|
|---|
| 236 | return "Photoshop";
|
|---|
| 237 | }
|
|---|
| 238 |
|
|---|
| 239 | @Override
|
|---|
| 240 | @NotNull
|
|---|
| 241 | protected HashMap<Integer, String> getTagNameMap()
|
|---|
| 242 | {
|
|---|
| 243 | return _tagNameMap;
|
|---|
| 244 | }
|
|---|
| 245 |
|
|---|
| 246 | @Nullable
|
|---|
| 247 | public byte[] getThumbnailBytes()
|
|---|
| 248 | {
|
|---|
| 249 | byte[] storedBytes = getByteArray(PhotoshopDirectory.TAG_THUMBNAIL);
|
|---|
| 250 | if (storedBytes == null)
|
|---|
| 251 | storedBytes = getByteArray(PhotoshopDirectory.TAG_THUMBNAIL_OLD);
|
|---|
| 252 | if (storedBytes == null || storedBytes.length <= 28)
|
|---|
| 253 | return null;
|
|---|
| 254 |
|
|---|
| 255 | int thumbSize = storedBytes.length - 28;
|
|---|
| 256 | byte[] thumbBytes = new byte[thumbSize];
|
|---|
| 257 | System.arraycopy(storedBytes, 28, thumbBytes, 0, thumbSize);
|
|---|
| 258 | return thumbBytes;
|
|---|
| 259 | }
|
|---|
| 260 | }
|
|---|