Scoop API

scoop:scoop.graphics:0.1.0

src/drawing/raster.scoop

Selected production source · src/drawing/raster.scoop

1package scoop.graphics
3import scoop.graphics.native.RenderTarget
5/** A CPU surface usable without an Application or GPU. */
6public class RasterSurface public constructor(
7 public val width: Int,
8 public val height: Int
9): Closeable {
10 private val target: RenderTarget = createRaster(width, height)
11 public val isClosed: Boolean get() = target.isClosed
12 public fun <T> draw(block: (Canvas) -> T): T = target.draw(block)
13 public fun readPixels(): Array<Byte> = target.readPixels()
14 public fun snapshot(): Image = target.snapshot()
15 public override fun close() {
16 target.close()
17 }
20private fun createRaster(width: Int, height: Int): RenderTarget {
21 pixelBytes(width, height)
22 @Unsafe
23 {
24 return RenderTarget(
25 ownedGraphics(rasterCreate(width, height), "create raster surface"),
26 width,
27 height,
28 1.0
29 )
30 }
33@Extern(name = "scoop_graphics_raster_create")
34private fun rasterCreate(width: Int, height: Int): Ptr<Unit>?