package org.jnbis.internal; import java.util.Arrays; import org.bouncycastle.crypto.tls.CipherSuite; import org.jnbis.Bitmap; import org.jnbis.internal.WsqHelper; /* loaded from: classes6.dex */ public class InternalWsqDecoder { private int getCPpiWSQ() { return -1; } private int intSign(int i) { if (i == 0) { return 1; } int i2 = -1; for (int i3 = 1; i3 < i; i3++) { i2 = -i2; } return i2; } public Bitmap decode(byte[] bArr) { WsqHelper.Token token = new WsqHelper.Token(bArr); token.initialize(); getCMarkerWSQ(token, 65440); int cMarkerWSQ = getCMarkerWSQ(token, 2); while (cMarkerWSQ != 65442) { getCTableWSQ(token, cMarkerWSQ); cMarkerWSQ = getCMarkerWSQ(token, 2); } WsqHelper.HeaderFrm cFrameHeaderWSQ = getCFrameHeaderWSQ(token); int i = cFrameHeaderWSQ.width; int i2 = cFrameHeaderWSQ.height; int cPpiWSQ = getCPpiWSQ(); buildWSQTrees(token, i, i2); float[] unquantize = unquantize(token, huffmanDecodeDataMem(token, i * i2), i, i2); wsqReconstruct(token, unquantize, i, i2); return new Bitmap(convertImage2Byte(unquantize, i, i2, cFrameHeaderWSQ.mShift, cFrameHeaderWSQ.rScale), i, i2, cPpiWSQ, 8, 1); } private int getCMarkerWSQ(WsqHelper.Token token, int i) { if (token.pointer >= token.buffer.length) { StringBuilder sb = new StringBuilder("Error, Invalid pointer : "); sb.append(token.pointer); throw new RuntimeException(sb.toString()); } int readShort = token.readShort(); if (i == 2) { if (readShort == 65444 || readShort == 65445 || readShort == 65446 || readShort == 65442 || readShort == 65448) { return readShort; } throw new RuntimeException("ERROR : getc_marker_wsq : No SOF, Table, or comment markers : ".concat(String.valueOf(readShort))); } if (i == 4) { if (readShort == 65444 || readShort == 65445 || readShort == 65446 || readShort == 65443 || readShort == 65448) { return readShort; } throw new RuntimeException("ERROR : getc_marker_wsq : No SOB, Table, or comment markers : ".concat(String.valueOf(readShort))); } if (i == 65440) { if (readShort == 65440) { return readShort; } throw new RuntimeException("ERROR : getCMarkerWSQ : No SOI marker : ".concat(String.valueOf(readShort))); } if (i != 65535) { throw new RuntimeException("ERROR : getc_marker_wsq : Invalid marker : ".concat(String.valueOf(readShort))); } if ((readShort & CipherSuite.DRAFT_TLS_DHE_RSA_WITH_AES_128_OCB) != 65280) { throw new RuntimeException("ERROR : getc_marker_wsq : no marker found : ".concat(String.valueOf(readShort))); } if (readShort < 65440 || readShort > 65448) { throw new RuntimeException("ERROR : getc_marker_wsq : not a valid marker : ".concat(String.valueOf(readShort))); } return readShort; } private void getCTableWSQ(WsqHelper.Token token, int i) { switch (i) { case 65444: getCTransformTable(token); return; case 65445: getCQuantizationTable(token); return; case 65446: getCHuffmanTableWSQ(token); return; case 65447: default: throw new RuntimeException("ERROR: getCTableWSQ : Invalid table defined : ".concat(String.valueOf(i))); case 65448: getCComment(token); return; } } private String getCComment(WsqHelper.Token token) { return Arrays.toString(token.readBytes(token.readShort() - 2)); } private void getCTransformTable(WsqHelper.Token token) { int i; int i2; token.readShort(); token.tableDTT.hisz = token.readByte(); token.tableDTT.losz = token.readByte(); token.tableDTT.hifilt = new float[token.tableDTT.hisz]; token.tableDTT.lofilt = new float[token.tableDTT.losz]; if (token.tableDTT.hisz % 2 != 0) { i = (token.tableDTT.hisz + 1) / 2; } else { i = token.tableDTT.hisz / 2; } float[] fArr = new float[i]; int i3 = i - 1; for (int i4 = 0; i4 <= i3; i4++) { int readByte = token.readByte(); fArr[i4] = (float) token.readInt(); for (int readByte2 = token.readByte(); readByte2 > 0; readByte2--) { fArr[i4] = (float) (fArr[i4] / 10.0d); } if (readByte != 0) { fArr[i4] = (float) (-fArr[i4]); } if (token.tableDTT.hisz % 2 != 0) { int i5 = i4 + i3; token.tableDTT.hifilt[i5] = intSign(i4) * fArr[i4]; if (i4 > 0) { token.tableDTT.hifilt[i3 - i4] = token.tableDTT.hifilt[i5]; } } else { int i6 = i4 + i3 + 1; token.tableDTT.hifilt[i6] = intSign(i4) * fArr[i4]; token.tableDTT.hifilt[i3 - i4] = -token.tableDTT.hifilt[i6]; } } if (token.tableDTT.losz % 2 != 0) { i2 = (token.tableDTT.losz + 1) / 2; } else { i2 = token.tableDTT.losz / 2; } float[] fArr2 = new float[i2]; int i7 = i2 - 1; for (int i8 = 0; i8 <= i7; i8++) { int readByte3 = token.readByte(); fArr2[i8] = (float) token.readInt(); for (int readByte4 = token.readByte(); readByte4 > 0; readByte4--) { fArr2[i8] = (float) (fArr2[i8] / 10.0d); } if (readByte3 != 0) { fArr2[i8] = (float) (-fArr2[i8]); } if (token.tableDTT.losz % 2 != 0) { int i9 = i8 + i7; token.tableDTT.lofilt[i9] = intSign(i8) * fArr2[i8]; if (i8 > 0) { token.tableDTT.lofilt[i7 - i8] = token.tableDTT.lofilt[i9]; } } else { int i10 = i8 + i7 + 1; token.tableDTT.lofilt[i10] = intSign(i8 + 1) * fArr2[i8]; token.tableDTT.lofilt[i7 - i8] = token.tableDTT.lofilt[i10]; } } token.tableDTT.lodef = 1; token.tableDTT.hidef = 1; } public void getCQuantizationTable(WsqHelper.Token token) { token.readShort(); token.tableDQT.binCenter = token.readShort(); for (int readByte = token.readByte(); readByte > 0; readByte--) { token.tableDQT.binCenter = (float) (r3.binCenter / 10.0d); } for (int i = 0; i < 64; i++) { token.tableDQT.qBin[i] = token.readShort(); for (int readByte2 = token.readByte(); readByte2 > 0; readByte2--) { token.tableDQT.qBin[i] = (float) (r4[i] / 10.0d); } token.tableDQT.zBin[i] = token.readShort(); for (int readByte3 = token.readByte(); readByte3 > 0; readByte3--) { token.tableDQT.zBin[i] = (float) (r4[i] / 10.0d); } } token.tableDQT.dqtDef = (char) 1; } public void getCHuffmanTableWSQ(WsqHelper.Token token) { WsqHelper.HuffmanTable cHuffmanTable = getCHuffmanTable(token, 256, 0, true); int i = cHuffmanTable.tableId; token.tableDHT[i].huffbits = (int[]) cHuffmanTable.huffbits.clone(); token.tableDHT[i].huffvalues = (int[]) cHuffmanTable.huffvalues.clone(); token.tableDHT[i].tabdef = (byte) 1; int i2 = cHuffmanTable.bytesLeft; while (i2 != 0) { WsqHelper.HuffmanTable cHuffmanTable2 = getCHuffmanTable(token, 256, i2, false); int i3 = cHuffmanTable2.tableId; if (token.tableDHT[i3].tabdef != 0) { throw new RuntimeException("ERROR : getCHuffmanTableWSQ : huffman table already defined."); } token.tableDHT[i3].huffbits = (int[]) cHuffmanTable2.huffbits.clone(); token.tableDHT[i3].huffvalues = (int[]) cHuffmanTable2.huffvalues.clone(); token.tableDHT[i3].tabdef = (byte) 1; i2 = cHuffmanTable2.bytesLeft; } } private WsqHelper.HuffmanTable getCHuffmanTable(WsqHelper.Token token, int i, int i2, boolean z) { WsqHelper.HuffmanTable huffmanTable = new WsqHelper.HuffmanTable(); if (z) { huffmanTable.tableLen = token.readShort(); huffmanTable.bytesLeft = huffmanTable.tableLen - 2; i2 = huffmanTable.bytesLeft; } else { huffmanTable.bytesLeft = i2; } if (i2 <= 0) { throw new RuntimeException("ERROR : getCHuffmanTable : no huffman table bytes remaining"); } huffmanTable.tableId = token.readByte(); huffmanTable.bytesLeft--; huffmanTable.huffbits = new int[16]; int i3 = 0; for (int i4 = 0; i4 < 16; i4++) { huffmanTable.huffbits[i4] = token.readByte(); i3 += huffmanTable.huffbits[i4]; } huffmanTable.bytesLeft -= 16; int i5 = i + 1; if (i3 > i5) { throw new RuntimeException("ERROR : getCHuffmanTable : numHufvals is larger than MAX_HUFFCOUNTS"); } huffmanTable.huffvalues = new int[i5]; for (int i6 = 0; i6 < i3; i6++) { huffmanTable.huffvalues[i6] = token.readByte(); } huffmanTable.bytesLeft -= i3; return huffmanTable; } private WsqHelper.HeaderFrm getCFrameHeaderWSQ(WsqHelper.Token token) { WsqHelper.HeaderFrm headerFrm = new WsqHelper.HeaderFrm(); token.readShort(); headerFrm.black = token.readByte(); headerFrm.white = token.readByte(); headerFrm.height = token.readShort(); headerFrm.width = token.readShort(); headerFrm.mShift = token.readShort(); for (int readByte = token.readByte(); readByte > 0; readByte--) { headerFrm.mShift = (float) (headerFrm.mShift / 10.0d); } headerFrm.rScale = token.readShort(); for (int readByte2 = token.readByte(); readByte2 > 0; readByte2--) { headerFrm.rScale = (float) (headerFrm.rScale / 10.0d); } headerFrm.wsqEncoder = token.readByte(); headerFrm.software = token.readShort(); return headerFrm; } private void buildWSQTrees(WsqHelper.Token token, int i, int i2) { buildWTree(token, 20, i, i2); buildQTree(token, 64); } private void buildWTree(WsqHelper.Token token, int i, int i2, int i3) { int i4; int i5; int i6; int i7; token.wtree = new WsqHelper.WavletTree[i]; for (int i8 = 0; i8 < i; i8++) { token.wtree[i8] = new WsqHelper.WavletTree(); token.wtree[i8].invrw = 0; token.wtree[i8].invcl = 0; } token.wtree[2].invrw = 1; token.wtree[4].invrw = 1; token.wtree[7].invrw = 1; token.wtree[9].invrw = 1; token.wtree[11].invrw = 1; token.wtree[13].invrw = 1; token.wtree[16].invrw = 1; token.wtree[18].invrw = 1; token.wtree[3].invcl = 1; token.wtree[5].invcl = 1; token.wtree[8].invcl = 1; token.wtree[9].invcl = 1; token.wtree[12].invcl = 1; token.wtree[13].invcl = 1; token.wtree[17].invcl = 1; token.wtree[18].invcl = 1; wtree4(token, 0, 1, i2, i3, 0, 0, 1); if (token.wtree[1].lenx % 2 == 0) { i5 = token.wtree[1].lenx / 2; i4 = i5; } else { int i9 = (token.wtree[1].lenx + 1) / 2; i4 = i9; i5 = i9 - 1; } if (token.wtree[1].leny % 2 == 0) { i6 = token.wtree[1].leny / 2; i7 = i6; } else { int i10 = (token.wtree[1].leny + 1) / 2; i6 = i10; i7 = i10 - 1; } wtree4(token, 4, 6, i5, i6, i4, 0, 0); int i11 = i4; wtree4(token, 5, 10, i11, i7, 0, i6, 0); wtree4(token, 14, 15, i11, i6, 0, 0, 0); token.wtree[19].x = 0; token.wtree[19].y = 0; if (token.wtree[15].lenx % 2 == 0) { token.wtree[19].lenx = token.wtree[15].lenx / 2; } else { token.wtree[19].lenx = (token.wtree[15].lenx + 1) / 2; } if (token.wtree[15].leny % 2 == 0) { token.wtree[19].leny = token.wtree[15].leny / 2; } else { token.wtree[19].leny = (token.wtree[15].leny + 1) / 2; } } private void wtree4(WsqHelper.Token token, int i, int i2, int i3, int i4, int i5, int i6, int i7) { token.wtree[i].x = i5; token.wtree[i].y = i6; token.wtree[i].lenx = i3; token.wtree[i].leny = i4; token.wtree[i2].x = i5; int i8 = i2 + 2; token.wtree[i8].x = i5; token.wtree[i2].y = i6; int i9 = i2 + 1; token.wtree[i9].y = i6; if (i3 % 2 == 0) { token.wtree[i2].lenx = i3 / 2; token.wtree[i9].lenx = token.wtree[i2].lenx; } else if (i == 4) { token.wtree[i2].lenx = (i3 - 1) / 2; token.wtree[i9].lenx = token.wtree[i2].lenx + 1; } else { token.wtree[i2].lenx = (i3 + 1) / 2; token.wtree[i9].lenx = token.wtree[i2].lenx - 1; } token.wtree[i9].x = token.wtree[i2].lenx + i5; if (i7 == 0) { int i10 = i2 + 3; token.wtree[i10].lenx = token.wtree[i9].lenx; token.wtree[i10].x = token.wtree[i9].x; } token.wtree[i8].lenx = token.wtree[i2].lenx; if (i4 % 2 == 0) { token.wtree[i2].leny = i4 / 2; token.wtree[i8].leny = token.wtree[i2].leny; } else if (i == 5) { token.wtree[i2].leny = (i4 - 1) / 2; token.wtree[i8].leny = token.wtree[i2].leny + 1; } else { token.wtree[i2].leny = (i4 + 1) / 2; token.wtree[i8].leny = token.wtree[i2].leny - 1; } token.wtree[i8].y = token.wtree[i2].leny + i6; if (i7 == 0) { int i11 = i2 + 3; token.wtree[i11].leny = token.wtree[i8].leny; token.wtree[i11].y = token.wtree[i8].y; } token.wtree[i9].leny = token.wtree[i2].leny; } private void buildQTree(WsqHelper.Token token, int i) { token.qtree = new WsqHelper.QuantTree[i]; for (int i2 = 0; i2 < token.qtree.length; i2++) { token.qtree[i2] = new WsqHelper.QuantTree(); } qtree16(token, 3, token.wtree[14].lenx, token.wtree[14].leny, token.wtree[14].x, token.wtree[14].y, 0, 0); qtree16(token, 19, token.wtree[4].lenx, token.wtree[4].leny, token.wtree[4].x, token.wtree[4].y, 0, 1); qtree16(token, 48, token.wtree[0].lenx, token.wtree[0].leny, token.wtree[0].x, token.wtree[0].y, 0, 0); qtree16(token, 35, token.wtree[5].lenx, token.wtree[5].leny, token.wtree[5].x, token.wtree[5].y, 1, 0); qtree4(token, 0, token.wtree[19].lenx, token.wtree[19].leny, token.wtree[19].x, token.wtree[19].y); } private void qtree16(WsqHelper.Token token, int i, int i2, int i3, int i4, int i5, int i6, int i7) { int i8; int i9; int i10; int i11; if (i2 % 2 == 0) { i8 = i2 / 2; i9 = i8; } else if (i7 != 0) { int i12 = (i2 + 1) / 2; i9 = i12; i8 = i12 - 1; } else { i8 = (i2 + 1) / 2; i9 = i8 - 1; } if (i3 % 2 == 0) { i10 = i3 / 2; i11 = i10; } else if (i6 != 0) { int i13 = (i3 + 1) / 2; i11 = i13; i10 = i13 - 1; } else { i10 = (i3 + 1) / 2; i11 = i10 - 1; } token.qtree[i].x = i4; int i14 = i + 2; token.qtree[i14].x = i4; token.qtree[i].y = i5; int i15 = i + 1; token.qtree[i15].y = i5; if (i8 % 2 == 0) { token.qtree[i].lenx = i8 / 2; token.qtree[i15].lenx = token.qtree[i].lenx; token.qtree[i14].lenx = token.qtree[i].lenx; token.qtree[i + 3].lenx = token.qtree[i].lenx; } else { token.qtree[i].lenx = (i8 + 1) / 2; token.qtree[i15].lenx = token.qtree[i].lenx - 1; token.qtree[i14].lenx = token.qtree[i].lenx; token.qtree[i + 3].lenx = token.qtree[i15].lenx; } token.qtree[i15].x = token.qtree[i].lenx + i4; int i16 = i + 3; token.qtree[i16].x = token.qtree[i15].x; if (i10 % 2 == 0) { token.qtree[i].leny = i10 / 2; token.qtree[i15].leny = token.qtree[i].leny; token.qtree[i14].leny = token.qtree[i].leny; token.qtree[i16].leny = token.qtree[i].leny; } else { token.qtree[i].leny = (i10 + 1) / 2; token.qtree[i15].leny = token.qtree[i].leny; token.qtree[i14].leny = token.qtree[i].leny - 1; token.qtree[i16].leny = token.qtree[i14].leny; } token.qtree[i14].y = token.qtree[i].leny + i5; token.qtree[i16].y = token.qtree[i14].y; int i17 = i + 4; token.qtree[i17].x = i8 + i4; int i18 = i + 6; token.qtree[i18].x = token.qtree[i17].x; token.qtree[i17].y = i5; int i19 = i + 5; token.qtree[i19].y = i5; token.qtree[i18].y = token.qtree[i14].y; int i20 = i + 7; token.qtree[i20].y = token.qtree[i14].y; token.qtree[i17].leny = token.qtree[i].leny; token.qtree[i19].leny = token.qtree[i].leny; token.qtree[i18].leny = token.qtree[i14].leny; token.qtree[i20].leny = token.qtree[i14].leny; if (i9 % 2 == 0) { token.qtree[i17].lenx = i9 / 2; token.qtree[i19].lenx = token.qtree[i17].lenx; token.qtree[i18].lenx = token.qtree[i17].lenx; token.qtree[i20].lenx = token.qtree[i17].lenx; } else { token.qtree[i19].lenx = (i9 + 1) / 2; token.qtree[i17].lenx = token.qtree[i19].lenx - 1; token.qtree[i18].lenx = token.qtree[i17].lenx; token.qtree[i20].lenx = token.qtree[i19].lenx; } token.qtree[i19].x = token.qtree[i17].x + token.qtree[i17].lenx; token.qtree[i20].x = token.qtree[i19].x; int i21 = i + 8; token.qtree[i21].x = i4; int i22 = i + 9; token.qtree[i22].x = token.qtree[i15].x; int i23 = i + 10; token.qtree[i23].x = i4; int i24 = i + 11; token.qtree[i24].x = token.qtree[i15].x; token.qtree[i21].y = i5 + i10; token.qtree[i22].y = token.qtree[i21].y; token.qtree[i21].lenx = token.qtree[i].lenx; token.qtree[i22].lenx = token.qtree[i15].lenx; token.qtree[i23].lenx = token.qtree[i].lenx; token.qtree[i24].lenx = token.qtree[i15].lenx; if (i11 % 2 == 0) { token.qtree[i21].leny = i11 / 2; token.qtree[i22].leny = token.qtree[i21].leny; token.qtree[i23].leny = token.qtree[i21].leny; token.qtree[i24].leny = token.qtree[i21].leny; } else { token.qtree[i23].leny = (i11 + 1) / 2; token.qtree[i24].leny = token.qtree[i23].leny; token.qtree[i21].leny = token.qtree[i23].leny - 1; token.qtree[i22].leny = token.qtree[i21].leny; } token.qtree[i23].y = token.qtree[i21].y + token.qtree[i21].leny; token.qtree[i24].y = token.qtree[i23].y; int i25 = i + 12; token.qtree[i25].x = token.qtree[i17].x; int i26 = i + 13; token.qtree[i26].x = token.qtree[i19].x; int i27 = i + 14; token.qtree[i27].x = token.qtree[i17].x; int i28 = i + 15; token.qtree[i28].x = token.qtree[i19].x; token.qtree[i25].y = token.qtree[i21].y; token.qtree[i26].y = token.qtree[i21].y; token.qtree[i27].y = token.qtree[i23].y; token.qtree[i28].y = token.qtree[i23].y; token.qtree[i25].lenx = token.qtree[i17].lenx; token.qtree[i26].lenx = token.qtree[i19].lenx; token.qtree[i27].lenx = token.qtree[i17].lenx; token.qtree[i28].lenx = token.qtree[i19].lenx; token.qtree[i25].leny = token.qtree[i21].leny; token.qtree[i26].leny = token.qtree[i21].leny; token.qtree[i27].leny = token.qtree[i23].leny; token.qtree[i28].leny = token.qtree[i23].leny; } private void qtree4(WsqHelper.Token token, int i, int i2, int i3, int i4, int i5) { token.qtree[i].x = i4; int i6 = i + 2; token.qtree[i6].x = i4; token.qtree[i].y = i5; int i7 = i + 1; token.qtree[i7].y = i5; if (i2 % 2 == 0) { token.qtree[i].lenx = i2 / 2; token.qtree[i7].lenx = token.qtree[i].lenx; token.qtree[i6].lenx = token.qtree[i].lenx; token.qtree[i + 3].lenx = token.qtree[i].lenx; } else { token.qtree[i].lenx = (i2 + 1) / 2; token.qtree[i7].lenx = token.qtree[i].lenx - 1; token.qtree[i6].lenx = token.qtree[i].lenx; token.qtree[i + 3].lenx = token.qtree[i7].lenx; } token.qtree[i7].x = i4 + token.qtree[i].lenx; int i8 = i + 3; token.qtree[i8].x = token.qtree[i7].x; if (i3 % 2 == 0) { token.qtree[i].leny = i3 / 2; token.qtree[i7].leny = token.qtree[i].leny; token.qtree[i6].leny = token.qtree[i].leny; token.qtree[i8].leny = token.qtree[i].leny; } else { token.qtree[i].leny = (i3 + 1) / 2; token.qtree[i7].leny = token.qtree[i].leny; token.qtree[i6].leny = token.qtree[i].leny - 1; token.qtree[i8].leny = token.qtree[i6].leny; } token.qtree[i6].y = i5 + token.qtree[i].leny; token.qtree[i8].y = token.qtree[i6].y; } private int[] huffmanDecodeDataMem(WsqHelper.Token token, int i) { WsqHelper.IntRef intRef; int i2; int i3; int[] iArr = new int[i]; int[] iArr2 = new int[17]; int[] iArr3 = new int[17]; int[] iArr4 = new int[17]; int i4 = 4; WsqHelper.IntRef intRef2 = new WsqHelper.IntRef(getCMarkerWSQ(token, 4)); int i5 = 0; WsqHelper.IntRef intRef3 = new WsqHelper.IntRef(0); WsqHelper.IntRef intRef4 = new WsqHelper.IntRef(0); int i6 = 0; int i7 = 0; while (intRef2.value != 65441) { if (intRef2.value != 0) { while (intRef2.value != 65443) { getCTableWSQ(token, intRef2.value); intRef2.value = getCMarkerWSQ(token, i4); } i2 = getCBlockHeader(token); if (token.tableDHT[i2].tabdef != 1) { throw new RuntimeException("ERROR : huffmanDecodeDataMem : huffman table undefined."); } WsqHelper.HuffCode[] buildHuffsizes = buildHuffsizes(token.tableDHT[i2].huffbits, 256); buildHuffcodes(buildHuffsizes); intRef = intRef4; genDecodeTable(buildHuffsizes, iArr2, iArr3, iArr4, token.tableDHT[i2].huffbits); intRef3.value = i5; intRef2.value = i5; } else { intRef = intRef4; i2 = i6; } int i8 = i5; WsqHelper.IntRef intRef5 = intRef3; int i9 = i4; int decodeDataMem = decodeDataMem(token, iArr3, iArr2, iArr4, token.tableDHT[i2].huffvalues, intRef3, intRef2, intRef); if (decodeDataMem != -1) { if (decodeDataMem > 0 && decodeDataMem <= 100) { int i10 = i8; while (i10 < decodeDataMem) { iArr[i7] = i8; i10++; i7++; } } else if (decodeDataMem <= 106 || decodeDataMem >= 255) { if (decodeDataMem == 101) { i3 = i7 + 1; intRef4 = intRef; iArr[i7] = getCNextbitsWSQ(token, intRef2, intRef5, 8, intRef4); } else if (decodeDataMem == 102) { i3 = i7 + 1; intRef4 = intRef; iArr[i7] = -getCNextbitsWSQ(token, intRef2, intRef5, 8, intRef4); } else if (decodeDataMem == 103) { i3 = i7 + 1; intRef4 = intRef; iArr[i7] = getCNextbitsWSQ(token, intRef2, intRef5, 16, intRef4); } else if (decodeDataMem == 104) { i3 = i7 + 1; intRef4 = intRef; iArr[i7] = -getCNextbitsWSQ(token, intRef2, intRef5, 16, intRef4); } else if (decodeDataMem == 105) { for (int cNextbitsWSQ = getCNextbitsWSQ(token, intRef2, intRef5, 8, intRef); cNextbitsWSQ > 0; cNextbitsWSQ--) { iArr[i7] = i8; i7++; } } else if (decodeDataMem == 106) { for (int cNextbitsWSQ2 = getCNextbitsWSQ(token, intRef2, intRef5, 16, intRef); cNextbitsWSQ2 > 0; cNextbitsWSQ2--) { iArr[i7] = i8; i7++; } } else { StringBuilder sb = new StringBuilder("ERROR: huffman_decode_data_mem : Invalid code ("); sb.append(decodeDataMem); sb.append(")"); throw new RuntimeException(sb.toString()); } i7 = i3; i6 = i2; i5 = i8; intRef3 = intRef5; i4 = i9; } else { iArr[i7] = decodeDataMem - 180; i7++; } } i6 = i2; i5 = i8; intRef4 = intRef; intRef3 = intRef5; i4 = i9; } return iArr; } private int getCBlockHeader(WsqHelper.Token token) { token.readShort(); return token.readByte(); } private WsqHelper.HuffCode[] buildHuffsizes(int[] iArr, int i) { WsqHelper.HuffCode[] huffCodeArr = new WsqHelper.HuffCode[i + 1]; int i2 = 0; for (int i3 = 1; i3 <= 16; i3++) { for (int i4 = 1; i4 <= iArr[i3 - 1]; i4++) { WsqHelper.HuffCode huffCode = new WsqHelper.HuffCode(); huffCodeArr[i2] = huffCode; huffCode.size = i3; i2++; } } WsqHelper.HuffCode huffCode2 = new WsqHelper.HuffCode(); huffCodeArr[i2] = huffCode2; huffCode2.size = 0; return huffCodeArr; } private void buildHuffcodes(WsqHelper.HuffCode[] huffCodeArr) { int i = 0; int i2 = huffCodeArr[0].size; if (huffCodeArr[0].size == 0) { return; } int i3 = i2; short s = 0; while (true) { huffCodeArr[i].code = s; s = (short) (s + 1); i++; if (huffCodeArr[i].size != i3) { if (huffCodeArr[i].size == 0) { return; } do { s = (short) (s << 1); i3++; } while (huffCodeArr[i].size != i3); if (huffCodeArr[i].size != i3) { return; } } } } private void genDecodeTable(WsqHelper.HuffCode[] huffCodeArr, int[] iArr, int[] iArr2, int[] iArr3, int[] iArr4) { int i = 0; for (int i2 = 0; i2 <= 16; i2++) { iArr[i2] = 0; iArr2[i2] = 0; iArr3[i2] = 0; } for (int i3 = 1; i3 <= 16; i3++) { int i4 = i3 - 1; if (iArr4[i4] == 0) { iArr[i3] = -1; } else { iArr3[i3] = i; iArr2[i3] = huffCodeArr[i].code; i += iArr4[i4]; iArr[i3] = huffCodeArr[i - 1].code; } } } private int decodeDataMem(WsqHelper.Token token, int[] iArr, int[] iArr2, int[] iArr3, int[] iArr4, WsqHelper.IntRef intRef, WsqHelper.IntRef intRef2, WsqHelper.IntRef intRef3) { short cNextbitsWSQ = (short) getCNextbitsWSQ(token, intRef2, intRef, 1, intRef3); if (intRef2.value != 0) { return -1; } int i = 1; while (cNextbitsWSQ > iArr2[i]) { cNextbitsWSQ = (short) ((cNextbitsWSQ << 1) + getCNextbitsWSQ(token, intRef2, intRef, 1, intRef3)); if (intRef2.value != 0) { return -1; } i++; } return iArr4[(iArr3[i] + cNextbitsWSQ) - iArr[i]]; } private int getCNextbitsWSQ(WsqHelper.Token token, WsqHelper.IntRef intRef, WsqHelper.IntRef intRef2, int i, WsqHelper.IntRef intRef3) { if (intRef2.value == 0) { intRef3.value = token.readByte(); intRef2.value = 8; if (intRef3.value == 255) { int readByte = token.readByte(); if (readByte != 0 && i == 1) { intRef.value = (intRef3.value << 8) | readByte; return 1; } if (readByte != 0) { throw new RuntimeException("ERROR: getCNextbitsWSQ : No stuffed zeros."); } } } if (i <= intRef2.value) { int i2 = (intRef3.value >> (intRef2.value - i)) & WsqHelper.BITMASK[i]; intRef2.value -= i; intRef3.value &= WsqHelper.BITMASK[intRef2.value]; return i2; } int i3 = i - intRef2.value; int i4 = intRef3.value; intRef2.value = 0; return getCNextbitsWSQ(token, intRef, intRef2, i3, intRef3) | (i4 << i3); } private float[] unquantize(WsqHelper.Token token, int[] iArr, int i, int i2) { float[] fArr = new float[i2 * i]; if (token.tableDQT.dqtDef != 1) { throw new RuntimeException("ERROR: unquantize : quantization table parameters not defined!"); } float f = token.tableDQT.binCenter; int i3 = 0; for (int i4 = 0; i4 < 60; i4++) { if (token.tableDQT.qBin[i4] != 0.0d) { int i5 = (token.qtree[i4].y * i) + token.qtree[i4].x; int i6 = 0; while (i6 < token.qtree[i4].leny) { for (int i7 = 0; i7 < token.qtree[i4].lenx; i7++) { int i8 = iArr[i3]; if (i8 == 0) { fArr[i5] = 0.0f; } else if (i8 > 0) { fArr[i5] = (token.tableDQT.qBin[i4] * (iArr[i3] - f)) + (token.tableDQT.zBin[i4] / 2.0f); } else if (i8 < 0) { fArr[i5] = (token.tableDQT.qBin[i4] * (iArr[i3] + f)) - (token.tableDQT.zBin[i4] / 2.0f); } else { throw new RuntimeException("ERROR : unquantize : invalid quantization pixel value"); } i5++; i3++; } i6++; i5 += i - token.qtree[i4].lenx; } } } return fArr; } private void wsqReconstruct(WsqHelper.Token token, float[] fArr, int i, int i2) { if (token.tableDTT.lodef != 1) { throw new RuntimeException("ERROR: wsq_reconstruct : Lopass filter coefficients not defined"); } if (token.tableDTT.hidef != 1) { throw new RuntimeException("ERROR: wsq_reconstruct : Hipass filter coefficients not defined"); } float[] fArr2 = new float[i * i2]; for (int i3 = 19; i3 >= 0; i3--) { int i4 = (token.wtree[i3].y * i) + token.wtree[i3].x; joinLets(fArr2, fArr, 0, i4, token.wtree[i3].lenx, token.wtree[i3].leny, 1, i, token.tableDTT.hifilt, token.tableDTT.hisz, token.tableDTT.lofilt, token.tableDTT.losz, token.wtree[i3].invcl); joinLets(fArr, fArr2, i4, 0, token.wtree[i3].leny, token.wtree[i3].lenx, i, 1, token.tableDTT.hifilt, token.tableDTT.hisz, token.tableDTT.lofilt, token.tableDTT.losz, token.wtree[i3].invrw); } } private void joinLets(float[] fArr, float[] fArr2, int i, int i2, int i3, int i4, int i5, int i6, float[] fArr3, int i7, float[] fArr4, int i8, int i9) { int i10; int i11; boolean z; boolean z2; int i12; int i13; int i14; boolean z3; float f; int i15; int i16; boolean z4; int i17; int i18; int i19; int i20; int i21; int i22; int i23; float f2; int i24; boolean z5; int i25; float f3; boolean z6; int i26 = i8; int i27 = i4 % 2; int i28 = i26 % 2; int i29 = -i6; boolean z7 = true; if (i27 != 0) { i10 = (i4 + 1) / 2; i11 = i10 - 1; } else { i10 = i4 / 2; i11 = i10; } if (i28 != 0) { int i30 = i26 - 1; i16 = i30 / 4; int i31 = i7 + 1; i15 = (i31 / 4) - 1; i12 = (i30 / 2) % 2; i14 = (i31 / 2) % 2; if (i27 != 0) { z6 = true; z = false; } else { z = true; z6 = false; } z3 = z6; f = 1.0f; i13 = 0; z2 = false; z4 = false; } else { int i32 = (i26 / 4) - 1; int i33 = (i7 / 4) - 1; int i34 = i26 / 2; int i35 = (i7 / 2) % 2; z = i27 == 0; if (i32 == -1) { i32 = 0; z2 = false; } else { z2 = true; } if (i33 == -1) { z7 = false; i33 = 0; } else { z7 = true; } int i36 = 0; while (i36 < i7) { fArr3[i36] = (float) (-fArr3[i36]); i36++; i32 = i32; } int i37 = i32; i12 = i34 % 2; i13 = 2; i14 = i35; z3 = true; f = -1.0f; i15 = i33; i16 = i37; z4 = true; } int i38 = i3; int i39 = 0; int i40 = 0; while (i39 < i38) { int i41 = i39 * i5; int i42 = i + i41; fArr[i42] = 0.0f; fArr[i42 + i6] = 0.0f; if (i9 != 0) { i18 = i2 + i41; i17 = i18 + (i6 * i11); } else { i17 = i2 + i41; i18 = i17 + (i6 * i10); } int i43 = i18; boolean z8 = z7; int i44 = i17; int i45 = i10; int i46 = i44 + ((i10 - 1) * i6); boolean z9 = z3; int i47 = i43 + ((i11 - 1) * i6); int i48 = i44 + (i16 * i6); float f4 = f; int i49 = i13; int i50 = i12; int i51 = i16; int i52 = i14; boolean z10 = z2; int i53 = i29; int i54 = i53; boolean z11 = z8; int i55 = i43 + (i15 * i6); int i56 = 0; int i57 = i48; int i58 = i42; while (i56 < i11) { while (i50 >= 0) { fArr[i42] = fArr2[i57] * fArr4[i50]; int i59 = i28; int i60 = i11; int i61 = i57; boolean z12 = z; int i62 = i53; boolean z13 = z10; for (int i63 = i50 + 2; i63 < i26; i63 += 2) { if (i61 == i44) { if (z13) { z13 = false; i62 = 0; } else { i62 = i6; } } if (i61 == i46) { if (z12) { z12 = false; i62 = 0; } else { i62 = i29; } } i61 += i62; fArr[i42] = fArr[i42] + (fArr2[i61] * fArr4[i63]); } i42 += i6; i50--; i11 = i60; i28 = i59; } int i64 = i28; int i65 = i11; if (i57 == i44) { if (z10) { i53 = 0; z10 = false; } else { i53 = i6; } } int i66 = i57 + i53; while (i52 >= 0) { int i67 = i66; int i68 = i55; boolean z14 = z9; i40 = i49; float f5 = f4; boolean z15 = z11; int i69 = i54; int i70 = i52; while (i70 < i7) { if (i68 == i43) { if (z15) { z15 = false; i69 = 0; } else { i69 = i6; f5 = 1.0f; } } if (i68 != i47) { i24 = i39; z5 = z15; i25 = i47; } else if (z14) { if (!z4 || i27 == 0) { i24 = i39; z5 = z15; i25 = i47; } else { z5 = z15; int i71 = i40 - 1; i24 = i39; f3 = i71; i40 = i71; i25 = i47; if (f3 != 0.0d) { z14 = true; f5 = f3; i69 = 0; } else { f5 = f3; } } f3 = f5; z14 = false; f5 = f3; i69 = 0; } else { i24 = i39; z5 = z15; i25 = i47; i69 = i29; if (z4) { f5 = -1.0f; } } fArr[i58] = fArr[i58] + (fArr2[i68] * fArr3[i70] * f5); i68 += i69; i70 += 2; z15 = z5; i39 = i24; i47 = i25; } i58 += i6; i52--; i66 = i67; } int i72 = i39; int i73 = i47; int i74 = i66; if (i55 == i43) { if (z11) { z11 = false; i54 = 0; } else { i54 = i6; f4 = 1.0f; } } i55 += i54; i56++; i11 = i65; i28 = i64; i57 = i74; i39 = i72; i47 = i73; i50 = 1; i52 = 1; } int i75 = i28; int i76 = i39; int i77 = i11; int i78 = i47; if (i27 != 0) { if (i12 == 0) { i19 = 0; } i19 = 1; } else { if (i12 != 0) { i19 = 2; } i19 = 1; } for (int i79 = 1; i79 >= i19; i79--) { fArr[i42] = fArr2[i57] * fArr4[i79]; int i80 = i57; boolean z16 = z; int i81 = i53; boolean z17 = z10; for (int i82 = i79 + 2; i82 < i26; i82 += 2) { if (i80 == i44) { if (z17) { z17 = false; i81 = 0; } else { i81 = i6; } } if (i80 == i46) { if (z16) { z16 = false; i81 = 0; } else { i81 = i29; } } i80 += i81; fArr[i42] = fArr[i42] + (fArr2[i80] * fArr4[i82]); } i42 += i6; } if (i27 != 0) { i21 = i14 != 0 ? 1 : 0; i20 = 2; if (i7 == 2) { i55 -= i54; i40 = 1; } } else { i20 = 2; i21 = i14 != 0 ? 2 : 1; } int i83 = 1; while (i83 >= i21) { if (i7 != i20) { i40 = i49; } int i84 = i83; int i85 = i55; boolean z18 = z9; float f6 = f4; boolean z19 = z11; int i86 = i54; while (i84 < i7) { if (i85 != i43) { i22 = i78; } else if (z19) { i22 = i78; z19 = false; i86 = 0; } else { i86 = i6; i22 = i78; f6 = 1.0f; } if (i85 != i22) { i23 = i27; } else if (z18) { if (!z4 || i27 == 0) { i23 = i27; } else { int i87 = i40 - 1; f2 = i87; i23 = i27; i40 = i87; if (f2 != 0.0d) { z18 = true; f6 = f2; i86 = 0; } else { f6 = f2; } } f2 = f6; z18 = false; f6 = f2; i86 = 0; } else { i23 = i27; i86 = i29; if (z4) { f6 = -1.0f; } } fArr[i58] = fArr[i58] + (fArr2[i85] * fArr3[i84] * f6); i85 += i86; i84 += 2; i78 = i22; i27 = i23; } i58 += i6; i83--; i20 = 2; } i39 = i76 + 1; i38 = i3; i26 = i8; z7 = z8; i10 = i45; z3 = z9; f = f4; i13 = i49; i16 = i51; i11 = i77; i28 = i75; } if (i28 == 0) { for (int i88 = 0; i88 < i7; i88++) { fArr3[i88] = (float) (-fArr3[i88]); } } } private byte[] convertImage2Byte(float[] fArr, int i, int i2, float f, float f2) { byte[] bArr = new byte[i * i2]; int i3 = 0; for (int i4 = 0; i4 < i2; i4++) { for (int i5 = 0; i5 < i; i5++) { float f3 = (float) ((fArr[i3] * f2) + f + 0.5d); double d = f3; if (d < 0.0d) { bArr[i3] = 0; } else if (d > 255.0d) { bArr[i3] = -1; } else { bArr[i3] = (byte) f3; } i3++; } } return bArr; } }