[orx-compute-graph] Add compute graph code
This commit is contained in:
27
orx-compute-graph-nodes/src/commonMain/kotlin/FilterNode.kt
Normal file
27
orx-compute-graph-nodes/src/commonMain/kotlin/FilterNode.kt
Normal file
@@ -0,0 +1,27 @@
|
||||
package org.openrndr.extra.computegraph.nodes
|
||||
|
||||
import org.openrndr.draw.ColorBuffer
|
||||
import org.openrndr.draw.Filter
|
||||
import org.openrndr.draw.createEquivalent
|
||||
import org.openrndr.extra.computegraph.ComputeGraph
|
||||
import org.openrndr.extra.computegraph.ComputeNode
|
||||
import org.openrndr.extra.computegraph.withKey
|
||||
|
||||
fun <T : Filter> ComputeGraph.filterNode(
|
||||
filter: T, input: ComputeNode, inputKey: String = "image", outputKey: String = "image",
|
||||
config: ComputeNode.(f: Filter) -> Unit
|
||||
): ComputeNode {
|
||||
return node {
|
||||
name = "filter-${filter::class.simpleName}"
|
||||
inputs = filter.parameters
|
||||
config(filter)
|
||||
val inputImage by input.outputs.withKey<ColorBuffer>(inputKey)
|
||||
var outputImage by outputs.withKey<ColorBuffer>(outputKey)
|
||||
outputImage = inputImage.createEquivalent()
|
||||
compute {
|
||||
filter.apply(inputImage, outputImage)
|
||||
}
|
||||
dependOn(input)
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package org.openrndr.extra.computegraph.nodes
|
||||
|
||||
import org.openrndr.Program
|
||||
import org.openrndr.draw.ColorBuffer
|
||||
import org.openrndr.draw.isolatedWithTarget
|
||||
import org.openrndr.draw.renderTarget
|
||||
import org.openrndr.extra.computegraph.ComputeGraph
|
||||
import org.openrndr.extra.computegraph.ComputeNode
|
||||
import org.openrndr.extra.computegraph.withKey
|
||||
import org.openrndr.extras.imageFit.imageFit
|
||||
|
||||
fun ComputeGraph.fitImageNode(program: Program, input: ComputeNode) : ComputeNode {
|
||||
return node {
|
||||
name = "fit-image"
|
||||
val rt = renderTarget(program.width, program.height) {
|
||||
colorBuffer()
|
||||
}
|
||||
val inputImage: ColorBuffer by input.outputs.withKey("image")
|
||||
var outputImage:ColorBuffer by outputs.withKey("image")
|
||||
outputImage = rt.colorBuffer(0)
|
||||
compute {
|
||||
program.drawer.isolatedWithTarget(rt) {
|
||||
ortho(rt)
|
||||
imageFit(inputImage, bounds)
|
||||
}
|
||||
}
|
||||
dependOn(input)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user