Class ImageInfo


  • public class ImageInfo
    extends java.lang.Object

    Describes pixel dimensions and encoding. Bitmap, Image, Pixmap, and Surface can be created from ImageInfo. ImageInfo can be retrieved from Bitmap and Pixmap, but not from Image and Surface. For example, Image and Surface implementations may defer pixel depth, so may not completely specify ImageInfo.

    ImageInfo contains dimensions, the pixel integral width and height. It encodes how pixel bits describe alpha, transparency; color components red, blue, and green; and ColorSpace, the range and linearity of colors.

    • Field Detail

      • _colorInfo

        public final ColorInfo _colorInfo
      • _width

        public final int _width
      • _height

        public final int _height
      • DEFAULT

        public static final ImageInfo DEFAULT
    • Constructor Detail

      • ImageInfo

        public ImageInfo​(int width,
                         int height,
                         @NotNull
                         @NotNull ColorType colorType,
                         @NotNull
                         @NotNull ColorAlphaType alphaType)
      • ImageInfo

        public ImageInfo​(int width,
                         int height,
                         @NotNull
                         @NotNull ColorType colorType,
                         @NotNull
                         @NotNull ColorAlphaType alphaType,
                         @Nullable
                         @Nullable ColorSpace colorSpace)
      • ImageInfo

        @Internal
        public ImageInfo​(int width,
                         int height,
                         int colorType,
                         int alphaType,
                         long colorSpace)
      • ImageInfo

        public ImageInfo​(ColorInfo colorInfo,
                         int width,
                         int height)
    • Method Detail

      • makeN32

        @NotNull
        @Contract("_, _, _ -> new")
        public static @NotNull ImageInfo makeN32​(int width,
                                                 int height,
                                                 @NotNull
                                                 @NotNull ColorAlphaType alphaType)
        Returns:
        ImageInfo with ColorType.N32
      • makeN32

        @NotNull
        @Contract("_, _, _, _ -> new")
        public static @NotNull ImageInfo makeN32​(int width,
                                                 int height,
                                                 @NotNull
                                                 @NotNull ColorAlphaType alphaType,
                                                 @Nullable
                                                 @Nullable ColorSpace colorSpace)
        Returns:
        ImageInfo with ColorType.N32
      • getColorType

        @NotNull
        public @NotNull ColorType getColorType()
      • withColorType

        @NotNull
        public @NotNull ImageInfo withColorType​(@NotNull
                                                @NotNull ColorType colorType)
      • getColorAlphaType

        @NotNull
        public @NotNull ColorAlphaType getColorAlphaType()
      • withColorAlphaType

        @NotNull
        public @NotNull ImageInfo withColorAlphaType​(@NotNull
                                                     @NotNull ColorAlphaType alphaType)
      • getColorSpace

        @Nullable
        public @Nullable ColorSpace getColorSpace()
      • withColorSpace

        @NotNull
        public @NotNull ImageInfo withColorSpace​(@NotNull
                                                 @NotNull ColorSpace colorSpace)
      • isEmpty

        public boolean isEmpty()
        Returns:
        true if either dimension is zero or smaller
      • isOpaque

        public boolean isOpaque()

        Returns true if ColorAlphaType is set to hint that all pixels are opaque; their alpha value is implicitly or explicitly 1.0. If true, and all pixels are not opaque, Skia may draw incorrectly.

        Does not check if ColorType allows alpha, or if any pixel value has transparency.

        Returns:
        true if alphaType is ColorAlphaType.OPAQUE
      • getBounds

        @NotNull
        public @NotNull io.github.humbleui.types.IRect getBounds()
        Returns:
        integral rectangle from (0, 0) to (getWidth(), getHeight())
      • isGammaCloseToSRGB

        public boolean isGammaCloseToSRGB()
        Returns:
        true if associated ColorSpace is not null, and ColorSpace gamma is approximately the same as sRGB.
      • withWidthHeight

        @NotNull
        public @NotNull ImageInfo withWidthHeight​(int width,
                                                  int height)
      • getBytesPerPixel

        public int getBytesPerPixel()
        Returns number of bytes per pixel required by ColorType. Returns zero if getColorType() is ColorType.UNKNOWN.
        Returns:
        bytes in pixel
      • getShiftPerPixel

        public int getShiftPerPixel()
        Returns bit shift converting row bytes to row pixels. Returns zero for ColorType.UNKNOWN.
        Returns:
        one of: 0, 1, 2, 3, 4; left shift to convert pixels to bytes
      • getMinRowBytes

        public long getMinRowBytes()
        Returns minimum bytes per row, computed from pixel getWidth() and ColorType, which specifies getBytesPerPixel(). Bitmap maximum value for row bytes must fit in 31 bits.
      • computeOffset

        public long computeOffset​(int x,
                                  int y,
                                  long rowBytes)

        Returns byte offset of pixel from pixel base address.

        Asserts in debug build if x or y is outside of bounds. Does not assert if rowBytes is smaller than getMinRowBytes(), even though result may be incorrect.

        Parameters:
        x - column index, zero or greater, and less than getWidth()
        y - row index, zero or greater, and less than getHeight()
        rowBytes - size of pixel row or larger
        Returns:
        offset within pixel array
        See Also:
        https://fiddle.skia.org/c/@ImageInfo_computeOffset
      • computeByteSize

        public long computeByteSize​(long rowBytes)

        Returns storage required by pixel array, given ImageInfo dimensions, ColorType, and rowBytes. rowBytes is assumed to be at least as large as getMinRowBytes().

        Returns zero if height is zero.

        Parameters:
        rowBytes - size of pixel row or larger
        Returns:
        memory required by pixel buffer
        See Also:
        https://fiddle.skia.org/c/@ImageInfo_computeByteSize
      • computeMinByteSize

        public long computeMinByteSize()

        Returns storage required by pixel array, given ImageInfo dimensions, and ColorType. Uses getMinRowBytes() to compute bytes for pixel row.

        Returns zero if height is zero.
        Returns:
        least memory required by pixel buffer
      • isRowBytesValid

        public boolean isRowBytesValid​(long rowBytes)
        Returns true if rowBytes is valid for this ImageInfo.
        Parameters:
        rowBytes - size of pixel row including padding
        Returns:
        true if rowBytes is large enough to contain pixel row and is properly aligned
      • getColorInfo

        public ColorInfo getColorInfo()
      • getWidth

        public int getWidth()
      • getHeight

        public int getHeight()
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • canEqual

        protected boolean canEqual​(java.lang.Object other)
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • withWidth

        public ImageInfo withWidth​(int _width)
        Returns:
        this.
      • withHeight

        public ImageInfo withHeight​(int _height)
        Returns:
        this.