Class ContourPlot.Img

    • Field Detail

      • boundary_mode_repeat_edge

        public static final int boundary_mode_repeat_edge
        boundary mode that will repeat the edge of of an Img for out of bounds positions.
        Since:
        1.0
        See Also:
        getValue(int, int, int), Constant Field Values
      • data

        private final int[] data
        data array of this Img containing a value for each pixel in row major order
        Since:
        1.0
      • width

        private final int width
        width and height of this image
      • height

        private final int height
        width and height of this image
      • spliteratorMinimumSplitSize

        private int spliteratorMinimumSplitSize
        minimum number of elements this Img's Spliterators can be split to. Default value is 1024.
        Since:
        1.3
    • Constructor Detail

      • Img

        public Img​(int width,
                   int height)
        Creates a new Img of specified dimensions. Values are initialized to 0.
        Parameters:
        width - of the Img
        height - of the Img
        Since:
        1.0
      • Img

        public Img​(java.awt.Dimension dimension)
        Creates a new Img of specified Dimension. Values are initilaized to 0.
        Parameters:
        dimension - extend of the Img (width and height)
        Since:
        1.0
      • Img

        public Img​(java.awt.image.BufferedImage bimg)
        Creates a new Img of same dimensions as provided BufferedImage. Values are copied from argument Image
        Parameters:
        bimg - the BufferedImage
        Since:
        1.0
        See Also:
        createRemoteImg(BufferedImage)
      • Img

        public Img​(int width,
                   int height,
                   int[] data)
        Creates a new Img of specified dimensions. Provided data array will be used as this images data.
        Parameters:
        width - of the Img
        height - of the Img
        data - values (pixels) that will be used as the content of this Img
        Throws:
        java.lang.IllegalArgumentException - when the number of pixels of this Img resulting from width*height does not match the number of provided data values.
        Since:
        1.0
      • Img

        public Img​(java.awt.Dimension dim,
                   int[] data)
        Creates a new Img of specified dimensions. Provided data array will be used as this images data.
        Parameters:
        dim - extend of the image (width and height)
        data - values (pixels) that will be used as the content of this Img
        Throws:
        java.lang.IllegalArgumentException - when the number of pixels of this Img resulting from width*height does not match the number of provided data values.
        Since:
        1.0
    • Method Detail

      • getData

        public int[] getData()
        Returns:
        data array of this Img
        Since:
        1.0
      • getValue

        public int getValue​(int x,
                            int y)
        Returns the value of this Img at the specified position. No bounds checks will be performed, positions outside of this image's dimension can either result in a value for a different position or an ArrayIndexOutOfBoundsException.
        Parameters:
        x - coordinate
        y - coordinate
        Returns:
        value for specified position
        Throws:
        java.lang.ArrayIndexOutOfBoundsException - if resulting index from x and y is not within the data arrays bounds.
        Since:
        1.0
        See Also:
        getValue(int, int, int), getPixel(int, int), setValue(int, int, int)
      • getValue

        public int getValue​(int x,
                            int y,
                            int boundaryMode)
        Returns the value of this Img at the specified position. Bounds checks will be performed and positions outside of this image's dimensions will be handled according to the specified boundary mode.

        Boundary Modes
        boundary_mode_zero
        will return 0 for out of bounds positions.
        -boundary_mode_repeat_edge
        will return the same value as the nearest edge value.
        -boundary_mode_repeat_image
        will return a value of the image as if the if the image was repeated on all sides.
        -boundary_mode_mirror
        will return a value of the image as if the image was mirrored on all sides.
        -other values for boundary mode
        will be used as default color for out of bounds positions. It is safe to use opaque colors (0xff000000 - 0xffffffff) and transparent colors above 0x0000000f which will not collide with one of the boundary modes (number of boundary modes is limited to 16 for the future).

        Parameters:
        x - coordinate
        y - coordinate
        boundaryMode - one of the boundary modes e.g. boundary_mode_mirror
        Returns:
        value at specified position or a value depending on the boundary mode for out of bounds positions.
        Since:
        1.0
      • interpolateARGB

        public int interpolateARGB​(double xNormalized,
                                   double yNormalized)
        Returns a bilinearly interpolated ARGB value of the image for the specified normalized position (x and y within [0,1]). Position {0,0} denotes the image's origin (top left corner), position {1,1} denotes the opposite corner (pixel at {width-1, height-1}).

        An ArrayIndexOutOfBoundsException may be thrown for x and y greater than 1 or less than 0.

        Parameters:
        xNormalized - coordinate within [0,1]
        yNormalized - coordinate within [0,1]
        Returns:
        bilinearly interpolated ARGB value.
        Throws:
        java.lang.ArrayIndexOutOfBoundsException - when a resulting index is out of the data array's bounds, which can only happen for x and y values less than 0 or greater than 1.
        Since:
        1.0
      • interpolateColors

        private int interpolateColors​(int c00,
                                      int c01,
                                      int c10,
                                      int c11,
                                      double mx,
                                      double my)
      • blend

        private int blend​(int channel1,
                          int channel2,
                          double m)
      • copyArea

        public ContourPlot.Img copyArea​(int x,
                                        int y,
                                        int w,
                                        int h,
                                        ContourPlot.Img dest,
                                        int destX,
                                        int destY)
        Copies specified area of this Img to the specified destination Img at specified destination coordinates. If destination Img is null a new Img with the areas size will be created and the destination coordinates will be ignored so that the Img will contain all the values of the area.

        The specified area has to be within the bounds of this image or otherwise an IllegalArgumentException will be thrown. Only the intersecting part of the area and the destination image is copied which allows for an out of bounds destination area origin.

        Parameters:
        x - area origin in this image (x-coordinate)
        y - area origin in this image (y-coordinate)
        w - width of area
        h - height of area
        dest - destination Img
        destX - area origin in destination Img (x-coordinate)
        destY - area origin in destination Img (y-coordinate)
        Returns:
        the destination Img
        Throws:
        java.lang.IllegalArgumentException - if the specified area is not within the bounds of this Img or if the size of the area is not positive.
        Since:
        1.0
      • setValue

        public void setValue​(int x,
                             int y,
                             int value)
        Sets value at the specified position. No bounds checks will be performed, positions outside of this images dimension can either result in a value for a different position or an ArrayIndexOutOfBoundsException.
        Parameters:
        x - coordinate
        y - coordinate
        value - to be set at specified position. e.g. 0xff0000ff for blue color
        Throws:
        java.lang.ArrayIndexOutOfBoundsException - if resulting index from x and y is not within the data arrays bounds.
        Since:
        1.0
        See Also:
        getValue(int, int)
      • fill

        public ContourPlot.Img fill​(int value)
        Fills the whole image with the specified value.
        Parameters:
        value - for filling image
        Returns:
        this for chaining
        Since:
        1.0
      • createRemoteImg

        public ContourPlot.Img createRemoteImg​(java.awt.image.BufferedImage bimg)
        Creates an Img sharing the specified BufferedImage's data. Changes in the BufferdImage are reflected in the created Img and vice versa.

        Only BufferedImages with DataBuffer of DataBuffer.TYPE_INT can be used since the Img class uses an int[] to store its data. An IllegalArgumentException will be thrown if a BufferedImage with a different DataBufferType is provided.

        Parameters:
        bimg - BufferedImage with TYPE_INT DataBuffer.
        Returns:
        Throws:
        java.lang.IllegalArgumentException - if a BufferedImage with a DataBufferType other than DataBuffer.TYPE_INT is provided.
        Since:
        1.0
        See Also:
        getRemoteBufferedImage(), Img(BufferedImage)
      • getSpliteratorMinimumSplitSize

        public int getSpliteratorMinimumSplitSize()
        Returns the minimum number of elements in a split of a Spliterator of this Img. Spliterators will only split if they contain more elements than specified by this value. Default is 1024.
        Specified by:
        getSpliteratorMinimumSplitSize in interface ContourPlot.ImgBase<ContourPlot.Pixel>
        Returns:
        minimum number of elements of a Spliterator to allow for splitting.
        Since:
        1.3
      • setSpliteratorMinimumSplitSize

        public void setSpliteratorMinimumSplitSize​(int size)
        Sets the minimum number of elements in a split of a Spliterator of this Img. Spliterators will only split if they contain more elements than specified by this value. Default is 1024.

        It is advised that this number is chosen carefully and with respect to the Img's size and application of the spliterator, as it can decrease performance of the parallelized methods
        ContourPlot.ImgBase.forEach(boolean parallel, Consumer action),
        ContourPlot.ImgBase.forEach(boolean parallel, int x, int y, int w, int h, Consumer action) or
        ContourPlot.ImgBase.stream(boolean parallel) etc.
        Small values cause a Spliterator to be split more often which will consume more memory compared to higher values. Special applications on small Imgs using sophisticated consumers or stream operations may justify the use of small split sizes. High values cause a Spliterator to be split less often which may cause the work items to be badly apportioned among the threads and lower throughput.

        Parameters:
        size - the minimum number of elements a split covers
        Throws:
        java.lang.IllegalArgumentException - if specified size is less than 1
        Since:
        1.3