Subversion Repositories filter_foundry

Rev

Rev 387 | Rev 393 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 387 Rev 389
Line 38... Line 38...
38
                PIUNLOCKHANDLE(h);
38
                PIUNLOCKHANDLE(h);
39
        }
39
        }
40
        return e;
40
        return e;
41
}
41
}
42
 
42
 
43
OSErr saveparams(Handle h){
43
OSErr saveparams_afs_pff(Handle h){
44
        char outbuf[CHOPLINES*2+2],*q,*p,*r,*start;
44
        char outbuf[CHOPLINES*2+2],*q,*p,*r,*start;
45
        size_t n, chunk, j;
45
        size_t n, chunk, j;
46
        int i;
46
        int i;
47
        OSErr e;
47
        OSErr e;
48
        size_t est;
48
        size_t est;
49
        static char afs_sig[] = "%RGB-1.0\r";
49
        static char afs_sig[] = "%RGB-1.0\r";
50
 
50
 
51
        if(!h) DBG("saveparams: Null handle!");
51
        if(!h) DBG("saveparams_afs_pff: Null handle!");
52
 
52
 
53
        est = strlen(expr[0]) + strlen(expr[1]) + strlen(expr[2]) + strlen(expr[3]);
53
        est = strlen(expr[0]) + strlen(expr[1]) + strlen(expr[2]) + strlen(expr[3]);
54
        // do not be tempted to combine into one expression: 'est' is referenced below
54
        // do not be tempted to combine into one expression: 'est' is referenced below
55
        est += strlen(afs_sig) + est/CHOPLINES + 4 + 8*6 + 64 /*slop*/ ;
55
        est += strlen(afs_sig) + est/CHOPLINES + 4 + 8*6 + 64 /*slop*/ ;
56
 
56
 
Line 96... Line 96...
96
        }
96
        }
97
 
97
 
98
        return e;
98
        return e;
99
}
99
}
100
 
100
 
-
 
