This commit is contained in:
Louis Dalibard 2024-12-24 16:59:23 +01:00
parent 4f079e775d
commit c6ebdab026
2 changed files with 31 additions and 8 deletions

View File

@ -8,6 +8,13 @@ import System.Environment ( getArgs )
import System.Exit ( die )
import System.Random ( setStdGen, mkStdGen )
import Text.JSON ( encode )
import Text.Read (readMaybe)
-- String to float
stringToFloat :: String -> Float
stringToFloat s = case readMaybe s of
Just x -> x
Nothing -> error "Invalid float value"
-- | Load an image file.
loadImage :: String -- ^ Path to the file
@ -22,7 +29,7 @@ mainProcess (polarity,primaryScaleDark,primaryScaleLight, input, output) = do
setStdGen $ mkStdGen 0
image <- loadImage input
palette <- evolve (polarity, primaryScaleDark,primaryScaleLight,convertRGB8 image)
palette <- evolve (polarity,stringToFloat primaryScaleDark,stringToFloat primaryScaleLight,convertRGB8 image)
let outputTable = makeOutputTable $ V.map lab2rgb palette
writeFile output $ encode outputTable

View File

@ -34,7 +34,7 @@ randomFromImage image = do
color = RGB (fromIntegral r) (fromIntegral g) (fromIntegral b)
return $ rgb2lab color
instance Species (String,String,String, Image PixelRGB8) (V.Vector LAB) where
instance Species (String,Float,Float, Image PixelRGB8) (V.Vector LAB) where
generate (_,_,_, image) = V.replicateM 16 $ randomFromImage image
crossover _ a b = return $ alternatingZip a b
@ -84,6 +84,17 @@ instance Species (String,String,String, Image PixelRGB8) (V.Vector LAB) where
lightScheme
= lightnessError (V.fromList [90, 70, 55, 35, 25, 10, 5, 5]) 40
// 0.2, 0.133,0.178,0.85,0.93,0.88,1.0,1.0 for 0.1 scale
// f(x) = ax+b for multiplier (light)
// 0.889, 0.111
// 0.963, 0.037
// 0.913, 0.087
// 0.167, 0.833
// 0.078, 0.922
// 0.133, 0.087
// 0.0, 1.0
// 0.0, 1.0
{-
For dark themes, the background is dark and the text is bright.
The accent colours are slightly brighter.
@ -91,8 +102,13 @@ instance Species (String,String,String, Image PixelRGB8) (V.Vector LAB) where
darkScheme
= lightnessError (V.fromList [10, 30, 45, 65, 75, 90, 95, 95]) 60
darkerScheme
= lightnessError (V.fromList [5, 10, 15, 60, 70, 80, 95, 95]) 60
evenDarkerScheme
= lightnessError (V.fromList [2, 4, 8, 55, 70, 80, 95, 95]) 60
// 0.2, 0.133,0.178,0.85,0.93,0.88,1.0,1.0 for 0.1 scale
// f(x) = ax+b for multiplier (dark)
// 0.889, 0.111
// 0.963, 0.037
// 0.913, 0.087
// 0.167, 0.833
// 0.078, 0.922
// 0.133, 0.087
// 0.0, 1.0
// 0.0, 1.0