 				while (remain--) {
 					vlcs.push(new VlcCode());
 				}
-            }
-            if (ctx.length) { throw new Error(RESULT_SYNTAX_ERROR); }
-        }
+			}
+			if (ctx.length) { throw new Error(RESULT_SYNTAX_ERROR); }
+		}
 
 		
 		private function _DecodeDQT():void {

		
		
		private function _UpsampleH(c:Component):void {
            const xmax:int = c.width - 3;
            var x:int, y:int;
            var org:ByteArray = c.pixels;
			var out:ByteArray = new ByteArray();
			out.length = ((c.width * c.height) << 1) * 4;
			var iorg:int = 0;
            var iout:int = 0;
            for (y = c.height;  y;  --y) {
                out[iout + 0] = CF(CF2A * org[iorg + 0] + CF2B * org[iorg + 1]);
				out[iout + 1] = CF(CF3X * org[iorg + 0] + CF3Y * org[iorg + 1] + CF3Z * org[iorg + 2]);
                out[iout + 2] = CF(CF3A * org[iorg + 0] + CF3B * org[iorg + 1] + CF3C * org[iorg + 2]);
                for (x = 0;  x < xmax;  ++x) {
                    out[iout + (x << 1) + 3] = CF(CF4A * org[iorg + x] + CF4B * org[iorg + x + 1] + CF4C * org[iorg + x + 2] + CF4D * org[iorg + x + 3]);
                    out[iout + (x << 1) + 4] = CF(CF4D * org[iorg + x] + CF4C * org[iorg + x + 1] + CF4B * org[iorg + x + 2] + CF4A * org[iorg + x + 3]);
                }
				iorg += c.stride;
				iout += c.width << 1;
                out[iout - 3] = CF(CF3A * org[iorg - 1] + CF3B * org[iorg - 2] + CF3C * org[iorg - 3]);
                out[iout - 2] = CF(CF3X * org[iorg - 1] + CF3Y * org[iorg - 2] + CF3Z * org[iorg - 3]);
                out[iout - 1] = CF(CF2A * org[iorg - 1] + CF2B * org[iorg - 2]);
            }
            c.width <<= 1;
            c.stride = c.width;
            c.pixels = out;
		}

		

		private static const W7:int = 565;
		
		private function _RowIDCT(blk:Vector.<int>, offset:int):void {
			var x0:int, x1:int, x2:int, x3:int, x4:int, x5:int, x6:int, x7:int, x8:int;
			var i0:int = offset;
			var i1:int = offset + 1;
			var i2:int = offset + 2;
			var i3:int = offset + 3;
			var i4:int = offset + 4;
			var i5:int = offset + 5;
			var i6:int = offset + 6;
			var i7:int = offset + 7;
			if (!((x1 = blk[i4] << 11)
				| (x2 = blk[i6])
				| (x3 = blk[i2])
				| (x4 = blk[i1])
				| (x5 = blk[i7])
				| (x6 = blk[i5])
				| (x7 = blk[i3])))
			{
				blk[i0] = blk[i1] = blk[i2] = blk[i3] = blk[i4] = blk[i5] = blk[i6] = blk[i7] = blk[i0] << 3;
				return;
			}
			x0 = (blk[i0] << 11) + 128;
			x8 = W7 * (x4 + x5);
			x4 = x8 + (W1 - W7) * x4;
			x5 = x8 - (W1 + W7) * x5;
			x8 = W3 * (x6 + x7);
			x6 = x8 - (W3 - W5) * x6;
			x7 = x8 - (W3 + W5) * x7;
			x8 = x0 + x1;
			x0 -= x1;
			x1 = W6 * (x3 + x2);
			x2 = x1 - (W2 + W6) * x2;
			x3 = x1 + (W2 - W6) * x3;
			x1 = x4 + x6;
			x4 -= x6;
			x6 = x5 + x7;
			x5 -= x7;
			x7 = x8 + x3;
			x8 -= x3;
			x3 = x0 + x2;
			x0 -= x2;
			x2 = (181 * (x4 + x5) + 128) >> 8;
			x4 = (181 * (x4 - x5) + 128) >> 8;
			blk[i0] = (x7 + x1) >> 8;
			blk[i1] = (x3 + x2) >> 8;
			blk[i2] = (x0 + x4) >> 8;
			blk[i3] = (x8 + x6) >> 8;
			blk[i4] = (x8 - x6) >> 8;
			blk[i5] = (x0 - x4) >> 8;
			blk[i6] = (x3 - x2) >> 8;
			blk[i7] = (x7 - x1) >> 8;
		}

		
		private function _ColIDCT(blk:Vector.<int>, out:ByteArray, offset:int, stride:int):void {
			var x0:int, x1:int, x2:int, x3:int, x4:int, x5:int, x6:int, x7:int, x8:int;
			var p:int = out.position + offset;
			if (!((x1 = blk[8*4+offset] << 8)
				| (x2 = blk[8*6+offset])
				| (x3 = blk[8*2+offset])
				| (x4 = blk[8*1+offset])
				| (x5 = blk[8*7+offset])
				| (x6 = blk[8*5+offset])
				| (x7 = blk[8*3+offset])))
			{
				x1 = _Clip(((blk[offset] + 32) >> 6) + 128);
				for (x0 = 8;  x0;  --x0) {
					out[p] = x1;
					p += stride;
				}
				return;
			}
			x0 = (blk[offset] << 8) + 8192;
			x8 = W7 * (x4 + x5) + 4;
			x4 = (x8 + (W1 - W7) * x4) >> 3;
			x5 = (x8 - (W1 + W7) * x5) >> 3;
			x8 = W3 * (x6 + x7) + 4;
			x6 = (x8 - (W3 - W5) * x6) >> 3;
			x7 = (x8 - (W3 + W5) * x7) >> 3;
			x8 = x0 + x1;
			x0 -= x1;
			x1 = W6 * (x3 + x2) + 4;
			x2 = (x1 - (W2 + W6) * x2) >> 3;
			x3 = (x1 + (W2 - W6) * x3) >> 3;
			x1 = x4 + x6;
			x4 -= x6;
			x6 = x5 + x7;
			x5 -= x7;
			x7 = x8 + x3;
			x8 -= x3;
			x3 = x0 + x2;
			x0 -= x2;
			x2 = (181 * (x4 + x5) + 128) >> 8;
			x4 = (181 * (x4 - x5) + 128) >> 8;
			out[p] = _Clip(((x7 + x1) >> 14) + 128); p += stride;
			out[p] = _Clip(((x3 + x2) >> 14) + 128); p += stride;
			out[p] = _Clip(((x0 + x4) >> 14) + 128); p += stride;
			out[p] = _Clip(((x8 + x6) >> 14) + 128); p += stride;
			out[p] = _Clip(((x8 - x6) >> 14) + 128); p += stride;
			out[p] = _Clip(((x0 - x4) >> 14) + 128); p += stride;
			out[p] = _Clip(((x3 - x2) >> 14) + 128); p += stride;
			out[p] = _Clip(((x7 - x1) >> 14) + 128);		
		}

		
		private function _Convert():void {
			var i:int;
			var c:Component;
			for (i = 0;	 i < ctx.ncomp;	 ++i) {
				c = ctx.comp[i];
				while ((c.width < ctx.width) || (c.height < ctx.height)) {
					if (c.height < ctx.height) _UpsampleV(c);
					if (c.width < ctx.width) _UpsampleH(c);
				}
				if ((c.width < ctx.width) || (c.height < ctx.height)) { throw new Error(RESULT_INTERNAL_ERROR); }
			}
			if (ctx.ncomp == 3) {
				// convert to RGB
				var x:int, yy:int;
				const prgb:ByteArray = ctx.rgb;
				const py:ByteArray	= ctx.comp[0].pixels;
				const pcb:ByteArray = ctx.comp[1].pixels;
				const pcr:ByteArray = ctx.comp[2].pixels;
				var iprgb:int = 0;
				var ipy:int = 0;
				var ipcb:int = 0;
				var ipcr:int = 0;
				for (yy = ctx.height;  yy;	--yy) {
					for (x = 0;	 x < ctx.width;	 ++x) {
						var y:int = py[ipy + x] << 8;
						var cb:int = pcb[ipcb + x] - 128;
						var cr:int = pcr[ipcr + x] - 128;
						prgb[iprgb++] = 255; // alpha
						prgb[iprgb++] = _Clip((y			+ 359 * cr + 128) >> 8); // red
						prgb[iprgb++] = _Clip((y -	88 * cb - 183 * cr + 128) >> 8); // green
						prgb[iprgb++] = _Clip((y + 454 * cb			   + 128) >> 8); // blue
					}
					ipy += ctx.comp[0].stride;
					ipcb += ctx.comp[1].stride;
