mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
wip : needs tests
This commit is contained in:
@@ -18,19 +18,9 @@
|
||||
|
||||
ns.CanvasRenderer.prototype.render = function () {
|
||||
var canvas = this.createCanvas_();
|
||||
var context = canvas.getContext('2d');
|
||||
|
||||
for (var x = 0, width = this.frame.getWidth(); x < width; x++) {
|
||||
for (var y = 0, height = this.frame.getHeight(); y < height; y++) {
|
||||
var color = this.frame.getPixel(x, y);
|
||||
var w = 1;
|
||||
while (color === this.frame.getPixel(x, y + w)) {
|
||||
w++;
|
||||
}
|
||||
this.renderLine_(color, x, y, w, context);
|
||||
y = y + w - 1;
|
||||
}
|
||||
}
|
||||
// Draw in canvas
|
||||
pskl.utils.FrameUtils.drawToCanvas(this.frame, canvas, this.transparentColor_);
|
||||
|
||||
var scaledCanvas = this.createCanvas_(this.zoom);
|
||||
var scaledContext = scaledCanvas.getContext('2d');
|
||||
@@ -49,14 +39,6 @@
|
||||
context.fillRect(x, y, 1, 1);
|
||||
};
|
||||
|
||||
ns.CanvasRenderer.prototype.renderLine_ = function (color, x, y, width, context) {
|
||||
if (color == Constants.TRANSPARENT_COLOR) {
|
||||
color = this.transparentColor_;
|
||||
}
|
||||
context.fillStyle = color;
|
||||
context.fillRect(x, y, 1, width);
|
||||
};
|
||||
|
||||
ns.CanvasRenderer.prototype.createCanvas_ = function (zoom) {
|
||||
zoom = zoom || 1;
|
||||
var width = this.frame.getWidth() * zoom;
|
||||
|
||||
@@ -219,18 +219,8 @@
|
||||
this.canvas = pskl.utils.CanvasUtils.createCanvas(frame.getWidth(), frame.getHeight());
|
||||
}
|
||||
|
||||
var context = this.canvas.getContext('2d');
|
||||
for (var x = 0, width = frame.getWidth() ; x < width ; x++) {
|
||||
for (var y = 0, height = frame.getHeight() ; y < height ; y++) {
|
||||
var color = frame.getPixel(x, y);
|
||||
var w = 1;
|
||||
while (color === frame.getPixel(x, y + w)) {
|
||||
w++;
|
||||
}
|
||||
this.renderLine_(color, x, y, w, context);
|
||||
y = y + w - 1;
|
||||
}
|
||||
}
|
||||
// Draw in canvas
|
||||
pskl.utils.FrameUtils.drawToCanvas(frame, this.canvas);
|
||||
|
||||
this.updateMargins_(frame);
|
||||
|
||||
@@ -264,18 +254,4 @@
|
||||
}
|
||||
displayContext.restore();
|
||||
};
|
||||
|
||||
ns.FrameRenderer.prototype.renderPixel_ = function (color, x, y, context) {
|
||||
if (color != Constants.TRANSPARENT_COLOR) {
|
||||
context.fillStyle = color;
|
||||
context.fillRect(x, y, 1, 1);
|
||||
}
|
||||
};
|
||||
|
||||
ns.FrameRenderer.prototype.renderLine_ = function (color, x, y, width, context) {
|
||||
if (color != Constants.TRANSPARENT_COLOR) {
|
||||
context.fillStyle = color;
|
||||
context.fillRect(x, y, 1, width);
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user