Search in sources :

Example 16 with ByteOrder

use of java.nio.ByteOrder in project weiui by kuaifan.

the class ImageHeaderParser method parseExifSegment.

private static int parseExifSegment(RandomAccessReader segmentData) {
    final int headerOffsetSize = JPEG_EXIF_SEGMENT_PREAMBLE.length();
    short byteOrderIdentifier = segmentData.getInt16(headerOffsetSize);
    final ByteOrder byteOrder;
    if (byteOrderIdentifier == MOTOROLA_TIFF_MAGIC_NUMBER) {
        byteOrder = ByteOrder.BIG_ENDIAN;
    } else if (byteOrderIdentifier == INTEL_TIFF_MAGIC_NUMBER) {
        byteOrder = ByteOrder.LITTLE_ENDIAN;
    } else {
        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "Unknown endianness = " + byteOrderIdentifier);
        }
        byteOrder = ByteOrder.BIG_ENDIAN;
    }
    segmentData.order(byteOrder);
    int firstIfdOffset = segmentData.getInt32(headerOffsetSize + 4) + headerOffsetSize;
    int tagCount = segmentData.getInt16(firstIfdOffset);
    int tagOffset, tagType, formatCode, componentCount;
    for (int i = 0; i < tagCount; i++) {
        tagOffset = calcTagOffset(firstIfdOffset, i);
        tagType = segmentData.getInt16(tagOffset);
        // We only want orientation.
        if (tagType != ORIENTATION_TAG_TYPE) {
            continue;
        }
        formatCode = segmentData.getInt16(tagOffset + 2);
        // 12 is max format code.
        if (formatCode < 1 || formatCode > 12) {
            if (Log.isLoggable(TAG, Log.DEBUG)) {
                Log.d(TAG, "Got invalid format code = " + formatCode);
            }
            continue;
        }
        componentCount = segmentData.getInt32(tagOffset + 4);
        if (componentCount < 0) {
            if (Log.isLoggable(TAG, Log.DEBUG)) {
                Log.d(TAG, "Negative tiff component count");
            }
            continue;
        }
        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "Got tagIndex=" + i + " tagType=" + tagType + " formatCode=" + formatCode + " componentCount=" + componentCount);
        }
        final int byteCount = componentCount + BYTES_PER_FORMAT[formatCode];
        if (byteCount > 4) {
            if (Log.isLoggable(TAG, Log.DEBUG)) {
                Log.d(TAG, "Got byte count > 4, not orientation, continuing, formatCode=" + formatCode);
            }
            continue;
        }
        final int tagValueOffset = tagOffset + 8;
        if (tagValueOffset < 0 || tagValueOffset > segmentData.length()) {
            if (Log.isLoggable(TAG, Log.DEBUG)) {
                Log.d(TAG, "Illegal tagValueOffset=" + tagValueOffset + " tagType=" + tagType);
            }
            continue;
        }
        if (byteCount < 0 || tagValueOffset + byteCount > segmentData.length()) {
            if (Log.isLoggable(TAG, Log.DEBUG)) {
                Log.d(TAG, "Illegal number of bytes for TI tag data tagType=" + tagType);
            }
            continue;
        }
        // assume componentCount == 1 && fmtCode == 3
        return segmentData.getInt16(tagValueOffset);
    }
    return -1;
}
Also used : ByteOrder(java.nio.ByteOrder)

Example 17 with ByteOrder

use of java.nio.ByteOrder in project Rocket by mozilla-tw.

the class DefaultImageHeaderParser method parseExifSegment.

private static int parseExifSegment(RandomAccessReader segmentData) {
    final int headerOffsetSize = JPEG_EXIF_SEGMENT_PREAMBLE.length();
    short byteOrderIdentifier = segmentData.getInt16(headerOffsetSize);
    final ByteOrder byteOrder;
    if (byteOrderIdentifier == MOTOROLA_TIFF_MAGIC_NUMBER) {
        byteOrder = ByteOrder.BIG_ENDIAN;
    } else if (byteOrderIdentifier == INTEL_TIFF_MAGIC_NUMBER) {
        byteOrder = ByteOrder.LITTLE_ENDIAN;
    } else {
        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "Unknown endianness = " + byteOrderIdentifier);
        }
        byteOrder = ByteOrder.BIG_ENDIAN;
    }
    segmentData.order(byteOrder);
    int firstIfdOffset = segmentData.getInt32(headerOffsetSize + 4) + headerOffsetSize;
    int tagCount = segmentData.getInt16(firstIfdOffset);
    int tagOffset, tagType, formatCode, componentCount;
    for (int i = 0; i < tagCount; i++) {
        tagOffset = calcTagOffset(firstIfdOffset, i);
        tagType = segmentData.getInt16(tagOffset);
        // We only want orientation.
        if (tagType != ORIENTATION_TAG_TYPE) {
            continue;
        }
        formatCode = segmentData.getInt16(tagOffset + 2);
        // 12 is max format code.
        if (formatCode < 1 || formatCode > 12) {
            if (Log.isLoggable(TAG, Log.DEBUG)) {
                Log.d(TAG, "Got invalid format code = " + formatCode);
            }
            continue;
        }
        componentCount = segmentData.getInt32(tagOffset + 4);
        if (componentCount < 0) {
            if (Log.isLoggable(TAG, Log.DEBUG)) {
                Log.d(TAG, "Negative tiff component count");
            }
            continue;
        }
        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "Got tagIndex=" + i + " tagType=" + tagType + " formatCode=" + formatCode + " componentCount=" + componentCount);
        }
        final int byteCount = componentCount + BYTES_PER_FORMAT[formatCode];
        if (byteCount > 4) {
            if (Log.isLoggable(TAG, Log.DEBUG)) {
                Log.d(TAG, "Got byte count > 4, not orientation, continuing, formatCode=" + formatCode);
            }
            continue;
        }
        final int tagValueOffset = tagOffset + 8;
        if (tagValueOffset < 0 || tagValueOffset > segmentData.length()) {
            if (Log.isLoggable(TAG, Log.DEBUG)) {
                Log.d(TAG, "Illegal tagValueOffset=" + tagValueOffset + " tagType=" + tagType);
            }
            continue;
        }
        if (byteCount < 0 || tagValueOffset + byteCount > segmentData.length()) {
            if (Log.isLoggable(TAG, Log.DEBUG)) {
                Log.d(TAG, "Illegal number of bytes for TI tag data tagType=" + tagType);
            }
            continue;
        }
        // assume componentCount == 1 && fmtCode == 3
        return segmentData.getInt16(tagValueOffset);
    }
    return -1;
}
Also used : ByteOrder(java.nio.ByteOrder)

