{"version":3,"sources":["webpack:///1.chunk.js","webpack:///src/lib/megapix-image.js"],"names":["webpackJsonp",6,"module","exports","__webpack_require__","__WEBPACK_AMD_DEFINE_ARRAY__","__WEBPACK_AMD_DEFINE_RESULT__","detectSubsampling","img","iw","naturalWidth","ih","naturalHeight","canvas","document","createElement","width","height","ctx","getContext","drawImage","getImageData","data","detectVerticalSquash","sy","ey","py","alpha","ratio","renderImageToDataURL","options","doSquash","renderImageToCanvas","toDataURL","quality","save","transformCoordinate","orientation","subsampled","d","tmpCanvas","tmpCtx","vertSquashRatio","dw","Math","ceil","dh","dy","sx","dx","clearRect","restore","translate","scale","rotate","PI","MegaPixImage","srcImage","window","Blob","Image","URL","createObjectURL","webkitURL","Error","src","this","blob","_this","onload","listeners","imageLoadListeners","i","len","length","prototype","render","target","callback","push","srcLength","imgWidth","imgHeight","maxWidth","maxHeight","type","indexOf","opt","k","tagName","toLowerCase","onrender","apply","undefined"],"mappings":"AAAAA,cAAc,IAERC,EACA,SAASC,EAAQC,EAASC,GCHhC,GAAAC,GAAAC,GAUA,WAMA,QAAAC,GAAAC,GACA,GAAAC,GAAAD,EAAAE,aAAAC,EAAAH,EAAAI,aACA,IAAAH,EAAAE,EAAA,SACA,GAAAE,GAAAC,SAAAC,cAAA,SACAF,GAAAG,MAAAH,EAAAI,OAAA,CACA,IAAAC,GAAAL,EAAAM,WAAA,KAKA,OAJAD,GAAAE,UAAAZ,GAAAC,EAAA,KAIA,IAAAS,EAAAG,aAAA,SAAAC,KAAA,GAEA,SAQA,QAAAC,GAAAf,EAAAC,EAAAE,GACA,GAAAE,GAAAC,SAAAC,cAAA,SACAF,GAAAG,MAAA,EACAH,EAAAI,OAAAN,CACA,IAAAO,GAAAL,EAAAM,WAAA,KACAD,GAAAE,UAAAZ,EAAA,IAMA,KALA,GAAAc,GAAAJ,EAAAG,aAAA,MAAAV,GAAAW,KAEAE,EAAA,EACAC,EAAAd,EACAe,EAAAf,EACAe,EAAAF,GAAA,CACA,GAAAG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onp([1],{\n\n/***/ 6:\n/***/ function(module, exports, __webpack_require__) {\n\n\tvar __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/**\n\t * Mega pixel image rendering library for iOS6 Safari\n\t *\n\t * Fixes iOS6 Safari's image file rendering issue for large size image (over mega-pixel),\n\t * which causes unexpected subsampling when drawing it in canvas.\n\t * By using this library, you can safely render the image with proper stretching.\n\t *\n\t * Copyright (c) 2012 Shinichi Tomita \n\t * Released under the MIT license\n\t */\n\t(function () {\n\t\n\t /**\n\t * Detect subsampling in loaded image.\n\t * In iOS, larger images than 2M pixels may be subsampled in rendering.\n\t */\n\t function detectSubsampling (img) {\n\t var iw = img.naturalWidth, ih = img.naturalHeight;\n\t if (iw * ih > 1024 * 1024) { // subsampling may happen over megapixel image\n\t var canvas = document.createElement('canvas');\n\t canvas.width = canvas.height = 1;\n\t var ctx = canvas.getContext('2d');\n\t ctx.drawImage(img, -iw + 1, 0);\n\t // subsampled image becomes half smaller in rendering size.\n\t // check alpha channel value to confirm image is covering edge pixel or not.\n\t // if alpha value is 0 image is not covering, hence subsampled.\n\t return ctx.getImageData(0, 0, 1, 1).data[3] === 0;\n\t } else {\n\t return false;\n\t }\n\t }\n\t\n\t /**\n\t * Detecting vertical squash in loaded image.\n\t * Fixes a bug which squash image vertically while drawing into canvas for some images.\n\t */\n\t function detectVerticalSquash (img, iw, ih) {\n\t var canvas = document.createElement('canvas');\n\t canvas.width = 1;\n\t canvas.height = ih;\n\t var ctx = canvas.getContext('2d');\n\t ctx.drawImage(img, 0, 0);\n\t var data = ctx.getImageData(0, 0, 1, ih).data;\n\t // search image edge pixel position in case it is squashed vertically.\n\t var sy = 0;\n\t var ey = ih;\n\t var py = ih;\n\t while (py > sy) {\n\t var alpha = data[(py - 1) * 4 + 3];\n\t if (alpha === 0) {\n\t ey = py;\n\t } else {\n\t sy = py;\n\t }\n\t py = (ey + sy) >> 1;\n\t }\n\t var ratio = (py / ih);\n\t return (ratio === 0) ? 1 : ratio;\n\t }\n\t\n\t /**\n\t * Rendering image element (with resizing) and get its data URL\n\t */\n\t function renderImageToDataURL (img, options, doSquash) {\n\t var canvas = document.createElement('canvas');\n\t renderImageToCanvas(img, canvas, options, doSquash);\n\t return canvas.toDataURL(\"image/jpeg\", options.quality || 0.8);\n\t }\n\t\n\t /**\n\t * Rendering image element (with resizing) into the canvas element\n\t */\n\t function renderImageToCanvas (img, canvas, options, doSquash) {\n\t var iw = img.naturalWidth, ih = img.naturalHeight;\n\t var width = options.width, height = options.height;\n\t var ctx = canvas.getContext('2d');\n\t ctx.save();\n\t transformCoordinate(canvas, ctx, width, height, options.orientation);\n\t var subsampled = detectSubsampling(img);\n\t if (subsampled) {\n\t iw /= 2;\n\t ih /= 2;\n\t }\n\t var d = 1024; // size of tiling canvas\n\t var tmpCanvas = document.createElement('canvas');\n\t tmpCanvas.width = tmpCanvas.height = d;\n\t var tmpCtx = tmpCanvas.getContext('2d');\n\t var vertSquashRatio = doSquash ? detectVerticalSquash(img, iw, ih) : 1;\n\t var dw = Math.ceil(d * width / iw);\n\t var dh = Math.ceil(d * height / ih / vertSquashRatio);\n\t var sy = 0;\n\t var dy = 0;\n\t while (sy < ih) {\n\t var sx = 0;\n\t var dx = 0;\n\t while (sx < iw) {\n\t tmpCtx.clearRect(0, 0, d, d);\n\t tmpCtx.drawImage(img, -sx, -sy);\n\t ctx.drawImage(tmpCanvas, 0, 0, d, d, dx, dy, dw, dh);\n\t sx += d;\n\t dx += dw;\n\t }\n\t sy += d;\n\t dy += dh;\n\t }\n\t ctx.restore();\n\t tmpCanvas = tmpCtx = null;\n\t }\n\t\n\t /**\n\t * Transform canvas coordination according to specified frame size and orientation\n\t * Orientation value is from EXIF tag\n\t */\n\t function transformCoordinate (canvas, ctx, width, height, orientation) {\n\t switch (orientation) {\n\t case 5:\n\t case 6:\n\t case 7:\n\t case 8:\n\t canvas.width = height;\n\t canvas.height = width;\n\t break;\n\t default:\n\t canvas.width = width;\n\t canvas.height = height;\n\t }\n\t switch (orientation) {\n\t case 2:\n\t // horizontal flip\n\t ctx.translate(width, 0);\n\t ctx.scale(-1, 1);\n\t break;\n\t case 3:\n\t // 180 rotate left\n\t ctx.translate(width, height);\n\t ctx.rotate(Math.PI);\n\t break;\n\t case 4:\n\t // vertical flip\n\t ctx.translate(0, height);\n\t ctx.scale(1, -1);\n\t break;\n\t case 5:\n\t // vertical flip + 90 rotate right\n\t ctx.rotate(0.5 * Math.PI);\n\t ctx.scale(1, -1);\n\t break;\n\t case 6:\n\t // 90 rotate right\n\t ctx.rotate(0.5 * Math.PI);\n\t ctx.translate(0, -height);\n\t break;\n\t case 7:\n\t // horizontal flip + 90 rotate right\n\t ctx.rotate(0.5 * Math.PI);\n\t ctx.translate(width, -height);\n\t ctx.scale(-1, 1);\n\t break;\n\t case 8:\n\t // 90 rotate left\n\t ctx.rotate(-0.5 * Math.PI);\n\t ctx.translate(-width, 0);\n\t break;\n\t default:\n\t break;\n\t }\n\t }\n\t\n\t\n\t /**\n\t * MegaPixImage class\n\t */\n\t function MegaPixImage (srcImage) {\n\t if (window.Blob && srcImage instanceof Blob) {\n\t var img = new Image();\n\t var URL = window.URL && window.URL.createObjectURL ? window.URL :\n\t window.webkitURL && window.webkitURL.createObjectURL ? window.webkitURL :\n\t null;\n\t if (!URL) {\n\t throw Error(\"No createObjectURL function found to create blob url\");\n\t }\n\t img.src = URL.createObjectURL(srcImage);\n\t this.blob = srcImage;\n\t srcImage = img;\n\t }\n\t if (!srcImage.naturalWidth && !srcImage.naturalHeight) {\n\t var _this = this;\n\t srcImage.onload = function () {\n\t var listeners = _this.imageLoadListeners;\n\t if (listeners) {\n\t _this.imageLoadListeners = null;\n\t for (var i = 0, len = listeners.length; i < len; i++) {\n\t listeners[i]();\n\t }\n\t }\n\t };\n\t this.imageLoadListeners = [];\n\t }\n\t this.srcImage = srcImage;\n\t }\n\t\n\t /**\n\t * Rendering megapix image into specified target element\n\t */\n\t MegaPixImage.prototype.render = function (target, options, callback) {\n\t if (this.imageLoadListeners) {\n\t var _this = this;\n\t this.imageLoadListeners.push(function () {\n\t _this.render(target, options, callback);\n\t });\n\t return;\n\t }\n\t options = options || {};\n\t var srcImage = this.srcImage,\n\t src = srcImage.src,\n\t srcLength = src.length,\n\t imgWidth = srcImage.naturalWidth, imgHeight = srcImage.naturalHeight,\n\t width = options.width, height = options.height,\n\t maxWidth = options.maxWidth, maxHeight = options.maxHeight,\n\t doSquash = this.blob && this.blob.type === 'image/jpeg' ||\n\t src.indexOf('data:image/jpeg') === 0 ||\n\t src.indexOf('.jpg') === srcLength - 4 ||\n\t src.indexOf('.jpeg') === srcLength - 5;\n\t if (width && !height) {\n\t height = (imgHeight * width / imgWidth) << 0;\n\t } else if (height && !width) {\n\t width = (imgWidth * height / imgHeight) << 0;\n\t } else {\n\t width = imgWidth;\n\t height = imgHeight;\n\t }\n\t if (maxWidth && width > maxWidth) {\n\t width = maxWidth;\n\t height = (imgHeight * width / imgWidth) << 0;\n\t }\n\t if (maxHeight && height > maxHeight) {\n\t height = maxHeight;\n\t width = (imgWidth * height / imgHeight) << 0;\n\t }\n\t var opt = {width: width, height: height};\n\t for (var k in options) opt[k] = options[k];\n\t\n\t var tagName = target.tagName.toLowerCase();\n\t if (tagName === 'img') {\n\t target.src = renderImageToDataURL(this.srcImage, opt, doSquash);\n\t } else if (tagName === 'canvas') {\n\t renderImageToCanvas(this.srcImage, target, opt, doSquash);\n\t }\n\t if (typeof this.onrender === 'function') {\n\t this.onrender(target);\n\t }\n\t if (callback) {\n\t callback();\n\t }\n\t };\n\t\n\t /**\n\t * Export class to global\n\t */\n\t if (true) {\n\t !(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_RESULT__ = function () {\n\t return MegaPixImage;\n\t }.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); // for AMD loader\n\t } else {\n\t this.MegaPixImage = MegaPixImage;\n\t }\n\t\n\t})();\n\n\n/***/ }\n\n});\n\n\n/** WEBPACK FOOTER **\n ** 1.chunk.js\n **/","null\n\n\n/** WEBPACK FOOTER **\n ** src/lib/megapix-image.js\n **/"],"sourceRoot":""}