Rev 503 | Rev 529 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
259 | daniel-mar | 1 | /* |
268 | daniel-mar | 2 | This file is part of "Filter Foundry", a filter plugin for Adobe Photoshop |
312 | daniel-mar | 3 | Copyright (C) 2003-2009 Toby Thain, toby@telegraphics.com.au |
503 | daniel-mar | 4 | Copyright (C) 2018-2022 Daniel Marschall, ViaThinkSoft |
259 | daniel-mar | 5 | |
312 | daniel-mar | 6 | This program is free software; you can redistribute it and/or modify |
7 | it under the terms of the GNU General Public License as published by |
||
8 | the Free Software Foundation; either version 2 of the License, or |
||
9 | (at your option) any later version. |
||
259 | daniel-mar | 10 | |
312 | daniel-mar | 11 | This program is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
14 | GNU General Public License for more details. |
||
259 | daniel-mar | 15 | |
312 | daniel-mar | 16 | You should have received a copy of the GNU General Public License |
17 | along with this program; if not, write to the Free Software |
||
18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
259 | daniel-mar | 19 | */ |
20 | |||
21 | //#include <stdio.h> |
||
22 | //#include <sound.h> |
||
23 | |||
24 | #include "ff.h" |
||
25 | |||
444 | daniel-mar | 26 | #include "str.h" |
259 | daniel-mar | 27 | #include "node.h" |
28 | #include "funcs.h" |
||
29 | #include "y.tab.h" |
||
30 | #include "scripting.h" |
||
31 | #include <math.h> |
||
32 | #include "PIBufferSuite.h" |
||
33 | |||
34 | // GIMP (PSPI) and IrfanView preserve neither *data(gdata), nor pb->parameters between invocations! |
||
35 | // For debugging, we can simulate it here |
||
36 | //#define DEBUG_SIMULATE_GIMP |
||
37 | |||
264 | daniel-mar | 38 | // Used to find out which host signatures and memory settings a plugin host has |
39 | //#define SHOW_HOST_DEBUG |
||
40 | |||
480 | daniel-mar | 41 | // Here are working variables: |
259 | daniel-mar | 42 | struct node *tree[4]; |
492 | daniel-mar | 43 | TCHAR *err[4]; |
259 | daniel-mar | 44 | int errpos[4],errstart[4],nplanes,cnvused,chunksize,toprow; |
381 | daniel-mar | 45 | uint8_t slider[8]; // this is the "working data". We cannot always use gdata->parm, because parm will not be loaded if a AFS file is read |
46 | char* expr[4]; // this is the "working data". We cannot always use gdata->parm, because parm will not be loaded if a AFS file is read |
||
301 | daniel-mar | 47 | value_type cell[NUM_CELLS]; |
480 | daniel-mar | 48 | |
49 | // this is the only memory area that keeps preserved by Photoshop: |
||
259 | daniel-mar | 50 | globals_t *gdata; |
51 | FilterRecordPtr gpb; |
||
52 | |||
53 | #ifdef MAC_ENV |
||
483 | daniel-mar | 54 | #define HINSTANCE HANDLE |
55 | #define hDllInstance NULL /* fake this Windows-only global */ |
||
259 | daniel-mar | 56 | #endif |
57 | |||
58 | #ifdef WIN_ENV |
||
59 | #include "manifest.h" |
||
60 | #endif |
||
61 | |||
62 | extern struct sym_rec predefs[]; |
||
63 | extern int nplanes,varused[]; |
||
64 | |||
65 | int checkandinitparams(Handle params); |
||
66 | |||
67 | // MPW MrC requires prototype |
||
68 | DLLEXPORT MACPASCAL |
||
69 | void ENTRYPOINT(short selector,FilterRecordPtr pb,intptr_t *data,short *result); |
||
70 | |||
276 | daniel-mar | 71 | unsigned long get_parm_hash(PARM_T *parm) { |
259 | daniel-mar | 72 | unsigned long hash; |
73 | int i; |
||
74 | |||
393 | daniel-mar | 75 | hash = djb2(parm->szCategory); |
76 | hash += djb2(parm->szTitle); |
||
77 | hash += djb2(parm->szCopyright); |
||
78 | hash += djb2(parm->szAuthor); |
||
79 | for (i = 0; i < 4; i++) hash += djb2(parm->szMap[i]); |
||
80 | for (i = 0; i < 8; i++) hash += djb2(parm->szCtl[i]); |
||
81 | for (i = 0; i < 4; i++) hash += djb2(parm->szFormula[i]); |
||
259 | daniel-mar | 82 | |
83 | return hash; |
||
84 | } |
||
85 | |||
444 | daniel-mar | 86 | size_t get_temp_afs(LPTSTR outfilename, Boolean isStandalone, PARM_T *parm) { |
87 | char* atempdir; |
||
373 | daniel-mar | 88 | int hash; |
444 | daniel-mar | 89 | size_t i, j; |
90 | TCHAR out[MAX_PATH + 1]; |
||
91 | char ahash[20]; |
||
373 | daniel-mar | 92 | |
444 | daniel-mar | 93 | // out = getenv("TMP") |
94 | atempdir = getenv("TMP"); |
||
95 | for (i = 0; i < strlen(atempdir); i++) { |
||
96 | out[i] = (TCHAR)atempdir[i]; |
||
97 | out[i + 1] = 0; |
||
98 | } |
||
99 | |||
373 | daniel-mar | 100 | #ifdef WIN_ENV |
444 | daniel-mar | 101 | if (xstrlen(out) > 0) xstrcat(out, TEXT("\\")); |
373 | daniel-mar | 102 | #else |
444 | daniel-mar | 103 | if (xstrlen(out) > 0) xstrcat(out, TEXT("/")); |
373 | daniel-mar | 104 | #endif |
105 | |||
106 | hash = (isStandalone) ? get_parm_hash(parm) : 0; |
||
444 | daniel-mar | 107 | |
108 | // sprintf(outfilename, "%sFilterFoundry%d.afs", atempdir, hash); |
||
109 | xstrcat(out, TEXT("FilterFoundry")); |
||
110 | _itoa(hash, &ahash[0], 10); |
||
111 | for (i = 0; i < strlen(ahash); i++) { |
||
112 | j = xstrlen(out); |
||
113 | out[j] = (TCHAR)ahash[i]; |
||
114 | out[j + 1] = 0; |
||
115 | } |
||
116 | xstrcat(out, TEXT(".afs")); |
||
117 | if (outfilename != NULL) { |
||
118 | xstrcpy(outfilename, out); |
||
119 | } |
||
120 | return xstrlen(out); |
||
373 | daniel-mar | 121 | } |
122 | |||
461 | daniel-mar | 123 | void CALLBACK FakeRundll32(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow) { |
463 | daniel-mar | 124 | UNREFERENCED_PARAMETER(hwnd); |
125 | UNREFERENCED_PARAMETER(hinst); |
||
126 | UNREFERENCED_PARAMETER(lpszCmdLine); |
||
127 | UNREFERENCED_PARAMETER(nCmdShow); |
||
461 | daniel-mar | 128 | |
462 | daniel-mar | 129 | /* |
463 | daniel-mar | 130 | char* tmp = (char*)malloc(512); |
461 | daniel-mar | 131 | if (tmp != 0) { |
132 | sprintf(tmp, "hwnd: %p\nhinst: %p\nlpszCmdLine: %s\nCmdShow: %d", (void*)(hwnd), (void*)(hinst), lpszCmdLine, nCmdShow); |
||
133 | MessageBoxA(0, tmp, 0, 0); |
||
134 | free(tmp); |
||
135 | } |
||
462 | daniel-mar | 136 | */ |
461 | daniel-mar | 137 | |
492 | daniel-mar | 138 | simplealert_id(MSG_RUNDLL_ERR_ID); |
139 | |||
461 | daniel-mar | 140 | return; |
141 | } |
||
142 | |||
479 | daniel-mar | 143 | void CreateDataPointer(intptr_t* data) { |
144 | // Register "gdata" that contains the PARM information and other things which need to be persistant |
||
145 | // and preserve them in *data |
||
146 | // This memory allocation is never freed, because the filter can always be invoked again. |
||
147 | // The memory allocation will be kept for the lifetime of the Photoshop process and |
||
148 | // freed together with the application termination. |
||
149 | |||
150 | // We have at least 5 options to allocate memory: |
||
480 | daniel-mar | 151 | |
152 | // (Method 1) |
||
481 | daniel-mar | 153 | // 1. The deprecated Standard Buffer Suite (pb->bufferProcs) - works fine! |
486 | daniel-mar | 154 | /* |
155 | BufferID tempId; |
||
156 | if (gpb->bufferProcs->allocateProc(sizeof(globals_t), &tempId) != noErr) { |
||
157 | *data = NULL; |
||
158 | } |
||
159 | else { |
||
160 | *data = (void*)gpb->bufferProcs->lockProc(tempId, true); |
||
161 | if (*data) memset((void*)*data, 0, sizeof(globals_t)); |
||
162 | } |
||
163 | */ |
||
480 | daniel-mar | 164 | |
165 | // (Method 2) *DOES NOT WORK* |
||
166 | // 2. The recommended buffer suite (kPSBufferSuite), |
||
167 | // It does not work, since it causes memory corruption when the filter is invoked a second time. |
||
168 | // Probably the BufferSuite cannot be used to share data between filter invocations? |
||
169 | // Also, the buffer suite is only available in a Adobe Photoshop host. |
||
486 | daniel-mar | 170 | /* |
171 | FFBuffer buf; |
||
172 | newBuffer(&buf, sizeof(globals_t)); |
||
173 | *data = (intptr_t)lockBuffer(&buf); |
||
174 | if (*data) memset((void*)*data, 0, sizeof(globals_t)); |
||
175 | */ |
||
480 | daniel-mar | 176 | |
177 | // (Method 3) |
||
479 | daniel-mar | 178 | // 3. Using malloc(), which works also fine and is more independent from the host. It is also easier. |
179 | // However, we do not know how malloc() is implemented, and it might cause problems if the |
||
180 | // DLL is unloaded between invocations. |
||
486 | daniel-mar | 181 | /* |
182 | *data = (intptr_t)malloc(sizeof(globals_t)); |
||
183 | if (*data) memset((void*)*data, 0, sizeof(globals_t)); |
||
184 | */ |
||
480 | daniel-mar | 185 | |
186 | // (Method 4) |
||
479 | daniel-mar | 187 | // 4. Using PLUGIN.DLL:NewPtr(). This does FilterFactory 3.0.4, but requires an Adobe host. |
480 | daniel-mar | 188 | // In Plugin.dll, the function NewPtr() and NewPtrClear() are implemented as GlobalAlloc/GlobalLock. |
189 | // Nothing special. |
||
190 | |||
191 | // (Method 5) |
||
479 | daniel-mar | 192 | // 5. Using GlobalAlloc/GlobalLock. This does FilterFactory 3.00 (Flags GHND = GMEM_MOVEABLE and GMEM_ZEROINIT). |
193 | // This is Windows dependant. (However, on Mac we will just call NewPtr.) |
||
194 | // GlobalAlloc and LocalAlloc are equal in 32-bit windows. The memory allocation is NOT global anymore, |
||
195 | // instead it is on the private heap of the application. (Therefore we do not cause a leak when |
||
196 | // Photoshop is closed). |
||
480 | daniel-mar | 197 | // In Filter Foundry 1.7.0.17 we define a function called NewPtrClear, which is natively supported by Mac, |
198 | // and in Windows it will be implemented using GlobalAlloc/GlobalLock. |
||
479 | daniel-mar | 199 | *data = (intptr_t)NewPtrClear(sizeof(globals_t)); |
200 | } |
||
201 | |||
461 | daniel-mar | 202 | DLLEXPORT MACPASCAL |
259 | daniel-mar | 203 | void ENTRYPOINT(short selector, FilterRecordPtr pb, intptr_t *data, short *result){ |
204 | static Boolean wantdialog = false; |
||
205 | static Boolean premiereWarnedOnce = false; |
||
393 | daniel-mar | 206 | |
284 | daniel-mar | 207 | #ifdef SHOW_HOST_DEBUG |
208 | char* tmp; |
||
209 | #endif |
||
268 | daniel-mar | 210 | |
211 | #ifdef WIN_ENV |
||
259 | daniel-mar | 212 | // For Windows, we use an activation context to enforce that our Manifest resource will |
213 | // be used. This allows us to use Visual Styles, even if the host application does not |
||
214 | // support it. |
||
215 | ManifestActivationCtx manifestVars; |
||
216 | BOOL activationContextUsed; |
||
268 | daniel-mar | 217 | #endif |
259 | daniel-mar | 218 | |
284 | daniel-mar | 219 | // --------------------------------------------------------------------- |
220 | |||
221 | EnterCodeResource(); |
||
222 | |||
283 | daniel-mar | 223 | #ifdef WIN_ENV |
483 | daniel-mar | 224 | activationContextUsed = ActivateManifest((HMODULE)hDllInstance, 1, &manifestVars); |
225 | #endif |
||
226 | |||
227 | #ifdef WIN_ENV |
||
461 | daniel-mar | 228 | if ((intptr_t)result == SW_SHOWDEFAULT) { |
283 | daniel-mar | 229 | // When the 8BF file is analyzed with VirusTotal.com, it will invoke each |
230 | // exported function by calling |
||
461 | daniel-mar | 231 | // loaddll64.exe 'C:\Users\user\Desktop\attachment.dll' |
232 | // ==> rundll32.exe C:\Users\user\Desktop\attachment.dll,PluginMain |
||
233 | // ==> C:\Windows\system32\WerFault.exe -u -p 6612 -s 480 |
||
234 | // |
||
283 | daniel-mar | 235 | // But RunDLL32 requires following signature: |
461 | daniel-mar | 236 | // void __stdcall EntryPoint(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow); |
237 | // Our signature is: |
||
238 | // void PluginMain(short selector, FilterRecordPtr pb, intptr_t *data, short *result); |
||
239 | // |
||
283 | daniel-mar | 240 | // Obviously, this will cause an Exception. (It crashes at *result=e because result is 0xA) |
241 | // Here is the problem: The crash will be handled by WerFault.exe inside the |
||
242 | // VirusTotal virtual machine. WerFault connects to various servers (9 DNS resolutions!) and does |
||
243 | // a lot of weird things, but VirusTotal thinks that our plugin does all that stuff, |
||
244 | // and so they mark our plugin as "malware"! |
||
245 | // This is a problem with VirusTotal! It shall not assume that WerFault.exe actions are our actions! |
||
246 | // Even processes like "MicrosoftEdgeUpdate.exe" and "SpeechRuntime.exe" are reported to be our |
||
247 | // actions, although they have nothing to do with us! |
||
248 | // See https://www.virustotal.com/gui/file/1f1012c567208186be455b81afc1ee407ae6476c197d633c70cc70929113223a/behavior |
||
393 | daniel-mar | 249 | // |
461 | daniel-mar | 250 | // TODO: Usually, The first 64KB of address space are always invalid. However, in Win32s (Windows 3.11), the |
251 | // variable "result" is <=0xFFFF ! Let's just hope that it is never 0x000A (SW_SHOWDEFAULT), |
||
252 | // otherwise we have a problem here! |
||
253 | // I don't understand why this works! Aren't we __cdecl and rundll expected __stdcall? But why is the parameter order correct and not reversed? |
||
463 | daniel-mar | 254 | FakeRundll32((HWND)(intptr_t)selector, (HINSTANCE)pb, (LPSTR)data, (int)(intptr_t)result); |
483 | daniel-mar | 255 | goto endmain; |
283 | daniel-mar | 256 | } |
483 | daniel-mar | 257 | else { |
258 | // will be changed if an error happens |
||
259 | *result = noErr; |
||
260 | } |
||
283 | daniel-mar | 261 | #endif |
393 | daniel-mar | 262 | |
264 | daniel-mar | 263 | #ifdef SHOW_HOST_DEBUG |
284 | daniel-mar | 264 | tmp = (char*)malloc(512); |
459 | daniel-mar | 265 | sprintf(tmp, "Host signature: '%c%c%c%c' (%d)\nMaxSpace32 = %d\nMaxSpace64 = %lld\nNum buffer procs: %d", (pb->hostSig >> 24) & 0xFF, (pb->hostSig >> 16) & 0xFF, (pb->hostSig >> 8) & 0xFF, pb->hostSig & 0xFF, pb->hostSig, pb->maxSpace, pb->maxSpace64, pb->bufferProcs == 0 ? -999/*About has no BufferProcs*/ : pb->bufferProcs->numBufferProcs); |
284 | daniel-mar | 266 | simplealert(tmp); |
424 | daniel-mar | 267 | free(tmp); |
264 | daniel-mar | 268 | #endif |
259 | daniel-mar | 269 | |
270 | if (pb->hostSig == HOSTSIG_ADOBE_PREMIERE) { |
||
491 | daniel-mar | 271 | // DM 19.07.2021 : Tried running the 8BF file in Adobe Premiere 5 + Win98 (yes, that's possible, |
396 | daniel-mar | 272 | // and there is even a FilterFactory for Premiere!), |
259 | daniel-mar | 273 | // but it crashes in evalpixel() where there is write-access to the "outp". |
491 | daniel-mar | 274 | // DM 24.04.2022 : On Adobe Premiere 6 + Win10, the filter opens sometimes (and sometimes crashes inside DialogBoxParam), |
275 | // but the filter is not applied when you click "OK" (because it crashes internally; only the debugger sees it)... |
||
259 | daniel-mar | 276 | // Probably the canvas structure is different (maybe it contains frames to achieve transitions?) |
277 | if (!premiereWarnedOnce) { |
||
492 | daniel-mar | 278 | simplealert_id(MSG_PREMIERE_COMPAT_ID); |
259 | daniel-mar | 279 | } |
280 | premiereWarnedOnce = true; |
||
281 | *result = errPlugInHostInsufficient; |
||
483 | daniel-mar | 282 | goto endmain; |
259 | daniel-mar | 283 | } |
284 | |||
285 | #ifdef DEBUG_SIMULATE_GIMP |
||
286 | *data = 0; |
||
287 | pb->parameters = pb->handleProcs->newProc(1); |
||
288 | #endif |
||
289 | |||
483 | daniel-mar | 290 | gpb = pb; // required for CreateDataPointer() |
480 | daniel-mar | 291 | |
259 | daniel-mar | 292 | if (selector != filterSelectorAbout && !*data) { |
479 | daniel-mar | 293 | // The filter was never called before. We allocate (zeroed) memory now. |
294 | // Note: gdata->standalone and gdata->parmloaded will be set later |
||
295 | CreateDataPointer(data); |
||
296 | if (!*data) { |
||
297 | *result = memFullErr; |
||
483 | daniel-mar | 298 | goto endmain; |
259 | daniel-mar | 299 | } |
300 | } |
||
301 | |||
479 | daniel-mar | 302 | gdata = (globals_t*)*data; |
303 | |||
259 | daniel-mar | 304 | nplanes = MIN(pb->planes,4); |
305 | |||
306 | switch (selector){ |
||
307 | case filterSelectorAbout: |
||
308 | if (!gdata) { |
||
479 | daniel-mar | 309 | // This is a temporary gdata structure just for the About dialog! |
310 | // Not to be confused with the "real" gdata during the filter invocation (containing more data). |
||
259 | daniel-mar | 311 | gdata = (globals_t*)malloc(sizeof(globals_t)); |
312 | if (!gdata) break; |
||
411 | daniel-mar | 313 | gdata->hWndMainDlg = (HWND)((PlatformData*)((AboutRecordPtr)pb)->platformData)->hwnd; // so that simplealert() works |
498 | daniel-mar | 314 | gdata->standalone = gdata->parmloaded = readPARMresource((HMODULE)hDllInstance, NULL); |
309 | daniel-mar | 315 | if (gdata->parmloaded && (gdata->parm.cbSize != PARM_SIZE) && (gdata->parm.cbSize != PARM_SIZE_PREMIERE) && (gdata->parm.cbSize != PARM_SIG_MAC)) { |
316 | if (gdata->obfusc) { |
||
492 | daniel-mar | 317 | simplealert_id(MSG_INCOMPATIBLE_OBFUSCATION_ID); |
309 | daniel-mar | 318 | } |
319 | else { |
||
492 | daniel-mar | 320 | simplealert_id(MSG_INVALID_PARAMETER_DATA_ID); |
309 | daniel-mar | 321 | } |
322 | } |
||
323 | else { |
||
324 | DoAbout((AboutRecordPtr)pb); |
||
325 | } |
||
259 | daniel-mar | 326 | free(gdata); |
327 | gdata = NULL; |
||
328 | } else { |
||
329 | DoAbout((AboutRecordPtr)pb); |
||
330 | } |
||
331 | break; |
||
332 | case filterSelectorParameters: |
||
333 | wantdialog = true; |
||
334 | break; |
||
335 | case filterSelectorPrepare: |
||
410 | daniel-mar | 336 | gdata->hWndMainDlg = 0; |
259 | daniel-mar | 337 | DoPrepare(pb); |
338 | init_symtab(predefs); // ready for parser calls |
||
339 | init_trigtab(); |
||
340 | break; |
||
341 | case filterSelectorStart: |
||
342 | if (HAS_BIG_DOC(pb)) { |
||
343 | // The BigDocument structure is required if the document is larger than 30,000 pixels |
||
344 | // It deprecates imageSize, filterRect, inRect, outRect, maskRect, floatCoord, and wholeSize. |
||
345 | // By setting it to nonzero, we communicate to Photoshop that we support the BigDocument structure. |
||
346 | pb->bigDocumentData->PluginUsing32BitCoordinates = true; |
||
347 | } |
||
348 | |||
349 | /* initialise the parameter handle that Photoshop keeps for us */ |
||
350 | if(!pb->parameters) |
||
351 | pb->parameters = PINEWHANDLE(1); // don't set initial size to 0, since some hosts (e.g. GIMP/PSPI) are incompatible with that. |
||
352 | |||
482 | daniel-mar | 353 | if (!pb->parameters) { |
483 | daniel-mar | 354 | *result = memFullErr; |
482 | daniel-mar | 355 | } |
356 | else |
||
357 | { |
||
358 | wantdialog |= checkandinitparams(pb->parameters); |
||
259 | daniel-mar | 359 | |
482 | daniel-mar | 360 | /* wantdialog = false means that we never got a Parameters call, so we're not supposed to ask user */ |
361 | if (wantdialog && (!gdata->standalone || gdata->parm.popDialog)) { |
||
362 | if (maindialog(pb)) { |
||
363 | if (!host_preserves_parameters()) { |
||
364 | /* Workaround for GIMP/PSPI, to avoid that formulas vanish when you re-open the main window. |
||
365 | The reason is a bug in PSPI: The host should preserve the value of pb->parameters, which PSPI does not do. |
||
366 | Also, all global variables are unloaded, so the plugin cannot preserve any data. |
||
367 | Workaround in FF 1.7: If the host GIMP is detected, then a special mode will be activated. |
||
368 | This mode saves the filter data into a temporary file "FilterFoundryXX.afs" and loads it |
||
369 | when the window is opened again. */ |
||
370 | // Workaround: Save settings in "FilterFoundryXX.afs" if the host does not preserve pb->parameters |
||
371 | TCHAR outfilename[MAX_PATH + 1]; |
||
372 | StandardFileReply sfr; |
||
373 | char* bakexpr[4]; |
||
374 | int i; |
||
259 | daniel-mar | 375 | |
482 | daniel-mar | 376 | sfr.sfGood = true; |
377 | sfr.sfReplacing = true; |
||
378 | sfr.sfType = PS_FILTER_FILETYPE; |
||
259 | daniel-mar | 379 | |
482 | daniel-mar | 380 | get_temp_afs(&outfilename[0], gdata->standalone, &gdata->parm); |
259 | daniel-mar | 381 | |
482 | daniel-mar | 382 | xstrcpy(sfr.sfFile.szName, outfilename); |
383 | #ifdef WIN_ENV |
||
384 | sfr.nFileExtension = (WORD)(xstrlen(outfilename) - strlen(".afs") + 1); |
||
385 | #endif |
||
386 | sfr.sfScript = 0; // FIXME: is that ok? |
||
264 | daniel-mar | 387 | |
482 | daniel-mar | 388 | // We only want the parameters (ctl,map) in the temporary .afs file |
389 | // It is important to remove the expressions, otherwise they would be |
||
390 | // revealed in the temporary files. |
||
391 | for (i = 0; i < 4; i++) { |
||
392 | bakexpr[i] = expr[i]; // moved out of the if-definition to make the compiler happy |
||
393 | } |
||
394 | if (gdata->standalone) { |
||
395 | expr[0] = _strdup("r"); |
||
396 | expr[1] = _strdup("g"); |
||
397 | expr[2] = _strdup("b"); |
||
398 | expr[3] = _strdup("a"); |
||
399 | } |
||
264 | daniel-mar | 400 | |
482 | daniel-mar | 401 | savefile_afs_pff_picotxt(&sfr); |
264 | daniel-mar | 402 | |
482 | daniel-mar | 403 | if (gdata->standalone) { |
404 | for (i = 0; i < 4; i++) { |
||
405 | if (expr[i]) free(expr[i]); |
||
406 | expr[i] = bakexpr[i]; |
||
407 | } |
||
377 | daniel-mar | 408 | } |
264 | daniel-mar | 409 | } |
482 | daniel-mar | 410 | else { |
411 | /* update stored parameters from new user settings */ |
||
412 | if (pb->parameters) |
||
413 | saveparams_afs_pff(pb->parameters); |
||
414 | } |
||
259 | daniel-mar | 415 | } |
482 | daniel-mar | 416 | else |
483 | daniel-mar | 417 | *result = userCanceledErr; |
482 | daniel-mar | 418 | } |
419 | wantdialog = false; |
||
259 | daniel-mar | 420 | } |
421 | |||
483 | daniel-mar | 422 | if(*result == noErr){ |
259 | daniel-mar | 423 | if(setup(pb)){ |
424 | DoStart(pb); |
||
425 | }else{ |
||
510 | daniel-mar | 426 | simplealert_id(MSG_SAVED_EXPR_ERR_ID); |
483 | daniel-mar | 427 | *result = filterBadParameters; |
259 | daniel-mar | 428 | } |
429 | } |
||
430 | break; |
||
431 | case filterSelectorContinue: |
||
483 | daniel-mar | 432 | *result = DoContinue(pb); |
259 | daniel-mar | 433 | break; |
434 | case filterSelectorFinish: |
||
435 | DoFinish(pb); |
||
436 | break; |
||
437 | default: |
||
483 | daniel-mar | 438 | *result = filterBadParameters; |
259 | daniel-mar | 439 | } |
440 | |||
483 | daniel-mar | 441 | endmain: |
259 | daniel-mar | 442 | |
476 | daniel-mar | 443 | // TODO: Question: Is that OK to call this every invocation, or should it be only around UI stuff? |
259 | daniel-mar | 444 | #ifdef WIN_ENV |
445 | if (activationContextUsed) DeactivateManifest(&manifestVars); |
||
446 | #endif |
||
447 | |||
448 | ExitCodeResource(); |
||
449 | } |
||
450 | |||
451 | int checkandinitparams(Handle params){ |
||
456 | daniel-mar | 452 | int i; |
453 | Boolean bUninitializedParams; |
||
259 | daniel-mar | 454 | Boolean showdialog; |
455 | |||
456 | if (!host_preserves_parameters()) { |
||
457 | // Workaround: Load settings in "FilterFoundryXX.afs" if host does not preserve pb->parameters |
||
444 | daniel-mar | 458 | TCHAR outfilename[MAX_PATH + 1]; |
259 | daniel-mar | 459 | Boolean isStandalone; |
460 | StandardFileReply sfr; |
||
264 | daniel-mar | 461 | char* bakexpr[4]; |
462 | |||
259 | daniel-mar | 463 | sfr.sfGood = true; |
464 | sfr.sfReplacing = true; |
||
465 | sfr.sfType = PS_FILTER_FILETYPE; |
||
466 | |||
467 | // We need to set gdata->standalone after loadfile(), but we must call readPARMresource() before loadfile() |
||
468 | // Reason: readPARMresource() reads parameters from the DLL while loadfile() reads parameters from the AFS file |
||
469 | // But loadfile() will reset gdata->standalone ... |
||
498 | daniel-mar | 470 | isStandalone = readPARMresource((HMODULE)hDllInstance, NULL); |
309 | daniel-mar | 471 | if (isStandalone && (gdata->parm.cbSize != PARM_SIZE) && (gdata->parm.cbSize != PARM_SIZE_PREMIERE) && (gdata->parm.cbSize != PARM_SIG_MAC)) { |
472 | if (gdata->obfusc) { |
||
492 | daniel-mar | 473 | simplealert_id(MSG_INCOMPATIBLE_OBFUSCATION_ID); |
309 | daniel-mar | 474 | } |
475 | else { |
||
492 | daniel-mar | 476 | simplealert_id(MSG_INVALID_PARAMETER_DATA_ID); |
309 | daniel-mar | 477 | } |
478 | gdata->parmloaded = false; |
||
479 | return false; |
||
480 | } |
||
259 | daniel-mar | 481 | |
373 | daniel-mar | 482 | get_temp_afs(&outfilename[0], isStandalone, &gdata->parm); |
259 | daniel-mar | 483 | |
444 | daniel-mar | 484 | xstrcpy(sfr.sfFile.szName, outfilename); |
264 | daniel-mar | 485 | #ifdef WIN_ENV |
444 | daniel-mar | 486 | sfr.nFileExtension = (WORD)(xstrlen(outfilename) - strlen(".afs") + 1); |
264 | daniel-mar | 487 | #endif |
488 | sfr.sfScript = 0; // FIXME: is that ok? |
||
259 | daniel-mar | 489 | |
264 | daniel-mar | 490 | // We only want the parameters (ctl,map) in the temporary .afs file |
491 | if (isStandalone) { |
||
377 | daniel-mar | 492 | for (i = 0; i < 4; i++) { |
493 | bakexpr[i] = my_strdup(expr[i]); |
||
494 | } |
||
264 | daniel-mar | 495 | } |
496 | |||
498 | daniel-mar | 497 | if (loadfile(&sfr, NULL)) { |
264 | daniel-mar | 498 | gdata->standalone = gdata->parmloaded = isStandalone; |
499 | |||
500 | if (isStandalone) { |
||
377 | daniel-mar | 501 | for (i = 0; i < 4; i++) { |
502 | if (expr[i]) free(expr[i]); |
||
503 | expr[i] = bakexpr[i]; |
||
504 | } |
||
259 | daniel-mar | 505 | } |
264 | daniel-mar | 506 | |
507 | return true; |
||
259 | daniel-mar | 508 | } |
509 | } |
||
510 | |||
498 | daniel-mar | 511 | if( (bUninitializedParams = !(params && readparams_afs_pff(params, NULL))) ){ |
259 | daniel-mar | 512 | /* either the parameter handle was uninitialised, |
513 | or the parameter data couldn't be read; set default values */ |
||
514 | |||
515 | // see if saved parameters exist |
||
498 | daniel-mar | 516 | gdata->standalone = gdata->parmloaded = readPARMresource((HMODULE)hDllInstance, NULL); |
309 | daniel-mar | 517 | if (gdata->parmloaded && (gdata->parm.cbSize != PARM_SIZE) && (gdata->parm.cbSize != PARM_SIZE_PREMIERE) && (gdata->parm.cbSize != PARM_SIG_MAC)) { |
518 | if (gdata->obfusc) { |
||
492 | daniel-mar | 519 | simplealert_id(MSG_INCOMPATIBLE_OBFUSCATION_ID); |
309 | daniel-mar | 520 | } |
521 | else { |
||
492 | daniel-mar | 522 | simplealert_id(MSG_INVALID_PARAMETER_DATA_ID); |
309 | daniel-mar | 523 | } |
524 | gdata->parmloaded = false; |
||
525 | return false; |
||
526 | } |
||
259 | daniel-mar | 527 | |
528 | if(!gdata->standalone){ |
||
529 | // no saved settings (not standalone) |
||
530 | for(i = 0; i < 8; ++i) |
||
456 | daniel-mar | 531 | slider[i] = (uint8_t)(i*10+100); |
259 | daniel-mar | 532 | for(i = 0; i < 4; ++i) |
533 | if(expr[i]) |
||
534 | free(expr[i]); |
||
535 | if(gpb->imageMode == plugInModeRGBColor){ |
||
536 | expr[0] = _strdup("r"); |
||
537 | expr[1] = _strdup("g"); |
||
538 | expr[2] = _strdup("b"); |
||
539 | expr[3] = _strdup("a"); |
||
540 | }else{ |
||
541 | expr[0] = _strdup("c"); |
||
542 | expr[1] = _strdup("c"); |
||
543 | expr[2] = _strdup("c"); |
||
544 | expr[3] = _strdup("c"); |
||
545 | } |
||
546 | } |
||
547 | } |
||
548 | |||
549 | // let scripting system change parameters, if we're scripted; |
||
550 | // user may want to force display of dialog during scripting playback |
||
551 | switch (ReadScriptParamsOnRead()) { |
||
552 | case SCR_SHOW_DIALOG: |
||
553 | showdialog = true; |
||
554 | break; |
||
555 | case SCR_HIDE_DIALOG: |
||
556 | showdialog = false; |
||
557 | break; |
||
558 | default: |
||
559 | case SCR_NO_SCRIPT: |
||
560 | showdialog = bUninitializedParams; |
||
561 | break; |
||
562 | } |
||
563 | |||
482 | daniel-mar | 564 | if (params) saveparams_afs_pff(params); |
259 | daniel-mar | 565 | |
566 | return showdialog; |
||
567 | } |
||
568 | |||
569 | Boolean host_preserves_parameters() { |
||
570 | #ifdef DEBUG_SIMULATE_GIMP |
||
571 | return false; |
||
572 | #endif |
||
573 | |||
574 | if (gpb->hostSig == HOSTSIG_GIMP) return false; |
||
575 | if (gpb->hostSig == HOSTSIG_IRFANVIEW) return false; |
||
576 | |||
577 | // We just assume the other hosts preserve the parameters |
||
578 | return true; |
||
579 | } |
||
580 | |||
581 | int64_t maxspace(){ |
||
582 | // Please see "Hosts.md" for details about the MaxSpace implementations of tested plugins |
||
583 | |||
584 | // Plugins that don't support MaxSpace64 shall set the field to zero; then we will use MaxSpace instead. |
||
585 | // Also check "gpb->bufferProcs->numBufferProcs" to see if 64 bit API is available |
||
586 | if ((gpb->bufferProcs->numBufferProcs >= 8) && (gpb->maxSpace64 > 0)) { |
||
587 | uint64_t maxSpace64 = gpb->maxSpace64; |
||
588 | |||
589 | return maxSpace64; |
||
590 | } else { |
||
591 | // Note: If maxSpace gets converted from Int32 to unsigned int, we can reach up to 4 GB RAM. However, after this, there will be a wrap to 0 GB again. |
||
592 | unsigned int maxSpace32 = (unsigned int) gpb->maxSpace; |
||
593 | uint64_t maxSpace64 = maxSpace32; |
||
594 | |||
595 | if (gpb->hostSig == HOSTSIG_IRFANVIEW) maxSpace64 *= 1024; // IrfanView is giving Kilobytes instead of Bytes |
||
596 | //if (gpb->hostSig == HOSTSIG_SERIF_PHOTOPLUS) maxSpace64 *= 1024; // TODO: Serif PhotoPlus also gives Kilobytes instead of bytes. But since it uses not a unique host signature, there is nothing we can do??? |
||
597 | |||
598 | return maxSpace64; |
||
599 | } |
||
600 | } |
||
601 | |||
602 | Boolean maxspace_available() { |
||
603 | // Please see "Hosts.md" for details about the MaxSpace implementations of tested plugins |
||
604 | |||
605 | // GIMP PSPI sets MaxSpace to hardcoded 100 MB |
||
606 | if (gpb->hostSig == HOSTSIG_GIMP) return false; |
||
607 | |||
608 | // HOSTSIG_PAINT_NET sets MaxSpace to hardcoded 1 GB, see https://github.com/0xC0000054/PSFilterPdn/issues/5 |
||
609 | // Comment by the host author "This was done to avoid any compatibility issues with plugins handling 2 GB - 1" |
||
610 | if (gpb->hostSig == HOSTSIG_PAINT_NET) return false; |
||
611 | |||
612 | return true; |
||
613 | } |
||
614 | |||
615 | void DoPrepare(FilterRecordPtr pb){ |
||
616 | int i; |
||
617 | |||
618 | for(i = 4; i--;){ |
||
619 | expr[i] = NULL; |
||
620 | tree[i] = NULL; |
||
482 | daniel-mar | 621 | err[i] = NULL; |
259 | daniel-mar | 622 | } |
623 | |||
624 | // Commented out by DM, 18 Dec 2018: |
||
625 | // This code did not work on systems with 8 GB RAM: |
||
626 | /* |
||
627 | long space = (pb->maxSpace*9)/10; // don't ask for more than 90% of available memory |
||
628 | |||
629 | maxSpace = 512L<<10; // this is a wild guess, actually |
||
630 | if(maxSpace > space) |
||
631 | maxSpace = space; |
||
632 | pb->maxSpace = maxSpace; |
||
633 | */ |
||
634 | |||
635 | // New variant: |
||
636 | if (maxspace_available()) { |
||
481 | daniel-mar | 637 | // don't ask for more than 90% of available memory |
638 | int64 ninetyPercent = (int64)ceil((maxspace() / 10.) * 9); |
||
639 | if ((gpb->bufferProcs->numBufferProcs >= 8) && (gpb->maxSpace64 > 0)) { |
||
640 | pb->maxSpace64 = ninetyPercent; |
||
641 | } |
||
642 | if (ninetyPercent <= 0x7FFFFFFF) { |
||
643 | pb->maxSpace = (int32)ninetyPercent; |
||
644 | } |
||
259 | daniel-mar | 645 | } |
646 | } |
||
647 | |||
456 | daniel-mar | 648 | void RequestNext(FilterRecordPtr pb){ |
259 | daniel-mar | 649 | /* Request next block of the image */ |
650 | |||
651 | pb->inLoPlane = pb->outLoPlane = 0; |
||
652 | pb->inHiPlane = pb->outHiPlane = nplanes-1; |
||
653 | |||
654 | if (HAS_BIG_DOC(pb)) { |
||
655 | // if any of the formulae involve random access to image pixels, |
||
656 | // ask for the entire image |
||
657 | if (needall) { |
||
658 | SETRECT(BIGDOC_IN_RECT(pb), 0, 0, BIGDOC_IMAGE_SIZE(pb).h, BIGDOC_IMAGE_SIZE(pb).v); |
||
659 | } else { |
||
660 | // TODO: This does not work with GIMP. So, if we are using GIMP, we should |
||
661 | // somehow always use "needall=true", and/or find out why this doesn't work |
||
662 | // with GIMP. |
||
663 | |||
664 | // otherwise, process the filtered area, by chunksize parts |
||
665 | BIGDOC_IN_RECT(pb).left = BIGDOC_FILTER_RECT(pb).left; |
||
666 | BIGDOC_IN_RECT(pb).right = BIGDOC_FILTER_RECT(pb).right; |
||
667 | BIGDOC_IN_RECT(pb).top = (int32)toprow; |
||
668 | BIGDOC_IN_RECT(pb).bottom = (int32)MIN(toprow + chunksize, BIGDOC_FILTER_RECT(pb).bottom); |
||
669 | |||
670 | if (cnvused) { |
||
671 | // cnv() needs one extra pixel in each direction |
||
672 | if (BIGDOC_IN_RECT(pb).left > 0) |
||
673 | --BIGDOC_IN_RECT(pb).left; |
||
674 | if (BIGDOC_IN_RECT(pb).right < BIGDOC_IMAGE_SIZE(pb).h) |
||
675 | ++BIGDOC_IN_RECT(pb).right; |
||
676 | if (BIGDOC_IN_RECT(pb).top > 0) |
||
677 | --BIGDOC_IN_RECT(pb).top; |
||
678 | if (BIGDOC_IN_RECT(pb).bottom < BIGDOC_IMAGE_SIZE(pb).v) |
||
679 | ++BIGDOC_IN_RECT(pb).bottom; |
||
680 | } |
||
681 | } |
||
682 | BIGDOC_OUT_RECT(pb) = BIGDOC_FILTER_RECT(pb); |
||
683 | /* |
||
684 | {char s[0x100];sprintf(s,"RequestNext needall=%d inRect=(%d,%d,%d,%d) filterRect=(%d,%d,%d,%d)", |
||
685 | needall, |
||
686 | BIGDOC_IN_RECT(pb).left,BIGDOC_IN_RECT(pb).top,BIGDOC_IN_RECT(pb).right,BIGDOC_IN_RECT(pb).bottom, |
||
687 | BIGDOC_FILTER_RECT(pb).left,BIGDOC_FILTER_RECT(pb).top,BIGDOC_FILTER_RECT(pb).right,BIGDOC_FILTER_RECT(pb).bottom);dbg(s);} |
||
688 | */ |
||
689 | } else { |
||
690 | // if any of the formulae involve random access to image pixels, |
||
691 | // ask for the entire image |
||
692 | if (needall) { |
||
693 | SETRECT(IN_RECT(pb), 0, 0, IMAGE_SIZE(pb).h, IMAGE_SIZE(pb).v); |
||
694 | } |
||
695 | else { |
||
696 | // TODO: This does not work with GIMP. So, if we are using GIMP, we should |
||
697 | // somehow always use "needall=true", and/or find out why this doesn't work |
||
698 | // with GIMP. |
||
699 | |||
700 | // otherwise, process the filtered area, by chunksize parts |
||
701 | IN_RECT(pb).left = FILTER_RECT(pb).left; |
||
702 | IN_RECT(pb).right = FILTER_RECT(pb).right; |
||
703 | IN_RECT(pb).top = (int16)toprow; |
||
704 | IN_RECT(pb).bottom = (int16)MIN(toprow + chunksize, FILTER_RECT(pb).bottom); |
||
705 | |||
706 | if (cnvused) { |
||
707 | // cnv() needs one extra pixel in each direction |
||
708 | if (IN_RECT(pb).left > 0) |
||
709 | --IN_RECT(pb).left; |
||
710 | if (IN_RECT(pb).right < IMAGE_SIZE(pb).h) |
||
711 | ++IN_RECT(pb).right; |
||
712 | if (IN_RECT(pb).top > 0) |
||
713 | --IN_RECT(pb).top; |
||
714 | if (IN_RECT(pb).bottom < IMAGE_SIZE(pb).v) |
||
715 | ++IN_RECT(pb).bottom; |
||
716 | } |
||
717 | } |
||
718 | OUT_RECT(pb) = FILTER_RECT(pb); |
||
719 | /* |
||
720 | {char s[0x100];sprintf(s,"RequestNext needall=%d inRect=(%d,%d,%d,%d) filterRect=(%d,%d,%d,%d)", |
||
721 | needall, |
||
722 | IN_RECT(pb).left,IN_RECT(pb).top,IN_RECT(pb).right,IN_RECT(pb).bottom, |
||
723 | FILTER_RECT(pb).left,FILTER_RECT(pb).top,FILTER_RECT(pb).right,FILTER_RECT(pb).bottom);dbg(s);} |
||
724 | */ |
||
725 | } |
||
726 | } |
||
727 | |||
728 | void DoStart(FilterRecordPtr pb){ |
||
264 | daniel-mar | 729 | /* Global variable "needall": if src() or rad() functions are used, random access to the image data is required, |
730 | so we must request the entire image in a single chunk, otherwise we will use chunksize "CHUNK_ROWS". */ |
||
259 | daniel-mar | 731 | if (HAS_BIG_DOC(pb)) { |
732 | chunksize = needall ? (BIGDOC_FILTER_RECT(pb).bottom - BIGDOC_FILTER_RECT(pb).top) : CHUNK_ROWS; |
||
733 | toprow = BIGDOC_FILTER_RECT(pb).top; |
||
734 | } else { |
||
735 | chunksize = needall ? (FILTER_RECT(pb).bottom - FILTER_RECT(pb).top) : CHUNK_ROWS; |
||
736 | toprow = FILTER_RECT(pb).top; |
||
737 | } |
||
456 | daniel-mar | 738 | RequestNext(pb); |
259 | daniel-mar | 739 | } |
740 | |||
741 | OSErr DoContinue(FilterRecordPtr pb){ |
||
742 | OSErr e = noErr; |
||
743 | long outoffset; |
||
744 | |||
745 | if (HAS_BIG_DOC(pb)) { |
||
746 | VRect fr; |
||
747 | if (needall) { |
||
748 | fr = BIGDOC_FILTER_RECT(pb); // filter whole selection at once |
||
749 | } else if (cnvused) { |
||
750 | // we've requested one pixel extra all around |
||
751 | // (see RequestNext()), just for access purposes. But filter |
||
752 | // original selection only. |
||
753 | fr.left = BIGDOC_FILTER_RECT(pb).left; |
||
754 | fr.right = BIGDOC_FILTER_RECT(pb).right; |
||
755 | fr.top = toprow; |
||
756 | fr.bottom = MIN(toprow + chunksize, BIGDOC_FILTER_RECT(pb).bottom); |
||
757 | } else { // filter whatever portion we've been given |
||
758 | fr = BIGDOC_IN_RECT(pb); |
||
759 | } |
||
760 | |||
761 | outoffset = (long)pb->outRowBytes * (fr.top - BIGDOC_OUT_RECT(pb).top) |
||
762 | + (long)nplanes * (fr.left - BIGDOC_OUT_RECT(pb).left); |
||
763 | |||
764 | if (!(e = process_scaled_bigdoc(pb, true, fr, fr, |
||
765 | (Ptr)pb->outData + outoffset, pb->outRowBytes, 1.))) |
||
766 | { |
||
767 | toprow += chunksize; |
||
768 | if (toprow < BIGDOC_FILTER_RECT(pb).bottom) |
||
456 | daniel-mar | 769 | RequestNext(pb); |
259 | daniel-mar | 770 | else { |
771 | SETRECT(BIGDOC_IN_RECT(pb), 0, 0, 0, 0); |
||
772 | BIGDOC_OUT_RECT(pb) = BIGDOC_MASK_RECT(pb) = BIGDOC_IN_RECT(pb); |
||
773 | } |
||
774 | } |
||
775 | } else { |
||
776 | Rect fr; |
||
777 | if (needall) { |
||
778 | fr = FILTER_RECT(pb); // filter whole selection at once |
||
779 | } else if (cnvused) { |
||
780 | // we've requested one pixel extra all around |
||
781 | // (see RequestNext()), just for access purposes. But filter |
||
782 | // original selection only. |
||
783 | fr.left = FILTER_RECT(pb).left; |
||
784 | fr.right = FILTER_RECT(pb).right; |
||
785 | fr.top = toprow; |
||
786 | fr.bottom = MIN(toprow + chunksize, FILTER_RECT(pb).bottom); |
||
787 | } else { // filter whatever portion we've been given |
||
788 | fr = IN_RECT(pb); |
||
789 | } |
||
790 | |||
791 | outoffset = (long)pb->outRowBytes*(fr.top - OUT_RECT(pb).top) |
||
792 | + (long)nplanes*(fr.left - OUT_RECT(pb).left); |
||
793 | |||
794 | if(!(e = process_scaled_olddoc(pb, true, fr, fr, |
||
795 | (Ptr)pb->outData+outoffset, pb->outRowBytes, 1.))) |
||
796 | { |
||
797 | toprow += chunksize; |
||
798 | if(toprow < FILTER_RECT(pb).bottom) |
||
456 | daniel-mar | 799 | RequestNext(pb); |
259 | daniel-mar | 800 | else{ |
801 | SETRECT(IN_RECT(pb),0,0,0,0); |
||
802 | OUT_RECT(pb) = MASK_RECT(pb) = IN_RECT(pb); |
||
803 | } |
||
804 | } |
||
805 | } |
||
806 | return e; |
||
807 | } |
||
808 | |||
809 | void DoFinish(FilterRecordPtr pb){ |
||
810 | int i; |
||
811 | |||
433 | daniel-mar | 812 | UNREFERENCED_PARAMETER(pb); |
813 | |||
259 | daniel-mar | 814 | WriteScriptParamsOnRead(); |
815 | |||
816 | for(i = 4; i--;){ |
||
817 | freetree(tree[i]); |
||
818 | if(expr[i]) free(expr[i]); |
||
819 | } |
||
820 | } |
||
379 | daniel-mar | 821 | |
430 | daniel-mar | 822 | InternalState saveInternalState() { |
823 | InternalState ret; |
||
379 | daniel-mar | 824 | int i; |
825 | |||
826 | ret.bak_obfusc = gdata->obfusc; |
||
827 | ret.bak_standalone = gdata->standalone; |
||
828 | ret.bak_parmloaded = gdata->parmloaded; |
||
829 | memcpy(&ret.bak_parm, &gdata->parm, sizeof(PARM_T)); |
||
830 | for (i = 0; i < 4; i++) ret.bak_expr[i] = my_strdup(expr[i]); |
||
831 | for (i = 0; i < 8; i++) ret.bak_slider[i] = slider[i]; |
||
832 | |||
833 | return ret; |
||
834 | } |
||
835 | |||
430 | daniel-mar | 836 | void restoreInternalState(InternalState state) { |
379 | daniel-mar | 837 | int i; |
838 | gdata->obfusc = state.bak_obfusc; |
||
839 | gdata->standalone = state.bak_standalone; |
||
840 | gdata->parmloaded = state.bak_parmloaded; |
||
841 | memcpy(&gdata->parm, &state.bak_parm, sizeof(PARM_T)); |
||
842 | for (i = 0; i < 4; i++) { |
||
843 | if (expr[i]) free(expr[i]); |
||
844 | expr[i] = state.bak_expr[i]; |
||
845 | } |
||
846 | for (i = 0; i < 8; i++) { |
||
847 | slider[i] = state.bak_slider[i]; |
||
848 | } |
||
849 | } |