faster minifyBy2
This commit is contained in:
parent
6df03ed1d1
commit
de1b1b95ca
1 changed files with 20 additions and 6 deletions
|
@ -180,12 +180,26 @@ proc minifyBy2*(image: Image, power = 1): Image =
|
||||||
result = newImage(image.width div 2, image.height div 2)
|
result = newImage(image.width div 2, image.height div 2)
|
||||||
for y in 0 ..< result.height:
|
for y in 0 ..< result.height:
|
||||||
for x in 0 ..< result.width:
|
for x in 0 ..< result.width:
|
||||||
var color =
|
let
|
||||||
image.getRgbaUnsafe(x * 2 + 0, y * 2 + 0).color / 4.0 +
|
a = image.getRgbaUnsafe(x * 2 + 0, y * 2 + 0)
|
||||||
image.getRgbaUnsafe(x * 2 + 1, y * 2 + 0).color / 4.0 +
|
b = image.getRgbaUnsafe(x * 2 + 1, y * 2 + 0)
|
||||||
image.getRgbaUnsafe(x * 2 + 1, y * 2 + 1).color / 4.0 +
|
c = image.getRgbaUnsafe(x * 2 + 1, y * 2 + 1)
|
||||||
image.getRgbaUnsafe(x * 2 + 0, y * 2 + 1).color / 4.0
|
d = image.getRgbaUnsafe(x * 2 + 0, y * 2 + 1)
|
||||||
result.setRgbaUnsafe(x, y, color.rgba)
|
|
||||||
|
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 =
|
proc magnifyBy2*(image: Image, power = 1): Image =
|
||||||
## Scales image image up by 2 ^ power.
|
## Scales image image up by 2 ^ power.
|
||||||
|
|
Loading…
Reference in a new issue