reanimate/videos/color-theory/Common.hs
David Himmelstrup 3e371f7627 Narrated animation about color theory (#84)
* Add slide transitions.

Co-authored-by: eveyyp <55053150+eveyyp@users.noreply.github.com>
Former-commit-id: afa93f45f8d0f556ad73e349091f0226ce173eed
2020-06-02 20:14:47 +08:00

32 lines
989 B
Haskell
Executable file

module Common
( monalisa
, monalisaLarge
, applyColorMap
)
where
import qualified Data.ByteString as BS
import Codec.Picture
import System.IO.Unsafe
monalisa :: Image PixelRGB8
monalisa = unsafePerformIO $ do
dat <- BS.readFile "monalisa.jpg"
case decodeJpeg dat of
Left err -> error err
Right img -> return $ convertRGB8 img
monalisaLarge :: Image PixelRGB8
monalisaLarge = scaleImage 15 monalisa
scaleImage :: Pixel a => Int -> Image a -> Image a
scaleImage factor img = generateImage fn
(imageWidth img * factor)
(imageHeight img * factor)
where fn x y = pixelAt img (x `div` factor) (y `div` factor)
applyColorMap :: (Double -> PixelRGB8) -> Image PixelRGB8 -> Image PixelRGB8
applyColorMap cmap img = generateImage fn (imageWidth img) (imageHeight img)
where
fn x y = case pixelAt img x y of
PixelRGB8 r _ _ -> cmap (fromIntegral r / 255)