diff --git a/build/includes.r b/build/includes.r index df1a093ac1..d708d5fcb9 100644 --- a/build/includes.r +++ b/build/includes.r @@ -101,7 +101,7 @@ write %build/bin/sources.r set-cache [ %tools.reds %unicode.reds %utils.reds - %image-crop.reds + %image-utils.reds %vector2d.reds %datatypes/ [ %action.reds diff --git a/runtime/datatypes/image.reds b/runtime/datatypes/image.reds index 6bc4bc17c8..f7812478f2 100644 --- a/runtime/datatypes/image.reds +++ b/runtime/datatypes/image.reds @@ -10,7 +10,7 @@ Red/System [ } ] -#include %../image-crop.reds +#include %../image-utils.reds image: context [ verbose: 0 @@ -126,7 +126,7 @@ image: context [ h [integer!] w1 [integer!] h1 [integer!] - vertex [CROP-VERTEX! value] + vertex [TRANS-VERTEX! value] pos [red-pair!] vec1 [VECTOR2D! value] vec2 [VECTOR2D! value] @@ -224,22 +224,22 @@ image: context [ neg-y?: no if vertex/v1x > vertex/v2x [ neg-x?: yes - image-crop/flip-x vertex vertex/v1x + image-utils/flip-x vertex vertex/v1x ] if vertex/v2y > vertex/v3y [ neg-y?: yes - image-crop/flip-y vertex vertex/v1y + image-utils/flip-y vertex vertex/v1y ] handle: 0 buf: acquire-buffer src :handle either crop1 <> null [ pb: allocate crop.w * crop.h * 4 - image-crop/crop as byte-ptr! buf w h crop.x crop.y crop.w crop.h pb - nbuf: image-crop/transform as int-ptr! pb crop.w crop.h vertex rect.x rect.y rect.w rect.h + image-utils/crop as byte-ptr! buf w h crop.x crop.y crop.w crop.h pb + nbuf: image-utils/transform as int-ptr! pb crop.w crop.h vertex rect.x rect.y rect.w rect.h free pb ][ - nbuf: image-crop/transform buf w h vertex rect.x rect.y rect.w rect.h + nbuf: image-utils/transform buf w h vertex rect.x rect.y rect.w rect.h ] release-buffer src handle no if null? nbuf [dst/header: TYPE_NONE exit] @@ -247,13 +247,14 @@ image: context [ handle2: 0 buf2: acquire-buffer dst :handle2 copy-memory as byte-ptr! buf2 as byte-ptr! nbuf rect.w/1 * rect.h/1 * 4 + release-buffer dst handle2 yes + free as byte-ptr! nbuf if neg-x? [ rect.w/1: 0 - rect.w/1 ] if neg-y? [ rect.h/1: 0 - rect.h/1 ] - release-buffer dst handle2 yes ] load-binary: func [ diff --git a/runtime/image-crop.reds b/runtime/image-utils.reds similarity index 93% rename from runtime/image-crop.reds rename to runtime/image-utils.reds index fb44104196..14fabb4b88 100644 --- a/runtime/image-crop.reds +++ b/runtime/image-utils.reds @@ -1,7 +1,7 @@ Red/System [ - Title: "image-crop" + Title: "image utils" Author: "bitbegin" - File: %image-crop.reds + File: %image-utils.reds Note: "useful functions for image!" Tabs: 4 Rights: "Copyright (C) 2020 Red Foundation. All rights reserved." @@ -13,7 +13,7 @@ Red/System [ #include %vector2d.reds -CROP-VERTEX!: alias struct! [ +TRANS-VERTEX!: alias struct! [ v1x [float32!] v1y [float32!] v2x [float32!] @@ -27,10 +27,10 @@ CROP-VERTEX!: alias struct! [ float32-max: as float32! 3.40282347E+38 float32-min: as float32! -3.40282347E+38 -image-crop: context [ +image-utils: context [ flip-x: func [ - vertex [CROP-VERTEX!] + vertex [TRANS-VERTEX!] x0 [float32!] /local p [pointer! [float32!]] @@ -45,7 +45,7 @@ image-crop: context [ ] flip-y: func [ - vertex [CROP-VERTEX!] + vertex [TRANS-VERTEX!] y0 [float32!] /local p [pointer! [float32!]] @@ -61,7 +61,7 @@ image-crop: context [ ] on-plane?: func [ - vertex [CROP-VERTEX!] + vertex [TRANS-VERTEX!] x [float32!] y [float32!] return: [logic!] @@ -77,17 +77,17 @@ image-crop: context [ crop: func [ src [byte-ptr!] - sw [integer!] ;-- width - sh [integer!] ;-- height + sw [integer!] ;-- src width + sh [integer!] ;-- src height x [integer!] ;-- start.x y [integer!] ;-- start.y - dw [integer!] ;-- width - dh [integer!] ;-- height + dw [integer!] ;-- dst width + dh [integer!] ;-- dst height dst [byte-ptr!] return: [logic!] /local - ss [integer!] ;-- stride - ds [integer!] ;-- stride + ss [integer!] ;-- src stride + ds [integer!] ;-- dst stride offset [integer!] from [byte-ptr!] to [byte-ptr!] @@ -121,13 +121,13 @@ image-crop: context [ transform: func [ src [int-ptr!] - sw [integer!] ;-- width - sh [integer!] ;-- height - vertex [CROP-VERTEX!] + sw [integer!] ;-- src width + sh [integer!] ;-- src height + vertex [TRANS-VERTEX!] dx [int-ptr!] dy [int-ptr!] - dw [int-ptr!] ;-- width - dh [int-ptr!] ;-- height + dw [int-ptr!] ;-- dst width + dh [int-ptr!] ;-- dst height return: [int-ptr!] /local xmin [float32!] @@ -339,7 +339,7 @@ image-crop: context [ dh [integer!] ;-- height return: [int-ptr!] /local - vertex [CROP-VERTEX! value] + vertex [TRANS-VERTEX! value] w [integer!] h [integer!] x [integer!]