mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
moved rgbToHex correct implementation to pskl core utils
This commit is contained in:
parent
b5465ca066
commit
6583d3d560
@ -68,34 +68,13 @@
|
|||||||
if (a < 125) {
|
if (a < 125) {
|
||||||
grid[x][y] = Constants.TRANSPARENT_COLOR;
|
grid[x][y] = Constants.TRANSPARENT_COLOR;
|
||||||
} else {
|
} else {
|
||||||
grid[x][y] = pskl.utils.FrameUtils.rgbToHex_(r,g,b);
|
grid[x][y] = pskl.utils.rgbToHex(r,g,b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return pskl.model.Frame.fromPixelGrid(grid);
|
return pskl.model.Frame.fromPixelGrid(grid);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert a rgb(Number, Number, Number) color to hexadecimal representation
|
|
||||||
* @param {Number} r red value, between 0 and 255
|
|
||||||
* @param {Number} g green value, between 0 and 255
|
|
||||||
* @param {Number} b blue value, between 0 and 255
|
|
||||||
* @return {String} hex representation of the color '#ABCDEF'
|
|
||||||
*/
|
|
||||||
rgbToHex_ : function (r, g, b) {
|
|
||||||
return "#" + this.componentToHex_(r) + this.componentToHex_(g) + this.componentToHex_(b);
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert a color component (as a Number between 0 and 255) to its string hexa representation
|
|
||||||
* @param {Number} c component value, between 0 and 255
|
|
||||||
* @return {String} eg. '0A'
|
|
||||||
*/
|
|
||||||
componentToHex_ : function (c) {
|
|
||||||
var hex = c.toString(16);
|
|
||||||
return hex.length == 1 ? "0" + hex : hex;
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Alpha compositing using porter duff algorithm :
|
* Alpha compositing using porter duff algorithm :
|
||||||
* http://en.wikipedia.org/wiki/Alpha_compositing
|
* http://en.wikipedia.org/wiki/Alpha_compositing
|
||||||
|
@ -46,12 +46,25 @@ if (!Function.prototype.bind) {
|
|||||||
|
|
||||||
var ns = $.namespace("pskl.utils");
|
var ns = $.namespace("pskl.utils");
|
||||||
|
|
||||||
ns.rgbToHex = function(r, g, b) {
|
/**
|
||||||
if (r > 255 || g > 255 || b > 255) {
|
* Convert a rgb(Number, Number, Number) color to hexadecimal representation
|
||||||
throw "Invalid color component";
|
* @param {Number} r red value, between 0 and 255
|
||||||
}
|
* @param {Number} g green value, between 0 and 255
|
||||||
|
* @param {Number} b blue value, between 0 and 255
|
||||||
|
* @return {String} hex representation of the color '#ABCDEF'
|
||||||
|
*/
|
||||||
|
ns.rgbToHex = function (r, g, b) {
|
||||||
|
return "#" + pskl.utils.componentToHex(r) + pskl.utils.componentToHex(g) + pskl.utils.componentToHex(b);
|
||||||
|
};
|
||||||
|
|
||||||
return ((r << 16) | (g << 8) | b).toString(16);
|
/**
|
||||||
|
* Convert a color component (as a Number between 0 and 255) to its string hexa representation
|
||||||
|
* @param {Number} c component value, between 0 and 255
|
||||||
|
* @return {String} eg. '0A'
|
||||||
|
*/
|
||||||
|
ns.componentToHex = function (c) {
|
||||||
|
var hex = c.toString(16);
|
||||||
|
return hex.length == 1 ? "0" + hex : hex;
|
||||||
};
|
};
|
||||||
|
|
||||||
ns.normalize = function (value, def) {
|
ns.normalize = function (value, def) {
|
||||||
|
Loading…
Reference in New Issue
Block a user