From 48e115cf30f7217d5d2296330721839fafd7ca41 Mon Sep 17 00:00:00 2001 From: Yury Delendik Date: Mon, 9 Jul 2012 13:59:50 -0500 Subject: [PATCH] Implements segmentation symbol check for JPX --- src/jpx.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/jpx.js b/src/jpx.js index 63193753d..fdf41f48b 100644 --- a/src/jpx.js +++ b/src/jpx.js @@ -254,8 +254,7 @@ var JpxImage = (function JpxImageClosure() { cod.selectiveArithmeticCodingBypass || cod.resetContextProbabilities || cod.terminationOnEachCodingPass || - cod.verticalyStripe || cod.predictableTermination || - cod.segmentationSymbolUsed) + cod.verticalyStripe || cod.predictableTermination) throw 'Unsupported COD options: ' + uneval(cod); if (context.mainHeader) @@ -832,7 +831,8 @@ var JpxImage = (function JpxImageClosure() { return position; } function copyCoefficients(coefficients, x0, y0, width, height, - delta, mb, codeblocks, transformation) { + delta, mb, codeblocks, transformation, + segmentationSymbolUsed) { var r = 0.5; // formula (E-6) for (var i = 0, ii = codeblocks.length; i < ii; ++i) { var codeblock = codeblocks[i]; @@ -876,6 +876,8 @@ var JpxImage = (function JpxImageClosure() { break; case 2: bitModel.runCleanupPass(); + if (segmentationSymbolUsed) + bitModel.checkSegmentationSymbol(); break; } currentCodingpassType = (currentCodingpassType + 1) % 3; @@ -912,6 +914,7 @@ var JpxImage = (function JpxImageClosure() { var scalarExpounded = quantizationParameters.scalarExpounded; var guardBits = quantizationParameters.guardBits; var transformation = codingStyleParameters.transformation; + var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed; var precision = context.components[c].precision; var subbandCoefficients = []; @@ -942,7 +945,8 @@ var JpxImage = (function JpxImageClosure() { var coefficients = new Float32Array(width * height); copyCoefficients(coefficients, subband.tbx0, subband.tby0, - width, height, delta, mb, subband.codeblocks, transformation); + width, height, delta, mb, subband.codeblocks, transformation, + segmentationSymbolUsed); subbandCoefficients.push({ width: width, @@ -1645,6 +1649,14 @@ var JpxImage = (function JpxImageClosure() { } } } + }, + checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() { + var decoder = this.decoder; + var cx = this.uniformContext; + var symbol = (decoder.readBit(cx) << 3) | (decoder.readBit(cx) << 2) | + (decoder.readBit(cx) << 1) | decoder.readBit(cx); + if (symbol != 0xA) + throw 'Invalid segmentation symbol'; } };