Package java.nio

Examples of java.nio.ByteOrder


            default: assert (false);
        }
        int stride = frame.stride();
        int size = frame.image_bytes();
        int numChannels = stride/w*8/depth;
        ByteOrder frameEndian = frame.little_endian() != 0 ?
                ByteOrder.LITTLE_ENDIAN : ByteOrder.BIG_ENDIAN;
        boolean alreadySwapped = false;
        int color_coding = frame.color_coding();
        boolean colorbayer = color_coding == DC1394_COLOR_CODING_RAW8 ||
                             color_coding == DC1394_COLOR_CODING_RAW16;
        boolean colorrgb   = color_coding == DC1394_COLOR_CODING_RGB8 ||
                             color_coding == DC1394_COLOR_CODING_RGB16;
        boolean coloryuv   = color_coding == DC1394_COLOR_CODING_YUV411 ||
                             color_coding == DC1394_COLOR_CODING_YUV422 ||
                             color_coding == DC1394_COLOR_CODING_YUV444;
        BytePointer imageData = frame.image();

        if ((depth <= 8 || frameEndian.equals(ByteOrder.nativeOrder())) && !coloryuv &&
                (colorMode == ColorMode.RAW || (colorMode == ColorMode.BGR && numChannels == 3) ||
                (colorMode == ColorMode.GRAY && numChannels == 1 && !colorbayer))) {
            if (return_image == null) {
                return_image = IplImage.createHeader(w, h, iplDepth, numChannels);
            }
            return_image.widthStep(stride);
            return_image.imageSize(size);
            return_image.imageData(imageData);
        } else {
            // in the padding, there's sometimes timeframe information and stuff
            // that libdc1394 will copy for us, so we need to allocate it
            int padding_bytes = frame.padding_bytes();
            int padding1 = (int)Math.ceil((double)padding_bytes/(w * depth/8));
            int padding3 = (int)Math.ceil((double)padding_bytes/(w*3*depth/8));
            if (return_image == null) {
                int c       = colorMode == ColorMode.BGR ? 3 : 1;
                int padding = colorMode == ColorMode.BGR ? padding3 : padding1;
                return_image = IplImage.create(w, h+padding, iplDepth, c);
                return_image.height(return_image.height() - padding);
            }
            if (temp_image == null) {
                if (colorMode == ColorMode.BGR && numChannels != 3 && !colorbayer) {
                    temp_image = IplImage.create(w, h+padding1, iplDepth, 1);
                    temp_image.height(temp_image.height() - padding1);
                } else if (colorMode == ColorMode.GRAY &&
                        (coloryuv || colorbayer || (colorrgb && depth > 8))) {
                    temp_image = IplImage.create(w, h+padding3, iplDepth, 3);
                    temp_image.height(temp_image.height() - padding3);
                } else if (colorMode == ColorMode.GRAY && colorrgb) {
                    temp_image = IplImage.createHeader(w, h, iplDepth, 3);
                    temp_image.widthStep(stride);
                    temp_image.imageSize(size);
                    temp_image.imageData(imageData);
                } else {
                    temp_image = return_image;
                }
            }
            conv_image.size(0, temp_image.width());
            conv_image.size(1, temp_image.height());
            if (depth > 8) {
                conv_image.color_coding(colorMode == ColorMode.RAW  ? DC1394_COLOR_CODING_RAW16  :
                                        temp_image.nChannels() == 1 ? DC1394_COLOR_CODING_MONO16 :
                                                                      DC1394_COLOR_CODING_RGB16);
                conv_image.data_depth(16);
            } else {
                conv_image.color_coding(colorMode == ColorMode.RAW  ? DC1394_COLOR_CODING_RAW8   :
                                        temp_image.nChannels() == 1 ? DC1394_COLOR_CODING_MONO8  :
                                                                      DC1394_COLOR_CODING_RGB8);
                conv_image.data_depth(8);
            }
            conv_image.stride(temp_image.widthStep());
            int temp_size = temp_image.imageSize();
            conv_image.allocated_image_bytes(temp_size).
                    total_bytes(temp_size).image_bytes(temp_size);
            conv_image.image(temp_image.imageData());

            if (colorbayer) {
                // from raw Bayer... invert R and B to get BGR images
                // (like OpenCV wants them) instead of RGB
                int c = frame.color_filter();
                if (c               == DC1394_COLOR_FILTER_RGGB) {
                    frame.color_filter(DC1394_COLOR_FILTER_BGGR);
                } else if (c        == DC1394_COLOR_FILTER_GBRG) {
                    frame.color_filter(DC1394_COLOR_FILTER_GRBG);
                } else if (c        == DC1394_COLOR_FILTER_GRBG) {
                    frame.color_filter(DC1394_COLOR_FILTER_GBRG);
                } else if (c        == DC1394_COLOR_FILTER_BGGR) {
                    frame.color_filter(DC1394_COLOR_FILTER_RGGB);
                } else {
                    assert(false);
                }
                // other better methods than "simple" give garbage at 16 bits..
                err = dc1394_debayer_frames(frame, conv_image, DC1394_BAYER_METHOD_SIMPLE);
                frame.color_filter(c);
                if (err != DC1394_SUCCESS) {
                    throw new Exception("dc1394_debayer_frames() Error " + err + ": Could not debayer frame.");
                }
            } else if (depth > 8 &&
                    frame.data_depth()   == conv_image.data_depth() &&
                    frame.color_coding() == conv_image.color_coding() &&
                    frame.stride()       == conv_image.stride()) {
                // we just need a copy to swap bytes..
                ShortBuffer in  = frame.getByteBuffer().order(frameEndian).asShortBuffer();
                ShortBuffer out = temp_image.getByteBuffer().order(ByteOrder.nativeOrder()).asShortBuffer();
                out.put(in);
                alreadySwapped = true;
            } else if (!colorrgb) {
                // from YUV, etc.
                err = dc1394_convert_frames(frame, conv_image);
                if (err != DC1394_SUCCESS) {
                    throw new Exception("dc1394_convert_frames() Error " + err + ": Could not convert frame.");
                }
            }
        }

        if (!alreadySwapped && depth > 8 && !frameEndian.equals(ByteOrder.nativeOrder())) {
            // ack, the camera's endianness doesn't correspond to our machine ...
            // swap bytes of 16-bit images
            ByteBuffer  bb  = temp_image.getByteBuffer();
            ShortBuffer in  = bb.order(frameEndian).asShortBuffer();
            ShortBuffer out = bb.order(ByteOrder.nativeOrder()).asShortBuffer();
View Full Code Here


      writeToChannel(_response);
      _response = null;
    }

    //We need to lie to netty that the buffer is BIG_ENDIAN event if it is LITTLE_ENDIAN (see DDS-1212)
    ByteOrder bufferOrder = buffer.order();
    ByteBuffer realBuffer = bufferOrder == ByteOrder.BIG_ENDIAN
        ? buffer : buffer.slice().order(ByteOrder.BIG_ENDIAN);
    if (null == _chunkReuse)
    {
      _chunkReuse = new DefaultHttpChunk(ChannelBuffers.wrappedBuffer(realBuffer));
View Full Code Here

        if ( adjustments != null ) {
            offset += adjustments[0];
            valueOffsetAdjustment = adjustments[1];
        }
        if ( !dir.readMakerNotes( m_buf, offset, byteCount ) ) {
            final ByteOrder origOrder = m_buf.probeOrder( offset );
            m_exifParser.parseDirectory( offset, valueOffsetAdjustment, dir );
            m_buf.order( origOrder );
        }
    }