Example 18 with ByteOrder

use of java.nio.ByteOrder in project jeesuite-libs by vakinge.

the class ConsistencyHash method hash.

private static Long hash(String key) {
    if (key == null)
        return 0L;
    ByteBuffer buf = ByteBuffer.wrap(key.getBytes());
    int seed = 0x1234ABCD;
    ByteOrder byteOrder = buf.order();
    buf.order(ByteOrder.LITTLE_ENDIAN);
    long m = 0xc6a4a7935bd1e995L;
    int r = 47;
    long h = seed ^ (buf.remaining() * m);
    long k;
    while (buf.remaining() >= 8) {
        k = buf.getLong();
        k *= m;
        k ^= k >>> r;
        k *= m;
        h ^= k;
        h *= m;
    }
    if (buf.remaining() > 0) {
        ByteBuffer finish = ByteBuffer.allocate(8).order(ByteOrder.LITTLE_ENDIAN);
        finish.put(buf).rewind();
        h ^= finish.getLong();
        h *= m;
    }
    h ^= h >>> r;
    h *= m;
    h ^= h >>> r;
    buf.order(byteOrder);
    return Math.abs(h);
}
Also used : ByteOrder(java.nio.ByteOrder) ByteBuffer(java.nio.ByteBuffer)

Example 19 with ByteOrder

use of java.nio.ByteOrder in project Mycat_plus by coderczp.

the class Shard method hash.

/**
 * MurMurHash算法,是非加密HASH算法,性能很高,
 * 比传统的CRC32,MD5,SHA-1(这两个算法都是加密HASH算法,复杂度本身就很高,带来的性能上的损害也不可避免)
 * 等HASH算法要快很多,而且据说这个算法的碰撞率很低.
 * http://murmurhash.googlepages.com/
 */
private Long hash(String key) {
    ByteBuffer buf = ByteBuffer.wrap(key.getBytes());
    int seed = 0x1234ABCD;
    ByteOrder byteOrder = buf.order();
    buf.order(ByteOrder.LITTLE_ENDIAN);
    long m = 0xc6a4a7935bd1e995L;
    int r = 47;
    long h = seed ^ (buf.remaining() * m);
    long k;
    while (buf.remaining() >= 8) {
        k = buf.getLong();
        k *= m;
        k ^= k >>> r;
        k *= m;
        h ^= k;
        h *= m;
    }
    if (buf.remaining() > 0) {
        ByteBuffer finish = ByteBuffer.allocate(8).order(ByteOrder.LITTLE_ENDIAN);
        // for big-endian version, do this first:
        // finish.position(8-buf.remaining());
        finish.put(buf).rewind();
        h ^= finish.getLong();
        h *= m;
    }
    h ^= h >>> r;
    h *= m;
    h ^= h >>> r;
    buf.order(byteOrder);
    return h;
}
Also used : ByteOrder(java.nio.ByteOrder) ByteBuffer(java.nio.ByteBuffer)

Example 20 with ByteOrder

use of java.nio.ByteOrder in project sis by apache.

the class ImageInputStreamComparator method getByteOrder.

/**
 * Forwards the call to the two streams and ensures that they return identical results.
 *
 * @return the result of the forwarded call.
 */
@Override
public ByteOrder getByteOrder() {
    final ByteOrder r = expected.getByteOrder();
    assertEquals(r, actual.getByteOrder());
    return r;
}
Also used : ByteOrder(java.nio.ByteOrder)

Aggregations

ByteOrder (java.nio.ByteOrder)111 ByteBuffer (java.nio.ByteBuffer)39 IOException (java.io.IOException)8 Test (org.junit.Test)7 QuickTest (com.hazelcast.test.annotation.QuickTest)5 DataInputStream (java.io.DataInputStream)5 FileInputStream (java.io.FileInputStream)5 UUID (java.util.UUID)5 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)4 HKL (ffx.crystal.HKL)3 DataOutputStream (java.io.DataOutputStream)3 EOFException (java.io.EOFException)3 FileOutputStream (java.io.FileOutputStream)3 ShortBuffer (java.nio.ShortBuffer)3 ArrayList (java.util.ArrayList)3 Element (org.jdom.Element)3 InvalidDumpFormatException (com.ibm.j9ddr.corereaders.InvalidDumpFormatException)2 Point (com.revolsys.geometry.model.Point)2 Crystal (ffx.crystal.Crystal)2 BigInteger (java.math.BigInteger)2