Package java.nio

Examples of java.nio.ShortBuffer


                        bb.put((byte)(int)vv[i+offset]);
                    }
                    break;
                case CV_16U:
                case CV_16S:
                    ShortBuffer sb = getShortBuffer();
                    sb.position(index);
                    for (int i = 0; i < length; i++) {
                        sb.put((short)(int)vv[i+offset]);
                    }
                    break;
                case CV_32S:
                    IntBuffer ib = getIntBuffer();
                    ib.position(index);
View Full Code Here


                    case 8:
                        cvCvtColor(grabbedImages[i], colorImages[i], CV_GRAY2RGB);
                        break;
                    case 16:
                        ByteBuffer colorBuf = colorImages[i].getByteBuffer();
                        ShortBuffer shortBuf = grabbedImages[i].getByteBuffer().asShortBuffer();
                        for (int j = 0; j < colorBuf.limit()/3; j++) {
                            byte msb = (byte)((int)(shortBuf.get()>>8) & 0xFF);
                            colorBuf.put(msb);
                            colorBuf.put(msb);
                            colorBuf.put(msb);
                        }
                        break;
View Full Code Here

                for (int i = 0; i < sb.capacity(); i++) {
                    db.put(i, (byte)Math.max(Math.min(sb.get(i) & 0xFF,max),min));
                }
                break; }
            case IPL_DEPTH_16U: {
                ShortBuffer sb = src.getByteBuffer().asShortBuffer();
                ShortBuffer db = dst.getByteBuffer().asShortBuffer();
                for (int i = 0; i < sb.capacity(); i++) {
                    db.put(i, (short)Math.max(Math.min(sb.get(i) & 0xFFFF,max),min));
                }
                break; }
            case IPL_DEPTH_32F: {
                FloatBuffer sb = src.getByteBuffer().asFloatBuffer();
                FloatBuffer db = dst.getByteBuffer().asFloatBuffer();
                for (int i = 0; i < sb.capacity(); i++) {
                    db.put(i, (float)Math.max(Math.min(sb.get(i),max),min));
                }
                break; }
            case IPL_DEPTH_8S: {
                ByteBuffer sb = src.getByteBuffer();
                ByteBuffer db = dst.getByteBuffer();
                for (int i = 0; i < sb.capacity(); i++) {
                    db.put(i, (byte)Math.max(Math.min(sb.get(i),max),min));
                }
                break; }
            case IPL_DEPTH_16S: {
                ShortBuffer sb = src.getByteBuffer().asShortBuffer();
                ShortBuffer db = dst.getByteBuffer().asShortBuffer();
                for (int i = 0; i < sb.capacity(); i++) {
                    db.put(i, (short)Math.max(Math.min(sb.get(i),max),min));
                }
                break; }
            case IPL_DEPTH_32S: {
                IntBuffer sb = src.getByteBuffer().asIntBuffer();
                IntBuffer db = dst.getByteBuffer().asIntBuffer();
                for (int i = 0; i < sb.capacity(); i++) {
                    db.put(i, (int)Math.max(Math.min(sb.get(i),max),min));
                }
                break; }
            case IPL_DEPTH_64F: {
                DoubleBuffer sb = src.getByteBuffer().asDoubleBuffer();
                DoubleBuffer db = dst.getByteBuffer().asDoubleBuffer();
                for (int i = 0; i < sb.capacity(); i++) {
                    db.put(i, Math.max(Math.min(sb.get(i),max),min));
                }
                break; }
            default: assert(false);
        }
View Full Code Here

        if (iplDepth > 8 && ByteOrder.nativeOrder().equals(ByteOrder.LITTLE_ENDIAN)) {
            // ack, the camera's endianness doesn't correspond to our machine ...
            // swap bytes of 16-bit images
            ByteBuffer  bb  = rawImage.getByteBuffer();
            ShortBuffer in  = bb.order(ByteOrder.BIG_ENDIAN   ).asShortBuffer();
            ShortBuffer out = bb.order(ByteOrder.LITTLE_ENDIAN).asShortBuffer();
            out.put(in);
        }

        if (colorMode == ColorMode.GRAY && channels == 3) {
            if (grayImage == null) {
                grayImage = IplImage.create(w, h, iplDepth, 1);
View Full Code Here

          ByteArrayInputStream bis = new ByteArrayInputStream(buf.array());
          return bis;
        } else if (type.getName().equals(CAS.TYPE_NAME_SHORT_ARRAY)) {
          arrayStart = this.getHeap().heap[getArrayStartAddress(fs.getAddress())];
          buf = ByteBuffer.allocate(arraySize * 2);
          ShortBuffer shortbuf = buf.asShortBuffer();
          shortbuf.put(this.getShortHeap().heap, arrayStart, arraySize);

          ByteArrayInputStream bis = new ByteArrayInputStream(buf.array());
          return bis;
        } else if (type.getName().equals(CAS.TYPE_NAME_LONG_ARRAY)) {
          arrayStart = this.getHeap().heap[getArrayStartAddress(fs.getAddress())];
View Full Code Here

  /** Bulk input of a short array. */
  public short[] readShorts (int length) throws KryoException {
    if (capacity - position >= length * 2 && isNativeOrder()) {
      short[] array = new short[length];
      ShortBuffer buf = niobuffer.asShortBuffer();
      buf.get(array);
      position += length * 2;
      niobuffer.position(position);
      return array;
    } else
      return super.readShorts(length);
View Full Code Here

  }

  /** Bulk output of a short array. */
  public void writeShorts (short[] object) throws KryoException {
    if (capacity - position >= object.length * 2 && isNativeOrder()) {
      ShortBuffer buf = niobuffer.asShortBuffer();
      buf.put(object);
      position += object.length * 2;
    } else
      super.writeShorts(object);
  }
View Full Code Here

        for (int i=0;i < buf.capacity();i++) {
            assertEquals("Bad value at index " + i, MAGIC, buf.get(i));
        }
    }
    public void testShortBufferArgument() {
        ShortBuffer buf  = ShortBuffer.allocate(1024);
        final short MAGIC = (short)0xABED;
        lib.fillInt16Buffer(buf, 1024, MAGIC);
        for (int i=0;i < buf.capacity();i++) {
            assertEquals("Bad value at index " + i, MAGIC, buf.get(i));
        }
    }
View Full Code Here

        }
    }
   
    public void testDirectShortBufferArgument() {
        ByteBuffer buf  = ByteBuffer.allocateDirect(1024*2).order(ByteOrder.nativeOrder());
        ShortBuffer shortBuf = buf.asShortBuffer();
        final short MAGIC = (short)0xABED;
        lib.fillInt16Buffer(shortBuf, 1024, MAGIC);
        for (int i=0;i < shortBuf.capacity();i++) {
            assertEquals("Bad value at index " + i, MAGIC, shortBuf.get(i));
        }
    }
View Full Code Here

                         i < 512 ? 0 : MAGIC, array[i]);
        }
    }
    public void testWrappedShortArrayArgument() {
        short[] array = new short[1024];
        ShortBuffer buf = ShortBuffer.wrap(array, 512, 512);
        final short MAGIC = (short)0xABED;
        lib.fillInt16Buffer(buf, 512, MAGIC);
        for (int i=0;i < array.length;i++) {
            assertEquals("Bad value at index " + i,
                         i < 512 ? 0 : MAGIC, array[i]);
View Full Code Here

TOP

Related Classes of java.nio.ShortBuffer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.