-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrotate.go
110 lines (96 loc) · 2.39 KB
/
rotate.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package example
//go:generate go run ./cmd/download/halide.go
/*
#cgo CFLAGS: -I${SRCDIR}/include
#cgo LDFLAGS: -L${SRCDIR}/lib -ldl -lm
#cgo darwin LDFLAGS: -lrotate90_darwin
#cgo darwin LDFLAGS: -lrotate180_darwin
#cgo darwin LDFLAGS: -lrotate270_darwin
#cgo linux LDFLAGS: -lrotate90_linux
#cgo linux LDFLAGS: -lrotate180_linux
#cgo linux LDFLAGS: -lrotate270_linux
#include "rotate90.h"
#include "rotate180.h"
#include "rotate270.h"
*/
import "C"
import (
"fmt"
"image"
_ "github.com/benesch/cgosymbolizer"
)
//go:generate go run ./cmd/compile/object.go f rotate90 rotate.cpp
func Rotate90(in *image.RGBA) (*image.RGBA, error) {
width, height := in.Rect.Dx(), in.Rect.Dy()
out := image.NewRGBA(image.Rect(0, 0, height, width))
outBuf, err := HalideBufferRGBA(out.Pix, height, width)
if err != nil {
return nil, err
}
defer HalideFreeBuffer(outBuf)
inBuf, err := HalideBufferRGBA(in.Pix, width, height)
if err != nil {
return nil, err
}
defer HalideFreeBuffer(inBuf)
ret := C.rotate90(
inBuf,
C.int(width),
C.int(height),
outBuf,
)
if ret != C.int(0) {
return nil, fmt.Errorf("failed to rotate90")
}
return out, nil
}
//go:generate go run ./cmd/compile/object.go f rotate180 rotate.cpp
func Rotate180(in *image.RGBA) (*image.RGBA, error) {
width, height := in.Rect.Dx(), in.Rect.Dy()
out := image.NewRGBA(image.Rect(0, 0, width, height))
outBuf, err := HalideBufferRGBA(out.Pix, width, height)
if err != nil {
return nil, err
}
defer HalideFreeBuffer(outBuf)
inBuf, err := HalideBufferRGBA(in.Pix, width, height)
if err != nil {
return nil, err
}
defer HalideFreeBuffer(inBuf)
ret := C.rotate180(
inBuf,
C.int(width),
C.int(height),
outBuf,
)
if ret != C.int(0) {
return nil, fmt.Errorf("failed to rotate180")
}
return out, nil
}
//go:generate go run ./cmd/compile/object.go f rotate270 rotate.cpp
func Rotate270(in *image.RGBA) (*image.RGBA, error) {
width, height := in.Rect.Dx(), in.Rect.Dy()
out := image.NewRGBA(image.Rect(0, 0, height, width))
outBuf, err := HalideBufferRGBA(out.Pix, height, width)
if err != nil {
return nil, err
}
defer HalideFreeBuffer(outBuf)
inBuf, err := HalideBufferRGBA(in.Pix, width, height)
if err != nil {
return nil, err
}
defer HalideFreeBuffer(inBuf)
ret := C.rotate270(
inBuf,
C.int(width),
C.int(height),
outBuf,
)
if ret != C.int(0) {
return nil, fmt.Errorf("failed to rotate90")
}
return out, nil
}