Skip to content

Commit

Permalink
FIX: better name
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbegin authored and qtxie committed Mar 13, 2020
1 parent c66e4f8 commit 5dba63a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 28 deletions.
2 changes: 1 addition & 1 deletion build/includes.r
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 9 additions & 8 deletions runtime/datatypes/image.reds
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Red/System [
}
]

#include %../image-crop.reds
#include %../image-utils.reds

image: context [
verbose: 0
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -224,36 +224,37 @@ 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]
init-image dst OS-image/make-image rect.w/1 rect.h/1 null null null
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 [
Expand Down
38 changes: 19 additions & 19 deletions runtime/image-crop.reds → runtime/image-utils.reds
Original file line number Diff line number Diff line change
@@ -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."
Expand All @@ -13,7 +13,7 @@ Red/System [

#include %vector2d.reds

CROP-VERTEX!: alias struct! [
TRANS-VERTEX!: alias struct! [
v1x [float32!]
v1y [float32!]
v2x [float32!]
Expand All @@ -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!]]
Expand All @@ -45,7 +45,7 @@ image-crop: context [
]

flip-y: func [
vertex [CROP-VERTEX!]
vertex [TRANS-VERTEX!]
y0 [float32!]
/local
p [pointer! [float32!]]
Expand All @@ -61,7 +61,7 @@ image-crop: context [
]

on-plane?: func [
vertex [CROP-VERTEX!]
vertex [TRANS-VERTEX!]
x [float32!]
y [float32!]
return: [logic!]
Expand All @@ -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!]
Expand Down Expand Up @@ -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!]
Expand Down Expand Up @@ -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!]
Expand Down

0 comments on commit 5dba63a

Please sign in to comment.