Subversion Repositories filter_foundry

Rev

Rev 484 | Rev 486 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
259 daniel-mar 1
/*
2
    This file is part of Filter Foundry, a filter plugin for Adobe Photoshop
3
    Copyright (C) 2003-2009 Toby Thain, toby@telegraphics.com.au
4
    Copyright (C) 2018-2021 Daniel Marschall, ViaThinkSoft
5
 
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.
10
 
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.
15
 
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
19
*/
20
 
21
/* This is PLATFORM INDEPENDENT user interface code - mainly dialog logic */
22
 
23
#include "ff.h"
24
#include "preview.h"
25
 
26
#ifdef MAC_ENV
27
        #include <fp.h>
28
#endif
29
#include <math.h>
30
 
31
#include "PIProperties.h"
32
 
33
extern FilterRecordPtr gpb;
34
 
35
PSPixelMap preview_pmap;
36
PSPixelMask preview_pmask;
485 daniel-mar 37
FFBuffer preview_handle;
259 daniel-mar 38
UIRECT preview_rect;
39
int preview_w,preview_h,previewerr = false,needall = false,needinput = true;
40
Point preview_scroll;
41
Boolean preview_complete = false;
42
double zoomfactor,fitzoom;
43
 
44
Boolean setup_preview(FilterRecordPtr pb, int nplanes){
45
        double zh,zv;
46
 
47
        if(pb->displayPixels && pb->advanceState){
48
                // Possibility 1: Only the part of the preview rect is filled with background color,
49
                // which can be occupied by image data if zoom factor becomes 100%
50
                /*
51
                if (HAS_BIG_DOC(pb)) {
52
                        preview_w = MIN(preview_rect.right - preview_rect.left,
53
                                                        BIGDOC_FILTER_RECT(pb).right - BIGDOC_FILTER_RECT(pb).left);
54
                        preview_h = MIN(preview_rect.bottom - preview_rect.top,
55
                                                        BIGDOC_FILTER_RECT(pb).bottom - BIGDOC_FILTER_RECT(pb).top);
56
                } else {
57
                        preview_w = MIN(preview_rect.right - preview_rect.left,
58
                                                        FILTER_RECT(pb).right - FILTER_RECT(pb).left);
59
                        preview_h = MIN(preview_rect.bottom - preview_rect.top,
60
                                                        FILTER_RECT(pb).bottom - FILTER_RECT(pb).top);
61
                }
62
                */
63
                // Possibility 2: The whole preview rect is always filled with the background color,
64
                // so you can easily see what is the preview area and what is not
65
                preview_w = preview_rect.right - preview_rect.left;
66
                preview_h = preview_rect.bottom - preview_rect.top;
67
 
68
                if (HAS_BIG_DOC(pb)) {
69
                        zh = ((double)BIGDOC_FILTER_RECT(pb).right - (double)BIGDOC_FILTER_RECT(pb).left) / (double)preview_w;
70
                        zv = ((double)BIGDOC_FILTER_RECT(pb).bottom - (double)BIGDOC_FILTER_RECT(pb).top) / (double)preview_h;
71
                } else {
72
                        zh = ((double)FILTER_RECT(pb).right - (double)FILTER_RECT(pb).left) / (double)preview_w;
73
                        zv = ((double)FILTER_RECT(pb).bottom - (double)FILTER_RECT(pb).top) / (double)preview_h;
74
                }
75
                fitzoom = zh > zv ? zh : zv;
76
 
77
                preview_pmap.version = 1;
78
                preview_pmap.bounds.left = preview_pmap.bounds.top = 0;
79
                preview_pmap.bounds.right = preview_w;
80
                preview_pmap.bounds.bottom = preview_h;
81
                preview_pmap.imageMode = pb->imageMode;
82
                preview_pmap.rowBytes = nplanes*preview_w;
83
                preview_pmap.colBytes = nplanes;
84
                preview_pmap.planeBytes = 1; /*interleaved*/
85
        //      preview_pmap.baseAddr = preview_data;
86
        /* baseAddr must be set before using pixelmap */
87
 
88
                //---------------------------------------------------------------------------
89
                // Fields new in version 1:
90
                //---------------------------------------------------------------------------
91
                preview_pmap.mat = NULL;
92
 
93
                if( (pb->imageMode == plugInModeRGBColor && nplanes == 4)
94
                 || (pb->imageMode == plugInModeLabColor && nplanes == 4)
95
                 || (pb->imageMode == plugInModeGrayScale && nplanes == 2)
96
                 || (pb->imageMode == plugInModeDuotone && nplanes == 2) )
97
                {
98
                        preview_pmask.next = NULL;
99
        //              preview_pmask.maskData = preview_data+3;
100
                        preview_pmask.rowBytes = preview_pmap.rowBytes;
101
                        preview_pmask.colBytes = nplanes;
102
                        preview_pmask.maskDescription = kSimplePSMask;
103
                        preview_pmap.masks = &preview_pmask;
104
                }else
105
                        preview_pmap.masks = NULL;
106
 
484 daniel-mar 107
                preview_handle = newBuffer((long)preview_h * preview_pmap.rowBytes);
259 daniel-mar 108
        }else
485 daniel-mar 109
                preview_handle.signature = BUFVERSION_NULL;
110
        return preview_handle.signature != BUFVERSION_NULL;
259 daniel-mar 111
 
112
        //---------------------------------------------------------------------------
113
        // Fields new in version 2:
114
        //---------------------------------------------------------------------------
115
//      preview_pmap.pixelOverlays;
116
//      preview_pmap.colorManagementOptions;
117
}
118
 
119
void dispose_preview(){
485 daniel-mar 120
        disposeBuffer(&preview_handle);
259 daniel-mar 121
}
122
 
123
void* memset_bgcolor(void* ptr, size_t num) {
124
        int i;
125
        unsigned char* p;
126
 
127
        i = 0;
128
        p = (unsigned char*)ptr;
129
        for (i=0; i<(int)num; ++i) {
268 daniel-mar 130
                #ifdef WIN_ENV
259 daniel-mar 131
                DWORD color;
132
 
133
                color = GetSysColor(COLOR_APPWORKSPACE);
134
 
135
                if (gpb->imageMode == plugInModeRGBColor) {
136
                        if (i%nplanes == 0) p[i] = GetRValue(color);
137
                        if (i%nplanes == 1) p[i] = GetGValue(color);
138
                        if (i%nplanes == 2) p[i] = GetBValue(color);
139
                        if (i%nplanes == 3) p[i] = 255; // alpha channel
140
                } else if (gpb->imageMode == plugInModeGrayScale) {
141
                        uint8_t r, g, b;
142
 
143
                        r = GetRValue(color);
144
                        g = GetGValue(color);
145
                        b = GetBValue(color);
146
 
147
                        if (i%nplanes == 0) p[i] = (uint8_t)(((299L*r)+(587L*g)+(114L*b))/1000);
148
                        if (i%nplanes == 1) p[i] = 255; // alpha channel
149
                } else if (gpb->imageMode == plugInModeCMYKColor) {
150
                        uint8_t r, g, b;
151
                        double dmax, dr, dg, db, k, c, m, y;
152
 
153
                        r = GetRValue(color);
154
                        g = GetGValue(color);
155
                        b = GetBValue(color);
156
 
157
                        dr = (double)r / 255;
158
                        dg = (double)g / 255;
159
                        db = (double)b / 255;
160
 
161
                        dmax = dr;
162
                        if (dg>dmax) dmax = dg;
163
                        if (db>dmax) dmax = db;
164
 
165
                        k = 1 - dmax;
166
                        c = (1 - dr - k) / (1 - k);
167
                        m = (1 - dg - k) / (1 - k);
168
                        y = (1 - db - k) / (1 - k);
169
 
170
                        if (i%nplanes == 0) p[i] = (uint8_t)(255 - c * 255);
171
                        if (i%nplanes == 1) p[i] = (uint8_t)(255 - m * 255);
172
                        if (i%nplanes == 2) p[i] = (uint8_t)(255 - y * 255);
173
                        if (i%nplanes == 3) p[i] = (uint8_t)(255 - k * 255);
174
                } else {
175
                        // FIXME: If we are in such a non supported color mode, then
176
                        //        these color codes would be all wrong!
177
                        //        Just to be safe use (what is probably) white
178
                        p[i] = 0xFF;
179
 
180
                        /*
181
                        #define plugInModeBitmap                        0
182
                        #define plugInModeGrayScale                     1 supported
183
                        #define plugInModeIndexedColor          2
184
                        #define plugInModeRGBColor                      3 supported
185
                        #define plugInModeCMYKColor                     4 supported
186
                        #define plugInModeHSLColor                      5
187
                        #define plugInModeHSBColor                      6
188
                        #define plugInModeMultichannel          7
189
                        #define plugInModeDuotone                       8
190
                        #define plugInModeLabColor                      9
191
                        #define plugInModeGray16                        10
192
                        #define plugInModeRGB48                         11
193
                        #define plugInModeLab48                         12
194
                        #define plugInModeCMYK64                        13
195
                        #define plugInModeDeepMultichannel      14
196
                        #define plugInModeDuotone16                     15
197
                        #define plugInModeRGB96                         16
198
                        #define plugInModeGray32                        17
199
                        */
200
 
201
                }
268 daniel-mar 202
                #else
259 daniel-mar 203
                // This is the behavior of FilterFoundry <1.7 was this (filled with 0xFF)
204
                // FIXME: Should we do something fancy here, too?
205
                p[i] = 0xFF;
268 daniel-mar 206
                #endif
259 daniel-mar 207
        }
208
        return ptr;
209
}
210
 
211
void recalc_preview_olddoc(FilterRecordPtr pb, DIALOGREF dp) {
212
        OSErr e;
213
        double scaledw, scaledh;
214
        int j, n, imgw, imgh;
215
        Rect r, outRect;
216
        Ptr outrow;
217
 
218
        preview_complete = false;
219
 
485 daniel-mar 220
        if (preview_handle.signature != BUFVERSION_NULL) {
259 daniel-mar 221
                /* size of previewed area, of source image; but no larger than filtered area (selection) */
222
                scaledw = zoomfactor * preview_w;
223
                if (scaledw > ((double)FILTER_RECT(pb).right - (double)FILTER_RECT(pb).left))
224
                        scaledw = (double)FILTER_RECT(pb).right - (double)FILTER_RECT(pb).left;
225
                scaledh = zoomfactor * preview_h;
226
                if (scaledh > ((double)FILTER_RECT(pb).bottom - (double)FILTER_RECT(pb).top))
227
                        scaledh = (double)FILTER_RECT(pb).bottom - (double)FILTER_RECT(pb).top;
228
 
229
                /* scale clipped preview area down again - this becomes the pixel size of preview */
230
                imgw = (int)ceil(scaledw / zoomfactor);
231
                if (imgw > preview_w)
232
                        imgw = preview_w;
233
                imgh = (int)ceil(scaledh / zoomfactor);
234
                if (imgh > preview_h)
235
                        imgh = preview_h;
236
 
237
                /* compute source data rectangle (inRect) */
238
 
239
                /* centre preview on filtered part of input image, adding scroll offset */
240
                r.left = (int16)(((double)FILTER_RECT(pb).left + (double)FILTER_RECT(pb).right - scaledw) / 2 + preview_scroll.h);
241
                /* make sure it does not go outside the input area */
242
                if (r.left < FILTER_RECT(pb).left) {
243
                        preview_scroll.h += FILTER_RECT(pb).left - r.left;
244
                        r.left = FILTER_RECT(pb).left;
245
                }
246
                else if ((double)r.left + scaledw > FILTER_RECT(pb).right) {
247
                        preview_scroll.h += (int16)((double)FILTER_RECT(pb).right - ((double)r.left + scaledw));
248
                        r.left = (int16)((double)FILTER_RECT(pb).right - scaledw);
249
                }
250
                r.right = (int16)((double)r.left + scaledw);
251
                preview_pmap.maskPhaseCol = (int32)((preview_scroll.h) / zoomfactor); // phase of the checkerboard
252
 
253
                /* now compute for vertical */
254
                r.top = (int16)(((double)FILTER_RECT(pb).top + (double)FILTER_RECT(pb).bottom - scaledh) / 2 + preview_scroll.v);
255
                if (r.top < FILTER_RECT(pb).top) {
256
                        preview_scroll.v += FILTER_RECT(pb).top - r.top;
257
                        r.top = FILTER_RECT(pb).top;
258
                }
259
                else if ((double)r.top + scaledh > FILTER_RECT(pb).bottom) {
260
                        preview_scroll.v += (int16)(FILTER_RECT(pb).bottom - ((double)r.top + scaledh));
261
                        r.top = (int16)((double)FILTER_RECT(pb).bottom - scaledh);
262
                }
263
                r.bottom = (int16)((double)r.top + scaledh);
264
                preview_pmap.maskPhaseRow = (int32)((preview_scroll.v) / zoomfactor); // phase of the checkerboard
265
 
266
                /* if formulae need random access to image - src(), rad() - we must request entire area: */
267
                if (needall)
268
                        SETRECT(IN_RECT(pb), 0, 0, IMAGE_SIZE(pb).h, IMAGE_SIZE(pb).v);
269
                else
270
                        IN_RECT(pb) = r;
271
 
272
                OUT_RECT(pb) = IN_RECT(pb);
273
                SETRECT(MASK_RECT(pb), 0, 0, 0, 0);
274
                pb->inLoPlane = pb->outLoPlane = 0;
275
                pb->inHiPlane = pb->outHiPlane = nplanes - 1;
276
 
277
                if (!needinput || !(e = pb->advanceState())) {
484 daniel-mar 278
                        Ptr outptr = lockBuffer(preview_handle);
259 daniel-mar 279
                        int blankrows = (preview_h - imgh) / 2,
312 daniel-mar 280
                            blankcols = (preview_w - imgw) / 2,
281
                            pmrb = preview_pmap.rowBytes;
259 daniel-mar 282
 
283
                        evalinit();
284
 
285
                        SETRECT(outRect, 0, 0, imgw, imgh);
286
 
287
                        e = process_scaled_olddoc(pb, false, r, outRect,
288
                                outptr + pmrb * blankrows + nplanes * blankcols, pmrb, zoomfactor);
289
                        if (blankrows) {
290
                                // blank rows on top of preview:
291
                                memset_bgcolor(outptr, pmrb * blankrows);
292
                                // blank rows below preview:
293
                                n = preview_h - blankrows - imgh;
294
                                memset_bgcolor(outptr + pmrb * (blankrows + imgh), pmrb * n);
295
                        }
296
                        if (blankcols) {
297
                                n = preview_w - blankcols - imgw;
298
                                outrow = outptr + pmrb * blankrows;
299
                                for (j = blankrows; j < preview_h - blankrows; ++j) {
300
                                        // blank columns on left side of preview (if picture is smaller than the preview area):
301
                                        memset_bgcolor(outrow, nplanes * blankcols);
302
                                        // blank columns on right side of preview (if picture is smaller than the preview area):
303
                                        memset_bgcolor(outrow + nplanes * (blankcols + imgw), nplanes * n);
304
                                        outrow += pmrb;
305
                                }
306
                        }
307
 
482 daniel-mar 308
                        if (e == noErr) {
259 daniel-mar 309
                                preview_complete = true;
310
 
268 daniel-mar 311
                                #ifdef WIN_ENV
259 daniel-mar 312
                                {
313
                                        extern HWND preview_hwnd;
314
                                        HDC hdc = GetDC(preview_hwnd);
315
 
316
                                        drawpreview(dp, hdc, outptr);
317
 
318
                                        ReleaseDC(preview_hwnd, hdc);
319
                                }
268 daniel-mar 320
                                #else
259 daniel-mar 321
                                {
322
                                        GrafPtr saveport;
323
 
324
                                        GetPort(&saveport);
325
                                        SetPortDialogPort(dp);
326
 
327
                                        drawpreview(dp, NULL, outptr);
328
 
329
                                        SetPort(saveport);
330
                                }
268 daniel-mar 331
                                #endif
259 daniel-mar 332
                        }
333
 
484 daniel-mar 334
                        unlockBuffer(preview_handle);
259 daniel-mar 335
                }
336
 
337
                if (e && !previewerr) {
444 daniel-mar 338
                        alertuser((TCHAR*)TEXT("Could not build preview at chosen zoom level."),
339
                                e == memFullErr && !needall ? (TCHAR*)TEXT("The image is too large for available memory. Try zooming in.\nIf that does not help, cancel and retry the filter.") : (TCHAR*)TEXT(""));
259 daniel-mar 340
                        previewerr = true;
341
                }
342
 
343
        }
344
}
345
 
346
void recalc_preview_bigdoc(FilterRecordPtr pb, DIALOGREF dp) {
347
        OSErr e;
348
        double scaledw, scaledh;
349
        int j, n, imgw, imgh;
350
        VRect r, outRect;
351
        Ptr outrow;
352
 
353
        preview_complete = false;
354
 
485 daniel-mar 355
        if (preview_handle.signature != BUFVERSION_NULL) {
259 daniel-mar 356
                /* size of previewed area, of source image; but no larger than filtered area (selection) */
357
                scaledw = zoomfactor * preview_w;
358
                if (scaledw > ((double)BIGDOC_FILTER_RECT(pb).right - (double)BIGDOC_FILTER_RECT(pb).left))
359
                        scaledw = (double)BIGDOC_FILTER_RECT(pb).right - (double)BIGDOC_FILTER_RECT(pb).left;
360
                scaledh = zoomfactor * preview_h;
361
                if (scaledh > ((double)BIGDOC_FILTER_RECT(pb).bottom - (double)BIGDOC_FILTER_RECT(pb).top))
362
                        scaledh = (double)BIGDOC_FILTER_RECT(pb).bottom - (double)BIGDOC_FILTER_RECT(pb).top;
363
 
364
                /* scale clipped preview area down again - this becomes the pixel size of preview */
365
                imgw = (int)ceil(scaledw / zoomfactor);
366
                if (imgw > preview_w)
367
                        imgw = preview_w;
368
                imgh = (int)ceil(scaledh / zoomfactor);
369
                if (imgh > preview_h)
370
                        imgh = preview_h;
371
 
372
                /* compute source data rectangle (inRect) */
373
 
374
                /* centre preview on filtered part of input image, adding scroll offset */
375
                r.left = (int32)(((double)BIGDOC_FILTER_RECT(pb).left + (double)BIGDOC_FILTER_RECT(pb).right - scaledw) / 2 + preview_scroll.h);
376
                /* make sure it does not go outside the input area */
377
                if (r.left < BIGDOC_FILTER_RECT(pb).left) {
378
                        preview_scroll.h += BIGDOC_FILTER_RECT(pb).left - r.left;
379
                        r.left = BIGDOC_FILTER_RECT(pb).left;
380
                }
381
                else if ((double)r.left + scaledw > BIGDOC_FILTER_RECT(pb).right) {
382
                        preview_scroll.h += (int32)((double)BIGDOC_FILTER_RECT(pb).right - ((double)r.left + scaledw));
383
                        r.left = (int32)((double)BIGDOC_FILTER_RECT(pb).right - scaledw);
384
                }
385
                r.right = (int32)((double)r.left + scaledw);
386
                preview_pmap.maskPhaseCol = (int32)((preview_scroll.h) / zoomfactor); // phase of the checkerboard
387
 
388
                /* now compute for vertical */
389
                r.top = (int32)(((double)BIGDOC_FILTER_RECT(pb).top + (double)BIGDOC_FILTER_RECT(pb).bottom - scaledh) / 2 + preview_scroll.v);
390
                if (r.top < BIGDOC_FILTER_RECT(pb).top) {
391
                        preview_scroll.v += BIGDOC_FILTER_RECT(pb).top - r.top;
392
                        r.top = BIGDOC_FILTER_RECT(pb).top;
393
                }
394
                else if ((double)r.top + scaledh > BIGDOC_FILTER_RECT(pb).bottom) {
395
                        preview_scroll.v += (int32)(BIGDOC_FILTER_RECT(pb).bottom - ((double)r.top + scaledh));
396
                        r.top = (int32)((double)BIGDOC_FILTER_RECT(pb).bottom - scaledh);
397
                }
398
                r.bottom = (int32)((double)r.top + scaledh);
399
                preview_pmap.maskPhaseRow = (int32)((preview_scroll.v) / zoomfactor); // phase of the checkerboard
400
 
401
                /* if formulae need random access to image - src(), rad() - we must request entire area: */
402
                if (needall)
403
                        SETRECT(BIGDOC_IN_RECT(pb), 0, 0, BIGDOC_IMAGE_SIZE(pb).h, BIGDOC_IMAGE_SIZE(pb).v);
404
                else
405
                        BIGDOC_IN_RECT(pb) = r;
406
 
407
                BIGDOC_OUT_RECT(pb) = BIGDOC_IN_RECT(pb);
408
                SETRECT(BIGDOC_MASK_RECT(pb), 0, 0, 0, 0);
409
                pb->inLoPlane = pb->outLoPlane = 0;
410
                pb->inHiPlane = pb->outHiPlane = nplanes - 1;
411
 
412
                if (!needinput || !(e = pb->advanceState())) {
484 daniel-mar 413
                        Ptr outptr = lockBuffer(preview_handle);
259 daniel-mar 414
                        int blankrows = (preview_h - imgh) / 2,
312 daniel-mar 415
                            blankcols = (preview_w - imgw) / 2,
416
                            pmrb = preview_pmap.rowBytes;
259 daniel-mar 417
 
418
                        evalinit();
419
 
420
                        SETRECT(outRect, 0, 0, imgw, imgh);
421
 
422
                        e = process_scaled_bigdoc(pb, false, r, outRect,
423
                                outptr + pmrb * blankrows + nplanes * blankcols, pmrb, zoomfactor);
424
                        if (blankrows) {
425
                                // blank rows on top of preview:
426
                                memset_bgcolor(outptr, pmrb * blankrows);
427
                                // blank rows below preview:
428
                                n = preview_h - blankrows - imgh;
429
                                memset_bgcolor(outptr + pmrb * (blankrows + imgh), pmrb * n);
430
                        }
431
                        if (blankcols) {
432
                                n = preview_w - blankcols - imgw;
433
                                outrow = outptr + pmrb * blankrows;
434
                                for (j = blankrows; j < preview_h - blankrows; ++j) {
435
                                        // blank columns on left side of preview (if picture is smaller than the preview area):
436
                                        memset_bgcolor(outrow, nplanes * blankcols);
437
                                        // blank columns on right side of preview (if picture is smaller than the preview area):
438
                                        memset_bgcolor(outrow + nplanes * (blankcols + imgw), nplanes * n);
439
                                        outrow += pmrb;
440
                                }
441
                        }
442
 
482 daniel-mar 443
                        if (e == noErr) {
259 daniel-mar 444
                                preview_complete = true;
445
 
268 daniel-mar 446
                                #ifdef WIN_ENV
259 daniel-mar 447
                                {
448
                                        extern HWND preview_hwnd;
449
                                        HDC hdc = GetDC(preview_hwnd);
450
 
451
                                        drawpreview(dp, hdc, outptr);
452
 
453
                                        ReleaseDC(preview_hwnd, hdc);
454
                                }
268 daniel-mar 455
                                #else
259 daniel-mar 456
                                {
457
                                        GrafPtr saveport;
458
 
459
                                        GetPort(&saveport);
460
                                        SetPortDialogPort(dp);
461
 
462
                                        drawpreview(dp, NULL, outptr);
463
 
464
                                        SetPort(saveport);
465
                                }
268 daniel-mar 466
                                #endif
259 daniel-mar 467
                        }
468
 
484 daniel-mar 469
                        unlockBuffer(preview_handle);
259 daniel-mar 470
                }
471
 
472
                if (e && !previewerr) {
444 daniel-mar 473
                        alertuser((TCHAR*)TEXT("Could not build preview at chosen zoom level."),
474
                                e == memFullErr && !needall ? (TCHAR*)TEXT("The image is too large for available memory. Try zooming in.\nIf that does not help, cancel and retry the filter.") : (TCHAR*)TEXT(""));
259 daniel-mar 475
                        previewerr = true;
476
                }
477
 
478
        }
479
}
480
 
