Subversion Repositories filter_foundry

Rev

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

Rev 89 Rev 94
Line 1... Line 1...
1
/*
1
/*
2
    This file is part of Filter Foundry, a filter plugin for Adobe Photoshop
2
    This file is part of Filter Foundry, a filter plugin for Adobe Photoshop
3
    Copyright (C) 2003-5 Toby Thain, toby@telegraphics.com.au
3
    Copyright (C) 2003-7 Toby Thain, toby@telegraphics.com.au
4
 
4
 
5
    This program is free software; you can redistribute it and/or modify
5
    This program is free software; you can redistribute it and/or modify
6
    it under the terms of the GNU General Public License as published by  
6
    it under the terms of the GNU General Public License as published by  
7
    the Free Software Foundation; either version 2 of the License, or
7
    the Free Software Foundation; either version 2 of the License, or
8
    (at your option) any later version.
8
    (at your option) any later version.
Line 17... Line 17...
17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
*/
18
*/
19
 
19
 
20
/* This is PLATFORM INDEPENDENT user interface code - mainly dialog logic */
20
/* This is PLATFORM INDEPENDENT user interface code - mainly dialog logic */
21
 
21
 
-
 
22
#include "preview.h"
-
 
23
 
-
 
24
#ifdef MAC_ENV
22
#include "ff.h"
25
        #include <fp.h>
-
 
26
#endif
-
 
27
#include <math.h>
23
 
28
 
24
#include "PIProperties.h"
29
#include "PIProperties.h"
25
 
30
 
26
#include "node.h"
-
 
27
#include "funcs.h"
-
 
28
#include "y.tab.h"
-
 
29
#include "choosefile.h"
31
extern FilterRecordPtr gpb;
30
 
32
 
31
PSPixelMap preview_pmap;
33
PSPixelMap preview_pmap;
32
PSPixelMask preview_pmask;
34
PSPixelMask preview_pmask;
33
Handle preview_handle;
35
Handle preview_handle;
34
UIRECT preview_rect;
36
UIRECT preview_rect;
35
int preview_w,preview_h,previewerr = false;
37
int preview_w,preview_h,previewerr = false,needall = false,needinput = true;
36
Point preview_scroll;
38
Point preview_scroll;
37
Boolean preview_complete = false;
39
Boolean preview_complete = false;
-
 
40
double zoomfactor,fitzoom;
-
 
41
 
-
 
