-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathExternalMaskGenPlugin.bas
More file actions
executable file
·79 lines (73 loc) · 1.97 KB
/
ExternalMaskGenPlugin.bas
File metadata and controls
executable file
·79 lines (73 loc) · 1.97 KB
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
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 "ExternalMaskGen"
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 "getDefaultParamValues"
Return getDefaultSettings
Case "genMask"
wait for (genMask(Params.Get("img"),Params.GetDefault("settings",getDefaultSettings))) complete (result As B4XBitmap)
Return result
End Select
Return ""
End Sub
Private Sub getDefaultSettings As Map
Return CreateMap("url":"http://127.0.0.1:8080/getmask")
End Sub
Sub genMask(img As B4XBitmap,settings As Map) As ResumableSub
Dim out As OutputStream
out=File.OpenOutput(File.DirApp,"image.jpg",False)
img.WriteToStream(out,"100","JPEG")
out.Close
Dim job As HttpJob
job.Initialize("",Me)
Dim fd As MultipartFileData
fd.Initialize
fd.KeyName = "upload"
fd.Dir = File.DirApp
fd.FileName = "image.jpg"
fd.ContentType = "image/jpg"
job.PostMultipart(settings.GetDefault("url","http://127.0.0.1:8080/getmask"),Null, Array(fd))
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
Else
Log(job.ErrorMessage)
End If
job.Release
Return emptyMask(img)
End Sub
Private Sub emptyMask(img As B4XBitmap) As B4XBitmap
Dim bc As BitmapCreator
bc.Initialize(img.Width,img.Height)
Return bc.Bitmap
End Sub