From 5a95e4de1e305eb9ef2cf38d8f658fb2da028ecc Mon Sep 17 00:00:00 2001 From: Naveen Michaud-Agrawal Date: Wed, 22 May 2024 23:33:15 +0000 Subject: Crop images in image space (between 0 - 1) --- virtual-programs/display/image.folk | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'virtual-programs') 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] } } -- cgit v1.2.3