From d7ccf6883c1aa825f0b11c51024c285db7db956f Mon Sep 17 00:00:00 2001 From: vanitasvitae Date: Mon, 13 Apr 2015 22:42:16 +0200 Subject: [PATCH] Commented a lot --- src/ArrayUtils.java | 48 +++++++++-- src/Const.java | 92 +++++++++++++++----- src/DepthMapNeedle.java | 14 ++++ src/HexUtil.java | 25 +++++- src/JPEG.java | 162 ++++++++++++++++++++++++++++++++++- src/JPEGUtils.java | 182 ++++++++++++++++++++++++++++++++++++---- 6 files changed, 470 insertions(+), 53 deletions(-) diff --git a/src/ArrayUtils.java b/src/ArrayUtils.java index ba148bf..17a8682 100644 --- a/src/ArrayUtils.java +++ b/src/ArrayUtils.java @@ -2,6 +2,13 @@ public class ArrayUtils { + /** + * Return true, if the array part is sub array of src from offset + * @param src array + * @param part array + * @param offset int + * @return true, if part is completely a subarray of src on offset offset, else false + */ public static boolean arrayIsPartOfOtherArrayOnOffset(byte[] src, byte[] part, int offset) { if(offset<0 || part.length+offset > src.length) return false; @@ -12,6 +19,11 @@ public class ArrayUtils return true; } + /** + * converts the byte array b into a char array by casting all the bytes into chars + * @param b byte array + * @return char array + */ public static char[] bytesToChars(byte[] b) { char[] c = new char[b.length]; @@ -20,6 +32,11 @@ public class ArrayUtils return c; } + /** + * converts the char array into a byte array by casting all the chars into bytes + * @param c char array + * @return byte array + */ public static byte[] charsToBytes(char[] c) { byte[] b = new byte[c.length]; @@ -28,17 +45,28 @@ public class ArrayUtils return b; } - public static byte[] concatenate (byte[] out, byte[] bs) { - if(out == null) return bs; - if(bs == null) return out; - int aLen = out.length; - int bLen = bs.length; + /** + * concatenate two byte arrays + * @param first first byte array + * @param second second byte array + * @return first + second + */ + public static byte[] concatenate (byte[] first, byte[] second) { + if(first == null) return second; + if(second == null) return first; + int aLen = first.length; + int bLen = second.length; byte[] c = new byte[aLen+bLen]; - System.arraycopy(out, 0, c, 0, aLen); - System.arraycopy(bs, 0, c, aLen, bLen); + System.arraycopy(first, 0, c, 0, aLen); + System.arraycopy(second, 0, c, aLen, bLen); return c; } + /** + * convert an integer into a 32 bit byte array + * @param value integer + * @return byte array + */ public static final byte[] intToByteArray(int value) { return new byte[] { (byte)(value >>> 24), @@ -47,12 +75,16 @@ public class ArrayUtils (byte)value}; } + /** + * convert a signed byte array into an unsigned byte array (sort of) + * @param b byte array of signed bytes + * @return byte array of unsigned bytes + */ public static byte[] unsign(byte[] b) { byte[] u = new byte[b.length]; for(int i=0; i show help text if(args.length==0 || args[0].equals("-h")) help(); + + //export depthmap if(args.length >= 2 && args[0].equals("-e")) { for(int i=1; i=2 && args[0].equals("-s")) { for(int i=1; i= 3 && args[0].equals("-i")) { String depthmap = args[1]; @@ -36,6 +47,9 @@ public class DepthMapNeedle } } + /** + * Show help text + */ public static void help() { System.out.println("Welcome to DepthMapNeedle!" diff --git a/src/HexUtil.java b/src/HexUtil.java index eed7af0..f7dc06e 100644 --- a/src/HexUtil.java +++ b/src/HexUtil.java @@ -5,12 +5,21 @@ import java.security.NoSuchAlgorithmException; public class HexUtil { + /** + * Print out a byte array in hexadecimal + * @param bytes array + */ public static void printHex(byte[] bytes) { - for(byte b : bytes) System.out.print(byteToHex(b)); + for(byte b : bytes) System.out.print(byteToHexString(b)); } - public static String byteToHex(byte data) { + /** + * convert a byte to a hex string + * @param data array + * @return String representation in hex + */ + public static String byteToHexString(byte data) { StringBuffer buf = new StringBuffer(); buf.append(toHexChar((data >>> 4) & 0x0F)); @@ -19,6 +28,11 @@ public class HexUtil return buf.toString(); } + /** + * convert a integer into a hexadecimal character + * @param i integer + * @return hex char + */ public static char toHexChar(int i) { if ((0 <= i) && (i <= 9)) { return (char) ('0' + i); @@ -27,6 +41,11 @@ public class HexUtil } } + /** + * Generate the md5 digest of the byte array data in hexadecimal + * @param data array + * @return byte array of the md5 digest in hex + */ public static byte[] generateMD5(byte[] data) { try @@ -35,7 +54,7 @@ public class HexUtil String m=""; for(int i=0; i CHUNKSIZE multiple ExtendedXMPBlocks will be generated and concatenated. + * Available types: + * Const.EXIF, Const.STANDARDXMP, Const.EXTENDEDXMP + * @param data byte array of data that will be decorated + * @param type String declaring the type of header for the block. + * @return decorated block + */ public static byte[] decorateBlock(byte[] data, String type) { + //EXIF Block: 'APP1 + BLOCKLENGTH + EXIF\0\0 + data' if(type.equals(EXIF)) { data = ArrayUtils.concatenate(markEXIF, data); byte[] pre = ArrayUtils.concatenate(markAPP1, genLen(data.length+2)); return ArrayUtils.concatenate(pre, data); } + //StandardXMP: 'APP1 + BLOCKLENGTH + http://ns.adobe.com/xap/1.0/\0 + data' else if(type.equals(STANDARDXMP)) { data = ArrayUtils.concatenate(markStandardXMP, data); byte[] pre = ArrayUtils.concatenate(markAPP1, genLen(data.length+2)); return ArrayUtils.concatenate(pre,data); } + //ExtendedXMP: 'APP1 + BLOCKLENGTH + http://ns.adobe.com/xmp/extension/\0 + MD5 + EXTENDEDLENGTH + EXTENDEDOFFSET + DATAPORTION else if(type.equals(EXTENDEDXMP)) { byte[] out = new byte[0]; + //MD5 checksum is digest of the datacontent byte[] md5 = HexUtil.generateMD5(data); int i=0; int blockCount = data.length/CHUNKSIZE; + //decorate blockportions of size CHUNKSIZE while (i