Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- ReadImageFile.hs
- import qualified Codec.Picture as Picture
- import qualified Data.Vector.Storable as Vector
- intToDouble i = fromIntegral i::Double
- printImageInfo imageType image =
- putStrLn ("Length: " ++ (show imgLength)) >>
- putStrLn ("Numbers per pixel: " ++ (show numbersPerPixel)) >>
- putStrLn ("Minimum value: " ++ (show $ Vector.minimum imgData)) >>
- putStrLn ("Maximum value: " ++ (show $ Vector.maximum imgData)) >>
- putStrLn ("Image type: " ++ imageType) >>
- putStrLn ("Dimensions: (" ++ (show width) ++ "," ++ (show height) ++ ")")
- where
- imgData = Picture.imageData image
- imgLength = Vector.length imgData
- width = Picture.imageWidth image
- height = Picture.imageHeight image
- numbersPerPixel = (intToDouble imgLength) / (intToDouble width) / (intToDouble height)
- processImage img =
- case img of
- Picture.ImageY8 i -> printImageInfo "ImageY8" i
- Picture.ImageYF i -> printImageInfo "ImageYF" i
- Picture.ImageYA8 i -> printImageInfo "ImageYA8" i
- Picture.ImageRGB8 i -> printImageInfo "ImageRGB8" i
- Picture.ImageRGBF i -> printImageInfo "ImageRGBF" i
- Picture.ImageRGBA8 i -> printImageInfo "ImageRGBA8" i
- Picture.ImageYCbCr8 i -> printImageInfo "ImageYCbCr8" i
- readImageFile imageFile =
- putStrLn ("\nReading image: " ++ imageFile) >>
- Picture.readImage imageFile >>= \result ->
- case result of
- Left error -> putStrLn ("ERROR: " ++ show error)
- Right image -> processImage image
- main =
- readImageFile "Halflife-Haskell.jpg" >>
- readImageFile "development-haskell.png"
- -- Download images from:
- -- http://images.wikia.com/uncyclopedia/images/f/fb/Halflife-Haskell.jpg
- -- http://www.iconattitude.com/icons/open_icon_library/apps/png/256/development-haskell.png
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement