Subversion Repositories filter_foundry

Rev

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

Rev 206 Rev 232
Line 18... Line 18...
18
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
*/
19
*/
20
 
20
 
21
/* This is PLATFORM INDEPENDENT user interface code - mainly dialog logic */
21
/* This is PLATFORM INDEPENDENT user interface code - mainly dialog logic */
22
 
22
 
-
 
23
#include "ff.h"
23
#include "preview.h"
24
#include "preview.h"
24
 
25
 
25
#ifdef MAC_ENV
26
#ifdef MAC_ENV
26
        #include <fp.h>
27
        #include <fp.h>
27
#endif
28
#endif
Line 45... Line 46...
45
 
46
 
46
        if(pb->displayPixels && pb->advanceState){
47
        if(pb->displayPixels && pb->advanceState){
47
                // Possibility 1: Only the part of the preview rect is filled with background color,
48
                // Possibility 1: Only the part of the preview rect is filled with background color,
48
                // which can be occupied by image data if zoom factor becomes 100%
49
                // which can be occupied by image data if zoom factor becomes 100%
49
                /*
50
                /*
-
 
51
                if (HAS_BIG_DOC(pb)) {
50
                preview_w = MIN(preview_rect.right - preview_rect.left,
52
                        preview_w = MIN(preview_rect.right - preview_rect.left,
51
                                                pb->filterRect.right - pb->filterRect.left);
53
                                                        BIGDOC_FILTER_RECT(pb).right - BIGDOC_FILTER_RECT(pb).left);
52
                preview_h = MIN(preview_rect.bottom - preview_rect.top,
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,
53
                                                pb->filterRect.bottom - pb->filterRect.top);
60
                                                        FILTER_RECT(pb).bottom - FILTER_RECT(pb).top);
-
 
61
                }
54
                */
62
                */
55
                // Possibility 2: The whole preview rect is always filled with the background color,
63
                // Possibility 2: The whole preview rect is always filled with the background color,
56
                // so you can easily see what is the preview area and what is not
64
                // so you can easily see what is the preview area and what is not
57
                preview_w = preview_rect.right - preview_rect.left;
65
                preview_w = preview_rect.right - preview_rect.left;
58
                preview_h = preview_rect.bottom - preview_rect.top;
66
                preview_h = preview_rect.bottom - preview_rect.top;
59
 
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 {
60
                zh = (pb->filterRect.right - pb->filterRect.left)/(double)preview_w;
72
                        zh = ((double)FILTER_RECT(pb).right - (double)FILTER_RECT(pb).left) / (double)preview_w;
61
                zv = (pb->filterRect.bottom - pb->filterRect.top)/(double)preview_h;
73
                        zv = ((double)FILTER_RECT(pb).bottom - (double)FILTER_RECT(pb).top) / (double)preview_h;
-
 
74
                }
62
                fitzoom = zh > zv ? zh : zv;
75
                fitzoom = zh > zv ? zh : zv;
63
 
76
 
64
                preview_pmap.version = 1;
77
                preview_pmap.version = 1;
65
                preview_pmap.bounds.left = preview_pmap.bounds.top = 0;
78
                preview_pmap.bounds.left = preview_pmap.bounds.top = 0;
66
                preview_pmap.bounds.right = preview_w;
79
                preview_pmap.bounds.right = preview_w;
Line 196... Line 209...
196
#endif
209
#endif
197
        }
210
        }
198
        return ptr;
211
        return ptr;
199
}
212
}
200
 
213
 
201
void recalc_preview(FilterRecordPtr pb,DIALOGREF dp){
214
void recalc_preview_olddoc(FilterRecordPtr pb, DIALOGREF dp) {
202
        OSErr e;
215
        OSErr e;
203
        double scaledw, scaledh;
216
        double scaledw, scaledh;
204
        int j,n,imgw,imgh;
217
        int j, n, imgw, imgh;
205
        Rect r,outRect;
218
        Rect r, outRect;
206
        Ptr outrow;
219
        Ptr outrow;
Line 208... Line 221...
208
        preview_complete = false;
221
        preview_complete = false;
209
 
222
 
210
        if(preview_handle){
223
        if (preview_handle) {
211
                /* size of previewed area, of source image; but no larger than filtered area (selection) */
224
                /* size of previewed area, of source image; but no larger than filtered area (selection) */
212
                scaledw = zoomfactor*preview_w;
225
                scaledw = zoomfactor * preview_w;
213
                if(scaledw > (pb->filterRect.right - pb->filterRect.left))
226
                if (scaledw > ((double)FILTER_RECT(pb).right - (double)FILTER_RECT(pb).left))
214
                        scaledw = pb->filterRect.right - pb->filterRect.left;
227
                        scaledw = (double)FILTER_RECT(pb).right - (double)FILTER_RECT(pb).left;
-
 
228
                scaledh = zoomfactor * preview_h;
-
 
229
                if (scaledh > ((double)FILTER_RECT(pb).bottom - (double)FILTER_RECT(pb).top))
-
 
230
                        scaledh = (double)FILTER_RECT(pb).bottom - (double)FILTER_RECT(pb).top;
-
 
231
 
-
 
232
                /* scale clipped preview area down again - this becomes the pixel size of preview */
-
 
233
                imgw = (int)ceil(scaledw / zoomfactor);
-
 
234
                if (imgw > preview_w)
-
 
235
                        imgw = preview_w;
-
 
236
                imgh = (int)ceil(scaledh / zoomfactor);
-
 
237
                if (imgh > preview_h)
-
 
238
                        imgh = preview_h;
-
 
239
 
-
 
240
                /* compute source data rectangle (inRect) */
-
 
241
 
-
 
242
                /* centre preview on filtered part of input image, adding scroll offset */
-
 
243
                r.left = (int16)(((double)FILTER_RECT(pb).left + (double)FILTER_RECT(pb).right - scaledw) / 2 + preview_scroll.h);
-
 
244
                /* make sure it does not go outside the input area */
-
 
245
                if (r.left < FILTER_RECT(pb).left) {
-
 
246
                        preview_scroll.h += FILTER_RECT(pb).left - r.left;
-
 
247
                        r.left = FILTER_RECT(pb).left;
-
 
248
                }
-
 
249
                else if ((double)r.left + scaledw > FILTER_RECT(pb).right) {
-
 
250
                        preview_scroll.h += (int16)((double)FILTER_RECT(pb).right - ((double)r.left + scaledw));
-
 
251
                        r.left = (int16)((double)FILTER_RECT(pb).right - scaledw);
-
 
252
                }
-
 
253
                r.right = (int16)((double)r.left + scaledw);
-
 
254
                preview_pmap.maskPhaseCol = (int32)((preview_scroll.h) / zoomfactor); // phase of the checkerboard
-
 
255
 
-
 
256
                /* now compute for vertical */
-
 
257
                r.top = (int16)(((double)FILTER_RECT(pb).top + (double)FILTER_RECT(pb).bottom - scaledh) / 2 + preview_scroll.v);
-
 
258
                if (r.top < FILTER_RECT(pb).top) {
-
 
259
                        preview_scroll.v += FILTER_RECT(pb).top - r.top;
-
 
260
                        r.top = FILTER_RECT(pb).top;
-
 
261
                }
-
 
262
                else if ((double)r.top + scaledh > FILTER_RECT(pb).bottom) {
-
 
263
                        preview_scroll.v += (int16)(FILTER_RECT(pb).bottom - ((double)r.top + scaledh));
-
 
264
                        r.top = (int16)((double)FILTER_RECT(pb).bottom - scaledh);
-
 
265
                }
-
 
266
                r.bottom = (int16)((double)r.top + scaledh);
-
 
267
                preview_pmap.maskPhaseRow = (int32)((preview_scroll.v) / zoomfactor); // phase of the checkerboard
-
 
268
 
-
 
269
                /* if formulae need random access to image - src(), rad() - we must request entire area: */
-
 
270
                if (needall)
-
 
271
                        SETRECT(IN_RECT(pb), 0, 0, IMAGE_SIZE(pb).h, IMAGE_SIZE(pb).v);
-
 
272
                else
-
 
273
                        IN_RECT(pb) = r;
-
 
274
 
-
 
275
                OUT_RECT(pb) = IN_RECT(pb);
-
 
276
                SETRECT(MASK_RECT(pb), 0, 0, 0, 0);
-
 
277
                pb->inLoPlane = pb->outLoPlane = 0;
-
 
278
                pb->inHiPlane = pb->outHiPlane = nplanes - 1;
-
 
279
 
-
 
280
                if (!needinput || !(e = pb->advanceState())) {
-
 
281
                        Ptr outptr = PILOCKHANDLE(preview_handle, false);
-
 
282
                        int blankrows = (preview_h - imgh) / 2,
-
 
283
                                blankcols = (preview_w - imgw) / 2,
-
 
284
                                pmrb = preview_pmap.rowBytes;
-
 
285
 
-
 
286
                        evalinit();
-
 
287
 
-
 
288
                        SETRECT(outRect, 0, 0, imgw, imgh);
-
 
289
 
-
 
290
                        e = process_scaled_olddoc(pb, false, r, outRect,
-
 
291
                                outptr + pmrb * blankrows + nplanes * blankcols, pmrb, zoomfactor);
-
 
292
                        if (blankrows) {
-
 
293
                                // blank rows on top of preview:
-
 
294
                                memset_bgcolor(outptr, pmrb * blankrows);
-
 
295
                                // blank rows below preview:
-
 
296
                                n = preview_h - blankrows - imgh;
-
 
297
                                memset_bgcolor(outptr + pmrb * (blankrows + imgh), pmrb * n);
-
 
298
                        }
-
 
299
                        if (blankcols) {
-
 
300
                                n = preview_w - blankcols - imgw;
-
 
301
                                outrow = outptr + pmrb * blankrows;
-
 
302
                                for (j = blankrows; j < preview_h - blankrows; ++j) {
-
 
303
                                        // blank columns on left side of preview (if picture is smaller than the preview area):
-
 
304
                                        memset_bgcolor(outrow, nplanes * blankcols);
-
 
305
                                        // blank columns on right side of preview (if picture is smaller than the preview area):
-
 
306
                                        memset_bgcolor(outrow + nplanes * (blankcols + imgw), nplanes * n);
-
 
307
                                        outrow += pmrb;
-
 
308
                                }
-
 
309
                        }
-
 
310
 
-
 
311
                        if (!e) {
-
 
312
                                preview_complete = true;
-
 
313
 
-
 
314
#ifdef WIN_ENV
-
 
315
                                {
-
 
316
                                        extern HWND preview_hwnd;
-
 
317
                                        HDC hdc = GetDC(preview_hwnd);
-
 
318
 
-
 
319
                                        drawpreview(dp, hdc, outptr);
-
 
320
 
-
 
321
                                        ReleaseDC(preview_hwnd, hdc);
-
 
322
                                }
-
 
323
#else
-
 
324
                                {
-
 
325
                                        GrafPtr saveport;
-
 
326
 
-
 
327
                                        GetPort(&saveport);
-
 
328
                                        SetPortDialogPort(dp);
-
 
329
 
-
 
330
                                        drawpreview(dp, NULL, outptr);
-
 
331
 
-
 
332
                                        SetPort(saveport);
-
 
333
                                }
-
 
334
#endif
-
 
335
                        }
-
 
336
 
-
 
337
                        PIUNLOCKHANDLE(preview_handle);
-
 
338
                }
-
 
339
 
-
 
340
                if (e && !previewerr) {
-
 
341
                        alertuser(_strdup("Could not build preview at chosen zoom level."),
-
 
342
                                e == memFullErr && !needall ? _strdup("The image is too large for available memory. Try zooming in.\nIf that does not help, cancel and retry the filter.") : _strdup(""));
-
 
343
                        previewerr = true;
-
 
344
                }
-
 
345
 
-
 
346
        }
-
 
347
}
-
 
348
 
-
 
349
void recalc_preview_bigdoc(FilterRecordPtr pb, DIALOGREF dp) {
-
 
350
        OSErr e;
-
 
351
        double scaledw, scaledh;
-
 
352
        int j, n, imgw, imgh;
-
 
353
        VRect r, outRect;
-
 
354
        Ptr outrow;
-
 
355
 
-
 
356
        preview_complete = false;
-
 
357
 
-
 
358
        if (preview_handle) {
-
 
359
                /* size of previewed area, of source image; but no larger than filtered area (selection) */
-
 
360
                scaledw = zoomfactor * preview_w;
-
 
361
                if (scaledw > ((double)BIGDOC_FILTER_RECT(pb).right - (double)BIGDOC_FILTER_RECT(pb).left))
-
 
362
                        scaledw = (double)BIGDOC_FILTER_RECT(pb).right - (double)BIGDOC_FILTER_RECT(pb).left;
215
                scaledh = zoomfactor*preview_h;
363
                scaledh = zoomfactor * preview_h;
216
                if(scaledh > (pb->filterRect.bottom - pb->filterRect.top))
364
                if (scaledh > ((double)BIGDOC_FILTER_RECT(pb).bottom - (double)BIGDOC_FILTER_RECT(pb).top))
217
                        scaledh = pb->filterRect.bottom - pb->filterRect.top;
365
                        scaledh = (double)BIGDOC_FILTER_RECT(pb).bottom - (double)BIGDOC_FILTER_RECT(pb).top;
218
 
366
 
219
                /* scale clipped preview area down again - this becomes the pixel size of preview */
367
                /* scale clipped preview area down again - this becomes the pixel size of preview */
220
                imgw = (int)ceil(scaledw/zoomfactor);
368
                imgw = (int)ceil(scaledw / zoomfactor);
221
                if(imgw > preview_w)
369
                if (imgw > preview_w)
222
                        imgw = preview_w;
370
                        imgw = preview_w;
Line 225... Line 373...
225
                        imgh = preview_h;
373
                        imgh = preview_h;
226
 
374
 
227
                /* compute source data rectangle (inRect) */
375
                /* compute source data rectangle (inRect) */
228
 
376
 
229
                /* centre preview on filtered part of input image, adding scroll offset */
377
                /* centre preview on filtered part of input image, adding scroll offset */
230
                r.left = (int16)((pb->filterRect.left + pb->filterRect.right - scaledw)/2 + preview_scroll.h);
378
                r.left = (int32)(((double)BIGDOC_FILTER_RECT(pb).left + (double)BIGDOC_FILTER_RECT(pb).right - scaledw) / 2 + preview_scroll.h);
231
                /* make sure it does not go outside the input area */
379
                /* make sure it does not go outside the input area */
232
                if(r.left < pb->filterRect.left) {
380
                if (r.left < BIGDOC_FILTER_RECT(pb).left) {
233
                        preview_scroll.h += pb->filterRect.left - r.left;
381
                        preview_scroll.h += BIGDOC_FILTER_RECT(pb).left - r.left;
234
                        r.left = pb->filterRect.left;
382
                        r.left = BIGDOC_FILTER_RECT(pb).left;
235
                }
383
                }
236
                else if(r.left+scaledw > pb->filterRect.right) {
384
                else if ((double)r.left + scaledw > BIGDOC_FILTER_RECT(pb).right) {
237
                        preview_scroll.h += (int16)(pb->filterRect.right - (r.left+scaledw));
385
                        preview_scroll.h += (int32)((double)BIGDOC_FILTER_RECT(pb).right - ((double)r.left + scaledw));
238
                        r.left = (int16)(pb->filterRect.right - scaledw);
386
                        r.left = (int32)((double)BIGDOC_FILTER_RECT(pb).right - scaledw);
239
                }
387
                }
240
                r.right = (int16)(r.left + scaledw);
388
                r.right = (int32)((double)r.left + scaledw);
241
                preview_pmap.maskPhaseCol = (int32)((preview_scroll.h)/zoomfactor); // phase of the checkerboard
389
                preview_pmap.maskPhaseCol = (int32)((preview_scroll.h) / zoomfactor); // phase of the checkerboard
242
 
390
 
243
                /* now compute for vertical */
391
                /* now compute for vertical */
244
                r.top = (int16)((pb->filterRect.top + pb->filterRect.bottom - scaledh)/2 + preview_scroll.v);
392
                r.top = (int32)(((double)BIGDOC_FILTER_RECT(pb).top + (double)BIGDOC_FILTER_RECT(pb).bottom - scaledh) / 2 + preview_scroll.v);
245
                if(r.top < pb->filterRect.top) {
393
                if (r.top < BIGDOC_FILTER_RECT(pb).top) {
246
                        preview_scroll.v += pb->filterRect.top - r.top;
394
                        preview_scroll.v += BIGDOC_FILTER_RECT(pb).top - r.top;
247
                        r.top = pb->filterRect.top;
395
                        r.top = BIGDOC_FILTER_RECT(pb).top;
248
                }
396
                }
249
                else if(r.top+scaledh > pb->filterRect.bottom) {
397
                else if ((double)r.top + scaledh > BIGDOC_FILTER_RECT(pb).bottom) {
250
                        preview_scroll.v += (int16)(pb->filterRect.bottom - (r.top+scaledh));
398
                        preview_scroll.v += (int32)(BIGDOC_FILTER_RECT(pb).bottom - ((double)r.top + scaledh));
251
                        r.top = (int16)(pb->filterRect.bottom - scaledh);
399
                        r.top = (int32)((double)BIGDOC_FILTER_RECT(pb).bottom - scaledh);
252
                }
400
                }
253
                r.bottom = (int16)(r.top + scaledh);
401
                r.bottom = (int32)((double)r.top + scaledh);
254
                preview_pmap.maskPhaseRow = (int32)((preview_scroll.v)/zoomfactor); // phase of the checkerboard
402
                preview_pmap.maskPhaseRow = (int32)((preview_scroll.v) / zoomfactor); // phase of the checkerboard
255
 
403
 
256
                /* if formulae need random access to image - src(), rad() - we must request entire area: */
404
                /* if formulae need random access to image - src(), rad() - we must request entire area: */
257
                if(needall)
405
                if (needall)
258
                        SETRECT(pb->inRect,0,0,pb->imageSize.h,pb->imageSize.v);
406
                        SETRECT(BIGDOC_IN_RECT(pb), 0, 0, BIGDOC_IMAGE_SIZE(pb).h, BIGDOC_IMAGE_SIZE(pb).v);
259
                else
407
                else
260
                        pb->inRect = r;
408
                        BIGDOC_IN_RECT(pb) = r;
261
 
409
 
262
                pb->outRect = pb->inRect;
410
                BIGDOC_OUT_RECT(pb) = BIGDOC_IN_RECT(pb);
263
                SETRECT(pb->maskRect,0,0,0,0);
411
                SETRECT(BIGDOC_MASK_RECT(pb), 0, 0, 0, 0);
264
                pb->inLoPlane = pb->outLoPlane = 0;
412
                pb->inLoPlane = pb->outLoPlane = 0;
265
                pb->inHiPlane = pb->outHiPlane = nplanes-1;
413
                pb->inHiPlane = pb->outHiPlane = nplanes - 1;
266
 
414
 
267
                if( !needinput || !(e = pb->advanceState()) ){
415
                if (!needinput || !(e = pb->advanceState())) {
268
                        Ptr outptr = PILOCKHANDLE(preview_handle,false);
416
                        Ptr outptr = PILOCKHANDLE(preview_handle, false);
Line 272... Line 420...
272
 
420
 
273
                        evalinit();
421
                        evalinit();
274
 
422
 
275
                        SETRECT(outRect,0,0,imgw,imgh);
423
                        SETRECT(outRect, 0, 0, imgw, imgh);
276
 
424
 
277
                        e = process_scaled(pb, false, &r, &outRect,
425
                        e = process_scaled_bigdoc(pb, false, r, outRect,
278
                                        outptr + pmrb*blankrows + nplanes*blankcols, pmrb, zoomfactor);
426
                                outptr + pmrb * blankrows + nplanes * blankcols, pmrb, zoomfactor);
279
                        if(blankrows){
427
                        if (blankrows) {
280
                                // blank rows on top of preview:
428
                                // blank rows on top of preview:
281
                                memset_bgcolor(outptr, pmrb*blankrows);
429
                                memset_bgcolor(outptr, pmrb * blankrows);
282
                                // blank rows below preview:
430
                                // blank rows below preview:
Line 331... Line 479...
331
                }
479
                }
332
 
480
 
333
        }
481
        }
334
}
482
}
335
 
483
 
-
 
484
void recalc_preview(FilterRecordPtr pb, DIALOGREF dp) {
-
 
485
        if (HAS_BIG_DOC(pb)) {
-
 
486
                recalc_preview_bigdoc(pb, dp);
-
 
487
        }
-
 
488
        else {
-
 
489
                recalc_preview_olddoc(pb, dp);
-
 
490
        }
-
 
491
}
-
 
492
 
336
OSErr drawpreview(DIALOGREF dp,void *hdc,Ptr imageptr){
493
OSErr drawpreview(DIALOGREF dp,void *hdc,Ptr imageptr){
337
        intptr_t watchsusp;
494
        intptr_t watchsusp;
338
        OSErr e = noErr;
495
        OSErr e = noErr;
339
        VRect srcRect;
496
        VRect srcRect;
340
        UIRECT imagebounds;
497
        UIRECT imagebounds;