mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
perf step 1 : ok on chrome,horrible on FF
This commit is contained in:
parent
304a5c06da
commit
b3bb2472f1
@ -18,7 +18,8 @@
|
||||
toDescriptor('rectangleSelect', 'S', new pskl.drawingtools.RectangleSelect()),
|
||||
toDescriptor('shapeSelect', 'Z', new pskl.drawingtools.ShapeSelect()),
|
||||
toDescriptor('lighten', 'U', new pskl.drawingtools.Lighten()),
|
||||
toDescriptor('colorPicker', 'O', new pskl.drawingtools.ColorPicker())
|
||||
toDescriptor('colorPicker', 'O', new pskl.drawingtools.ColorPicker()),
|
||||
toDescriptor('colorSwap', 'F', new pskl.drawingtools.ColorSwap())
|
||||
];
|
||||
|
||||
this.currentSelectedTool = this.tools[0];
|
||||
|
45
src/js/drawingtools/ColorSwap.js
Normal file
45
src/js/drawingtools/ColorSwap.js
Normal file
@ -0,0 +1,45 @@
|
||||
/**
|
||||
* @provide pskl.drawingtools.ColorSwap
|
||||
*
|
||||
* @require pskl.utils
|
||||
*/
|
||||
(function() {
|
||||
var ns = $.namespace("pskl.drawingtools");
|
||||
|
||||
ns.ColorSwap = function() {
|
||||
this.toolId = "tool-colorswap";
|
||||
this.helpText = "Color swap";
|
||||
};
|
||||
|
||||
pskl.utils.inherit(ns.ColorSwap, ns.BaseTool);
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
ns.ColorSwap.prototype.applyToolAt = function(col, row, color, frame, overlay, event) {
|
||||
if (frame.containsPixel(col, row)) {
|
||||
var sampledColor = frame.getPixel(col, row);
|
||||
console.time('swapColors');
|
||||
this.swapColors(sampledColor, color);
|
||||
console.timeEnd('swapColors');
|
||||
|
||||
$.publish(Events.PISKEL_SAVE_STATE, {
|
||||
type : pskl.service.HistoryService.SNAPSHOT
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
ns.ColorSwap.prototype.swapColors = function(oldColor, newColor) {
|
||||
var swapPixels = function (pixelColor,x,y,frame) {
|
||||
if (pixelColor == oldColor) {
|
||||
frame.pixels[x][y] = newColor;
|
||||
}
|
||||
};
|
||||
pskl.app.piskelController.getPiskel().getLayers().forEach(function (l) {
|
||||
l.getFrames().forEach(function (f) {
|
||||
f.forEachPixel(swapPixels);
|
||||
f.version++;
|
||||
});
|
||||
});
|
||||
};
|
||||
})();
|
@ -96,16 +96,22 @@
|
||||
|
||||
ns.Frame.prototype.getPixel = function (x, y) {
|
||||
if (this.containsPixel(x, y)) {
|
||||
return this.pixels[x][y];
|
||||
return this._unsafeGetPixel(x,y);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
ns.Frame.prototype._unsafeGetPixel = function (x, y) {
|
||||
return this.pixels[x][y];
|
||||
};
|
||||
|
||||
ns.Frame.prototype.forEachPixel = function (callback) {
|
||||
for (var col = 0 ; col < this.getWidth() ; col++) {
|
||||
for (var row = 0 ; row < this.getHeight() ; row++) {
|
||||
callback(this.getPixel(col, row), col, row);
|
||||
var width = this.getWidth();
|
||||
var height = this.getHeight();
|
||||
for (var col = 0 ; col < width ; col++) {
|
||||
for (var row = 0 ; row < height ; row++) {
|
||||
callback(this._unsafeGetPixel(col, row), col, row, this);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -131,6 +131,7 @@
|
||||
"js/drawingtools/selectiontools/RectangleSelect.js",
|
||||
"js/drawingtools/selectiontools/ShapeSelect.js",
|
||||
"js/drawingtools/ColorPicker.js",
|
||||
"js/drawingtools/ColorSwap.js",
|
||||
// Application controller and initialization
|
||||
"js/app.js"
|
||||
];
|
Loading…
Reference in New Issue
Block a user