Class Bitmap
- java.lang.Object
-
- io.github.humbleui.skija.impl.Native
-
- io.github.humbleui.skija.impl.Managed
-
- io.github.humbleui.skija.Bitmap
-
- All Implemented Interfaces:
IHasImageInfo,java.lang.AutoCloseable
public class Bitmap extends Managed implements IHasImageInfo
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classBitmap._FinalizerHolder-
Nested classes/interfaces inherited from class io.github.humbleui.skija.impl.Managed
Managed.CleanerThunk
-
-
Field Summary
Fields Modifier and Type Field Description ImageInfo_imageInfo-
Fields inherited from class io.github.humbleui.skija.impl.Managed
_cleanable
-
-
Constructor Summary
Constructors Constructor Description Bitmap()Creates an empty Bitmap without pixels, withColorType.UNKNOWN,ColorAlphaType.UNKNOWN, and with a width and height of zero.Bitmap(long ptr)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static boolean_nAllocPixels(long ptr)static boolean_nAllocPixelsFlags(long ptr, int width, int height, int colorType, int alphaType, long colorSpacePtr, int flags)static boolean_nAllocPixelsRowBytes(long ptr, int width, int height, int colorType, int alphaType, long colorSpacePtr, long rowBytes)static long_nComputeByteSize(long ptr)static boolean_nComputeIsOpaque(long ptr)static void_nErase(long ptr, int color)static void_nErase4f(long ptr, float r, float g, float b, float a)static void_nEraseRect(long ptr, int color, int left, int top, int right, int bottom)static void_nEraseRect4f(long ptr, float r, float g, float b, float a, int left, int top, int right, int bottom)static io.github.humbleui.types.IPoint_nExtractAlpha(long ptr, long dstPtr, long paintPtr)static boolean_nExtractSubset(long ptr, long dstPtr, int left, int top, int right, int bottom)static float_nGetAlphaf(long ptr, int x, int y)static int_nGetColor(long ptr, int x, int y)static Color4f_nGetColor4f(long ptr, int x, int y)static long_nGetFinalizer()static int_nGetGenerationId(long ptr)static ImageInfo_nGetImageInfo(long ptr)static long_nGetPixelRef(long ptr)static long_nGetPixelRefOrigin(long ptr)static long_nGetPixmap(long ptr)static long_nGetRowBytes(long ptr)static int_nGetRowBytesAsPixels(long ptr)static boolean_nInstallPixels(long ptr, int width, int height, int colorType, int alphaType, long colorSpacePtr, byte[] pixels, long rowBytes)static boolean_nIsImmutable(long ptr)static boolean_nIsNull(long ptr)static boolean_nIsReadyToDraw(long ptr)static boolean_nIsVolatile(long ptr)static long_nMake()static long_nMakeClone(long ptr)static long_nMakeShader(long ptr, int tmx, int tmy, long samplingMode, float[] localMatrix)static void_nNotifyPixelsChanged(long ptr)static java.nio.ByteBuffer_nPeekPixels(long ptr)static byte[]_nReadPixels(long ptr, int width, int height, int colorType, int alphaType, long colorSpacePtr, long dstRowBytes, int srcX, int srcY)static void_nReset(long ptr)static boolean_nSetAlphaType(long ptr, int alphaType)static boolean_nSetImageInfo(long ptr, int width, int height, int colorType, int alphaType, long colorSpacePtr, long rowBytes)static void_nSetImmutable(long ptr)static void_nSetPixelRef(long ptr, long pixelRefPtr, int dx, int dy)static void_nSetVolatile(long ptr, boolean value)static void_nSwap(long ptr, long otherPtr)booleanallocN32Pixels(int width, int height)Sets ImageInfo to width, height, and native color type; and allocates pixel memory.booleanallocN32Pixels(int width, int height, boolean opaque)Sets ImageInfo to width, height, and native color type; and allocates pixel memory.booleanallocPixels()Allocates pixel memory with HeapAllocator, and replaces existing PixelRef.booleanallocPixels(@NotNull ImageInfo imageInfo)Sets ImageInfo to info following the rules insetImageInfo(ImageInfo, long)and allocates pixel memory.booleanallocPixels(@NotNull ImageInfo info, long rowBytes)Sets ImageInfo to info following the rules in setImageInfo() and allocates pixel memory.booleanallocPixelsFlags(@NotNull ImageInfo imageInfo, boolean zeroPixels)Sets ImageInfo to info following the rules in setImageInfo() and allocates pixel memory.longcomputeByteSize()Returns minimum memory required for pixel storage.booleancomputeIsOpaque()Returns true if all pixels are opaque.booleandrawsNothing()Returns true if width or height are zero, or if PixelRef is null.@NotNull Bitmaperase(int color)Replaces pixel values with color, interpreted as being in the sRGB ColorSpace.@NotNull Bitmaperase(int color, @NotNull io.github.humbleui.types.IRect area)Replaces pixel values inside area with color, interpreted as being in the sRGB ColorSpace.@NotNull Bitmaperase(@NotNull Color4f color)Replaces pixel values with color, interpreted as being in the sRGB.@NotNull Bitmaperase(@NotNull Color4f color, @NotNull io.github.humbleui.types.IRect area)Replaces pixel values with color, interpreted as being in the sRGB.booleanextractAlpha(@NotNull Bitmap dst)Sets dst to alpha described by pixels.@Nullable io.github.humbleui.types.IPointextractAlpha(@NotNull Bitmap dst, @Nullable Paint paint)Sets dst to alpha described by pixels.booleanextractSubset(@NotNull Bitmap dst, @NotNull io.github.humbleui.types.IRect subset)Shares PixelRef with dst.floatgetAlphaf(int x, int y)Look up the pixel at (x,y) and return its alpha component, normalized to [0..1].@NotNull io.github.humbleui.types.IRectgetBounds()Returns IRect { 0, 0, width(), height() }.intgetColor(int x, int y)Returns pixel at (x, y) as unpremultiplied color.Color4fgetColor4f(int x, int y)Returns pixel at (x, y) as unpremultiplied color.intgetGenerationId()Returns a unique value corresponding to the pixels in PixelRef.@NotNull ImageInfogetImageInfo()@Nullable PixelRefgetPixelRef()Returns PixelRef, which contains: pixel base address; its dimensions; and rowBytes(), the interval from one row to the next.@NotNull io.github.humbleui.types.IPointgetPixelRefOrigin()Returns origin of pixels within PixelRef.longgetRowBytes()Returns row bytes, the interval from one pixel row to the next.intgetRowBytesAsPixels()Returns number of pixels that fit on row.@NotNull io.github.humbleui.types.IRectgetSubset()Returns the bounds of this bitmap, offset by its PixelRef origin.booleaninstallPixels(byte[] pixels)booleaninstallPixels(@NotNull ImageInfo info, @org.jetbrains.annotations.Nullable byte[] pixels, long rowBytes)Sets ImageInfo to info following the rules in setImageInfo(), and creates PixelRef containing pixels and rowBytes.booleanisImmutable()Returns true if pixels can not change.booleanisNull()Returns true if PixelRef is null.booleanisReadyToDraw()Returns true if Bitmap can be drawn.@NotNull BitmapmakeClone()Copies settings from src to returned Bitmap.static @NotNull BitmapmakeFromImage(@NotNull Image image)@NotNull ShadermakeShader()@NotNull ShadermakeShader(@NotNull FilterTileMode tm)@NotNull ShadermakeShader(@NotNull FilterTileMode tmx, @NotNull FilterTileMode tmy)@NotNull ShadermakeShader(@NotNull FilterTileMode tmx, @NotNull FilterTileMode tmy, @NotNull SamplingMode sampling, @Nullable Matrix33 localMatrix)@NotNull ShadermakeShader(@NotNull FilterTileMode tmx, @NotNull FilterTileMode tmy, @Nullable Matrix33 localMatrix)@NotNull ShadermakeShader(@Nullable Matrix33 localMatrix)@NotNull BitmapnotifyPixelsChanged()Marks that pixels in PixelRef have changed.@Nullable java.nio.ByteBufferpeekPixels()If pixel address is available, return ByteBuffer wrapping it.@org.jetbrains.annotations.Nullable byte[]readPixels()@org.jetbrains.annotations.Nullable byte[]readPixels(@NotNull ImageInfo dstInfo, long dstRowBytes, int srcX, int srcY)Copies a rect of pixels from Bitmap.@NotNull Bitmapreset()Resets to its initial state; all fields are set to zero, as if Bitmap had been initialized by Bitmap().booleansetAlphaType(ColorAlphaType alphaType)Sets alpha type, if argument is compatible with current color type.booleansetImageInfo(@NotNull ImageInfo imageInfo)Sets width, height, ColorAlphaType, ColorType, ColorSpace.booleansetImageInfo(@NotNull ImageInfo imageInfo, long rowBytes)Sets width, height, ColorAlphaType, ColorType, ColorSpace, and optional rowBytes.@NotNull BitmapsetImmutable()Sets internal flag to mark Bitmap as immutable.@NotNull BitmapsetPixelRef(@Nullable PixelRef pixelRef, int dx, int dy)Replaces pixelRef and origin in Bitmap.voidswap(@NotNull Bitmap other)Swaps the fields of the two bitmaps.-
Methods inherited from class io.github.humbleui.skija.impl.Managed
_nInvokeFinalizer, close, isClosed
-
Methods inherited from class io.github.humbleui.skija.impl.Native
_nativeEquals, equals, getPtr, hashCode, toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface io.github.humbleui.skija.IHasImageInfo
getAlphaType, getBytesPerPixel, getColorInfo, getColorSpace, getColorType, getHeight, getShiftPerPixel, getWidth, isEmpty, isOpaque
-
-
-
-
Field Detail
-
_imageInfo
@Internal public ImageInfo _imageInfo
-
-
Constructor Detail
-
Bitmap
@Internal public Bitmap(long ptr)
-
Bitmap
public Bitmap()
Creates an empty Bitmap without pixels, withColorType.UNKNOWN,ColorAlphaType.UNKNOWN, and with a width and height of zero. PixelRef origin is set to (0, 0). Bitmap is not volatile. UsesetImageInfo(ImageInfo, long)to associate ColorType, ColorAlphaType, width, and height after Bitmap has been created.
-
-
Method Detail
-
makeClone
@NotNull @Contract("-> new") public @NotNull Bitmap makeClone()Copies settings from src to returned Bitmap. Shares pixels if src has pixels allocated, so both bitmaps reference the same pixels.- Returns:
- copy of src
- See Also:
- https://fiddle.skia.org/c/@Bitmap_copy_const_SkBitmap
-
makeFromImage
@NotNull @Contract("-> new") public static @NotNull Bitmap makeFromImage(@NotNull @NotNull Image image)
-
swap
public void swap(@NotNull @NotNull Bitmap other)Swaps the fields of the two bitmaps.- Parameters:
other- Bitmap exchanged with original- See Also:
- https://fiddle.skia.org/c/@Bitmap_swap
-
getImageInfo
@NotNull public @NotNull ImageInfo getImageInfo()
- Specified by:
getImageInfoin interfaceIHasImageInfo
-
getRowBytesAsPixels
public int getRowBytesAsPixels()
Returns number of pixels that fit on row. Should be greater than or equal to getWidth().- Returns:
- maximum pixels per row
-
isNull
public boolean isNull()
Returns true if PixelRef is null. Does not check if width or height are zero; calldrawsNothing()to check width, height, and PixelRef.- Returns:
- true if no PixelRef is associated
-
drawsNothing
public boolean drawsNothing()
Returns true if width or height are zero, or if PixelRef is null. If true, Bitmap has no effect when drawn or drawn into.- Returns:
- true if drawing has no effect
-
getRowBytes
public long getRowBytes()
Returns row bytes, the interval from one pixel row to the next. Row bytes is at least as large as: getWidth() * getBytesPerPixel(). Returns zero if getColorType() isColorType.UNKNOWN, or if row bytes supplied tosetImageInfo(ImageInfo)is not large enough to hold a row of pixels.- Returns:
- byte length of pixel row
-
setAlphaType
public boolean setAlphaType(ColorAlphaType alphaType)
Sets alpha type, if argument is compatible with current color type. Returns true unless argument is
ColorAlphaType.UNKNOWNand current value isColorAlphaType.UNKNOWN.Returns true if current color type is
ColorType.UNKNOWN. Argument is ignored, and alpha type remainsColorAlphaType.UNKNOWN.Returns true if current color type is
ColorType.RGB_565orColorType.GRAY_8. Argument is ignored, and alpha type remainsColorAlphaType.OPAQUE.If current color type is
ColorType.ARGB_4444,ColorType.RGBA_8888,ColorType.BGRA_8888, orColorType.RGBA_F16: returns true unless argument isColorAlphaType.UNKNOWNand current alpha type is notColorAlphaType.UNKNOWN. If current alpha type isColorAlphaType.UNKNOWN, argument is ignored.If current color type is
ColorType.ALPHA_8, returns true unless argument isColorAlphaType.UNKNOWNand current alpha type is notColorAlphaType.UNKNOWN. If current alpha type isColorAlphaType.UNKNOWN, argument is ignored. If argument isColorAlphaType.UNPREMUL, it is treated asColorAlphaType.PREMUL.This changes alpha type in PixelRef; all bitmaps sharing PixelRef are affected.
- Returns:
- true if alpha type is set
- See Also:
- https://fiddle.skia.org/c/@Bitmap_setAlphaType
-
computeByteSize
public long computeByteSize()
Returns minimum memory required for pixel storage. Does not include unused memory on last row when getRowBytesAsPixels() exceeds getWidth(). Returns zero if height() or width() is 0. Returns getHeight() times getRowBytes() if getColorType() isColorType.UNKNOWN.- Returns:
- size in bytes of image buffer
-
isImmutable
public boolean isImmutable()
Returns true if pixels can not change.
Most immutable Bitmap checks trigger an assert only on debug builds.
- Returns:
- true if pixels are immutable
- See Also:
- https://fiddle.skia.org/c/@Bitmap_isImmutable
-
setImmutable
@NotNull @Contract("-> this") public @NotNull Bitmap setImmutable()Sets internal flag to mark Bitmap as immutable. Once set, pixels can not change. Any other bitmap sharing the same PixelRef are also marked as immutable. Once PixelRef is marked immutable, the setting cannot be cleared.
Writing to immutable Bitmap pixels triggers an assert on debug builds.
-
reset
@NotNull @Contract("-> this") public @NotNull Bitmap reset()Resets to its initial state; all fields are set to zero, as if Bitmap had been initialized by Bitmap().
Sets width, height, row bytes to zero; pixel address to nullptr; ColorType to
ColorType.UNKNOWN; and ColorAlphaType toColorAlphaType.UNKNOWN.If PixelRef is allocated, its reference count is decreased by one, releasing its memory if Bitmap is the sole owner.
- See Also:
- https://fiddle.skia.org/c/@Bitmap_reset
-
computeIsOpaque
public boolean computeIsOpaque()
Returns true if all pixels are opaque. ColorType determines how pixels are encoded, and whether pixel describes alpha. Returns true for ColorType without alpha in each pixel; for other ColorType, returns true if all pixels have alpha values equivalent to 1.0 or greater.
For
ColorType.RGB_565orColorType.GRAY_8: always returns true. ForColorType.ALPHA_8,ColorType.BGRA_8888,ColorType.RGBA_8888: returns true if all pixel alpha values are 255. ForColorType.ARGB_4444: returns true if all pixel alpha values are 15. ForColorType.RGBA_F16: returns true if all pixel alpha values are 1.0 or greater.Returns false for
ColorType.UNKNOWN.- Returns:
- true if all pixels have opaque values or ColorType is opaque
-
getBounds
@NotNull public @NotNull io.github.humbleui.types.IRect getBounds()
Returns IRect { 0, 0, width(), height() }.
-
getSubset
@NotNull public @NotNull io.github.humbleui.types.IRect getSubset()
Returns the bounds of this bitmap, offset by its PixelRef origin.
-
setImageInfo
public boolean setImageInfo(@NotNull @NotNull ImageInfo imageInfo)Sets width, height, ColorAlphaType, ColorType, ColorSpace. Frees pixels, and returns true if successful.
imageInfo.getAlphaType() may be altered to a value permitted by imageInfo.getColorSpace(). If imageInfo.getColorType() is
ColorType.UNKNOWN, imageInfo.getAlphaType() is set toColorAlphaType.UNKNOWN. If imageInfo.colorType() isColorType.ALPHA_8and imageInfo.getAlphaType() isColorAlphaType.UNPREMUL, imageInfo.getAlphaType() is replaced byColorAlphaType.PREMUL. If imageInfo.colorType() isColorType.RGB_565orColorType.GRAY_8, imageInfo.getAlphaType() is set toColorAlphaType.OPAQUE. If imageInfo.colorType() isColorType.ARGB_4444,ColorType.RGBA_8888,ColorType.BGRA_8888, orColorType.RGBA_F16: imageInfo.getAlphaType() remains unchanged.Calls reset() and returns false if: - rowBytes exceeds 31 bits - imageInfo.getWidth() is negative - imageInfo.getHeight() is negative - rowBytes is positive and less than imageInfo.getWidth() times imageInfo.getBytesPerPixel()
- Parameters:
imageInfo- contains width, height, AlphaType, ColorType, ColorSpace- Returns:
- true if ImageInfo set successfully
- See Also:
- https://fiddle.skia.org/c/@Bitmap_setInfo
-
setImageInfo
public boolean setImageInfo(@NotNull @NotNull ImageInfo imageInfo, long rowBytes)Sets width, height, ColorAlphaType, ColorType, ColorSpace, and optional rowBytes. Frees pixels, and returns true if successful.
imageInfo.getAlphaType() may be altered to a value permitted by imageInfo.getColorSpace(). If imageInfo.getColorType() is
ColorType.UNKNOWN, imageInfo.getAlphaType() is set toColorAlphaType.UNKNOWN. If imageInfo.colorType() isColorType.ALPHA_8and imageInfo.getAlphaType() isColorAlphaType.UNPREMUL, imageInfo.getAlphaType() is replaced byColorAlphaType.PREMUL. If imageInfo.colorType() isColorType.RGB_565orColorType.GRAY_8, imageInfo.getAlphaType() is set toColorAlphaType.OPAQUE. If imageInfo.colorType() isColorType.ARGB_4444,ColorType.RGBA_8888,ColorType.BGRA_8888, orColorType.RGBA_F16: imageInfo.getAlphaType() remains unchanged.rowBytes must equal or exceed imageInfo.getMinRowBytes(). If imageInfo.getColorSpace() is
ColorType.UNKNOWN, rowBytes is ignored and treated as zero; for all other ColorSpace values, rowBytes of zero is treated as imageInfo.getMinRowBytes().Calls reset() and returns false if: - rowBytes exceeds 31 bits - imageInfo.getWidth() is negative - imageInfo.getHeight() is negative - rowBytes is positive and less than imageInfo.getWidth() times imageInfo.getBytesPerPixel()
- Parameters:
imageInfo- contains width, height, AlphaType, ColorType, ColorSpacerowBytes- imageInfo.getMinRowBytes() or larger; or zero- Returns:
- true if ImageInfo set successfully
- See Also:
- https://fiddle.skia.org/c/@Bitmap_setInfo
-
allocPixelsFlags
public boolean allocPixelsFlags(@NotNull @NotNull ImageInfo imageInfo, boolean zeroPixels)Sets ImageInfo to info following the rules in setImageInfo() and allocates pixel memory. Memory is zeroed.
Returns false and calls reset() if ImageInfo could not be set, or memory could not be allocated, or memory could not optionally be zeroed.
On most platforms, allocating pixel memory may succeed even though there is not sufficient memory to hold pixels; allocation does not take place until the pixels are written to. The actual behavior depends on the platform implementation of calloc().
- Parameters:
imageInfo- contains width, height, ColorAlphaType, ColorType, ColorSpacezeroPixels- whether pixels should be zeroed- Returns:
- true if pixels allocation is successful
-
allocPixels
public boolean allocPixels(@NotNull @NotNull ImageInfo info, long rowBytes)Sets ImageInfo to info following the rules in setImageInfo() and allocates pixel memory. rowBytes must equal or exceed info.width() times info.bytesPerPixel(), or equal zero.
Returns false and calls reset() if ImageInfo could not be set, or memory could not be allocated.
On most platforms, allocating pixel memory may succeed even though there is not sufficient memory to hold pixels; allocation does not take place until the pixels are written to. The actual behavior depends on the platform implementation of malloc().
- Parameters:
info- contains width, height, ColorAlphaType, ColorType, ColorSpacerowBytes- size of pixel row or larger; may be zero- Returns:
- true if pixel storage is allocated
-
allocPixels
public boolean allocPixels(@NotNull @NotNull ImageInfo imageInfo)Sets ImageInfo to info following the rules in
setImageInfo(ImageInfo, long)and allocates pixel memory.Returns false and calls reset() if ImageInfo could not be set, or memory could not be allocated.
On most platforms, allocating pixel memory may succeed even though there is not sufficient memory to hold pixels; allocation does not take place until the pixels are written to. The actual behavior depends on the platform implementation of malloc().
- Parameters:
imageInfo- contains width, height, ColorAlphaType, ColorType, ColorSpace- Returns:
- true if pixel storage is allocated
- See Also:
- https://fiddle.skia.org/c/@Bitmap_allocPixels_2
-
allocN32Pixels
public boolean allocN32Pixels(int width, int height)Sets ImageInfo to width, height, and native color type; and allocates pixel memory. Sets ImageInfo toColorAlphaType.PREMUL. Calls reset() and returns false if width exceeds 29 bits or is negative, or height is negative. Returns false if allocation fails. Use to create Bitmap that matches the native pixel arrangement on the platform. Bitmap drawn to output device skips converting its pixel format.- Parameters:
width- pixel column count; must be zero or greaterheight- pixel row count; must be zero or greater- Returns:
- true if pixel storage is allocated
-
allocN32Pixels
public boolean allocN32Pixels(int width, int height, boolean opaque)Sets ImageInfo to width, height, and native color type; and allocates pixel memory. If opaque is true, sets ImageInfo toColorAlphaType.OPAQUE; otherwise, sets toColorAlphaType.PREMUL. Calls reset() and returns false if width exceeds 29 bits or is negative, or height is negative. Returns false if allocation fails. Use to create Bitmap that matches the native pixel arrangement on the platform. Bitmap drawn to output device skips converting its pixel format.- Parameters:
width- pixel column count; must be zero or greaterheight- pixel row count; must be zero or greateropaque- true if pixels do not have transparency- Returns:
- true if pixel storage is allocated
-
installPixels
public boolean installPixels(byte[] pixels)
-
installPixels
public boolean installPixels(@NotNull @NotNull ImageInfo info, @Nullable @org.jetbrains.annotations.Nullable byte[] pixels, long rowBytes)Sets ImageInfo to info following the rules in setImageInfo(), and creates PixelRef containing pixels and rowBytes.
If ImageInfo could not be set, or rowBytes is less than info.getMinRowBytes(): calls reset(), and returns false.
- Parameters:
info- contains width, height, SkAlphaType, SkColorType, SkColorSpacepixels- pixel storagerowBytes- size of pixel row or larger- Returns:
- true if ImageInfo is set to info
-
allocPixels
public boolean allocPixels()
Allocates pixel memory with HeapAllocator, and replaces existing PixelRef. The allocation size is determined by ImageInfo width, height, and ColorType.
Returns false if info().colorType() is
ColorType.UNKNOWN, or allocation fails.- Returns:
- true if the allocation succeeds
-
getPixelRef
@Nullable public @Nullable PixelRef getPixelRef()
Returns PixelRef, which contains: pixel base address; its dimensions; and rowBytes(), the interval from one row to the next. PixelRef may be shared by multiple bitmaps. If PixelRef has not been set, returns null.- Returns:
- SkPixelRef, or null
-
getPixelRefOrigin
@NotNull public @NotNull io.github.humbleui.types.IPoint getPixelRefOrigin()
Returns origin of pixels within PixelRef. Bitmap bounds is always contained by PixelRef bounds, which may be the same size or larger. Multiple Bitmap can share the same PixelRef, where each Bitmap has different bounds.
The returned origin added to Bitmap dimensions equals or is smaller than the PixelRef dimensions.
Returns (0, 0) if PixelRef is nullptr.
- Returns:
- pixel origin within PixelRef
- See Also:
- https://fiddle.skia.org/c/@Bitmap_pixelRefOrigin
-
setPixelRef
@NotNull @Contract("_, _, _ -> this") public @NotNull Bitmap setPixelRef(@Nullable @Nullable PixelRef pixelRef, int dx, int dy)Replaces pixelRef and origin in Bitmap. dx and dy specify the offset within the PixelRef pixels for the top-left corner of the bitmap.
Asserts in debug builds if dx or dy are out of range. Pins dx and dy to legal range in release builds.
The caller is responsible for ensuring that the pixels match the ColorType and ColorAlphaType in ImageInfo.
- Parameters:
pixelRef- PixelRef describing pixel address and rowBytes()dx- column offset in PixelRef for bitmap origindy- row offset in PixelRef for bitmap origin- See Also:
- https://fiddle.skia.org/c/@Bitmap_setPixelRef
-
isReadyToDraw
public boolean isReadyToDraw()
Returns true if Bitmap can be drawn.- Returns:
- true if getPixels() is not null
-
getGenerationId
public int getGenerationId()
Returns a unique value corresponding to the pixels in PixelRef. Returns a different value after notifyPixelsChanged() has been called. Returns zero if PixelRef is null.
Determines if pixels have changed since last examined.
- Returns:
- unique value for pixels in PixelRef
- See Also:
- https://fiddle.skia.org/c/@Bitmap_getGenerationID
-
notifyPixelsChanged
@NotNull @Contract("-> this") public @NotNull Bitmap notifyPixelsChanged()Marks that pixels in PixelRef have changed. Subsequent calls to getGenerationId() return a different value.
-
erase
@NotNull @Contract("_ -> this") public @NotNull Bitmap erase(@NotNull @NotNull Color4f color)Replaces pixel values with color, interpreted as being in the sRGB. All pixels contained by getBounds() are affected. If the getColorType() isColorType.GRAY_8orColorType.RGB_565, then alpha is ignored; RGB is treated as opaque. If getColorType() isColorType.ALPHA_8, then RGB is ignored.- Parameters:
color- unpremultiplied color- Returns:
- this
- See Also:
- https://fiddle.skia.org/c/@Bitmap_eraseColor
-
erase
@NotNull @Contract("_, _ -> this") public @NotNull Bitmap erase(@NotNull @NotNull Color4f color, @NotNull @NotNull io.github.humbleui.types.IRect area)Replaces pixel values with color, interpreted as being in the sRGB. All pixels contained by getBounds() are affected. If the getColorType() isColorType.GRAY_8orColorType.RGB_565, then alpha is ignored; RGB is treated as opaque. If getColorType() isColorType.ALPHA_8, then RGB is ignored.- Parameters:
color- unpremultiplied colorarea- rectangle to fill- Returns:
- this
- See Also:
- https://fiddle.skia.org/c/@Bitmap_erase
-
erase
@NotNull @Contract("_ -> this") public @NotNull Bitmap erase(int color)Replaces pixel values with color, interpreted as being in the sRGB ColorSpace. All pixels contained by getBounds() are affected. If the getColorType() isColorType.GRAY_8orColorType.RGB_565, then alpha is ignored; RGB is treated as opaque. If getColorType() isColorType.ALPHA_8, then RGB is ignored.- Parameters:
color- unpremultiplied color- Returns:
- this
- See Also:
- https://fiddle.skia.org/c/@Bitmap_eraseColor
-
erase
@NotNull @Contract("_, _ -> this") public @NotNull Bitmap erase(int color, @NotNull @NotNull io.github.humbleui.types.IRect area)Replaces pixel values inside area with color, interpreted as being in the sRGB ColorSpace. If area does not intersect getBounds(), call has no effect. If the getColorType() isColorType.GRAY_8orColorType.RGB_565, then alpha is ignored; RGB is treated as opaque. If getColorType() isColorType.ALPHA_8, then RGB is ignored.- Parameters:
color- unpremultiplied colorarea- rectangle to fill- Returns:
- this
- See Also:
- https://fiddle.skia.org/c/@Bitmap_erase
-
getColor
public int getColor(int x, int y)Returns pixel at (x, y) as unpremultiplied color. Returns black with alpha if ColorType is
ColorType.ALPHA_8.Input is not validated: out of bounds values of x or y returns undefined values or may crash if. Fails if ColorType is
ColorType.UNKNOWNor pixel address is nullptr.ColorSpace in ImageInfo is ignored. Some color precision may be lost in the conversion to unpremultiplied color; original pixel data may have additional precision.
- Parameters:
x- column index, zero or greater, and less than getWidth()y- row index, zero or greater, and less than getHeight()- Returns:
- pixel converted to unpremultiplied color
-
getColor4f
public Color4f getColor4f(int x, int y)
Returns pixel at (x, y) as unpremultiplied color. Returns black with alpha if ColorType is
ColorType.ALPHA_8.Input is not validated: out of bounds values of x or y returns undefined values or may crash if. Fails if ColorType is
ColorType.UNKNOWNor pixel address is nullptr.ColorSpace in ImageInfo is ignored. Some color precision may be lost in the conversion to unpremultiplied color; original pixel data may have additional precision.
- Parameters:
x- column index, zero or greater, and less than getWidth()y- row index, zero or greater, and less than getHeight()- Returns:
- pixel converted to unpremultiplied color
-
getAlphaf
public float getAlphaf(int x, int y)Look up the pixel at (x,y) and return its alpha component, normalized to [0..1]. This is roughly equivalent to GetColorA(getColor()), but can be more efficent (and more precise if the pixels store more than 8 bits per component).
- Parameters:
x- column index, zero or greater, and less than getWidth()y- row index, zero or greater, and less than getHeight()- Returns:
- alpha converted to normalized float
-
extractSubset
public boolean extractSubset(@NotNull @NotNull Bitmap dst, @NotNull @NotNull io.github.humbleui.types.IRect subset)Shares PixelRef with dst. Pixels are not copied; this and dst point to the same pixels; dst.getBounds() are set to the intersection of subset and the original getBounds().
subset may be larger than getBounds(). Any area outside of getBounds() is ignored.
Any contents of dst are discarded. isVolatile() setting is copied to dst. dst is set to getColorType(), getAlphaType(), and getColorSpace().
Return false if:
- dst is null
- PixelRef is null
- subset does not intersect getBounds()
- Parameters:
dst- Bitmap set to subsetsubset- rectangle of pixels to reference- Returns:
- true if dst is replaced by subset
- See Also:
- https://fiddle.skia.org/c/@Bitmap_extractSubset
-
readPixels
@Nullable public @org.jetbrains.annotations.Nullable byte[] readPixels()
-
readPixels
@Nullable public @org.jetbrains.annotations.Nullable byte[] readPixels(@NotNull @NotNull ImageInfo dstInfo, long dstRowBytes, int srcX, int srcY)Copies a rect of pixels from Bitmap. Copy starts at (srcX, srcY), and does not exceed Bitmap (getWidth(), getHeight()).
dstInfo specifies width, height, ColorType, AlphaType, and ColorSpace of destination. dstRowBytes specifics the gap from one destination row to the next. Returns true if pixels are copied. Returns false if:
- dstRowBytes is less than dstInfo.getMinRowBytes()
- PixelRef is null
Pixels are copied only if pixel conversion is possible. If Bitmap getColorType() is
ColorType.GRAY_8, orColorType.ALPHA_8; dstInfo.colorType() must match. If Bitmap getClorType() isColorType.GRAY_8, dstInfo.getColorSpace() must match. If Bitmap getAlphaType() isColorAlphaType.OPAQUE, dstInfo.getAlphaType() must match. If Bitmap getColorSpace() is null, dstInfo.getColorSpace() must match. Returns false if pixel conversion is not possible.srcX and srcY may be negative to copy only top or left of source. Returns false if getWidth() or getHeight() is zero or negative. Returns false if abs(srcX) >= getWidth(), or if abs(srcY) >= getHeight().
- Parameters:
dstInfo- destination width, height, ColorType, AlphaType, ColorSpacedstRowBytes- destination row lengthsrcX- column index whose absolute value is less than width()srcY- row index whose absolute value is less than height()- Returns:
- pixel data or null
-
extractAlpha
public boolean extractAlpha(@NotNull @NotNull Bitmap dst)Sets dst to alpha described by pixels. Returns false if dst cannot be written to or dst pixels cannot be allocated.
- Parameters:
dst- holds PixelRef to fill with alpha layer- Returns:
- true if alpha layer was not constructed in dst PixelRef
-
extractAlpha
@Nullable public @Nullable io.github.humbleui.types.IPoint extractAlpha(@NotNull @NotNull Bitmap dst, @Nullable @Nullable Paint paint)Sets dst to alpha described by pixels. Returns false if dst cannot be written to or dst pixels cannot be allocated.
If paint is not null and contains MaskFilter, MaskFilter generates mask alpha from Bitmap. Returns offset to top-left position for dst for alignment with Bitmap; (0, 0) unless MaskFilter generates mask.
- Parameters:
dst- holds PixelRef to fill with alpha layerpaint- holds optional MaskFilter; may be null- Returns:
- null if alpha layer was not constructed in dst PixelRef, IPoint otherwise
-
peekPixels
@Nullable public @Nullable java.nio.ByteBuffer peekPixels()
If pixel address is available, return ByteBuffer wrapping it. If pixel address is not available, return null.- Returns:
- ByteBuffer with direct access to pixels, or null
- See Also:
- https://fiddle.skia.org/c/@Bitmap_peekPixels
-
makeShader
@NotNull public @NotNull Shader makeShader()
-
makeShader
@NotNull public @NotNull Shader makeShader(@NotNull @NotNull FilterTileMode tm)
-
makeShader
@NotNull public @NotNull Shader makeShader(@NotNull @NotNull FilterTileMode tmx, @NotNull @NotNull FilterTileMode tmy)
-
makeShader
@NotNull public @NotNull Shader makeShader(@NotNull @NotNull FilterTileMode tmx, @NotNull @NotNull FilterTileMode tmy, @Nullable @Nullable Matrix33 localMatrix)
-
makeShader
@NotNull public @NotNull Shader makeShader(@NotNull @NotNull FilterTileMode tmx, @NotNull @NotNull FilterTileMode tmy, @NotNull @NotNull SamplingMode sampling, @Nullable @Nullable Matrix33 localMatrix)
-
_nGetFinalizer
@Internal public static long _nGetFinalizer()
-
_nMake
@Internal public static long _nMake()
-
_nMakeClone
@Internal public static long _nMakeClone(long ptr)
-
_nSwap
@Internal public static void _nSwap(long ptr, long otherPtr)
-
_nGetPixmap
@Internal public static long _nGetPixmap(long ptr)
-
_nGetImageInfo
@Internal public static ImageInfo _nGetImageInfo(long ptr)
-
_nGetRowBytesAsPixels
@Internal public static int _nGetRowBytesAsPixels(long ptr)
-
_nIsNull
@Internal public static boolean _nIsNull(long ptr)
-
_nGetRowBytes
@Internal public static long _nGetRowBytes(long ptr)
-
_nSetAlphaType
@Internal public static boolean _nSetAlphaType(long ptr, int alphaType)
-
_nComputeByteSize
@Internal public static long _nComputeByteSize(long ptr)
-
_nIsImmutable
@Internal public static boolean _nIsImmutable(long ptr)
-
_nSetImmutable
@Internal public static void _nSetImmutable(long ptr)
-
_nIsVolatile
@Internal public static boolean _nIsVolatile(long ptr)
-
_nSetVolatile
@Internal public static void _nSetVolatile(long ptr, boolean value)
-
_nReset
@Internal public static void _nReset(long ptr)
-
_nComputeIsOpaque
@Internal public static boolean _nComputeIsOpaque(long ptr)
-
_nSetImageInfo
@Internal public static boolean _nSetImageInfo(long ptr, int width, int height, int colorType, int alphaType, long colorSpacePtr, long rowBytes)
-
_nAllocPixelsFlags
@Internal public static boolean _nAllocPixelsFlags(long ptr, int width, int height, int colorType, int alphaType, long colorSpacePtr, int flags)
-
_nAllocPixelsRowBytes
@Internal public static boolean _nAllocPixelsRowBytes(long ptr, int width, int height, int colorType, int alphaType, long colorSpacePtr, long rowBytes)
-
_nInstallPixels
@Internal public static boolean _nInstallPixels(long ptr, int width, int height, int colorType, int alphaType, long colorSpacePtr, byte[] pixels, long rowBytes)
-
_nAllocPixels
@Internal public static boolean _nAllocPixels(long ptr)
-
_nGetPixelRef
@Internal public static long _nGetPixelRef(long ptr)
-
_nGetPixelRefOrigin
@Internal public static long _nGetPixelRefOrigin(long ptr)
-
_nSetPixelRef
@Internal public static void _nSetPixelRef(long ptr, long pixelRefPtr, int dx, int dy)
-
_nIsReadyToDraw
@Internal public static boolean _nIsReadyToDraw(long ptr)
-
_nGetGenerationId
@Internal public static int _nGetGenerationId(long ptr)
-
_nNotifyPixelsChanged
@Internal public static void _nNotifyPixelsChanged(long ptr)
-
_nErase4f
@Internal public static void _nErase4f(long ptr, float r, float g, float b, float a)
-
_nEraseRect4f
@Internal public static void _nEraseRect4f(long ptr, float r, float g, float b, float a, int left, int top, int right, int bottom)
-
_nErase
@Internal public static void _nErase(long ptr, int color)
-
_nEraseRect
@Internal public static void _nEraseRect(long ptr, int color, int left, int top, int right, int bottom)
-
_nGetColor
@Internal public static int _nGetColor(long ptr, int x, int y)
-
_nGetColor4f
@Internal public static Color4f _nGetColor4f(long ptr, int x, int y)
-
_nGetAlphaf
@Internal public static float _nGetAlphaf(long ptr, int x, int y)
-
_nExtractSubset
@Internal public static boolean _nExtractSubset(long ptr, long dstPtr, int left, int top, int right, int bottom)
-
_nReadPixels
@Internal public static byte[] _nReadPixels(long ptr, int width, int height, int colorType, int alphaType, long colorSpacePtr, long dstRowBytes, int srcX, int srcY)
-
_nExtractAlpha
@Internal public static io.github.humbleui.types.IPoint _nExtractAlpha(long ptr, long dstPtr, long paintPtr)
-
_nPeekPixels
@Internal public static java.nio.ByteBuffer _nPeekPixels(long ptr)
-
_nMakeShader
@Internal public static long _nMakeShader(long ptr, int tmx, int tmy, long samplingMode, float[] localMatrix)
-
-