42
Boolean setup_preview(FilterRecordPtr pb, int nplanes){
-
 
43
        double zh,zv;
38
 
44
 
39
Boolean setup_preview(FilterRecordPtr pb){
-
 
40
        if(pb->displayPixels && pb->advanceState){
45
        if(pb->displayPixels && pb->advanceState){
41
                preview_w = MIN(preview_rect.right - preview_rect.left - 2,
46
                preview_w = MIN(preview_rect.right - preview_rect.left - 2,
42
                                                pb->filterRect.right - pb->filterRect.left);
47
                                                pb->filterRect.right - pb->filterRect.left);
43
                preview_h = MIN(preview_rect.bottom - preview_rect.top - 2,
48
                preview_h = MIN(preview_rect.bottom - preview_rect.top - 2,
44
                                                pb->filterRect.bottom - pb->filterRect.top);
49
                                                pb->filterRect.bottom - pb->filterRect.top);
-
 
50
                zh = (pb->filterRect.right - pb->filterRect.left)/(double)preview_w;
-
 
51
                zv = (pb->filterRect.bottom - pb->filterRect.top)/(double)preview_h;
-
 
52
                fitzoom = zh > zv ? zh : zv;
45
       
53
       
46
                preview_pmap.version = 1;
54
                preview_pmap.version = 1;
47
                preview_pmap.bounds.left = preview_pmap.bounds.top = 0;
55
                preview_pmap.bounds.left = preview_pmap.bounds.top = 0;
48
                preview_pmap.bounds.right = preview_w;
56
                preview_pmap.bounds.right = preview_w;
49
                preview_pmap.bounds.bottom = preview_h;
57
                preview_pmap.bounds.bottom = preview_h;
50
                preview_pmap.imageMode = gpb->imageMode;
58
                preview_pmap.imageMode = pb->imageMode;
51
                preview_pmap.rowBytes = nplanes*preview_w;
59
                preview_pmap.rowBytes = nplanes*preview_w;
52
                preview_pmap.colBytes = nplanes;
60
                preview_pmap.colBytes = nplanes;
53
                preview_pmap.planeBytes = 1; /*interleaved*/
61
                preview_pmap.planeBytes = 1; /*interleaved*/
54
        //      preview_pmap.baseAddr = preview_data;
62
        //      preview_pmap.baseAddr = preview_data;
55
        /* baseAddr must be set before using pixelmap */
63
        /* baseAddr must be set before using pixelmap */
Line 57... Line 65...
57
                //---------------------------------------------------------------------------
65
                //---------------------------------------------------------------------------
58
                // Fields new in version 1:
66
                // Fields new in version 1:
59
                //---------------------------------------------------------------------------   
67
                //---------------------------------------------------------------------------   
60
                preview_pmap.mat = NULL;
68
                preview_pmap.mat = NULL;
61
               
69
               
62
                if( (gpb->imageMode == plugInModeRGBColor && nplanes == 4)
70
                if( (pb->imageMode == plugInModeRGBColor && nplanes == 4)
63
                 || (gpb->imageMode == plugInModeLabColor && nplanes == 4)
71
                 || (pb->imageMode == plugInModeLabColor && nplanes == 4)
64
                 || (gpb->imageMode == plugInModeGrayScale && nplanes == 2)
72
                 || (pb->imageMode == plugInModeGrayScale && nplanes == 2)
65
                 || (gpb->imageMode == plugInModeDuotone && nplanes == 2) )
73
                 || (pb->imageMode == plugInModeDuotone && nplanes == 2) )
66
                {
74
                {
67
                        preview_pmask.next = NULL;
75
                        preview_pmask.next = NULL;
68
        //              preview_pmask.maskData = preview_data+3;
76
        //              preview_pmask.maskData = preview_data+3;
69
                        preview_pmask.rowBytes = preview_pmap.rowBytes;
77
                        preview_pmask.rowBytes = preview_pmap.rowBytes;
70
                        preview_pmask.colBytes = nplanes;
78
                        preview_pmask.colBytes = nplanes;
Line 91... Line 99...
91
                preview_handle = NULL;
99
                preview_handle = NULL;
92
        }
100
        }
93
}
101
}
94
 
102
 
95
void recalc_preview(FilterRecordPtr pb,DIALOGREF dp){
103
void recalc_preview(FilterRecordPtr pb,DIALOGREF dp){
96
        extern int srcradused,needinput;
-
 
97
        extern double zoomfactor;
-
 
98
        OSErr e;
104
        OSErr e;
99
        int j,n,scaledw,scaledh,imgw,imgh;
105
        int j,n,scaledw,scaledh,imgw,imgh;
100
        Rect r,outRect;
106
        Rect r,outRect;
101
        Ptr outrow;
107
        Ptr outrow;
102
 
108
 
Line 141... Line 147...
141
                else if(r.top > pb->filterRect.bottom-scaledh)
147
                else if(r.top > pb->filterRect.bottom-scaledh)
142
                        r.top = pb->filterRect.bottom - scaledh;
148
                        r.top = pb->filterRect.bottom - scaledh;
143
                r.bottom = r.top + scaledh;
149
                r.bottom = r.top + scaledh;
144
 
150
 
145
                /* if formulae need random access to image - src(), rad() - we must request entire area: */
151
                /* if formulae need random access to image - src(), rad() - we must request entire area: */
146
                if(srcradused){
152
                if(needall)
147
                        SETRECT(pb->inRect,0,0,pb->imageSize.h,pb->imageSize.v);
153
                        SETRECT(pb->inRect,0,0,pb->imageSize.h,pb->imageSize.v);
148
                }else
154
                else
149
                        pb->inRect = r;
155
                        pb->inRect = r;
150
               
156
               
151
                pb->outRect = pb->inRect;
157
                pb->outRect = pb->inRect;
152
                SETRECT(pb->maskRect,0,0,0,0);
158
                SETRECT(pb->maskRect,0,0,0,0);
153
                pb->inLoPlane = pb->outLoPlane = 0;
159
                pb->inLoPlane = pb->outLoPlane = 0;
154
                pb->inHiPlane = pb->outHiPlane = nplanes-1;
160
                pb->inHiPlane = pb->outHiPlane = nplanes-1;
155
                               
161
 
156
//dbg("recalc_preview: about to call advanceState()");
-
 
157
 
-
 
158
                if( !needinput || !(e = pb->advanceState()) ){
162
                if( !needinput || !(e = pb->advanceState()) ){
159
                        Ptr outptr = PILOCKHANDLE(preview_handle,false);
163
                        Ptr outptr = PILOCKHANDLE(preview_handle,false);
160
                        int blankrows = (preview_h - imgh)/2,
164
                        int blankrows = (preview_h - imgh)/2,
161
                                blankcols = (preview_w - imgw)/2,
165
                                blankcols = (preview_w - imgw)/2,
162
                                pmrb = preview_pmap.rowBytes;
166
                                pmrb = preview_pmap.rowBytes;
163
 
167
 
164
                        INITRANDSEED();
168
                        evalinit();
165
//dbg("recalc_preview: about to call process()");
-
 
166
                               
169
                               
167
                        SETRECT(outRect,0,0,imgw,imgh);
170
                        SETRECT(outRect,0,0,imgw,imgh);
168
                       
171
                       
169
                        e = process_scaled(pb, false, &r, &outRect,
172
                        e = process_scaled(pb, false, &r, &outRect,
170
                                        outptr + pmrb*blankrows + nplanes*blankcols, pmrb, zoomfactor);
173
                                        outptr + pmrb*blankrows + nplanes*blankcols, pmrb, zoomfactor);
Line 208... Line 211...
208
                                }
211
                                }
209
#endif
212
#endif
210
                        }
213
                        }
211
 
214
 
212
                        PIUNLOCKHANDLE(preview_handle);
215
                        PIUNLOCKHANDLE(preview_handle);
213
 
-
 
214
                }/*else{
-
 
215
                        char s[0x100];
-
 
216
                        sprintf(s,"recalc_preview: advanceState failed (%d)\n\
-
 
217
inRect=(%d,%d,%d,%d) filterRect=(%d,%d,%d,%d) inLoPlane=%d inHiPlane=%d ",
-
 
218
                                e,
-
 
219
                                pb->inRect.left,pb->inRect.top,pb->inRect.right,pb->inRect.bottom,
-
 
220
                                pb->filterRect.left,pb->filterRect.top,pb->filterRect.right,pb->filterRect.bottom,
-
 
221
                                pb->inLoPlane,pb->inHiPlane);
-
 
222
                        dbg(s);
-
 
223
                }*/
216
                }
