MCPcopy Index your code
hub / github.com/cifertech/DisplayKit / hexToRgb

Function hexToRgb

app.js:1946–1967  ·  view source on GitHub ↗
(hex)

Source from the content-addressed store, hash-verified

1944}
1945
1946function hexToRgb(hex) {
1947 // Remove # if present
1948 hex = hex.replace(/^#/, '');
1949
1950 // Parse the hex value
1951 let r, g, b;
1952 if (hex.length === 3) {
1953 // Short format (#RGB)
1954 r = parseInt(hex.charAt(0) + hex.charAt(0), 16);
1955 g = parseInt(hex.charAt(1) + hex.charAt(1), 16);
1956 b = parseInt(hex.charAt(2) + hex.charAt(2), 16);
1957 } else if (hex.length === 6) {
1958 // Long format (#RRGGBB)
1959 r = parseInt(hex.substr(0, 2), 16);
1960 g = parseInt(hex.substr(2, 2), 16);
1961 b = parseInt(hex.substr(4, 2), 16);
1962 } else {
1963 return null; // Invalid format
1964 }
1965
1966 return { r, g, b };
1967}
1968
1969function isLightColor(hex) {
1970 const rgb = hexToRgb(hex || "#000000");

Callers 4

isLightColorFunction · 0.85
imageDataToRgb565Function · 0.85
loadPngToRgb565Function · 0.85
renderElementsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected