-
Notifications
You must be signed in to change notification settings - Fork 1
/
pmotion_file-io.pb
493 lines (391 loc) · 18.2 KB
/
pmotion_file-io.pb
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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
; "pmotion_file-io.pb" DRAFT v0.0.3 | 2021/02/15
; ******************************************************************************
; * *
; * Cosmigo Pro Motion *
; * *
; * File I/O Plugin Interface *
; * *
; ******************************************************************************
#PLUGIN_PB_VER = 573 ; PureBasic 5.73 LTS x86
; Copyright (C) 2019-2021 by Tristano Ajmone, MIT License.
; https://github.com/cosmigo/pmotion-purebasic
; ------------------------------------------------------------------------------
; STATUS: NOT FULLY TESTED IN REAL CASE SCENARIOS.
; ******************************************************************************
; * *
;- PLUGIN SETUP
; * *
;{******************************************************************************
; ------------------------------------------------------------------------------
;- Plugin Settings
; ------------------------------------------------------------------------------
#PLUGIN_SUPPORTS_ANIMATION = #False ; or #True
#PLUGIN_SUPPORTS_PALETTE_EXTRACT = #False ; or #True
#PLUGIN_SUPPORTS_READ = #False ; or #True
#PLUGIN_SUPPORTS_WRITE = #False ; or #True
#PLUGIN_SUPPORTS_WRITE_TRUECOLOR = #False ; or #True
Global FILE_TYPE_ID$ = "your.plugin.id" ; A unique identifier of the plugin
Global FILE_BOX_DESCRIPTION$ = "xxx etc" ; Extensions description (for UI)
Global FILE_EXTENSION$ = "xxx" ; File extension (without dot)
; ------------------------------------------------------------------------------
; Hard-Coded Plugin Settings
; ------------------------------------------------------------------------------
; Plugin interface internal settings (for maintainers of the PB interface only).
; At the moment there is only version "1" of the file plugin interface:
#PLUGIN_INTERFACE_VERSION_USED = 1
; ------------------------------------------------------------------------------
;- Check Compiler Settings
; ------------------------------------------------------------------------------
CompilerIf #PB_Compiler_OS <> #PB_OS_Windows Or
#PB_Compiler_Processor <> #PB_Processor_x86 Or
#PB_Compiler_ExecutableFormat <> #PB_Compiler_DLL Or
#PB_Compiler_Thread = #True
CompilerError "WRONG COMPILER SETTINGS! Must be Windows DLL for x86 (32 bit) not threadsafe"
CompilerEndIf
CompilerIf #PB_Compiler_Version <> #PLUGIN_PB_VER
CompilerWarning ~"This plugin was tested only on PureBasic "+ #PLUGIN_PB_VER + "."
CompilerEndIf
; ------------------------------------------------------------------------------
;- Global Strings for PMNG
; ------------------------------------------------------------------------------
; Strings that need to be returned from the plugin DLL procedures to Pro Motion
; (via pointers) must be defined as globals.
Global PLUGIN_ERROR_MSG$ = #Empty$
; ==============================================================================
;- Useful Helpers
;{==============================================================================
#Success = #True
#Failure = #False
; ------------------------------------------------------------------------------
; C++ Types
; ------------------------------------------------------------------------------
; Custom types, macros and other helpers to simplify reading C++ API interfacing.
; Boolean
Macro boolean
i
EndMacro
; String Pointer (x86)
Macro strpointer
i
EndMacro
; Pointer (x86)
Macro pointer
i
EndMacro
Macro int32
l
EndMacro
Macro uint16
u
EndMacro
; ------------------------------------------------------------------------------
; Error Macros
; ------------------------------------------------------------------------------
Macro resetError
PLUGIN_ERROR_MSG$ = #Empty$
EndMacro
Macro setError( errString )
PLUGIN_ERROR_MSG$ = errString
EndMacro
;}==============================================================================
;- DLL Setup
; ==============================================================================
; ------------------------------------------------------------------------------
;- Sharable Variables (for internal use)
; ------------------------------------------------------------------------------
; These variables are handled transparently by the plugin interface template,
; which takes care of setting their values based on the transactions with Pro
; Motion. They can be accessed by the user via the Shared keyword if/when he/she
; needs them in his/her code.
UILang$ = #Empty$ ; PMNG user interface locale (2 chars ISO language code)
FileName$ = #Empty$ ; Full path to the selected file.
; This structure and the corresponding ImageData var are provided by the plugin
; interface template as a convenient way to handle image/frames data across
; procedures by sharing a single variable on demand.
; Also, the template is designed to implicitly handle ImageData in some plugin
; native procedures, thus lifting from the plugin author the burden of having to
; write any code in them — e.g. getWidth(), getHeight(), and others.
; But the plugin author ** MUST ALWAYS ** update ImageData with any acquired
; info about the images/frames being processed.
Structure ImageDataStruct
Width.int32
Height.int32
Frames.int32
TranspColorIndex.int32
AlphaEnabled.boolean
EndStructure
ImageData.ImageDataStruct
; See also resetImageData() for a quick way to reset ImageData values.
; ------------------------------------------------------------------------------
;- Procedures Declaration (Plugin)
; ------------------------------------------------------------------------------
; Initialization:
DeclareDLL.boolean initialize(*language, *version.Unicode, *animation.Ascii)
DeclareDLL setProgressCallback( *progressCallback )
; Plugin Info:
DeclareDLL.strpointer getFileExtension()
DeclareDLL.strpointer getFileTypeId()
DeclareDLL.strpointer getFileBoxDescription()
; Plugin Capabilities:
DeclareDLL.boolean isReadSupported()
DeclareDLL.boolean isWriteSupported()
DeclareDLL.boolean isWriteTrueColorSupported()
DeclareDLL.boolean canExtractPalette()
; Process Control:
DeclareDLL.strpointer getErrorMessage()
DeclareDLL setFilename( *filename_pnt )
DeclareDLL.boolean loadBasicData()
DeclareDLL finishProcessing()
DeclareDLL.boolean canHandle()
; File Load Procedures:
DeclareDLL.boolean isAlphaEnabled()
DeclareDLL.int32 getWidth()
DeclareDLL.int32 getHeight()
DeclareDLL.int32 getImageCount()
DeclareDLL.pointer getRgbPalette()
DeclareDLL.int32 getTransparentColor()
DeclareDLL.boolean loadNextImage(*colorFrame,
*colorFramePalette,
*alphaFrame,
*alphaFramePalette,
delayMs.uint16)
; File Save Procedures:
DeclareDLL.boolean beginWrite(width.int32,
height.int32,
transparentColor.int32,
alphaEnabled.boolean,
numberOfFrames.int32)
DeclareDLL.boolean writeNextImage(*colorFrame,
*colorFramePalette,
*alphaFrame,
*alphaFramePalette,
*rgba,
delayMs.uint16)
; ------------------------------------------------------------------------------
;- Procedures Declaration (Interface Helpers)
; ------------------------------------------------------------------------------
Declare resetImageData()
;}******************************************************************************
; * *
;- PLUGIN DLL PROCEDURES
; * *
;{******************************************************************************
; These are the mandatory DLL procedures required by every file I/O plugin.
; Pro Motion expects them to be exported with these exact names and signature.
; Even if you plug-in doesn't use some of these procedures (because it only
; supports import or export) you still need to define all of them, otherwise the
; plugin will fail the initialization test as "invalid" and will be ignored.
; Some procedures don't require any custom code from the plugin author (they can
; handle the call via the available data and settings) while others require the
; plugin author to add code, as indicated by the comments in the procedure body.
; Below is a reference table with all the mandatory DLL procedures and whether
; they need custom code additions, and if they can set error or not.
; +-----------------------------+------------+---------------+
; | plugin DLL procedure | your code? | set error? |
; +-----------------------------+------------+---------------+
; | beginWrite() | needs code | can set error |
; | canExtractPalette() | | |
; | canHandle() | needs code | can set error |
; | finishProcessing() | needs code | |
; | getErrorMessage() | | |
; | getFileBoxDescription() | | |
; | getFileExtension() | | |
; | getFileTypeId() | | |
; | getHeight() | | |
; | getImageCount() | needs code | |
; | getRgbPalette() | needs code | |
; | getTransparentColor() | needs code | |
; | getWidth() | | |
; | initialize() | needs code | can set error |
; | isAlphaEnabled() | | |
; | isReadSupported() | | |
; | isWriteSupported() | | |
; | isWriteTrueColorSupported() | | |
; | loadBasicData() | needs code | can set error |
; | loadNextImage() | needs code | can set error |
; | setFilename() | needs code | |
; | setProgressCallback() | | |
; | writeNextImage() | needs code | can set error |
; +-----------------------------+------------+---------------+
;- /// Plugin Initialization ///
ProcedureDLL.boolean initialize(*language, *version.Unicode, *animation.Ascii)
resetError ; -> This procedure can set error!
*version\u = #PLUGIN_INTERFACE_VERSION_USED
*animation\a = #PLUGIN_SUPPORTS_ANIMATION
Shared UILang$
UILang$ = Chr(PeekA(*language)) + Chr(PeekA(*language +1))
; >>> Your code here >>>>>>>>>>>>>>>
; Do whatever you need to...
ProcedureReturn #Success ; or #Failure + setError("Why failed...")
; <<< Your code ends <<<<<<<<<<<<<<<
EndProcedure
Prototype ProtoProgressCallback( progress.int32 )
Global progressCallback.ProtoProgressCallback
ProcedureDLL setProgressCallback( *progressCallback )
progressCallback = *progressCallback
EndProcedure
;- /// Plugin Info ///
ProcedureDLL.strpointer getFileExtension()
ProcedureReturn @FILE_EXTENSION$
EndProcedure
ProcedureDLL.strpointer getFileTypeId()
ProcedureReturn @FILE_TYPE_ID$
EndProcedure
ProcedureDLL.strpointer getFileBoxDescription()
ProcedureReturn @FILE_BOX_DESCRIPTION$
EndProcedure
;- /// Plugin Features Support Info ///
ProcedureDLL.boolean isReadSupported()
ProcedureReturn #PLUGIN_SUPPORTS_READ
EndProcedure
ProcedureDLL.boolean isWriteSupported()
ProcedureReturn #PLUGIN_SUPPORTS_WRITE
EndProcedure
ProcedureDLL.boolean isWriteTrueColorSupported()
ProcedureReturn #PLUGIN_SUPPORTS_WRITE_TRUECOLOR
EndProcedure
ProcedureDLL.boolean canExtractPalette()
ProcedureReturn #PLUGIN_SUPPORTS_PALETTE_EXTRACT
EndProcedure
;- /// Image Processing Control ///
ProcedureDLL.strpointer getErrorMessage()
If PLUGIN_ERROR_MSG$ <> #Empty$
ProcedureReturn @PLUGIN_ERROR_MSG$
Else
ProcedureReturn #Null
EndIf
EndProcedure
ProcedureDLL setFilename( *filename_pnt )
Shared FileName$
NewFileName$ = PeekS( *filename_pnt )
If NewFileName$ <> FileName$
; >>> Your code here >>>>>>>>>>>>>>>
; A new file was selected ...
; <<< Your code ends <<<<<<<<<<<<<<<
EndIf
FileName$ = NewFileName$
EndProcedure
ProcedureDLL.boolean loadBasicData()
resetError ; -> This procedure can set error!
Shared ImageData
; >>> Your code here >>>>>>>>>>>>>>>
; Extract basic graphics data information from the target file, such as its
; dimensions, color palette, etc. and update the ImageData structured var:
; With ImageData
; \Width = ; pixels width
; \Height = ; pixels height
; \Frames = ; number of frames (or -1 on failure)
; \TranspColorIndex = ; index of transp. color (or -1 if none)
; \AlphaEnabled = ; #True/#False
; EndWith
ProcedureReturn #Success ; or #Failure + setError("Why failed...")
; <<< Your code ends <<<<<<<<<<<<<<<
EndProcedure
ProcedureDLL finishProcessing()
; >>> Your code here >>>>>>>>>>>>>>>
; Close file, free memory, and other wrap-up chores...
; <<< Your code ends <<<<<<<<<<<<<<<
EndProcedure
ProcedureDLL.boolean canHandle()
resetError ; -> This procedure can set error!
; >>> Your code here >>>>>>>>>>>>>>>
; Establish if the plugin can handle the selected file...
ProcedureReturn #True ; or #False + setError("Why can't handle...")
; <<< Your code ends <<<<<<<<<<<<<<<
EndProcedure
;- /// File Load Procedures ///
; The next five procedures rely on you having correctly updated the ImageData
; structured variable during loadBasicData(), and will not require you to add
; any code to them.
ProcedureDLL.boolean isAlphaEnabled()
Shared ImageData
ProcedureReturn ImageData\AlphaEnabled
EndProcedure
ProcedureDLL.int32 getWidth()
Shared ImageData
ProcedureReturn ImageData\Width
EndProcedure
ProcedureDLL.int32 getHeight()
Shared ImageData
ProcedureReturn ImageData\Height
EndProcedure
ProcedureDLL.int32 getTransparentColor()
Shared ImageData
ProcedureReturn ImageData\TranspColorIndex
EndProcedure
ProcedureDLL.int32 getImageCount()
Shared ImageData
; >>> Your code here >>>>>>>>>>>>>>>
; <<< Your code ends <<<<<<<<<<<<<<<
ProcedureReturn ImageData\Frames
EndProcedure
ProcedureDLL.pointer getRgbPalette()
; >>> Your code here >>>>>>>>>>>>>>>
; Return a pointer to the extracted RGB palette or #Null if palette extraction
; is not supported.
; <<< Your code ends <<<<<<<<<<<<<<<
EndProcedure
ProcedureDLL.boolean loadNextImage(*colorFrame,
*colorFramePalette,
*alphaFrame,
*alphaFramePalette,
delayMs.uint16)
resetError ; -> This procedure can set error!
; >>> Your code here >>>>>>>>>>>>>>>
; Load the image/frame in memory and set the pointers of the parameters
; accordingly ...
ProcedureReturn #Success ; or #Failure + setError("Why failed...")
; <<< Your code ends <<<<<<<<<<<<<<<
EndProcedure
;- /// File Save Procedures ///
ProcedureDLL.boolean beginWrite(width.int32,
height.int32,
transparentColor.int32,
alphaEnabled.boolean,
numberOfFrames.int32)
resetError ; -> This procedure can set error!
; >>> Your code here >>>>>>>>>>>>>>>
; Do something...
ProcedureReturn #Success ; or #Failure + setError("Why failed...")
; <<< Your code ends <<<<<<<<<<<<<<<
EndProcedure
ProcedureDLL.boolean writeNextImage(*colorFrame,
*colorFramePalette,
*alphaFrame,
*alphaFramePalette,
*rgba,
delayMs.uint16)
resetError ; -> This procedure can set error!
; >>> Your code here >>>>>>>>>>>>>>>
; Get the image/frame data from the parameters pointers and do what you have
; to do with it ...
ProcedureReturn #Success ; or #Failure + setError("Why failed...")
; <<< Your code ends <<<<<<<<<<<<<<<
EndProcedure
;}******************************************************************************
; * *
;- INTERFACE HELPER PROCEDURES
; * *
;{******************************************************************************
; Some internal procedures provided by the interface template to support the
; plugin DLL interface.
Procedure resetImageData()
; ----------------------------------------------------------------------------
; Reset all values of ImageData structure to defaults.
; ----------------------------------------------------------------------------
Shared ImageData
With ImageData
\Height = -1
\Width = -1
\Frames = -1
\TranspColorIndex = -1
\AlphaEnabled = #False
EndWith
EndProcedure
;}******************************************************************************
; * *
;- YOUR INTERNAL PLUGIN PROCEDURES
; * *
; ******************************************************************************
; Add below all your custom procedures that make your plugin unique...
; EOF ;