diff options
| author | Naveen Michaud-Agrawal <naveen.michaudagrawal@gmail.com> | 2024-05-22 23:33:15 +0000 |
|---|---|---|
| committer | Naveen Michaud-Agrawal <naveen.michaudagrawal@gmail.com> | 2024-05-22 23:45:38 +0000 |
| commit | 5a95e4de1e305eb9ef2cf38d8f658fb2da028ecc (patch) | |
| tree | a589cbd75567061d0b43add40da1391b63d87aa9 /virtual-programs | |
| parent | Merge pull request #139 from FolkComputer/osnr/cleanup (diff) | |
| download | folk-5a95e4de1e305eb9ef2cf38d8f658fb2da028ecc.tar.gz folk-5a95e4de1e305eb9ef2cf38d8f658fb2da028ecc.zip | |
Crop images in image space (between 0 - 1)
Diffstat (limited to 'virtual-programs')
| -rw-r--r-- | virtual-programs/display/image.folk | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/virtual-programs/display/image.folk b/virtual-programs/display/image.folk index b654f846..b42ff12d 100644 --- a/virtual-programs/display/image.folk +++ b/virtual-programs/display/image.folk @@ -3,7 +3,7 @@ On process "display" { set rotate $::rotate # TODO: Do this with a wish, instead of hard-coding the global dict. dict set ::pipelines "image" [Gpu::pipeline {sampler2D image vec2 imageSize - vec2 pos float radians vec2 scale + vec2 pos float radians vec2 scale vec4 crop fn rotate} { vec2 a = pos + rotate(scale*-imageSize/2, -radians); vec2 b = pos + rotate(scale*vec2(imageSize.x, -imageSize.y)/2, -radians); @@ -19,7 +19,10 @@ On process "display" { vec2 p = gl_FragCoord.xy; vec2 uv = invBilinear(p, a, b, c, d); if( max( abs(uv.x-0.5), abs(uv.y-0.5))<0.5 ) { - return texture(image, uv); + if ((crop[0] < uv.x) && (uv.x < crop[2]) && + (crop[1] < uv.y) && (uv.y < crop[3])) { + return texture(image, uv); + } } return vec4(0.0, 0.0, 0.0, 0.0); }] @@ -108,6 +111,7 @@ On process "display" { set im [dict get $options image] set radians [dict get $options radians] set scale [dict_getdef $options scale 1.0] + set crop [dict_getdef $options crop [list 0. 0. 1.0 1.0]] if {[llength $scale] == 1} { set scale [list $scale $scale] } @@ -116,6 +120,6 @@ On process "display" { Wish the GPU draws pipeline "image" with arguments \ [list $gim [list [image_t width $im] [image_t height $im]] \ - $center $radians $scale] + $center $radians $scale $crop] } } |