View Full Code Here

        final LCByteBuffer buf = imageInfo.getByteBuffer();
        //
        // The pointer to where the JPEG starts is 84 bytes in.  The length of
        // the JPEG is 4 bytes after that.  Both are always in big-endian.
        //
        final ByteOrder origOrder = buf.order();
        buf.order( ByteOrder.BIG_ENDIAN );
        final int offset = buf.getInt( 84 );
        final int length = buf.getInt( 88 );
        buf.order( origOrder );
        return JPEGImageType.getImageFromBuffer(
View Full Code Here

    /**
     * {@inheritDoc}
     */
    protected boolean readMakerNotes( LCByteBuffer buf, int offset,
                                      int byteCount ) throws IOException {
        final ByteOrder origOrder =
            buf.probeOrder( offset + KODAK_IMAGE_WIDTH );

        int tagID = 0;
        final int end = offset + byteCount;
        while ( offset < end && tagID <= KODAK_SHARPNESS ) {
View Full Code Here

        if ( m_includeHeader ) {
            m_nextEXIFBigValuePos += EXIF_HEADER_SIZE;
            m_endPosPlus1 += EXIF_HEADER_SIZE;
        }
        final ByteBuffer buf = ByteBuffer.allocate( m_endPosPlus1 );
        final ByteOrder nativeOrder = ByteOrder.nativeOrder();
        buf.order( nativeOrder );
        if ( m_includeHeader ) {
            ByteBufferUtil.put( buf, "Exif\0\0", "ASCII" );
            buf.putShort(
                nativeOrder == ByteOrder.BIG_ENDIAN ?
View Full Code Here

     * @return Returns the original {@link ByteOrder}.
     * @throws BufferUnderflowException if there are fewer than 2 bytes
     * remaining in the buffer starting at its current position.
     */
    public ByteOrder probeOrder( int shortOffset ) throws IOException {
        final ByteOrder origOrder = order();
        //
        // We use a heuristic of extracting a short both using big and little
        // endian byte orders.  The assumption is that reading the bytes in the
        // right order willl yield a smaller number than the wrong order, e.g.
        // 0x0100 is 1 when read as little endian is 1 but is 256 when read as
View Full Code Here

            System.err.println("Usage: java " + ChronicleSource.class.getName() + " {chronicle-base-path} {port} [delayNS]");
            System.exit(-1);
        }
        int dataBitsHintSize = Integer.getInteger("dataBitsHintSize", 27);
        String def = ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN ? "Big" : "Little";
        ByteOrder byteOrder = System.getProperty("byteOrder", def).equalsIgnoreCase("Big") ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN;
        String basePath = args[0];
        int port = Integer.parseInt(args[1]);
        int delayNS = 5 * 1000 * 1000;
        if (args.length > 2)
            delayNS = Integer.parseInt(args[2]);
View Full Code Here

            System.err.println("Usage: java " + ChronicleSink.class.getName() + " {chronicle-base-path} {hostname} {port}");
            System.exit(-1);
        }
        int dataBitsHintSize = Integer.getInteger("dataBitsHintSize", 27);
        String def = ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN ? "Big" : "Little";
        ByteOrder byteOrder = System.getProperty("byteOrder", def).equalsIgnoreCase("Big") ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN;
        String basePath = args[0];
        String hostname = args[1];
        int port = Integer.parseInt(args[2]);
        IndexedChronicle ic = new IndexedChronicle(basePath, dataBitsHintSize, byteOrder);
        new ChronicleSink(ic, hostname, port);
View Full Code Here

     *            The seed for the hash.
     * @return The 32 bit murmur hash of the bytes in the buffer.
     */
    public static int hash(ByteBuffer buf, int seed) {
  // save byte order for later restoration
  ByteOrder byteOrder = buf.order();
  buf.order(ByteOrder.LITTLE_ENDIAN);

  int m = 0x5bd1e995;
  int r = 24;

View Full Code Here

TOP

Related Classes of java.nio.ByteOrder

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.