Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nano-color

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nano-color - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

30

index.js

@@ -9,11 +9,17 @@ "use strict";

var c = 10000, inv = 10000,
hsv_lut = [],
rgb_lut = [];
/* --- value to byte ------------------------------------------------------------------------------------ */
var v2b/* = function _v2b(v) {
return Math.pow(v, 1/hsv_gamma) * 255 + .5 | 0;
}*/;
// Math.pow(v, 1/hsv_gamma) * 255 + .5 | 0;
var v2b = function _v2b(v) {
return hsv_lut[(v*c+.5)>>0];
};
/* --- byte to value ------------------------------------------------------------------------------------ */
var b2v/* = function _b2v(v) {
return Math.pow(v/255, hsv_gamma);
}*/;
// Math.pow(v/255, hsv_gamma);
var b2v = function _b2v(v) {
return rgb_lut[v/255*inv+.5|0];
};

@@ -28,6 +34,2 @@ /* --------------------------------------------------------------------------------------- */

var c = 30000, inv = 30000,
hsv_lut = [],
rgb_lut = [];
for (var i = 0; i <= c; ++i)

@@ -38,10 +40,2 @@ hsv_lut[i] = Math.pow(i/c, gamma) * 255 + .5 | 0;

rgb_lut[i] = Math.pow(i/inv, g);
v2b = function (v) {
return hsv_lut[(v*c+.5)>>0];
}
b2v = function (v) {
return rgb_lut[v/255*inv+.5|0];
}
};

@@ -48,0 +42,0 @@

2

package.json
{
"name": "nano-color",
"version": "1.0.1",
"version": "1.0.2",
"description": "",

@@ -5,0 +5,0 @@ "keywords" : [ "HSV", "RGB", "RGBA", "hsv-filter", "coloring-filter", "gradient" ],

@@ -13,3 +13,122 @@ # nano-color

## Functions
### Common parameter names
* R,G,B,A -- integer channel value (0..255);
* h -- hue value (0..359);
* s,v,a -- saturation, volume, alpha value (0..1);
* g -- gamma value;
* RGB -- [ R, G, B ];
* RGBA -- [ R, G, B, A ];
* IRGBA -- 0xRRGGBBAA;
* IRGB -- 0xRRGGBB;
* data -- array of bytes;
* addr -- offset in an array of bytes.
### setGamma(g)
set Gamma correction value
### rgb2hsv(R,G,B)
Converts RGB to HSV. Returns array [ h, s, v ].
### hsv2rgb(h,s,v)
Returns [ R, G, B ].
### hsva2rgba(h,s,v,a)
Returns [ R, G, B, A ].
### rgba2hsva(R,G,B,A)
Returns [ h, s, v, a ].
### rgb2hex(RGB)
Return CSS hex color string -- '#RRGGBB'.
### rgba2hex(RGBA)
Return SVN hex color string -- '#RRGGBBAA'.
### hex2rgb(h)
Returns [ R, G, B ]. Eats '#RGB', '#RGBA', '#RRGGBB' and '#RRGGBBAA' formats.
### hex2rgba(hex)
Returns [ R, G, B, A ]. Eats '#RGB', '#RGBA', '#RRGGBB' and '#RRGGBBAA' formats.
### rgb2array(IRGB)
Returns [ R, G, B ].
### rgba2array(IRGBA)
Returns [ R, G, B, A ].
### hsva2irgba(h,s,v,a)
Returns 0xRRGGBBAA.
### put_rgb(data, addr, RGBA)
Put or mix in RGBA to the RGB bitmap array (data).
### put_rgba(data, addr, RGBA)
Put or mix in RGBA to the RGBA bitmap array (data).
### hsv_filter(data, addr, h, s, v)
Applyes HSV filter to the bitmap pixel.
### colorify_filter(data, addr, h, s, v)
Applyes Colorify filter to the bitmap pixel.
There are special case for v < 0. A result volume will be calculated by the formula ```(.21*r + .72*g + .07*b) * -val```.
### gradient(first_pos, last_pos, stops, fn)
* {stops} -- Object with color stops like:
```
{ 0: '#000', 4000: '#1234', 6000: 0x33445566, 10000: [ 255, 255, 255, 255 ] }
```
where, keys of object should be numeric value in bounds between 0 and 10000, that means from 0 to 1.0.
* {fn(position, RGBA)} -- callback function
Example:
```
> var c = require('nano-color');
c.gradient(0, 10, {
0: '#000',
4000: '#1234',
6000: 0x33445566,
10000: [ 255, 255, 255, 255 ]
}, function (pos, RGBA) {
console.log('%s: [ %s ]', pos, RGBA.join(', '));
});
```
will produce console output:
```
0: [ 0, 0, 0, 255 ]
1: [ 4, 9, 13, 208 ]
2: [ 9, 17, 26, 162 ]
3: [ 13, 26, 38, 115 ]
4: [ 17, 34, 51, 68 ]
4: [ 17, 34, 51, 68 ]
5: [ 34, 51, 68, 85 ]
6: [ 51, 68, 85, 102 ]
6: [ 51, 68, 85, 102 ]
7: [ 102, 115, 128, 140 ]
8: [ 153, 162, 170, 179 ]
9: [ 204, 208, 213, 217 ]
10: [ 255, 255, 255, 255 ]
```
[gitter-image]: https://badges.gitter.im/Holixus/nano-color.png

@@ -16,0 +135,0 @@ [gitter-url]: https://gitter.im/Holixus/nano-color

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc