fixing image width and height bug in resources

This commit is contained in:
Danny Yoo 2012-01-17 12:38:33 -05:00
parent 4aed984bb8
commit 3881e0c085
2 changed files with 25 additions and 10 deletions

View File

@ -19,6 +19,8 @@
distorted-image distorted-image
(image-width distorted-image)
(image-height distorted-image)
;; We will want to decompose the image into its individual pixels. We can use ;; We will want to decompose the image into its individual pixels. We can use
;; image->color-list to do this. ;; image->color-list to do this.
@ -60,3 +62,5 @@ dark-image
;; the landmark. ;; the landmark.
red-eye-image red-eye-image
(image-width red-eye-image)
(image-height red-eye-image)

View File

@ -31,10 +31,10 @@ var isImagePath = function(s) {
// A lot of this comes from image/private/kernel.js // A lot of this comes from image/private/kernel.js
var injectImageMethods = function(r, img) { var injectImageMethods = function(r, img, after) {
r.img = img; r.img = img;
r.getHeight = function() { return img.width; }; r.getWidth = function() { return img.width; };
r.getWidth = function() { return img.height; }; r.getHeight = function() { return img.height; };
r.getBaseline = function() { return img.height; }; r.getBaseline = function() { return img.height; };
r.updatePinhole = function() { r.updatePinhole = function() {
var aCopy = plt.baselib.clone(this); var aCopy = plt.baselib.clone(this);
@ -43,20 +43,29 @@ var injectImageMethods = function(r, img) {
return aCopy; return aCopy;
}; };
r.render = function(ctx, x, y) { r.render = function(ctx, x, y) {
installHackToSupportAnimatedGifs(r);
ctx.drawImage(r.animationHackImg, x, y); ctx.drawImage(r.animationHackImg, x, y);
}; };
r.toDomNode = function(params) { r.toDomNode = function(params) {
return img.cloneNode(true); return img.cloneNode(true);
}; };
installHackToSupportAnimatedGifs(r, after);
}; };
var installHackToSupportAnimatedGifs = function(r) { var installHackToSupportAnimatedGifs = function(r, after) {
if (r.animationHackImg) { return; }
r.animationHackImg = r.img.cloneNode(true); r.animationHackImg = r.img.cloneNode(true);
document.body.appendChild(r.animationHackImg); document.body.appendChild(r.animationHackImg);
r.animationHackImg.width = 0; r.animationHackImg.width = 0;
r.animationHackImg.height = 0; r.animationHackImg.height = 0;
if (r.animationHackImg.complete) {
after();
} else {
r.animationHackImg.onload = function() {
delete (r.animationHackImg.onload);
after();
};
}
}; };
@ -79,10 +88,12 @@ EXPORTS['specialize!'] = makeClosure(
rawImage.onload = function() { rawImage.onload = function() {
delete(rawImage.onload); delete(rawImage.onload);
delete(rawImage.onerror); delete(rawImage.onerror);
injectImageMethods(resource, rawImage); var after = function() {
restart(function(MACHINE) { restart(function(MACHINE) {
return finalizeClosureCall(MACHINE, resource); return finalizeClosureCall(MACHINE, resource);
}); });
};
injectImageMethods(resource, rawImage, after);
}; };
rawImage.onerror = function(e) { rawImage.onerror = function(e) {
delete(rawImage.onload); delete(rawImage.onload);