224
 
217
 
225
                if(e && !previewerr){
218
                if(e && !previewerr){
226
                        alertuser("Could not build preview at chosen zoom level.",
219
                        alertuser("Could not build preview at chosen zoom level.",
227
                                e == memFullErr && !srcradused ? "The image is too large for available memory. Try zooming in.\nIf that does not help, Cancel and retry the filter." : "");
220
                                e == memFullErr && !needall ? "The image is too large for available memory. Try zooming in.\nIf that does not help, Cancel and retry the filter." : "");
228
                        previewerr = true;
221
                        previewerr = true;
229
                }
222
                }
230
 
223
 
231
        }
224
        }
232
}
225
}
Line 245... Line 238...
245
                imagebounds.top = (preview_rect.top + preview_rect.bottom - preview_h)/2;
238
                imagebounds.top = (preview_rect.top + preview_rect.bottom - preview_h)/2;
246
                imagebounds.right = imagebounds.left + preview_w;
239
                imagebounds.right = imagebounds.left + preview_w;
247
                imagebounds.bottom = imagebounds.top + preview_h;
240
                imagebounds.bottom = imagebounds.top + preview_h;
248
 
241
 
249
                preview_pmap.baseAddr = imageptr;
242
                preview_pmap.baseAddr = imageptr;
250
                preview_pmask.maskData = imageptr+3;
243
                preview_pmask.maskData = imageptr+3; // FIXME: is this offset correct for all modes?!
251
 
244
 
252
                if(gpb->propertyProcs->getPropertyProc){
245
                if(gpb->propertyProcs->getPropertyProc){
253
                        gpb->propertyProcs->getPropertyProc(kPhotoshopSignature,propWatchSuspension,0,&watchsusp,NULL);
246
                        gpb->propertyProcs->getPropertyProc(kPhotoshopSignature,propWatchSuspension,0,&watchsusp,NULL);
254
                        gpb->propertyProcs->setPropertyProc(kPhotoshopSignature,propWatchSuspension,0,watchsusp+1,NULL);
247
                        gpb->propertyProcs->setPropertyProc(kPhotoshopSignature,propWatchSuspension,0,watchsusp+1,NULL);
255
                }
248
                }