Optimized JPX's transformComponents
This commit is contained in:
parent
27d532efeb
commit
7067409e00
@ -1076,7 +1076,7 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Section G.2.2 Inverse multi component transform
|
// Section G.2.2 Inverse multi component transform
|
||||||
var shift, offset, max, min;
|
var shift, offset, max, min, maxK;
|
||||||
var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
|
var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
|
||||||
if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
|
if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
|
||||||
var fourComponents = componentsCount === 4;
|
var fourComponents = componentsCount === 4;
|
||||||
@ -1090,45 +1090,44 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
// compute shift and offset only once.
|
// compute shift and offset only once.
|
||||||
shift = components[0].precision - 8;
|
shift = components[0].precision - 8;
|
||||||
offset = (128 << shift) + 0.5;
|
offset = (128 << shift) + 0.5;
|
||||||
max = (127.5 * (1 << shift));
|
max = 255 * (1 << shift);
|
||||||
min = -max;
|
maxK = max * 0.5;
|
||||||
|
min = -maxK;
|
||||||
|
|
||||||
var component0 = tile.components[0];
|
var component0 = tile.components[0];
|
||||||
|
var alpha01 = componentsCount - 3;
|
||||||
|
jj = y0items.length;
|
||||||
if (!component0.codingStyleParameters.reversibleTransformation) {
|
if (!component0.codingStyleParameters.reversibleTransformation) {
|
||||||
// inverse irreversible multiple component transform
|
// inverse irreversible multiple component transform
|
||||||
for (j = 0, jj = y0items.length; j < jj; ++j) {
|
for (j = 0; j < jj; j++, pos += alpha01) {
|
||||||
y0 = y0items[j];
|
y0 = y0items[j] + offset;
|
||||||
y1 = y1items[j];
|
y1 = y1items[j];
|
||||||
y2 = y2items[j];
|
y2 = y2items[j];
|
||||||
r = y0 + 1.402 * y2;
|
r = y0 + 1.402 * y2;
|
||||||
g = y0 - 0.34413 * y1 - 0.71414 * y2;
|
g = y0 - 0.34413 * y1 - 0.71414 * y2;
|
||||||
b = y0 + 1.772 * y1;
|
b = y0 + 1.772 * y1;
|
||||||
out[pos++] = r <= min ? 0 : r >= max ? 255 : (r + offset) >> shift;
|
out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
|
||||||
out[pos++] = g <= min ? 0 : g >= max ? 255 : (g + offset) >> shift;
|
out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
|
||||||
out[pos++] = b <= min ? 0 : b >= max ? 255 : (b + offset) >> shift;
|
out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
|
||||||
if (fourComponents) {
|
|
||||||
k = y3items[j];
|
|
||||||
out[pos++] =
|
|
||||||
k <= min ? 0 : k >= max ? 255 : (k + offset) >> shift;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// inverse reversible multiple component transform
|
// inverse reversible multiple component transform
|
||||||
for (j = 0, jj = y0items.length; j < jj; ++j) {
|
for (j = 0; j < jj; j++, pos += alpha01) {
|
||||||
y0 = y0items[j];
|
y0 = y0items[j] + offset;
|
||||||
y1 = y1items[j];
|
y1 = y1items[j];
|
||||||
y2 = y2items[j];
|
y2 = y2items[j];
|
||||||
g = y0 - ((y2 + y1) >> 2);
|
g = y0 - ((y2 + y1) >> 2);
|
||||||
r = g + y2;
|
r = g + y2;
|
||||||
b = g + y1;
|
b = g + y1;
|
||||||
out[pos++] = r <= min ? 0 : r >= max ? 255 : (r + offset) >> shift;
|
out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
|
||||||
out[pos++] = g <= min ? 0 : g >= max ? 255 : (g + offset) >> shift;
|
out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
|
||||||
out[pos++] = b <= min ? 0 : b >= max ? 255 : (b + offset) >> shift;
|
out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
|
||||||
if (fourComponents) {
|
}
|
||||||
k = y3items[j];
|
}
|
||||||
out[pos++] =
|
if (fourComponents) {
|
||||||
k <= min ? 0 : k >= max ? 255 : (k + offset) >> shift;
|
for (j = 0, pos = 3; j < jj; j++, pos += 4) {
|
||||||
}
|
k = y3items[j];
|
||||||
|
out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else { // no multi-component transform
|
} else { // no multi-component transform
|
||||||
|
Loading…
Reference in New Issue
Block a user