mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-03 19:45:44 -05:00
parent
69512ac396
commit
ead3646581
2 changed files with 9 additions and 7 deletions
|
@ -446,10 +446,11 @@ var Raster = this.Raster = Item.extend(/** @lends Raster# */{
|
|||
getPixel: function(point) {
|
||||
point = Point.read(arguments);
|
||||
var pixels = this.getContext().getImageData(point.x, point.y, 1, 1).data,
|
||||
components = [0, 0, 0, 0];
|
||||
for (var i = 0; i < 4; i++)
|
||||
components = [0, 0, 0];
|
||||
for (var i = 0; i < 3; i++)
|
||||
components[i] = pixels[i] / 255;
|
||||
return new Color('rgb', components);
|
||||
// Alpha is separate now:
|
||||
return new Color('rgb', components, pixels[3] / 255);
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -474,10 +475,11 @@ var Raster = this.Raster = Item.extend(/** @lends Raster# */{
|
|||
_color = Color.read(arguments);
|
||||
var ctx = this.getContext(true),
|
||||
imageData = ctx.createImageData(1, 1),
|
||||
components = _color._convert('rgb'),
|
||||
alpha = _color.getAlpha();
|
||||
imageData.data[0] = _color.getRed() * 255;
|
||||
imageData.data[1] = _color.getGreen() * 255;
|
||||
imageData.data[2] = _color.getBlue() * 255;
|
||||
imageData.data[0] = components[0] * 255;
|
||||
imageData.data[1] = components[1] * 255;
|
||||
imageData.data[2] = components[2] * 255;
|
||||
imageData.data[3] = alpha != null ? alpha * 255 : 255;
|
||||
ctx.putImageData(imageData, _point.x, _point.y);
|
||||
},
|
||||
|
|
|
@ -609,7 +609,7 @@ var Color = this.Color = Base.extend(new function() {
|
|||
*/
|
||||
_convert: function(type) {
|
||||
var converter;
|
||||
return this._type == type
|
||||
return this._type === type
|
||||
? this._components.slice()
|
||||
: (converter = converters[this._type + '-' + type])
|
||||
? converter.apply(this, this._components)
|
||||
|
|
Loading…
Reference in a new issue