Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Updated to Exifer r5527
  • Loading branch information
bharat committed Jun 7, 2010
1 parent cb1568c commit 06376a5
Show file tree
Hide file tree
Showing 8 changed files with 587 additions and 516 deletions.
602 changes: 332 additions & 270 deletions exifer/upstream/exif.php

Large diffs are not rendered by default.

15 changes: 4 additions & 11 deletions exifer/upstream/makers/canon.php
Expand Up @@ -40,6 +40,7 @@ function lookup_Canon_tag($tag) {
case "0009": $tag = "OwnerName";break;
case "000c": $tag = "CameraSerialNumber";break;
case "000f": $tag = "CustomFunctions";break;
case "0095": $tag = "LensInfo";break;

default: $tag = "unknown:".$tag;break;
}
Expand All @@ -57,21 +58,15 @@ function formatCanonData($type,$tag,$intel,$data,$exif,&$result) {
if($type=="ASCII") {
$result = $data = str_replace("\0", "", $data);
} else if($type=="URATIONAL" || $type=="SRATIONAL") {
$data = bin2hex($data);
if($intel==1) $data = intel2Moto($data);
$top = hexdec(substr($data,8,8));
$bottom = hexdec(substr($data,0,8));
if($bottom!=0) $data=$top/$bottom;
else if($top==0) $data = 0;
else $data=$top."/".$bottom;
$data = unRational($data,$type,$intel);

if($tag=="0204") { //DigitalZoom
$data=$data."x";
}

} else if($type=="USHORT" || $type=="SSHORT" || $type=="ULONG" || $type=="SLONG" || $type=="FLOAT" || $type=="DOUBLE") {

$data = bin2hex($data);
$data = rational($data,$type,$intel);
$result['RAWDATA'] = $data;

if($tag=="0001") { //first chunk
Expand Down Expand Up @@ -377,20 +372,18 @@ function parseCanon($block,&$result,$seek, $globalOffset) {
//2 byte type
$type = bin2hex(substr($block,$place,2));$place+=2;
if($intel==1) $type = intel2Moto($type);
lookup_type($type,$size);
lookup_type($type,$size);

//4 byte count of number of data units
$count = bin2hex(substr($block,$place,4));$place+=4;
if($intel==1) $count = intel2Moto($count);
$bytesofdata = $size*hexdec($count);

if($bytesofdata<=0) {
return; //if this value is 0 or less then we have read all the tags we can
}

//4 byte value of data or pointer to data
$value = substr($block,$place,4);$place+=4;

if($bytesofdata<=4) {
$data = $value;
} else {
Expand Down
13 changes: 2 additions & 11 deletions exifer/upstream/makers/fujifilm.php
Expand Up @@ -44,7 +44,6 @@ function lookup_Fujifilm_tag($tag) {
case "1021": $tag = "FocusMode";break;
case "1030": $tag = "SlowSync";break;
case "1031": $tag = "PictureMode";break;
case "1032": $tag = "Unknown";break;
case "1100": $tag = "ContinuousTakingBracket";break;
case "1200": $tag = "Unknown";break;
case "1300": $tag = "BlurWarning";break;
Expand All @@ -66,22 +65,14 @@ function formatFujifilmData($type,$tag,$intel,$data) {


} else if($type=="URATIONAL" || $type=="SRATIONAL") {
$data = bin2hex($data);
if($intel==1) $data = intel2Moto($data);
$top = hexdec(substr($data,8,8));
$bottom = hexdec(substr($data,0,8));
if($bottom!=0) $data=$top/$bottom;
else if($top==0) $data = 0;
else $data=$top."/".$bottom;
$data = unRational($data,$type,$intel);

if($tag=="1011") { //FlashStrength
$data=$data." EV";
}

} else if($type=="USHORT" || $type=="SSHORT" || $type=="ULONG" || $type=="SLONG" || $type=="FLOAT" || $type=="DOUBLE") {
$data = bin2hex($data);
if($intel==1) $data = intel2Moto($data);
$data=hexdec($data);
$data =rational($data,$type,$intel);

if($tag=="1001") { //Sharpness
if($data == 1) $data = gettext("Soft");
Expand Down
134 changes: 51 additions & 83 deletions exifer/upstream/makers/gps.php
Expand Up @@ -72,103 +72,66 @@ function lookup_GPS_tag($tag) {
return $tag;
}

//=================
// Formats a rational number
//====================================================================
function GPSRational($data, $intel) {

if($intel==1) $top = hexdec(substr($data,8,8)); //intel stores them bottom-top
else $top = hexdec(substr($data,0,8)); //motorola stores them top-bottom

if($intel==1) $bottom = hexdec(substr($data,0,8)); //intel stores them bottom-top
else $bottom = hexdec(substr($data,8,8)); //motorola stores them top-bottom

if($bottom!=0) $data=$top/$bottom;
else if($top==0) $data = 0;
else $data=$top."/".$bottom;

return $data;
}
//=================
// Formats Data for the data type
//====================================================================
function formatGPSData($type,$tag,$intel,$data) {

if($type=="ASCII") {
if($tag=="0001" || $tag=="0003"){ // Latitude Reference, Longitude Reference
$data = ($data{1} == $data{2} && $data{1} == $data{3}) ? $data{0} : $data;
}
if($tag=="0001" || $tag=="0003"){ // Latitude Reference, Longitude Reference
$data = ($data{1} == $data{2} && $data{1} == $data{3}) ? $data{0} : $data;
}

} else if($type=="URATIONAL" || $type=="SRATIONAL") {
$data = bin2hex($data);
if($intel==1) $data = intel2Moto($data);

if($intel==1) $top = hexdec(substr($data,8,8)); //intel stores them bottom-top
else $top = hexdec(substr($data,0,8)); //motorola stores them top-bottom

if($intel==1) $bottom = hexdec(substr($data,0,8)); //intel stores them bottom-top
else $bottom = hexdec(substr($data,8,8)); //motorola stores them top-bottom

if($type=="SRATIONAL" && $top>2147483647) $top = $top - 4294967296; //this makes the number signed instead of unsigned

if($tag=="0002" || $tag=="0004") { //Latitude, Longitude

if($intel==1){
$seconds = GPSRational(substr($data,0,16),$intel);
$hour = GPSRational(substr($data,32,16),$intel);
} else {
$hour= GPSRational(substr($data,0,16),$intel);
$seconds = GPSRational(substr($data,32,16),$intel);
}
$minutes = GPSRational(substr($data,16,16),$intel);

$data = $hour+$minutes/60+$seconds/3600;
} else if($tag=="0007") { //Time
$seconds = GPSRational(substr($data,0,16),$intel);
$minutes = GPSRational(substr($data,16,16),$intel);
$hour = GPSRational(substr($data,32,16),$intel);

$data = $hour.":".$minutes.":".$seconds;
if($tag=="0002" || $tag=="0004" || $tag=='0007') { //Latitude, Longitude, Time
$datum = array();
for ($i=0;$i<strlen($data);$i=$i+8) {
array_push($datum,substr($data, $i, 8));
}
$hour = unRational($datum[0],$type,$intel);
$minutes = unRational($datum[1],$type,$intel);
$seconds = unRational($datum[2],$type,$intel);
if($tag=="0007") { //Time
$data = $hour.":".$minutes.":".$seconds;
} else {
$data = $hour+$minutes/60+$seconds/3600;
}
} else {
if($bottom!=0) $data=$top/$bottom;
else if($top==0) $data = 0;
else $data=$top."/".$bottom;

if($tag=="0006"){
$data .= 'm';
}
$data = unRational($data,$type,$intel);

if($tag=="0006"){
$data .= 'm';
}
}
} else if($type=="USHORT" || $type=="SSHORT" || $type=="ULONG" || $type=="SLONG" || $type=="FLOAT" || $type=="DOUBLE") {
$data = bin2hex($data);
if($intel==1) $data = intel2Moto($data);
$data=hexdec($data);


$data = rational($data,$type,$intel);


} else if($type=="UNDEFINED") {



} else if($type=="UBYTE") {
$data = bin2hex($data);
if($intel==1) $num = intel2Moto($data);


if($tag=="0000") { // VersionID
$data = hexdec(substr($data,0,2)) .
$data = hexdec(substr($data,0,2)) .
".". hexdec(substr($data,2,2)) .
".". hexdec(substr($data,4,2)) .
".". hexdec(substr($data,6,2));

} else if($tag=="0005"){ // Altitude Reference
if($data == "00000000"){ $data = 'Above Sea Level'; }
else if($data == "01000000"){ $data = 'Below Sea Level'; }
}
} else if($tag=="0005"){ // Altitude Reference
if($data == "00000000"){ $data = '+'; }
else if($data == "01000000"){ $data = '-'; }
}

} else {
$data = bin2hex($data);
if($intel==1) $data = intel2Moto($data);
}

return $data;
}

Expand Down Expand Up @@ -220,29 +183,34 @@ function parseGPS($block,&$result,$offset,$seek, $globalOffset) {

//4 byte value or pointer to value if larger than 4 bytes
$value = substr($block,$place,4);$place+=4;

if($bytesofdata<=4) {
if($bytesofdata<=4) {
$data = $value;
} else {
$value = bin2hex($value);
if($intel==1) $value = intel2Moto($value);

$v = fseek($seek,$globalOffset+hexdec($value)); //offsets are from TIFF header which is 12 bytes from the start of the file
if($v==0) {
$data = fread($seek, $bytesofdata);
} else if($v==-1) {
if (strpos('unknown',$tag_name) !== false || $bytesofdata > 1024) {
$result['Errors'] = $result['Errors']++;
$data = '';
$type = 'ASCII';
} else {
$value = bin2hex($value);
if($intel==1) $value = intel2Moto($value);
$v = fseek($seek,$globalOffset+hexdec($value)); //offsets are from TIFF header which is 12 bytes from the start of the file
if($v==0) {
$data = fread($seek, $bytesofdata);
} else {
$result['Errors'] = $result['Errors']++;
$data = '';
$type = 'ASCII';
}
}
}

if($result['VerboseOutput']==1) {
$result['GPS'][$tag_name] = formatGPSData($type,$tag,$intel,$data);
$result['GPS'][$tag_name."_Verbose"]['RawData'] = bin2hex($data);
$result['GPS'][$tag_name."_Verbose"]['Type'] = $type;
$result['GPS'][$tag_name."_Verbose"]['Bytes'] = $bytesofdata;
} else {
$result['GPS'][$tag_name] = formatGPSData($type,$tag,$intel,$data);
}
}
}
}

Expand Down

0 comments on commit 06376a5

Please sign in to comment.