Search in sources :

Example 71 with ShortBuffer

use of java.nio.ShortBuffer in project Purus-Pasta by puruscor.

the class MapMesh method consflat.

private void consflat() {
    class Buf implements Tiler.MCons {

        int vn = 0, in = 0, vl = sz.x * sz.y * 4;

        float[] pos = new float[vl * 3];

        float[] col = new float[vl * 4];

        short[] ind = new short[sz.x * sz.y * 6];

        public void faces(MapMesh m, Tiler.MPart d) {
            if (vn + d.v.length > vl) {
                vl *= 2;
                pos = Utils.extend(pos, vl * 12);
                col = Utils.extend(col, vl * 16);
            }
            float cx = (d.lc.x + 1) / 256.0f, cy = (d.lc.y + 1) / 256.0f;
            for (int i = 0; i < d.v.length; i++) {
                int pb = (vn + i) * 3, cb = (vn + i) * 4;
                pos[pb + 0] = d.v[i].x;
                pos[pb + 1] = d.v[i].y;
                pos[pb + 2] = d.v[i].z;
                col[cb + 0] = cx;
                col[cb + 1] = cy;
                col[cb + 2] = d.tcx[i];
                col[cb + 3] = d.tcy[i];
            }
            if (in + d.f.length > ind.length)
                ind = Utils.extend(ind, ind.length * 2);
            for (int fi : d.f) ind[in++] = (short) (vn + fi);
            vn += d.v.length;
        }
    }
    Buf buf = new Buf();
    Coord c = new Coord();
    for (c.y = 0; c.y < sz.y; c.y++) {
        for (c.x = 0; c.x < sz.x; c.x++) {
            Coord gc = c.add(ul);
            map.tiler(map.gettile(gc)).lay(this, c, gc, buf, true);
        }
    }
    float[] pos = buf.pos, col = buf.col;
    short[] ind = buf.ind;
    if (pos.length != buf.vn * 3)
        pos = Utils.extend(pos, buf.vn * 3);
    if (col.length != buf.vn * 4)
        col = Utils.extend(col, buf.vn * 4);
    if (ind.length != buf.in)
        ind = Utils.extend(ind, buf.in);
    VertexBuf.VertexArray posa = new VertexBuf.VertexArray(FloatBuffer.wrap(pos));
    VertexBuf.ColorArray cola = new VertexBuf.ColorArray(FloatBuffer.wrap(col));
    ShortBuffer indb = ShortBuffer.wrap(ind);
    flats = new FastMesh[] { new FastMesh(new VertexBuf(posa), indb), new FastMesh(new VertexBuf(posa, cola), indb) };
}
Also used : ShortBuffer(java.nio.ShortBuffer)

Example 72 with ShortBuffer

use of java.nio.ShortBuffer in project Pix-Art-Messenger by kriztan.

the class AudioChannel method feedEncoder.

public boolean feedEncoder(long timeoutUs) {
    final boolean hasOverflow = mOverflowBuffer.data != null && mOverflowBuffer.data.hasRemaining();
    if (mFilledBuffers.isEmpty() && !hasOverflow) {
        // No audio data - Bail out
        return false;
    }
    final int encoderInBuffIndex = mEncoder.dequeueInputBuffer(timeoutUs);
    if (encoderInBuffIndex < 0) {
        // Encoder is full - Bail out
        return false;
    }
    // Drain overflow first
    final ShortBuffer outBuffer = mEncoderBuffers.getInputBuffer(encoderInBuffIndex).asShortBuffer();
    if (hasOverflow) {
        final long presentationTimeUs = drainOverflow(outBuffer);
        mEncoder.queueInputBuffer(encoderInBuffIndex, 0, outBuffer.position() * BYTES_PER_SHORT, presentationTimeUs, 0);
        return true;
    }
    final AudioBuffer inBuffer = mFilledBuffers.poll();
    if (inBuffer.bufferIndex == BUFFER_INDEX_END_OF_STREAM) {
        mEncoder.queueInputBuffer(encoderInBuffIndex, 0, 0, 0, MediaCodec.BUFFER_FLAG_END_OF_STREAM);
        return false;
    }
    final long presentationTimeUs = remixAndMaybeFillOverflow(inBuffer, outBuffer);
    mEncoder.queueInputBuffer(encoderInBuffIndex, 0, outBuffer.position() * BYTES_PER_SHORT, presentationTimeUs, 0);
    if (inBuffer != null) {
        mDecoder.releaseOutputBuffer(inBuffer.bufferIndex, false);
        mEmptyBuffers.add(inBuffer);
    }
    return true;
}
Also used : ShortBuffer(java.nio.ShortBuffer)

