| 6 | import org.jetbrains.skija.impl.*; |
| 7 | |
| 8 | public class Image extends RefCnt implements IHasImageInfo { |
| 9 | static { Library.staticLoad(); } |
| 10 | |
| 11 | @ApiStatus.Internal |
| 12 | public ImageInfo _imageInfo = null; |
| 13 | |
| 14 | @ApiStatus.Internal |
| 15 | public Image(long ptr) { |
| 16 | super(ptr); |
| 17 | } |
| 18 | |
| 19 | /** |
| 20 | * <p>Creates Image from pixels.</p> |
| 21 | * |
| 22 | * <p>Image is returned if pixels are valid. Valid Pixmap parameters include:</p> |
| 23 | * <ul> |
| 24 | * <li>dimensions are greater than zero;</li> |
| 25 | * <li>each dimension fits in 29 bits;</li> |
| 26 | * <li>ColorType and AlphaType are valid, and ColorType is not ColorType.UNKNOWN;</li> |
| 27 | * <li>row bytes are large enough to hold one row of pixels;</li> |
| 28 | * <li>pixel address is not null.</li> |
| 29 | * </ul> |
| 30 | * |
| 31 | * @param imageInfo ImageInfo |
| 32 | * @param bytes pixels array |
| 33 | * @param rowBytes how many bytes in a row |
| 34 | * @return Image |
| 35 | * |
| 36 | * @see <a href="https://fiddle.skia.org/c/@Image_MakeRasterCopy">https://fiddle.skia.org/c/@Image_MakeRasterCopy</a> |
| 37 | */ |
| 38 | public static Image makeRaster(ImageInfo imageInfo, byte[] bytes, long rowBytes) { |
| 39 | try { |
| 40 | Stats.onNativeCall(); |
| 41 | long ptr = _nMakeRaster(imageInfo._width, |
| 42 | imageInfo._height, |
| 43 | imageInfo._colorInfo._colorType.ordinal(), |
| 44 | imageInfo._colorInfo._alphaType.ordinal(), |
| 45 | Native.getPtr(imageInfo._colorInfo._colorSpace), |
| 46 | bytes, |
| 47 | rowBytes); |
| 48 | if (ptr == 0) |
| 49 | throw new RuntimeException("Failed to makeRaster " + imageInfo + " " + bytes + " " + rowBytes); |
| 50 | return new Image(ptr); |
| 51 | } finally { |
| 52 | Reference.reachabilityFence(imageInfo._colorInfo._colorSpace); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * <p>Creates Image from pixels.</p> |
| 58 | * |
| 59 | * <p>Image is returned if pixels are valid. Valid Pixmap parameters include:</p> |
| 60 | * <ul> |
| 61 | * <li>dimensions are greater than zero;</li> |
| 62 | * <li>each dimension fits in 29 bits;</li> |
| 63 | * <li>ColorType and AlphaType are valid, and ColorType is not ColorType.UNKNOWN;</li> |
| 64 | * <li>row bytes are large enough to hold one row of pixels;</li> |
| 65 | * <li>pixel address is not null.</li> |
no test coverage detected