fix(resize): use Int instead of Double to increase performance
This commit is contained in:
parent
529d503204
commit
0a9712fe4a
@ -178,13 +178,14 @@ module Data.Picture ( Picture
|
|||||||
where
|
where
|
||||||
initial = vector [0..fromIntegral sWidth * fromIntegral sHeight - 1]
|
initial = vector [0..fromIntegral sWidth * fromIntegral sHeight - 1]
|
||||||
(width, height) = (rows r, cols r)
|
(width, height) = (rows r, cols r)
|
||||||
(xRatio, yRatio) = (fromIntegral width / fromIntegral sWidth, fromIntegral height / fromIntegral sHeight)
|
factor = 2 ^ 16
|
||||||
|
(xRatio, yRatio) = (width * factor `div` sWidth + 1, height * factor `div` sHeight + 1)
|
||||||
f m = tr $ reshape sWidth $ V.map replace initial
|
f m = tr $ reshape sWidth $ V.map replace initial
|
||||||
where
|
where
|
||||||
v = flatten (tr m)
|
v = flatten (tr m)
|
||||||
replace index =
|
replace index =
|
||||||
let (x, y) = (fromIntegral $ floor index `mod` sWidth, fromIntegral . floor $ index / fromIntegral sWidth)
|
let (x, y) = (floor index `mod` sWidth, floor index `div` sWidth)
|
||||||
(px, py) = (floor $ x * xRatio, floor $ y * yRatio)
|
(px, py) = (x * xRatio `div` factor, y * yRatio `div` factor)
|
||||||
in v ! (py * width + px)
|
in v ! (py * width + px)
|
||||||
|
|
||||||
-- | Scale an image using the resize function
|
-- | Scale an image using the resize function
|
||||||
|
Loading…
Reference in New Issue
Block a user