Example 73 with ShortBuffer

use of java.nio.ShortBuffer in project Pix-Art-Messenger by kriztan.

the class AudioChannel method drainOverflow.

private long drainOverflow(final ShortBuffer outBuff) {
    final ShortBuffer overflowBuff = mOverflowBuffer.data;
    final int overflowLimit = overflowBuff.limit();
    final int overflowSize = overflowBuff.remaining();
    final long beginPresentationTimeUs = mOverflowBuffer.presentationTimeUs + sampleCountToDurationUs(overflowBuff.position(), mInputSampleRate, mOutputChannelCount);
    outBuff.clear();
    // Limit overflowBuff to outBuff's capacity
    overflowBuff.limit(outBuff.capacity());
    // Load overflowBuff onto outBuff
    outBuff.put(overflowBuff);
    if (overflowSize >= outBuff.capacity()) {
        // Overflow fully consumed - Reset
        overflowBuff.clear().limit(0);
    } else {
        // Only partially consumed - Keep position & restore previous limit
        overflowBuff.limit(overflowLimit);
    }
    return beginPresentationTimeUs;
}
Also used : ShortBuffer(java.nio.ShortBuffer)

Example 74 with ShortBuffer

use of java.nio.ShortBuffer in project bioformats by openmicroscopy.

the class CellH5Writer method saveBytes.

/**
 * Saves the given image to the specified (possibly already open) file.
 */
@Override
public void saveBytes(int no, byte[] buf) throws IOException, FormatException {
    LOGGER.info("CellH5Writer: Save image to HDF5 path: " + outputPath);
    MetadataRetrieve r = getMetadataRetrieve();
    int sizeX = r.getPixelsSizeX(series).getValue();
    int sizeY = r.getPixelsSizeY(series).getValue();
    int sizeC = r.getPixelsSizeC(series).getValue();
    int sizeT = r.getPixelsSizeT(series).getValue();
    int sizeZ = r.getPixelsSizeZ(series).getValue();
    DimensionOrder dimo = r.getPixelsDimensionOrder(0);
    int c, z, t;
    if (dimo.equals(DimensionOrder.XYCZT)) {
        c = no % sizeC;
        z = ((no - c) / sizeC) % sizeZ;
        t = (((no - c) / sizeC)) / sizeZ;
    } else if (dimo.equals(DimensionOrder.XYCTZ)) {
        c = no % sizeC;
        t = ((no - c) / sizeC) % sizeT;
        z = (((no - c) / sizeC)) / sizeT;
    } else if (dimo.equals(DimensionOrder.XYZTC)) {
        z = no % sizeZ;
        t = ((no - z) / sizeZ) % sizeT;
        c = (((no - z) / sizeZ)) / sizeT;
    } else {
        throw new FormatException("CellH5Writer: Dimension order not understood: " + dimo.getValue());
    }
    LOGGER.info("CellH5Writer.saveBytes(): Current c, t, z == {} {} {}", c, t, z);
    LOGGER.info("CellH5Writer.saveBytes(): bpp {} byte buffer len {}", bpp, buf.length);
    if (bpp == 1) {
        MDByteArray image = new MDByteArray(new int[] { 1, 1, 1, sizeY, sizeX });
        for (int x_i = 0; x_i < sizeX; x_i++) {
            for (int y_i = 0; y_i < sizeY; y_i++) {
                byte value = (byte) buf[y_i * sizeX + x_i];
                image.set(value, 0, 0, 0, y_i, x_i);
            }
        }
        jhdf.writeArraySlice(outputPath, image, new long[] { c, t, z, 0, 0 });
    } else if (bpp == 2) {
        ByteBuffer bb = ByteBuffer.wrap(buf);
        ShortBuffer sb = bb.asShortBuffer();
        MDShortArray image = new MDShortArray(new int[] { 1, 1, 1, sizeY, sizeX });
        for (int x_i = 0; x_i < sizeX; x_i++) {
            for (int y_i = 0; y_i < sizeY; y_i++) {
                short value = sb.get(y_i * sizeX + x_i);
                image.set(value, 0, 0, 0, y_i, x_i);
            }
        }
        jhdf.writeArraySlice(outputPath, image, new long[] { c, t, z, 0, 0 });
    } else if (bpp == 4) {
        ByteBuffer bb = ByteBuffer.wrap(buf);
        IntBuffer ib = bb.asIntBuffer();
        MDIntArray image = new MDIntArray(new int[] { 1, 1, 1, sizeY, sizeX });
        for (int x_i = 0; x_i < sizeX; x_i++) {
            for (int y_i = 0; y_i < sizeY; y_i++) {
                int value = (int) ib.get(y_i * sizeX + x_i);
                image.set(value, 0, 0, 0, y_i, x_i);
            }
        }
        jhdf.writeArraySlice(outputPath, image, new long[] { c, t, z, 0, 0 });
    } else {
        throw new FormatException("CellH5Writer: Pixel type not supported");
    }
}
Also used : MDIntArray(ch.systemsx.cisd.base.mdarray.MDIntArray) IntBuffer(java.nio.IntBuffer) MDShortArray(ch.systemsx.cisd.base.mdarray.MDShortArray) DimensionOrder(ome.xml.model.enums.DimensionOrder) MetadataRetrieve(loci.formats.meta.MetadataRetrieve) ByteBuffer(java.nio.ByteBuffer) ShortBuffer(java.nio.ShortBuffer) FormatException(loci.formats.FormatException) MDByteArray(ch.systemsx.cisd.base.mdarray.MDByteArray)