481
void recalc_preview(FilterRecordPtr pb, DIALOGREF dp) {
445 daniel-mar 482
        // TODO? When a formula has an error, the preview should not be changeable
483
        // (This code does not work because you can still try to zoom)
484
        /*
485
        if (!gdata->standalone) {
486
                int i;
487
                for (i = 0; i < 4; i++)
488
                        if (!parseexpr(expr[i])) return;
489
        }
490
        */
491
 
259 daniel-mar 492
        if (HAS_BIG_DOC(pb)) {
493
                recalc_preview_bigdoc(pb, dp);
494
        }
495
        else {
496
                recalc_preview_olddoc(pb, dp);
497
        }
498
}
499
 
500
OSErr drawpreview(DIALOGREF dp,void *hdc,Ptr imageptr){
501
        intptr_t watchsusp;
502
        OSErr e = noErr;
503
        VRect srcRect;
504
        UIRECT imagebounds;
505
 
433 daniel-mar 506
        UNREFERENCED_PARAMETER(dp);
507
 
485 daniel-mar 508
        if((preview_handle.signature != BUFVERSION_NULL) && preview_complete){
259 daniel-mar 509
 
510
                srcRect = preview_pmap.bounds;
511
 
512
                imagebounds.left = (preview_rect.left + preview_rect.right - preview_w)/2;
513
                imagebounds.top = (preview_rect.top + preview_rect.bottom - preview_h)/2;
514
                imagebounds.right = imagebounds.left + preview_w;
515
                imagebounds.bottom = imagebounds.top + preview_h;
516
 
517
                preview_pmap.baseAddr = imageptr;
518
                preview_pmask.maskData = imageptr+3; // FIXME: is this offset correct for all modes?!
519
 
403 daniel-mar 520
                if((gpb->propertyProcs != NULL) && gpb->propertyProcs->getPropertyProc){
259 daniel-mar 521
                        gpb->propertyProcs->getPropertyProc(kPhotoshopSignature,propWatchSuspension,0,&watchsusp,NULL);
522
                        gpb->propertyProcs->setPropertyProc(kPhotoshopSignature,propWatchSuspension,0,watchsusp+1,NULL);
523
                }
524
 
525
                e = gpb->displayPixels(&preview_pmap,&srcRect,imagebounds.top,imagebounds.left,hdc);
526
 
403 daniel-mar 527
                if((gpb->propertyProcs != NULL) && gpb->propertyProcs->getPropertyProc)
259 daniel-mar 528
                        gpb->propertyProcs->setPropertyProc(kPhotoshopSignature,propWatchSuspension,0,watchsusp,NULL);
529
        }
530
        return e;
531
}