[Build] Run build, remove useless colours

This commit is contained in:
2025-04-26 15:54:35 +02:00
parent 4aa4bc57b9
commit 8c4af4f817
8 changed files with 52 additions and 34 deletions

View File

@@ -11,6 +11,7 @@ const build = ( wallpaper, lockpaper, theme ) => {
console.log( '\n=> Extracting colours' );
// Extract colour palette from chosen wallpaper using Color-Thief
colorThief.getPalette( wallpaper ).then( palette => {
palette = util.removeUselessColours( palette );
// Define view options (for rendering with mustache)
if ( theme === 'test' ) {
palette = [ [ 255, 0, 0 ], [ 0, 255, 0 ], [ 0, 0, 255 ] ];

View File

@@ -57,6 +57,22 @@ const renderColourAsRGBAHex = ( colour, ambiance ) => {
return `rgba(${hexCol}${decimalToHex(ambiance)})`.toLowerCase();
}
const removeUselessColours = ( palette ) => {
const p = [];
for ( let i = 0; i < palette.length; i++ ) {
const luminance = calculateLuminance( palette[ i ] );
if ( luminance < 215 && luminance > 40 ) {
p.push( palette[ i ] );
}
}
return p;
}
const calculateLuminance = ( colour ) => {
return colour[ 0 ] + colour[ 1 ] + colour[ 2 ] / 3;
}
/*
* Replace the colours with variable names
@@ -149,5 +165,6 @@ module.exports = {
renderColourAsRGBHex,
renderColourAsRGBAHex,
themePreProcessor,
getGradientColour
getGradientColour,
removeUselessColours
}