コード例 #1
0
ファイル: canon.php プロジェクト: anqh/core
function parseCanon($block, &$result, $seek, $globalOffset)
{
    $place = 0;
    //current place
    if ($result['Endien'] == "Intel") {
        $intel = 1;
    } else {
        $intel = 0;
    }
    $model = $result['IFD0']['Model'];
    //Get number of tags (2 bytes)
    $num = bin2hex(substr($block, $place, 2));
    $place += 2;
    if ($intel == 1) {
        $num = intel2Moto($num);
    }
    $result['SubIFD']['MakerNote']['MakerNoteNumTags'] = hexdec($num);
    //loop thru all tags  Each field is 12 bytes
    for ($i = 0; $i < hexdec($num); $i++) {
        //2 byte tag
        $tag = bin2hex(substr($block, $place, 2));
        $place += 2;
        if ($intel == 1) {
            $tag = intel2Moto($tag);
        }
        $tag_name = lookup_Canon_tag($tag);
        //2 byte type
        $type = bin2hex(substr($block, $place, 2));
        $place += 2;
        if ($intel == 1) {
            $type = intel2Moto($type);
        }
        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 {
            $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 (isset($GLOBALS['exiferFileSize'])) {
                $exiferFileSize = $GLOBALS['exiferFileSize'];
            } else {
                $exiferFileSize = 0;
            }
            if ($v == 0 && $bytesofdata < $exiferFileSize) {
                $data = fread($seek, $bytesofdata);
            } else {
                if ($v == -1) {
                    $result['Errors'] = $result['Errors']++;
                    $data = '';
                } else {
                    $data = '';
                }
            }
        }
        $result['SubIFD']['MakerNote'][$tag_name] = '';
        // insure the index exists
        $formated_data = formatCanonData($type, $tag, $intel, $data, $result, $result['SubIFD']['MakerNote'][$tag_name]);
        if ($result['VerboseOutput'] == 1) {
            //$result['SubIFD']['MakerNote'][$tag_name] = $formated_data;
            if ($type == "URATIONAL" || $type == "SRATIONAL" || $type == "USHORT" || $type == "SSHORT" || $type == "ULONG" || $type == "SLONG" || $type == "FLOAT" || $type == "DOUBLE") {
                $data = bin2hex($data);
                if ($intel == 1) {
                    $data = intel2Moto($data);
                }
            }
            $result['SubIFD']['MakerNote'][$tag_name . "_Verbose"]['RawData'] = $data;
            $result['SubIFD']['MakerNote'][$tag_name . "_Verbose"]['Type'] = $type;
            $result['SubIFD']['MakerNote'][$tag_name . "_Verbose"]['Bytes'] = $bytesofdata;
        } else {
            //$result['SubIFD']['MakerNote'][$tag_name] = $formated_data;
        }
    }
}
コード例 #2
0
ファイル: canon.php プロジェクト: alx/rosaveloso
function parseCanon($block, &$result, $seek, $globalOffset)
{
    global $exiferFileSize;
    //Manuel: this makes canon maker notes work
    $place = 0;
    //current place
    if ($result['Endien'] == "Intel") {
        $intel = 1;
    } else {
        $intel = 0;
    }
    /* Manuel: start determine a possible makernote offset given in the makernote trailer */
    $offsetDelta = 0;
    //currentOffset of MakerNote starting after TIFF header
    $blockLenBytes = strlen(bin2hex($block)) / 2;
    $currentOffset = ftell($seek) - $blockLenBytes - $globalOffset;
    //get potential trailer 8bytes from end of MakerNote
    //first 4 bytes are trailer signature corresponding to TIFF header
    $trailerId = bin2hex(substr($block, -8, 4));
    if ($intel) {
        $tiffHeader = bin2hex('II');
        //Intel
        // 2 bytes of 0x002a
        $tiffHeader .= intel2Moto('002a');
    } else {
        $tiffHeader = bin2hex('MM');
        //Motorola
        $tiffHeader .= '002a';
    }
    if ($trailerId == $tiffHeader) {
        //is it the trailer?
        //next 4 bytes contain offset value
        $mnOffset = bin2hex(substr($block, -4));
        if ($intel == 1) {
            $mnOffset = intel2Moto($mnOffset);
        }
        //calculate the delta
        $offsetDelta = $currentOffset - hexdec($mnOffset);
    }
    /* Manuel: end determine makernote offset */
    $model = $result['IFD0']['Model'];
    //Get number of tags (2 bytes)
    $num = bin2hex(substr($block, $place, 2));
    $place += 2;
    if ($intel == 1) {
        $num = intel2Moto($num);
    }
    $result['SubIFD']['MakerNote']['MakerNoteNumTags'] = hexdec($num);
    //loop thru all tags  Each field is 12 bytes
    for ($i = 0; $i < hexdec($num); $i++) {
        //2 byte tag
        $tag = bin2hex(substr($block, $place, 2));
        $place += 2;
        if ($intel == 1) {
            $tag = intel2Moto($tag);
        }
        $tag_name = lookup_Canon_tag($tag);
        //2 byte type
        $type = bin2hex(substr($block, $place, 2));
        $place += 2;
        if ($intel == 1) {
            $type = intel2Moto($type);
        }
        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 {
            $value = bin2hex($value);
            if ($intel == 1) {
                $value = intel2Moto($value);
            }
            //offsets are from TIFF header which is 12 bytes from the start of the file
            //Manuel: also account for $offsetDelta given by the makernote offset in TIFF trailer
            $v = fseek($seek, $globalOffset + hexdec($value) + $offsetDelta);
            if ($v == 0 && $bytesofdata < $exiferFileSize) {
                //Manuel: this makes canon maker notes work
                $data = fread($seek, $bytesofdata);
            } else {
                if ($v == -1) {
                    $result['Errors'] = $result['Errors']++;
                }
            }
        }
        $formated_data = formatCanonData($type, $tag, $intel, $data, $result, $result['SubIFD']['MakerNote'][$tag_name]);
        if ($result['VerboseOutput'] == 1) {
            //$result['SubIFD']['MakerNote'][$tag_name] = $formated_data;
            if ($type == "URATIONAL" || $type == "SRATIONAL" || $type == "USHORT" || $type == "SSHORT" || $type == "ULONG" || $type == "SLONG" || $type == "FLOAT" || $type == "DOUBLE") {
                $data = bin2hex($data);
                if ($intel == 1) {
                    $data = intel2Moto($data);
                }
            }
            $result['SubIFD']['MakerNote'][$tag_name . "_Verbose"]['RawData'] = $data;
            $result['SubIFD']['MakerNote'][$tag_name . "_Verbose"]['Type'] = $type;
            $result['SubIFD']['MakerNote'][$tag_name . "_Verbose"]['Bytes'] = $bytesofdata;
        } else {
            //$result['SubIFD']['MakerNote'][$tag_name] = $formated_data;
        }
    }
}