Here you can find the source of getShiftedI32(final int bytesPerPixel, final ByteBuffer data, final boolean retainDataPos)
Parameter | Description |
---|---|
bytesPerPixel | number of bytes per pixel to fetch, a maximum of 4 are allowed |
data | byte buffer covering complete pixel at position offset |
retainDataPos | if true, absolute ByteBuffer#get(int) is used and the data position stays unchanged. Otherwise relative ByteBuffer#get() is used and the data position changes. |
public static int getShiftedI32(final int bytesPerPixel, final ByteBuffer data, final boolean retainDataPos)
//package com.java2s; import java.nio.ByteBuffer; public class Main { /**//from w ww . j a v a 2 s. c om * Returns shifted bytes from the given {@code data} at given {@code offset} * of maximal 4 {@code bytesPerPixel}. * @param bytesPerPixel number of bytes per pixel to fetch, a maximum of 4 are allowed * @param data byte buffer covering complete pixel at position {@code offset} * @param offset byte offset of pixel {@code data} start * @return the shifted 32bit integer value of the pixel */ public static int getShiftedI32(final int bytesPerPixel, final byte[] data, final int offset) { if (bytesPerPixel <= 4) { int shiftedI32 = 0; for (int i = 0; i < bytesPerPixel; i++) { shiftedI32 |= (0xff & data[offset + i]) << 8 * i; } return shiftedI32; } else { throw new UnsupportedOperationException(bytesPerPixel + " bytesPerPixel too big, i.e. > 4"); } } /** * Returns shifted bytes from the given {@code data} at current position * of maximal 4 {@code bytesPerPixel}. * @param bytesPerPixel number of bytes per pixel to fetch, a maximum of 4 are allowed * @param data byte buffer covering complete pixel at position {@code offset} * @param retainDataPos if true, absolute {@link ByteBuffer#get(int)} is used and the {@code data} position stays unchanged. * Otherwise relative {@link ByteBuffer#get()} is used and the {@code data} position changes. * @return the shifted 32bit integer value of the pixel */ public static int getShiftedI32(final int bytesPerPixel, final ByteBuffer data, final boolean retainDataPos) { if (bytesPerPixel <= 4) { int shiftedI32 = 0; if (retainDataPos) { final int offset = data.position(); for (int i = 0; i < bytesPerPixel; i++) { shiftedI32 |= (0xff & data.get(offset + i)) << 8 * i; } } else { for (int i = 0; i < bytesPerPixel; i++) { shiftedI32 |= (0xff & data.get()) << 8 * i; } } return shiftedI32; } else { throw new UnsupportedOperationException(bytesPerPixel + " bytesPerPixel too big, i.e. > 4"); } } }