-
Notifications
You must be signed in to change notification settings - Fork 4
/
ExternalInpaintPlugin.bas
executable file
·87 lines (76 loc) · 2.2 KB
/
ExternalInpaintPlugin.bas
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
B4J=true
Group=Default Group
ModulesStructureVersion=1
Type=Class
Version=4.2
@EndOfDesignText@
Sub Class_Globals
Private fx As JFX
End Sub
'Initializes the object. You can NOT add parameters to this method!
Public Sub Initialize() As String
Log("Initializing plugin " & GetNiceName)
' Here return a key to prevent running unauthorized plugins
Return "MyKey"
End Sub
' must be available
public Sub GetNiceName() As String
Return "ExternalInpaint"
End Sub
' must be available
public Sub Run(Tag As String, Params As Map) As ResumableSub
Log("run"&Params)
Select Tag
Case "getParams"
Dim paramsList As List
paramsList.Initialize
paramsList.Add("url")
Return paramsList
Case "inpaint"
wait for (inpaint(Params.Get("origin"),Params.Get("mask"),Params.GetDefault("settings",getDefaultSettings))) complete (result As B4XBitmap)
Return result
Case "getDefaultParamValues"
Return getDefaultSettings
End Select
Return ""
End Sub
Private Sub getDefaultSettings As Map
Return CreateMap("url":"http://127.0.0.1:8080/gettxtremoved")
End Sub
Sub inpaint(origin As B4XBitmap,mask As B4XBitmap,settings As Map) As ResumableSub
Dim out As OutputStream
out=File.OpenOutput(File.DirApp,"origin.jpg",False)
origin.WriteToStream(out,"100","JPEG")
out.Close
Dim out As OutputStream
out=File.OpenOutput(File.DirApp,"mask.png",False)
mask.WriteToStream(out,"100","PNG")
out.Close
Dim job As HttpJob
job.Initialize("",Me)
Dim originFd As MultipartFileData
originFd.Initialize
originFd.KeyName = "origin"
originFd.Dir = File.DirApp
originFd.FileName = "origin.jpg"
originFd.ContentType = "image/jpg"
Dim maskFd As MultipartFileData
maskFd.Initialize
maskFd.KeyName = "mask"
maskFd.Dir = File.DirApp
maskFd.FileName = "mask.png"
maskFd.ContentType = "image/png"
job.PostMultipart(settings.GetDefault("url","http://127.0.0.1:8080/gettxtremoved"),Null, Array(originFd,maskFd))
job.GetRequest.Timeout=240*1000
Wait For (job) JobDone(job As HttpJob)
If job.Success Then
Try
Dim result As B4XBitmap=job.GetBitmap
Return result
Catch
Log(LastException)
End Try
End If
job.Release
Return origin
End Sub