You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by da...@apache.org on 2012/05/26 17:35:06 UTC
svn commit: r1342914 [3/5] - in
/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging: ./
color/ common/ common/bytesource/ common/itu_t4/ common/mylzw/
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryFileFunctions.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryFileFunctions.java?rev=1342914&r1=1342913&r2=1342914&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryFileFunctions.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryFileFunctions.java Sat May 26 15:35:04 2012
@@ -26,56 +26,43 @@ import java.io.RandomAccessFile;
import org.apache.commons.imaging.ImageReadException;
import org.apache.commons.imaging.ImageWriteException;
-public class BinaryFileFunctions implements BinaryConstants
-{
+public class BinaryFileFunctions implements BinaryConstants {
protected boolean debug = false;
- public final void setDebug(boolean b)
- {
+ public final void setDebug(boolean b) {
debug = b;
}
- public final boolean getDebug()
- {
+ public final boolean getDebug() {
return debug;
}
- protected final void readRandomBytes(InputStream is)
- throws IOException
- {
+ protected final void readRandomBytes(InputStream is) throws IOException {
- for (int counter = 0; counter < 100; counter++)
- {
+ for (int counter = 0; counter < 100; counter++) {
readByte("" + counter, is, "Random Data");
}
}
- public final void debugNumber(String msg, int data)
- {
+ public final void debugNumber(String msg, int data) {
debugNumber(msg, data, 1);
}
- public final void debugNumber(String msg, int data, int bytes)
- {
+ public final void debugNumber(String msg, int data, int bytes) {
PrintWriter pw = new PrintWriter(System.out);
- debugNumber(pw, msg,
- data, bytes);
+ debugNumber(pw, msg, data, bytes);
pw.flush();
}
-
- public final void debugNumber(PrintWriter pw, String msg, int data)
- {
+ public final void debugNumber(PrintWriter pw, String msg, int data) {
debugNumber(pw, msg, data, 1);
}
public final void debugNumber(PrintWriter pw, String msg, int data,
- int bytes)
- {
+ int bytes) {
pw.print(msg + ": " + data + " (");
int byteData = data;
- for (int i = 0; i < bytes; i++)
- {
+ for (int i = 0; i < bytes; i++) {
if (i > 0)
pw.print(",");
int singleByte = 0xff & byteData;
@@ -87,8 +74,7 @@ public class BinaryFileFunctions impleme
pw.flush();
}
- public final boolean startsWith(byte haystack[], byte needle[])
- {
+ public final boolean startsWith(byte haystack[], byte needle[]) {
if (needle == null)
return false;
if (haystack == null)
@@ -96,8 +82,7 @@ public class BinaryFileFunctions impleme
if (needle.length > haystack.length)
return false;
- for (int i = 0; i < needle.length; i++)
- {
+ for (int i = 0; i < needle.length; i++) {
if (needle[i] != haystack[i])
return false;
}
@@ -105,31 +90,25 @@ public class BinaryFileFunctions impleme
return true;
}
- public final byte[] readBytes(InputStream is, int count)
- throws IOException
- {
+ public final byte[] readBytes(InputStream is, int count) throws IOException {
byte result[] = new byte[count];
- for (int i = 0; i < count; i++)
- {
+ for (int i = 0; i < count; i++) {
int data = is.read();
result[i] = (byte) data;
}
return result;
}
-
+
public final void readAndVerifyBytes(InputStream is, byte expected[],
- String exception) throws ImageReadException, IOException
- {
- for (int i = 0; i < expected.length; i++)
- {
+ String exception) throws ImageReadException, IOException {
+ for (int i = 0; i < expected.length; i++) {
int data = is.read();
byte b = (byte) (0xff & data);
if (data < 0)
throw new ImageReadException("Unexpected EOF.");
- if (b != expected[i])
- {
+ if (b != expected[i]) {
// System.out.println("i" + ": " + i);
// this.debugByteArray("expected", expected);
@@ -141,11 +120,10 @@ public class BinaryFileFunctions impleme
}
}
- public final void readAndVerifyBytes(InputStream is, BinaryConstant expected,
- String exception) throws ImageReadException, IOException
- {
- for (int i = 0; i < expected.size(); i++)
- {
+ public final void readAndVerifyBytes(InputStream is,
+ BinaryConstant expected, String exception)
+ throws ImageReadException, IOException {
+ for (int i = 0; i < expected.size(); i++) {
int data = is.read();
byte b = (byte) (0xff & data);
@@ -159,14 +137,11 @@ public class BinaryFileFunctions impleme
protected final void readAndVerifyBytes(String name, InputStream is,
byte expected[], String exception) throws ImageReadException,
- IOException
- {
+ IOException {
byte bytes[] = readByteArray(name, expected.length, is, exception);
- for (int i = 0; i < expected.length; i++)
- {
- if (bytes[i] != expected[i])
- {
+ for (int i = 0; i < expected.length; i++) {
+ if (bytes[i] != expected[i]) {
// System.out.println("i" + ": " + i);
// debugNumber("bytes[" + i + "]", bytes[i]);
// debugNumber("expected[" + i + "]", expected[i]);
@@ -177,11 +152,9 @@ public class BinaryFileFunctions impleme
}
public final void skipBytes(InputStream is, int length, String exception)
- throws IOException
- {
+ throws IOException {
long total = 0;
- while (length != total)
- {
+ while (length != total) {
long skipped = is.skip(length - total);
if (skipped < 1)
throw new IOException(exception + " (" + skipped + ")");
@@ -190,8 +163,7 @@ public class BinaryFileFunctions impleme
}
protected final void scanForByte(InputStream is, byte value)
- throws IOException
- {
+ throws IOException {
int count = 0;
for (int i = 0; count < 3; i++)
// while(count<3)
@@ -199,8 +171,7 @@ public class BinaryFileFunctions impleme
int b = is.read();
if (b < 0)
return;
- if ((0xff & b) == value)
- {
+ if ((0xff & b) == value) {
System.out.println("\t" + i + ": match.");
count++;
}
@@ -208,12 +179,10 @@ public class BinaryFileFunctions impleme
}
public final byte readByte(String name, InputStream is, String exception)
- throws IOException
- {
+ throws IOException {
int result = is.read();
- if ((result < 0))
- {
+ if ((result < 0)) {
System.out.println(name + ": " + result);
throw new IOException(exception);
}
@@ -225,12 +194,10 @@ public class BinaryFileFunctions impleme
}
protected final RationalNumber[] convertByteArrayToRationalArray(
- String name, byte bytes[], int start, int length, int byteOrder)
- {
+ String name, byte bytes[], int start, int length, int byteOrder) {
int expectedLength = start + length * 8;
- if (bytes.length < expectedLength)
- {
+ if (bytes.length < expectedLength) {
System.out.println(name + ": expected length: " + expectedLength
+ ", actual length: " + bytes.length);
return null;
@@ -238,8 +205,7 @@ public class BinaryFileFunctions impleme
RationalNumber result[] = new RationalNumber[length];
- for (int i = 0; i < length; i++)
- {
+ for (int i = 0; i < length; i++) {
result[i] = convertByteArrayToRational(name, bytes, start + i * 8,
byteOrder);
}
@@ -248,14 +214,12 @@ public class BinaryFileFunctions impleme
}
protected final RationalNumber convertByteArrayToRational(String name,
- byte bytes[], int byteOrder)
- {
+ byte bytes[], int byteOrder) {
return convertByteArrayToRational(name, bytes, 0, byteOrder);
}
protected final RationalNumber convertByteArrayToRational(String name,
- byte bytes[], int start, int byteOrder)
- {
+ byte bytes[], int start, int byteOrder) {
int numerator = convertByteArrayToInt(name, bytes, start + 0, byteOrder);
int divisor = convertByteArrayToInt(name, bytes, start + 4, byteOrder);
@@ -263,14 +227,12 @@ public class BinaryFileFunctions impleme
}
protected final int convertByteArrayToInt(String name, byte bytes[],
- int byteOrder)
- {
+ int byteOrder) {
return convertByteArrayToInt(name, bytes, 0, byteOrder);
}
protected final int convertByteArrayToInt(String name, byte bytes[],
- int start, int byteOrder)
- {
+ int start, int byteOrder) {
byte byte0 = bytes[start + 0];
byte byte1 = bytes[start + 1];
byte byte2 = bytes[start + 2];
@@ -282,8 +244,7 @@ public class BinaryFileFunctions impleme
{
result = ((0xff & byte0) << 24) | ((0xff & byte1) << 16)
| ((0xff & byte2) << 8) | ((0xff & byte3) << 0);
- } else
- {
+ } else {
// intel, little endian
result = ((0xff & byte3) << 24) | ((0xff & byte2) << 16)
| ((0xff & byte1) << 8) | ((0xff & byte0) << 0);
@@ -296,12 +257,10 @@ public class BinaryFileFunctions impleme
}
protected final int[] convertByteArrayToIntArray(String name, byte bytes[],
- int start, int length, int byteOrder)
- {
+ int start, int length, int byteOrder) {
int expectedLength = start + length * 4;
- if (bytes.length < expectedLength)
- {
+ if (bytes.length < expectedLength) {
System.out.println(name + ": expected length: " + expectedLength
+ ", actual length: " + bytes.length);
return null;
@@ -309,8 +268,7 @@ public class BinaryFileFunctions impleme
int result[] = new int[length];
- for (int i = 0; i < length; i++)
- {
+ for (int i = 0; i < length; i++) {
result[i] = convertByteArrayToInt(name, bytes, start + i * 4,
byteOrder);
}
@@ -319,16 +277,14 @@ public class BinaryFileFunctions impleme
}
protected final void writeIntInToByteArray(int value, byte bytes[],
- int start, int byteOrder)
- {
+ int start, int byteOrder) {
if (byteOrder == BYTE_ORDER_MOTOROLA) // motorola, big endian
{
bytes[start + 0] = (byte) (value >> 24);
bytes[start + 1] = (byte) (value >> 16);
bytes[start + 2] = (byte) (value >> 8);
bytes[start + 3] = (byte) (value >> 0);
- } else
- {
+ } else {
bytes[start + 3] = (byte) (value >> 24);
bytes[start + 2] = (byte) (value >> 16);
bytes[start + 1] = (byte) (value >> 8);
@@ -336,8 +292,7 @@ public class BinaryFileFunctions impleme
}
}
- protected static final byte[] int2ToByteArray(int value, int byteOrder)
- {
+ protected static final byte[] int2ToByteArray(int value, int byteOrder) {
if (byteOrder == BYTE_ORDER_MOTOROLA) // motorola, big endian
return new byte[] { (byte) (value >> 8), (byte) (value >> 0), };
else
@@ -345,12 +300,10 @@ public class BinaryFileFunctions impleme
}
protected final byte[] convertIntArrayToByteArray(int values[],
- int byteOrder)
- {
+ int byteOrder) {
byte result[] = new byte[values.length * 4];
- for (int i = 0; i < values.length; i++)
- {
+ for (int i = 0; i < values.length; i++) {
writeIntInToByteArray(values[i], result, i * 4, byteOrder);
}
@@ -358,20 +311,17 @@ public class BinaryFileFunctions impleme
}
protected final byte[] convertShortArrayToByteArray(int values[],
- int byteOrder)
- {
+ int byteOrder) {
byte result[] = new byte[values.length * 2];
- for (int i = 0; i < values.length; i++)
- {
+ for (int i = 0; i < values.length; i++) {
int value = values[i];
if (byteOrder == BYTE_ORDER_MOTOROLA) // motorola, big endian
{
result[i * 2 + 0] = (byte) (value >> 8);
result[i * 2 + 1] = (byte) (value >> 0);
- } else
- {
+ } else {
result[i * 2 + 1] = (byte) (value >> 8);
result[i * 2 + 0] = (byte) (value >> 0);
}
@@ -380,16 +330,14 @@ public class BinaryFileFunctions impleme
return result;
}
- protected final byte[] convertShortToByteArray(int value, int byteOrder)
- {
+ protected final byte[] convertShortToByteArray(int value, int byteOrder) {
byte result[] = new byte[2];
if (byteOrder == BYTE_ORDER_MOTOROLA) // motorola, big endian
{
result[0] = (byte) (value >> 8);
result[1] = (byte) (value >> 0);
- } else
- {
+ } else {
result[1] = (byte) (value >> 8);
result[0] = (byte) (value >> 0);
}
@@ -398,8 +346,7 @@ public class BinaryFileFunctions impleme
}
protected final byte[] convertIntArrayToRationalArray(int numerators[],
- int denominators[], int byteOrder) throws ImageWriteException
- {
+ int denominators[], int byteOrder) throws ImageWriteException {
if (numerators.length != denominators.length)
throw new ImageWriteException("numerators.length ("
+ numerators.length + " != denominators.length ("
@@ -407,8 +354,7 @@ public class BinaryFileFunctions impleme
byte result[] = new byte[numerators.length * 8];
- for (int i = 0; i < numerators.length; i++)
- {
+ for (int i = 0; i < numerators.length; i++) {
writeIntInToByteArray(numerators[i], result, i * 8, byteOrder);
writeIntInToByteArray(denominators[i], result, i * 8 + 4, byteOrder);
}
@@ -417,13 +363,11 @@ public class BinaryFileFunctions impleme
}
protected final byte[] convertRationalArrayToByteArray(
- RationalNumber numbers[], int byteOrder)
- {
+ RationalNumber numbers[], int byteOrder) {
// Debug.debug("convertRationalArrayToByteArray 2");
byte result[] = new byte[numbers.length * 8];
- for (int i = 0; i < numbers.length; i++)
- {
+ for (int i = 0; i < numbers.length; i++) {
writeIntInToByteArray(numbers[i].numerator, result, i * 8,
byteOrder);
writeIntInToByteArray(numbers[i].divisor, result, i * 8 + 4,
@@ -434,8 +378,7 @@ public class BinaryFileFunctions impleme
}
protected final byte[] convertRationalToByteArray(RationalNumber number,
- int byteOrder)
- {
+ int byteOrder) {
byte result[] = new byte[8];
writeIntInToByteArray(number.numerator, result, 0, byteOrder);
@@ -445,14 +388,12 @@ public class BinaryFileFunctions impleme
}
protected final int convertByteArrayToShort(String name, byte bytes[],
- int byteOrder) throws ImageReadException
- {
+ int byteOrder) throws ImageReadException {
return convertByteArrayToShort(name, 0, bytes, byteOrder);
}
protected final int convertByteArrayToShort(String name, int index,
- byte bytes[], int byteOrder) throws ImageReadException
- {
+ byte bytes[], int byteOrder) throws ImageReadException {
if (index + 1 >= bytes.length)
throw new ImageReadException("Index out of bounds. Array size: "
+ bytes.length + ", index: " + index);
@@ -481,8 +422,7 @@ public class BinaryFileFunctions impleme
{
int expectedLength = start + length * 2;
- if (bytes.length < expectedLength)
- {
+ if (bytes.length < expectedLength) {
System.out.println(name + ": expected length: " + expectedLength
+ ", actual length: " + bytes.length);
return null;
@@ -490,8 +430,7 @@ public class BinaryFileFunctions impleme
int result[] = new int[length];
- for (int i = 0; i < length; i++)
- {
+ for (int i = 0; i < length; i++) {
result[i] = convertByteArrayToShort(name, start + i * 2, bytes,
byteOrder);
}
@@ -500,64 +439,55 @@ public class BinaryFileFunctions impleme
}
public final byte[] readByteArray(String name, int length, InputStream is)
- throws IOException
- {
+ throws IOException {
String exception = name + " could not be read.";
return readByteArray(name, length, is, exception);
}
public final byte[] readByteArray(String name, int length, InputStream is,
- String exception) throws IOException
- {
+ String exception) throws IOException {
byte result[] = new byte[length];
int read = 0;
- while (read < length)
- {
+ while (read < length) {
int count = is.read(result, read, length - read);
// Debug.debug("count", count);
if (count < 1)
- throw new IOException(exception+" count: "+ count + " read: "+read+" length: "+length);
+ throw new IOException(exception + " count: " + count
+ + " read: " + read + " length: " + length);
read += count;
}
- if (debug)
- {
- for (int i = 0; ((i < length) && (i < 50)); i++)
- {
+ if (debug) {
+ for (int i = 0; ((i < length) && (i < 50)); i++) {
debugNumber(name + " (" + i + ")", 0xff & result[i]);
}
}
return result;
}
- public final void debugByteArray(String name, byte bytes[])
- {
+ public final void debugByteArray(String name, byte bytes[]) {
System.out.println(name + ": " + bytes.length);
- for (int i = 0; ((i < bytes.length) && (i < 50)); i++)
- {
+ for (int i = 0; ((i < bytes.length) && (i < 50)); i++) {
debugNumber("\t" + " (" + i + ")", 0xff & bytes[i]);
}
}
- protected final void debugNumberArray(String name, int numbers[], int length)
- {
+ protected final void debugNumberArray(String name, int numbers[], int length) {
System.out.println(name + ": " + numbers.length);
- for (int i = 0; ((i < numbers.length) && (i < 50)); i++)
- {
+ for (int i = 0; ((i < numbers.length) && (i < 50)); i++) {
debugNumber(name + " (" + i + ")", numbers[i], length);
}
}
public final byte[] readBytearray(String name, byte bytes[], int start,
- int count) throws ImageReadException
- {
- if (bytes.length < (start + count))
- {
- throw new ImageReadException("Invalid read. bytes.length: " + bytes.length+ ", start: " + start + ", count: " + count);
+ int count) throws ImageReadException {
+ if (bytes.length < (start + count)) {
+ throw new ImageReadException("Invalid read. bytes.length: "
+ + bytes.length + ", start: " + start + ", count: " + count);
// return null;
}
@@ -570,18 +500,17 @@ public class BinaryFileFunctions impleme
return result;
}
- protected final byte[] getByteArrayTail(String name, byte bytes[], int count) throws ImageReadException
- {
+ protected final byte[] getByteArrayTail(String name, byte bytes[], int count)
+ throws ImageReadException {
return readBytearray(name, bytes, count, bytes.length - count);
}
- protected final byte[] getBytearrayHead(String name, byte bytes[], int count) throws ImageReadException
- {
+ protected final byte[] getBytearrayHead(String name, byte bytes[], int count)
+ throws ImageReadException {
return readBytearray(name, bytes, 0, bytes.length - count);
}
- public static final byte[] slice(byte bytes[], int start, int count)
- {
+ public static final byte[] slice(byte bytes[], int start, int count) {
if (bytes.length < (start + count))
return null;
@@ -591,22 +520,19 @@ public class BinaryFileFunctions impleme
return result;
}
- public static final byte[] tail(byte bytes[], int count)
- {
+ public static final byte[] tail(byte bytes[], int count) {
if (count > bytes.length)
count = bytes.length;
return slice(bytes, bytes.length - count, count);
}
- public static final byte[] head(byte bytes[], int count)
- {
+ public static final byte[] head(byte bytes[], int count) {
if (count > bytes.length)
count = bytes.length;
return slice(bytes, 0, count);
}
- public final boolean compareByteArrays(byte a[], byte b[])
- {
+ public final boolean compareByteArrays(byte a[], byte b[]) {
if (a.length != b.length)
return false;
@@ -614,19 +540,15 @@ public class BinaryFileFunctions impleme
}
public final boolean compareByteArrays(byte a[], int aStart, byte b[],
- int bStart, int length)
- {
- if (a.length < (aStart + length))
- {
+ int bStart, int length) {
+ if (a.length < (aStart + length)) {
return false;
}
if (b.length < (bStart + length))
return false;
- for (int i = 0; i < length; i++)
- {
- if (a[aStart + i] != b[bStart + i])
- {
+ for (int i = 0; i < length; i++) {
+ if (a[aStart + i] != b[bStart + i]) {
// debugNumber("\t" + "a[" + (aStart + i) + "]", a[aStart + i]);
// debugNumber("\t" + "b[" + (bStart + i) + "]", b[bStart + i]);
@@ -637,8 +559,7 @@ public class BinaryFileFunctions impleme
return true;
}
- public static final boolean compareBytes(byte a[], byte b[])
- {
+ public static final boolean compareBytes(byte a[], byte b[]) {
if (a.length != b.length)
return false;
@@ -646,15 +567,13 @@ public class BinaryFileFunctions impleme
}
public static final boolean compareBytes(byte a[], int aStart, byte b[],
- int bStart, int length)
- {
+ int bStart, int length) {
if (a.length < (aStart + length))
return false;
if (b.length < (bStart + length))
return false;
- for (int i = 0; i < length; i++)
- {
+ for (int i = 0; i < length; i++) {
if (a[aStart + i] != b[bStart + i])
return false;
}
@@ -663,14 +582,12 @@ public class BinaryFileFunctions impleme
}
protected final int read4Bytes(String name, InputStream is,
- String exception, int byteOrder) throws IOException
- {
+ String exception, int byteOrder) throws IOException {
int size = 4;
byte bytes[] = new byte[size];
int read = 0;
- while (read < size)
- {
+ while (read < size) {
int count = is.read(bytes, read, size - read);
if (count < 1)
throw new IOException(exception);
@@ -682,8 +599,7 @@ public class BinaryFileFunctions impleme
}
protected final int read3Bytes(String name, InputStream is,
- String exception, int byteOrder) throws IOException
- {
+ String exception, int byteOrder) throws IOException {
byte byte0 = (byte) is.read();
byte byte1 = (byte) is.read();
byte byte2 = (byte) is.read();
@@ -722,14 +638,12 @@ public class BinaryFileFunctions impleme
protected final int read2Bytes(String name, InputStream is,
String exception, int byteOrder) throws ImageReadException,
- IOException
- {
+ IOException {
int size = 2;
byte bytes[] = new byte[size];
int read = 0;
- while (read < size)
- {
+ while (read < size) {
int count = is.read(bytes, read, size - read);
if (count < 1)
throw new IOException(exception);
@@ -740,41 +654,34 @@ public class BinaryFileFunctions impleme
return convertByteArrayToShort(name, bytes, byteOrder);
}
- protected final void printCharQuad(String msg, int i)
- {
+ protected final void printCharQuad(String msg, int i) {
System.out.println(msg + ": '" + (char) (0xff & (i >> 24))
+ (char) (0xff & (i >> 16)) + (char) (0xff & (i >> 8))
+ (char) (0xff & (i >> 0)) + "'");
}
- protected final void printCharQuad(PrintWriter pw, String msg, int i)
- {
+ protected final void printCharQuad(PrintWriter pw, String msg, int i) {
pw.println(msg + ": '" + (char) (0xff & (i >> 24))
+ (char) (0xff & (i >> 16)) + (char) (0xff & (i >> 8))
+ (char) (0xff & (i >> 0)) + "'");
}
- protected final void printByteBits(String msg, byte i)
- {
+ protected final void printByteBits(String msg, byte i) {
System.out.println(msg + ": '" + Integer.toBinaryString(0xff & i));
}
- public final static int charsToQuad(char c1, char c2, char c3, char c4)
- {
+ public final static int charsToQuad(char c1, char c2, char c3, char c4) {
return (((0xff & c1) << 24) | ((0xff & c2) << 16) | ((0xff & c3) << 8) | ((0xff & c4) << 0));
}
- public final int findNull(byte src[])
- {
+ public final int findNull(byte src[]) {
return findNull(src, 0);
}
- public final int findNull(byte src[], int start)
- {
- for (int i = start; i < src.length; i++)
- {
+ public final int findNull(byte src[], int start) {
+ for (int i = start; i < src.length; i++) {
if (src[i] == 0)
return i;
@@ -783,10 +690,8 @@ public class BinaryFileFunctions impleme
}
protected final byte[] getRAFBytes(RandomAccessFile raf, long pos,
- int length, String exception) throws IOException
- {
- if (debug)
- {
+ int length, String exception) throws IOException {
+ if (debug) {
System.out.println("getRAFBytes pos" + ": " + pos);
System.out.println("getRAFBytes length" + ": " + length);
}
@@ -796,8 +701,7 @@ public class BinaryFileFunctions impleme
raf.seek(pos);
int read = 0;
- while (read < length)
- {
+ while (read < length) {
int count = raf.read(result, read, length - read);
if (count < 1)
throw new IOException(exception);
@@ -810,14 +714,12 @@ public class BinaryFileFunctions impleme
}
protected final float convertByteArrayToFloat(String name, byte bytes[],
- int byteOrder)
- {
+ int byteOrder) {
return convertByteArrayToFloat(name, bytes, 0, byteOrder);
}
protected final float convertByteArrayToFloat(String name, byte bytes[],
- int start, int byteOrder)
- {
+ int start, int byteOrder) {
// TODO: not tested; probably wrong.
byte byte0 = bytes[start + 0];
@@ -831,8 +733,7 @@ public class BinaryFileFunctions impleme
{
bits = ((0xff & byte0) << 24) | ((0xff & byte1) << 16)
| ((0xff & byte2) << 8) | ((0xff & byte3) << 0);
- } else
- {
+ } else {
// intel, little endian
bits = ((0xff & byte3) << 24) | ((0xff & byte2) << 16)
| ((0xff & byte1) << 8) | ((0xff & byte0) << 0);
@@ -847,12 +748,10 @@ public class BinaryFileFunctions impleme
}
protected final float[] convertByteArrayToFloatArray(String name,
- byte bytes[], int start, int length, int byteOrder)
- {
+ byte bytes[], int start, int length, int byteOrder) {
int expectedLength = start + length * 4;
- if (bytes.length < expectedLength)
- {
+ if (bytes.length < expectedLength) {
System.out.println(name + ": expected length: " + expectedLength
+ ", actual length: " + bytes.length);
return null;
@@ -860,8 +759,7 @@ public class BinaryFileFunctions impleme
float result[] = new float[length];
- for (int i = 0; i < length; i++)
- {
+ for (int i = 0; i < length; i++) {
result[i] = convertByteArrayToFloat(name, bytes, start + i * 4,
byteOrder);
}
@@ -869,8 +767,7 @@ public class BinaryFileFunctions impleme
return result;
}
- protected final byte[] convertFloatToByteArray(float value, int byteOrder)
- {
+ protected final byte[] convertFloatToByteArray(float value, int byteOrder) {
byte result[] = new byte[4];
int bits = Float.floatToRawIntBits(value);
@@ -881,8 +778,7 @@ public class BinaryFileFunctions impleme
result[1] = (byte) (0xff & (bits >> 8));
result[2] = (byte) (0xff & (bits >> 16));
result[3] = (byte) (0xff & (bits >> 24));
- } else
- {
+ } else {
result[3] = (byte) (0xff & (bits >> 0));
result[2] = (byte) (0xff & (bits >> 8));
result[1] = (byte) (0xff & (bits >> 16));
@@ -893,11 +789,9 @@ public class BinaryFileFunctions impleme
}
protected final byte[] convertFloatArrayToByteArray(float values[],
- int byteOrder)
- {
+ int byteOrder) {
byte result[] = new byte[values.length * 4];
- for (int i = 0; i < values.length; i++)
- {
+ for (int i = 0; i < values.length; i++) {
float value = values[i];
int bits = Float.floatToRawIntBits(value);
@@ -908,8 +802,7 @@ public class BinaryFileFunctions impleme
result[start + 1] = (byte) (0xff & (bits >> 8));
result[start + 2] = (byte) (0xff & (bits >> 16));
result[start + 3] = (byte) (0xff & (bits >> 24));
- } else
- {
+ } else {
result[start + 3] = (byte) (0xff & (bits >> 0));
result[start + 2] = (byte) (0xff & (bits >> 8));
result[start + 1] = (byte) (0xff & (bits >> 16));
@@ -919,8 +812,7 @@ public class BinaryFileFunctions impleme
return result;
}
- protected final byte[] convertDoubleToByteArray(double value, int byteOrder)
- {
+ protected final byte[] convertDoubleToByteArray(double value, int byteOrder) {
byte result[] = new byte[8];
long bits = Double.doubleToRawLongBits(value);
@@ -935,8 +827,7 @@ public class BinaryFileFunctions impleme
result[5] = (byte) (0xff & (bits >> 40));
result[6] = (byte) (0xff & (bits >> 48));
result[7] = (byte) (0xff & (bits >> 56));
- } else
- {
+ } else {
result[7] = (byte) (0xff & (bits >> 0));
result[6] = (byte) (0xff & (bits >> 8));
result[5] = (byte) (0xff & (bits >> 16));
@@ -951,11 +842,9 @@ public class BinaryFileFunctions impleme
}
protected final byte[] convertDoubleArrayToByteArray(double values[],
- int byteOrder)
- {
+ int byteOrder) {
byte result[] = new byte[values.length * 8];
- for (int i = 0; i < values.length; i++)
- {
+ for (int i = 0; i < values.length; i++) {
double value = values[i];
long bits = Double.doubleToRawLongBits(value);
@@ -970,8 +859,7 @@ public class BinaryFileFunctions impleme
result[start + 5] = (byte) (0xff & (bits >> 40));
result[start + 6] = (byte) (0xff & (bits >> 48));
result[start + 7] = (byte) (0xff & (bits >> 56));
- } else
- {
+ } else {
result[start + 7] = (byte) (0xff & (bits >> 0));
result[start + 6] = (byte) (0xff & (bits >> 8));
result[start + 5] = (byte) (0xff & (bits >> 16));
@@ -986,14 +874,12 @@ public class BinaryFileFunctions impleme
}
protected final double convertByteArrayToDouble(String name, byte bytes[],
- int byteOrder)
- {
+ int byteOrder) {
return convertByteArrayToDouble(name, bytes, 0, byteOrder);
}
protected final double convertByteArrayToDouble(String name, byte bytes[],
- int start, int byteOrder)
- {
+ int start, int byteOrder) {
byte byte0 = bytes[start + 0];
byte byte1 = bytes[start + 1];
byte byte2 = bytes[start + 2];
@@ -1012,8 +898,7 @@ public class BinaryFileFunctions impleme
| ((0xffL & byte4) << 24) | ((0xffL & byte5) << 16)
| ((0xffL & byte6) << 8) | ((0xffL & byte7) << 0);
- } else
- {
+ } else {
// intel, little endian
bits = ((0xffL & byte7) << 56) | ((0xffL & byte6) << 48)
| ((0xffL & byte5) << 40) | ((0xffL & byte4) << 32)
@@ -1069,12 +954,10 @@ public class BinaryFileFunctions impleme
}
protected final double[] convertByteArrayToDoubleArray(String name,
- byte bytes[], int start, int length, int byteOrder)
- {
+ byte bytes[], int start, int length, int byteOrder) {
int expectedLength = start + length * 8;
- if (bytes.length < expectedLength)
- {
+ if (bytes.length < expectedLength) {
System.out.println(name + ": expected length: " + expectedLength
+ ", actual length: " + bytes.length);
return null;
@@ -1082,8 +965,7 @@ public class BinaryFileFunctions impleme
double result[] = new double[length];
- for (int i = 0; i < length; i++)
- {
+ for (int i = 0; i < length; i++) {
result[i] = convertByteArrayToDouble(name, bytes, start + i * 8,
byteOrder);
}
@@ -1091,26 +973,22 @@ public class BinaryFileFunctions impleme
return result;
}
- protected void skipBytes(InputStream is, int length) throws IOException
- {
+ protected void skipBytes(InputStream is, int length) throws IOException {
this.skipBytes(is, length, "Couldn't skip bytes");
}
public final void copyStreamToStream(InputStream is, OutputStream os)
- throws IOException
- {
+ throws IOException {
byte buffer[] = new byte[1024];
int read;
- while ((read = is.read(buffer)) > 0)
- {
+ while ((read = is.read(buffer)) > 0) {
os.write(buffer, 0, read);
}
}
- public final byte[] getStreamBytes(InputStream is) throws IOException
- {
+ public final byte[] getStreamBytes(InputStream is) throws IOException {
ByteArrayOutputStream os = new ByteArrayOutputStream();
copyStreamToStream(is, os);
return os.toByteArray();
}
-}
\ No newline at end of file
+}
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryFileParser.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryFileParser.java?rev=1342914&r1=1342913&r2=1342914&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryFileParser.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryFileParser.java Sat May 26 15:35:04 2012
@@ -21,15 +21,12 @@ import java.io.InputStream;
import org.apache.commons.imaging.ImageReadException;
-public class BinaryFileParser extends BinaryFileFunctions
-{
- public BinaryFileParser(int byteOrder)
- {
+public class BinaryFileParser extends BinaryFileFunctions {
+ public BinaryFileParser(int byteOrder) {
this.byteOrder = byteOrder;
}
- public BinaryFileParser()
- {
+ public BinaryFileParser() {
}
@@ -38,8 +35,7 @@ public class BinaryFileParser extends Bi
// protected boolean BYTE_ORDER_reversed = true;
- protected void setByteOrder(int a, int b) throws ImageReadException
- {
+ protected void setByteOrder(int a, int b) throws ImageReadException {
if (a != b)
throw new ImageReadException("Byte Order bytes don't match (" + a
+ ", " + b + ").");
@@ -52,54 +48,45 @@ public class BinaryFileParser extends Bi
throw new ImageReadException("Unknown Byte Order hint: " + a);
}
- protected void setByteOrder(int byteOrder)
- {
+ protected void setByteOrder(int byteOrder) {
this.byteOrder = byteOrder;
}
- public int getByteOrder()
- {
+ public int getByteOrder() {
return byteOrder;
}
protected final int convertByteArrayToInt(String name, int start,
- byte bytes[])
- {
+ byte bytes[]) {
return convertByteArrayToInt(name, bytes, start, byteOrder);
}
- protected final int convertByteArrayToInt(String name, byte bytes[])
- {
+ protected final int convertByteArrayToInt(String name, byte bytes[]) {
return convertByteArrayToInt(name, bytes, byteOrder);
}
public final int convertByteArrayToShort(String name, byte bytes[])
- throws ImageReadException
- {
+ throws ImageReadException {
return convertByteArrayToShort(name, bytes, byteOrder);
}
public final int convertByteArrayToShort(String name, int start,
- byte bytes[]) throws ImageReadException
- {
+ byte bytes[]) throws ImageReadException {
return convertByteArrayToShort(name, start, bytes, byteOrder);
}
public final int read4Bytes(String name, InputStream is, String exception)
- throws IOException
- {
+ throws IOException {
return read4Bytes(name, is, exception, byteOrder);
}
public final int read3Bytes(String name, InputStream is, String exception)
- throws IOException
- {
+ throws IOException {
return read3Bytes(name, is, exception, byteOrder);
}
public final int read2Bytes(String name, InputStream is, String exception)
- throws ImageReadException, IOException
- {
+ throws ImageReadException, IOException {
return read2Bytes(name, is, exception, byteOrder);
}
@@ -113,9 +100,8 @@ public class BinaryFileParser extends Bi
return true;
}
-
- public static boolean byteArrayHasPrefix(byte bytes[], byte prefix[])
- {
+
+ public static boolean byteArrayHasPrefix(byte bytes[], byte prefix[]) {
if ((bytes == null) || (bytes.length < prefix.length))
return false;
@@ -126,9 +112,8 @@ public class BinaryFileParser extends Bi
return true;
}
- protected final byte[] int2ToByteArray(int value)
- {
+ protected final byte[] int2ToByteArray(int value) {
return int2ToByteArray(value, byteOrder);
}
-}
\ No newline at end of file
+}
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryInputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryInputStream.java?rev=1342914&r1=1342913&r2=1342914&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryInputStream.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryInputStream.java Sat May 26 15:35:04 2012
@@ -23,44 +23,37 @@ import java.io.RandomAccessFile;
import org.apache.commons.imaging.ImageReadException;
-public class BinaryInputStream extends InputStream implements BinaryConstants
-{
+public class BinaryInputStream extends InputStream implements BinaryConstants {
protected boolean debug = false;
- public final void setDebug(boolean b)
- {
+ public final void setDebug(boolean b) {
debug = b;
}
- public final boolean getDebug()
- {
+ public final boolean getDebug() {
return debug;
}
private final InputStream is;
- public BinaryInputStream(byte bytes[], int byteOrder)
- {
+ public BinaryInputStream(byte bytes[], int byteOrder) {
this.byteOrder = byteOrder;
this.is = new ByteArrayInputStream(bytes);
}
- public BinaryInputStream(InputStream is, int byteOrder)
- {
+ public BinaryInputStream(InputStream is, int byteOrder) {
this.byteOrder = byteOrder;
this.is = is;
}
- public BinaryInputStream(InputStream is)
- {
+ public BinaryInputStream(InputStream is) {
this.is = is;
}
// default byte order for Java, many file formats.
private int byteOrder = BYTE_ORDER_NETWORK;
- protected void setByteOrder(int a, int b) throws ImageReadException
- {
+ protected void setByteOrder(int a, int b) throws ImageReadException {
if (a != b)
throw new ImageReadException("Byte Order bytes don't match (" + a
+ ", " + b + ").");
@@ -73,76 +66,62 @@ public class BinaryInputStream extends I
throw new ImageReadException("Unknown Byte Order hint: " + a);
}
- protected void setByteOrder(int byteOrder)
- {
+ protected void setByteOrder(int byteOrder) {
this.byteOrder = byteOrder;
}
- protected int getByteOrder()
- {
+ protected int getByteOrder() {
return byteOrder;
}
@Override
- public int read() throws IOException
- {
+ public int read() throws IOException {
return is.read();
}
- protected final int convertByteArrayToInt(String name, byte bytes[])
- {
+ protected final int convertByteArrayToInt(String name, byte bytes[]) {
return convertByteArrayToInt(name, bytes, byteOrder);
}
- public final int convertByteArrayToShort(String name, byte bytes[])
- {
+ public final int convertByteArrayToShort(String name, byte bytes[]) {
return convertByteArrayToShort(name, bytes, byteOrder);
}
public final int convertByteArrayToShort(String name, int start,
- byte bytes[])
- {
+ byte bytes[]) {
return convertByteArrayToShort(name, start, bytes, byteOrder);
}
public final int read4Bytes(String name, String exception)
- throws IOException
- {
+ throws IOException {
return read4Bytes(name, exception, byteOrder);
}
public final int read3Bytes(String name, String exception)
- throws IOException
- {
+ throws IOException {
return read3Bytes(name, exception, byteOrder);
}
public final int read2Bytes(String name, String exception)
- throws IOException
- {
+ throws IOException {
return read2Bytes(name, exception, byteOrder);
}
- protected final void readRandomBytes() throws IOException
- {
+ protected final void readRandomBytes() throws IOException {
- for (int counter = 0; counter < 100; counter++)
- {
+ for (int counter = 0; counter < 100; counter++) {
readByte("" + counter, "Random Data");
}
}
- public final void debugNumber(String msg, int data)
- {
+ public final void debugNumber(String msg, int data) {
debugNumber(msg, data, 1);
}
- public final void debugNumber(String msg, int data, int bytes)
- {
+ public final void debugNumber(String msg, int data, int bytes) {
System.out.print(msg + ": " + data + " (");
int byteData = data;
- for (int i = 0; i < bytes; i++)
- {
+ for (int i = 0; i < bytes; i++) {
if (i > 0)
System.out.print(",");
int singleByte = 0xff & byteData;
@@ -154,15 +133,12 @@ public class BinaryInputStream extends I
}
public final void readAndVerifyBytes(byte expected[], String exception)
- throws ImageReadException, IOException
- {
- for (int i = 0; i < expected.length; i++)
- {
+ throws ImageReadException, IOException {
+ for (int i = 0; i < expected.length; i++) {
int data = is.read();
byte b = (byte) (0xff & data);
- if ((data < 0) || (b != expected[i]))
- {
+ if ((data < 0) || (b != expected[i])) {
System.out.println("i" + ": " + i);
this.debugByteArray("expected", expected);
@@ -175,14 +151,11 @@ public class BinaryInputStream extends I
}
protected final void readAndVerifyBytes(String name, byte expected[],
- String exception) throws ImageReadException, IOException
- {
+ String exception) throws ImageReadException, IOException {
byte bytes[] = readByteArray(name, expected.length, exception);
- for (int i = 0; i < expected.length; i++)
- {
- if (bytes[i] != expected[i])
- {
+ for (int i = 0; i < expected.length; i++) {
+ if (bytes[i] != expected[i]) {
System.out.println("i" + ": " + i);
debugNumber("bytes[" + i + "]", bytes[i]);
debugNumber("expected[" + i + "]", expected[i]);
@@ -193,11 +166,9 @@ public class BinaryInputStream extends I
}
public final void skipBytes(int length, String exception)
- throws IOException
- {
+ throws IOException {
long total = 0;
- while (length != total)
- {
+ while (length != total) {
long skipped = is.skip(length - total);
if (skipped < 1)
throw new IOException(exception + " (" + skipped + ")");
@@ -205,8 +176,7 @@ public class BinaryInputStream extends I
}
}
- protected final void scanForByte(byte value) throws IOException
- {
+ protected final void scanForByte(byte value) throws IOException {
int count = 0;
for (int i = 0; count < 3; i++)
// while(count<3)
@@ -214,8 +184,7 @@ public class BinaryInputStream extends I
int b = is.read();
if (b < 0)
return;
- if ((0xff & b) == value)
- {
+ if ((0xff & b) == value) {
System.out.println("\t" + i + ": match.");
count++;
}
@@ -223,12 +192,10 @@ public class BinaryInputStream extends I
}
public final byte readByte(String name, String exception)
- throws IOException
- {
+ throws IOException {
int result = is.read();
- if ((result < 0))
- {
+ if ((result < 0)) {
System.out.println(name + ": " + result);
throw new IOException(exception);
}
@@ -240,12 +207,10 @@ public class BinaryInputStream extends I
}
protected final RationalNumber[] convertByteArrayToRationalArray(
- String name, byte bytes[], int start, int length, int byteOrder)
- {
+ String name, byte bytes[], int start, int length, int byteOrder) {
int expectedLength = start + length * 8;
- if (bytes.length < expectedLength)
- {
+ if (bytes.length < expectedLength) {
System.out.println(name + ": expected length: " + expectedLength
+ ", actual length: " + bytes.length);
return null;
@@ -253,8 +218,7 @@ public class BinaryInputStream extends I
RationalNumber result[] = new RationalNumber[length];
- for (int i = 0; i < length; i++)
- {
+ for (int i = 0; i < length; i++) {
result[i] = convertByteArrayToRational(name, bytes, start + i * 8,
byteOrder);
}
@@ -263,14 +227,12 @@ public class BinaryInputStream extends I
}
protected final RationalNumber convertByteArrayToRational(String name,
- byte bytes[], int byteOrder)
- {
+ byte bytes[], int byteOrder) {
return convertByteArrayToRational(name, bytes, 0, byteOrder);
}
protected final RationalNumber convertByteArrayToRational(String name,
- byte bytes[], int start, int byteOrder)
- {
+ byte bytes[], int start, int byteOrder) {
int numerator = convertByteArrayToInt(name, bytes, start + 0, 4,
byteOrder);
int divisor = convertByteArrayToInt(name, bytes, start + 4, 4,
@@ -280,14 +242,12 @@ public class BinaryInputStream extends I
}
protected final int convertByteArrayToInt(String name, byte bytes[],
- int byteOrder)
- {
+ int byteOrder) {
return convertByteArrayToInt(name, bytes, 0, 4, byteOrder);
}
protected final int convertByteArrayToInt(String name, byte bytes[],
- int start, int length, int byteOrder)
- {
+ int start, int length, int byteOrder) {
byte byte0 = bytes[start + 0];
byte byte1 = bytes[start + 1];
byte byte2 = bytes[start + 2];
@@ -319,12 +279,10 @@ public class BinaryInputStream extends I
}
protected final int[] convertByteArrayToIntArray(String name, byte bytes[],
- int start, int length, int byteOrder)
- {
+ int start, int length, int byteOrder) {
int expectedLength = start + length * 4;
- if (bytes.length < expectedLength)
- {
+ if (bytes.length < expectedLength) {
System.out.println(name + ": expected length: " + expectedLength
+ ", actual length: " + bytes.length);
return null;
@@ -332,8 +290,7 @@ public class BinaryInputStream extends I
int result[] = new int[length];
- for (int i = 0; i < length; i++)
- {
+ for (int i = 0; i < length; i++) {
result[i] = convertByteArrayToInt(name, bytes, start + i * 4, 4,
byteOrder);
}
@@ -342,14 +299,12 @@ public class BinaryInputStream extends I
}
protected final int convertByteArrayToShort(String name, byte bytes[],
- int byteOrder)
- {
+ int byteOrder) {
return convertByteArrayToShort(name, 0, bytes, byteOrder);
}
protected final int convertByteArrayToShort(String name, int start,
- byte bytes[], int byteOrder)
- {
+ byte bytes[], int byteOrder) {
byte byte0 = bytes[start + 0];
byte byte1 = bytes[start + 1];
@@ -370,12 +325,10 @@ public class BinaryInputStream extends I
}
protected final int[] convertByteArrayToShortArray(String name,
- byte bytes[], int start, int length, int byteOrder)
- {
+ byte bytes[], int start, int length, int byteOrder) {
int expectedLength = start + length * 2;
- if (bytes.length < expectedLength)
- {
+ if (bytes.length < expectedLength) {
System.out.println(name + ": expected length: " + expectedLength
+ ", actual length: " + bytes.length);
return null;
@@ -383,8 +336,7 @@ public class BinaryInputStream extends I
int result[] = new int[length];
- for (int i = 0; i < length; i++)
- {
+ for (int i = 0; i < length; i++) {
result[i] = convertByteArrayToShort(name, start + i * 2, bytes,
byteOrder);
@@ -397,13 +349,11 @@ public class BinaryInputStream extends I
}
public final byte[] readByteArray(String name, int length, String exception)
- throws IOException
- {
+ throws IOException {
byte result[] = new byte[length];
int read = 0;
- while (read < length)
- {
+ while (read < length) {
int count = is.read(result, read, length - read);
if (count < 1)
throw new IOException(exception);
@@ -411,39 +361,32 @@ public class BinaryInputStream extends I
read += count;
}
- if (debug)
- {
- for (int i = 0; ((i < length) && (i < 150)); i++)
- {
+ if (debug) {
+ for (int i = 0; ((i < length) && (i < 150)); i++) {
debugNumber(name + " (" + i + ")", 0xff & result[i]);
}
}
return result;
}
- protected final void debugByteArray(String name, byte bytes[])
- {
+ protected final void debugByteArray(String name, byte bytes[]) {
System.out.println(name + ": " + bytes.length);
- for (int i = 0; ((i < bytes.length) && (i < 50)); i++)
- {
+ for (int i = 0; ((i < bytes.length) && (i < 50)); i++) {
debugNumber(name + " (" + i + ")", bytes[i]);
}
}
- protected final void debugNumberArray(String name, int numbers[], int length)
- {
+ protected final void debugNumberArray(String name, int numbers[], int length) {
System.out.println(name + ": " + numbers.length);
- for (int i = 0; ((i < numbers.length) && (i < 50)); i++)
- {
+ for (int i = 0; ((i < numbers.length) && (i < 50)); i++) {
debugNumber(name + " (" + i + ")", numbers[i], length);
}
}
public final byte[] readBytearray(String name, byte bytes[], int start,
- int count)
- {
+ int count) {
if (bytes.length < (start + count))
return null;
@@ -457,8 +400,7 @@ public class BinaryInputStream extends I
}
public final byte[] readByteArray(int length, String error)
- throws ImageReadException, IOException
- {
+ throws ImageReadException, IOException {
boolean verbose = false;
boolean strict = true;
return readByteArray(length, error, verbose, strict);
@@ -466,46 +408,39 @@ public class BinaryInputStream extends I
public final byte[] readByteArray(int length, String error,
boolean verbose, boolean strict) throws ImageReadException,
- IOException
- {
+ IOException {
byte bytes[] = new byte[length];
int total = 0;
int read;
while ((read = read(bytes, total, length - total)) > 0)
total += read;
- if (total < length)
- {
+ if (total < length) {
if (strict)
throw new ImageReadException(error);
- else if(verbose)
+ else if (verbose)
System.out.println(error);
return null;
}
return bytes;
}
- protected final byte[] getBytearrayTail(String name, byte bytes[], int count)
- {
+ protected final byte[] getBytearrayTail(String name, byte bytes[], int count) {
return readBytearray(name, bytes, count, bytes.length - count);
}
- protected final byte[] getBytearrayHead(String name, byte bytes[], int count)
- {
+ protected final byte[] getBytearrayHead(String name, byte bytes[], int count) {
return readBytearray(name, bytes, 0, bytes.length - count);
}
public final boolean compareByteArrays(byte a[], int aStart, byte b[],
- int bStart, int length)
- {
+ int bStart, int length) {
if (a.length < (aStart + length))
return false;
if (b.length < (bStart + length))
return false;
- for (int i = 0; i < length; i++)
- {
- if (a[aStart + i] != b[bStart + i])
- {
+ for (int i = 0; i < length; i++) {
+ if (a[aStart + i] != b[bStart + i]) {
debugNumber("a[" + (aStart + i) + "]", a[aStart + i]);
debugNumber("b[" + (bStart + i) + "]", b[bStart + i]);
@@ -517,14 +452,12 @@ public class BinaryInputStream extends I
}
protected final int read4Bytes(String name, String exception, int byteOrder)
- throws IOException
- {
+ throws IOException {
int size = 4;
byte bytes[] = new byte[size];
int read = 0;
- while (read < size)
- {
+ while (read < size) {
int count = is.read(bytes, read, size - read);
if (count < 1)
throw new IOException(exception);
@@ -536,14 +469,12 @@ public class BinaryInputStream extends I
}
protected final int read3Bytes(String name, String exception, int byteOrder)
- throws IOException
- {
+ throws IOException {
int size = 3;
byte bytes[] = new byte[size];
int read = 0;
- while (read < size)
- {
+ while (read < size) {
int count = is.read(bytes, read, size - read);
if (count < 1)
throw new IOException(exception);
@@ -556,14 +487,12 @@ public class BinaryInputStream extends I
}
protected final int read2Bytes(String name, String exception, int byteOrder)
- throws IOException
- {
+ throws IOException {
int size = 2;
byte bytes[] = new byte[size];
int read = 0;
- while (read < size)
- {
+ while (read < size) {
int count = is.read(bytes, read, size - read);
if (count < 1)
throw new IOException(exception);
@@ -575,8 +504,7 @@ public class BinaryInputStream extends I
}
public final int read1ByteInteger(String exception)
- throws ImageReadException, IOException
- {
+ throws ImageReadException, IOException {
int byte0 = is.read();
if (byte0 < 0)
throw new ImageReadException(exception);
@@ -585,8 +513,7 @@ public class BinaryInputStream extends I
}
public final int read2ByteInteger(String exception)
- throws ImageReadException, IOException
- {
+ throws ImageReadException, IOException {
int byte0 = is.read();
int byte1 = is.read();
if (byte0 < 0 || byte1 < 0)
@@ -600,8 +527,7 @@ public class BinaryInputStream extends I
}
public final int read4ByteInteger(String exception)
- throws ImageReadException, IOException
- {
+ throws ImageReadException, IOException {
int byte0 = is.read();
int byte1 = is.read();
int byte2 = is.read();
@@ -618,33 +544,27 @@ public class BinaryInputStream extends I
+ ((0xff & byte1) << 8) + ((0xff & byte0) << 0);
}
- protected final void printCharQuad(String msg, int i)
- {
+ protected final void printCharQuad(String msg, int i) {
System.out.println(msg + ": '" + (char) (0xff & (i >> 24))
+ (char) (0xff & (i >> 16)) + (char) (0xff & (i >> 8))
+ (char) (0xff & (i >> 0)) + "'");
}
- protected final void printByteBits(String msg, byte i)
- {
+ protected final void printByteBits(String msg, byte i) {
System.out.println(msg + ": '" + Integer.toBinaryString(0xff & i));
}
- protected final static int charsToQuad(char c1, char c2, char c3, char c4)
- {
+ protected final static int charsToQuad(char c1, char c2, char c3, char c4) {
return (((0xff & c1) << 24) | ((0xff & c2) << 16) | ((0xff & c3) << 8) | ((0xff & c4) << 0));
}
- public final int findNull(byte src[])
- {
+ public final int findNull(byte src[]) {
return findNull(src, 0);
}
- public final int findNull(byte src[], int start)
- {
- for (int i = start; i < src.length; i++)
- {
+ public final int findNull(byte src[], int start) {
+ for (int i = start; i < src.length; i++) {
if (src[i] == 0)
return i;
@@ -653,12 +573,10 @@ public class BinaryInputStream extends I
}
protected final byte[] getRAFBytes(RandomAccessFile raf, long pos,
- int length, String exception) throws IOException
- {
+ int length, String exception) throws IOException {
byte result[] = new byte[length];
- if (debug)
- {
+ if (debug) {
System.out.println("getRAFBytes pos" + ": " + pos);
System.out.println("getRAFBytes length" + ": " + length);
}
@@ -666,8 +584,7 @@ public class BinaryInputStream extends I
raf.seek(pos);
int read = 0;
- while (read < length)
- {
+ while (read < length) {
int count = raf.read(result, read, length - read);
if (count < 1)
throw new IOException(exception);
@@ -679,9 +596,8 @@ public class BinaryInputStream extends I
}
- protected void skipBytes(int length) throws IOException
- {
+ protected void skipBytes(int length) throws IOException {
skipBytes(length, "Couldn't skip bytes");
}
-}
\ No newline at end of file
+}
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryOutputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryOutputStream.java?rev=1342914&r1=1342913&r2=1342914&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryOutputStream.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryOutputStream.java Sat May 26 15:35:04 2012
@@ -21,39 +21,33 @@ import java.io.OutputStream;
import org.apache.commons.imaging.ImageWriteException;
-public class BinaryOutputStream extends OutputStream implements BinaryConstants
-{
+public class BinaryOutputStream extends OutputStream implements BinaryConstants {
protected boolean debug = false;
private int count = 0;
- public final void setDebug(boolean b)
- {
+ public final void setDebug(boolean b) {
debug = b;
}
- public final boolean getDebug()
- {
+ public final boolean getDebug() {
return debug;
}
private final OutputStream os;
- public BinaryOutputStream(OutputStream os, int byteOrder)
- {
+ public BinaryOutputStream(OutputStream os, int byteOrder) {
this.byteOrder = byteOrder;
this.os = os;
}
- public BinaryOutputStream(OutputStream os)
- {
+ public BinaryOutputStream(OutputStream os) {
this.os = os;
}
// default byte order for Java, many file formats.
private int byteOrder = BYTE_ORDER_NETWORK;
- protected void setByteOrder(int a, int b) throws ImageWriteException
- {
+ protected void setByteOrder(int a, int b) throws ImageWriteException {
if (a != b)
throw new ImageWriteException("Byte Order bytes don't match (" + a
+ ", " + b + ").");
@@ -66,53 +60,43 @@ public class BinaryOutputStream extends
throw new ImageWriteException("Unknown Byte Order hint: " + a);
}
- protected void setByteOrder(int byteOrder)
- {
+ protected void setByteOrder(int byteOrder) {
this.byteOrder = byteOrder;
}
- public int getByteOrder()
- {
+ public int getByteOrder() {
return byteOrder;
}
@Override
- public void write(int i) throws IOException
- {
+ public void write(int i) throws IOException {
os.write(i);
count++;
}
- public int getByteCount()
- {
+ public int getByteCount() {
return count;
}
- public final void write4Bytes(int value) throws IOException
- {
+ public final void write4Bytes(int value) throws IOException {
writeNBytes(value, 4);
}
- public final void write3Bytes(int value) throws IOException
- {
+ public final void write3Bytes(int value) throws IOException {
writeNBytes(value, 3);
}
- public final void write2Bytes(int value) throws IOException
- {
+ public final void write2Bytes(int value) throws IOException {
writeNBytes(value, 2);
}
- public final void write4ByteInteger(int value) throws IOException
- {
- if (byteOrder == BYTE_ORDER_MOTOROLA)
- {
+ public final void write4ByteInteger(int value) throws IOException {
+ if (byteOrder == BYTE_ORDER_MOTOROLA) {
write(0xff & (value >> 24));
write(0xff & (value >> 16));
write(0xff & (value >> 8));
write(0xff & value);
- } else
- {
+ } else {
write(0xff & value);
write(0xff & (value >> 8));
write(0xff & (value >> 16));
@@ -120,40 +104,31 @@ public class BinaryOutputStream extends
}
}
- public final void write2ByteInteger(int value) throws IOException
- {
- if (byteOrder == BYTE_ORDER_MOTOROLA)
- {
+ public final void write2ByteInteger(int value) throws IOException {
+ if (byteOrder == BYTE_ORDER_MOTOROLA) {
write(0xff & (value >> 8));
write(0xff & value);
- } else
- {
+ } else {
write(0xff & value);
write(0xff & (value >> 8));
}
}
- public final void writeByteArray(byte bytes[]) throws IOException
- {
+ public final void writeByteArray(byte bytes[]) throws IOException {
os.write(bytes, 0, bytes.length);
count += bytes.length;
}
- private byte[] convertValueToByteArray(int value, int n)
- {
+ private byte[] convertValueToByteArray(int value, int n) {
byte result[] = new byte[n];
- if (byteOrder == BYTE_ORDER_MOTOROLA)
- {
- for (int i = 0; i < n; i++)
- {
+ if (byteOrder == BYTE_ORDER_MOTOROLA) {
+ for (int i = 0; i < n; i++) {
int b = 0xff & (value >> (8 * (n - i - 1)));
result[i] = (byte) b;
}
- } else
- {
- for (int i = 0; i < n; i++)
- {
+ } else {
+ for (int i = 0; i < n; i++) {
int b = 0xff & (value >> (8 * i));
result[i] = (byte) b;
}
@@ -162,10 +137,8 @@ public class BinaryOutputStream extends
return result;
}
- private final void writeNBytes(int value, int n)
- throws IOException
- {
+ private final void writeNBytes(int value, int n) throws IOException {
write(convertValueToByteArray(value, n));
}
-}
\ No newline at end of file
+}
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BitArrayOutputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BitArrayOutputStream.java?rev=1342914&r1=1342913&r2=1342914&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BitArrayOutputStream.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BitArrayOutputStream.java Sat May 26 15:35:04 2012
@@ -78,13 +78,13 @@ public class BitArrayOutputStream {
}
return count;
}
-
+
private void writeByte(int b) {
if (bytesWritten >= buffer.length) {
byte[] bigger = new byte[buffer.length * 2];
System.arraycopy(buffer, 0, bigger, 0, bytesWritten);
buffer = bigger;
}
- buffer[bytesWritten++] = (byte)b;
+ buffer[bytesWritten++] = (byte) b;
}
}
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BitInputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BitInputStream.java?rev=1342914&r1=1342913&r2=1342914&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BitInputStream.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BitInputStream.java Sat May 26 15:35:04 2012
@@ -19,22 +19,19 @@ package org.apache.commons.imaging.commo
import java.io.IOException;
import java.io.InputStream;
-public class BitInputStream extends InputStream implements BinaryConstants
-{
-
+public class BitInputStream extends InputStream implements BinaryConstants {
+
private final InputStream is;
private final int byteOrder;
- public BitInputStream(InputStream is, int byteOrder)
- {
+ public BitInputStream(InputStream is, int byteOrder) {
this.is = is;
this.byteOrder = byteOrder;
- // super(is);
+ // super(is);
}
@Override
- public int read() throws IOException
- {
+ public int read() throws IOException {
if (cacheBitsRemaining > 0)
throw new IOException("BitInputStream: incomplete bit read");
return is.read();
@@ -44,12 +41,9 @@ public class BitInputStream extends Inpu
private int cacheBitsRemaining = 0;
private long bytes_read = 0;
- public final int readBits(int count) throws IOException
- {
- if (count < 8)
- {
- if (cacheBitsRemaining == 0)
- {
+ public final int readBits(int count) throws IOException {
+ if (count < 8) {
+ if (cacheBitsRemaining == 0) {
// fill cache
cache = is.read();
cacheBitsRemaining = 8;
@@ -59,95 +53,83 @@ public class BitInputStream extends Inpu
throw new IOException(
"BitInputStream: can't read bit fields across bytes");
- // int bits_to_shift = cache_bits_remaining - count;
+ // int bits_to_shift = cache_bits_remaining - count;
cacheBitsRemaining -= count;
int bits = cache >> cacheBitsRemaining;
- switch (count)
- {
- case 1 :
- return bits & 1;
- case 2 :
- return bits & 3;
- case 3 :
- return bits & 7;
- case 4 :
- return bits & 15;
- case 5 :
- return bits & 31;
- case 6 :
- return bits & 63;
- case 7 :
- return bits & 127;
+ switch (count) {
+ case 1:
+ return bits & 1;
+ case 2:
+ return bits & 3;
+ case 3:
+ return bits & 7;
+ case 4:
+ return bits & 15;
+ case 5:
+ return bits & 31;
+ case 6:
+ return bits & 63;
+ case 7:
+ return bits & 127;
}
}
if (cacheBitsRemaining > 0)
throw new IOException("BitInputStream: incomplete bit read");
- if (count == 8)
- {
+ if (count == 8) {
bytes_read++;
return is.read();
}
-
+
/**
- * Taking default order of the Tiff to be
- * Little Endian and reversing the bytes in the end
- * if its Big Endian.This is done because majority (may be all)
- * of the files will be of Little Endian.
+ * Taking default order of the Tiff to be Little Endian and reversing
+ * the bytes in the end if its Big Endian.This is done because majority
+ * (may be all) of the files will be of Little Endian.
*/
- if(byteOrder == BYTE_ORDER_BIG_ENDIAN) {
- if (count == 16)
- {
+ if (byteOrder == BYTE_ORDER_BIG_ENDIAN) {
+ if (count == 16) {
bytes_read += 2;
return (is.read() << 8) | (is.read() << 0);
}
- if (count == 24)
- {
+ if (count == 24) {
bytes_read += 3;
return (is.read() << 16) | (is.read() << 8) | (is.read() << 0);
}
- if (count == 32)
- {
+ if (count == 32) {
bytes_read += 4;
return (is.read() << 24) | (is.read() << 16) | (is.read() << 8)
| (is.read() << 0);
}
- }
- else
- {
- if(count == 16)
- {
- bytes_read +=2;
+ } else {
+ if (count == 16) {
+ bytes_read += 2;
return ((is.read() << 0) | (is.read() << 8));
}
-
- if(count == 24)
- {
+
+ if (count == 24) {
bytes_read += 3;
return ((is.read() << 0) | (is.read() << 8) | (is.read() << 16));
}
-
- if(count == 32)
- {
+
+ if (count == 32) {
bytes_read += 4;
- return ((is.read() << 0) | (is.read() << 8) | (is.read() << 16) | (is.read() << 24));
+ return ((is.read() << 0) | (is.read() << 8) | (is.read() << 16) | (is
+ .read() << 24));
}
- }
+ }
throw new IOException("BitInputStream: unknown error");
}
- public void flushCache()
- {
+ public void flushCache() {
cacheBitsRemaining = 0;
}
- public long getBytesRead()
- {
+ public long getBytesRead() {
return bytes_read;
}
-}
\ No newline at end of file
+}
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BitInputStreamFlexible.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BitInputStreamFlexible.java?rev=1342914&r1=1342913&r2=1342914&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BitInputStreamFlexible.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BitInputStreamFlexible.java Sat May 26 15:35:04 2012
@@ -19,23 +19,19 @@ package org.apache.commons.imaging.commo
import java.io.IOException;
import java.io.InputStream;
-public class BitInputStreamFlexible extends InputStream
- implements
- BinaryConstants
-{
+public class BitInputStreamFlexible extends InputStream implements
+ BinaryConstants {
// TODO should be byte order conscious, ie TIFF for reading
// samples size<8 - shuoldn't that effect their order within byte?
private final InputStream is;
- public BitInputStreamFlexible(InputStream is)
- {
+ public BitInputStreamFlexible(InputStream is) {
this.is = is;
- // super(is);
+ // super(is);
}
@Override
- public int read() throws IOException
- {
+ public int read() throws IOException {
if (cacheBitsRemaining > 0)
throw new IOException("BitInputStream: incomplete bit read");
return is.read();
@@ -45,50 +41,43 @@ public class BitInputStreamFlexible exte
private int cacheBitsRemaining = 0;
private long bytesRead = 0;
- public final int readBits(int count) throws IOException
- {
+ public final int readBits(int count) throws IOException {
if (count <= 32) // catch-all
{
int result = 0;
- // int done = 0;
+ // int done = 0;
- if (cacheBitsRemaining > 0)
- {
- if (count >= cacheBitsRemaining)
- {
+ if (cacheBitsRemaining > 0) {
+ if (count >= cacheBitsRemaining) {
result = ((1 << cacheBitsRemaining) - 1) & cache;
count -= cacheBitsRemaining;
cacheBitsRemaining = 0;
- }
- else
- {
- // cache >>= count;
+ } else {
+ // cache >>= count;
cacheBitsRemaining -= count;
result = ((1 << count) - 1) & (cache >> cacheBitsRemaining);
count = 0;
}
}
- while (count >= 8)
- {
+ while (count >= 8) {
cache = is.read();
if (cache < 0)
throw new IOException("couldn't read bits");
-// System.out.println("cache 1: " + cache + " ("
-// + Integer.toHexString(cache) + ", "
-// + Integer.toBinaryString(cache) + ")");
+ // System.out.println("cache 1: " + cache + " ("
+ // + Integer.toHexString(cache) + ", "
+ // + Integer.toBinaryString(cache) + ")");
bytesRead++;
result = (result << 8) | (0xff & cache);
count -= 8;
}
- if (count > 0)
- {
+ if (count > 0) {
cache = is.read();
if (cache < 0)
throw new IOException("couldn't read bits");
-// System.out.println("cache 2: " + cache + " ("
-// + Integer.toHexString(cache) + ", "
-// + Integer.toBinaryString(cache) + ")");
+ // System.out.println("cache 2: " + cache + " ("
+ // + Integer.toHexString(cache) + ", "
+ // + Integer.toBinaryString(cache) + ")");
bytesRead++;
cacheBitsRemaining = 8 - count;
result = (result << count)
@@ -103,13 +92,11 @@ public class BitInputStreamFlexible exte
}
- public void flushCache()
- {
+ public void flushCache() {
cacheBitsRemaining = 0;
}
- public long getBytesRead()
- {
+ public long getBytesRead() {
return bytesRead;
}
-}
\ No newline at end of file
+}
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/Compression.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/Compression.java?rev=1342914&r1=1342913&r2=1342914&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/Compression.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/Compression.java Sat May 26 15:35:04 2012
@@ -24,12 +24,10 @@ import org.apache.commons.imaging.ImageR
import org.apache.commons.imaging.common.mylzw.MyLzwCompressor;
import org.apache.commons.imaging.common.mylzw.MyLzwDecompressor;
-public class Compression
-{
+public class Compression {
public byte[] decompressLZW(byte compressed[], int LZWMinimumCodeSize,
- int expectedSize, int byteOrder) throws IOException
- {
+ int expectedSize, int byteOrder) throws IOException {
InputStream is = new ByteArrayInputStream(compressed);
MyLzwDecompressor decompressor = new MyLzwDecompressor(
@@ -40,8 +38,7 @@ public class Compression
}
public byte[] decompressPackBits(byte compressed[], int expectedSize,
- int byteOrder) throws ImageReadException
- {
+ int byteOrder) throws ImageReadException {
byte unpacked[] = new PackBits().decompress(compressed, expectedSize);
return unpacked;
}
@@ -58,4 +55,4 @@ public class Compression
return compressed;
}
-}
\ No newline at end of file
+}
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/IBufferedImageFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/IBufferedImageFactory.java?rev=1342914&r1=1342913&r2=1342914&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/IBufferedImageFactory.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/IBufferedImageFactory.java Sat May 26 15:35:04 2012
@@ -19,8 +19,7 @@ package org.apache.commons.imaging.commo
import java.awt.image.BufferedImage;
-public interface IBufferedImageFactory
-{
+public interface IBufferedImageFactory {
public BufferedImage getColorBufferedImage(int width, int height,
boolean hasAlpha);
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/IImageMetadata.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/IImageMetadata.java?rev=1342914&r1=1342913&r2=1342914&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/IImageMetadata.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/IImageMetadata.java Sat May 26 15:35:04 2012
@@ -18,16 +18,14 @@ package org.apache.commons.imaging.commo
import java.util.List;
-public interface IImageMetadata
-{
+public interface IImageMetadata {
public String toString(String prefix);
public List<? extends IImageMetadataItem> getItems();
- public interface IImageMetadataItem
- {
+ public interface IImageMetadataItem {
public String toString(String prefix);
public String toString();
}
-}
\ No newline at end of file
+}
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/ImageBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/ImageBuilder.java?rev=1342914&r1=1342913&r2=1342914&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/ImageBuilder.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/ImageBuilder.java Sat May 26 15:35:04 2012
@@ -28,22 +28,22 @@ public class ImageBuilder {
private int width;
private int height;
private boolean hasAlpha;
-
+
public ImageBuilder(int width, int height, boolean hasAlpha) {
data = new int[width * height];
this.width = width;
this.height = height;
this.hasAlpha = hasAlpha;
}
-
+
public int getWidth() {
return width;
}
-
+
public int getHeight() {
return height;
}
-
+
public int getRGB(int x, int y) {
final int rowOffset = y * width;
return data[rowOffset + x];
@@ -53,27 +53,25 @@ public class ImageBuilder {
final int rowOffset = y * width;
data[rowOffset + x] = argb;
}
-
+
public BufferedImage getBufferedImage() {
ColorModel colorModel;
WritableRaster raster;
DataBufferInt buffer = new DataBufferInt(data, width * height);
if (hasAlpha) {
- colorModel = new DirectColorModel(32,
- 0x00ff0000,
- 0x0000ff00,
- 0x000000ff,
- 0xff000000);
- raster = WritableRaster.createPackedRaster(buffer, width, height, width,
- new int[] { 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, null);
+ colorModel = new DirectColorModel(32, 0x00ff0000, 0x0000ff00,
+ 0x000000ff, 0xff000000);
+ raster = WritableRaster.createPackedRaster(buffer, width, height,
+ width, new int[] { 0x00ff0000, 0x0000ff00, 0x000000ff,
+ 0xff000000 }, null);
} else {
- colorModel = new DirectColorModel(24,
- 0x00ff0000,
- 0x0000ff00,
+ colorModel = new DirectColorModel(24, 0x00ff0000, 0x0000ff00,
0x000000ff);
- raster = WritableRaster.createPackedRaster(buffer, width, height, width,
- new int[] { 0x00ff0000, 0x0000ff00, 0x000000ff }, null);
+ raster = WritableRaster.createPackedRaster(buffer, width, height,
+ width, new int[] { 0x00ff0000, 0x0000ff00, 0x000000ff },
+ null);
}
- return new BufferedImage(colorModel, raster, colorModel.isAlphaPremultiplied(), new Properties());
+ return new BufferedImage(colorModel, raster,
+ colorModel.isAlphaPremultiplied(), new Properties());
}
}