From 0a9712fe4a914367edb360d39161b63d973caa8e Mon Sep 17 00:00:00 2001 From: Mahdi Dibaiee Date: Fri, 3 Feb 2017 22:14:52 +0330 Subject: [PATCH] fix(resize): use Int instead of Double to increase performance --- src/Data/Picture.hs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Data/Picture.hs b/src/Data/Picture.hs index 9a758e1..810779a 100644 --- a/src/Data/Picture.hs +++ b/src/Data/Picture.hs @@ -178,13 +178,14 @@ module Data.Picture ( Picture where initial = vector [0..fromIntegral sWidth * fromIntegral sHeight - 1] (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 where v = flatten (tr m) replace index = - let (x, y) = (fromIntegral $ floor index `mod` sWidth, fromIntegral . floor $ index / fromIntegral sWidth) - (px, py) = (floor $ x * xRatio, floor $ y * yRatio) + let (x, y) = (floor index `mod` sWidth, floor index `div` sWidth) + (px, py) = (x * xRatio `div` factor, y * yRatio `div` factor) in v ! (py * width + px) -- | Scale an image using the resize function