# Count non-transparent pixels in a canvas

I need to count non-transparent pixels in a canvas. I am pretty sure there is a nice and elegant syntax for doing this. Note that the data returned by getImageData is not a regular array and cannot be sliced, for example, or it does not have a reduce method.

data = context.getImageData(0, 0, canvas.width, canvas.height).data
count = 0
i = 0
for x in data
if (i + 1) % 4 == 0 && x > 0
count++
i++


data = context.getImageData(0, 0, canvas.width, canvas.height).data