Example 75 with ShortBuffer

use of java.nio.ShortBuffer in project narchy by automenta.

the class SND_MIX method PaintChannelFrom16.

static void PaintChannelFrom16(channel_t ch, sfxcache_t sc, int count, int offset) {
    int data;
    int left, right;
    int leftvol, rightvol;
    int sfx;
    int i;
    portable_samplepair_t samp;
    leftvol = ch.leftvol * snd_vol;
    rightvol = ch.rightvol * snd_vol;
    ByteBuffer bb = ByteBuffer.wrap(sc.data);
    bb.order(ByteOrder.LITTLE_ENDIAN);
    ShortBuffer sb = bb.asShortBuffer();
    sfx = ch.pos;
    // samp = paintbuffer[offset];
    for (i = 0; i < count; i++, offset++) {
        left = paintbuffer.get(offset * 2);
        right = paintbuffer.get(offset * 2 + 1);
        data = sb.get(sfx + i);
        left += (data * leftvol) >> 8;
        right += (data * rightvol) >> 8;
        paintbuffer.put(offset * 2, left);
        paintbuffer.put(offset * 2 + 1, right);
    }
    ch.pos += count;
}
Also used : ByteBuffer(java.nio.ByteBuffer) ShortBuffer(java.nio.ShortBuffer)

Aggregations

ShortBuffer (java.nio.ShortBuffer)227 ByteBuffer (java.nio.ByteBuffer)78 FloatBuffer (java.nio.FloatBuffer)54 IntBuffer (java.nio.IntBuffer)45 DoubleBuffer (java.nio.DoubleBuffer)23 LongBuffer (java.nio.LongBuffer)16 Test (org.junit.Test)14 Buffer (java.nio.Buffer)11 BufferOverflowException (java.nio.BufferOverflowException)11 CharBuffer (java.nio.CharBuffer)11 VertexBuffer (com.jme3.scene.VertexBuffer)8 BufferUnderflowException (java.nio.BufferUnderflowException)7 BytePointer (org.bytedeco.javacpp.BytePointer)7 IndexBuffer (com.jme3.scene.mesh.IndexBuffer)6 IOException (java.io.IOException)5 Vector3f (com.jme3.math.Vector3f)4 ArrayList (java.util.ArrayList)4 Bitmap (android.graphics.Bitmap)3 Mesh (com.jme3.scene.Mesh)3 InvalidMarkException (java.nio.InvalidMarkException)3