1<?php 2 3/** 4 * Exifer 5 * Extracts EXIF information from digital photos. 6 * 7 * Copyright © 2003 Jake Olefsky 8 * http://www.offsky.com/software/exif/index.php 9 * jake@olefsky.com 10 * 11 * Please see exif.php for the complete information about this software. 12 * 13 * This program is free software; you can redistribute it and/or modify it under the terms of 14 * the GNU General Public License as published by the Free Software Foundation; either version 2 15 * of the License, or (at your option) any later version. 16 * 17 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 18 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 19 * See the GNU General Public License for more details. http://www.gnu.org/copyleft/gpl.html 20 */ 21 22/** 23 * Looks up the name of the tag for the MakerNote (Depends on Manufacturer) 24 * 25 * @param type $tag 26 * @return string 27 */ 28function lookup_Olympus_tag($tag) { 29 switch ($tag) { 30 case "0200": $tag = "SpecialMode"; 31 break; 32 case "0201": $tag = "JpegQual"; 33 break; 34 case "0202": $tag = "Macro"; 35 break; 36 case "0203": $tag = "Unknown1"; 37 break; 38 case "0204": $tag = "DigiZoom"; 39 break; 40 case "0205": $tag = "Unknown2"; 41 break; 42 case "0206": $tag = "Unknown3"; 43 break; 44 case "0207": $tag = "SoftwareRelease"; 45 break; 46 case "0208": $tag = "PictInfo"; 47 break; 48 case "0209": $tag = "CameraID"; 49 break; 50 case "0f00": $tag = "DataDump"; 51 break; 52 default: $tag = "unknown:" . $tag; 53 break; 54 } 55 56 return $tag; 57} 58 59/** 60 * Formats Data for the data type 61 * 62 * @param type $type 63 * @param type $tag 64 * @param type $intel 65 * @param type $data 66 * @return type 67 */ 68function formatOlympusData($type, $tag, $intel, $data) { 69 if ($type == "ASCII") { 70 71 } else if ($type == "URATIONAL" || $type == "SRATIONAL") { 72 $data = unRational($data, $type, $intel); 73 if ($intel == 1) { 74 $data = intel2Moto($data); 75 } 76 if ($tag == "0204") { //DigitalZoom 77 $data = $data . "x"; 78 } 79 if ($tag == "0205") { //Unknown2 80 } 81 } else if ($type == "USHORT" || $type == "SSHORT" || $type == "ULONG" || $type == "SLONG" || $type == "FLOAT" || $type == "DOUBLE") { 82 $data = rational($data, $type, $intel); 83 84 if ($tag == "0201") { //JPEGQuality 85 if ($data == 1) { 86 $data = "SQ"; 87 } else if ($data == 2) { 88 $data = "HQ"; 89 } else if ($data == 3) { 90 $data = "SHQ"; 91 } else { 92 $data = gettext("Unknown") . ": " . $data; 93 } 94 } 95 if ($tag == "0202") { //Macro 96 if ($data == 0) { 97 $data = "Normal"; 98 } else if ($data == 1) { 99 $data = "Macro"; 100 } else { 101 $data = gettext("Unknown") . ": " . $data; 102 } 103 } 104 } else if ($type == "UNDEFINED") { 105 106 } else { 107 $data = bin2hex($data); 108 if ($intel == 1) { 109 $data = intel2Moto($data); 110 } 111 } 112 113 return $data; 114} 115 116/** 117 * Olympus Special data section 118 // - Updated by Zenphoto for new header tag in E-410/E-510/E-3 cameras. 2/24/2008 119 * 120 * @param type $block 121 * @param type $result 122 * @param type $seek 123 * @param type $globalOffset 124 * @return boolean 125 */ 126function parseOlympus($block, &$result, $seek, $globalOffset) { 127 128 if ($result['Endien'] == "Intel") { 129 $intel = 1; 130 } else { 131 $intel = 0; 132 } 133 134 $model = $result['IFD0']['Model']; 135 136 // New header for new DSLRs - Check for it because the 137 // number of bytes that count the IFD fields differ in each case. 138 // Fixed by Zenphoto 2/24/08 139 $new = false; 140 if (substr($block, 0, 8) == "OLYMPUS\x00") { 141 $new = true; 142 } else if (substr($block, 0, 7) == "OLYMP\x00\x01" || substr($block, 0, 7) == "OLYMP\x00\x02") { 143 $new = false; 144 } else { 145 // Header does not match known Olympus headers. 146 // This is not a valid OLYMPUS Makernote. 147 return false; 148 } 149 150 // Offset of IFD entry after Olympus header. 151 $place = 8; 152 $offset = 8; 153 154 // Get number of tags (1 or 2 bytes, depending on New or Old makernote) 155 $countfieldbits = $new ? 1 : 2; 156 // New makernote repeats 1-byte value twice, so increment $place by 2 in either case. 157 $num = bin2hex(substr($block, $place, $countfieldbits)); 158 $place += 2; 159 if ($intel == 1) { 160 $num = intel2Moto($num); 161 } 162 $ntags = hexdec($num); 163 $result['SubIFD']['MakerNote']['MakerNoteNumTags'] = $ntags; 164 165 //loop thru all tags Each field is 12 bytes 166 for ($i = 0; $i < $ntags; $i++) { 167 //2 byte tag 168 $tag = bin2hex(substr($block, $place, 2)); 169 $place += 2; 170 if ($intel == 1) { 171 $tag = intel2Moto($tag); 172 } 173 $tag_name = lookup_Olympus_tag($tag); 174 175 //2 byte type 176 $type = bin2hex(substr($block, $place, 2)); 177 $place += 2; 178 if ($intel == 1) { 179 $type = intel2Moto($type); 180 } 181 lookup_type($type, $size); 182 183 //4 byte count of number of data units 184 $count = bin2hex(substr($block, $place, 4)); 185 $place += 4; 186 if ($intel == 1) { 187 $count = intel2Moto($count); 188 } 189 $bytesofdata = $size * hexdec($count); 190 191 //4 byte value of data or pointer to data 192 $value = substr($block, $place, 4); 193 $place += 4; 194 195 if ($bytesofdata <= 4) { 196 $data = substr($value, 0, $bytesofdata); 197 } else { 198 $value = bin2hex($value); 199 if ($intel == 1) { 200 $value = intel2Moto($value); 201 } 202 $v = fseek($seek, $globalOffset + hexdec($value)); //offsets are from TIFF header which is 12 bytes from the start of the file 203 if (isset($GLOBALS['exiferFileSize']) && $v == 0 && $bytesofdata < $GLOBALS['exiferFileSize']) { 204 $data = fread($seek, $bytesofdata); 205 } else { 206 $result['Errors'] = $result['Errors']++; 207 $data = ''; 208 } 209 } 210 $formated_data = formatOlympusData($type, $tag, $intel, $data); 211 212 if ($result['VerboseOutput'] == 1) { 213 $result['SubIFD']['MakerNote'][$tag_name] = $formated_data; 214 if ($type == "URATIONAL" || $type == "SRATIONAL" || $type == "USHORT" || $type == "SSHORT" || $type == "ULONG" || $type == "SLONG" || $type == "FLOAT" || $type == "DOUBLE") { 215 $data = bin2hex($data); 216 if ($intel == 1) { 217 $data = intel2Moto($data); 218 } 219 } 220 $result['SubIFD']['MakerNote'][$tag_name . "_Verbose"]['RawData'] = $data; 221 $result['SubIFD']['MakerNote'][$tag_name . "_Verbose"]['Type'] = $type; 222 $result['SubIFD']['MakerNote'][$tag_name . "_Verbose"]['Bytes'] = $bytesofdata; 223 } else { 224 $result['SubIFD']['MakerNote'][$tag_name] = $formated_data; 225 } 226 } 227} 228