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'}
];
this.resetUsedPixels_();
this.usedPixels_ = {
darken : {},
lighten : {}
};
};
pskl.utils.inherit(ns.Lighten, ns.SimplePen);
/**
* @Override
*/
ns.Lighten.prototype.resetUsedPixels_ = function() {
this.usedPixels_ = {
darken : {},
@ -31,8 +37,9 @@
};
this.superclass.resetUsedPixels_.call(this);
};
/**
* @override
* @Override
*/
ns.Lighten.prototype.applyToolAt = function(col, row, color, frame, overlay, event, mouseButton) {
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 cacheKey = frame.getHash();
if (this.cache_[cacheKey]) {
processedFrame = this.cache_[cacheKey];
if (cache[cacheKey]) {
processedFrame = cache[cacheKey];
} else {
var frameAsString = JSON.stringify(frame.getPixels());
if (this.cache_[frameAsString]) {
processedFrame = this.outputCloner(this.cache_[frameAsString], frame);
if (cache[frameAsString]) {
processedFrame = this.outputCloner(cache[frameAsString], frame);
} else {
processedFrame = this.frameProcessor(frame);
this.cache_[frameAsString] = processedFrame;
cache[frameAsString] = processedFrame;
}
this.cache_[cacheKey] = processedFrame;
cache[cacheKey] = processedFrame;
}
return processedFrame;
};