Merge pull request #4636 from fkaelberer/issue4553
Rename getUint32 to getInt32 and collect readInt*() in util.js
This commit is contained in:
commit
eb554a8756
@ -148,7 +148,7 @@ var ChunkedStream = (function ChunkedStreamClosure() {
|
|||||||
return (b0 << 8) + b1;
|
return (b0 << 8) + b1;
|
||||||
},
|
},
|
||||||
|
|
||||||
getUint32: function ChunkedStream_getUint32() {
|
getInt32: function ChunkedStream_getInt32() {
|
||||||
var b0 = this.getByte();
|
var b0 = this.getByte();
|
||||||
var b1 = this.getByte();
|
var b1 = this.getByte();
|
||||||
var b2 = this.getByte();
|
var b2 = this.getByte();
|
||||||
|
@ -2540,7 +2540,7 @@ var Font = (function FontClosure() {
|
|||||||
var idRangeOffsets = '';
|
var idRangeOffsets = '';
|
||||||
var glyphsIds = '';
|
var glyphsIds = '';
|
||||||
var bias = 0;
|
var bias = 0;
|
||||||
|
|
||||||
var range, start, end, codes;
|
var range, start, end, codes;
|
||||||
for (i = 0, ii = bmpLength; i < ii; i++) {
|
for (i = 0, ii = bmpLength; i < ii; i++) {
|
||||||
range = ranges[i];
|
range = ranges[i];
|
||||||
@ -2864,9 +2864,9 @@ var Font = (function FontClosure() {
|
|||||||
function readTableEntry(file) {
|
function readTableEntry(file) {
|
||||||
var tag = bytesToString(file.getBytes(4));
|
var tag = bytesToString(file.getBytes(4));
|
||||||
|
|
||||||
var checksum = file.getUint32();
|
var checksum = file.getInt32();
|
||||||
var offset = file.getUint32();
|
var offset = file.getInt32() >>> 0;
|
||||||
var length = file.getUint32();
|
var length = file.getInt32() >>> 0;
|
||||||
|
|
||||||
// Read the table associated data
|
// Read the table associated data
|
||||||
var previousPosition = file.pos;
|
var previousPosition = file.pos;
|
||||||
@ -2923,7 +2923,7 @@ var Font = (function FontClosure() {
|
|||||||
for (var i = 0; i < numTables; i++) {
|
for (var i = 0; i < numTables; i++) {
|
||||||
var platformId = font.getUint16();
|
var platformId = font.getUint16();
|
||||||
var encodingId = font.getUint16();
|
var encodingId = font.getUint16();
|
||||||
var offset = font.getUint32();
|
var offset = font.getInt32() >>> 0;
|
||||||
var useTable = false;
|
var useTable = false;
|
||||||
|
|
||||||
if (platformId == 1 && encodingId === 0) {
|
if (platformId == 1 && encodingId === 0) {
|
||||||
@ -3333,7 +3333,7 @@ var Font = (function FontClosure() {
|
|||||||
font.pos = start;
|
font.pos = start;
|
||||||
|
|
||||||
var length = post.length, end = start + length;
|
var length = post.length, end = start + length;
|
||||||
var version = font.getUint32();
|
var version = font.getInt32();
|
||||||
// skip rest to the tables
|
// skip rest to the tables
|
||||||
font.getBytes(28);
|
font.getBytes(28);
|
||||||
|
|
||||||
@ -3739,7 +3739,7 @@ var Font = (function FontClosure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
font.pos = (font.start || 0) + tables.maxp.offset;
|
font.pos = (font.start || 0) + tables.maxp.offset;
|
||||||
var version = font.getUint32();
|
var version = font.getInt32();
|
||||||
var numGlyphs = font.getUint16();
|
var numGlyphs = font.getUint16();
|
||||||
var maxFunctionDefs = 0;
|
var maxFunctionDefs = 0;
|
||||||
if (version >= 0x00010000 && tables.maxp.length >= 22) {
|
if (version >= 0x00010000 && tables.maxp.length >= 22) {
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
/* globals ArithmeticDecoder, error, shadow */
|
/* globals ArithmeticDecoder, error, log2, readInt8, readUint16, readUint32,
|
||||||
|
shadow */
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
@ -188,33 +189,6 @@ var Jbig2Image = (function Jbig2ImageClosure() {
|
|||||||
0x0008 // '0000' + '001000'
|
0x0008 // '0000' + '001000'
|
||||||
];
|
];
|
||||||
|
|
||||||
function log2(x) {
|
|
||||||
var n = 1, i = 0;
|
|
||||||
while (x > n) {
|
|
||||||
n <<= 1;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
function readInt32(data, start) {
|
|
||||||
return (data[start] << 24) | (data[start + 1] << 16) |
|
|
||||||
(data[start + 2] << 8) | data[start + 3];
|
|
||||||
}
|
|
||||||
|
|
||||||
function readUint32(data, start) {
|
|
||||||
var value = readInt32(data, start);
|
|
||||||
return value & 0x80000000 ? (value + 4294967296) : value;
|
|
||||||
}
|
|
||||||
|
|
||||||
function readUint16(data, start) {
|
|
||||||
return (data[start] << 8) | data[start + 1];
|
|
||||||
}
|
|
||||||
|
|
||||||
function readInt8(data, start) {
|
|
||||||
return (data[start] << 24) >> 24;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 6.2 Generic Region Decoding Procedure
|
// 6.2 Generic Region Decoding Procedure
|
||||||
function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at,
|
function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at,
|
||||||
decodingContext) {
|
decodingContext) {
|
||||||
@ -645,7 +619,7 @@ var Jbig2Image = (function Jbig2ImageClosure() {
|
|||||||
var retainBits = [referredFlags & 31];
|
var retainBits = [referredFlags & 31];
|
||||||
var position = start + 6;
|
var position = start + 6;
|
||||||
if (referredFlags == 7) {
|
if (referredFlags == 7) {
|
||||||
referredToCount = readInt32(data, position - 1) & 0x1FFFFFFF;
|
referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
|
||||||
position += 3;
|
position += 3;
|
||||||
var bytes = (referredToCount + 7) >> 3;
|
var bytes = (referredToCount + 7) >> 3;
|
||||||
retainBits[0] = data[position++];
|
retainBits[0] = data[position++];
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
/* globals ArithmeticDecoder, error, globalScope, warn */
|
/* globals ArithmeticDecoder, error, globalScope, log2, readUint16, readUint32,
|
||||||
|
warn */
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
@ -45,15 +46,8 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
xhr.send(null);
|
xhr.send(null);
|
||||||
},
|
},
|
||||||
parse: function JpxImage_parse(data) {
|
parse: function JpxImage_parse(data) {
|
||||||
function readUint(data, offset, bytes) {
|
|
||||||
var n = 0;
|
|
||||||
for (var i = 0; i < bytes; i++) {
|
|
||||||
n = n * 256 + (data[offset + i] & 0xFF);
|
|
||||||
}
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
var head = readUint(data, 0, 2);
|
var head = readUint16(data, 0);
|
||||||
// No box header, immediate start of codestream (SOC)
|
// No box header, immediate start of codestream (SOC)
|
||||||
if (head === 0xFF4F) {
|
if (head === 0xFF4F) {
|
||||||
this.parseCodestream(data, 0, data.length);
|
this.parseCodestream(data, 0, data.length);
|
||||||
@ -63,11 +57,14 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
var position = 0, length = data.length;
|
var position = 0, length = data.length;
|
||||||
while (position < length) {
|
while (position < length) {
|
||||||
var headerSize = 8;
|
var headerSize = 8;
|
||||||
var lbox = readUint(data, position, 4);
|
var lbox = readUint32(data, position);
|
||||||
var tbox = readUint(data, position + 4, 4);
|
var tbox = readUint32(data, position + 4);
|
||||||
position += headerSize;
|
position += headerSize;
|
||||||
if (lbox == 1) {
|
if (lbox === 1) {
|
||||||
lbox = readUint(data, position, 8);
|
// XLBox: read UInt64 according to spec.
|
||||||
|
// JavaScript's int precision of 53 bit should be sufficient here.
|
||||||
|
lbox = readUint32(data, position) * 4294967296 +
|
||||||
|
readUint32(data, position + 4);
|
||||||
position += 8;
|
position += 8;
|
||||||
headerSize += 8;
|
headerSize += 8;
|
||||||
}
|
}
|
||||||
@ -108,16 +105,16 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
// Image and tile size (SIZ)
|
// Image and tile size (SIZ)
|
||||||
if (code == 0xFF51) {
|
if (code == 0xFF51) {
|
||||||
stream.skip(4);
|
stream.skip(4);
|
||||||
var Xsiz = stream.getUint32(); // Byte 4
|
var Xsiz = stream.getInt32() >>> 0; // Byte 4
|
||||||
var Ysiz = stream.getUint32(); // Byte 8
|
var Ysiz = stream.getInt32() >>> 0; // Byte 8
|
||||||
var XOsiz = stream.getUint32(); // Byte 12
|
var XOsiz = stream.getInt32() >>> 0; // Byte 12
|
||||||
var YOsiz = stream.getUint32(); // Byte 16
|
var YOsiz = stream.getInt32() >>> 0; // Byte 16
|
||||||
stream.skip(16);
|
stream.skip(16);
|
||||||
var Csiz = stream.getUint16(); // Byte 36
|
var Csiz = stream.getUint16(); // Byte 36
|
||||||
this.width = Xsiz - XOsiz;
|
this.width = Xsiz - XOsiz;
|
||||||
this.height = Ysiz - YOsiz;
|
this.height = Ysiz - YOsiz;
|
||||||
this.componentsCount = Csiz;
|
this.componentsCount = Csiz;
|
||||||
// Results are always returned as UInt8Arrays
|
// Results are always returned as Uint8Arrays
|
||||||
this.bitsPerComponent = 8;
|
this.bitsPerComponent = 8;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -379,21 +376,6 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
this.componentsCount = context.SIZ.Csiz;
|
this.componentsCount = context.SIZ.Csiz;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
function readUint32(data, offset) {
|
|
||||||
return (data[offset] << 24) | (data[offset + 1] << 16) |
|
|
||||||
(data[offset + 2] << 8) | data[offset + 3];
|
|
||||||
}
|
|
||||||
function readUint16(data, offset) {
|
|
||||||
return (data[offset] << 8) | data[offset + 1];
|
|
||||||
}
|
|
||||||
function log2(x) {
|
|
||||||
var n = 1, i = 0;
|
|
||||||
while (x > n) {
|
|
||||||
n <<= 1;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
function calculateComponentDimensions(component, siz) {
|
function calculateComponentDimensions(component, siz) {
|
||||||
// Section B.2 Component mapping
|
// Section B.2 Component mapping
|
||||||
component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
|
component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
|
||||||
|
@ -46,7 +46,7 @@ var Stream = (function StreamClosure() {
|
|||||||
var b1 = this.getByte();
|
var b1 = this.getByte();
|
||||||
return (b0 << 8) + b1;
|
return (b0 << 8) + b1;
|
||||||
},
|
},
|
||||||
getUint32: function Stream_getUint32() {
|
getInt32: function Stream_getInt32() {
|
||||||
var b0 = this.getByte();
|
var b0 = this.getByte();
|
||||||
var b1 = this.getByte();
|
var b1 = this.getByte();
|
||||||
var b2 = this.getByte();
|
var b2 = this.getByte();
|
||||||
@ -164,7 +164,7 @@ var DecodeStream = (function DecodeStreamClosure() {
|
|||||||
var b1 = this.getByte();
|
var b1 = this.getByte();
|
||||||
return (b0 << 8) + b1;
|
return (b0 << 8) + b1;
|
||||||
},
|
},
|
||||||
getUint32: function DecodeStream_getUint32() {
|
getInt32: function DecodeStream_getInt32() {
|
||||||
var b0 = this.getByte();
|
var b0 = this.getByte();
|
||||||
var b1 = this.getByte();
|
var b1 = this.getByte();
|
||||||
var b2 = this.getByte();
|
var b2 = this.getByte();
|
||||||
|
@ -423,6 +423,28 @@ function string32(value) {
|
|||||||
(value >> 8) & 0xff, value & 0xff);
|
(value >> 8) & 0xff, value & 0xff);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function log2(x) {
|
||||||
|
var n = 1, i = 0;
|
||||||
|
while (x > n) {
|
||||||
|
n <<= 1;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
function readInt8(data, start) {
|
||||||
|
return (data[start] << 24) >> 24;
|
||||||
|
}
|
||||||
|
|
||||||
|
function readUint16(data, offset) {
|
||||||
|
return (data[offset] << 8) | data[offset + 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
function readUint32(data, offset) {
|
||||||
|
return ((data[offset] << 24) | (data[offset + 1] << 16) |
|
||||||
|
(data[offset + 2] << 8) | data[offset + 3]) >>> 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Lazy test the endianness of the platform
|
// Lazy test the endianness of the platform
|
||||||
// NOTE: This will be 'true' for simulated TypedArrays
|
// NOTE: This will be 'true' for simulated TypedArrays
|
||||||
function isLittleEndian() {
|
function isLittleEndian() {
|
||||||
|
Loading…
Reference in New Issue
Block a user