function downScaleCanvas(a, b) {
var c = Math.ceil,
d = Math.floor;
if (!(1 > b) || !(0 < b)) throw "scale must be a positive number <1 ";
var e = b * b,
f = a.width,
g = a.height,
h = d(f * b),
i = d(g * b),
j = 0,
k = 0,
l = 0,
m = 0,
n = 0,
o = 0,
p = 0,
q = 0,
r = 0,
s = 0,
t = 0,
u = 0,
v = 0,
x = 0,
y = 0,
z = !1,
A = !1,
B = a.getContext("2d").getImageData(0, 0, f, g).data,
C = new Float32Array(3 * h * i),
D = 0,
E = 0,
F = 0;
for (k = 0; k < g; k++)
for (n = k * b, r = 0 | n, o = 3 * r * h, A = r != (0 | n + b), A && (x = r + 1 - n, y = n + b - r - 1), j = 0; j < f; j++, l += 4) m = j * b, q = 0 | m, p = o + 3 * q, z = q != (0 | m + b), z && (u = q + 1 - m, v = m + b - q - 1), D = B[l], E = B[l + 1], F = B[l + 2], z || A ? z && !A ? (s = u * b, C[p] += D * s, C[p + 1] += E * s, C[p + 2] += F * s, t = v * b, C[p + 3] += D * t, C[p + 4] += E * t, C[p + 5] += F * t) : A && !z ? (s = x * b, C[p] += D * s, C[p + 1] += E * s, C[p + 2] += F * s, t = y * b, C[p + 3 * h] += D * t, C[p + 3 * h + 1] += E * t, C[p + 3 * h + 2] += F * t) : (s = u * x, C[p] += D * s, C[p + 1] += E * s, C[p + 2] += F * s, t = v * x, C[p + 3] += D * t, C[p + 4] += E * t, C[p + 5] += F * t, t = u * y, C[p + 3 * h] += D * t, C[p + 3 * h + 1] += E * t, C[p + 3 * h + 2] += F * t, t = v * y, C[p + 3 * h + 3] += D * t, C[p + 3 * h + 4] += E * t, C[p + 3 * h + 5] += F * t) : (C[p] += D * e, C[p + 1] += E * e, C[p + 2] += F * e);
var G = document.createElement("canvas");
G.width = h, G.height = i;
var H = G.getContext("2d"),
I = H.getImageData(0, 0, h, i),
J = I.data,
K = 0;
for (l = 0, p = 0; K < h * i; l += 3, p += 4, K++) J[p] = c(C[l]), J[p + 1] = c(C[l + 1]), J[p + 2] = c(C[l + 2]), J[p + 3] = 255;
return H.putImageData(I, 0, 0), G
}
dohhhhhh !!