Java Array Unpack unpack(double[] packed, int width, int height, int outputIndex)

Here you can find the source of unpack(double[] packed, int width, int height, int outputIndex)

Description

Returns a new array that is the result of unpacking the given 1D array into a 2D array, row-first.

License

Open Source License

Parameter

Parameter Description
packed The packed array.
width The width, or number of columns, in the unpacked array.
height The height, or number of rows, in the unpacked array.
outputIndex The index to start reading from in the packed array.

Declaration

public static double[][] unpack(double[] packed, int width, int height, int outputIndex) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /** //  w  ww.j  a  v a 2s .com
     * Returns a new array that is the result of unpacking the given 1D array into a 2D array, row-first.
     * @param packed The packed array.
     * @param width The width, or number of columns, in the unpacked array.
     * @param height The height, or number of rows, in the unpacked array.
     * @param outputIndex The index to start reading from in the packed array.
     * @see #pack(double[][])
     */
    public static double[][] unpack(double[] packed, int width, int height, int outputIndex) {
        double[][] unpacked = new double[height][width];
        return unpack(packed, unpacked, outputIndex);
    }

    /** 
     * Unpacks the values in the given 1D array into the given 2D array, row-first.
     * @param packed The packed array.
     * @param unpacked an array to copy the result into. Should have dimensions [height/rows][width/columns].
     * @param outputIndex The index to start reading from in the packed array.
     * @return a reference to the array passed in for parameter unpacked.
     * @see #pack(double[][])
     */
    public static double[][] unpack(double[] packed, double[][] unpacked, int outputIndex) {
        int width = unpacked[0].length;
        int height = unpacked.length;
        int i = outputIndex;
        for (int y = 0; y < height; y++) {
            for (int x = 0; x < width; x++) {
                unpacked[y][x] = packed[i++];
            }
        }
        return unpacked;
    }
}

Related

  1. unpack(byte[] array)
  2. unpack(byte[] bytes)
  3. unpack(int[] sourcearray, int arraypos, int[] data, int datapos, int num, int b)
  4. unpackBCD(byte[] source)
  5. unpackDie(byte[] bytes)
  6. UnpackFloat(byte[] bytes, float value)