Merge pull request #4636 from fkaelberer/issue4553

Rename getUint32 to getInt32 and collect readInt*() in util.js
This commit is contained in:
Yury Delendik 2014-04-16 16:44:42 -05:00
commit eb554a8756
6 changed files with 50 additions and 72 deletions

View File

@ -148,7 +148,7 @@ var ChunkedStream = (function ChunkedStreamClosure() {
return (b0 << 8) + b1;
},
getUint32: function ChunkedStream_getUint32() {
getInt32: function ChunkedStream_getInt32() {
var b0 = this.getByte();
var b1 = this.getByte();
var b2 = this.getByte();

View File

@ -2540,7 +2540,7 @@ var Font = (function FontClosure() {
var idRangeOffsets = '';
var glyphsIds = '';
var bias = 0;
var range, start, end, codes;
for (i = 0, ii = bmpLength; i < ii; i++) {
range = ranges[i];
@ -2864,9 +2864,9 @@ var Font = (function FontClosure() {
function readTableEntry(file) {
var tag = bytesToString(file.getBytes(4));
var checksum = file.getUint32();
var offset = file.getUint32();
var length = file.getUint32();
var checksum = file.getInt32();
var offset = file.getInt32() >>> 0;
var length = file.getInt32() >>> 0;
// Read the table associated data
var previousPosition = file.pos;
@ -2923,7 +2923,7 @@ var Font = (function FontClosure() {
for (var i = 0; i < numTables; i++) {
var platformId = font.getUint16();
var encodingId = font.getUint16();
var offset = font.getUint32();
var offset = font.getInt32() >>> 0;
var useTable = false;
if (platformId == 1 && encodingId === 0) {
@ -3333,7 +3333,7 @@ var Font = (function FontClosure() {
font.pos = start;
var length = post.length, end = start + length;
var version = font.getUint32();
var version = font.getInt32();
// skip rest to the tables
font.getBytes(28);
@ -3739,7 +3739,7 @@ var Font = (function FontClosure() {
}
font.pos = (font.start || 0) + tables.maxp.offset;
var version = font.getUint32();
var version = font.getInt32();
var numGlyphs = font.getUint16();
var maxFunctionDefs = 0;
if (version >= 0x00010000 && tables.maxp.length >= 22) {

View File

@ -14,7 +14,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* globals ArithmeticDecoder, error, shadow */
/* globals ArithmeticDecoder, error, log2, readInt8, readUint16, readUint32,
shadow */
'use strict';
@ -188,33 +189,6 @@ var Jbig2Image = (function Jbig2ImageClosure() {
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
function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at,
decodingContext) {
@ -645,7 +619,7 @@ var Jbig2Image = (function Jbig2ImageClosure() {
var retainBits = [referredFlags & 31];
var position = start + 6;
if (referredFlags == 7) {
referredToCount = readInt32(data, position - 1) & 0x1FFFFFFF;
referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
position += 3;
var bytes = (referredToCount + 7) >> 3;
retainBits[0] = data[position++];

View File

@ -14,7 +14,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* globals ArithmeticDecoder, error, globalScope, warn */
/* globals ArithmeticDecoder, error, globalScope, log2, readUint16, readUint32,
warn */
'use strict';
@ -45,15 +46,8 @@ var JpxImage = (function JpxImageClosure() {
xhr.send(null);
},
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)
if (head === 0xFF4F) {
this.parseCodestream(data, 0, data.length);
@ -63,11 +57,14 @@ var JpxImage = (function JpxImageClosure() {
var position = 0, length = data.length;
while (position < length) {
var headerSize = 8;
var lbox = readUint(data, position, 4);
var tbox = readUint(data, position + 4, 4);
var lbox = readUint32(data, position);
var tbox = readUint32(data, position + 4);
position += headerSize;
if (lbox == 1) {
lbox = readUint(data, position, 8);
if (lbox === 1) {
// 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;
headerSize += 8;
}
@ -108,16 +105,16 @@ var JpxImage = (function JpxImageClosure() {
// Image and tile size (SIZ)
if (code == 0xFF51) {
stream.skip(4);
var Xsiz = stream.getUint32(); // Byte 4
var Ysiz = stream.getUint32(); // Byte 8
var XOsiz = stream.getUint32(); // Byte 12
var YOsiz = stream.getUint32(); // Byte 16
var Xsiz = stream.getInt32() >>> 0; // Byte 4
var Ysiz = stream.getInt32() >>> 0; // Byte 8
var XOsiz = stream.getInt32() >>> 0; // Byte 12
var YOsiz = stream.getInt32() >>> 0; // Byte 16
stream.skip(16);
var Csiz = stream.getUint16(); // Byte 36
this.width = Xsiz - XOsiz;
this.height = Ysiz - YOsiz;
this.componentsCount = Csiz;
// Results are always returned as UInt8Arrays
// Results are always returned as Uint8Arrays
this.bitsPerComponent = 8;
return;
}
@ -379,21 +376,6 @@ var JpxImage = (function JpxImageClosure() {
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) {
// Section B.2 Component mapping
component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);

View File

@ -46,7 +46,7 @@ var Stream = (function StreamClosure() {
var b1 = this.getByte();
return (b0 << 8) + b1;
},
getUint32: function Stream_getUint32() {
getInt32: function Stream_getInt32() {
var b0 = this.getByte();
var b1 = this.getByte();
var b2 = this.getByte();
@ -164,7 +164,7 @@ var DecodeStream = (function DecodeStreamClosure() {
var b1 = this.getByte();
return (b0 << 8) + b1;
},
getUint32: function DecodeStream_getUint32() {
getInt32: function DecodeStream_getInt32() {
var b0 = this.getByte();
var b1 = this.getByte();
var b2 = this.getByte();

View File

@ -423,6 +423,28 @@ function string32(value) {
(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
// NOTE: This will be 'true' for simulated TypedArrays
function isLittleEndian() {