blob: 6cc15649f7cd6f718573f6178dd9ba9181929ece [file] [log] [blame]
Kevin Lubick217056c2018-09-20 17:39:31 -04001
2// Adds any extra JS functions/helpers we want to CanvasKit.
3// Wrapped in a function to avoid leaking global variables.
4(function(CanvasKit){
5
6 function clamp(c) {
7 return Math.round(Math.max(0, Math.min(c || 0, 255)));
8 }
9
10 // Colors are just a 32 bit number with 8 bits each of a, r, g, b
11 // The API is the same as CSS's representation of color rgba(), that is
12 // r,g,b are 0-255, and a is 0.0 to 1.0.
13 CanvasKit.Color = function(r, g, b, a) {
14 return (clamp(a*255) << 24) | (clamp(r) << 16) | (clamp(g) << 8) | (clamp(b) << 0);
15 }
16}(Module)); // When this file is loaded in, the high level object is "Module";