Prescales shading pattern packed data indices

This commit is contained in:
Yury Delendik 2014-02-13 08:20:00 -06:00
parent 5262e6f84f
commit 1e8d70af98
2 changed files with 48 additions and 38 deletions

View File

@ -670,6 +670,38 @@ Shadings.Mesh = (function MeshClosure() {
mesh.bounds = [minX, minY, maxX, maxY];
}
function packData(mesh) {
var i, ii, j, jj;
var coords = mesh.coords;
var coordsPacked = new Float32Array(coords.length * 2);
for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
var xy = coords[i];
coordsPacked[j++] = xy[0];
coordsPacked[j++] = xy[1];
}
mesh.coords = coordsPacked;
var colors = mesh.colors;
var colorsPacked = new Uint8Array(colors.length * 3);
for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
var c = colors[i];
colorsPacked[j++] = c[0];
colorsPacked[j++] = c[1];
colorsPacked[j++] = c[2];
}
mesh.colors = colorsPacked;
var figures = mesh.figures;
for (i = 0, ii = figures.length; i < ii; i++) {
var figure = figures[i], ps = figure.coords, cs = figure.colors;
for (j = 0, jj = ps.length; j < jj; j++) {
ps[j] *= 2;
cs[j] *= 3;
}
}
}
function Mesh(stream, matrix, xref, res) {
assert(isStream(stream), 'Mesh data is not a stream');
var dict = stream.dict;
@ -757,35 +789,14 @@ Shadings.Mesh = (function MeshClosure() {
}
// calculate bounds
updateBounds(this);
packData(this);
}
Mesh.prototype = {
getIR: function Mesh_getIR() {
var type = this.shadingType;
var i, ii, j;
var coords = this.coords;
var coordsPacked = new Float32Array(coords.length * 2);
for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
var xy = coords[i];
coordsPacked[j++] = xy[0];
coordsPacked[j++] = xy[1];
}
var colors = this.colors;
var colorsPacked = new Uint8Array(colors.length * 3);
for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
var c = colors[i];
colorsPacked[j++] = c[0];
colorsPacked[j++] = c[1];
colorsPacked[j++] = c[2];
}
var figures = this.figures;
var bbox = this.bbox;
var bounds = this.bounds;
var matrix = this.matrix;
var background = this.background;
return ['Mesh', type, coordsPacked, colorsPacked, figures, bounds,
matrix, bbox, background];
return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
this.bounds, this.matrix, this.bbox, this.background];
}
};

View File

@ -55,28 +55,27 @@ var createMeshCanvas = (function createMeshCanvasClosure() {
var coords = context.coords, colors = context.colors;
var bytes = data.data, rowSize = data.width * 4;
var tmp;
if (coords[p1 * 2 + 1] > coords[p2 * 2 + 1]) {
if (coords[p1 + 1] > coords[p2 + 1]) {
tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
}
if (coords[p2 * 2 + 1] > coords[p3 * 2 + 1]) {
if (coords[p2 + 1] > coords[p3 + 1]) {
tmp = p2; p2 = p3; p3 = tmp; tmp = c2; c2 = c3; c3 = tmp;
}
if (coords[p1 * 2 + 1] > coords[p2 * 2 + 1]) {
if (coords[p1 + 1] > coords[p2 + 1]) {
tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
}
var x1 = (coords[p1 * 2] + context.offsetX) * context.scaleX;
var y1 = (coords[p1 * 2 + 1] + context.offsetY) * context.scaleY;
var x2 = (coords[p2 * 2] + context.offsetX) * context.scaleX;
var y2 = (coords[p2 * 2 + 1] + context.offsetY) * context.scaleY;
var x3 = (coords[p3 * 2] + context.offsetX) * context.scaleX;
var y3 = (coords[p3 * 2 + 1] + context.offsetY) * context.scaleY;
var x1 = (coords[p1] + context.offsetX) * context.scaleX;
var y1 = (coords[p1 + 1] + context.offsetY) * context.scaleY;
var x2 = (coords[p2] + context.offsetX) * context.scaleX;
var y2 = (coords[p2 + 1] + context.offsetY) * context.scaleY;
var x3 = (coords[p3] + context.offsetX) * context.scaleX;
var y3 = (coords[p3 + 1] + context.offsetY) * context.scaleY;
if (y1 >= y3) {
return;
}
var c1i = c1 * 3, c2i = c2 * 3, c3i = c3 * 3;
var c1r = colors[c1i], c1g = colors[c1i + 1], c1b = colors[c1i + 2];
var c2r = colors[c2i], c2g = colors[c2i + 1], c2b = colors[c2i + 2];
var c3r = colors[c3i], c3g = colors[c3i + 1], c3b = colors[c3i + 2];
var c1r = colors[c1], c1g = colors[c1 + 1], c1b = colors[c1 + 2];
var c2r = colors[c2], c2g = colors[c2 + 1], c2b = colors[c2 + 2];
var c3r = colors[c3], c3g = colors[c3 + 1], c3b = colors[c3 + 2];
var minY = Math.round(y1), maxY = Math.round(y3);
var xa, car, cag, cab;