101
OSErr saveparams_picotxt(Handle h, Boolean useparm) {
-
 
102
        extern int ctls[], maps[];
-
 
103
 
-
 
104
        char * p, *start;
-
 
105
        int i;
-
 
106
        OSErr e;
-
 
107
        size_t est;
-
 
108
 
-
 
109
        if (!h) DBG("saveparams_picotxt: Null handle!");
-
 
110
 
-
 
111
        est = strlen(expr[0]) + strlen(expr[1]) + strlen(expr[2]) + strlen(expr[3]);
-
 
112
        // do not be tempted to combine into one expression: 'est' is referenced below
-
 
113
        est += 16000;
-
 
114
 
-
 
115
        PIUNLOCKHANDLE(h); // should not be necessary
-
 
116
        if (!(e = PISETHANDLESIZE(h, (int32)(est))) && (p = start = PILOCKHANDLE(h, false))) {
-
 
117
                checksliders(4, ctls, maps);
-
 
118
 
-
 
119
                // Metadata
-
 
120
                p += sprintf(p, "Category: %s\r\n", useparm ? INPLACEP2CSTR(gdata->parm.category) : "...");
-
 
121
                p += sprintf(p, "Title: %s\r\n", useparm ? INPLACEP2CSTR(gdata->parm.title) : "...");
-
 
122
                p += sprintf(p, "Copyright: %s\r\n", useparm ? INPLACEP2CSTR(gdata->parm.copyright) : "...");
-
 
123
                p += sprintf(p, "Author: %s\r\n", useparm ? INPLACEP2CSTR(gdata->parm.author) : "...");
-
 
124
                p += sprintf(p, "Filename: %s\r\n", useparm ? "Untitled.8bf" : "Untitled.8bf"); // TODO: get .txt filename and change .txt to .8bf
-
 
125
                p += sprintf(p, "\r\n");
-
 
126
                p += sprintf(p, "R: %s\r\n", useparm ? (char*)gdata->parm.formula[0] : expr[0]);
-
 
127
                p += sprintf(p, "\r\n");
-
 
128
                p += sprintf(p, "G: %s\r\n", useparm ? (char*)gdata->parm.formula[1] : expr[1]);
-
 
129
                p += sprintf(p, "\r\n");
-
 
130
                p += sprintf(p, "B: %s\r\n", useparm ? (char*)gdata->parm.formula[2] : expr[2]);
-
 
131
                p += sprintf(p, "\r\n");
-
 
132
                p += sprintf(p, "A: %s\r\n", useparm ? (char*)gdata->parm.formula[3] : expr[3]);
-
 
133
                p += sprintf(p, "\r\n");
-
 
134
                if (useparm) {
-
 
135
                        for (i = 0; i < 8; i++) {
-
 
136
                                if (gdata->parm.ctl_used[i]) {
-
 
137
                                        p += sprintf(p, "ctl[%d]: %s\r\n", i, INPLACEP2CSTR(gdata->parm.ctl[i]));
-
 
138
                                }
-
 
139
                        }
-
 
140
                        for (i = 0; i < 4; i++) {
-
 
141
                                if (gdata->parm.map_used[i]) {
-
 
142
                                        p += sprintf(p, "map[%d]: %s\r\n", i, INPLACEP2CSTR(gdata->parm.map[i]));
-
 
143
                                }
-
 
144
                        }
-
 
145
                        p += sprintf(p, "\r\n");
-
 
146
                        for (i = 0; i < 8; i++) {
-
 
147
                                if (gdata->parm.ctl_used[i]) {
-
 
148
                                        p += sprintf(p, "val[%d]: %d\r\n", i, gdata->parm.val[i]);
-
 
149
                                }
-
 
150
                        }
-
 
151
                        /*
-
 
152
                        p += sprintf(p, "\r\n");
-
 
153
                        for (i = 0; i < 8; i++) {
-
 
154
                                if (gdata->parm.ctl_used[i]) {
-
 
155
                                        p += sprintf(p, "def[%d]: %d\r\n", i, gdata->parm.val[i]);
-
 
156
                                }
-
 
157
                        }
-
 
158
                        */
-
 
159
                }
-
 
160
                else {
-
 
161
                        for (i = 0; i < 8; i++) {
-
 
162
                                if (ctls[i]) {
-
 
163
                                        p += sprintf(p, "ctl[%d]: %s\r\n", i, "...");
-
 
164
                                }
-
 
165
                        }
-
 
166
                        for (i = 0; i < 4; i++) {
-
 
167
                                if (maps[i]) {
-
 
168
                                        p += sprintf(p, "map[%d]: %s\r\n", i, "...");
-
 
169
                                }
-
 
170
                        }
-
 
171
                        p += sprintf(p, "\r\n");
-
 
172
                        for (i = 0; i < 8; i++) {
-
 
173
                                if (ctls[i]) {
-
 
174
                                        p += sprintf(p, "val[%d]: %d\r\n", i, slider[i]);
-
 
175
                                }
-
 
176
                        }
-
 
177
                        /*
-
 
178
                        p += sprintf(p, "\r\n");
-
 
179
                        for (i = 0; i < 8; i++) {
-
 
180
                                if (ctls[i]) {
-
 
181
                                        p += sprintf(p, "def[%d]: %s\r\n", i, "...");
-
 
182
                                }
-
 
183
                        }
-
 
184
                        */
-
 
185
                }
-
 
186
 
-
 
187
                PIUNLOCKHANDLE(h);
-
 
188
                e = PISETHANDLESIZE(h, (int32)(p - start)); // could ignore this error, maybe
-
 
189
        }
-
 
190
 
-
 
191
        return e;
-
 
192
}
-
 
193
 
101
OSErr savehandleintofile(Handle h,FILEREF r){
194
OSErr savehandleintofile(Handle h,FILEREF r){
102
        Ptr p = PILOCKHANDLE(h,false);
195
        Ptr p = PILOCKHANDLE(h,false);
103
        long n = PIGETHANDLESIZE(h);
196
        long n = PIGETHANDLESIZE(h);
104
        OSErr e = FSWrite(r,&n,p);
197
        OSErr e = FSWrite(r,&n,p);
105
        PIUNLOCKHANDLE(h);
198
        PIUNLOCKHANDLE(h);
106
        return e;
199
        return e;
107
}
200
}
108
 
