Created
August 22, 2012 14:52
-
-
Save kmels/3426383 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- tests if an image is valid and, if it is, returns the resolution of the picture as a pair of the x-resolution and the y-resolution. An image is valid if all its pixels are valid and if all the rows have equally many columns. | |
ANTES | |
----------------------------- | |
validImage rows@(firstRow:nextRow:rrs) = | |
if (isValidRow firstRow && length firstRow == length nextRow && (isJust $ validImage (nextRow:rrs))) then | |
Just (length firstRow, length rows) | |
else | |
Nothing | |
validImage rows@(r:rs) = if isValidRow r && (isJust $ validImage rs) then Just (length r, length rows) else Nothing | |
DESPUES | |
----------------------------- | |
validImage :: [[RGB]] -> Maybe (Int, Int) | |
validImage [] = Just (0,0) | |
validImage rows = if all isValidRow rows && allEquals (map length rows) | |
then Just (length $ head rows,length rows) | |
else Nothing | |
allEquals (x:y:xs) = x == y && allEquals (y:xs) | |
allEquals [x] = True | |
allEquals [] = True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment