Light optimization
This commit is contained in:
parent
b89f544b18
commit
ac592a2fdd
72
src/jpx.js
72
src/jpx.js
@ -438,10 +438,10 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
if (i >= height)
|
if (i >= height)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
var contextLabel = labels[neighborsSignificance[index]];
|
if (coefficentsMagnitude[index] || !neighborsSignificance[index])
|
||||||
if (coefficentsMagnitude[index] || !contextLabel)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
var contextLabel = labels[neighborsSignificance[index]];
|
||||||
var cx = contexts[contextLabel];
|
var cx = contexts[contextLabel];
|
||||||
var decision = decoder.readBit(cx);
|
var decision = decoder.readBit(cx);
|
||||||
if (decision) {
|
if (decision) {
|
||||||
@ -538,18 +538,23 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
var processingFlags = this.processingFlags;
|
var processingFlags = this.processingFlags;
|
||||||
var processedMask = 1;
|
var processedMask = 1;
|
||||||
var firstMagnitudeBitMask = 2;
|
var firstMagnitudeBitMask = 2;
|
||||||
|
var oneRowDown = width;
|
||||||
|
var twoRowsDown = width * 2;
|
||||||
|
var threeRowsDown = width * 3;
|
||||||
for (var i0 = 0; i0 < height; i0 += 4) {
|
for (var i0 = 0; i0 < height; i0 += 4) {
|
||||||
for (var j = 0; j < width; j++) {
|
for (var j = 0; j < width; j++) {
|
||||||
var index0 = i0 * width + j;
|
var index0 = i0 * width + j;
|
||||||
|
// using the property: labels[neighborsSignificance[index]] == 0
|
||||||
|
// when neighborsSignificance[index] == 0
|
||||||
var allEmpty = i0 + 3 < height &&
|
var allEmpty = i0 + 3 < height &&
|
||||||
processingFlags[index0] == 0 &&
|
processingFlags[index0] == 0 &&
|
||||||
processingFlags[index0 + width] == 0 &&
|
processingFlags[index0 + oneRowDown] == 0 &&
|
||||||
processingFlags[index0 + 2 * width] == 0 &&
|
processingFlags[index0 + twoRowsDown] == 0 &&
|
||||||
processingFlags[index0 + 3 * width] == 0 &&
|
processingFlags[index0 + threeRowsDown] == 0 &&
|
||||||
labels[neighborsSignificance[index0]] == 0 &&
|
neighborsSignificance[index0] == 0 &&
|
||||||
labels[neighborsSignificance[index0 + width]] == 0 &&
|
neighborsSignificance[index0 + oneRowDown] == 0 &&
|
||||||
labels[neighborsSignificance[index0 + 2 * width]] == 0 &&
|
neighborsSignificance[index0 + twoRowsDown] == 0 &&
|
||||||
labels[neighborsSignificance[index0 + 3 * width]] == 0;
|
neighborsSignificance[index0 + threeRowsDown] == 0;
|
||||||
var i1 = 0, index = index0;
|
var i1 = 0, index = index0;
|
||||||
var cx, i;
|
var cx, i;
|
||||||
if (allEmpty) {
|
if (allEmpty) {
|
||||||
@ -557,9 +562,9 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
var hasSignificantCoefficent = decoder.readBit(cx);
|
var hasSignificantCoefficent = decoder.readBit(cx);
|
||||||
if (!hasSignificantCoefficent) {
|
if (!hasSignificantCoefficent) {
|
||||||
bitsDecoded[index0]++;
|
bitsDecoded[index0]++;
|
||||||
bitsDecoded[index0 + width]++;
|
bitsDecoded[index0 + oneRowDown]++;
|
||||||
bitsDecoded[index0 + 2 * width]++;
|
bitsDecoded[index0 + twoRowsDown]++;
|
||||||
bitsDecoded[index0 + 3 * width]++;
|
bitsDecoded[index0 + threeRowsDown]++;
|
||||||
continue; // next column
|
continue; // next column
|
||||||
}
|
}
|
||||||
cx = this.uniformContext;
|
cx = this.uniformContext;
|
||||||
@ -584,11 +589,11 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
if (i >= height)
|
if (i >= height)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
var contextLabel = labels[neighborsSignificance[index]];
|
|
||||||
if (coefficentsMagnitude[index] ||
|
if (coefficentsMagnitude[index] ||
|
||||||
(processingFlags[index] & processedMask) != 0)
|
(processingFlags[index] & processedMask) != 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
var contextLabel = labels[neighborsSignificance[index]];
|
||||||
cx = contexts[contextLabel];
|
cx = contexts[contextLabel];
|
||||||
var decision = decoder.readBit(cx);
|
var decision = decoder.readBit(cx);
|
||||||
if (decision == 1) {
|
if (decision == 1) {
|
||||||
@ -623,29 +628,34 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
};
|
};
|
||||||
Transform.prototype.iterate = function transformIterate(ll, hl, lh, hh,
|
Transform.prototype.iterate = function transformIterate(ll, hl, lh, hh,
|
||||||
u0, v0) {
|
u0, v0) {
|
||||||
|
var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
|
||||||
|
var hlWidth = hl.width, hlHeight = hl.height, hlItems = hl.items;
|
||||||
|
var lhWidth = lh.width, lhHeight = lh.height, lhItems = lh.items;
|
||||||
|
var hhWidth = hh.width, hhHeight = hh.height, hhItems = hh.items;
|
||||||
|
|
||||||
// Section F.3.3 interleave
|
// Section F.3.3 interleave
|
||||||
var width = ll.width + hl.width;
|
var width = llWidth + hlWidth;
|
||||||
var height = ll.height + lh.height;
|
var height = llHeight + lhHeight;
|
||||||
var items = new Float32Array(width * height);
|
var items = new Float32Array(width * height);
|
||||||
for (var i = 0, ii = ll.height; i < ii; i++) {
|
for (var i = 0, ii = llHeight; i < ii; i++) {
|
||||||
var k = i * ll.width, l = i * 2 * width;
|
var k = i * llWidth, l = i * 2 * width;
|
||||||
for (var j = 0, jj = ll.width; j < jj; j++, k++, l += 2)
|
for (var j = 0, jj = llWidth; j < jj; j++, k++, l += 2)
|
||||||
items[l] = ll.items[k];
|
items[l] = llItems[k];
|
||||||
}
|
}
|
||||||
for (var i = 0, ii = hl.height; i < ii; i++) {
|
for (var i = 0, ii = hlHeight; i < ii; i++) {
|
||||||
var k = i * hl.width, l = i * 2 * width + 1;
|
var k = i * hlWidth, l = i * 2 * width + 1;
|
||||||
for (var j = 0, jj = hl.width; j < jj; j++, k++, l += 2)
|
for (var j = 0, jj = hlWidth; j < jj; j++, k++, l += 2)
|
||||||
items[l] = hl.items[k];
|
items[l] = hlItems[k];
|
||||||
}
|
}
|
||||||
for (var i = 0, ii = lh.height; i < ii; i++) {
|
for (var i = 0, ii = lhHeight; i < ii; i++) {
|
||||||
var k = i * lh.width, l = (i * 2 + 1) * width;
|
var k = i * lhWidth, l = (i * 2 + 1) * width;
|
||||||
for (var j = 0, jj = lh.width; j < jj; j++, k++, l += 2)
|
for (var j = 0, jj = lhWidth; j < jj; j++, k++, l += 2)
|
||||||
items[l] = lh.items[k];
|
items[l] = lhItems[k];
|
||||||
}
|
}
|
||||||
for (var i = 0, ii = hh.height; i < ii; i++) {
|
for (var i = 0, ii = hhHeight; i < ii; i++) {
|
||||||
var k = i * hh.width, l = (i * 2 + 1) * width + 1;
|
var k = i * hhWidth, l = (i * 2 + 1) * width + 1;
|
||||||
for (var j = 0, jj = hh.width; j < jj; j++, k++, l += 2)
|
for (var j = 0, jj = hhWidth; j < jj; j++, k++, l += 2)
|
||||||
items[l] = hh.items[k];
|
items[l] = hhItems[k];
|
||||||
}
|
}
|
||||||
|
|
||||||
var bufferPadding = 4;
|
var bufferPadding = 4;
|
||||||
|
Loading…
Reference in New Issue
Block a user