@@ -46,24 +46,28 @@ instance Show SingleRowSingleAttrImage where
4646newtype WidthResize = WidthResize (Image -> (Image, Int))
4747
4848instance Arbitrary WidthResize where
49− arbitrary = oneof
50− [ return $ WidthResize $ \i -> (i, image_width i)
51− , do
52− WidthResize f <- arbitrary
53− out_width <- choose (1, 256)
54− return $ WidthResize $ \i -> (resize_width out_width $ fst $ f i, out_width)
55− ]
49+ arbitrary = do
50+ WidthResize f <- arbitrary
51+ w <- choose (1,1024)
52+ oneof $ map (return . WidthResize)
53+ [ \i -> (i, image_width i)
54+ , \i -> (resize_width w $ fst $ f i, w)
55+ , \i -> let i' = fst $ f i in (crop_left w i', min (image_width i') w)
56+ , \i -> let i' = fst $ f i in (crop_right w i', min (image_width i') w)
57+ ]
5658
5759newtype HeightResize = HeightResize (Image -> (Image, Int))
5860
5961instance Arbitrary HeightResize where
60− arbitrary = oneof
61− [ return $ HeightResize $ \i -> (i, image_height i)
62− , do
63− HeightResize f <- arbitrary
64− out_height <- choose (1, 256)
65− return $ HeightResize $ \i -> (resize_height out_height $ fst $ f i, out_height)
66− ]
62+ arbitrary = do
63+ HeightResize f <- arbitrary
64+ h <- choose (1,1024)
65+ oneof $ map (return . HeightResize)
66+ [ \i -> (i, image_height i)
67+ , \i -> (resize_height h $ fst $ f i, h)
68+ , \i -> let i' = fst $ f i in (crop_top h i', min (image_height i') h)
69+ , \i -> let i' = fst $ f i in (crop_bottom h i', min (image_height i') h)
70+ ]
6771
6872newtype ImageResize = ImageResize (Image -> (Image, (Int, Int)))
6973
@@ -162,3 +166,24 @@ instance Arbitrary Image where
162166 return $! fst $! f i
163167 ]
164168
169+data CropOperation
170+ = CropFromLeft
171+ | CropFromRight
172+ | CropFromTop
173+ | CropFromBottom
174+ deriving (Eq, Show)
175+
176+instance Arbitrary CropOperation where
177+ arbitrary = oneof $ map return [CropFromLeft, CropFromRight, CropFromTop, CropFromBottom]
178+
179+data Translation = Translation Image (Int, Int) Image
180+ deriving (Eq, Show)
181+
182+instance Arbitrary Translation where
183+ arbitrary = do
184+ i <- arbitrary
185+ x <- arbitrary `suchThat` (> 0)
186+ y <- arbitrary `suchThat` (> 0)
187+ let i' = translate x y i
188+ return $ Translation i (x,y) i'
189+