-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexport frame.bas
76 lines (68 loc) · 1.36 KB
/
export frame.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
REM BASIC8
REM Copyright (C) 2018 - 2019 Tony Wang
REM Plugin program of BASIC8.
REM Imports common modules.
import "common/utils"
REM Loads the plugin.
def plug()
print "Loading plugin: Export frame...";
register_plugin
(
"sprite, quantized", ' Target assets.
"Export frame", ' Name.
"Export the selection or current frame to image", ' Tooltips.
false, ' Selection only?
false, ' Square only?
40, ' Category.
60 ' Priority.
)
enddef
REM Runs the plugin.
def run()
' Prepares.
print "Running plugin: Export frame...";
x0 = 0
y0 = 0
x1 = 0
y1 = 0
w = 0
h = 0
' Gets the operating area.
if has_selection() then
v = get_selection_range()
unpack(v, x0, y0, x1, y1)
else
v = get_frame_size()
unpack(v, x1, y1)
x1 = x1 - 1
y1 = y1 - 1
endif
w = x1 - x0 + 1
h = y1 - y0 + 1
' Fills in the pixels at target image with the working area.
g = image()
g.resize(w, h)
for j = 0 to h - 1
y = y0 + j
for i = 0 to w - 1
x = x0 + i
p = get_pixel(x, y)
c = get_color_from_palette(p)
g.set(i, j, c)
next
next
' Saves to file.
f = save_file_dialog("png,bmp,tga,jpg")
if not f then
return
endif
f = validate_image_file(f)
g.save(f, right(f, 3))
enddef
REM Checks the operation.
ph = get_phase()
if ph = "plug" then
plug()
elseif ph = "run" then
run()
endif