id
stringlengths
36
36
text
stringlengths
1
1.25M
bff23120-1437-4426-8ec8-d9e68558ce4c
public F5Random(final byte[] password) { this.random = new SecureRandom(); this.random.engineSetSeed(password); this.b = new byte[1]; }
6ee8891c-0fe4-4765-a328-8d00135cd3f6
public int getNextByte() { this.random.engineNextBytes(this.b); return this.b[0]; }
72f18085-5fd4-4be2-997c-a160cfc4a07f
public int getNextValue(final int maxValue) { int retVal = getNextByte() | getNextByte() << 8 | getNextByte() << 16 | getNextByte() << 24; retVal %= maxValue; if (retVal < 0) { retVal += maxValue; } return retVal; }
fe35d381-c6c5-43ad-b5d2-072e71e9a31c
public static void main(final String args[]) { Image image = null; FileOutputStream dataOut = null; File file, outFile; JpegEncoder jpg; int i, Quality = 80; // Check to see if the input file name has one of the extensions: // .tif, .gif, .jpg // If not, print the standard use info. boolean haveInputImage = false; String embFileName = null; String comment = "TEST"; String password = "abc123"; String inFileName = null; String outFileName = null; if (args.length < 1) { StandardUsage(); return; } for (i = 0; i < args.length; i++) { if (!args[i].startsWith("-")) { if (!haveInputImage) { if (!args[i].endsWith(".jpg") && !args[i].endsWith(".tif") && !args[i].endsWith(".gif") && !args[i].endsWith(".bmp")) { StandardUsage(); return; } inFileName = args[i]; outFileName = args[i].substring(0, args[i].lastIndexOf(".")) + ".jpg"; haveInputImage = true; } else { outFileName = args[i]; if (outFileName.endsWith(".tif") || outFileName.endsWith(".gif") || outFileName.endsWith(".bmp")) { outFileName = outFileName.substring(0, outFileName.lastIndexOf(".")); } if (!outFileName.endsWith(".jpg")) { outFileName = outFileName.concat(".jpg"); } } continue; } if (args.length < i + 1) { System.out.println("Missing parameter for switch " + args[i]); StandardUsage(); return; } if (args[i].equals("-e")) { embFileName = args[i + 1]; } else if (args[i].equals("-p")) { password = args[i + 1]; } else if (args[i].equals("-q")) { try { Quality = Integer.parseInt(args[i + 1]); } catch (final NumberFormatException e) { StandardUsage(); return; } } else if (args[i].equals("-c")) { comment = args[i + 1]; } else { System.out.println("Unknown switch " + args[i] + " ignored."); } i++; } outFile = new File(outFileName); i = 1; while (outFile.exists()) { outFile = new File(outFileName.substring(0, outFileName.lastIndexOf(".")) + i++ + ".jpg"); if (i > 100) { System.exit(0); } } file = new File(inFileName); if (file.exists()) { try { dataOut = new FileOutputStream(outFile); } catch (final IOException e) { } if (inFileName.endsWith(".bmp")) { final Bmp bmp = new Bmp(inFileName); image = bmp.getImage(); } else { image = Toolkit.getDefaultToolkit().getImage(inFileName); } jpg = new JpegEncoder(image, Quality, dataOut, comment); try { if (embFileName == null) { jpg.Compress(); } else { jpg.Compress(new FileInputStream(embFileName), password); } } catch (final Exception e) { e.printStackTrace(); } try { dataOut.close(); } catch (final IOException e) { } } else { System.out.println("I couldn't find " + inFileName + ". Is it in another directory?"); } }
28a43e58-2e56-40f0-b828-822f754265c3
public static void StandardUsage() { System.out.println("F5/JpegEncoder for Java(tm)"); System.out.println(""); System.out.println("Program usage: java Embed [Options] \"InputImage\".\"ext\" [\"OutputFile\"[.jpg]]"); System.out.println(""); System.out.println("You have the following options:"); System.out.println("-e <file to embed>\tdefault: embed nothing"); System.out.println("-p <password>\t\tdefault: \"abc123\", only used when -e is specified"); System.out.println("-q <quality 0 ... 100>\tdefault: 80"); System.out .println("-c <comment>\t\tdefault: \"JPEG Encoder Copyright 1998, James R. Weeks and BioElectroMech. \""); System.out.println(""); System.out.println("\"InputImage\" is the name of an existing image in the current directory."); System.out.println(" (\"InputImage may specify a directory, too.) \"ext\" must be .tif, .gif,"); System.out.println(" or .jpg."); System.out.println("Quality is an integer (0 to 100) that specifies how similar the compressed"); System.out.println(" image is to \"InputImage.\" 100 is almost exactly like \"InputImage\" and 0 is"); System.out.println(" most dissimilar. In most cases, 70 - 80 gives very good results."); System.out.println("\"OutputFile\" is an optional argument. If \"OutputFile\" isn't specified, then"); System.out.println(" the input file name is adopted. This program will NOT write over an existing"); System.out.println(" file. If a directory is specified for the input image, then \"OutputFile\""); System.out.println(" will be written in that directory. The extension \".jpg\" may automatically be"); System.out.println(" added."); System.out.println(""); System.out.println("Copyright 1998 BioElectroMech and James R. Weeks. Portions copyright IJG and"); System.out.println(" Florian Raemy, LCAV. See license.txt for details."); System.out.println("Visit BioElectroMech at www.obrador.com. Email [email protected]."); System.out.println("Steganography added by Andreas Westfeld, [email protected]"); }
c1c741cd-9443-493d-83b8-72beb3d06acb
public static void extract(final InputStream fis, final int flength, final OutputStream fos, final String password) throws IOException { carrier = new byte[flength]; fis.read(carrier); final HuffmanDecode hd = new HuffmanDecode(carrier); System.out.println("Huffman decoding starts"); coeff = hd.decode(); System.out.println("Permutation starts"); final F5Random random = new F5Random(password.getBytes()); final Permutation permutation = new Permutation(coeff.length, random); System.out.println(coeff.length + " indices shuffled"); int extractedByte = 0; int availableExtractedBits = 0; int extractedFileLength = 0; int nBytesExtracted = 0; int shuffledIndex = 0; int extractedBit; int i; System.out.println("Extraction starts"); // extract length information for (i = 0; availableExtractedBits < 32; i++) { shuffledIndex = permutation.getShuffled(i); if (shuffledIndex % 64 == 0) { continue; // skip DC coefficients } shuffledIndex = shuffledIndex - shuffledIndex % 64 + deZigZag[shuffledIndex % 64]; if (coeff[shuffledIndex] == 0) { continue; // skip zeroes } if (coeff[shuffledIndex] > 0) { extractedBit = coeff[shuffledIndex] & 1; } else { extractedBit = 1 - (coeff[shuffledIndex] & 1); } extractedFileLength |= extractedBit << availableExtractedBits++; } // remove pseudo random pad extractedFileLength ^= random.getNextByte(); extractedFileLength ^= random.getNextByte() << 8; extractedFileLength ^= random.getNextByte() << 16; extractedFileLength ^= random.getNextByte() << 24; int k = extractedFileLength >> 24; k %= 32; final int n = (1 << k) - 1; extractedFileLength &= 0x007fffff; System.out.println("Length of embedded file: " + extractedFileLength + " bytes"); availableExtractedBits = 0; if (n > 0) { int startOfN = i; int hash; System.out.println("(1, " + n + ", " + k + ") code used"); extractingLoop: do { // 1. read n places, and calculate k bits hash = 0; int code = 1; for (i = 0; code <= n; i++) { // check for pending end of coeff if (startOfN + i >= coeff.length) { break extractingLoop; } shuffledIndex = permutation.getShuffled(startOfN + i); if (shuffledIndex % 64 == 0) { continue; // skip DC coefficients } shuffledIndex = shuffledIndex - shuffledIndex % 64 + deZigZag[shuffledIndex % 64]; if (coeff[shuffledIndex] == 0) { continue; // skip zeroes } if (coeff[shuffledIndex] > 0) { extractedBit = coeff[shuffledIndex] & 1; } else { extractedBit = 1 - (coeff[shuffledIndex] & 1); } if (extractedBit == 1) { hash ^= code; } code++; } startOfN += i; // 2. write k bits bytewise for (i = 0; i < k; i++) { extractedByte |= (hash >> i & 1) << availableExtractedBits++; if (availableExtractedBits == 8) { // remove pseudo random pad extractedByte ^= random.getNextByte(); fos.write((byte) extractedByte); extractedByte = 0; availableExtractedBits = 0; nBytesExtracted++; // check for pending end of embedded data if (nBytesExtracted == extractedFileLength) { break extractingLoop; } } } } while (true); } else { System.out.println("Default code used"); for (; i < coeff.length; i++) { shuffledIndex = permutation.getShuffled(i); if (shuffledIndex % 64 == 0) { continue; // skip DC coefficients } shuffledIndex = shuffledIndex - shuffledIndex % 64 + deZigZag[shuffledIndex % 64]; if (coeff[shuffledIndex] == 0) { continue; // skip zeroes } if (coeff[shuffledIndex] > 0) { extractedBit = coeff[shuffledIndex] & 1; } else { extractedBit = 1 - (coeff[shuffledIndex] & 1); } extractedByte |= extractedBit << availableExtractedBits++; if (availableExtractedBits == 8) { // remove pseudo random pad extractedByte ^= random.getNextByte(); fos.write((byte) extractedByte); extractedByte = 0; availableExtractedBits = 0; nBytesExtracted++; if (nBytesExtracted == extractedFileLength) { break; } } } } if (nBytesExtracted < extractedFileLength) { System.out.println("Incomplete file: only " + nBytesExtracted + " of " + extractedFileLength + " bytes extracted"); } }
56af0078-df10-4f31-9470-5ba0970d0099
public static void main(final String[] args) { embFileName = "output.txt"; password = "abc123"; try { if (args.length < 1) { usage(); return; } for (int i = 0; i < args.length; i++) { if (!args[i].startsWith("-")) { if (!args[i].endsWith(".jpg")) { usage(); return; } f = new File(args[i]); continue; } if (args.length < i + 1) { System.out.println("Missing parameter for switch " + args[i]); usage(); return; } if (args[i].equals("-e")) { embFileName = args[i + 1]; } else if (args[i].equals("-p")) { password = args[i + 1]; } else { System.out.println("Unknown switch " + args[i] + " ignored."); } i++; } final FileInputStream fis = new FileInputStream(f); fos = new FileOutputStream(new File(embFileName)); extract(fis, (int) f.length(), fos, password); } catch (final Exception e) { e.printStackTrace(); } }
83326d00-c5df-479f-912f-c007eb3216eb
static void usage() { System.out.println("java Extract [Options] \"image.jpg\""); System.out.println("Options:"); System.out.println("\t-p password (default: abc123)"); System.out.println("\t-e extractedFileName (default: output.txt)"); System.out.println("\nAuthor: Andreas Westfeld, [email protected]"); }
56320b3a-ca4b-4297-baa9-bd3dee0c232a
public Bmp(final String fileName) { try { this.imageFile = new BufferedInputStream(new FileInputStream(fileName)); readBitmapFileHeader(); readBitmapInfoHeader(); this.pixel = new int[this.biWidth * this.biHeight]; int padding = 3 * this.biWidth % 4; if (padding > 0) { padding = 4 - padding; } int offset; for (int y = 1; y <= this.biHeight; y++) { offset = (this.biHeight - y) * this.biWidth; for (int x = 0; x < this.biWidth; x++) { this.pixel[offset + x] = readPixel(); } for (int x = 0; x < padding; x++) { this.imageFile.read(); } } } catch (final Exception e) { System.out.println(fileName + " is not a true colour file."); System.exit(1); } }
3816fefd-7f1a-4a7d-8639-36a6e4750767
public Image getImage() { MemoryImageSource mis; mis = new MemoryImageSource(this.biWidth, this.biHeight, this.pixel, 0, this.biWidth); return Toolkit.getDefaultToolkit().createImage(mis); }
6553a1b0-5ce8-4ce9-8e11-807cd4ab29ef
void readBitmapFileHeader() throws Exception { if (this.imageFile.read() != 'B') throw new Exception(); if (this.imageFile.read() != 'M') throw new Exception(); this.bfSize = readInt(); readInt(); // ignore 4 bytes reserved this.bfOffBits = readInt(); }
b519ae43-d207-47de-88d5-4e30f76ba192
void readBitmapInfoHeader() throws Exception { this.biSize = readInt(); this.biWidth = readInt(); this.biHeight = readInt(); this.biPlanes = readShort(); this.biBitCount = readShort(); if (this.biBitCount != 24) throw new Exception(); this.biCompression = readInt(); this.biSizeImage = readInt(); this.biXPelsPerMeter = readInt(); this.biYPelsPerMeter = readInt(); this.biClrUsed = readInt(); this.biClrImportant = readInt(); }
2342ca39-a460-4c54-ac27-162958d33158
int readInt() throws IOException { int retVal = 0; for (int i = 0; i < 4; i++) { retVal += (this.imageFile.read() & 0xff) << 8 * i; } return retVal; }
7ea7f77b-2760-485f-bc17-ea2e6db696cf
int readPixel() throws IOException { int retVal = 0; for (int i = 0; i < 3; i++) { retVal += (this.imageFile.read() & 0xff) << 8 * i; } return retVal | 0xff000000; }
fddf42a8-35f3-4714-8fe9-ec3f5ea56b31
int readShort() throws IOException { int retVal; retVal = this.imageFile.read() & 0xff; retVal += (this.imageFile.read() & 0xff) << 8; return retVal; }
429a165f-902a-44f5-93b9-b906e01f85d9
public static void main(final String args[]) { Image image = null; FileOutputStream dataOut = null; File file, outFile; JpegEncoder jpg; String string = new String(); int i, Quality = 80; if (args.length < 2) { StandardUsage(); } if (!args[0].endsWith(".jpg") && !args[0].endsWith(".tif") && !args[0].endsWith(".gif")) { StandardUsage(); } if (args.length < 3) { string = args[0].substring(0, args[0].lastIndexOf(".")) + ".jpg"; } else { string = args[2]; if (string.endsWith(".tif") || string.endsWith(".gif")) { string = string.substring(0, string.lastIndexOf(".")); } if (!string.endsWith(".jpg")) { string = string.concat(".jpg"); } } outFile = new File(string); i = 1; while (outFile.exists()) { outFile = new File(string.substring(0, string.lastIndexOf(".")) + i++ + ".jpg"); if (i > 100) { System.exit(0); } } file = new File(args[0]); if (file.exists()) { try { dataOut = new FileOutputStream(outFile); } catch (final IOException e) { } try { Quality = Integer.parseInt(args[1]); } catch (final NumberFormatException e) { StandardUsage(); } image = Toolkit.getDefaultToolkit().getImage(args[0]); jpg = new JpegEncoder(image, Quality, dataOut, ""); jpg.Compress(); try { dataOut.close(); } catch (final IOException e) { } } else { System.out.println("I couldn't find " + args[0] + ". Is it in another directory?"); } System.exit(0); }
2fdadd21-8dbf-4454-9697-ca276a45074f
public static void StandardUsage() { System.out.println("JpegEncoder for Java(tm) Version 0.9"); System.out.println(""); System.out.println("Program usage: java Jpeg \"InputImage\".\"ext\" Quality [\"OutputFile\"[.jpg]]"); System.out.println(""); System.out.println("Where \"InputImage\" is the name of an existing image in the current directory."); System.out.println(" (\"InputImage may specify a directory, too.) \"ext\" must be .tif, .gif,"); System.out.println(" or .jpg."); System.out.println("Quality is an integer (0 to 100) that specifies how similar the compressed"); System.out.println(" image is to \"InputImage.\" 100 is almost exactly like \"InputImage\" and 0 is"); System.out.println(" most dissimilar. In most cases, 70 - 80 gives very good results."); System.out.println("\"OutputFile\" is an optional argument. If \"OutputFile\" isn't specified, then"); System.out.println(" the input file name is adopted. This program will NOT write over an existing"); System.out.println(" file. If a directory is specified for the input image, then \"OutputFile\""); System.out.println(" will be written in that directory. The extension \".jpg\" may automatically be"); System.out.println(" added."); System.out.println(""); System.out.println("Copyright 1998 BioElectroMech and James R. Weeks. Portions copyright IJG and"); System.out.println(" Florian Raemy, LCAV. See license.txt for details."); System.out.println("Visit BioElectroMech at www.obrador.com. Email [email protected]."); System.exit(0); }
863302fd-eac7-48eb-a69e-2d092da4a242
public DCT(final int QUALITY) { initMatrix(QUALITY); }
d01734c4-1bb6-4e16-bb16-28a706c6a4ad
public double[][] forwardDCT(final float input[][]) { final double output[][] = new double[this.N][this.N]; double tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; double tmp10, tmp11, tmp12, tmp13; double z1, z2, z3, z4, z5, z11, z13; int i; int j; // Subtracts 128 from the input values for (i = 0; i < 8; i++) { for (j = 0; j < 8; j++) { output[i][j] = input[i][j] - 128.0; // input[i][j] -= 128; } } for (i = 0; i < 8; i++) { tmp0 = output[i][0] + output[i][7]; tmp7 = output[i][0] - output[i][7]; tmp1 = output[i][1] + output[i][6]; tmp6 = output[i][1] - output[i][6]; tmp2 = output[i][2] + output[i][5]; tmp5 = output[i][2] - output[i][5]; tmp3 = output[i][3] + output[i][4]; tmp4 = output[i][3] - output[i][4]; tmp10 = tmp0 + tmp3; tmp13 = tmp0 - tmp3; tmp11 = tmp1 + tmp2; tmp12 = tmp1 - tmp2; output[i][0] = tmp10 + tmp11; output[i][4] = tmp10 - tmp11; z1 = (tmp12 + tmp13) * 0.707106781; output[i][2] = tmp13 + z1; output[i][6] = tmp13 - z1; tmp10 = tmp4 + tmp5; tmp11 = tmp5 + tmp6; tmp12 = tmp6 + tmp7; z5 = (tmp10 - tmp12) * 0.382683433; z2 = 0.541196100 * tmp10 + z5; z4 = 1.306562965 * tmp12 + z5; z3 = tmp11 * 0.707106781; z11 = tmp7 + z3; z13 = tmp7 - z3; output[i][5] = z13 + z2; output[i][3] = z13 - z2; output[i][1] = z11 + z4; output[i][7] = z11 - z4; } for (i = 0; i < 8; i++) { tmp0 = output[0][i] + output[7][i]; tmp7 = output[0][i] - output[7][i]; tmp1 = output[1][i] + output[6][i]; tmp6 = output[1][i] - output[6][i]; tmp2 = output[2][i] + output[5][i]; tmp5 = output[2][i] - output[5][i]; tmp3 = output[3][i] + output[4][i]; tmp4 = output[3][i] - output[4][i]; tmp10 = tmp0 + tmp3; tmp13 = tmp0 - tmp3; tmp11 = tmp1 + tmp2; tmp12 = tmp1 - tmp2; output[0][i] = tmp10 + tmp11; output[4][i] = tmp10 - tmp11; z1 = (tmp12 + tmp13) * 0.707106781; output[2][i] = tmp13 + z1; output[6][i] = tmp13 - z1; tmp10 = tmp4 + tmp5; tmp11 = tmp5 + tmp6; tmp12 = tmp6 + tmp7; z5 = (tmp10 - tmp12) * 0.382683433; z2 = 0.541196100 * tmp10 + z5; z4 = 1.306562965 * tmp12 + z5; z3 = tmp11 * 0.707106781; z11 = tmp7 + z3; z13 = tmp7 - z3; output[5][i] = z13 + z2; output[3][i] = z13 - z2; output[1][i] = z11 + z4; output[7][i] = z11 - z4; } return output; }
872afcca-7220-4d3e-b4c9-acebcbc93888
public double[][] forwardDCTExtreme(final float input[][]) { final double output[][] = new double[this.N][this.N]; final double tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; final double tmp10, tmp11, tmp12, tmp13; final double z1, z2, z3, z4, z5, z11, z13; final int i; final int j; int v, u, x, y; for (v = 0; v < 8; v++) { for (u = 0; u < 8; u++) { for (x = 0; x < 8; x++) { for (y = 0; y < 8; y++) { output[v][u] += input[x][y] * Math.cos((double) (2 * x + 1) * (double) u * Math.PI / 16) * Math.cos((double) (2 * y + 1) * (double) v * Math.PI / 16); } } output[v][u] *= 0.25 * (u == 0 ? 1.0 / Math.sqrt(2) : (double) 1.0) * (v == 0 ? 1.0 / Math.sqrt(2) : (double) 1.0); } } return output; }
b1445843-6664-4a15-b817-3b0831fff6c3
private void initMatrix(final int quality) { final double[] AANscaleFactor = { 1.0, 1.387039845, 1.306562965, 1.175875602, 1.0, 0.785694958, 0.541196100, 0.275899379 }; int i; int j; int index; int Quality; int temp; // converting quality setting to that specified in the // jpeg_quality_scaling // method in the IJG Jpeg-6a C libraries Quality = quality; if (Quality <= 0) { Quality = 1; } if (Quality > 100) { Quality = 100; } if (Quality < 50) { Quality = 5000 / Quality; } else { Quality = 200 - Quality * 2; } // Creating the luminance matrix this.quantum_luminance[0] = 16; this.quantum_luminance[1] = 11; this.quantum_luminance[2] = 10; this.quantum_luminance[3] = 16; this.quantum_luminance[4] = 24; this.quantum_luminance[5] = 40; this.quantum_luminance[6] = 51; this.quantum_luminance[7] = 61; this.quantum_luminance[8] = 12; this.quantum_luminance[9] = 12; this.quantum_luminance[10] = 14; this.quantum_luminance[11] = 19; this.quantum_luminance[12] = 26; this.quantum_luminance[13] = 58; this.quantum_luminance[14] = 60; this.quantum_luminance[15] = 55; this.quantum_luminance[16] = 14; this.quantum_luminance[17] = 13; this.quantum_luminance[18] = 16; this.quantum_luminance[19] = 24; this.quantum_luminance[20] = 40; this.quantum_luminance[21] = 57; this.quantum_luminance[22] = 69; this.quantum_luminance[23] = 56; this.quantum_luminance[24] = 14; this.quantum_luminance[25] = 17; this.quantum_luminance[26] = 22; this.quantum_luminance[27] = 29; this.quantum_luminance[28] = 51; this.quantum_luminance[29] = 87; this.quantum_luminance[30] = 80; this.quantum_luminance[31] = 62; this.quantum_luminance[32] = 18; this.quantum_luminance[33] = 22; this.quantum_luminance[34] = 37; this.quantum_luminance[35] = 56; this.quantum_luminance[36] = 68; this.quantum_luminance[37] = 109; this.quantum_luminance[38] = 103; this.quantum_luminance[39] = 77; this.quantum_luminance[40] = 24; this.quantum_luminance[41] = 35; this.quantum_luminance[42] = 55; this.quantum_luminance[43] = 64; this.quantum_luminance[44] = 81; this.quantum_luminance[45] = 104; this.quantum_luminance[46] = 113; this.quantum_luminance[47] = 92; this.quantum_luminance[48] = 49; this.quantum_luminance[49] = 64; this.quantum_luminance[50] = 78; this.quantum_luminance[51] = 87; this.quantum_luminance[52] = 103; this.quantum_luminance[53] = 121; this.quantum_luminance[54] = 120; this.quantum_luminance[55] = 101; this.quantum_luminance[56] = 72; this.quantum_luminance[57] = 92; this.quantum_luminance[58] = 95; this.quantum_luminance[59] = 98; this.quantum_luminance[60] = 112; this.quantum_luminance[61] = 100; this.quantum_luminance[62] = 103; this.quantum_luminance[63] = 99; for (j = 0; j < 64; j++) { temp = (this.quantum_luminance[j] * Quality + 50) / 100; if (temp <= 0) { temp = 1; } if (temp > 255) { temp = 255; } this.quantum_luminance[j] = temp; } index = 0; for (i = 0; i < 8; i++) { for (j = 0; j < 8; j++) { // The divisors for the LL&M method (the slow integer method // used in // jpeg 6a library). This method is currently (04/04/98) // incompletely // implemented. // DivisorsLuminance[index] = ((double) // quantum_luminance[index]) << 3; // The divisors for the AAN method (the float method used in // jpeg 6a library. this.DivisorsLuminance[index] = 1.0 / (this.quantum_luminance[index] * AANscaleFactor[i] * AANscaleFactor[j] * 8.0); index++; } } // Creating the chrominance matrix this.quantum_chrominance[0] = 17; this.quantum_chrominance[1] = 18; this.quantum_chrominance[2] = 24; this.quantum_chrominance[3] = 47; this.quantum_chrominance[4] = 99; this.quantum_chrominance[5] = 99; this.quantum_chrominance[6] = 99; this.quantum_chrominance[7] = 99; this.quantum_chrominance[8] = 18; this.quantum_chrominance[9] = 21; this.quantum_chrominance[10] = 26; this.quantum_chrominance[11] = 66; this.quantum_chrominance[12] = 99; this.quantum_chrominance[13] = 99; this.quantum_chrominance[14] = 99; this.quantum_chrominance[15] = 99; this.quantum_chrominance[16] = 24; this.quantum_chrominance[17] = 26; this.quantum_chrominance[18] = 56; this.quantum_chrominance[19] = 99; this.quantum_chrominance[20] = 99; this.quantum_chrominance[21] = 99; this.quantum_chrominance[22] = 99; this.quantum_chrominance[23] = 99; this.quantum_chrominance[24] = 47; this.quantum_chrominance[25] = 66; this.quantum_chrominance[26] = 99; this.quantum_chrominance[27] = 99; this.quantum_chrominance[28] = 99; this.quantum_chrominance[29] = 99; this.quantum_chrominance[30] = 99; this.quantum_chrominance[31] = 99; this.quantum_chrominance[32] = 99; this.quantum_chrominance[33] = 99; this.quantum_chrominance[34] = 99; this.quantum_chrominance[35] = 99; this.quantum_chrominance[36] = 99; this.quantum_chrominance[37] = 99; this.quantum_chrominance[38] = 99; this.quantum_chrominance[39] = 99; this.quantum_chrominance[40] = 99; this.quantum_chrominance[41] = 99; this.quantum_chrominance[42] = 99; this.quantum_chrominance[43] = 99; this.quantum_chrominance[44] = 99; this.quantum_chrominance[45] = 99; this.quantum_chrominance[46] = 99; this.quantum_chrominance[47] = 99; this.quantum_chrominance[48] = 99; this.quantum_chrominance[49] = 99; this.quantum_chrominance[50] = 99; this.quantum_chrominance[51] = 99; this.quantum_chrominance[52] = 99; this.quantum_chrominance[53] = 99; this.quantum_chrominance[54] = 99; this.quantum_chrominance[55] = 99; this.quantum_chrominance[56] = 99; this.quantum_chrominance[57] = 99; this.quantum_chrominance[58] = 99; this.quantum_chrominance[59] = 99; this.quantum_chrominance[60] = 99; this.quantum_chrominance[61] = 99; this.quantum_chrominance[62] = 99; this.quantum_chrominance[63] = 99; for (j = 0; j < 64; j++) { temp = (this.quantum_chrominance[j] * Quality + 50) / 100; if (temp <= 0) { temp = 1; } if (temp >= 255) { temp = 255; } this.quantum_chrominance[j] = temp; } index = 0; for (i = 0; i < 8; i++) { for (j = 0; j < 8; j++) { // The divisors for the LL&M method (the slow integer method // used in // jpeg 6a library). This method is currently (04/04/98) // incompletely // implemented. // DivisorsChrominance[index] = ((double) // quantum_chrominance[index]) << 3; // The divisors for the AAN method (the float method used in // jpeg 6a library. this.DivisorsChrominance[index] = 1.0 / (this.quantum_chrominance[index] * AANscaleFactor[i] * AANscaleFactor[j] * 8.0); index++; } } // quantum and Divisors are objects used to hold the appropriate matices this.quantum[0] = this.quantum_luminance; this.Divisors[0] = this.DivisorsLuminance; this.quantum[1] = this.quantum_chrominance; this.Divisors[1] = this.DivisorsChrominance; }
a9cb057b-f0a3-451f-aa60-66ef04de5ca8
public int[] quantizeBlock(final double inputData[][], final int code) { final int outputData[] = new int[this.N * this.N]; int i, j; int index; index = 0; for (i = 0; i < 8; i++) { for (j = 0; j < 8; j++) { // The second line results in significantly better compression. outputData[index] = (int) Math.round(inputData[i][j] * ((double[]) this.Divisors[code])[index]); // outputData[index] = (int)(((inputData[i][j] * (((double[]) // (Divisors[code]))[index])) + 16384.5) -16384); index++; } } return outputData; }
69fad664-035f-4089-bac1-a2535a352167
public int[] quantizeBlockExtreme(final double inputData[][], final int code) { final int outputData[] = new int[this.N * this.N]; int i, j; int index; index = 0; for (i = 0; i < 8; i++) { for (j = 0; j < 8; j++) { outputData[index] = (int) Math.round(inputData[i][j] / ((int[]) this.quantum[code])[index]); index++; } } return outputData; }
4a1692a8-5446-4ebc-8e2d-4115dc486b50
public Huffman(final int Width, final int Height) { this.bits = new Vector<int[]>(); this.bits.addElement(this.bitsDCluminance); this.bits.addElement(this.bitsACluminance); this.bits.addElement(this.bitsDCchrominance); this.bits.addElement(this.bitsACchrominance); this.val = new Vector<int[]>(); this.val.addElement(this.valDCluminance); this.val.addElement(this.valACluminance); this.val.addElement(this.valDCchrominance); this.val.addElement(this.valACchrominance); initHuf(); this.ImageWidth = Width; this.ImageHeight = Height; }
b71e7b05-4fd5-4e10-aea6-31d1298d85dc
void bufferIt(final BufferedOutputStream outStream, final int code, final int size) { int PutBuffer = code; int PutBits = this.bufferPutBits; PutBuffer &= (1 << size) - 1; PutBits += size; PutBuffer <<= 24 - PutBits; PutBuffer |= this.bufferPutBuffer; while (PutBits >= 8) { final int c = PutBuffer >> 16 & 0xFF; try { outStream.write(c); } catch (final IOException e) { System.out.println("IO Error: " + e.getMessage()); } if (c == 0xFF) { try { outStream.write(0); } catch (final IOException e) { System.out.println("IO Error: " + e.getMessage()); } } PutBuffer <<= 8; PutBits -= 8; } this.bufferPutBuffer = PutBuffer; this.bufferPutBits = PutBits; }
b8c110dd-a700-4e98-8878-93c90c1b1bfc
void flushBuffer(final BufferedOutputStream outStream) { int PutBuffer = this.bufferPutBuffer; int PutBits = this.bufferPutBits; while (PutBits >= 8) { final int c = PutBuffer >> 16 & 0xFF; try { outStream.write(c); } catch (final IOException e) { System.out.println("IO Error: " + e.getMessage()); } if (c == 0xFF) { try { outStream.write(0); } catch (final IOException e) { System.out.println("IO Error: " + e.getMessage()); } } PutBuffer <<= 8; PutBits -= 8; } if (PutBits > 0) { final int c = PutBuffer >> 16 & 0xFF; try { outStream.write(c); } catch (final IOException e) { System.out.println("IO Error: " + e.getMessage()); } } }
1a07ddcb-fbbf-4c9d-a4a0-2ca7f45b055a
public void HuffmanBlockEncoder(final BufferedOutputStream outStream, final int zigzag[], final int prec, final int DCcode, final int ACcode) { int temp, temp2, nbits, k, r, i; this.NumOfDCTables = 2; this.NumOfACTables = 2; // The DC portion temp = temp2 = zigzag[0] - prec; if (temp < 0) { temp = -temp; temp2--; } nbits = 0; while (temp != 0) { nbits++; temp >>= 1; } // if (nbits > 11) nbits = 11; bufferIt(outStream, ((int[][]) this.DC_matrix[DCcode])[nbits][0], ((int[][]) this.DC_matrix[DCcode])[nbits][1]); // The arguments in bufferIt are code and size. if (nbits != 0) { bufferIt(outStream, temp2, nbits); } // The AC portion r = 0; for (k = 1; k < 64; k++) { if ((temp = zigzag[jpegNaturalOrder[k]]) == 0) { r++; } else { while (r > 15) { bufferIt(outStream, ((int[][]) this.AC_matrix[ACcode])[0xF0][0], ((int[][]) this.AC_matrix[ACcode])[0xF0][1]); r -= 16; } temp2 = temp; if (temp < 0) { temp = -temp; temp2--; } nbits = 1; while ((temp >>= 1) != 0) { nbits++; } i = (r << 4) + nbits; bufferIt(outStream, ((int[][]) this.AC_matrix[ACcode])[i][0], ((int[][]) this.AC_matrix[ACcode])[i][1]); bufferIt(outStream, temp2, nbits); r = 0; } } if (r > 0) { bufferIt(outStream, ((int[][]) this.AC_matrix[ACcode])[0][0], ((int[][]) this.AC_matrix[ACcode])[0][1]); } }
f13958bd-4dd7-45b5-b616-51e848629d8d
public void initHuf() { this.DC_matrix0 = new int[12][2]; this.DC_matrix1 = new int[12][2]; this.AC_matrix0 = new int[255][2]; this.AC_matrix1 = new int[255][2]; this.DC_matrix = new Object[2]; this.AC_matrix = new Object[2]; int p, l, i, lastp, si, code; final int[] huffsize = new int[257]; final int[] huffcode = new int[257]; /* * init of the DC values for the chrominance [][0] is the code [][1] is * the number of bit */ p = 0; for (l = 1; l <= 16; l++) { for (i = 1; i <= this.bitsDCchrominance[l]; i++) { huffsize[p++] = l; } } huffsize[p] = 0; lastp = p; code = 0; si = huffsize[0]; p = 0; while (huffsize[p] != 0) { while (huffsize[p] == si) { huffcode[p++] = code; code++; } code <<= 1; si++; } for (p = 0; p < lastp; p++) { this.DC_matrix1[this.valDCchrominance[p]][0] = huffcode[p]; this.DC_matrix1[this.valDCchrominance[p]][1] = huffsize[p]; } /* * Init of the AC hufmann code for the chrominance matrix [][][0] is the * code & matrix[][][1] is the number of bit needed */ p = 0; for (l = 1; l <= 16; l++) { for (i = 1; i <= this.bitsACchrominance[l]; i++) { huffsize[p++] = l; } } huffsize[p] = 0; lastp = p; code = 0; si = huffsize[0]; p = 0; while (huffsize[p] != 0) { while (huffsize[p] == si) { huffcode[p++] = code; code++; } code <<= 1; si++; } for (p = 0; p < lastp; p++) { this.AC_matrix1[this.valACchrominance[p]][0] = huffcode[p]; this.AC_matrix1[this.valACchrominance[p]][1] = huffsize[p]; } /* * init of the DC values for the luminance [][0] is the code [][1] is * the number of bit */ p = 0; for (l = 1; l <= 16; l++) { for (i = 1; i <= this.bitsDCluminance[l]; i++) { huffsize[p++] = l; } } huffsize[p] = 0; lastp = p; code = 0; si = huffsize[0]; p = 0; while (huffsize[p] != 0) { while (huffsize[p] == si) { huffcode[p++] = code; code++; } code <<= 1; si++; } for (p = 0; p < lastp; p++) { this.DC_matrix0[this.valDCluminance[p]][0] = huffcode[p]; this.DC_matrix0[this.valDCluminance[p]][1] = huffsize[p]; } /* * Init of the AC hufmann code for luminance matrix [][][0] is the code * & matrix[][][1] is the number of bit */ p = 0; for (l = 1; l <= 16; l++) { for (i = 1; i <= this.bitsACluminance[l]; i++) { huffsize[p++] = l; } } huffsize[p] = 0; lastp = p; code = 0; si = huffsize[0]; p = 0; while (huffsize[p] != 0) { while (huffsize[p] == si) { huffcode[p++] = code; code++; } code <<= 1; si++; } for (int q = 0; q < lastp; q++) { this.AC_matrix0[this.valACluminance[q]][0] = huffcode[q]; this.AC_matrix0[this.valACluminance[q]][1] = huffsize[q]; } this.DC_matrix[0] = this.DC_matrix0; this.DC_matrix[1] = this.DC_matrix1; this.AC_matrix[0] = this.AC_matrix0; this.AC_matrix[1] = this.AC_matrix1; }
d1ace73b-480f-4236-a4da-b5d441174098
public JpegEncoder(final Image image, final int quality, final OutputStream out, final String comment) { final MediaTracker tracker = new MediaTracker(this); tracker.addImage(image, 0); try { tracker.waitForID(0); } catch (final InterruptedException e) { // Got to do something? } /* * Quality of the image. 0 to 100 and from bad image quality, high * compression to good image quality low compression */ this.Quality = quality; /* * Getting picture information It takes the Width, Height and RGB scans * of the image. */ this.JpegObj = new JpegInfo(image, comment); this.imageHeight = this.JpegObj.imageHeight; this.imageWidth = this.JpegObj.imageWidth; this.outStream = new BufferedOutputStream(out); this.dct = new DCT(this.Quality); this.Huf = new Huffman(this.imageWidth, this.imageHeight); }
4746d860-89ba-4d29-b198-35a7e3e5d395
public void Compress() { WriteHeaders(this.outStream); WriteCompressedData(this.outStream); WriteEOI(this.outStream); try { this.outStream.flush(); } catch (final IOException e) { System.out.println("IO Error: " + e.getMessage()); } }
25ddb771-42fa-497c-bd18-eae1c9f861ab
public void Compress(final InputStream embeddedData, final String password) { this.embeddedData = embeddedData; this.password = password; Compress(); }
0af70c28-5b7c-40fd-b21f-2320c8c866e1
public int getQuality() { return this.Quality; }
3f93bbf0-d3e7-4da0-b9bb-4d25e8dc8ecc
public void setQuality(final int quality) { this.dct = new DCT(quality); }
978982cc-fea1-4918-91dd-8773d69b15bb
void WriteArray(final byte[] data, final BufferedOutputStream out) { final int i; int length; try { length = ((data[2] & 0xFF) << 8) + (data[3] & 0xFF) + 2; out.write(data, 0, length); } catch (final IOException e) { System.out.println("IO Error: " + e.getMessage()); } }
d3d665d1-1178-4150-a14b-b16fb2922b3c
public void WriteCompressedData(final BufferedOutputStream outStream) { final int offset; int i, j, r, c, a, b; final int temp = 0; int comp, xpos, ypos, xblockoffset, yblockoffset; float inputArray[][]; final float dctArray1[][] = new float[8][8]; double dctArray2[][] = new double[8][8]; int dctArray3[] = new int[8 * 8]; /* * This method controls the compression of the image. Starting at the * upper left of the image, it compresses 8x8 blocks of data until the * entire image has been compressed. */ final int lastDCvalue[] = new int[this.JpegObj.NumberOfComponents]; final int zeroArray[] = new int[64]; // initialized to hold all zeros int Width = 0, Height = 0; final int nothing = 0, not; int MinBlockWidth, MinBlockHeight; // This initial setting of MinBlockWidth and MinBlockHeight is done to // ensure they start with values larger than will actually be the case. MinBlockWidth = this.imageWidth % 8 != 0 ? (int) (Math.floor(this.imageWidth / 8.0) + 1) * 8 : this.imageWidth; MinBlockHeight = this.imageHeight % 8 != 0 ? (int) (Math.floor(this.imageHeight / 8.0) + 1) * 8 : this.imageHeight; for (comp = 0; comp < this.JpegObj.NumberOfComponents; comp++) { MinBlockWidth = Math.min(MinBlockWidth, this.JpegObj.BlockWidth[comp]); MinBlockHeight = Math.min(MinBlockHeight, this.JpegObj.BlockHeight[comp]); } xpos = 0; // westfeld // Before we enter these loops, we initialise the // coeff for steganography here: int shuffledIndex = 0; int coeffCount = 0; for (r = 0; r < MinBlockHeight; r++) { for (c = 0; c < MinBlockWidth; c++) { for (comp = 0; comp < this.JpegObj.NumberOfComponents; comp++) { for (i = 0; i < this.JpegObj.VsampFactor[comp]; i++) { for (j = 0; j < this.JpegObj.HsampFactor[comp]; j++) { coeffCount += 64; } } } } } final int coeff[] = new int[coeffCount]; System.out.println("DCT/quantisation starts"); System.out.println(this.imageWidth + " x " + this.imageHeight); for (r = 0; r < MinBlockHeight; r++) { for (c = 0; c < MinBlockWidth; c++) { xpos = c * 8; ypos = r * 8; for (comp = 0; comp < this.JpegObj.NumberOfComponents; comp++) { Width = this.JpegObj.BlockWidth[comp]; Height = this.JpegObj.BlockHeight[comp]; inputArray = (float[][]) this.JpegObj.Components[comp]; for (i = 0; i < this.JpegObj.VsampFactor[comp]; i++) { for (j = 0; j < this.JpegObj.HsampFactor[comp]; j++) { xblockoffset = j * 8; yblockoffset = i * 8; for (a = 0; a < 8; a++) { for (b = 0; b < 8; b++) { // I believe this is where the dirty line at // the bottom of the image is // coming from. I need to do a check here to // make sure I'm not reading past // image data. // This seems to not be a big issue right // now. (04/04/98) // westfeld - dirty line fixed, Jun 6 2000 int ia = ypos * this.JpegObj.VsampFactor[comp] + yblockoffset + a; int ib = xpos * this.JpegObj.HsampFactor[comp] + xblockoffset + b; if (this.imageHeight / 2 * this.JpegObj.VsampFactor[comp] <= ia) { ia = this.imageHeight / 2 * this.JpegObj.VsampFactor[comp] - 1; } if (this.imageWidth / 2 * this.JpegObj.HsampFactor[comp] <= ib) { ib = this.imageWidth / 2 * this.JpegObj.HsampFactor[comp] - 1; } // dctArray1[a][b] = inputArray[ypos + // yblockoffset + a][xpos + xblockoffset + // b]; dctArray1[a][b] = inputArray[ia][ib]; } } // The following code commented out because on some // images this technique // results in poor right and bottom borders. // if ((!JpegObj.lastColumnIsDummy[comp] || c < // Width - 1) && (!JpegObj.lastRowIsDummy[comp] || r // < Height - 1)) { dctArray2 = this.dct.forwardDCT(dctArray1); dctArray3 = this.dct.quantizeBlock(dctArray2, this.JpegObj.QtableNumber[comp]); // } // else { // zeroArray[0] = dctArray3[0]; // zeroArray[0] = lastDCvalue[comp]; // dctArray3 = zeroArray; // } // westfeld // For steganography, all dct // coefficients are collected in // coeff[] first. We do not encode // any Huffman Blocks here (we'll do // this later). System.arraycopy(dctArray3, 0, coeff, shuffledIndex, 64); shuffledIndex += 64; } } } } } System.out.println("got " + coeffCount + " DCT AC/DC coefficients"); int _changed = 0; int _embedded = 0; int _examined = 0; int _expected = 0; int _one = 0; int _large = 0; int _thrown = 0; int _zero = 0; for (i = 0; i < coeffCount; i++) { if (i % 64 == 0) { continue; } if (coeff[i] == 1) { _one++; } if (coeff[i] == -1) { _one++; } if (coeff[i] == 0) { _zero++; } } _large = coeffCount - _zero - _one - coeffCount / 64; _expected = _large + (int) (0.49 * _one); // // System.out.println("zero="+_zero); System.out.println("one=" + _one); System.out.println("large=" + _large); // System.out.println("expected capacity: " + _expected + " bits"); System.out.println("expected capacity with"); for (i = 1; i < 8; i++) { int usable, changed, n; n = (1 << i) - 1; usable = _expected * i / n - _expected * i / n % n; changed = coeffCount - _zero - coeffCount / 64; changed = changed * i / n - changed * i / n % n; changed = n * changed / (n + 1) / i; // changed = _large - _large % (n + 1); changed = (changed + _one + _one / 2 - _one / (n + 1)) / (n + 1); usable /= 8; if (usable == 0) { break; } if (i == 1) { System.out.print("default"); } else { System.out.print("(1, " + n + ", " + i + ")"); } System.out.println(" code: " + usable + " bytes (efficiency: " + usable * 8 / changed + "." + usable * 80 / changed % 10 + " bits per change)"); } // westfeld if (this.embeddedData != null) { // Now we embed the secret data in the permutated sequence. System.out.println("Permutation starts"); final F5Random random = new F5Random(this.password.getBytes()); final Permutation permutation = new Permutation(coeffCount, random); int nextBitToEmbed = 0; int byteToEmbed = 0; int availableBitsToEmbed = 0; // We start with the length information. Well, // the length information it is more than one // byte, so this first "byte" is 32 bits long. try { byteToEmbed = this.embeddedData.available(); } catch (final Exception e) { e.printStackTrace(); } System.out.print("Embedding of " + (byteToEmbed * 8 + 32) + " bits (" + byteToEmbed + "+4 bytes) "); // We use the most significant byte for the 1 of n // code, and reserve one extra bit for future use. if (byteToEmbed > 0x007fffff) { byteToEmbed = 0x007fffff; } // We calculate n now for (i = 1; i < 8; i++) { int usable; final int changed; this.n = (1 << i) - 1; usable = _expected * i / this.n - _expected * i / this.n % this.n; usable /= 8; if (usable == 0) { break; } if (usable < byteToEmbed + 4) { break; } } final int k = i - 1; this.n = (1 << k) - 1; switch (this.n) { case 0: System.out.println("using default code, file will not fit"); this.n++; break; case 1: System.out.println("using default code"); break; default: System.out.println("using (1, " + this.n + ", " + k + ") code"); } byteToEmbed |= k << 24; // store k in the status word // Since shuffling cannot hide the distribution, the // distribution of all bits to embed is unified by // adding a pseudo random bit-string. We continue the random // we used for Permutation, initially seeked with password. byteToEmbed ^= random.getNextByte(); byteToEmbed ^= random.getNextByte() << 8; byteToEmbed ^= random.getNextByte() << 16; byteToEmbed ^= random.getNextByte() << 24; nextBitToEmbed = byteToEmbed & 1; byteToEmbed >>= 1; availableBitsToEmbed = 31; _embedded++; if (this.n > 1) { // use 1 of n code int kBitsToEmbed; int extractedBit; final int[] codeWord = new int[this.n]; int hash; int startOfN = 0; int endOfN = 0; boolean isLastByte = false; // embed status word first for (i = 0; i < coeffCount; i++) { shuffledIndex = permutation.getShuffled(i); if (shuffledIndex % 64 == 0) { continue; // skip DC coefficients } if (coeff[shuffledIndex] == 0) { continue; // skip zeroes } if (coeff[shuffledIndex] > 0) { if ((coeff[shuffledIndex] & 1) != nextBitToEmbed) { coeff[shuffledIndex]--; // decrease absolute value _changed++; } } else { if ((coeff[shuffledIndex] & 1) == nextBitToEmbed) { coeff[shuffledIndex]++; // decrease absolute value _changed++; } } if (coeff[shuffledIndex] != 0) { // The coefficient is still nonzero. We // successfully embedded "nextBitToEmbed". // We will read a new bit to embed now. if (availableBitsToEmbed == 0) { break; // statusword embedded. } nextBitToEmbed = byteToEmbed & 1; byteToEmbed >>= 1; availableBitsToEmbed--; _embedded++; } else { _thrown++; } } startOfN = i + 1; // now embed the data using 1 of n code embeddingLoop: do { kBitsToEmbed = 0; // get k bits to embed for (i = 0; i < k; i++) { if (availableBitsToEmbed == 0) { // If the byte of embedded text is // empty, we will get a new one. try { if (this.embeddedData.available() == 0) { isLastByte = true; break; } byteToEmbed = this.embeddedData.read(); byteToEmbed ^= random.getNextByte(); } catch (final Exception e) { e.printStackTrace(); break; } availableBitsToEmbed = 8; } nextBitToEmbed = byteToEmbed & 1; byteToEmbed >>= 1; availableBitsToEmbed--; kBitsToEmbed |= nextBitToEmbed << i; _embedded++; } // embed k bits do { j = startOfN; // fill codeWord[] with the indices of the // next n non-zero coefficients in coeff[] for (i = 0; i < this.n; j++) { if (j >= coeffCount) { // in rare cases the estimated capacity is too // small System.out.println("Capacity exhausted."); break embeddingLoop; } shuffledIndex = permutation.getShuffled(j); if (shuffledIndex % 64 == 0) { continue; // skip DC coefficients } if (coeff[shuffledIndex] == 0) { continue; // skip zeroes } codeWord[i++] = shuffledIndex; } endOfN = j; hash = 0; for (i = 0; i < this.n; i++) { if (coeff[codeWord[i]] > 0) { extractedBit = coeff[codeWord[i]] & 1; } else { extractedBit = 1 - (coeff[codeWord[i]] & 1); } if (extractedBit == 1) { hash ^= i + 1; } } i = hash ^ kBitsToEmbed; if (i == 0) { break; // embedded without change } i--; if (coeff[codeWord[i]] > 0) { coeff[codeWord[i]]--; } else { coeff[codeWord[i]]++; } _changed++; if (coeff[codeWord[i]] == 0) { _thrown++; } } while (coeff[codeWord[i]] == 0); startOfN = endOfN; } while (!isLastByte); } else { // default code // The main embedding loop follows. It works on the // shuffled stream of coefficients. for (i = 0; i < coeffCount; i++) { shuffledIndex = permutation.getShuffled(i); if (shuffledIndex % 64 == 0) { continue; // skip DC coefficients } if (coeff[shuffledIndex] == 0) { continue; // skip zeroes } _examined++; if (coeff[shuffledIndex] > 0) { if ((coeff[shuffledIndex] & 1) != nextBitToEmbed) { coeff[shuffledIndex]--; // decrease absolute value _changed++; } } else { if ((coeff[shuffledIndex] & 1) == nextBitToEmbed) { coeff[shuffledIndex]++; // decrease absolute value _changed++; } } if (coeff[shuffledIndex] != 0) { // The coefficient is still nonzero. We // successfully embedded "nextBitToEmbed". // We will read a new bit to embed now. if (availableBitsToEmbed == 0) { // If the byte of embedded text is // empty, we will get a new one. try { if (this.embeddedData.available() == 0) { break; } byteToEmbed = this.embeddedData.read(); byteToEmbed ^= random.getNextByte(); } catch (final Exception e) { e.printStackTrace(); break; } availableBitsToEmbed = 8; } nextBitToEmbed = byteToEmbed & 1; byteToEmbed >>= 1; availableBitsToEmbed--; _embedded++; } else { _thrown++; } } } if (_examined > 0) { System.out.println(_examined + " coefficients examined"); } System.out.println(_changed + " coefficients changed (efficiency: " + _embedded / _changed + "." + _embedded * 10 / _changed % 10 + " bits per change)"); System.out.println(_thrown + " coefficients thrown (zeroed)"); System.out.println(_embedded + " bits (" + _embedded / 8 + " bytes) embedded"); } System.out.println("Starting Huffman Encoding."); // Do the Huffman Encoding now. shuffledIndex = 0; for (r = 0; r < MinBlockHeight; r++) { for (c = 0; c < MinBlockWidth; c++) { for (comp = 0; comp < this.JpegObj.NumberOfComponents; comp++) { for (i = 0; i < this.JpegObj.VsampFactor[comp]; i++) { for (j = 0; j < this.JpegObj.HsampFactor[comp]; j++) { System.arraycopy(coeff, shuffledIndex, dctArray3, 0, 64); this.Huf.HuffmanBlockEncoder(outStream, dctArray3, lastDCvalue[comp], this.JpegObj.DCtableNumber[comp], this.JpegObj.ACtableNumber[comp]); lastDCvalue[comp] = dctArray3[0]; shuffledIndex += 64; } } } } } this.Huf.flushBuffer(outStream); }
ef258749-e7bb-418c-8654-a5bc906286b9
public void WriteEOI(final BufferedOutputStream out) { final byte[] EOI = { (byte) 0xFF, (byte) 0xD9 }; WriteMarker(EOI, out); }
b968e9d6-5d15-4d1f-86ff-f30093197c7d
public void WriteHeaders(final BufferedOutputStream out) { int i, j, index, offset, length; int tempArray[]; // the SOI marker final byte[] SOI = { (byte) 0xFF, (byte) 0xD8 }; WriteMarker(SOI, out); // The order of the following headers is quiet inconsequential. // the JFIF header final byte JFIF[] = new byte[18]; JFIF[0] = (byte) 0xff; // app0 marker JFIF[1] = (byte) 0xe0; JFIF[2] = (byte) 0x00; // length JFIF[3] = (byte) 0x10; JFIF[4] = (byte) 0x4a; // "JFIF" JFIF[5] = (byte) 0x46; JFIF[6] = (byte) 0x49; JFIF[7] = (byte) 0x46; JFIF[8] = (byte) 0x00; JFIF[9] = (byte) 0x01; // 1.01 JFIF[10] = (byte) 0x01; JFIF[11] = (byte) 0x00; JFIF[12] = (byte) 0x00; JFIF[13] = (byte) 0x01; JFIF[14] = (byte) 0x00; JFIF[15] = (byte) 0x01; JFIF[16] = (byte) 0x00; JFIF[17] = (byte) 0x00; if (this.JpegObj.getComment().equals("TEST")) { JFIF[10] = (byte) 0x00; // 1.00 } WriteArray(JFIF, out); // Comment Header String comment = new String(); comment = this.JpegObj.getComment(); length = comment.length(); if (length != 0) { final byte COM[] = new byte[length + 4]; COM[0] = (byte) 0xFF; COM[1] = (byte) 0xFE; COM[2] = (byte) (length >> 8 & 0xFF); COM[3] = (byte) (length & 0xFF); java.lang.System.arraycopy(this.JpegObj.Comment.getBytes(), 0, COM, 4, this.JpegObj.Comment.length()); WriteArray(COM, out); } // The DQT header // 0 is the luminance index and 1 is the chrominance index final byte DQT[] = new byte[134]; DQT[0] = (byte) 0xFF; DQT[1] = (byte) 0xDB; DQT[2] = (byte) 0x00; DQT[3] = (byte) 0x84; offset = 4; for (i = 0; i < 2; i++) { DQT[offset++] = (byte) ((0 << 4) + i); tempArray = (int[]) this.dct.quantum[i]; for (j = 0; j < 64; j++) { DQT[offset++] = (byte) tempArray[jpegNaturalOrder[j]]; } } WriteArray(DQT, out); // Start of Frame Header final byte SOF[] = new byte[19]; SOF[0] = (byte) 0xFF; SOF[1] = (byte) 0xC0; SOF[2] = (byte) 0x00; SOF[3] = (byte) 17; SOF[4] = (byte) this.JpegObj.Precision; SOF[5] = (byte) (this.JpegObj.imageHeight >> 8 & 0xFF); SOF[6] = (byte) (this.JpegObj.imageHeight & 0xFF); SOF[7] = (byte) (this.JpegObj.imageWidth >> 8 & 0xFF); SOF[8] = (byte) (this.JpegObj.imageWidth & 0xFF); SOF[9] = (byte) this.JpegObj.NumberOfComponents; index = 10; for (i = 0; i < SOF[9]; i++) { SOF[index++] = (byte) this.JpegObj.CompID[i]; SOF[index++] = (byte) ((this.JpegObj.HsampFactor[i] << 4) + this.JpegObj.VsampFactor[i]); SOF[index++] = (byte) this.JpegObj.QtableNumber[i]; } WriteArray(SOF, out); // The DHT Header byte DHT1[], DHT2[], DHT3[], DHT4[]; int bytes, temp, oldindex, intermediateindex; length = 2; index = 4; oldindex = 4; DHT1 = new byte[17]; DHT4 = new byte[4]; DHT4[0] = (byte) 0xFF; DHT4[1] = (byte) 0xC4; for (i = 0; i < 4; i++) { bytes = 0; DHT1[index++ - oldindex] = (byte) this.Huf.bits.elementAt(i)[0]; for (j = 1; j < 17; j++) { temp = this.Huf.bits.elementAt(i)[j]; DHT1[index++ - oldindex] = (byte) temp; bytes += temp; } intermediateindex = index; DHT2 = new byte[bytes]; for (j = 0; j < bytes; j++) { DHT2[index++ - intermediateindex] = (byte) this.Huf.val.elementAt(i)[j]; } DHT3 = new byte[index]; java.lang.System.arraycopy(DHT4, 0, DHT3, 0, oldindex); java.lang.System.arraycopy(DHT1, 0, DHT3, oldindex, 17); java.lang.System.arraycopy(DHT2, 0, DHT3, oldindex + 17, bytes); DHT4 = DHT3; oldindex = index; } DHT4[2] = (byte) (index - 2 >> 8 & 0xFF); DHT4[3] = (byte) (index - 2 & 0xFF); WriteArray(DHT4, out); // Start of Scan Header final byte SOS[] = new byte[14]; SOS[0] = (byte) 0xFF; SOS[1] = (byte) 0xDA; SOS[2] = (byte) 0x00; SOS[3] = (byte) 12; SOS[4] = (byte) this.JpegObj.NumberOfComponents; index = 5; for (i = 0; i < SOS[4]; i++) { SOS[index++] = (byte) this.JpegObj.CompID[i]; SOS[index++] = (byte) ((this.JpegObj.DCtableNumber[i] << 4) + this.JpegObj.ACtableNumber[i]); } SOS[index++] = (byte) this.JpegObj.Ss; SOS[index++] = (byte) this.JpegObj.Se; SOS[index++] = (byte) ((this.JpegObj.Ah << 4) + this.JpegObj.Al); WriteArray(SOS, out); }
22da2a07-d5d6-4aea-b4a1-5edc5cf623ec
void WriteMarker(final byte[] data, final BufferedOutputStream out) { try { out.write(data, 0, 2); } catch (final IOException e) { System.out.println("IO Error: " + e.getMessage()); } }
8b40d90e-9a77-496b-a9bf-f1c6eabd4157
public JpegInfo(final Image image, final String comment) { this.Components = new Object[this.NumberOfComponents]; this.compWidth = new int[this.NumberOfComponents]; this.compHeight = new int[this.NumberOfComponents]; this.BlockWidth = new int[this.NumberOfComponents]; this.BlockHeight = new int[this.NumberOfComponents]; this.imageobj = image; this.imageWidth = image.getWidth(null); this.imageHeight = image.getHeight(null); // Comment = // "JPEG Encoder Copyright 1998, James R. Weeks and BioElectroMech. "; this.Comment = comment; getYCCArray(); }
73bc25c0-5f5e-4c8a-93f9-f484e3e28ebf
float[][] DownSample(final float[][] C, final int comp) { int inrow, incol; int outrow, outcol; float output[][]; float temp; int bias; inrow = 0; incol = 0; output = new float[this.compHeight[comp]][this.compWidth[comp]]; for (outrow = 0; outrow < this.compHeight[comp]; outrow++) { bias = 1; for (outcol = 0; outcol < this.compWidth[comp]; outcol++) { // System.out.println("outcol="+outcol); temp = C[inrow][incol++]; // 00 temp += C[inrow++][incol--]; // 01 temp += C[inrow][incol++]; // 10 temp += C[inrow--][incol++] + bias; // 11 -> 02 output[outrow][outcol] = temp / (float) 4.0; bias ^= 3; } inrow += 2; incol = 0; } return output; }
584296fa-7fde-43bd-8f3e-6f3d181464ac
public String getComment() { return this.Comment; }
7f538fe5-5e9a-44fa-8921-86209ef77009
private void getYCCArray() { final int values[] = new int[this.imageWidth * this.imageHeight]; int r, g, b, y, x; // In order to minimize the chance that grabPixels will throw an // exception // it may be necessary to grab some pixels every few scanlines and // process // those before going for more. The time expense may be prohibitive. // However, for a situation where memory overhead is a concern, this may // be // the only choice. final PixelGrabber grabber = new PixelGrabber(this.imageobj.getSource(), 0, 0, this.imageWidth, this.imageHeight, values, 0, this.imageWidth); this.MaxHsampFactor = 1; this.MaxVsampFactor = 1; for (y = 0; y < this.NumberOfComponents; y++) { this.MaxHsampFactor = Math.max(this.MaxHsampFactor, this.HsampFactor[y]); this.MaxVsampFactor = Math.max(this.MaxVsampFactor, this.VsampFactor[y]); } for (y = 0; y < this.NumberOfComponents; y++) { this.compWidth[y] = (this.imageWidth % 8 != 0 ? (int) Math.ceil(this.imageWidth / 8.0) * 8 : this.imageWidth) / this.MaxHsampFactor * this.HsampFactor[y]; if (this.compWidth[y] != this.imageWidth / this.MaxHsampFactor * this.HsampFactor[y]) { this.lastColumnIsDummy[y] = true; } // results in a multiple of 8 for compWidth // this will make the rest of the program fail for the unlikely // event that someone tries to compress an 16 x 16 pixel image // which would of course be worse than pointless this.BlockWidth[y] = (int) Math.ceil(this.compWidth[y] / 8.0); this.compHeight[y] = (this.imageHeight % 8 != 0 ? (int) Math.ceil(this.imageHeight / 8.0) * 8 : this.imageHeight) / this.MaxVsampFactor * this.VsampFactor[y]; if (this.compHeight[y] != this.imageHeight / this.MaxVsampFactor * this.VsampFactor[y]) { this.lastRowIsDummy[y] = true; } this.BlockHeight[y] = (int) Math.ceil(this.compHeight[y] / 8.0); } try { if (grabber.grabPixels() != true) { try { throw new AWTException("Grabber returned false: " + grabber.getStatus()); } catch (final Exception e) { } ; } } catch (final InterruptedException e) { } ; final float Y[][] = new float[this.compHeight[0]][this.compWidth[0]]; final float Cr1[][] = new float[this.compHeight[0]][this.compWidth[0]]; final float Cb1[][] = new float[this.compHeight[0]][this.compWidth[0]]; float Cb2[][] = new float[this.compHeight[1]][this.compWidth[1]]; float Cr2[][] = new float[this.compHeight[2]][this.compWidth[2]]; int index = 0; for (y = 0; y < this.imageHeight; ++y) { for (x = 0; x < this.imageWidth; ++x) { r = values[index] >> 16 & 0xff; g = values[index] >> 8 & 0xff; b = values[index] & 0xff; // The following three lines are a more correct color conversion // but // the current conversion technique is sufficient and results in // a higher // compression rate. // Y[y][x] = 16 + (float)(0.8588*(0.299 * (float)r + 0.587 * // (float)g + 0.114 * (float)b )); // Cb1[y][x] = 128 + (float)(0.8784*(-0.16874 * (float)r - // 0.33126 * (float)g + 0.5 * (float)b)); // Cr1[y][x] = 128 + (float)(0.8784*(0.5 * (float)r - 0.41869 * // (float)g - 0.08131 * (float)b)); Y[y][x] = (float) (0.299 * r + 0.587 * g + 0.114 * b); Cb1[y][x] = 128 + (float) (-0.16874 * r - 0.33126 * g + 0.5 * b); Cr1[y][x] = 128 + (float) (0.5 * r - 0.41869 * g - 0.08131 * b); index++; } } // Need a way to set the H and V sample factors before allowing // downsampling. // For now (04/04/98) downsampling must be hard coded. // Until a better downsampler is implemented, this will not be done. // Downsampling is currently supported. The downsampling method here // is a simple box filter. this.Components[0] = Y; Cb2 = DownSample(Cb1, 1); this.Components[1] = Cb2; Cr2 = DownSample(Cr1, 2); this.Components[2] = Cr2; }
d68f3845-8b3c-40c8-8eac-372f3231c43c
public void setComment(final String comment) { this.Comment.concat(comment); }
387f5260-beaf-4e07-a12f-4d2b8203ebad
public HuffTable(final DataInputStream d, final int l) { this.dis = d; // System.out.println("L�nge="+l); // Get table data from input stream this.Ln = 19 + getTableData(); // System.out.println(Ln); Generate_size_table(); // Flow Chart C.1 Generate_code_table(); // Flow Chart C.2 Order_codes(); // Flow Chart C.3 Decoder_tables(); // Generate decoder tables Flow Chart F.15 }
734b81eb-89d7-4816-a9cf-7ffc994c0d42
private void Decoder_tables() { // Decoder table generation Flow Chart F.15 this.I = 0; this.J = 0; while (true) { if (++this.I > 16) return; if (this.BITS[this.I] == 0) { this.MAXCODE[this.I] = -1; } else { this.VALPTR[this.I] = this.J; this.MINCODE[this.I] = this.HUFFCODE[this.J]; this.J = this.J + this.BITS[this.I] - 1; this.MAXCODE[this.I] = this.HUFFCODE[this.J++]; } } }
7000892d-41d7-462f-aa79-459015792503
private void Generate_code_table() { // Generate Code table Flow Chart C.2 this.K = 0; this.CODE = 0; this.SI = this.HUFFSIZE[0]; while (true) { this.HUFFCODE[this.K++] = this.CODE++; if (this.HUFFSIZE[this.K] == this.SI) { continue; } if (this.HUFFSIZE[this.K] == 0) { break; } while (true) { this.CODE <<= 1; this.SI++; if (this.HUFFSIZE[this.K] == this.SI) { break; } } } }
9dbb81c8-6204-4348-a825-4a9825f14448
private void Generate_size_table() { // Generate HUFFSIZE table Flow Chart C.1 this.K = 0; this.I = 1; this.J = 1; while (true) { if (this.J > this.BITS[this.I]) { this.J = 1; this.I++; if (this.I > 16) { break; } } else { this.HUFFSIZE[this.K++] = this.I; this.J++; } } this.HUFFSIZE[this.K] = 0; this.LASTK = this.K; }
bbbe4c2f-800e-4e84-b094-bfe34a727437
private int getByte() { try { return this.dis.readUnsignedByte(); } catch (final IOException e) { return -1; } }
8ad1480d-0472-4282-9eaa-c3528a984e73
public int[] getHUFFVAL() { return this.HUFFVAL; }
acd6f4e5-029e-4ae0-b627-35d323ba786b
public int getLen() { return this.Ln; }
c9072728-59e1-4e67-b006-84d1dfbcbefb
public int[] getMAXCODE() { return this.MAXCODE; }
e6f26f63-a126-4c59-9178-8d8dcd96cab2
public int[] getMINCODE() { return this.MINCODE; }
d10b8d4b-e3b9-49c7-a524-e72aa7a00567
private int getTableData() { // Get BITS list int count = 0; for (int x = 1; x < 17; x++) { this.BITS[x] = getByte(); count += this.BITS[x]; } // Read in HUFFVAL for (int x = 0; x < count; x++) { // System.out.println(Ln); this.HUFFVAL[x] = getByte(); } return count; }
d90cb175-87bd-471c-91e1-0a3647187f4f
public int[] getVALPTR() { return this.VALPTR; }
15c62df2-10f4-4624-bdc8-442b89db1c2c
private void Order_codes() { // Order Codes Flow Chart C.3 this.K = 0; while (true) { this.I = this.HUFFVAL[this.K]; this.EHUFCO[this.I] = this.HUFFCODE[this.K]; this.EHUFSI[this.I] = this.HUFFSIZE[this.K++]; if (this.K >= this.LASTK) { break; } } }
25562a54-6de7-40f0-91ed-4f91d17937ac
public HuffmanDecode(final byte[] data) { this.size = (short) data.length; this.dis = new DataInputStream(new ByteArrayInputStream(data)); // Parse out markers and header info boolean cont = true; while (cont) { if (255 == getByte()) { switch (getByte()) { case 192: sof0(); break; case 196: dht(); break; case 219: dqt(); break; case 217: cont = false; break; case 218: cont = false; break; case APP0: case APP1: case APP2: case APP3: case APP4: case APP5: case APP6: case APP7: case APP8: case APP9: case APP10: case APP11: case APP12: case APP13: case APP14: case APP15: skipVariable(); break; case DRI: dri(); break; } } } }
9cb1eb49-12b6-46a6-be48-121d0cfccfaa
private int available() { try { return this.dis.available(); } catch (final IOException e) { e.printStackTrace(); } return 0; }
2e317739-f88f-41fd-ae77-2f46b7758526
private void closeStream() { // Close input stream try { this.dis.close(); // close io stream to file } catch (final IOException e) { } }
248a4e63-699b-473a-887a-f8e07fcdfb80
public int[] decode() { final int x, y, a, b, line;// , sz = X * Y; int /* col, */tmp; final int blocks, MCU;// , scan=0; int[] Cs, Ta, Td; final int[] PRED = new int[this.Nf]; for (int nComponent = 0; nComponent < this.Nf; nComponent++) { PRED[nComponent] = 0; } final long t; final double time; this.CNT = 0; // Read in Scan Header information this.Ls = getInt(); this.Ns = getByte(); // System.out.println("SOS - Components: "+Integer.toString(Ns)); Cs = new int[this.Ns]; Td = new int[this.Ns]; Ta = new int[this.Ns]; // get table information for (this.lp = 0; this.lp < this.Ns; this.lp++) { Cs[this.lp] = getByte(); Td[this.lp] = getByte(); Ta[this.lp] = Td[this.lp] & 0x0f; Td[this.lp] >>= 4; // System.out.println("DC-Table: "+Integer.toString(Td[lp])+"AC-Table: "+Integer.toString(Ta[lp])); } this.Ss = getByte(); this.Se = getByte(); this.Ah = getByte(); this.Al = this.Ah & 0x0f; this.Ah >>= 4; // Calculate the Number of blocks encoded // warum doppelt so viel? final int buff[] = new int[2 * 8 * 8 * getBlockCount()]; int pos = 0; int MCUCount = 0; // System.out.println("BlockCount="+getBlockCount()); final boolean bDoIt = true; while (bDoIt) { // Get component 1 of MCU for (int nComponent = 0; nComponent < this.Nf; nComponent++) { for (this.cnt = 0; this.cnt < this.H[nComponent] * this.V[nComponent]; this.cnt++) { // Get DC coefficient this.hftbl = Td[nComponent] * 2; tmp = DECODE(); this.DIFF = RECEIVE(tmp); this.ZZ[0] = PRED[0] + EXTEND(this.DIFF, tmp); PRED[nComponent] = this.ZZ[0]; // Get AC coefficients this.hftbl = Ta[nComponent] * 2 + 1; Decode_AC_coefficients(); for (this.lp = 0; this.lp < 64; this.lp++) { // System.out.println("pos="+pos); // Zickzack??? // buff[pos++]=ZZ[deZigZag[lp]]; buff[pos++] = this.ZZ[this.lp]; } } } MCUCount++; if (MCUCount == this.RI) { MCUCount = 0; this.CNT = 0; for (int nComponent = 0; nComponent < this.Nf; nComponent++) { PRED[nComponent] = 0; } // System.out.println("MCUCount"); getByte(); // System.out.println(Integer.toHexString(getByte())); final int tmpB = getByte(); // System.out.println(Integer.toHexString(tmpB)); if (tmpB == EOI) { break; // System.out.println("MCUCount-Ende"); } } if (available() <= 2) { // System.out.println("expecting end of image"); if (available() == 2) { getByte(); if (getByte() != EOI) { System.out.println("file does not end with EOI"); } } else { if (available() > 0) { System.out.println(Integer.toHexString(getByte())); } System.out.println("file does not end with EOI"); } break; } } final int[] tmpBuff = new int[pos]; System.arraycopy(buff, 0, tmpBuff, 0, pos); return tmpBuff; }
7548a894-b73a-47ac-87bc-79c6c1fe45c8
private int DECODE() { int I, CD, VALUE; CD = NextBit(); I = 1; while (true) { // System.out.println(hftbl+" "+I); if (CD > this.MAXCODE[this.hftbl][I]) { CD = (CD << 1) + NextBit(); I++; } else { break; } } this.J = this.VALPTR[this.hftbl][I]; this.J = this.J + CD - this.MINCODE[this.hftbl][I]; VALUE = this.HUFFVAL[this.hftbl][this.J]; return VALUE; }
b40a2205-6b6e-4f4e-8e1f-ef4ba7dd5d8a
private void Decode_AC_coefficients() { this.K = 1; // Zero out array ZZ[] for (this.lp = 1; this.lp < 64; this.lp++) { this.ZZ[this.lp] = 0; } while (true) { // System.out.println(hftbl); this.RS = DECODE(); this.SSSS = this.RS % 16; this.R = this.RS >> 4; if (this.SSSS == 0) { if (this.R == 15) { this.K += 16; continue; } else return; } else { this.K = this.K + this.R; Decode_ZZ(this.K); if (this.K == 63) return; else { this.K++; } } } }
41eecc02-44e8-4346-9847-3742ac84a4ae
private void Decode_ZZ(final int k) { // Decoding a nonzero AC coefficient this.ZZ[k] = RECEIVE(this.SSSS); this.ZZ[k] = EXTEND(this.ZZ[k], this.SSSS); }
b4c86261-68e6-47de-80b5-4d350bbb53df
private void dht() { // Read in Huffman tables // System.out.println("Read in Huffman tables"); // Lh length // Th index // Tc AC? this.Lh = getInt(); while (this.Lh > 0) { this.Tc = getByte(); this.Th = this.Tc & 0x0f; this.Tc >>= 4; // System.out.println("______Lh="+Lh); if (this.Th == 0) { if (this.Tc == 0) { this.htDC0 = new HuffTable(this.dis, this.Lh); this.Lh -= this.htDC0.getLen(); this.HUFFVAL[0] = this.htDC0.getHUFFVAL(); this.VALPTR[0] = this.htDC0.getVALPTR(); this.MAXCODE[0] = this.htDC0.getMAXCODE(); // System.out.println("MAXCODE[0]="+MAXCODE[0]); this.MINCODE[0] = this.htDC0.getMINCODE(); this.htDC0 = null; System.gc(); } else { this.htAC0 = new HuffTable(this.dis, this.Lh); this.Lh -= this.htAC0.getLen(); this.HUFFVAL[1] = this.htAC0.getHUFFVAL(); this.VALPTR[1] = this.htAC0.getVALPTR(); this.MAXCODE[1] = this.htAC0.getMAXCODE(); // System.out.println("MAXCODE[1]="+MAXCODE[1]); this.MINCODE[1] = this.htAC0.getMINCODE(); this.htAC0 = null; System.gc(); } } else { if (this.Tc == 0) { this.htDC1 = new HuffTable(this.dis, this.Lh); this.Lh -= this.htDC1.getLen(); this.HUFFVAL[2] = this.htDC1.getHUFFVAL(); this.VALPTR[2] = this.htDC1.getVALPTR(); this.MAXCODE[2] = this.htDC1.getMAXCODE(); // System.out.println("MAXCODE[2]="+MAXCODE[2]); this.MINCODE[2] = this.htDC1.getMINCODE(); this.htDC1 = null; System.gc(); } else { this.htAC1 = new HuffTable(this.dis, this.Lh); this.Lh -= this.htAC1.getLen(); this.HUFFVAL[3] = this.htAC1.getHUFFVAL(); this.VALPTR[3] = this.htAC1.getVALPTR(); this.MAXCODE[3] = this.htAC1.getMAXCODE(); // System.out.println("MAXCODE[3]="+MAXCODE[3]); this.MINCODE[3] = this.htAC1.getMINCODE(); this.htAC1 = null; System.gc(); } } } }
114d0347-a5ff-40bf-b86a-09121d1bb472
private void dqt() { // Read in quatization tables this.Lq = getInt(); this.Pq = getByte(); this.Tq = this.Pq & 0x0f; this.Pq >>= 4; switch (this.Tq) { case 0: for (this.lp = 0; this.lp < 64; this.lp++) { this.QNT[0][this.lp] = getByte(); } break; case 1: for (this.lp = 0; this.lp < 64; this.lp++) { this.QNT[1][this.lp] = getByte(); } break; case 2: for (this.lp = 0; this.lp < 64; this.lp++) { this.QNT[2][this.lp] = getByte(); } break; case 3: for (this.lp = 0; this.lp < 64; this.lp++) { this.QNT[3][this.lp] = getByte(); } break; } }
1152e1d8-7c09-4e1d-b9f0-2019eff1ec66
private void dri() { getInt(); this.RI = getInt(); }
4be9da4e-2cc7-474e-8d4f-addc3c4d6db5
private int EXTEND(int V, final int T) { int Vt; Vt = 0x01 << T - 1; if (V < Vt) { Vt = (-1 << T) + 1; V += Vt; } return V; }
1f711a74-aa4f-4d19-a7d9-bb528cfcc29e
public int getBlockCount() { switch (this.Nf) { case 1: return (this.X + 7) / 8 * ((this.Y + 7) / 8); case 3: return 6 * ((this.X + 15) / 16) * ((this.Y + 15) / 16); default: System.out.println("Nf weder 1 noch 3"); } return 0; }
d1d366dc-6633-46e4-9c0d-39fc4631f763
public int getByte() { int b = 0; // Read Byte from DataInputStream try { b = this.dis.readUnsignedByte(); } catch (final IOException e) { e.printStackTrace(); } return b; }
4cb633f3-f9f2-43de-8046-db97f6bee247
public int getComp() { return this.Nf; }
f39a5bb3-3dfd-4a72-ba82-bae1cab7bb30
public int getInt() { int b = 0; // Read Integer from DataInputStream try { b = this.dis.readUnsignedByte(); b <<= 8; final int tmp = this.dis.readUnsignedByte(); b ^= tmp; } catch (final IOException e) { e.printStackTrace(); } return b; }
abb60e50-2716-4c10-b2c1-2c1dde2b400b
public int getPrec() { return this.P; }
93be85d2-0202-4ec8-aa0e-4179820b5840
public int getX() { return this.X; }
f9c024e4-2103-438c-8a44-c0282103b585
public int getY() { return this.Y; }
53392ce2-8056-4b80-bf5b-33a43e735ef5
public void HuffDecode(final int[][][] buffer) { int x, y, tmp; final int sz = this.X * this.Y, scan = 0; final int[][] Block = new int[8][8]; int Cs, Ta, Td, blocks; final long t; final double time; // Read in Scan Header information this.Ls = getInt(); this.Ns = getByte(); Cs = getByte(); Td = getByte(); Ta = Td & 0x0f; Td >>= 4; this.Ss = getByte(); this.Se = getByte(); this.Ah = getByte(); this.Al = this.Ah & 0x0f; this.Ah >>= 4; // Calculate the Number of blocks encoded // blocks = X * Y / 64; blocks = getBlockCount() / 6; // decode image data and return image data in array for (this.cnt = 0; this.cnt < blocks; this.cnt++) { // Get DC coefficient if (Td == 0) { this.hftbl = 0; } else { this.hftbl = 2; } tmp = DECODE(); this.DIFF = RECEIVE(tmp); this.ZZ[0] = this.PRED + EXTEND(this.DIFF, tmp); this.PRED = this.ZZ[0]; // Get AC coefficients if (Ta == 0) { this.hftbl = 1; } else { this.hftbl = 3; } Decode_AC_coefficients(); // dezigzag and dequantize block for (this.lp = 0; this.lp < 64; this.lp++) { Block[deZZ[this.lp][0]][deZZ[this.lp][1]] = this.ZZ[this.lp] * this.QNT[0][this.lp]; } // store blocks in buffer for (x = 0; x < 8; x++) { for (y = 0; y < 8; y++) { buffer[this.cnt][x][y] = Block[x][y]; } } } closeStream(); }
3d929adc-c4d1-4c8e-970d-55534ab8c425
private int NextBit() { // Get one bit from entropy coded data stream int b2; final int lns; int BIT; if (this.CNT == 0) { this.CNT = 8; this.B = getByte(); if (255 == this.B) { b2 = getByte(); } } BIT = this.B & 0X80; // get MSBit of B BIT >>= 7; // move MSB to LSB this.CNT--; // Decrement counter this.B <<= 1; // Shift left one bit return BIT; }
f26b8968-a627-4063-8b81-d8ea0adf0340
public void rawDecode(final int[][][] buffer) { int x, y, tmp; final int[][] Block = new int[8][8]; int Cs, Ta, Td, blocks; final long t; final double time; // Read in Scan Header information this.Ls = getInt(); this.Ns = getByte(); Cs = getByte(); Td = getByte(); Ta = Td & 0x0f; Td >>= 4; this.Ss = getByte(); this.Se = getByte(); this.Ah = getByte(); this.Al = this.Ah & 0x0f; this.Ah >>= 4; // Calculate the Number of blocks encoded blocks = getBlockCount() / 6; // decode image data and return image data in array for (this.cnt = 0; this.cnt < blocks; this.cnt++) { // Get DC coefficient if (Td == 0) { this.hftbl = 0; } else { this.hftbl = 2; } tmp = DECODE(); this.DIFF = RECEIVE(tmp); this.ZZ[0] = this.PRED + EXTEND(this.DIFF, tmp); this.PRED = this.ZZ[0]; // Get AC coefficients if (Ta == 0) { this.hftbl = 1; } else { this.hftbl = 3; } Decode_AC_coefficients(); // dezigzag for (this.lp = 0; this.lp < 64; this.lp++) { Block[deZZ[this.lp][0]][deZZ[this.lp][1]] = this.ZZ[this.lp]; } // store blocks in buffer System.out.print(this.cnt + " "); for (x = 0; x < 8; x++) { for (y = 0; y < 8; y++) { buffer[this.cnt][x][y] = Block[x][y]; } } } closeStream(); }
3c8f7714-c5fe-4ff9-aa0e-183efde04461
private int RECEIVE(final int SSS) { int V = 0, I = 0; while (true) { if (I == SSS) return V; I++; V = (V << 1) + NextBit(); } }
cd5b3546-1c8a-40dd-b442-2f5ff97a1886
public void RGBdecode(final int[][][] Lum) { int x, y, a, b, line, col, tmp; final int sz = this.X * this.Y; int blocks; final int MCU, scan = 0; final int[][] Block = new int[8][8]; int[] Cs, Ta, Td; final int[] PRED = { 0, 0, 0 }; final long t; final double time; // Read in Scan Header information this.Ls = getInt(); this.Ns = getByte(); Cs = new int[this.Ns]; Td = new int[this.Ns]; Ta = new int[this.Ns]; // get table information for (this.lp = 0; this.lp < this.Ns; this.lp++) { Cs[this.lp] = getByte(); Td[this.lp] = getByte(); Ta[this.lp] = Td[this.lp] & 0x0f; Td[this.lp] >>= 4; } this.Ss = getByte(); this.Se = getByte(); this.Ah = getByte(); this.Al = this.Ah & 0x0f; this.Ah >>= 4; // Calculate the Number of blocks encoded // blocks = X * Y / 64; blocks = getBlockCount() / 6; col = 2; // decode image data and return image data in array for (a = 0; a < 32; a++) { for (b = 0; b < 32; b++) { // Get component 1 of MCU for (this.cnt = 0; this.cnt < 4; this.cnt++) { // Get DC coefficient this.hftbl = 0; tmp = DECODE(); this.DIFF = RECEIVE(tmp); this.ZZ[0] = PRED[0] + EXTEND(this.DIFF, tmp); PRED[0] = this.ZZ[0]; // Get AC coefficients this.hftbl = 1; Decode_AC_coefficients(); // dezigzag and dequantize block for (this.lp = 0; this.lp < 64; this.lp++) { Block[deZZ[this.lp][0]][deZZ[this.lp][1]] = this.ZZ[this.lp] * this.QNT[0][this.lp]; } if (this.cnt < 2) { line = 0; } else { line = 62; } // store blocks in buffer for (x = 0; x < 8; x++) { for (y = 0; y < 8; y++) { Lum[b * 2 + this.cnt + line + a * 128][x][y] = Block[x][y]; } } } // getComponent 2 and 3 of image for (this.cnt = 0; this.cnt < 2; this.cnt++) { // Get DC coefficient this.hftbl = 2; tmp = DECODE(); this.DIFF = RECEIVE(tmp); this.ZZ[0] = PRED[this.cnt + 1] + EXTEND(this.DIFF, tmp); PRED[this.cnt + 1] = this.ZZ[0]; // Get AC coefficients this.hftbl = 3; Decode_AC_coefficients(); // dezigzag and dequantize block for (this.lp = 0; this.lp < 64; this.lp++) { Block[deZZ[this.lp][0]][deZZ[this.lp][1]] = this.ZZ[this.lp] * this.QNT[1][this.lp]; } // store blocks in buffer if (this.cnt == 0) { for (x = 0; x < 8; x++) { for (y = 0; y < 8; y++) { this.Cb[a * 32 + b][x][y] = Block[x][y]; } } } else { for (x = 0; x < 8; x++) { for (y = 0; y < 8; y++) { this.Cr[a * 32 + b][x][y] = Block[x][y]; } } } } } } closeStream(); }
8042ee07-c306-4dcf-bed2-261644af6b60
public void setCb(final int[][][] chrome) { this.Cb = chrome; }
d0e0fb34-3b48-4adf-a758-fd8e5fe746b4
public void setCr(final int[][][] chrome) { this.Cr = chrome; }
181af218-74e7-4dbb-a215-9fbe93d67d8c
private void skipVariable() { try { this.dis.skipBytes(getInt() - 2); } catch (final IOException e) { e.printStackTrace(); } }
51658e2a-49be-448c-8230-b9e9e0277366
private void sof0() { // Read in start of frame header data this.Lf = getInt(); this.P = getByte(); this.Y = getInt(); this.X = getInt(); this.Nf = getByte(); this.C = new int[this.Nf]; this.H = new int[this.Nf]; this.V = new int[this.Nf]; this.T = new int[this.Nf]; // Read in quatization table identifiers for (this.lp = 0; this.lp < this.Nf; this.lp++) { this.C[this.lp] = getByte(); this.H[this.lp] = getByte(); this.V[this.lp] = this.H[this.lp] & 0x0f; this.H[this.lp] >>= 4; this.T[this.lp] = getByte(); } }
abbb6c2e-3b29-4e92-93ff-ced4d46d5454
public Board() { board = new Piece[6][6]; graveyard = new ArrayList<Piece>(); Piece temp; //Place all the pawns on the board for (int count = 0; count < 6; count++) { temp = new Piece(ColorEnum.BLACK, PieceEnum.PAWN); board[1][count] = temp; temp = new Piece(ColorEnum.WHITE, PieceEnum.PAWN); board[4][count] = temp; } //Place all the knights on the board temp = new Piece(ColorEnum.BLACK, PieceEnum.KNIGHT); board[0][1] = temp; board[0][4] = temp; temp = new Piece(ColorEnum.WHITE, PieceEnum.KNIGHT); board[5][1] = temp; board[5][4] = temp; }
2781fa4c-b3ce-482b-af18-26923469107e
public ArrayList<Piece> getGraveyard() { return graveyard; }
b1350008-24a7-4e5f-8838-673fe74cc697
public void setGraveyard(ArrayList<Piece> graveyard) { this.graveyard = graveyard; }
cbdd9a93-909a-47d1-ab6a-bcf07af5fea3
public String toString() { String output; output = " -------------------\n"; for (int cx = 0; cx < 6; cx++) { output += 6-cx; output += "|"; for (int cy = 0; cy < 6; cy++) { if (board[cx][cy] == null) { output += " |"; } else { output += board[cx][cy].toString() + "|"; } } output += "\n"; output += " -------------------\n"; } output += " a b c d e f\n"; return output; }
acc69ba4-b1ce-4b94-a71e-e390bb913635
public Piece[][] getBoard() { return board; }
4f1ae87f-a0aa-4d3e-8430-baf04a1b852b
public void setBoard(Piece[][] board) { this.board = board; }
4ccd636b-eb24-4a77-b193-9a476a724ec8
public void movePiece(Move move) { //If a piece is being captured if (board[move.getB().getRow()][move.getB().getCollumn()] != null) { //Transfer it to the graveyard graveyard.add(board[move.getB().getRow()][move.getB().getCollumn()]); } //Move the piece to its destination board[move.getB().getRow()][move.getB().getCollumn()] = board[move.getA().getRow()][move.getA().getCollumn()]; //Erase the piece from its previous position board[move.getA().getRow()][move.getA().getCollumn()] = null; }
357c2f3c-09d4-4f75-90eb-13804d9b94cf
public GameStatus getResultingGameStatus() { return resultingGameStatus; }
5b8c49b6-3d81-43e5-a0bb-75c300f58918
public void setResultingGameStatus(GameStatus resultingGameStatus) { this.resultingGameStatus = resultingGameStatus; }
5cde2f40-cf48-4b5b-84f7-86da6855db0c
public BoardPosition getA() { return a; }
6bb3e021-d23e-408b-99f9-5227e2c710de
public void setA(BoardPosition a) { this.a = a; }
6ae31c35-a506-4de4-8f7d-21db71334b1d
public BoardPosition getB() { return b; }
3201c9dd-1ba7-4bf7-b017-2cbb05a35bde
public void setB(BoardPosition b) { this.b = b; }
ce1e852b-2a9c-47c5-b259-880982ed0683
Move(BoardPosition a, BoardPosition b, GameStatus resultingGameStatus) { this.a = a; this.b = b; this.resultingGameStatus = resultingGameStatus; }
207d25f3-82d9-4afd-a27f-d41819895743
public Player(ColorEnum color, Board board) { this.color = color; this.board = board; }
c30ae8ba-43c8-44a9-97a6-3891f02f4b02
public Move makeMove() { Move move; //Keep looping and getting moves 'till we get a valid move while (true) { move = getMove(); System.out.println("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); //If we're trying to move from positions that are actually in the board if (!(move.getA().isOutOfBounds() || move.getB().isOutOfBounds())) { //If we're trying to move a non-existent piece if (board.getBoard()[move.getA().getRow()][move.getA().getCollumn()] != null) { //If we're trying to move a piece that isn't ours if (board.getBoard()[move.getA().getRow()][move.getA().getCollumn()].getColor() == this.color) { //Is the move valid? if (PieceCanMove(board.getBoard()[move.getA().getRow()][move.getA().getCollumn()], move, board)) { System.out.println("Move is valid, hooraayy!"); return move; } } else { System.out.println("Sorry, that piece is not yours to move"); } } else { System.out.println("Sorry, there is no piece in the specified starting position"); } } else { System.out.println("Sorry, the position isn't within the board"); } System.out.println("You must re-enter your move"); System.out.println(board.toString()); } }
13ff652e-db06-442f-b6f5-467262786add
public Move getMove() { Move r; BoardPosition a; BoardPosition b; Scanner sc = new Scanner(System.in); int row; String collumn; System.out.print("Enter the row of the position of the piece you would like to move: "); row = sc.nextInt(); System.out.print("Enter the collumn of the position of the piece you would like to move: "); collumn = sc.next(); a = new BoardPosition(6 - row, getNumForCollumn(collumn)); System.out.print("Enter the row of the position you would like to move this piece to: "); row = sc.nextInt(); System.out.print("Enter the collumn of the position you would like to move this piece to: "); collumn = sc.next(); b = new BoardPosition(6 - row, getNumForCollumn(collumn)); r = new Move(a, b, GameStatus.CONTINUE); return r; }
a283d084-8aa6-4f6b-b818-c6306710719a
private int getNumForCollumn(String i) { ArrayList<String> colNames = new ArrayList<String>(); colNames.add("a"); colNames.add("b"); colNames.add("c"); colNames.add("d"); colNames.add("e"); colNames.add("f"); int r = colNames.indexOf(i); return r; }