[FOray-commit] SF.net SVN: foray: [8056] trunk/foray
Modular XSL-FO Implementation for Java.
Status: Alpha
Brought to you by:
victormote
|
From: <vic...@us...> - 2006-09-11 18:56:50
|
Revision: 8056
http://svn.sourceforge.net/foray/?rev=8056&view=rev
Author: victormote
Date: 2006-09-11 11:56:41 -0700 (Mon, 11 Sep 2006)
Log Message:
-----------
1. Fix names, return values, and doc for the unsigned operations.
2. Add new unsigned operations for converting bytes to ints.
Modified Paths:
--------------
trunk/foray/foray-common/src/java/org/foray/common/WKConstants.java
trunk/foray/foray-graphic/src/java/org/foray/graphic/BMPGraphic.java
trunk/foray/foray-graphic/src/java/org/foray/graphic/EPSGraphic.java
trunk/foray/foray-graphic/src/java/org/foray/graphic/PNGGraphic.java
trunk/foray/scripts/checkstyle-suppressions.xml
Modified: trunk/foray/foray-common/src/java/org/foray/common/WKConstants.java
===================================================================
--- trunk/foray/foray-common/src/java/org/foray/common/WKConstants.java 2006-09-11 18:38:39 UTC (rev 8055)
+++ trunk/foray/foray-common/src/java/org/foray/common/WKConstants.java 2006-09-11 18:56:41 UTC (rev 8056)
@@ -44,6 +44,9 @@
/** The number of bytes in an int. */
public static final byte BYTES_PER_INT = 4;
+ /** The number of bytes in a short. */
+ public static final byte BYTES_PER_SHORT = 2;
+
/** The number of bits in a byte. */
public static final byte BITS_PER_BYTE = 8;
@@ -85,14 +88,15 @@
private WKConstants() { }
/**
- * Converts four bytes to an int.
+ * Converts four unsigned bytes to a long.
+ * (It must be converted to a long because the Java int is signed).
* @param byte1 The high-order byte.
* @param byte2 The second highest-order byte.
* @param byte3 The third highest-order byte.
* @param byte4 The low-order byte.
- * @return The int represented by the four bytes.
+ * @return The long represented by the four bytes.
*/
- public static long bytesToLong(final byte byte1, final byte byte2,
+ public static long unsignedBytesToLong(final byte byte1, final byte byte2,
final byte byte3, final byte byte4) {
final int int1 = unsignedByteToInt(byte1);
final int int2 = unsignedByteToInt(byte2);
@@ -110,15 +114,17 @@
}
/**
- * Converts four big-endian bytes from an array of bytes to an int.
+ * Converts four unsigned big-endian bytes from an array of bytes to a long.
+ * (It must be converted to a long because the Java int is signed).
* @param byteArray The array of bytes containing the bytes to be converted.
* @param start The index to the first byte in the array to be converted.
* This is the high-order byte of the 4 bytes. The second byte will be
* indexed at start + 1, the third byte at start + 2, and the fourth byte
* at start + 3.
- * @return The int represented by the four bytes.
+ * @return The long represented by the four bytes.
*/
- public static long bytesToLongBE(final byte[] byteArray, final int start) {
+ public static long unsignedBytesToLongBE(final byte[] byteArray,
+ final int start) {
if (byteArray == null
|| start < 0
|| start + BYTES_PER_INT > byteArray.length) {
@@ -126,22 +132,25 @@
return 0;
}
int index = start;
- return bytesToLong(byteArray[index++],
+ return unsignedBytesToLong(byteArray[index++],
byteArray[index++],
byteArray[index++],
byteArray[index]);
}
/**
- * Converts four little-endian bytes from an array of bytes to an int.
+ * Converts four unsigned little-endian bytes from an array of bytes to a
+ * long.
+ * (It must be converted to a long because the Java int is signed).
* @param byteArray The array of bytes containing the bytes to be converted.
* @param start The index to the first byte in the array to be converted.
* This is the low-order byte of the 4 bytes. The second byte will be
* indexed at start + 1, the third byte at start + 2, and the fourth byte
* (the high-order byte) at start + 3.
- * @return The int represented by the four bytes.
+ * @return The long represented by the four bytes.
*/
- public static long bytesToLongLE(final byte[] byteArray, final int start) {
+ public static long unsignedBytesToLongLE(final byte[] byteArray,
+ final int start) {
if (byteArray == null
|| start < 0
|| start + BYTES_PER_INT > byteArray.length) {
@@ -149,10 +158,71 @@
return 0;
}
int index = start + BYTES_PER_INT - 1;
- return bytesToLong(byteArray[index--],
+ return unsignedBytesToLong(byteArray[index--],
byteArray[index--],
byteArray[index--],
byteArray[index]);
}
+ /**
+ * Converts two unsigned bytes to an int.
+ * (It must be converted to an int because the Java short is signed).
+ * @param byte1 The high-order byte.
+ * @param byte2 The low-order byte.
+ * @return The int represented by the two bytes.
+ */
+ public static int unsignedBytesToInt(final byte byte1, final byte byte2) {
+ return (int) unsignedBytesToLong((byte) 0, (byte) 0, byte1, byte2);
+ }
+
+ /**
+ * Converts two unsigned big-endian bytes from an array of bytes to an int.
+ * (It must be converted to an int because the Java short is signed).
+ * @param byteArray The array of bytes containing the bytes to be converted.
+ * @param start The index to the first byte in the array to be converted.
+ * This is the high-order byte of the 2 bytes. The second byte (the
+ * low-order byte) will be indexed at start + 1.
+ * @return The int represented by the two bytes.
+ */
+ public static int unsignedBytesToIntBE(final byte[] byteArray,
+ final int start) {
+ if (byteArray == null
+ || start < 0
+ || start + BYTES_PER_SHORT > byteArray.length) {
+ /* Fails silently. */
+ return 0;
+ }
+ int index = start;
+ return (int) unsignedBytesToLong(
+ (byte) 0,
+ (byte) 0,
+ byteArray[index++],
+ byteArray[index]);
+ }
+
+ /**
+ * Converts two unsigned little-endian bytes from an array of bytes to an
+ * int.
+ * (It must be converted to an int because the Java short is signed).
+ * @param byteArray The array of bytes containing the bytes to be converted.
+ * @param start The index to the first byte in the array to be converted.
+ * This is the low-order byte of the 4 bytes. The second byte (the
+ * high-order byte) at start + 1.
+ * @return The int represented by the two bytes.
+ */
+ public static long unsignedBytesToIntLE(final byte[] byteArray,
+ final int start) {
+ if (byteArray == null
+ || start < 0
+ || start + BYTES_PER_SHORT > byteArray.length) {
+ /* Fails silently. */
+ return 0;
+ }
+ int index = start + BYTES_PER_SHORT - 1;
+ return unsignedBytesToLong(byteArray[index--],
+ byteArray[index],
+ (byte) 0,
+ (byte) 0);
+ }
+
}
Modified: trunk/foray/foray-graphic/src/java/org/foray/graphic/BMPGraphic.java
===================================================================
--- trunk/foray/foray-graphic/src/java/org/foray/graphic/BMPGraphic.java 2006-09-11 18:38:39 UTC (rev 8055)
+++ trunk/foray/foray-graphic/src/java/org/foray/graphic/BMPGraphic.java 2006-09-11 18:56:41 UTC (rev 8056)
@@ -70,7 +70,7 @@
if (palette != null) {
filepos += palette.length * this.colorSpace.getNumComponents();
}
- final int imagestart = (int) WKConstants.bytesToLongLE(headermap,
+ final int imagestart = (int) WKConstants.unsignedBytesToLongLE(headermap,
IMAGE_START_OFFSET);
this.colorSpace = ColorSpace.getInstance(ColorSpace.CS_sRGB);
final int bytesPerRow = computeBytesPerRow();
@@ -240,8 +240,8 @@
final byte[] header = new byte[BMPGraphic.BMP_BASICS_LENGTH];
bis.read(header);
/* Little endian format. */
- this.pixelWidth = (int) WKConstants.bytesToLongLE(header, WIDTH_OFFSET);
- this.pixelHeight = (int) WKConstants.bytesToLongLE(header,
+ this.pixelWidth = (int) WKConstants.unsignedBytesToLongLE(header, WIDTH_OFFSET);
+ this.pixelHeight = (int) WKConstants.unsignedBytesToLongLE(header,
HEIGHT_OFFSET);
}
Modified: trunk/foray/foray-graphic/src/java/org/foray/graphic/EPSGraphic.java
===================================================================
--- trunk/foray/foray-graphic/src/java/org/foray/graphic/EPSGraphic.java 2006-09-11 18:38:39 UTC (rev 8055)
+++ trunk/foray/foray-graphic/src/java/org/foray/graphic/EPSGraphic.java 2006-09-11 18:56:41 UTC (rev 8056)
@@ -152,17 +152,17 @@
final byte[] fileStart = new byte[this.maxBytesToParseBasics()];
bis.read(fileStart);
if (! isAscii) {
- this.psStart = (int) WKConstants.bytesToLongBE(fileStart,
+ this.psStart = (int) WKConstants.unsignedBytesToLongBE(fileStart,
PS_START_OFFSET);
- this.psLength = (int) WKConstants.bytesToLongBE(fileStart,
+ this.psLength = (int) WKConstants.unsignedBytesToLongBE(fileStart,
PS_LENGTH_OFFSET);
- this.wmfStart = (int) WKConstants.bytesToLongBE(fileStart,
+ this.wmfStart = (int) WKConstants.unsignedBytesToLongBE(fileStart,
WMF_START_OFFSET);
- this.wmfLength = (int) WKConstants.bytesToLongBE(fileStart,
+ this.wmfLength = (int) WKConstants.unsignedBytesToLongBE(fileStart,
WMF_LENGTH_OFFSET);
- this.tiffStart = (int) WKConstants.bytesToLongBE(fileStart,
+ this.tiffStart = (int) WKConstants.unsignedBytesToLongBE(fileStart,
TIFF_START_OFFSET);
- this.tiffLength = (int) WKConstants.bytesToLongBE(fileStart,
+ this.tiffLength = (int) WKConstants.unsignedBytesToLongBE(fileStart,
TIFF_LENGTH_OFFSET);
}
readBBox(fileStart);
Modified: trunk/foray/foray-graphic/src/java/org/foray/graphic/PNGGraphic.java
===================================================================
--- trunk/foray/foray-graphic/src/java/org/foray/graphic/PNGGraphic.java 2006-09-11 18:38:39 UTC (rev 8055)
+++ trunk/foray/foray-graphic/src/java/org/foray/graphic/PNGGraphic.java 2006-09-11 18:56:41 UTC (rev 8056)
@@ -66,9 +66,9 @@
final byte[] header = new byte[PNGGraphic.PNG_BASICS_LENGTH];
bis.read(header);
/* PNG is always big endian. */
- this.pixelWidth = (int) WKConstants.bytesToLongBE(header,
+ this.pixelWidth = (int) WKConstants.unsignedBytesToLongBE(header,
PIXEL_WIDTH_STARTS);
- this.pixelHeight = (int) WKConstants.bytesToLongBE(header,
+ this.pixelHeight = (int) WKConstants.unsignedBytesToLongBE(header,
PIXEL_HEIGHT_STARTS);
}
Modified: trunk/foray/scripts/checkstyle-suppressions.xml
===================================================================
--- trunk/foray/scripts/checkstyle-suppressions.xml 2006-09-11 18:38:39 UTC (rev 8055)
+++ trunk/foray/scripts/checkstyle-suppressions.xml 2006-09-11 18:56:41 UTC (rev 8056)
@@ -14,8 +14,6 @@
<suppress checks="MagicNumber"
files="org.foray.fotree.*"/>
<suppress checks="MagicNumber"
- files="org.foray.graphic.*"/>
- <suppress checks="MagicNumber"
files="org.foray.hyphenR.*"/>
<suppress checks="MagicNumber"
files="org.foray.pdf.*"/>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|