on master help sign in
Attempt to fix problem with Image crop
c0b4ce8John Pybus
src/Graphics/Vty/Image.hs+3−4
@@ -366,11 +366,10 @@ translate v i = Translation v i
366crop :: (Word, Word) -> Image -> Image
366crop :: (Word, Word) -> Image -> Image
367crop (0,_) _ = EmptyImage
367crop (0,_) _ = EmptyImage
368crop (_,0) _ = EmptyImage
368crop (_,0) _ = EmptyImage
369−crop v (ImageCrop _size i) = ImagePad (min (fst v) (fst _size), min (snd v) (snd _size)) i
370−crop v (ImagePad _size i) = ImagePad (min (fst v) (fst _size), min (snd v) (snd _size)) i
369+crop v (ImageCrop _size i) = ImageCrop (min (fst v) (fst _size), min (snd v) (snd _size)) i
371−crop v i = ImagePad v i
370+crop v i = ImageCrop v i
372
371
373−-- | Ensure an image is at least the provided size. If the image is smaler then pad.
372+-- | Ensure an image is at least the provided size. If the image is smaller then pad.
374pad :: (Word, Word) -> Image -> Image
373pad :: (Word, Word) -> Image -> Image
375pad (0,_) _ = EmptyImage
374pad (0,_) _ = EmptyImage
376pad (_,0) _ = EmptyImage
375pad (_,0) _ = EmptyImage
src/Graphics/Vty/Span.hs+18−16
@@ -136,6 +136,7 @@ build_spans pic region = do
136 (0,0)
136 (0,0)
137 0
137 0
138 (region_width region)
138 (region_width region)
139+ (fromEnum $ region_height region)
139 -- Fill in any unspecified columns with the background pattern.
140 -- Fill in any unspecified columns with the background pattern.
140 forM_ [0 .. (fromEnum $ region_height region - 1)] $! \row -> do
141 forM_ [0 .. (fromEnum $ region_height region - 1)] $! \row -> do
141 end_x <- Vector.read mrow_ops row >>= return . span_ops_effected_columns
142 end_x <- Vector.read mrow_ops row >>= return . span_ops_effected_columns
@@ -145,7 +146,7 @@ build_spans pic region = do
145 else return ()
146 else return ()
146 return mrow_ops
147 return mrow_ops
147
148
148−row_ops_for_image :: MRowOps s -> Image -> Background -> DisplayRegion -> (Word, Word) -> Int -> Word -> ST s (Word, Word)
149+row_ops_for_image :: MRowOps s -> Image -> Background -> DisplayRegion -> (Word, Word) -> Int -> Word -> Int -> ST s (Word, Word)
149row_ops_for_image mrow_ops -- the image to output the ops to
150row_ops_for_image mrow_ops -- the image to output the ops to
150 image -- the image to rasterize in column order to mrow_ops
151 image -- the image to rasterize in column order to mrow_ops
151 bg -- the background fill
152 bg -- the background fill
@@ -153,7 +154,9 @@ row_ops_for_image mrow_ops -- the image to output the ops t
153 skip_dim@(skip_row,skip_col) -- the number of rows
154 skip_dim@(skip_row,skip_col) -- the number of rows
154 y -- ???
155 y -- ???
155 remaining_columns -- ???
156 remaining_columns -- ???
157+ remain_rows
156 | remaining_columns == 0 = return skip_dim
158 | remaining_columns == 0 = return skip_dim
159+ | remain_rows == 0 = return skip_dim
157 | y >= fromEnum (region_height region) = return skip_dim
160 | y >= fromEnum (region_height region) = return skip_dim
158 | otherwise = case image of
161 | otherwise = case image of
159 EmptyImage -> return skip_dim
162 EmptyImage -> return skip_dim
@@ -174,30 +177,31 @@ row_ops_for_image mrow_ops -- the image to output the ops t
174 skip_dim
177 skip_dim
175 y
178 y
176 remaining_columns
179 remaining_columns
180+ remain_rows
181+ let top_height = (fromEnum $! image_height top_image) - (fromEnum $! skip_row - skip_row')
177 (skip_row'',skip_col'') <- row_ops_for_image mrow_ops
182 (skip_row'',skip_col'') <- row_ops_for_image mrow_ops
178 bottom_image
183 bottom_image
179 bg
184 bg
180 region
185 region
181 (skip_row', skip_col)
186 (skip_row', skip_col)
182− (y + (fromEnum $! image_height top_image) - (fromEnum $! skip_row - skip_row'))
187+ (y + top_height)
183 remaining_columns
188 remaining_columns
189+ (remain_rows - top_height)
184 return (skip_row'', min skip_col' skip_col'')
190 return (skip_row'', min skip_col' skip_col'')
185 HorizJoin l r _ _ -> do
191 HorizJoin l r _ _ -> do
186− (skip_row',skip_col') <- row_ops_for_image mrow_ops l bg region skip_dim y remaining_columns
192+ (skip_row',skip_col') <- row_ops_for_image mrow_ops l bg region skip_dim y remaining_columns remain_rows
187 -- Don't output the right part unless there is at least a single column left after
193 -- Don't output the right part unless there is at least a single column left after
188 -- outputting the left part.
194 -- outputting the left part.
189 if image_width l - (skip_col - skip_col') > remaining_columns
195 if image_width l - (skip_col - skip_col') > remaining_columns
190 then return (skip_row,skip_col')
196 then return (skip_row,skip_col')
191 else do
197 else do
192− (skip_row'',skip_col'') <- row_ops_for_image mrow_ops r bg region (skip_row, skip_col') y (remaining_columns - image_width l + (skip_col - skip_col'))
198+ (skip_row'',skip_col'') <- row_ops_for_image mrow_ops r bg region (skip_row, skip_col') y (remaining_columns - image_width l + (skip_col - skip_col')) remain_rows
193 return (min skip_row' skip_row'', skip_col'')
199 return (min skip_row' skip_row'', skip_col'')
194 BGFill width height -> do
200 BGFill width height -> do
195 let min_height = if y + (fromEnum height) > (fromEnum $! region_height region)
201 let min_height = if y + (fromEnum height) > (fromEnum $! region_height region)
196 then region_height region - (toEnum y)
202 then region_height region - (toEnum y)
197− else height
203+ else min height (toEnum remain_rows)
198− min_width = if width > remaining_columns
199− then remaining_columns
204+ min_width = min width remaining_columns
200− else width
201 actual_height = if skip_row > min_height
205 actual_height = if skip_row > min_height
202 then 0
206 then 0
203 else min_height - skip_row
207 else min_height - skip_row
@@ -216,25 +220,23 @@ row_ops_for_image mrow_ops -- the image to output the ops t
216 if dx < 0
220 if dx < 0
217 -- Translation left
221 -- Translation left
218 -- Extract the delta and add it to skip_col.
222 -- Extract the delta and add it to skip_col.
219− then row_ops_for_image mrow_ops (translate (0, dy) i) bg region (skip_row, skip_col + dw) y remaining_columns
223+ then row_ops_for_image mrow_ops (translate (0, dy) i) bg region (skip_row, skip_col + dw) y remaining_columns remain_rows
220 -- Translation right
224 -- Translation right
221 else if dy < 0
225 else if dy < 0
222 -- Translation up
226 -- Translation up
223 -- Extract the delta and add it to skip_row.
227 -- Extract the delta and add it to skip_row.
224− then row_ops_for_image mrow_ops (translate (dx, 0) i) bg region (skip_row + dh, skip_col) y remaining_columns
228+ then row_ops_for_image mrow_ops (translate (dx, 0) i) bg region (skip_row + dh, skip_col) y remaining_columns remain_rows
225 -- Translation down
229 -- Translation down
226 -- Pad the start of lines and above the image with a
230 -- Pad the start of lines and above the image with a
227− -- background_fill image.
231+ -- background_fill image
228− else row_ops_for_image mrow_ops (background_fill ow dh <-> (background_fill dw ih <|> i)) bg region skip_dim y remaining_columns
232+ else row_ops_for_image mrow_ops (background_fill ow dh <-> (background_fill dw ih <|> i)) bg region skip_dim y remaining_columns remain_rows
229 where
233 where
230 dw = toEnum $ abs dx
234 dw = toEnum $ abs dx
231 dh = toEnum $ abs dy
235 dh = toEnum $ abs dy
232 ow = image_width image
236 ow = image_width image
233 ih = image_height i
237 ih = image_height i
234 ImageCrop (max_w,max_h) i ->
238 ImageCrop (max_w,max_h) i ->
235− if y >= fromEnum max_h
236− then return skip_dim
237− else row_ops_for_image mrow_ops i bg region skip_dim y (min remaining_columns max_w)
239+ row_ops_for_image mrow_ops i bg region skip_dim y (min remaining_columns max_w) (min remain_rows $ fromEnum max_h)
238 ImagePad (min_w,min_h) i -> do
240 ImagePad (min_w,min_h) i -> do
239 let hpad = if image_width i < min_w
241 let hpad = if image_width i < min_w
240 then background_fill (min_w - image_width i) (image_height i)
242 then background_fill (min_w - image_width i) (image_height i)
@@ -242,7 +244,7 @@ row_ops_for_image mrow_ops -- the image to output the ops t
242 let vpad = if image_height i < min_h
244 let vpad = if image_height i < min_h
243 then background_fill (image_width i) (min_h - image_height i)
245 then background_fill (image_width i) (min_h - image_height i)
244 else empty_image
246 else empty_image
245− row_ops_for_image mrow_ops ((i <|> hpad) <-> vpad) bg region skip_dim y remaining_columns
247+ row_ops_for_image mrow_ops ((i <|> hpad) <-> vpad) bg region skip_dim y remaining_columns remain_rows
246
248
247snoc_text_span :: Attr -- the display attributes of the text span
249snoc_text_span :: Attr -- the display attributes of the text span
248 -> DisplayString -- the text to output
250 -> DisplayString -- the text to output