diff --git a/src/pixie/images.nim b/src/pixie/images.nim index 540853a..bf3ec2d 100644 --- a/src/pixie/images.nim +++ b/src/pixie/images.nim @@ -347,8 +347,8 @@ proc blur*(image: Image, radius: float32, outOfBounds = ColorRGBX()) = (values[3] div 1024 div 255).uint8 ) - # Blur in the X direction. - let blurX = newImage(image.width, image.height) + # Blur in the X direction. Store with dimensions swapped for reading later. + let blurX = newImage(image.height, image.width) for y in 0 ..< image.height: for x in 0 ..< image.width: var values: array[4, uint32] @@ -361,7 +361,7 @@ proc blur*(image: Image, radius: float32, outOfBounds = ColorRGBX()) = for xx in max(x - radius, image.width) ..< x + radius: values += outOfBounds * lookup[xx - x + radius] - blurX.setRgbaUnsafe(x, y, values.rgbx()) + blurX.setRgbaUnsafe(y, x, values.rgbx()) # Blur in the Y direction. for y in 0 ..< image.height: @@ -371,7 +371,7 @@ proc blur*(image: Image, radius: float32, outOfBounds = ColorRGBX()) = values += outOfBounds * lookup[yy - y + radius] for yy in max(y - radius, 0) ..< min(y + radius, image.height): - values += blurX.getRgbaUnsafe(x, yy) * lookup[yy - y + radius] + values += blurX.getRgbaUnsafe(yy, x) * lookup[yy - y + radius] for yy in max(y - radius, image.height) ..< y + radius: values += outOfBounds * lookup[yy - y + radius] diff --git a/src/pixie/masks.nim b/src/pixie/masks.nim index 00507e8..c419778 100644 --- a/src/pixie/masks.nim +++ b/src/pixie/masks.nim @@ -162,8 +162,8 @@ proc blur*(mask: Mask, radius: float32, outOfBounds: uint8 = 0) = let lookup = gaussianLookup(radius) - # Blur in the X direction. - let blurX = newMask(mask.width, mask.height) + # Blur in the X direction. Store with dimensions swapped for reading later. + let blurX = newMask(mask.height, mask.width) for y in 0 ..< mask.height: for x in 0 ..< mask.width: var value: uint32 @@ -176,7 +176,7 @@ proc blur*(mask: Mask, radius: float32, outOfBounds: uint8 = 0) = for xx in max(x - radius, mask.width) ..< x + radius: value += outOfBounds * lookup[xx - x + radius] - blurX.setValueUnsafe(x, y, (value div 1024 div 255).uint8) + blurX.setValueUnsafe(y, x, (value div 1024 div 255).uint8) # Blur in the Y direction and modify image. for y in 0 ..< mask.height: @@ -186,7 +186,7 @@ proc blur*(mask: Mask, radius: float32, outOfBounds: uint8 = 0) = value += outOfBounds * lookup[yy - y + radius] for yy in max(y - radius, 0) ..< min(y + radius, mask.height): - value += blurX.getValueUnsafe(x, yy) * lookup[yy - y + radius] + value += blurX.getValueUnsafe(yy, x) * lookup[yy - y + radius] for yy in max(y - radius, mask.height) ..< y + radius: value += outOfBounds * lookup[yy - y + radius]