This commit is contained in:
Louis Dalibard 2024-12-24 17:14:37 +01:00
parent 411b8bd6d8
commit c91b133c88
2 changed files with 4 additions and 4 deletions

View File

@ -11,8 +11,8 @@ import Text.JSON ( encode )
import Text.Read (readMaybe) import Text.Read (readMaybe)
-- String to float -- String to float
stringToFloat :: String -> Float stringToDouble :: String -> Double
stringToFloat s = case readMaybe s of stringToDouble s = case readMaybe s of
Just x -> x Just x -> x
Nothing -> error "Invalid float value" Nothing -> error "Invalid float value"
@ -29,7 +29,7 @@ mainProcess (polarity,primaryScaleDark,primaryScaleLight, input, output) = do
setStdGen $ mkStdGen 0 setStdGen $ mkStdGen 0
image <- loadImage input image <- loadImage input
palette <- evolve (polarity,stringToFloat primaryScaleDark,stringToFloat primaryScaleLight,convertRGB8 image) palette <- evolve (polarity,stringToDouble primaryScaleDark,stringToDouble primaryScaleLight,convertRGB8 image)
let outputTable = makeOutputTable $ V.map lab2rgb palette let outputTable = makeOutputTable $ V.map lab2rgb palette
writeFile output $ encode outputTable writeFile output $ encode outputTable

View File

@ -38,7 +38,7 @@ randomFromImage image = do
color = RGB (fromIntegral r) (fromIntegral g) (fromIntegral b) color = RGB (fromIntegral r) (fromIntegral g) (fromIntegral b)
return $ rgb2lab color return $ rgb2lab color
instance Species (String,Float,Float, Image PixelRGB8) (V.Vector LAB) where instance Species (String,Double,Double, Image PixelRGB8) (V.Vector LAB) where
generate (_,_,_, image) = V.replicateM 16 $ randomFromImage image generate (_,_,_, image) = V.replicateM 16 $ randomFromImage image
crossover _ a b = return $ alternatingZip a b crossover _ a b = return $ alternatingZip a b