Skip to content

Commit

Permalink
Image, HTML5: Remove getAsImage (not really required and confusing). …
Browse files Browse the repository at this point in the history
…Do not extract meta info from image source now and then - only when it changes. Update internal image reference onresize.
  • Loading branch information
jayarjo committed Mar 21, 2013
1 parent 5831a88 commit cfc8f24
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 31 deletions.
5 changes: 0 additions & 5 deletions src/javascript/image/Image.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,6 @@ define("moxie/image/Image", [
return runtime.exec.call(self, 'Image', 'getAsCanvas');
},

getAsImage: function() {
var runtime = this.connectRuntime(this.ruid);
return runtime.exec.call(self, 'Image', 'getAsImage');
},

/**
Retrieves image in it's current state as mOxie.Blob object. Cannot be run on empty or image in progress (throws
DOMException.INVALID_STATE_ERR).
Expand Down
54 changes: 28 additions & 26 deletions src/javascript/runtime/html5/image/Image.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,29 +81,26 @@ define("moxie/runtime/html5/image/Image", [
if (exact) {
_loadFromBinaryString.call(this, img.getAsBinaryString());
} else {
_img = img.getAsImage();
this.trigger('load', me.getInfo.call(this));
_loadFromDataUrl.call(this, img.getAsDataURL());
}
},

getInfo: function() {
var I = this.getRuntime()
, info = {
var I = this.getRuntime(), info;

if (!_imgInfo && _binStr && I.can('access_image_binary')) {
_imgInfo = new ImageInfo(_binStr);
}

info = {
width: _img && _img.width || 0,
height: _img && _img.height || 0,
type: (_srcBlob.type || _srcBlob.name && Mime.mimes[_srcBlob.name.replace(/^.+\.([^\.]+)$/, "$1").toLowerCase()]) || '',
size: _binStr && _binStr.length || _srcBlob.size || 0,
name: _srcBlob.name || '',
meta: this.meta || {}
meta: _imgInfo && _imgInfo.meta || this.meta || {}
};

if (I.can('access_image_binary') && _binStr) {
if (_imgInfo) {
_imgInfo.purge();
}
_imgInfo = new ImageInfo(_binStr);
Basic.extend(info, _imgInfo);
}
return info;
},

Expand All @@ -114,14 +111,6 @@ define("moxie/runtime/html5/image/Image", [
_resize.apply(this, arguments);
},

getAsImage: function() {
if (!_img) {
throw new x.DOMException(x.DOMException.INVALID_STATE_ERR);
}
_img.id = this.uid + '_img';
return _img;
},

getAsCanvas: function() {
if (_canvas) {
_canvas.id = this.uid + '_canvas';
Expand Down Expand Up @@ -150,7 +139,9 @@ define("moxie/runtime/html5/image/Image", [
return blob;
},

getAsDataURL: function(type, quality) {
getAsDataURL: function(type) {
var quality = arguments[1] || 90;

// if image has not been modified, return the source right away
if (!_modified) {
return _img.src;
Expand Down Expand Up @@ -206,7 +197,12 @@ define("moxie/runtime/html5/image/Image", [
});
}

// re-inject the headers
_binStr = _imgInfo.writeHeaders(_binStr);

// will be re-created from fresh on next getInfo call
_imgInfo.purge();
_imgInfo = null;
}
}

Expand Down Expand Up @@ -291,7 +287,7 @@ define("moxie/runtime/html5/image/Image", [
}

function _resize(width, height, crop, preserveHeaders) {
var ctx, scale, mathFn, x, y, imgWidth, imgHeight, orientation;
var self = this, ctx, scale, mathFn, x, y, imgWidth, imgHeight, orientation;

_preserveHeaders = preserveHeaders; // we will need to check this on export

Expand Down Expand Up @@ -340,15 +336,21 @@ define("moxie/runtime/html5/image/Image", [

if (!_preserveHeaders) {
_rotateToOrientaion(_canvas.width, _canvas.height, orientation);
} else {
this.width = _canvas.width;
this.height = _canvas.height;
}

_drawToCanvas.call(this, _img, _canvas, -x, -y, imgWidth, imgHeight);

this.width = _canvas.width;
this.height = _canvas.height;

_modified = true;
this.trigger('Resize');

// update internal image reference
_img = new Image();
_img.onload = function() {
self.trigger('Resize');
};
_img.src = me.getAsDataURL.call(this);
}


Expand Down

0 comments on commit cfc8f24

Please sign in to comment.