@sardine/colour 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/CIEDE2000.js.map +1 -1
- package/dist/RGBdistance.js.map +1 -1
- package/dist/converters.js.map +1 -1
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/dist/umd/index.js +1 -0
- package/dist/umd/index.js.map +1 -0
- package/dist/umd/index.umd.js +3 -0
- package/dist/umd/index.umd.js.map +1 -0
- package/dist/util/index.js.map +1 -1
- package/package.json +6 -3
- package/dist/CIEDE2000.d.ts +0 -12
- package/dist/RGBdistance.d.ts +0 -2
- package/dist/converters.d.ts +0 -57
- package/dist/index.d.ts +0 -3
- package/dist/util/index.d.ts +0 -47
package/dist/CIEDE2000.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/CIEDE2000.ts"],"sourcesContent":["import { bigSquare, deltaHue_d, hue_d, meanHue_d, toRadians } from \"./util/index.js\";\nimport type { LabColour } from \"./
|
|
1
|
+
{"version":3,"sources":["../src/CIEDE2000.ts"],"sourcesContent":["import { bigSquare, deltaHue_d, hue_d, meanHue_d, toRadians } from \"./util/index.js\";\nimport type { LabColour } from \"./types\";\n\n/**\n * Mesures the colour difference between two colours in the Lab space\n *\n * Math taken from:\n *\n * https://en.wikipedia.org/wiki/Color_difference#CIEDE2000\n * http://www2.ece.rochester.edu/~gsharma/ciede2000/ciede2000noteCRNA.pdf\n * @param colour1 First colour to be compared\n * @param colour2 First colour to be compared\n */\nexport function ciede2000(colour1: LabColour, colour2: LabColour): number {\n /**\n * Glossary\n * L - Lightness as defined by L*a*b*\n * a - Describes the green–red opponent colors as defined by L*a*b*\n * b - Describes the blue–yellow opponent colors as defined by L*a*b*\n * C - Chroma as defined by CIE94\n *\n * Math notation\n * _d - Derivative\n * Δ - Difference between values\n * ̅ - Mean value\n */\n\n /** Lightness for colour 1 */\n const L1 = colour1.L;\n\n /** green–red colour opponent for colour 1 */\n const a1 = colour1.a;\n\n /** blue–yellow colour opponent for colour 1 */\n const b1 = colour1.b;\n\n /** Lightness for colour 2 */\n const L2 = colour2.L;\n\n /** green–red colour opponent for colour 1 */\n const a2 = colour2.a;\n\n /** blue–yellow colour opponent for colour 1 */\n const b2 = colour2.b;\n\n /** Weighting factor for Luminance */\n const kL = 1;\n\n /** Weighting factor for Chroma */\n const kC = 1;\n\n /** Weighting factor for Hue */\n const kH = 1;\n\n /** Chroma for colour 1 */\n const C1 = Math.sqrt(Math.pow(a1, 2) + Math.pow(b1, 2));\n\n /** Chroma for colour 2 */\n const C2 = Math.sqrt(Math.pow(a2, 2) + Math.pow(b2, 2));\n\n /** Derivative of the Lightness difference */\n const ΔL_d = L2 - L1;\n\n /** Chroma mean value */\n const C̅ = (C1 + C2) / 2;\n\n const G = 0.5 * (1 - bigSquare(C̅));\n\n /** Derivative of a1 */\n const a1_d = a1 * (1 + G);\n\n /** Derivative of a2 */\n const a2_d = a2 * (1 + G);\n\n /** Derivative of C1 */\n const C1_d = Math.sqrt(Math.pow(a1_d, 2) + Math.pow(b1, 2));\n\n /** Derivative of C2 */\n const C2_d = Math.sqrt(Math.pow(a2_d, 2) + Math.pow(b2, 2));\n\n /** Derivative of Chroma mean */\n const C̅_d = (C1_d + C2_d) / 2;\n\n /** Derivative of the mean difference of Chroma */\n const ΔC̅_d = C2_d - C1_d;\n\n /** Derivative of colour 1 Hue */\n const h1_d = hue_d(b1, a1_d);\n\n /** Derivative of colour 2 Hue */\n const h2_d = hue_d(b2, a2_d);\n\n /** Hue difference */\n const Δh_d = deltaHue_d({ C1, C2, h1_d, h2_d });\n\n const ΔH_d = 2 * Math.sqrt(C1_d * C2_d) * Math.sin(toRadians(Δh_d) / 2);\n\n /** Derivative of mean hue */\n const H̅_d = meanHue_d({ C1, C2, h1_d, h2_d });\n\n /** Lightness Mean value*/\n const L̅ = (L1 + L2) / 2;\n\n /** Compensation for neutral colors (the primed values in the L*C*h differences) */\n const T =\n 1 -\n 0.17 * Math.cos(toRadians(H̅_d - 30)) +\n 0.24 * Math.cos(toRadians(2 * H̅_d)) +\n 0.32 * Math.cos(toRadians(3 * H̅_d + 6)) -\n 0.2 * Math.cos(toRadians(4 * H̅_d - 63));\n\n /** Compensation for lightness */\n const SL =\n 1 + (0.015 * Math.pow(L̅ - 50, 2)) / Math.sqrt(20 + Math.pow(L̅ - 50, 2));\n\n /** Compensation for chroma */\n const SC = 0.045 * C̅_d + 1;\n\n /** Compensation for hue */\n const SH = 1 + 0.015 * C̅_d * T;\n\n const rotation = 30 * Math.exp(-Math.pow((H̅_d - 275) / 25, 2));\n\n /** A hue rotation term, to deal with the problematic blue region (hue angles in the neighborhood of 275°) */\n const RT = -2 * bigSquare(C̅_d) * Math.sin(toRadians(rotation * 2));\n\n /** Colour difference */\n const ΔE = Math.sqrt(\n Math.pow(ΔL_d / (kL * SL), 2) +\n Math.pow(ΔC̅_d / (kC * SC), 2) +\n Math.pow(ΔH_d / (kH * SH), 2) +\n RT * (ΔC̅_d / (kC * SC)) * (ΔH_d / (kH * SH))\n );\n\n return ΔE;\n}\n"],"names":["bigSquare","deltaHue_d","hue_d","meanHue_d","toRadians","ciede2000","colour1","colour2","L1","L","a1","a","b1","b","L2","a2","b2","kL","kC","kH","C1","Math","sqrt","pow","C2","ΔL_d","C̅","G","a1_d","a2_d","C1_d","C2_d","C̅_d","ΔC̅_d","h1_d","h2_d","Δh_d","ΔH_d","sin","H̅_d","L̅","T","cos","SL","SC","SH","rotation","exp","RT","ΔE"],"mappings":"AAAA,MAAM,GAAGA,SAAS,EAAEC,UAAU,EAAEC,KAAK,EAAEC,SAAS,EAAEC,SAAS,QAAQ,CAAiB;AAGpF,EASG,AATH;;;;;;;;;CASG,AATH,EASG,CACH,MAAM,UAAUC,SAAS,CAACC,OAAkB,EAAEC,OAAkB,EAAU,CAAC;IACzE,EAWG,AAXH;;;;;;;;;;;GAWG,AAXH,EAWG,CAEH,EAA6B,AAA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,CAACiB,GAAE,GAAI,EAAE,EAAE,CAAC;IAEzE,EAA4B,AAA9B,0BAA8B,AAA9B,EAA8B,CAC9B,KAAK,CAACI,EAAE,GAAG,KAAK,GAAGZ,KAAI,GAAI,CAAC;IAE3B,EAA0B,AAA3B,uBAA2B,AAA3B,EAA2B,CAC3B,KAAK,CAACa,EAAE,GAAG,CAAC,GAAG,KAAK,GAAGb,KAAI,GAAIS,CAAC;IAE/B,KAAI,CAACK,QAAQ,GAAG,EAAE,GAAGzB,IAAI,CAAC0B,GAAG,EAAE1B,IAAI,CAACE,GAAG,EAAEgB,KAAI,GAAI,GAAG,IAAI,EAAE,EAAE,CAAC;IAE7D,EAA4G,AAA7G,0GAA8G,AAA9G,EAA8G,CAC7G,KAAI,CAACS,EAAE,IAAI,CAAC,GAAGhD,SAAS,CAACgC,KAAI,IAAKX,IAAI,CAACiB,GAAG,CAAClC,SAAS,CAAC0C,QAAQ,GAAG,CAAC;IAEjE,EAAuB,AAAxB,oBAAwB,AAAxB,EAAwB,CACxB,KAAK,CAACG,GAAE,GAAI5B,IAAI,CAACC,IAAI,CAClBD,IAAG,CAACE,GAAG,CAACE,KAAI,IAAKR,EAAE,GAAG0B,EAAE,GAAG,CAAC,IAC1BtB,IAAG,CAACE,GAAG,CAACU,OAAK,IAAMf,EAAE,GAAG0B,EAAE,GAAG,CAAC,IAC7BvB,IAAE,CAACE,GAAG,CAACc,KAAI,IAAKlB,EAAE,GAAG0B,EAAE,GAAG,CAAC,IAC5BG,EAAC,IAAIf,OAAK,IAAMf,EAAE,GAAG0B,EAAE,MAAMP,KAAI,IAAKlB,EAAE,GAAG0B,EAAE;IAG/C,MAAG,CAACI,GAAE;AACX,CAAC"}
|
package/dist/RGBdistance.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/RGBdistance.ts"],"sourcesContent":["import { ciede2000 } from \"./CIEDE2000.js\";\nimport { convertRGBtoLab } from \"./converters.js\";\nimport type { RGBColour } from \"./
|
|
1
|
+
{"version":3,"sources":["../src/RGBdistance.ts"],"sourcesContent":["import { ciede2000 } from \"./CIEDE2000.js\";\nimport { convertRGBtoLab } from \"./converters.js\";\nimport type { RGBColour } from \"./types\";\n\nexport const RGBdistance = (colour1: RGBColour, colour2: RGBColour): number => {\n const c1 = convertRGBtoLab(colour1);\n const c2 = convertRGBtoLab(colour2);\n\n return ciede2000(c1, c2);\n};\n"],"names":["ciede2000","convertRGBtoLab","RGBdistance","colour1","colour2","c1","c2"],"mappings":"AAAA,MAAM,GAAGA,SAAS,QAAQ,CAAgB;AAC1C,MAAM,GAAGC,eAAe,QAAQ,CAAiB;AAGjD,MAAM,CAAC,KAAK,CAACC,WAAW,IAAIC,OAAkB,EAAEC,OAAkB,GAAa,CAAC;IAC9E,KAAK,CAACC,EAAE,GAAGJ,eAAe,CAACE,OAAO;IAClC,KAAK,CAACG,EAAE,GAAGL,eAAe,CAACG,OAAO;IAElC,MAAM,CAACJ,SAAS,CAACK,EAAE,EAAEC,EAAE;AACzB,CAAC"}
|
package/dist/converters.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/converters.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../src/converters.ts"],"sourcesContent":["import type { LabColour, RGBColour, XYZColour } from \"./types\";\nimport { constrainLab, linearRGB } from \"./util/index.js\";\n\n/**\n * Converts sRGB colour space to XYZ.\n * Math comes from https://en.wikipedia.org/wiki/SRGB#The_reverse_transformation\n * @param {RGBColour} colour sRGB colour\n * @return {XYZColour} XYZ colour\n */\nexport function convertRGBtoXYZ(colour: RGBColour): XYZColour {\n const { R, G, B } = colour;\n\n const _R = linearRGB(R) * 100;\n const _G = linearRGB(G) * 100;\n const _B = linearRGB(B) * 100;\n\n // Magic numbers are pre-calculated sRGB D65 constants\n const X = _R * 0.4124 + _G * 0.3576 + _B * 0.1805;\n const Y = _R * 0.2126 + _G * 0.7152 + _B * 0.0722;\n const Z = _R * 0.0193 + _G * 0.1192 + _B * 0.9505;\n\n return { X, Y, Z };\n}\n\n/**\n * Converts XYZ colour space to Lab\n * Math comes from https://en.wikipedia.org/wiki/CIELAB_color_space#From_CIEXYZ_to_CIELAB[11]\n * @param colour XYZ colour\n * @return {LabColour} Lab colour\n */\nexport function convertXYZtoLab(colour: XYZColour): LabColour {\n const { X, Y, Z } = colour;\n\n // Magic numbers are normalised for relative luminance from the D65 standard\n const _X = X / 95.047;\n const _Y = Y / 100;\n const _Z = Z / 108.883;\n\n const fX = constrainLab(_X);\n const fY = constrainLab(_Y);\n const fZ = constrainLab(_Z);\n\n const L = 116 * fY - 16;\n const a = 500 * (fX - fY);\n const b = 200 * (fY - fZ);\n\n return { L, a, b };\n}\n\n/**\n * Indirectly converts RGB to Lab.\n * First converts RGB to XYZ,\n * Then converts XYZ to Lab\n * @param {RGBColour} colour sRGB colour\n * @return {LabColour} Lab colour\n */\nexport function convertRGBtoLab(colour: RGBColour): LabColour {\n const XYZColour = convertRGBtoXYZ(colour);\n return convertXYZtoLab(XYZColour);\n}\n"],"names":["constrainLab","linearRGB","convertRGBtoXYZ","colour","R","G","B","_R","_G","_B","X","Y","Z","convertXYZtoLab","_X","_Y","_Z","fX","fY","fZ","L","a","b","convertRGBtoLab","XYZColour"],"mappings":"AACA,MAAM,GAAGA,YAAY,EAAEC,SAAS,QAAQ,CAAiB;AAEzD,EAKG,AALH;;;;;CAKG,AALH,EAKG,CACH,MAAM,UAAUC,eAAe,CAACC,MAAiB,EAAa,CAAC;IAC7D,KAAK,CAAC,CAAC,CAACC,CAAC,GAAEC,CAAC,GAAEC,CAAC,EAAC,CAAC,GAAGH,MAAM;IAE1B,KAAK,CAACI,EAAE,GAAGN,SAAS,CAACG,CAAC,IAAI,GAAG;IAC7B,KAAK,CAACI,EAAE,GAAGP,SAAS,CAACI,CAAC,IAAI,GAAG;IAC7B,KAAK,CAACI,EAAE,GAAGR,SAAS,CAACK,CAAC,IAAI,GAAG;IAE7B,EAAsD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MG,CACH,MAAM,UAAUC,eAAe,CAACpB,MAAiB,EAAa,CAAC;IAC7D,KAAK,CAACqB,SAAS,GAAGtB,eAAe,CAACC,MAAM;IACxC,MAAM,CAACU,eAAe,CAACW,SAAS;AAClC,CAAC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["/**\n * The RGB colour model represents a broad array of colours by describing the Red, Green and Blue channels.\n */\n export interface RGBColour {\n /** A number between 0 and 255 to describe the Red colour channel */\n R: number;\n /** A number between 0 and 255 to describe the Green colour channel */\n G: number;\n /** A number between 0 and 255 to describe the Blue colour channel */\n B: number;\n /** A optional number between 0 and 1 to describe the Alpha colour channel */\n A?: number;\n }\n \n /**\n * L*a*b* space is three-dimensional and covers the entire range of human colour perception\n */\n export interface LabColour {\n /** A number between 0 and 100 to describe the colour's lightness. (0 - black, 100 - white) */\n L: number;\n /** A number between -128 and 127 to describe the green–red opponent colors, with negative values toward green and positive values toward red */\n a: number;\n /** A number between -128 and 127 to describe blue–yellow opponents, with negative numbers toward blue and positive toward yellow */\n b: number;\n }\n \n /**\n * The CIE XYZ colour space is a device independent colour representation\n */\n export interface XYZColour {\n /** X is a mix of response curves chosen to be nonnegative */\n X: number;\n /** Y as luminance */\n Y: number;\n /** Z is quasi-equal to blue */\n Z: number;\n }\n\n export interface HueHelper {\n /** Chroma for colour 1 */\n C1: number;\n /** Chroma for colour 2 */\n C2: number;\n /** Derivative of colour 1 Hue */\n h1_d: number;\n /** Derivative of colour 2 Hue */\n h2_d: number;\n }"],"names":[],"mappings":"AAAA,EAEG,AAFH;;CAEG,AAFH,EAEG,CACF,MAAM"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function hue_d(a,b){if(0===a&&0===b)return 0;const c=Math.atan2(a,b)*(180/Math.PI);return c>=0?c:c+360}function deltaHue_d({C1:a,C2:b,h1_d:c,h2_d:d}){return a*b==0?0:180>=Math.abs(d-c)?d-c:d-c>180?d-c-360:d-c< -180?d-c+360:0}function meanHue_d({C1:a,C2:b,h1_d:c,h2_d:d}){return a*b==0?d+c:180>=Math.abs(c-d)?(d+c)/2:Math.abs(c-d)>180&&c+d<360?(d+c+360)/2:Math.abs(c-d)>180&&c+d>=360?(d+c-360)/2:0}const toRadians=a=>a*(Math.PI/180);const bigSquare=a=>Math.sqrt(Math.pow(a,7)/(Math.pow(a,7)+6103515625));function linearRGB(a){const b=a/255;return b>.04045?Math.pow((b+.055)/1.055,2.4):b/12.92}function constrainLab(a){const b=6/29;return a>Math.pow(b,3)?Math.cbrt(a):a/(3*Math.pow(b,2))+4/29}function ciede2000(f,g){const h=f.L,i=f.a,j=f.b,k=g.L,l=g.a,m=g.b,n=Math.sqrt(Math.pow(i,2)+Math.pow(j,2)),o=Math.sqrt(Math.pow(l,2)+Math.pow(m,2)),p=.5*(1-bigSquare((n+o)/2)),q=i*(1+p),r=l*(1+p),s=Math.sqrt(Math.pow(q,2)+Math.pow(j,2)),t=Math.sqrt(Math.pow(r,2)+Math.pow(m,2)),u=(s+t)/2,v=t-s,w=hue_d(j,q),x=hue_d(m,r),y=deltaHue_d({C1:n,C2:o,h1_d:w,h2_d:x}),z=2*Math.sqrt(s*t)*Math.sin(toRadians(y)/2),A=meanHue_d({C1:n,C2:o,h1_d:w,h2_d:x}),B=(h+k)/2,C=1-.17*Math.cos(toRadians(A-30))+.24*Math.cos(toRadians(2*A))+.32*Math.cos(toRadians(3*A+6))-.2*Math.cos(toRadians(4*A-63)),D=.045*u+1,E=1+.015*u*C,F=-2*bigSquare(u)*Math.sin(toRadians(2*(30*Math.exp(-Math.pow((A-275)/25,2)))));return Math.sqrt(Math.pow((k-h)/(1*(1+.015*Math.pow(B-50,2)/Math.sqrt(20+Math.pow(B-50,2)))),2)+Math.pow(v/(1*D),2)+Math.pow(z/(1*E),2)+F*(v/(1*D))*(z/(1*E)))}function convertRGBtoXYZ(a){const{R:c,G:d,B:e}=a,f=100*linearRGB(c),g=100*linearRGB(d),h=100*linearRGB(e);return{X:.4124*f+.3576*g+.1805*h,Y:.2126*f+.7152*g+.0722*h,Z:.0193*f+.1192*g+.9505*h}}function convertXYZtoLab(b){const{X:c,Y:d,Z:e}=b,f=constrainLab(c/95.047),g=constrainLab(d/100),h=constrainLab(e/108.883);return{L:116*g-16,a:500*(f-g),b:200*(g-h)}}function convertRGBtoLab(a){const b=convertRGBtoXYZ(a);return convertXYZtoLab(b)}const RGBdistance=(c,d)=>{const e=convertRGBtoLab(c),f=convertRGBtoLab(d);return ciede2000(e,f)};export{ciede2000 as ciede2000};export{convertRGBtoXYZ as convertRGBtoXYZ,convertRGBtoLab as convertRGBtoLab,convertXYZtoLab as convertXYZtoLab};export{RGBdistance as RGBdistance}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/hugo/colour/src/util/index.ts","/home/hugo/colour/src/CIEDE2000.ts","/home/hugo/colour/src/converters.ts","/home/hugo/colour/src/RGBdistance.ts","/home/hugo/colour/src/index.ts"],"sourcesContent":["import type { HueHelper } from \"../types\";\n\n/**\n * Calculates the Hue derivative\n * @param x A numeric expression representing the cartesian x-coordinate.\n * @param y A numeric expression representing the cartesian y-coordinate.\n */\nexport function hue_d(x: number, y: number): number {\n // early exit if both values are 0\n if (x === 0 && y === 0) {\n return 0;\n }\n /** The angle in degrees */\n const angle = Math.atan2(x, y) * (180 / Math.PI);\n if (angle >= 0) {\n return angle;\n }\n return angle + 360;\n}\n\n/**\n * Calculates the difference between two Hue derivatives\n * @param HueHelper param\n */\nexport function deltaHue_d({ C1, C2, h1_d, h2_d }: HueHelper): number {\n if (C1 * C2 === 0) {\n return 0;\n }\n if (Math.abs(h2_d - h1_d) <= 180) {\n return h2_d - h1_d;\n }\n if (h2_d - h1_d > 180) {\n return h2_d - h1_d - 360;\n }\n if (h2_d - h1_d < -180) {\n return h2_d - h1_d + 360;\n }\n // it should never reach this point\n return 0;\n}\n\n/**\n * Calculates the mean between two Hue derivatives\n * @param HueHelper param\n */\nexport function meanHue_d({ C1, C2, h1_d, h2_d }: HueHelper): number {\n if (C1 * C2 === 0) {\n return h2_d + h1_d;\n }\n if (Math.abs(h1_d - h2_d) <= 180) {\n return (h2_d + h1_d) / 2;\n }\n if (Math.abs(h1_d - h2_d) > 180 && h1_d + h2_d < 360) {\n return (h2_d + h1_d + 360) / 2;\n }\n if (Math.abs(h1_d - h2_d) > 180 && h1_d + h2_d >= 360) {\n return (h2_d + h1_d - 360) / 2;\n }\n // it should never reach this point\n return 0;\n}\n\n/**\n * Converts a number in degrees to radians\n * @param n Number in degrees to be converted\n */\nexport const toRadians = (n: number): number => n * (Math.PI / 180);\n\n/**\n * Calculates a recurring square root\n * @param n Input number\n */\nexport const bigSquare = (n: number): number =>\n Math.sqrt(Math.pow(n, 7) / (Math.pow(n, 7) + Math.pow(25, 7)));\n\n/**\n * Normalise black and white colorimetry as specified in IEC 61966-2-1\n * It takes a RGB channel in the range [0 - 255] and returns a value between 0 and 1\n * @param n number to be normalised\n */\nexport function linearRGB(rgbValue: number) {\n const rgbRatio = rgbValue / 255;\n let linearValue: number;\n\n if (rgbRatio > 0.04045) {\n linearValue = Math.pow((rgbRatio + 0.055) / 1.055, 2.4);\n } else {\n linearValue = rgbRatio / 12.92;\n }\n\n return linearValue;\n}\n\n/**\n * The division of the f function domain into two parts was done to prevent an infinite slope at n = 0\n * @param n Number to be constrained\n */\nexport function constrainLab(n: number): number {\n const delta = 6 / 29;\n const deltaCube = Math.pow(delta, 3);\n let t: number;\n\n if (n > deltaCube) {\n t = Math.cbrt(n);\n } else {\n t = n / (3 * Math.pow(delta, 2)) + 4 / 29;\n }\n\n return t;\n}\n","import { bigSquare, deltaHue_d, hue_d, meanHue_d, toRadians } from \"./util/index.js\";\nimport type { LabColour } from \"./types\";\n\n/**\n * Mesures the colour difference between two colours in the Lab space\n *\n * Math taken from:\n *\n * https://en.wikipedia.org/wiki/Color_difference#CIEDE2000\n * http://www2.ece.rochester.edu/~gsharma/ciede2000/ciede2000noteCRNA.pdf\n * @param colour1 First colour to be compared\n * @param colour2 First colour to be compared\n */\nexport function ciede2000(colour1: LabColour, colour2: LabColour): number {\n /**\n * Glossary\n * L - Lightness as defined by L*a*b*\n * a - Describes the green–red opponent colors as defined by L*a*b*\n * b - Describes the blue–yellow opponent colors as defined by L*a*b*\n * C - Chroma as defined by CIE94\n *\n * Math notation\n * _d - Derivative\n * Δ - Difference between values\n * ̅ - Mean value\n */\n\n /** Lightness for colour 1 */\n const L1 = colour1.L;\n\n /** green–red colour opponent for colour 1 */\n const a1 = colour1.a;\n\n /** blue–yellow colour opponent for colour 1 */\n const b1 = colour1.b;\n\n /** Lightness for colour 2 */\n const L2 = colour2.L;\n\n /** green–red colour opponent for colour 1 */\n const a2 = colour2.a;\n\n /** blue–yellow colour opponent for colour 1 */\n const b2 = colour2.b;\n\n /** Weighting factor for Luminance */\n const kL = 1;\n\n /** Weighting factor for Chroma */\n const kC = 1;\n\n /** Weighting factor for Hue */\n const kH = 1;\n\n /** Chroma for colour 1 */\n const C1 = Math.sqrt(Math.pow(a1, 2) + Math.pow(b1, 2));\n\n /** Chroma for colour 2 */\n const C2 = Math.sqrt(Math.pow(a2, 2) + Math.pow(b2, 2));\n\n /** Derivative of the Lightness difference */\n const ΔL_d = L2 - L1;\n\n /** Chroma mean value */\n const C̅ = (C1 + C2) / 2;\n\n const G = 0.5 * (1 - bigSquare(C̅));\n\n /** Derivative of a1 */\n const a1_d = a1 * (1 + G);\n\n /** Derivative of a2 */\n const a2_d = a2 * (1 + G);\n\n /** Derivative of C1 */\n const C1_d = Math.sqrt(Math.pow(a1_d, 2) + Math.pow(b1, 2));\n\n /** Derivative of C2 */\n const C2_d = Math.sqrt(Math.pow(a2_d, 2) + Math.pow(b2, 2));\n\n /** Derivative of Chroma mean */\n const C̅_d = (C1_d + C2_d) / 2;\n\n /** Derivative of the mean difference of Chroma */\n const ΔC̅_d = C2_d - C1_d;\n\n /** Derivative of colour 1 Hue */\n const h1_d = hue_d(b1, a1_d);\n\n /** Derivative of colour 2 Hue */\n const h2_d = hue_d(b2, a2_d);\n\n /** Hue difference */\n const Δh_d = deltaHue_d({ C1, C2, h1_d, h2_d });\n\n const ΔH_d = 2 * Math.sqrt(C1_d * C2_d) * Math.sin(toRadians(Δh_d) / 2);\n\n /** Derivative of mean hue */\n const H̅_d = meanHue_d({ C1, C2, h1_d, h2_d });\n\n /** Lightness Mean value*/\n const L̅ = (L1 + L2) / 2;\n\n /** Compensation for neutral colors (the primed values in the L*C*h differences) */\n const T =\n 1 -\n 0.17 * Math.cos(toRadians(H̅_d - 30)) +\n 0.24 * Math.cos(toRadians(2 * H̅_d)) +\n 0.32 * Math.cos(toRadians(3 * H̅_d + 6)) -\n 0.2 * Math.cos(toRadians(4 * H̅_d - 63));\n\n /** Compensation for lightness */\n const SL =\n 1 + (0.015 * Math.pow(L̅ - 50, 2)) / Math.sqrt(20 + Math.pow(L̅ - 50, 2));\n\n /** Compensation for chroma */\n const SC = 0.045 * C̅_d + 1;\n\n /** Compensation for hue */\n const SH = 1 + 0.015 * C̅_d * T;\n\n const rotation = 30 * Math.exp(-Math.pow((H̅_d - 275) / 25, 2));\n\n /** A hue rotation term, to deal with the problematic blue region (hue angles in the neighborhood of 275°) */\n const RT = -2 * bigSquare(C̅_d) * Math.sin(toRadians(rotation * 2));\n\n /** Colour difference */\n const ΔE = Math.sqrt(\n Math.pow(ΔL_d / (kL * SL), 2) +\n Math.pow(ΔC̅_d / (kC * SC), 2) +\n Math.pow(ΔH_d / (kH * SH), 2) +\n RT * (ΔC̅_d / (kC * SC)) * (ΔH_d / (kH * SH))\n );\n\n return ΔE;\n}\n","import type { LabColour, RGBColour, XYZColour } from \"./types\";\nimport { constrainLab, linearRGB } from \"./util/index.js\";\n\n/**\n * Converts sRGB colour space to XYZ.\n * Math comes from https://en.wikipedia.org/wiki/SRGB#The_reverse_transformation\n * @param {RGBColour} colour sRGB colour\n * @return {XYZColour} XYZ colour\n */\nexport function convertRGBtoXYZ(colour: RGBColour): XYZColour {\n const { R, G, B } = colour;\n\n const _R = linearRGB(R) * 100;\n const _G = linearRGB(G) * 100;\n const _B = linearRGB(B) * 100;\n\n // Magic numbers are pre-calculated sRGB D65 constants\n const X = _R * 0.4124 + _G * 0.3576 + _B * 0.1805;\n const Y = _R * 0.2126 + _G * 0.7152 + _B * 0.0722;\n const Z = _R * 0.0193 + _G * 0.1192 + _B * 0.9505;\n\n return { X, Y, Z };\n}\n\n/**\n * Converts XYZ colour space to Lab\n * Math comes from https://en.wikipedia.org/wiki/CIELAB_color_space#From_CIEXYZ_to_CIELAB[11]\n * @param colour XYZ colour\n * @return {LabColour} Lab colour\n */\nexport function convertXYZtoLab(colour: XYZColour): LabColour {\n const { X, Y, Z } = colour;\n\n // Magic numbers are normalised for relative luminance from the D65 standard\n const _X = X / 95.047;\n const _Y = Y / 100;\n const _Z = Z / 108.883;\n\n const fX = constrainLab(_X);\n const fY = constrainLab(_Y);\n const fZ = constrainLab(_Z);\n\n const L = 116 * fY - 16;\n const a = 500 * (fX - fY);\n const b = 200 * (fY - fZ);\n\n return { L, a, b };\n}\n\n/**\n * Indirectly converts RGB to Lab.\n * First converts RGB to XYZ,\n * Then converts XYZ to Lab\n * @param {RGBColour} colour sRGB colour\n * @return {LabColour} Lab colour\n */\nexport function convertRGBtoLab(colour: RGBColour): LabColour {\n const XYZColour = convertRGBtoXYZ(colour);\n return convertXYZtoLab(XYZColour);\n}\n","import { ciede2000 } from \"./CIEDE2000.js\";\nimport { convertRGBtoLab } from \"./converters.js\";\nimport type { RGBColour } from \"./types\";\n\nexport const RGBdistance = (colour1: RGBColour, colour2: RGBColour): number => {\n const c1 = convertRGBtoLab(colour1);\n const c2 = convertRGBtoLab(colour2);\n\n return ciede2000(c1, c2);\n};\n","export { ciede2000 } from \"./CIEDE2000.js\";\nexport {\n convertRGBtoXYZ,\n convertRGBtoLab,\n convertXYZtoLab,\n} from \"./converters.js\";\nexport { RGBdistance } from \"./RGBdistance.js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Aa,CAAC,AAC9E,KAAK,CAAC,CAAE,iBAAmB,CAAO,EAC5B,CAAE,iBAAmB,CAAO,EAElC,MAAM,WAAW,CAAE,CAAE,CAAE,CACzB,CAAC,CCTD,MAAM,cAAG,SAAS,EAClB,MAAM,oBACJ,eAAe,oBACf,eAAe,oBACf,eAAe,EAEjB,MAAM,gBAAG,WAAW"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
!function(a,b){if("function"==typeof define&&define.amd)define(["exports"],b);else if("undefined"!=typeof exports)b(exports);else{var c={exports:{}};b(c.exports),a.index=c.exports}}(this,function(a){"use strict";function b(a,b){if(0===a&&0===b)return 0;const c=Math.atan2(a,b)*(180/Math.PI);return c>=0?c:c+360}Object.defineProperty(a,"__esModule",{value:!0}),a.RGBdistance=a.convertXYZtoLab=a.convertRGBtoLab=a.convertRGBtoXYZ=a.ciede2000=void 0;const c=a=>a*(Math.PI/180),d=a=>Math.sqrt(Math.pow(a,7)/(Math.pow(a,7)+6103515625));function e(a){const b=a/255;return b>.04045?Math.pow((b+.055)/1.055,2.4):b/12.92}function f(a){const b=6/29;return a>Math.pow(b,3)?Math.cbrt(a):a/(3*Math.pow(b,2))+4/29}function g(a,e){const f=a.L,g=a.a,h=a.b,i=e.L,j=e.a,k=e.b,l=Math.sqrt(Math.pow(g,2)+Math.pow(h,2)),m=Math.sqrt(Math.pow(j,2)+Math.pow(k,2)),n=.5*(1-d((l+m)/2)),o=g*(1+n),p=j*(1+n),q=Math.sqrt(Math.pow(o,2)+Math.pow(h,2)),r=Math.sqrt(Math.pow(p,2)+Math.pow(k,2)),s=(q+r)/2,t=r-q,u=b(h,o),v=b(k,p),w=function({C1:a,C2:b,h1_d:c,h2_d:d}){return a*b==0?0:180>=Math.abs(d-c)?d-c:d-c>180?d-c-360:d-c< -180?d-c+360:0}({C1:l,C2:m,h1_d:u,h2_d:v}),x=2*Math.sqrt(q*r)*Math.sin(c(w)/2),y=function({C1:a,C2:b,h1_d:c,h2_d:d}){return a*b==0?d+c:180>=Math.abs(c-d)?(d+c)/2:Math.abs(c-d)>180&&c+d<360?(d+c+360)/2:Math.abs(c-d)>180&&c+d>=360?(d+c-360)/2:0}({C1:l,C2:m,h1_d:u,h2_d:v}),z=(f+i)/2,A=1-.17*Math.cos(c(y-30))+.24*Math.cos(c(2*y))+.32*Math.cos(c(3*y+6))-.2*Math.cos(c(4*y-63)),B=.045*s+1,C=1+.015*s*A,D=-2*d(s)*Math.sin(c(2*(30*Math.exp(-Math.pow((y-275)/25,2)))));return Math.sqrt(Math.pow((i-f)/(1*(1+.015*Math.pow(z-50,2)/Math.sqrt(20+Math.pow(z-50,2)))),2)+Math.pow(t/(1*B),2)+Math.pow(x/(1*C),2)+D*(t/(1*B))*(x/(1*C)))}function h(a){const{R:b,G:c,B:d}=a,f=100*e(b),g=100*e(c),h=100*e(d);return{X:.4124*f+.3576*g+.1805*h,Y:.2126*f+.7152*g+.0722*h,Z:.0193*f+.1192*g+.9505*h}}function i(a){const{X:b,Y:c,Z:d}=a,e=f(b/95.047),g=f(c/100),h=f(d/108.883);return{L:116*g-16,a:500*(e-g),b:200*(g-h)}}function j(a){const b=h(a);return i(b)}a.ciede2000=g,a.convertRGBtoXYZ=h,a.convertRGBtoLab=j,a.convertXYZtoLab=i,a.RGBdistance=(a,b)=>{const c=j(a),d=j(b);return g(c,d)}})
|
|
2
|
+
|
|
3
|
+
//# sourceMappingURL=index.umd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["index.js"],"names":[],"mappings":"6NAAS,CAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,C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2_d:d}){return a*b==0?0:180>=Math.abs(d-c)?d-c:d-c>180?d-c-360:d-c< -180?d-c+360:0}function meanHue_d({C1:a,C2:b,h1_d:c,h2_d:d}){return a*b==0?d+c:180>=Math.abs(c-d)?(d+c)/2:Math.abs(c-d)>180&&c+d<360?(d+c+360)/2:Math.abs(c-d)>180&&c+d>=360?(d+c-360)/2:0}const toRadians=a=>a*(Math.PI/180);const bigSquare=a=>Math.sqrt(Math.pow(a,7)/(Math.pow(a,7)+6103515625));function linearRGB(a){const b=a/255;return b>.04045?Math.pow((b+.055)/1.055,2.4):b/12.92}function constrainLab(a){const b=6/29;return a>Math.pow(b,3)?Math.cbrt(a):a/(3*Math.pow(b,2))+4/29}function ciede2000(f,g){const h=f.L,i=f.a,j=f.b,k=g.L,l=g.a,m=g.b,n=Math.sqrt(Math.pow(i,2)+Math.pow(j,2)),o=Math.sqrt(Math.pow(l,2)+Math.pow(m,2)),p=.5*(1-bigSquare((n+o)/2)),q=i*(1+p),r=l*(1+p),s=Math.sqrt(Math.pow(q,2)+Math.pow(j,2)),t=Math.sqrt(Math.pow(r,2)+Math.pow(m,2)),u=(s+t)/2,v=t-s,w=hue_d(j,q),x=hue_d(m,r),y=deltaHue_d({C1:n,C2:o,h1_d:w,h2_d:x}),z=2*Math.sqrt(s*t)*Math.sin(toRadians(y)/2),A=meanHue_d({C1:n,C2:o,h1_d:w,h2_d:x}),B=(h+k)/2,C=1-.17*Math.cos(toRadians(A-30))+.24*Math.cos(toRadians(2*A))+.32*Math.cos(toRadians(3*A+6))-.2*Math.cos(toRadians(4*A-63)),D=.045*u+1,E=1+.015*u*C,F=-2*bigSquare(u)*Math.sin(toRadians(2*(30*Math.exp(-Math.pow((A-275)/25,2)))));return Math.sqrt(Math.pow((k-h)/(1*(1+.015*Math.pow(B-50,2)/Math.sqrt(20+Math.pow(B-50,2)))),2)+Math.pow(v/(1*D),2)+Math.pow(z/(1*E),2)+F*(v/(1*D))*(z/(1*E)))}function convertRGBtoXYZ(a){const{R:c,G:d,B:e}=a,f=100*linearRGB(c),g=100*linearRGB(d),h=100*linearRGB(e);return{X:.4124*f+.3576*g+.1805*h,Y:.2126*f+.7152*g+.0722*h,Z:.0193*f+.1192*g+.9505*h}}function convertXYZtoLab(b){const{X:c,Y:d,Z:e}=b,f=constrainLab(c/95.047),g=constrainLab(d/100),h=constrainLab(e/108.883);return{L:116*g-16,a:500*(f-g),b:200*(g-h)}}function convertRGBtoLab(a){const b=convertRGBtoXYZ(a);return convertXYZtoLab(b)}const RGBdistance=(c,d)=>{const e=convertRGBtoLab(c),f=convertRGBtoLab(d);return ciede2000(e,f)};export{ciede2000 as ciede2000};export{convertRGBtoXYZ as convertRGBtoXYZ,convertRGBtoLab as convertRGBtoLab,convertXYZtoLab as convertXYZtoLab};export{RGBdistance as RGBdistance}"]}
|
package/dist/util/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/util/index.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../src/util/index.ts"],"sourcesContent":["import type { HueHelper } from \"../types\";\n\n/**\n * Calculates the Hue derivative\n * @param x A numeric expression representing the cartesian x-coordinate.\n * @param y A numeric expression representing the cartesian y-coordinate.\n */\nexport function hue_d(x: number, y: number): number {\n // early exit if both values are 0\n if (x === 0 && y === 0) {\n return 0;\n }\n /** The angle in degrees */\n const angle = Math.atan2(x, y) * (180 / Math.PI);\n if (angle >= 0) {\n return angle;\n }\n return angle + 360;\n}\n\n/**\n * Calculates the difference between two Hue derivatives\n * @param HueHelper param\n */\nexport function deltaHue_d({ C1, C2, h1_d, h2_d }: HueHelper): number {\n if (C1 * C2 === 0) {\n return 0;\n }\n if (Math.abs(h2_d - h1_d) <= 180) {\n return h2_d - h1_d;\n }\n if (h2_d - h1_d > 180) {\n return h2_d - h1_d - 360;\n }\n if (h2_d - h1_d < -180) {\n return h2_d - h1_d + 360;\n }\n // it should never reach this point\n return 0;\n}\n\n/**\n * Calculates the mean between two Hue derivatives\n * @param HueHelper param\n */\nexport function meanHue_d({ C1, C2, h1_d, h2_d }: HueHelper): number {\n if (C1 * C2 === 0) {\n return h2_d + h1_d;\n }\n if (Math.abs(h1_d - h2_d) <= 180) {\n return (h2_d + h1_d) / 2;\n }\n if (Math.abs(h1_d - h2_d) > 180 && h1_d + h2_d < 360) {\n return (h2_d + h1_d + 360) / 2;\n }\n if (Math.abs(h1_d - h2_d) > 180 && h1_d + h2_d >= 360) {\n return (h2_d + h1_d - 360) / 2;\n }\n // it should never reach this point\n return 0;\n}\n\n/**\n * Converts a number in degrees to radians\n * @param n Number in degrees to be converted\n */\nexport const toRadians = (n: number): number => n * (Math.PI / 180);\n\n/**\n * Calculates a recurring square root\n * @param n Input number\n */\nexport const bigSquare = (n: number): number =>\n Math.sqrt(Math.pow(n, 7) / (Math.pow(n, 7) + Math.pow(25, 7)));\n\n/**\n * Normalise black and white colorimetry as specified in IEC 61966-2-1\n * It takes a RGB channel in the range [0 - 255] and returns a value between 0 and 1\n * @param n number to be normalised\n */\nexport function linearRGB(rgbValue: number) {\n const rgbRatio = rgbValue / 255;\n let linearValue: number;\n\n if (rgbRatio > 0.04045) {\n linearValue = Math.pow((rgbRatio + 0.055) / 1.055, 2.4);\n } else {\n linearValue = rgbRatio / 12.92;\n }\n\n return linearValue;\n}\n\n/**\n * The division of the f function domain into two parts was done to prevent an infinite slope at n = 0\n * @param n Number to be constrained\n */\nexport function constrainLab(n: number): number {\n const delta = 6 / 29;\n const deltaCube = Math.pow(delta, 3);\n let t: number;\n\n if (n > deltaCube) {\n t = Math.cbrt(n);\n } else {\n t = n / (3 * Math.pow(delta, 2)) + 4 / 29;\n }\n\n return t;\n}\n"],"names":["hue_d","x","y","angle","Math","atan2","PI","deltaHue_d","C1","C2","h1_d","h2_d","abs","meanHue_d","toRadians","n","bigSquare","sqrt","pow","linearRGB","rgbValue","rgbRatio","linearValue","constrainLab","delta","deltaCube","t","cbrt"],"mappings":"AAEA,EAIG,AAJH;;;;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AAE7D,EAIG,AAJH;;;;CAIG,AAJH,EAIG,CACH,MAAM,UAAUC,SAAS,CAACC,QAAgB,EAAE,CAAC;IAC3C,KAAK,CAACC,QAAQ,GAAGD,QAAQ,GAAG,GAAG;IAC/B,GAAG,CAACE,WAAW;IAEf,EAAE,EAAED,QAAQ,GAAG,OAAO,EAAE,CAAC;QACvBC,WAAW,GAAGlB,IAAI,CAACc,GAAG,EAAEG,QAAQ,GAAG,KAAK,IAAI,KAAK,EAAE,GAAG;IACxD,CAAC,MAAM,CAAC;QACNC,WAAW,GAAGD,QAAQ,GAAG,KAAK;IAChC,CAAC;IAED,MAAM,CAACC,WAAW;AACpB,CAAC;AAED,EAGG,AAHH;;;CAGG,AAHH,EAGG,CACH,MAAM,UAAUC,YAAY,CAACR,CAAS,EAAU,CAAC;IAC/C,KAAK,CAACS,KAAK,GAAG,CAAC,GAAG,EAAE;IACpB,KAAK,CAACC,SAAS,GAAGrB,IAAI,CAACc,GAAG,CAACM,KAAK,EAAE,CAAC;IACnC,GAAG,CAACE,CAAC;IAEL,EAAE,EAAEX,CAAC,GAAGU,SAAS,EAAE,CAAC;QAClBC,CAAC,GAAGtB,IAAI,CAACuB,IAAI,CAACZ,CAAC;IACjB,CAAC,MAAM,CAAC;QACNW,CAAC,GAAGX,CAAC,IAAI,CAAC,GAAGX,IAAI,CAACc,GAAG,CAACM,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE;IAC3C,CAAC;IAED,MAAM,CAACE,CAAC;AACV,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sardine/colour",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "It does things to colours",
|
|
5
5
|
"module": "./dist/index.js",
|
|
6
|
-
"type": "module",
|
|
7
6
|
"types": "./dist/index.d.ts",
|
|
7
|
+
"unpkg": "dist/umd/index.js",
|
|
8
8
|
"sideEffects": false,
|
|
9
9
|
"scripts": {
|
|
10
|
-
"build": "rm -rf ./dist &&
|
|
10
|
+
"build": "rm -rf ./dist && npm run build:spack && npm run build:esm && npm run build:umd",
|
|
11
|
+
"build:esm": "npx swc ./src -d ./dist",
|
|
12
|
+
"build:umd": "npx swc ./dist/umd/index.js --config-file .umd.swcrc -o ./dist/umd/index.umd.js",
|
|
13
|
+
"build:spack": "npx spack",
|
|
11
14
|
"test": "npm run build && c8 ava",
|
|
12
15
|
"types:emit": "npx tsc --declaration --emitDeclarationOnly",
|
|
13
16
|
"types:check": "npx tsc --noEmit",
|
package/dist/CIEDE2000.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { LabColour } from "./converters";
|
|
2
|
-
/**
|
|
3
|
-
* Mesures the colour difference between two colours in the Lab space
|
|
4
|
-
*
|
|
5
|
-
* Math taken from:
|
|
6
|
-
*
|
|
7
|
-
* https://en.wikipedia.org/wiki/Color_difference#CIEDE2000
|
|
8
|
-
* http://www2.ece.rochester.edu/~gsharma/ciede2000/ciede2000noteCRNA.pdf
|
|
9
|
-
* @param colour1 First colour to be compared
|
|
10
|
-
* @param colour2 First colour to be compared
|
|
11
|
-
*/
|
|
12
|
-
export declare function ciede2000(colour1: LabColour, colour2: LabColour): number;
|
package/dist/RGBdistance.d.ts
DELETED
package/dist/converters.d.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The RGB colour model represents a broad array of colours by describing the Red, Green and Blue channels.
|
|
3
|
-
*/
|
|
4
|
-
export interface RGBColour {
|
|
5
|
-
/** A number between 0 and 255 to describe the Red colour channel */
|
|
6
|
-
R: number;
|
|
7
|
-
/** A number between 0 and 255 to describe the Green colour channel */
|
|
8
|
-
G: number;
|
|
9
|
-
/** A number between 0 and 255 to describe the Blue colour channel */
|
|
10
|
-
B: number;
|
|
11
|
-
/** A optional number between 0 and 1 to describe the Alpha colour channel */
|
|
12
|
-
A?: number;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* L*a*b* space is three-dimensional and covers the entire range of human colour perception
|
|
16
|
-
*/
|
|
17
|
-
export interface LabColour {
|
|
18
|
-
/** A number between 0 and 100 to describe the colour's lightness. (0 - black, 100 - white) */
|
|
19
|
-
L: number;
|
|
20
|
-
/** A number between -128 and 127 to describe the green–red opponent colors, with negative values toward green and positive values toward red */
|
|
21
|
-
a: number;
|
|
22
|
-
/** A number between -128 and 127 to describe blue–yellow opponents, with negative numbers toward blue and positive toward yellow */
|
|
23
|
-
b: number;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* The CIE XYZ colour space is a device independent colour representation
|
|
27
|
-
*/
|
|
28
|
-
export interface XYZColour {
|
|
29
|
-
/** X is a mix of response curves chosen to be nonnegative */
|
|
30
|
-
X: number;
|
|
31
|
-
/** Y as luminance */
|
|
32
|
-
Y: number;
|
|
33
|
-
/** Z is quasi-equal to blue */
|
|
34
|
-
Z: number;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Converts sRGB colour space to XYZ.
|
|
38
|
-
* Math comes from https://en.wikipedia.org/wiki/SRGB#The_reverse_transformation
|
|
39
|
-
* @param {RGBColour} colour sRGB colour
|
|
40
|
-
* @return {XYZColour} XYZ colour
|
|
41
|
-
*/
|
|
42
|
-
export declare function convertRGBtoXYZ(colour: RGBColour): XYZColour;
|
|
43
|
-
/**
|
|
44
|
-
* Converts XYZ colour space to Lab
|
|
45
|
-
* Math comes from https://en.wikipedia.org/wiki/CIELAB_color_space#From_CIEXYZ_to_CIELAB[11]
|
|
46
|
-
* @param colour XYZ colour
|
|
47
|
-
* @return {LabColour} Lab colour
|
|
48
|
-
*/
|
|
49
|
-
export declare function convertXYZtoLab(colour: XYZColour): LabColour;
|
|
50
|
-
/**
|
|
51
|
-
* Indirectly converts RGB to Lab.
|
|
52
|
-
* First converts RGB to XYZ,
|
|
53
|
-
* Then converts XYZ to Lab
|
|
54
|
-
* @param {RGBColour} colour sRGB colour
|
|
55
|
-
* @return {LabColour} Lab colour
|
|
56
|
-
*/
|
|
57
|
-
export declare function convertRGBtoLab(colour: RGBColour): LabColour;
|
package/dist/index.d.ts
DELETED
package/dist/util/index.d.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
export interface HueHelper {
|
|
2
|
-
/** Chroma for colour 1 */
|
|
3
|
-
C1: number;
|
|
4
|
-
/** Chroma for colour 2 */
|
|
5
|
-
C2: number;
|
|
6
|
-
/** Derivative of colour 1 Hue */
|
|
7
|
-
h1_d: number;
|
|
8
|
-
/** Derivative of colour 2 Hue */
|
|
9
|
-
h2_d: number;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Calculates the Hue derivative
|
|
13
|
-
* @param x A numeric expression representing the cartesian x-coordinate.
|
|
14
|
-
* @param y A numeric expression representing the cartesian y-coordinate.
|
|
15
|
-
*/
|
|
16
|
-
export declare function hue_d(x: number, y: number): number;
|
|
17
|
-
/**
|
|
18
|
-
* Calculates the difference between two Hue derivatives
|
|
19
|
-
* @param HueHelper param
|
|
20
|
-
*/
|
|
21
|
-
export declare function deltaHue_d({ C1, C2, h1_d, h2_d }: HueHelper): number;
|
|
22
|
-
/**
|
|
23
|
-
* Calculates the mean between two Hue derivatives
|
|
24
|
-
* @param HueHelper param
|
|
25
|
-
*/
|
|
26
|
-
export declare function meanHue_d({ C1, C2, h1_d, h2_d }: HueHelper): number;
|
|
27
|
-
/**
|
|
28
|
-
* Converts a number in degrees to radians
|
|
29
|
-
* @param n Number in degrees to be converted
|
|
30
|
-
*/
|
|
31
|
-
export declare const toRadians: (n: number) => number;
|
|
32
|
-
/**
|
|
33
|
-
* Calculates a recurring square root
|
|
34
|
-
* @param n Input number
|
|
35
|
-
*/
|
|
36
|
-
export declare const bigSquare: (n: number) => number;
|
|
37
|
-
/**
|
|
38
|
-
* Normalise black and white colorimetry as specified in IEC 61966-2-1
|
|
39
|
-
* It takes a RGB channel in the range [0 - 255] and returns a value between 0 and 1
|
|
40
|
-
* @param n number to be normalised
|
|
41
|
-
*/
|
|
42
|
-
export declare function linearRGB(rgbValue: number): number;
|
|
43
|
-
/**
|
|
44
|
-
* The division of the f function domain into two parts was done to prevent an infinite slope at n = 0
|
|
45
|
-
* @param n Number to be constrained
|
|
46
|
-
*/
|
|
47
|
-
export declare function constrainLab(n: number): number;
|