Open main menu

CDOT Wiki β

Changes

User:Dhhodgin

2,313 bytes added, 17:16, 13 December 2009
Code Blocks
== Code Blocks ==
Here is a list of code blocks I have written for the processing.js project<br />
0.3 - wip: blendColor(), blend(), copy()
=== copy() ===
=== blend() helper functions===
blit_resize, filter_new_scanline, filter_bilinear coming soon
p.intersect = function intersect(sx1, sy1, sx2, sy2, dx1, dy1, dx2, dy2) {
}
return !(dw <= 0 || dh <= 0);
};
p.filter_new_scanline = function filter_new_scanline() {
p.shared.sX = p.shared.srcXOffset;
p.shared.fracV = p.shared.srcYOffset & p.PREC_MAXVAL;
p.shared.ifV = p.PREC_MAXVAL - p.shared.fracV;
p.shared.v1 = (p.shared.srcYOffset >> p.PRECISIONB) * p.shared.iw;
p.shared.v2 = Math.min((p.shared.srcYOffset >> p.PRECISIONB) + 1, p.shared.ih1) * p.shared.iw;
};
p.filter_bilinear = function filter_bilinear() {
p.shared.fracU = p.shared.sX & p.PREC_MAXVAL;
p.shared.ifU = p.PREC_MAXVAL - p.shared.fracU;
p.shared.ul = (p.shared.ifU * p.shared.ifV) >> p.PRECISIONB;
p.shared.ll = (p.shared.ifU * p.shared.fracV) >> p.PRECISIONB;
p.shared.ur = (p.shared.fracU * p.shared.ifV) >> p.PRECISIONB;
p.shared.lr = (p.shared.fracU * p.shared.fracV) >> p.PRECISIONB;
p.shared.u1 = (p.shared.sX >> p.PRECISIONB);
p.shared.u2 = Math.min(p.shared.u1 + 1, p.shared.iw1);
// get color values of the 4 neighbouring texels
p.shared.cUL = p.shared.srcBuffer[p.shared.v1 + p.shared.u1];
p.shared.cUR = p.shared.srcBuffer[p.shared.v1 + p.shared.u2];
p.shared.cLL = p.shared.srcBuffer[p.shared.v2 + p.shared.u1];
p.shared.cLR = p.shared.srcBuffer[p.shared.v2 + p.shared.u2];
p.shared.r = ((p.shared.ul*((p.shared.cUL&p.RED_MASK)>>16) + p.shared.ll*((p.shared.cLL&p.RED_MASK)>>16) +
p.shared.ur*((p.shared.cUR&p.RED_MASK)>>16) + p.shared.lr*((p.shared.cLR&p.RED_MASK)>>16))
<< p.PREC_RED_SHIFT) & p.RED_MASK;
p.shared.g = ((p.shared.ul*(p.shared.cUL&p.GREEN_MASK) + p.shared.ll*(p.shared.cLL&p.GREEN_MASK) +
p.shared.ur*(p.shared.cUR&p.GREEN_MASK) + p.shared.lr*(p.shared.cLR&p.GREEN_MASK))
>>> p.PRECISIONB) & p.GREEN_MASK;
p.shared.b = (p.shared.ul*(p.shared.cUL&p.BLUE_MASK) + p.shared.ll*(p.shared.cLL&p.BLUE_MASK) +
p.shared.ur*(p.shared.cUR&p.BLUE_MASK) + p.shared.lr*(p.shared.cLR&p.BLUE_MASK))
>>> p.PRECISIONB;
p.shared.a = ((p.shared.ul*((p.shared.cUL&p.ALPHA_MASK)>>>24) + p.shared.ll*((p.shared.cLL&p.ALPHA_MASK)>>>24) +
p.shared.ur*((p.shared.cUR&p.ALPHA_MASK)>>>24) + p.shared.lr*((p.shared.cLR&p.ALPHA_MASK)>>>24))
<< p.PREC_ALPHA_SHIFT) & p.ALPHA_MASK;
return p.shared.a | p.shared.r | p.shared.g | p.shared.b;
};
1
edit