Skip to content

Commit

Permalink
Fix the issue that component.quantizationTable is undefined when 'Sta…
Browse files Browse the repository at this point in the history
…rt of Frame' section appears before 'DQT' section in the header. notmasteryet#34
  • Loading branch information
thorikawa committed Feb 19, 2015
1 parent 8e6f346 commit 4fb5029
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions jpg.js
Original file line number Diff line number Diff line change
Expand Up @@ -667,20 +667,22 @@ var JpegImage = (function jpegImage() {
var quantizationTablesEnd = quantizationTablesLength + offset - 2;
while (offset < quantizationTablesEnd) {
var quantizationTableSpec = data[offset++];
var tableData = new Int32Array(64);
var qId = quantizationTableSpec & 15;
if (!quantizationTables[qId]) {
quantizationTables[qId] = new Int32Array(64);
}
if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
for (j = 0; j < 64; j++) {
var z = dctZigZag[j];
tableData[z] = data[offset++];
quantizationTables[qId][z] = data[offset++];
}
} else if ((quantizationTableSpec >> 4) === 1) { //16 bit
for (j = 0; j < 64; j++) {
var z = dctZigZag[j];
tableData[z] = readUint16();
quantizationTables[qId][z] = readUint16();
}
} else
throw "DQT: invalid table spec";
quantizationTables[quantizationTableSpec & 15] = tableData;
}
break;

Expand Down Expand Up @@ -708,6 +710,8 @@ var JpegImage = (function jpegImage() {
if (maxH < h) maxH = h;
if (maxV < v) maxV = v;
var qId = data[offset + 2];
if (!quantizationTables) quantizationTables = {};
if (!quantizationTables[qId]) quantizationTables[qId] = new Int32Array(64);
var l = frame.components.push({
h: h,
v: v,
Expand Down

0 comments on commit 4fb5029

Please sign in to comment.