-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathIMG2ANS.BM
284 lines (256 loc) · 8.7 KB
/
IMG2ANS.BM
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
''
' IMG2ANS - IMG2ANS_BM (Module)
'
' @depends IMG2ANS.BI
' @depends IMG2ANS.BAS
' @depends include/MOUSE/MOUSE.BM
' @depends include/InForm-PE/InForm/InFormCommon.bi
' @depends include/InForm-PE/InForm/InForm.bi
' @depends include/InForm-PE/InForm/InForm.ui
' @depends include/QB64_GJ_LIB/CONSOLE/CONSOLE.BM
' @depends include/QB64_GJ_LIB/MISC/MISC.BM
'
$INCLUDEONCE
''
' Sets the size of the crop bounding box
' @param INTEGER w Width of the box
' @param INTEGER h Height of the box
'
SUB SetCropSize(w%, h%)
Text(RC_ResizeCropWTB) = _TRIM$(STR$(w%))
Text(RC_ResizeCropHTB) = _TRIM$(STR$(h%))
END SUB
''
' Sets input focus to image
' @param LONG pb picturebox control
'
SUB SetImgFocus(pb&)
console.info "SetImgFocus(" + _TRIM$(STR$(pb&)) + ")"
ClearImgFocus
Control(pb&).BorderColor = _RGB32(255, 0, 0)
Control(pb&).Redraw = TRUE
END SUB
''
' Clears ImgFocus
'
SUB ClearImgFocus
console.info "ClearImgFocus"
Control(SI_SourceImgPB).BorderColor = _RGB32(167, 166, 170)
Control(DP_DestPalPB).BorderColor = _RGB32(167, 166, 170)
Control(RC_ResizeCropPB).BorderColor = _RGB32(167, 166, 170)
Control(P_PreviewPB).BorderColor = _RGB32(167, 166, 170)
Control(SI_SourceImgPB).Redraw = TRUE
Control(DP_DestPalPB).Redraw = TRUE
Control(RC_ResizeCropPB).Redraw = TRUE
Control(P_PreviewPB).Redraw = TRUE
END SUB
''
' Clear all Picture Boxes
'
SUB ClearPBs
console.info "ClearPBs"
ClearImageFromPB SourceIMG, SI_SourceImgPB
ClearImageFromPB DestPalIMG, DP_DestPalPB
ClearImageFromPB ResizeCropIMG, RC_ResizeCropPB
ClearImageFromPB PreviewIMG, P_PreviewPB
ClearImgFocus
Text(S_SauceTitleTB) = ""
Text(S_SauceAuthorTB) = ""
Text(S_SauceGroupTB) = ""
Text(S_SauceCommentTB) = ""
Text(E_ExportAsFileTB) = ""
Text(E_ExportToDirTB) = ""
Text(SI_SourceImgBrightnessTB) = "50"
Text(SI_SourceImgContrastTB) = "50"
Text(SI_SourceImgPosterizeTB) = "0"
Control(SI_SourceImgBrightnessSlider).Value = 50
Control(SI_SourceImgContrastSlider).Value = 50
Control(SI_SourceImgPosterizeSlider).Value = 0
Text(RC_ResizeCropXTB) = ""
Text(RC_ResizeCropYTB) = ""
Text(RC_ResizeCropWTB) = ""
Text(RC_ResizeCropHTB) = ""
Control(DP_DestPalCB).Value = FALSE
Control(RC_ResizeCropCB).Value = FALSE
Control(DP_DestPalPalleteDL).Value = 1
END SUB
''
' Clear image from a Picture Box
' @param IMAGE img to clear
' @param LONG pb PictureBox to clear from
'
SUB ClearImageFromPB(img AS IMAGE, pb&)
console.info "ClearImageFromPB(" + img.file_name$ + "," + STR$(pb&) + ")"
ClearImage img
LoadImage Control(pb&), _STARTDIR$ + "/resources/images/blank.gif"
END SUB
''
' Load Image into PictureBox
' @param IMAGE img to load
' @param LONG pb Control ID of PictueBox
' @param STRING directory to start in for file picker
'
SUB LoadImageIntoPB(img AS IMAGE, pb&, directory$)
console.info "LoadImageIntoPB(" + img.file_name$ + "," + STR$(pb&) + "," + directory$ + ")"
DIM AS STRING image_file
image_file$ = BrowseForImageFile$(directory$)
PutImageIntoPB img, pb&, image_file$
PutImageIntoPB DestPalIMG, DP_DestPalPB, image_file$
PutImageIntoPB ResizeCropIMG, RC_ResizeCropPB, image_file$
PutImageIntoPB PreviewIMG, P_PreviewPB, image_file$
Text(S_SauceTitleTB) = img.file_name$
Text(E_ExportAsFileTB) = img.file_name$ + ".ans"
Text(E_ExportToDirTB) = MID$(img.file_path$, 0, _INSTRREV(img.file_path$, SLASH$) + 1)
END SUB
''
' Put Image Into PictureBox
' @param IMAGE img to put
' @param LONG pb Control ID of PictureBox
' @param STRING file_path of image to load into PictureBox HelperCanvas
'
SUB PutImageIntoPB(img AS IMAGE, pb&, file_path$)
console.info "PutImageIntoPB(" + img.file_name$ + "," + STR$(pb&) + "," + file_path$ + ")"
img.file_path$ = file_path$
img.file_name$ = MID$(img.file_path$, _INSTRREV(img.file_path$, SLASH$) + 1)
img.file_ext$ = MID$(img.file_name$, _INSTRREV(img.file_name$, "."))
img.ID& = pb&
img.handle& = Control(img.ID&).HelperCanvas&
img.src_w% = _WIDTH(img.handle&)
img.src_h% = _HEIGHT(img.handle&)
img.src_x% = 1
img.src_y% = 1
img.dst_w% = _WIDTH(img.handle&)
img.dst_h% = _HEIGHT(img.handle&)
img.dst_x% = 1
img.dst_y% = 1
img.x_offset% = 0
img.y_offset% = 0
img.zoom! = 1
img.has_mouse%% = FALSE
img.has_focus%% = FALSE
LoadImage Control(img.ID&), img.file_path$
CALL console.dir_image(img)
END SUB
''
' Clear an image
' @param IMAGE img to clear
'
SUB ClearImage(img AS IMAGE)
console.info "ClearImage(" + img.file_name$ + ")"
img.file_path$ = ""
img.file_name$ = ""
img.file_ext$ = ""
img.ID& = 0
img.handle& = 0
img.src_w% = 0
img.src_h% = 0
img.src_x% = 0
img.src_y% = 0
img.dst_w% = 0
img.dst_h% = 0
img.dst_x% = 0
img.dst_y% = 0
img.x_offset% = 0
img.y_offset% = 0
img.zoom! = 0
img.has_mouse%% = FALSE
img.has_focus%% = FALSE
END SUB
''
' Load a GPL GIMP Palette file from disk
' @param STRING file_path of palette
'
SUB LoadGPLFile(file_path$)
console.info "LoadGPLFile(" + file_path$ + ")"
END SUB
''
' Browses for image file using OS file browser dialog
' @param STRING directory to start in for file picker
'
FUNCTION BrowseForImageFile$(directory$)
console.info "BrowseForImageFile$(" + directory$ + ")"
' Choose an image file with dialog
BrowseForImageFile$ = _OPENFILEDIALOG$( _
"Choose an image", _
directory$, _
"*.jpg|*.jpeg|*.png|*.tga|*.bmp|*.psd|*.gif|*.pcx|*.svg|*.qoi", _
"Image Files", _
-1 _
)
END FUNCTION
''
' Browses for GPL palette file using OS file browser dialog
' @param STRING directory to start in for file picker
'
FUNCTION BrowseForGPLFile$(directory$)
console.info "BrowseForGPLFile$(" + directory$ + ")"
BrowseForGPLFile$ = _OPENFILEDIALOG$( _
"Choose a GPL (GIMP) palette", _
_STARTDIR$ + "/resources/palettes/", _
"*.gpl|*.GPL", _
"GPL (GIMP) Palette", _
0 _
)
END FUNCTION
''
' Applies GPL palette to image in picturebox
' @param STRING pal Palette to apply
' @param LONG img Image to apply palette to
' @param _BYTE dithering applied?
'
SUB ApplyPalToImg(pal$, img&, dithering%%)
console.info "ApplyPalToImg(" + pal$ + "," + STR$(img&) + "," + STR$(dithering%%) + ")"
END SUB
''
' GUI Hook for Destination Palette stuff
'
SUB ChangeDestPal
console.info "ChangeDestPal"
DIM AS STRING pal_sel, pal_2
DIM AS _BYTE checked
pal_2$ = GetItem$(DP_DestPalPalleteDL, 2)
pal_sel$ = GetItem$(DP_DestPalPalleteDL, Control(DP_DestPalPalleteDL).Value)
checked%% = Control(DP_DestPalCB).Value
IF checked%% THEN ' Use destination palette
IF pal_sel$ = "" THEN ' If no choice made, pick first option
pal_sel$ = pal_2$
Control(DP_DestPalPalleteDL).Value = 2
END IF
ApplyPalToImg _STARTDIR$ + "/resources/palettes/" + pal_sel$ + ".GPL", _
Control(DP_DestPalPB).HelperCanvas&, _
TRUE
ELSE
Control(DP_DestPalPalleteDL).Value = 1
END IF
END SUB
''
' Log IMAGE properties if DEBUGGING
' @param IMAGE image to log properties of
'
SUB console.dir_image(img AS IMAGE)
console.info _TRIM$(Control(img.ID&).Name$) + " {"
console.log " ID& = " + _TRIM$(STR$(img.ID&))
console.log " handle& = " + _TRIM$(STR$(img.handle&))
console.log " file_name$ = " + img.file_name$
console.log " file_path$ = " + img.file_path$
console.log " file_ext$ = " + img.file_ext$
console.log " src_w% = " + _TRIM$(STR$(img.src_w%))
console.log " src_h% = " + _TRIM$(STR$(img.src_h%))
console.log " src_x% = " + _TRIM$(STR$(img.src_x%))
console.log " src_y% = " + _TRIM$(STR$(img.src_y%))
console.log " dst_w% = " + _TRIM$(STR$(img.dst_w%))
console.log " dst_h% = " + _TRIM$(STR$(img.dst_h%))
console.log " dst_x% = " + _TRIM$(STR$(img.dst_x%))
console.log " dst_y% = " + _TRIM$(STR$(img.dst_y%))
console.log " x_offset% = " + _TRIM$(STR$(img.x_offset%))
console.log " y_offset% = " + _TRIM$(STR$(img.y_offset%))
console.log " has_mouse%% = " + _TRIM$(STR$(img.has_mouse%%))
console.log " has_focus%% = " + _TRIM$(STR$(img.has_focus%%))
console.log " zoom! = " + _TRIM$(STR$(img.zoom!))
console.warn "}"
END SUB
'$INCLUDE:'include/MOUSE/MOUSE.BM'
'$INCLUDE:'include/BOUNDING_BOX/BOUNDING_BOX.BM'
'$INCLUDE:'include/QB64_GJ_LIB/SYS/SYS.BM'
'$INCLUDE:'include/QB64_GJ_LIB/CONSOLE/CONSOLE.BM'
'$INCLUDE:'include/QB64_GJ_LIB/MISC/MISC.BM'