scoop:scoop.graphics:0.1.0
src/drawing/raster.scoop
Selected production source · src/drawing/raster.scoop
1
package scoop.graphics3
import scoop.graphics.native.RenderTarget5
/** A CPU surface usable without an Application or GPU. */6
public class RasterSurface public constructor(7
public val width: Int,8
public val height: Int9
): Closeable {10
private val target: RenderTarget = createRaster(width, height)11
public val isClosed: Boolean get() = target.isClosed12
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
}18
}20
private fun createRaster(width: Int, height: Int): RenderTarget {21
pixelBytes(width, height)22
@Unsafe23
{24
return RenderTarget(25
ownedGraphics(rasterCreate(width, height), "create raster surface"),26
width,27
height,28
1.029
)30
}31
}33
@Extern(name = "scoop_graphics_raster_create")34
private fun rasterCreate(width: Int, height: Int): Ptr<Unit>?