forked from mudler/go-stable-diffusion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstablediffusion.go
39 lines (32 loc) · 1.3 KB
/
stablediffusion.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
package stablediffusion
// #cgo CXXFLAGS: -I${SRCDIR}/ -I${SRCDIR}/ncnn/src -I${SRCDIR}/ncnn -I${SRCDIR}/ncnn/build/src/ -I${SRCDIR}/stable-diffusion/x86/vs2019_opencv-mobile_ncnn-dll_demo/vs2019_opencv-mobile_ncnn-dll_demo/ -std=c++17
// #cgo LDFLAGS: -L${SRCDIR}/ -lstablediffusion -lgomp -lopencv_core -lopencv_imgcodecs -lm -lstdc++
// #include "stablediffusion.h"
// #include <stdlib.h>
import "C"
import (
"fmt"
)
func GenerateImage(height, width, mode, step, seed int, positive_prompt, negative_prompt, dst, init_image, asset_dir string) error {
pp := C.CString(positive_prompt)
np := C.CString(negative_prompt)
ii := C.CString(init_image)
ad := C.CString(asset_dir)
destination := C.CString(dst)
ret := C.generate_image(C.int(height), C.int(width), C.int(mode), C.int(step), C.int(seed), pp, np, destination, ii, ad)
if ret != 0 {
return fmt.Errorf("failed")
}
return nil
}
func GenerateImageUpscaled(height, width, step, seed int, positive_prompt, negative_prompt, dst, asset_dir string) error {
pp := C.CString(positive_prompt)
np := C.CString(negative_prompt)
ad := C.CString(asset_dir)
destination := C.CString(dst)
ret := C.generate_image_upscaled(C.int(height), C.int(width), C.int(step), C.int(seed), pp, np, destination, ad)
if ret != 0 {
return fmt.Errorf("failed")
}
return nil
}