/** * Translates up to the first 2 bytes of a byte array to a short. * If there are fewer than 2 bytes available, the MSBs are all * assumed to be zero (regardless of endianness). * * @param bytes array of bytes to use for translation * @param little true if the bytes are provided in little-endian order * @return the short value that results from concatenating the specified bytes */ public static short bytesToShort(byte[] bytes, boolean little) { return bytesToShort(bytes, 0, 2, little); }
/** * Translates up to the first 2 bytes of a byte array to a short. * If there are fewer than 2 bytes available, the MSBs are all * assumed to be zero (regardless of endianness). */ public static short bytesToShort(short[] bytes, boolean little) { return bytesToShort(bytes, 0, 2, little); }
/** * Translates up to the first 2 bytes of a byte array beyond the given * offset to a short. If there are fewer than 2 bytes available * the MSBs are all assumed to be zero (regardless of endianness). */ public static short bytesToShort(byte[] bytes, int off, boolean little) { return bytesToShort(bytes, off, 2, little); }
/** * Translates up to the first 2 bytes of a byte array to a short. * If there are fewer than 2 bytes available, the MSBs are all * assumed to be zero (regardless of endianness). */ public static short bytesToShort(byte[] bytes, boolean little) { return bytesToShort(bytes, 0, 2, little); }
/** * Translates up to the first 2 bytes of a byte array byond the given * offset to a short. If there are fewer than 2 bytes available, * the MSBs are all assumed to be zero (regardless of endianness). */ public static short bytesToShort(short[] bytes, int off, boolean little) { return bytesToShort(bytes, off, 2, little); }
/** * Translates up to the first 2 bytes of a byte array to a short. * If there are fewer than 2 bytes available, the MSBs are all * assumed to be zero (regardless of endianness). * * @param bytes array of unsigned bytes to be translated to a short * @param little true if the bytes are provided in little-endian order * @return the short value that results from concatenating the specified bytes */ public static short bytesToShort(short[] bytes, boolean little) { return bytesToShort(bytes, 0, 2, little); }
/** * Translates up to the first 2 bytes of a byte array beyond the given * offset to a short. If there are fewer than 2 bytes available * the MSBs are all assumed to be zero (regardless of endianness). * * @param bytes array of bytes to use for translation * @param off offset to the first byte in the array * @param little true if the bytes are provided in little-endian order * @return the short value that results from concatenating the specified bytes */ public static short bytesToShort(byte[] bytes, int off, boolean little) { return bytesToShort(bytes, off, 2, little); }
/** * Translates up to the first 2 bytes of a byte array byond the given * offset to a short. If there are fewer than 2 bytes available, * the MSBs are all assumed to be zero (regardless of endianness). * * @param bytes array of unsigned bytes to be translated to a short * @param off offset into array of bytes; should be non-negative and less than * the length of the array * @param little true if the bytes are provided in little-endian order * @return the short value that results from concatenating the specified bytes */ public static short bytesToShort(short[] bytes, int off, boolean little) { return bytesToShort(bytes, off, 2, little); }
/** PackBits variant that outputs an int array. */ private void unpackBits(byte[] ib, int[] ob) { LOGGER.debug("unpackBits(...)"); int i = 0; int b; int rep; int end; for (int o=0; o<ob.length;) { if (i+1 < ib.length) { b = ib[i++]; if (b >= 0) { end = o + b + 1; while (o < end && o < ob.length && (i + 1) < ib.length) { ob[o++] = DataTools.bytesToShort(ib, i, 2, false); i += 2; } } else if (b != -128) { rep = DataTools.bytesToShort(ib, i, 2, false); i += 2; end = o - b + 1; while (o < end && o < ob.length) { ob[o++] = rep; } } } else o = ob.length; } }
/** PackBits variant that outputs an int array. */ private void unpackBits(byte[] ib, int[] ob) { LOGGER.debug("unpackBits(...)"); int i = 0; int b; int rep; int end; for (int o=0; o<ob.length;) { if (i+1 < ib.length) { b = ib[i++]; if (b >= 0) { end = o + b + 1; while (o < end && o < ob.length && (i + 1) < ib.length) { ob[o++] = DataTools.bytesToShort(ib, i, 2, false); i += 2; } } else if (b != -128) { rep = DataTools.bytesToShort(ib, i, 2, false); i += 2; end = o - b + 1; while (o < end && o < ob.length) { ob[o++] = rep; } } } else o = ob.length; } }
/** Scan a plane for the channel min and max values. */ public static Double[] scanData(byte[] plane, int bits, boolean littleEndian) { int max = 0; int min = Integer.MAX_VALUE; if (bits <= 8) { for (int j=0; j<plane.length; j++) { if (plane[j] < min) min = plane[j]; if (plane[j] > max) max = plane[j]; } } else if (bits == 16) { for (int j=0; j<plane.length; j+=2) { short s = DataTools.bytesToShort(plane, j, 2, littleEndian); if (s < min) min = s; if (s > max) max = s; } } else if (bits == 32) { for (int j=0; j<plane.length; j+=4) { int s = DataTools.bytesToInt(plane, j, 4, littleEndian); if (s < min) min = s; if (s > max) max = s; } } Double[] rtn = new Double[2]; rtn[0] = new Double(min); rtn[1] = new Double(max); return rtn; }
/** Scan a plane for the channel min and max values. */ public static Double[] scanData(byte[] plane, int bits, boolean littleEndian) { int max = 0; int min = Integer.MAX_VALUE; if (bits <= 8) { for (int j=0; j<plane.length; j++) { if (plane[j] < min) min = plane[j]; if (plane[j] > max) max = plane[j]; } } else if (bits == 16) { for (int j=0; j<plane.length; j+=2) { short s = DataTools.bytesToShort(plane, j, 2, littleEndian); if (s < min) min = s; if (s > max) max = s; } } else if (bits == 32) { for (int j=0; j<plane.length; j+=4) { int s = DataTools.bytesToInt(plane, j, 4, littleEndian); if (s < min) min = s; if (s > max) max = s; } } Double[] rtn = new Double[2]; rtn[0] = new Double(min); rtn[1] = new Double(max); return rtn; }
int length = DataTools.bytesToShort(buf, pointer, 2, true); if (length == 6 && new String( buf, pointer + 2, length, Constants.ENCODING).equals("CImage"))
int length = DataTools.bytesToShort(buf, pointer, 2, true); if (length == 6 && new String( buf, pointer + 2, length, Constants.ENCODING).equals("CImage"))
idx[i] = (int) DataTools.bytesToDouble(plane, offset, bpp, little); } else if (2 == bpp) { idx[i] = (int) DataTools.bytesToShort(plane, offset, bpp, little); } else { idx[i] = DataTools.bytesToInt(plane, offset, bpp, little);
idx[i] = (int) DataTools.bytesToDouble(plane, offset, bpp, little); } else if (2 == bpp) { idx[i] = (int) DataTools.bytesToShort(plane, offset, bpp, little); } else { idx[i] = DataTools.bytesToInt(plane, offset, bpp, little);
short[] s = new short[b.length / 2]; for (int i=0; i<s.length; i++) { s[i] = bytesToShort(b, i * 2, 2, little);
while (bufferPointer - row * width < width - 2) { short prevPixel = DataTools.bytesToShort(b, bufferPointer, isLittleEndian()); bufferPointer += 2; byte check = in.readByte();
while (bufferPointer - row * width < width - 2) { short prevPixel = DataTools.bytesToShort(b, bufferPointer, isLittleEndian()); bufferPointer += 2; byte check = in.readByte();
if (plane[q] != pixels[q]) { LOGGER.debug("FAILED on {}", DataTools.bytesToShort(pixels, false)); failureCount++; break;