diff --git a/src/pixie/images.nim b/src/pixie/images.nim index eee8d0c..ebbf8aa 100644 --- a/src/pixie/images.nim +++ b/src/pixie/images.nim @@ -180,12 +180,26 @@ proc minifyBy2*(image: Image, power = 1): Image = result = newImage(image.width div 2, image.height div 2) for y in 0 ..< result.height: for x in 0 ..< result.width: - var color = - image.getRgbaUnsafe(x * 2 + 0, y * 2 + 0).color / 4.0 + - image.getRgbaUnsafe(x * 2 + 1, y * 2 + 0).color / 4.0 + - image.getRgbaUnsafe(x * 2 + 1, y * 2 + 1).color / 4.0 + - image.getRgbaUnsafe(x * 2 + 0, y * 2 + 1).color / 4.0 - result.setRgbaUnsafe(x, y, color.rgba) + let + a = image.getRgbaUnsafe(x * 2 + 0, y * 2 + 0) + b = image.getRgbaUnsafe(x * 2 + 1, y * 2 + 0) + c = image.getRgbaUnsafe(x * 2 + 1, y * 2 + 1) + d = image.getRgbaUnsafe(x * 2 + 0, y * 2 + 1) + + var values: array[4, uint32] + values[0] = a.r.uint32 + b.r + c.r + d.r + values[1] = a.g.uint32 + b.g + c.g + d.g + values[2] = a.b.uint32 + b.b + c.b + d.b + values[3] = a.a.uint32 + b.a + c.a + d.a + + let color = rgba( + (values[0] div 4).uint8, + (values[1] div 4).uint8, + (values[2] div 4).uint8, + (values[3] div 4).uint8 + ) + + result.setRgbaUnsafe(x, y, color) proc magnifyBy2*(image: Image, power = 1): Image = ## Scales image image up by 2 ^ power.