123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- ;(function (factory) {
- 'use strict'
- if (typeof define === 'function' && define.amd) {
-
- define(['./load-image'], factory)
- } else if (typeof module === 'object' && module.exports) {
- factory(require('./load-image'))
- } else {
-
- factory(window.loadImage)
- }
- }(function (loadImage) {
- 'use strict'
- var hasblobSlice = typeof Blob !== 'undefined' && (Blob.prototype.slice ||
- Blob.prototype.webkitSlice || Blob.prototype.mozSlice)
- loadImage.blobSlice = hasblobSlice && function () {
- var slice = this.slice || this.webkitSlice || this.mozSlice
- return slice.apply(this, arguments)
- }
- loadImage.metaDataParsers = {
- jpeg: {
- 0xffe1: []
- }
- }
-
-
-
-
-
-
- loadImage.parseMetaData = function (file, callback, options, data) {
- options = options || {}
- data = data || {}
- var that = this
-
- var maxMetaDataSize = options.maxMetaDataSize || 262144
- var noMetaData = !(typeof DataView !== 'undefined' && file && file.size >= 12 &&
- file.type === 'image/jpeg' && loadImage.blobSlice)
- if (noMetaData || !loadImage.readFile(
- loadImage.blobSlice.call(file, 0, maxMetaDataSize),
- function (e) {
- if (e.target.error) {
-
- console.log(e.target.error)
- callback(data)
- return
- }
-
-
-
-
- var buffer = e.target.result
- var dataView = new DataView(buffer)
- var offset = 2
- var maxOffset = dataView.byteLength - 4
- var headLength = offset
- var markerBytes
- var markerLength
- var parsers
- var i
-
- if (dataView.getUint16(0) === 0xffd8) {
- while (offset < maxOffset) {
- markerBytes = dataView.getUint16(offset)
-
-
-
- if ((markerBytes >= 0xffe0 && markerBytes <= 0xffef) ||
- markerBytes === 0xfffe) {
-
-
-
-
- markerLength = dataView.getUint16(offset + 2) + 2
- if (offset + markerLength > dataView.byteLength) {
- console.log('Invalid meta data: Invalid segment size.')
- break
- }
- parsers = loadImage.metaDataParsers.jpeg[markerBytes]
- if (parsers) {
- for (i = 0; i < parsers.length; i += 1) {
- parsers[i].call(
- that,
- dataView,
- offset,
- markerLength,
- data,
- options
- )
- }
- }
- offset += markerLength
- headLength = offset
- } else {
-
-
- break
- }
- }
-
-
- if (!options.disableImageHead && headLength > 6) {
- if (buffer.slice) {
- data.imageHead = buffer.slice(0, headLength)
- } else {
-
-
- data.imageHead = new Uint8Array(buffer)
- .subarray(0, headLength)
- }
- }
- } else {
- console.log('Invalid JPEG file: Missing JPEG marker.')
- }
- callback(data)
- },
- 'readAsArrayBuffer'
- )) {
- callback(data)
- }
- }
-
- loadImage.hasMetaOption = function (options) {
- return options && options.meta
- }
- var originalTransform = loadImage.transform
- loadImage.transform = function (img, options, callback, file, data) {
- if (loadImage.hasMetaOption(options)) {
- loadImage.parseMetaData(file, function (data) {
- originalTransform.call(loadImage, img, options, callback, file, data)
- }, options, data)
- } else {
- originalTransform.apply(loadImage, arguments)
- }
- }
- }))
|