201
 
109
Boolean savefile_afs_pff(StandardFileReply *sfr){
202
Boolean savefile_afs_pff_picotxt(StandardFileReply *sfr){
110
        FILEREF r;
203
        FILEREF r;
111
        Handle h;
204
        Handle h;
112
        Boolean res = false;
205
        Boolean res = false;
113
        char *reasonstr = _strdup("");
206
        char *reasonstr = _strdup("");
114
 
207
 
115
        FSpDelete(&sfr->sfFile);
208
        FSpDelete(&sfr->sfFile);
116
        if(FSpCreate(&sfr->sfFile,SIG_SIMPLETEXT,TEXT_FILETYPE,sfr->sfScript) == noErr)
209
        if(FSpCreate(&sfr->sfFile,SIG_SIMPLETEXT,TEXT_FILETYPE,sfr->sfScript) == noErr)
117
                if(FSpOpenDF(&sfr->sfFile,fsWrPerm,&r) == noErr){
210
                if(FSpOpenDF(&sfr->sfFile,fsWrPerm,&r) == noErr){
118
 
211
 
-
 
212
                        if (fileHasExtension(sfr, ".txt")) {
-
 
213
                                // PluginCommander .txt
-
 
214
                                if ((h = PINEWHANDLE(1))) { // don't set initial size to 0, since some hosts (e.g. GIMP/PSPI) are incompatible with that.
-
 
215
                                        res = !(saveparams_picotxt(h,false) || savehandleintofile(h, r));
-
 
216
                                        PIDISPOSEHANDLE(h);
-
 
217
                                }
-
 
218
                        }
-
 
219
 
-
 
220
                        if ((fileHasExtension(sfr, ".afs")) || (fileHasExtension(sfr, ".pff"))) {
119
                        if (fileHasExtension(sfr, ".pff")) {
221
                                if (fileHasExtension(sfr, ".pff")) {
120
                                // If it is a Premiere settings file, we need to swap the channels red and blue
222
                                        // If it is a Premiere settings file, we need to swap the channels red and blue
121
                                // We just swap the pointers!
223
                                        // We just swap the pointers!
122
                                char* tmp;
224
                                        char* tmp;
123
                                tmp = expr[0];
225
                                        tmp = expr[0];
124
                                expr[0] = expr[2];
226
                                        expr[0] = expr[2];
125
                                expr[2] = tmp;
227
                                        expr[2] = tmp;
126
                        }
228
                                }
127
 
229
 
128
                        if( (h = PINEWHANDLE(1)) ){ // don't set initial size to 0, since some hosts (e.g. GIMP/PSPI) are incompatible with that.
230
                                if ((h = PINEWHANDLE(1))) { // don't set initial size to 0, since some hosts (e.g. GIMP/PSPI) are incompatible with that.
129
                                res = !(saveparams(h) || savehandleintofile(h,r));
231
                                        res = !(saveparams_afs_pff(h) || savehandleintofile(h, r));
130
                                PIDISPOSEHANDLE(h);
232
                                        PIDISPOSEHANDLE(h);
131
                        }
233
                                }
132
 
234
 
133
                        if (fileHasExtension(sfr, ".pff")) {
235
                                if (fileHasExtension(sfr, ".pff")) {
134
                                // Swap back so that the other program stuff will work normally again
236
                                        // Swap back so that the other program stuff will work normally again
135
                                char* tmp;
237
                                        char* tmp;
136
                                tmp = expr[0];
238
                                        tmp = expr[0];
137
                                expr[0] = expr[2];
239
                                        expr[0] = expr[2];
138
                                expr[2] = tmp;
240
                                        expr[2] = tmp;
139
                        }
241
                                }
-
 
242
                        }
140
 
243
 
141
                        FSClose(r);
244
                        FSClose(r);
142
                }else reasonstr = (_strdup("Could not open the file."));
245
                }else reasonstr = (_strdup("Could not open the file."));
143
        else reasonstr = (_strdup("Could not create the file."));
246
        else reasonstr = (_strdup("Could not create the file."));
144
 
247