Java Rectangle getRect(byte[] data, int i)

Here you can find the source of getRect(byte[] data, int i)

Description

Gets a rectangle out of an array of bytes.

License

Mozilla Public License

Parameter

Parameter Description
data The array of bytes to copy from.
i The index of the first byte of the rectangle.

Return

The rectangle at index i.

Declaration

public static java.awt.Rectangle getRect(byte[] data, int i) 

Method Source Code

//package com.java2s;
/*//from ww  w  .  j  av  a  2s  .c  o  m
 * Copyright © 2010-2011 Rebecca G. Bettencourt / Kreative Software
 * <p>
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * <a href="http://www.mozilla.org/MPL/">http://www.mozilla.org/MPL/</a>
 * <p>
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific language governing rights and limitations
 * under the License.
 * <p>
 * Alternatively, the contents of this file may be used under the terms
 * of the GNU Lesser General Public License (the "LGPL License"), in which
 * case the provisions of LGPL License are applicable instead of those
 * above. If you wish to allow use of your version of this file only
 * under the terms of the LGPL License and not to allow others to use
 * your version of this file under the MPL, indicate your decision by
 * deleting the provisions above and replace them with the notice and
 * other provisions required by the LGPL License. If you do not delete
 * the provisions above, a recipient may use your version of this file
 * under either the MPL or the LGPL License.
 * @since KSFL 1.0
 * @author Rebecca G. Bettencourt, Kreative Software
 */

public class Main {
    /**
     * Gets a rectangle out of an array of bytes.
     * A rectangle is defined by four 16-bit big-endian integers,
     * representing the top, left, bottom, and right.
     * @param data The array of bytes to copy from.
     * @param i The index of the first byte of the rectangle.
     * @return The rectangle at index <code>i</code>.
     */
    public static java.awt.Rectangle getRect(byte[] data, int i) {
        return new java.awt.Rectangle(getShort(data, i + 2), getShort(data,
                i + 0), getShort(data, i + 6) - getShort(data, i + 2),
                getShort(data, i + 4) - getShort(data, i + 0));
    }

    /**
     * Gets a rectangle out of an array of bytes.
     * A rectangle is defined by four 16-bit integers,
     * representing the top, left, bottom, and right.
     * @param data The array of bytes to copy from.
     * @param i The index of the first byte of the rectangle.
     * @param le True if the value is little-endian, false if the value is big-endian.
     * @return The rectangle at index <code>i</code>.
     */
    public static java.awt.Rectangle getRect(byte[] data, int i, boolean le) {
        return le ? getRectLE(data, i) : getRect(data, i);
    }

    /**
     * Gets a 16-bit big-endian integer out of an array of bytes.
     * @param data The array of bytes to copy from.
     * @param i The index of the first byte of the integer.
     * @return The 16-bit big-endian integer at index <code>i</code>.
     */
    public static short getShort(byte[] data, int i) {
        return (short) (((data[i + 0] & 0xFF) << 8) | ((data[i + 1] & 0xFF) << 0));
    }

    /**
     * Gets a 16-bit integer out of an array of bytes.
     * @param data The array of bytes to copy from.
     * @param i The index of the first byte of the integer.
     * @param le True if the value is little-endian, false if the value is big-endian.
     * @return The 16-bit integer at index <code>i</code>.
     */
    public static short getShort(byte[] data, int i, boolean le) {
        return le ? getShortLE(data, i) : getShort(data, i);
    }

    /**
     * Gets a rectangle out of an array of bytes.
     * A rectangle is defined by four 16-bit little-endian integers,
     * representing the top, left, bottom, and right.
     * @param data The array of bytes to copy from.
     * @param i The index of the first byte of the rectangle.
     * @return The rectangle at index <code>i</code>.
     */
    public static java.awt.Rectangle getRectLE(byte[] data, int i) {
        return new java.awt.Rectangle(getShortLE(data, i + 2), getShortLE(
                data, i + 0), getShortLE(data, i + 6)
                - getShortLE(data, i + 2), getShortLE(data, i + 4)
                - getShortLE(data, i + 0));
    }

    /**
     * Gets a 16-bit little-endian integer out of an array of bytes.
     * @param data The array of bytes to copy from.
     * @param i The index of the first byte of the integer.
     * @return The 16-bit little-endian integer at index <code>i</code>.
     */
    public static short getShortLE(byte[] data, int i) {
        return (short) (((data[i + 0] & 0xFF) << 0) | ((data[i + 1] & 0xFF) << 8));
    }
}

Related

  1. formatRect(Rectangle rc)
  2. formatRectangle(Rectangle rect)
  3. getAbsoluteRectangle(Rectangle rect)
  4. getFrameOrientations(Rectangle parent)
  5. getMaximalRectangle(Rectangle r1, Rectangle r2)
  6. getRectangleProperty(Map p, Object key, Rectangle defaultValue)
  7. getRectLE(byte[] data, int i)
  8. getSubArea(Shape retangulo, int divisorx, int divisory, int offsetx, int offsety)
  9. inflateRectangle(Rectangle r, int x, int y)