| 7 | import io.github.humbleui.types.*; |
| 8 | |
| 9 | public class Bitmap extends Managed implements IHasImageInfo { |
| 10 | static { Library.staticLoad(); } |
| 11 | |
| 12 | @ApiStatus.Internal |
| 13 | public ImageInfo _imageInfo = null; |
| 14 | |
| 15 | @ApiStatus.Internal |
| 16 | public Bitmap(long ptr) { |
| 17 | super(ptr, _FinalizerHolder.PTR); |
| 18 | } |
| 19 | |
| 20 | /** |
| 21 | * Creates an empty Bitmap without pixels, with {@link ColorType#UNKNOWN}, |
| 22 | * {@link ColorAlphaType#UNKNOWN}, and with a width and height of zero. |
| 23 | * PixelRef origin is set to (0, 0). Bitmap is not volatile. |
| 24 | * |
| 25 | * Use {@link #setImageInfo(ImageInfo, long)} to associate ColorType, ColorAlphaType, width, and height after Bitmap has been created. |
| 26 | * |
| 27 | * @see <a href="https://fiddle.skia.org/c/@Bitmap_empty_constructor">https://fiddle.skia.org/c/@Bitmap_empty_constructor</a> |
| 28 | */ |
| 29 | public Bitmap() { |
| 30 | this(_nMake()); |
| 31 | Stats.onNativeCall(); |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Copies settings from src to returned Bitmap. Shares pixels if src has pixels |
| 36 | * allocated, so both bitmaps reference the same pixels. |
| 37 | * |
| 38 | * @return copy of src |
| 39 | * |
| 40 | * @see <a href="https://fiddle.skia.org/c/@Bitmap_copy_const_SkBitmap">https://fiddle.skia.org/c/@Bitmap_copy_const_SkBitmap</a> |
| 41 | */ |
| 42 | @NotNull @Contract("-> new") |
| 43 | public Bitmap makeClone() { |
| 44 | try { |
| 45 | Stats.onNativeCall(); |
| 46 | return new Bitmap(_nMakeClone(_ptr)); |
| 47 | } finally { |
| 48 | ReferenceUtil.reachabilityFence(this); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | @NotNull @Contract("-> new") |
| 53 | public static Bitmap makeFromImage(@NotNull Image image) { |
| 54 | assert image != null : "Can’t makeFromImage with image == null"; |
| 55 | Bitmap bitmap = new Bitmap(); |
| 56 | bitmap.allocPixels(image.getImageInfo()); |
| 57 | if (image.readPixels(bitmap)) |
| 58 | return bitmap; |
| 59 | else { |
| 60 | bitmap.close(); |
| 61 | throw new RuntimeException("Failed to readPixels from " + image); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Swaps the fields of the two bitmaps. |
nothing calls this directly
no test coverage detected