Вход Регистрация
Файл: concrete5.7.5.6/concrete/js/build/vendor/jquery-fileupload/load-image-exif.js
Строк: 306
<?php
/*
 * JavaScript Load Image Exif Parser 1.0.0
 * https://github.com/blueimp/JavaScript-Load-Image
 *
 * Copyright 2013, Sebastian Tschan
 * https://blueimp.net
 *
 * Licensed under the MIT license:
 * http://www.opensource.org/licenses/MIT
 */

/*jslint unparam: true */
/*global define, window, console */

(function (factory) {
    
'use strict';
    if (
typeof define === 'function' && define.amd) {
        
// Register as an anonymous AMD module:
        
define(['load-image''load-image-meta'], factory);
    } else {
        
// Browser globals:
        
factory(window.loadImage);
    }
}(function (
loadImage) {
    
'use strict';

    
loadImage.ExifMap = function () {
        return 
this;
    };

    
loadImage.ExifMap.prototype.map = {
        
'Orientation'0x0112
    
};

    
loadImage.ExifMap.prototype.get = function (id) {
        return 
this[id] || this[this.map[id]];
    };

    
loadImage.getExifThumbnail = function (dataViewoffsetlength) {
        var 
hexData,
            
i,
            
b;
        if (!
length || offset length dataView.byteLength) {
            
console.log('Invalid Exif data: Invalid thumbnail data.');
            return;
        }
        
hexData = [];
        for (
0length+= 1) {
            
dataView.getUint8(offset i);
            
hexData.push((16 '0' '') + b.toString(16));
        }
        return 
'data:image/jpeg,%' hexData.join('%');
    };

    
loadImage.exifTagTypes = {
        
// byte, 8-bit unsigned int:
        
1: {
            
getValue: function (dataViewdataOffset) {
                return 
dataView.getUint8(dataOffset);
            },
            
size1
        
},
        
// ascii, 8-bit byte:
        
2: {
            
getValue: function (dataViewdataOffset) {
                return 
String.fromCharCode(dataView.getUint8(dataOffset));
            },
            
size1,
            
asciitrue
        
},
        
// short, 16 bit int:
        
3: {
            
getValue: function (dataViewdataOffsetlittleEndian) {
                return 
dataView.getUint16(dataOffsetlittleEndian);
            },
            
size2
        
},
        
// long, 32 bit int:
        
4: {
            
getValue: function (dataViewdataOffsetlittleEndian) {
                return 
dataView.getUint32(dataOffsetlittleEndian);
            },
            
size4
        
},
        
// rational = two long values, first is numerator, second is denominator:
        
5: {
            
getValue: function (dataViewdataOffsetlittleEndian) {
                return 
dataView.getUint32(dataOffsetlittleEndian) /
                    
dataView.getUint32(dataOffset 4littleEndian);
            },
            
size8
        
},
        
// slong, 32 bit signed int:
        
9: {
            
getValue: function (dataViewdataOffsetlittleEndian) {
                return 
dataView.getInt32(dataOffsetlittleEndian);
            },
            
size4
        
},
        
// srational, two slongs, first is numerator, second is denominator:
        
10: {
            
getValue: function (dataViewdataOffsetlittleEndian) {
                return 
dataView.getInt32(dataOffsetlittleEndian) /
                    
dataView.getInt32(dataOffset 4littleEndian);
            },
            
size8
        
}
    };
    
// undefined, 8-bit byte, value depending on field:
    
loadImage.exifTagTypes[7] = loadImage.exifTagTypes[1];

    
loadImage.getExifValue = function (dataViewtiffOffsetoffsettypelengthlittleEndian) {
        var 
tagType loadImage.exifTagTypes[type],
            
tagSize,
            
dataOffset,
            
values,
            
i,
            
str,
            
c;
        if (!
tagType) {
            
console.log('Invalid Exif data: Invalid tag type.');
            return;
        }
        
tagSize tagType.size length;
        
// Determine if the value is contained in the dataOffset bytes,
        // or if the value at the dataOffset is a pointer to the actual data:
        
dataOffset tagSize ?
                
tiffOffset dataView.getUint32(offset 8littleEndian) : (offset 8);
        if (
dataOffset tagSize dataView.byteLength) {
            
console.log('Invalid Exif data: Invalid data offset.');
            return;
        }
        if (
length === 1) {
            return 
tagType.getValue(dataViewdataOffsetlittleEndian);
        }
        
values = [];
        for (
0length+= 1) {
            
values[i] = tagType.getValue(dataViewdataOffset tagType.sizelittleEndian);
        }
        if (
tagType.ascii) {
            
str '';
            
// Concatenate the chars:
            
for (0values.length+= 1) {
                
values[i];
                
// Ignore the terminating NULL byte(s):
                
if (=== 'u0000') {
                    break;
                }
                
str += c;
            }
            return 
str;
        }
        return 
values;
    };

    
loadImage.parseExifTag = function (dataViewtiffOffsetoffsetlittleEndiandata) {
        var 
tag dataView.getUint16(offsetlittleEndian);
        
data.exif[tag] = loadImage.getExifValue(
            
dataView,
            
tiffOffset,
            
offset,
            
dataView.getUint16(offset 2littleEndian), // tag type
            
dataView.getUint32(offset 4littleEndian), // tag length
            
littleEndian
        
);
    };

    
loadImage.parseExifTags = function (dataViewtiffOffsetdirOffsetlittleEndiandata) {
        var 
tagsNumber,
            
dirEndOffset,
            
i;
        if (
dirOffset dataView.byteLength) {
            
console.log('Invalid Exif data: Invalid directory offset.');
            return;
        }
        
tagsNumber dataView.getUint16(dirOffsetlittleEndian);
        
dirEndOffset dirOffset 12 tagsNumber;
        if (
dirEndOffset dataView.byteLength) {
            
console.log('Invalid Exif data: Invalid directory size.');
            return;
        }
        for (
0tagsNumber+= 1) {
            
this.parseExifTag(
                
dataView,
                
tiffOffset,
                
dirOffset 12 i// tag offset
                
littleEndian,
                
data
            
);
        }
        
// Return the offset to the next directory:
        
return dataView.getUint32(dirEndOffsetlittleEndian);
    };

    
loadImage.parseExifData = function (dataViewoffsetlengthdataoptions) {
        if (
options.disableExif) {
            return;
        }
        var 
tiffOffset offset 10,
            
littleEndian,
            
dirOffset,
            
thumbnailData;
        
// Check for the ASCII code for "Exif" (0x45786966):
        
if (dataView.getUint32(offset 4) !== 0x45786966) {
            
// No Exif data, might be XMP data instead
            
return;
        }
        if (
tiffOffset dataView.byteLength) {
            
console.log('Invalid Exif data: Invalid segment size.');
            return;
        }
        
// Check for the two null bytes:
        
if (dataView.getUint16(offset 8) !== 0x0000) {
            
console.log('Invalid Exif data: Missing byte alignment offset.');
            return;
        }
        
// Check the byte alignment:
        
switch (dataView.getUint16(tiffOffset)) {
        case 
0x4949:
            
littleEndian true;
            break;
        case 
0x4D4D:
            
littleEndian false;
            break;
        default:
            
console.log('Invalid Exif data: Invalid byte alignment marker.');
            return;
        }
        
// Check for the TIFF tag marker (0x002A):
        
if (dataView.getUint16(tiffOffset 2littleEndian) !== 0x002A) {
            
console.log('Invalid Exif data: Missing TIFF marker.');
            return;
        }
        
// Retrieve the directory offset bytes, usually 0x00000008 or 8 decimal:
        
dirOffset dataView.getUint32(tiffOffset 4littleEndian);
        
// Create the exif object to store the tags:
        
data.exif = new loadImage.ExifMap();
        
// Parse the tags of the main image directory and retrieve the
        // offset to the next directory, usually the thumbnail directory:
        
dirOffset loadImage.parseExifTags(
            
dataView,
            
tiffOffset,
            
tiffOffset dirOffset,
            
littleEndian,
            
data
        
);
        if (
dirOffset && !options.disableExifThumbnail) {
            
thumbnailData = {exif: {}};
            
dirOffset loadImage.parseExifTags(
                
dataView,
                
tiffOffset,
                
tiffOffset dirOffset,
                
littleEndian,
                
thumbnailData
            
);
            
// Check for JPEG Thumbnail offset:
            
if (thumbnailData.exif[0x0201]) {
                
data.exif.Thumbnail loadImage.getExifThumbnail(
                    
dataView,
                    
tiffOffset thumbnailData.exif[0x0201],
                    
thumbnailData.exif[0x0202// Thumbnail data length
                
);
            }
        }
        
// Check for Exif Sub IFD Pointer:
        
if (data.exif[0x8769] && !options.disableExifSub) {
            
loadImage.parseExifTags(
                
dataView,
                
tiffOffset,
                
tiffOffset data.exif[0x8769], // directory offset
                
littleEndian,
                
data
            
);
        }
        
// Check for GPS Info IFD Pointer:
        
if (data.exif[0x8825] && !options.disableExifGps) {
            
loadImage.parseExifTags(
                
dataView,
                
tiffOffset,
                
tiffOffset data.exif[0x8825], // directory offset
                
littleEndian,
                
data
            
);
        }
    };

    
// Registers the Exif parser for the APP1 JPEG meta data segment:
    
loadImage.metaDataParsers.jpeg[0xffe1].push(loadImage.parseExifData);

    
// Adds the following properties to the parseMetaData callback data:
    // * exif: The exif tags, parsed by the parseExifData method

    // Adds the following options to the parseMetaData method:
    // * disableExif: Disables Exif parsing.
    // * disableExifThumbnail: Disables parsing of the Exif Thumbnail.
    // * disableExifSub: Disables parsing of the Exif Sub IFD.
    // * disableExifGps: Disables parsing of the Exif GPS Info IFD.

}));
?>
Онлайн: 3
Реклама