Simplified lighten + fixed frame caching bug

This commit is contained in:
jdescottes 2014-07-13 21:01:50 +02:00
parent 56f008bda6
commit 829bcb8ad1
2 changed files with 15 additions and 18 deletions

View File

@ -19,11 +19,17 @@
{key : 'shift', description : 'Apply only once per pixel'} {key : 'shift', description : 'Apply only once per pixel'}
]; ];
this.resetUsedPixels_(); this.usedPixels_ = {
darken : {},
lighten : {}
};
}; };
pskl.utils.inherit(ns.Lighten, ns.SimplePen); pskl.utils.inherit(ns.Lighten, ns.SimplePen);
/**
* @Override
*/
ns.Lighten.prototype.resetUsedPixels_ = function() { ns.Lighten.prototype.resetUsedPixels_ = function() {
this.usedPixels_ = { this.usedPixels_ = {
darken : {}, darken : {},
@ -31,8 +37,9 @@
}; };
this.superclass.resetUsedPixels_.call(this); this.superclass.resetUsedPixels_.call(this);
}; };
/** /**
* @override * @Override
*/ */
ns.Lighten.prototype.applyToolAt = function(col, row, color, frame, overlay, event, mouseButton) { ns.Lighten.prototype.applyToolAt = function(col, row, color, frame, overlay, event, mouseButton) {
var overlayColor = overlay.getPixel(col, row); var overlayColor = overlay.getPixel(col, row);
@ -63,14 +70,4 @@
} }
}; };
ns.Lighten.prototype.releaseToolAt = function(col, row, color, frame, overlay, event) {
this.setPixelsToFrame_(frame, this.pixels);
$.publish(Events.PISKEL_SAVE_STATE, {
type : pskl.service.HistoryService.SNAPSHOT
});
this.resetUsedPixels_();
};
})(); })();

View File

@ -62,17 +62,17 @@
var cache = this.cache_[namespace]; var cache = this.cache_[namespace];
var cacheKey = frame.getHash(); var cacheKey = frame.getHash();
if (this.cache_[cacheKey]) { if (cache[cacheKey]) {
processedFrame = this.cache_[cacheKey]; processedFrame = cache[cacheKey];
} else { } else {
var frameAsString = JSON.stringify(frame.getPixels()); var frameAsString = JSON.stringify(frame.getPixels());
if (this.cache_[frameAsString]) { if (cache[frameAsString]) {
processedFrame = this.outputCloner(this.cache_[frameAsString], frame); processedFrame = this.outputCloner(cache[frameAsString], frame);
} else { } else {
processedFrame = this.frameProcessor(frame); processedFrame = this.frameProcessor(frame);
this.cache_[frameAsString] = processedFrame; cache[frameAsString] = processedFrame;
} }
this.cache_[cacheKey] = processedFrame; cache[cacheKey] = processedFrame;
} }
return processedFrame; return processedFrame;
}; };