Rev 206 | Rev 259 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | toby | 1 | /* |
18 | toby | 2 | This file is part of Filter Foundry, a filter plugin for Adobe Photoshop |
192 | daniel-mar | 3 | Copyright (C) 2003-2009 Toby Thain, toby@telegraphics.com.au |
206 | daniel-mar | 4 | Copyright (C) 2018-2021 Daniel Marschall, ViaThinkSoft |
2 | toby | 5 | |
6 | This program is free software; you can redistribute it and/or modify |
||
110 | dmarschall | 7 | it under the terms of the GNU General Public License as published by |
2 | toby | 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 | |||
110 | dmarschall | 16 | You should have received a copy of the GNU General Public License |
2 | toby | 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 | |||
232 | daniel-mar | 23 | #include "ff.h" |
94 | toby | 24 | #include "preview.h" |
2 | toby | 25 | |
94 | toby | 26 | #ifdef MAC_ENV |
27 | #include <fp.h> |
||
28 | #endif |
||
29 | #include <math.h> |
||
30 | |||
29 | toby | 31 | #include "PIProperties.h" |
2 | toby | 32 | |
94 | toby | 33 | extern FilterRecordPtr gpb; |
2 | toby | 34 | |
35 | PSPixelMap preview_pmap; |
||
36 | PSPixelMask preview_pmask; |
||
37 | Handle preview_handle; |
||
38 | UIRECT preview_rect; |
||
94 | toby | 39 | int preview_w,preview_h,previewerr = false,needall = false,needinput = true; |
2 | toby | 40 | Point preview_scroll; |
41 | Boolean preview_complete = false; |
||
94 | toby | 42 | double zoomfactor,fitzoom; |
2 | toby | 43 | |
94 | toby | 44 | Boolean setup_preview(FilterRecordPtr pb, int nplanes){ |
45 | double zh,zv; |
||
46 | |||
2 | toby | 47 | if(pb->displayPixels && pb->advanceState){ |
157 | dmarschall | 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 | /* |
||
232 | daniel-mar | 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 | } |
||
157 | dmarschall | 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 | |||
232 | daniel-mar | 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 | } |
||
94 | toby | 75 | fitzoom = zh > zv ? zh : zv; |
110 | dmarschall | 76 | |
2 | toby | 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; |
||
94 | toby | 81 | preview_pmap.imageMode = pb->imageMode; |
2 | toby | 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 */ |
||
110 | dmarschall | 87 | |
2 | toby | 88 | //--------------------------------------------------------------------------- |
89 | // Fields new in version 1: |
||
110 | dmarschall | 90 | //--------------------------------------------------------------------------- |
2 | toby | 91 | preview_pmap.mat = NULL; |
110 | dmarschall | 92 | |
94 | toby | 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) ) |
||
89 | toby | 97 | { |
2 | toby | 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; |
||
110 | dmarschall | 106 | |
2 | toby | 107 | preview_handle = PINEWHANDLE((long)preview_h * preview_pmap.rowBytes); |
108 | }else |
||
109 | preview_handle = NULL; |
||
110 | return preview_handle != NULL; |
||
111 | |||
112 | //--------------------------------------------------------------------------- |
||
113 | // Fields new in version 2: |
||
110 | dmarschall | 114 | //--------------------------------------------------------------------------- |
2 | toby | 115 | // preview_pmap.pixelOverlays; |
116 | // preview_pmap.colorManagementOptions; |
||
117 | } |
||
118 | |||
119 | void dispose_preview(){ |
||
120 | if(preview_handle){ |
||
121 | PIDISPOSEHANDLE(preview_handle); |
||
122 | preview_handle = NULL; |
||
123 | } |
||
124 | } |
||
125 | |||
158 | dmarschall | 126 | void* memset_bgcolor(void* ptr, size_t num) { |
157 | dmarschall | 127 | int i; |
189 | dmarschall | 128 | unsigned char* p; |
157 | dmarschall | 129 | |
130 | i = 0; |
||
189 | dmarschall | 131 | p = (unsigned char*)ptr; |
185 | dmarschall | 132 | for (i=0; i<(int)num; ++i) { |
158 | dmarschall | 133 | #ifdef WIN_ENV |
159 | dmarschall | 134 | DWORD color; |
135 | |||
158 | dmarschall | 136 | color = GetSysColor(COLOR_APPWORKSPACE); |
159 | dmarschall | 137 | |
138 | if (gpb->imageMode == plugInModeRGBColor) { |
||
139 | if (i%nplanes == 0) p[i] = GetRValue(color); |
||
140 | if (i%nplanes == 1) p[i] = GetGValue(color); |
||
141 | if (i%nplanes == 2) p[i] = GetBValue(color); |
||
142 | if (i%nplanes == 3) p[i] = 255; // alpha channel |
||
143 | } else if (gpb->imageMode == plugInModeGrayScale) { |
||
189 | dmarschall | 144 | uint8_t r, g, b; |
159 | dmarschall | 145 | |
146 | r = GetRValue(color); |
||
147 | g = GetGValue(color); |
||
148 | b = GetBValue(color); |
||
149 | |||
189 | dmarschall | 150 | if (i%nplanes == 0) p[i] = (uint8_t)(((299L*r)+(587L*g)+(114L*b))/1000); |
159 | dmarschall | 151 | if (i%nplanes == 1) p[i] = 255; // alpha channel |
152 | } else if (gpb->imageMode == plugInModeCMYKColor) { |
||
189 | dmarschall | 153 | uint8_t r, g, b; |
194 | daniel-mar | 154 | double dmax, dr, dg, db, k, c, m, y; |
159 | dmarschall | 155 | |
156 | r = GetRValue(color); |
||
157 | g = GetGValue(color); |
||
158 | b = GetBValue(color); |
||
159 | |||
160 | dr = (double)r / 255; |
||
161 | dg = (double)g / 255; |
||
162 | db = (double)b / 255; |
||
194 | daniel-mar | 163 | |
164 | dmax = dr; |
||
165 | if (dg>dmax) dmax = dg; |
||
166 | if (db>dmax) dmax = db; |
||
167 | |||
168 | k = 1 - dmax; |
||
159 | dmarschall | 169 | c = (1 - dr - k) / (1 - k); |
170 | m = (1 - dg - k) / (1 - k); |
||
171 | y = (1 - db - k) / (1 - k); |
||
172 | |||
189 | dmarschall | 173 | if (i%nplanes == 0) p[i] = (uint8_t)(255 - c * 255); |
174 | if (i%nplanes == 1) p[i] = (uint8_t)(255 - m * 255); |
||
175 | if (i%nplanes == 2) p[i] = (uint8_t)(255 - y * 255); |
||
176 | if (i%nplanes == 3) p[i] = (uint8_t)(255 - k * 255); |
||
159 | dmarschall | 177 | } else { |
178 | // FIXME: If we are in such a non supported color mode, then |
||
179 | // these color codes would be all wrong! |
||
180 | // Just to be safe use (what is probably) white |
||
181 | p[i] = 0xFF; |
||
182 | |||
183 | /* |
||
184 | #define plugInModeBitmap 0 |
||
185 | #define plugInModeGrayScale 1 supported |
||
186 | #define plugInModeIndexedColor 2 |
||
187 | #define plugInModeRGBColor 3 supported |
||
188 | #define plugInModeCMYKColor 4 supported |
||
189 | #define plugInModeHSLColor 5 |
||
190 | #define plugInModeHSBColor 6 |
||
191 | #define plugInModeMultichannel 7 |
||
192 | #define plugInModeDuotone 8 |
||
193 | #define plugInModeLabColor 9 |
||
194 | #define plugInModeGray16 10 |
||
195 | #define plugInModeRGB48 11 |
||
196 | #define plugInModeLab48 12 |
||
197 | #define plugInModeCMYK64 13 |
||
198 | #define plugInModeDeepMultichannel 14 |
||
199 | #define plugInModeDuotone16 15 |
||
200 | #define plugInModeRGB96 16 |
||
201 | #define plugInModeGray32 17 |
||
202 | */ |
||
203 | |||
204 | } |
||
158 | dmarschall | 205 | #else |
206 | // This is the behavior of FilterFoundry <1.7 was this (filled with 0xFF) |
||
207 | // FIXME: Should we do something fancy here, too? |
||
208 | p[i] = 0xFF; |
||
209 | #endif |
||
156 | dmarschall | 210 | } |
211 | return ptr; |
||
212 | } |
||
213 | |||
232 | daniel-mar | 214 | void recalc_preview_olddoc(FilterRecordPtr pb, DIALOGREF dp) { |
2 | toby | 215 | OSErr e; |
185 | dmarschall | 216 | double scaledw, scaledh; |
232 | daniel-mar | 217 | int j, n, imgw, imgh; |
218 | Rect r, outRect; |
||
2 | toby | 219 | Ptr outrow; |
220 | |||
37 | toby | 221 | preview_complete = false; |
110 | dmarschall | 222 | |
232 | daniel-mar | 223 | if (preview_handle) { |
2 | toby | 224 | /* size of previewed area, of source image; but no larger than filtered area (selection) */ |
232 | daniel-mar | 225 | scaledw = zoomfactor * preview_w; |
226 | if (scaledw > ((double)FILTER_RECT(pb).right - (double)FILTER_RECT(pb).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; |
||
110 | dmarschall | 231 | |
2 | toby | 232 | /* scale clipped preview area down again - this becomes the pixel size of preview */ |
232 | daniel-mar | 233 | imgw = (int)ceil(scaledw / zoomfactor); |
234 | if (imgw > preview_w) |
||
2 | toby | 235 | imgw = preview_w; |
232 | daniel-mar | 236 | imgh = (int)ceil(scaledh / zoomfactor); |
237 | if (imgh > preview_h) |
||
2 | toby | 238 | imgh = preview_h; |
239 | |||
240 | /* compute source data rectangle (inRect) */ |
||
241 | |||
242 | /* centre preview on filtered part of input image, adding scroll offset */ |
||
232 | daniel-mar | 243 | r.left = (int16)(((double)FILTER_RECT(pb).left + (double)FILTER_RECT(pb).right - scaledw) / 2 + preview_scroll.h); |
2 | toby | 244 | /* make sure it does not go outside the input area */ |
232 | daniel-mar | 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; |
||
110 | dmarschall | 248 | } |
232 | daniel-mar | 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); |
||
110 | dmarschall | 252 | } |
232 | daniel-mar | 253 | r.right = (int16)((double)r.left + scaledw); |
254 | preview_pmap.maskPhaseCol = (int32)((preview_scroll.h) / zoomfactor); // phase of the checkerboard |
||
2 | toby | 255 | |
256 | /* now compute for vertical */ |
||
232 | daniel-mar | 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; |
||
110 | dmarschall | 261 | } |
232 | daniel-mar | 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); |
||
110 | dmarschall | 265 | } |
232 | daniel-mar | 266 | r.bottom = (int16)((double)r.top + scaledh); |
267 | preview_pmap.maskPhaseRow = (int32)((preview_scroll.v) / zoomfactor); // phase of the checkerboard |
||
2 | toby | 268 | |
269 | /* if formulae need random access to image - src(), rad() - we must request entire area: */ |
||
232 | daniel-mar | 270 | if (needall) |
271 | SETRECT(IN_RECT(pb), 0, 0, IMAGE_SIZE(pb).h, IMAGE_SIZE(pb).v); |
||
94 | toby | 272 | else |
232 | daniel-mar | 273 | IN_RECT(pb) = r; |
110 | dmarschall | 274 | |
232 | daniel-mar | 275 | OUT_RECT(pb) = IN_RECT(pb); |
276 | SETRECT(MASK_RECT(pb), 0, 0, 0, 0); |
||
2 | toby | 277 | pb->inLoPlane = pb->outLoPlane = 0; |
232 | daniel-mar | 278 | pb->inHiPlane = pb->outHiPlane = nplanes - 1; |
37 | toby | 279 | |
232 | daniel-mar | 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, |
||
89 | toby | 284 | pmrb = preview_pmap.rowBytes; |
2 | toby | 285 | |
94 | toby | 286 | evalinit(); |
110 | dmarschall | 287 | |
232 | daniel-mar | 288 | SETRECT(outRect, 0, 0, imgw, imgh); |
110 | dmarschall | 289 | |
232 | daniel-mar | 290 | e = process_scaled_olddoc(pb, false, r, outRect, |
291 | outptr + pmrb * blankrows + nplanes * blankcols, pmrb, zoomfactor); |
||
292 | if (blankrows) { |
||
157 | dmarschall | 293 | // blank rows on top of preview: |
232 | daniel-mar | 294 | memset_bgcolor(outptr, pmrb * blankrows); |
157 | dmarschall | 295 | // blank rows below preview: |
296 | n = preview_h - blankrows - imgh; |
||
232 | daniel-mar | 297 | memset_bgcolor(outptr + pmrb * (blankrows + imgh), pmrb * n); |
2 | toby | 298 | } |
232 | daniel-mar | 299 | if (blankcols) { |
157 | dmarschall | 300 | n = preview_w - blankcols - imgw; |
232 | daniel-mar | 301 | outrow = outptr + pmrb * blankrows; |
302 | for (j = blankrows; j < preview_h - blankrows; ++j) { |
||
157 | dmarschall | 303 | // blank columns on left side of preview (if picture is smaller than the preview area): |
232 | daniel-mar | 304 | memset_bgcolor(outrow, nplanes * blankcols); |
157 | dmarschall | 305 | // blank columns on right side of preview (if picture is smaller than the preview area): |
232 | daniel-mar | 306 | memset_bgcolor(outrow + nplanes * (blankcols + imgw), nplanes * n); |
53 | toby | 307 | outrow += pmrb; |
2 | toby | 308 | } |
309 | } |
||
310 | |||
232 | daniel-mar | 311 | if (!e) { |
2 | toby | 312 | preview_complete = true; |
313 | |||
314 | #ifdef WIN_ENV |
||
315 | { |
||
232 | daniel-mar | 316 | extern HWND preview_hwnd; |
317 | HDC hdc = GetDC(preview_hwnd); |
||
89 | toby | 318 | |
232 | daniel-mar | 319 | drawpreview(dp, hdc, outptr); |
110 | dmarschall | 320 | |
232 | daniel-mar | 321 | ReleaseDC(preview_hwnd, hdc); |
2 | toby | 322 | } |
323 | #else |
||
324 | { |
||
232 | daniel-mar | 325 | GrafPtr saveport; |
2 | toby | 326 | |
232 | daniel-mar | 327 | GetPort(&saveport); |
328 | SetPortDialogPort(dp); |
||
110 | dmarschall | 329 | |
232 | daniel-mar | 330 | drawpreview(dp, NULL, outptr); |
110 | dmarschall | 331 | |
232 | daniel-mar | 332 | SetPort(saveport); |
2 | toby | 333 | } |
334 | #endif |
||
335 | } |
||
336 | |||
337 | PIUNLOCKHANDLE(preview_handle); |
||
94 | toby | 338 | } |
2 | toby | 339 | |
232 | daniel-mar | 340 | if (e && !previewerr) { |
198 | daniel-mar | 341 | alertuser(_strdup("Could not build preview at chosen zoom level."), |
232 | daniel-mar | 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("")); |
37 | toby | 343 | previewerr = true; |
2 | toby | 344 | } |
37 | toby | 345 | |
2 | toby | 346 | } |
347 | } |
||
348 | |||
232 | daniel-mar | 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; |
||
363 | scaledh = zoomfactor * preview_h; |
||
364 | if (scaledh > ((double)BIGDOC_FILTER_RECT(pb).bottom - (double)BIGDOC_FILTER_RECT(pb).top)) |
||
365 | scaledh = (double)BIGDOC_FILTER_RECT(pb).bottom - (double)BIGDOC_FILTER_RECT(pb).top; |
||
366 | |||
367 | /* scale clipped preview area down again - this becomes the pixel size of preview */ |
||
368 | imgw = (int)ceil(scaledw / zoomfactor); |
||
369 | if (imgw > preview_w) |
||
370 | imgw = preview_w; |
||
371 | imgh = (int)ceil(scaledh / zoomfactor); |
||
372 | if (imgh > preview_h) |
||
373 | imgh = preview_h; |
||
374 | |||
375 | /* compute source data rectangle (inRect) */ |
||
376 | |||
377 | /* centre preview on filtered part of input image, adding scroll offset */ |
||
378 | r.left = (int32)(((double)BIGDOC_FILTER_RECT(pb).left + (double)BIGDOC_FILTER_RECT(pb).right - scaledw) / 2 + preview_scroll.h); |
||
379 | /* make sure it does not go outside the input area */ |
||
380 | if (r.left < BIGDOC_FILTER_RECT(pb).left) { |
||
381 | preview_scroll.h += BIGDOC_FILTER_RECT(pb).left - r.left; |
||
382 | r.left = BIGDOC_FILTER_RECT(pb).left; |
||
383 | } |
||
384 | else if ((double)r.left + scaledw > BIGDOC_FILTER_RECT(pb).right) { |
||
385 | preview_scroll.h += (int32)((double)BIGDOC_FILTER_RECT(pb).right - ((double)r.left + scaledw)); |
||
386 | r.left = (int32)((double)BIGDOC_FILTER_RECT(pb).right - scaledw); |
||
387 | } |
||
388 | r.right = (int32)((double)r.left + scaledw); |
||
389 | preview_pmap.maskPhaseCol = (int32)((preview_scroll.h) / zoomfactor); // phase of the checkerboard |
||
390 | |||
391 | /* now compute for vertical */ |
||
392 | r.top = (int32)(((double)BIGDOC_FILTER_RECT(pb).top + (double)BIGDOC_FILTER_RECT(pb).bottom - scaledh) / 2 + preview_scroll.v); |
||
393 | if (r.top < BIGDOC_FILTER_RECT(pb).top) { |
||
394 | preview_scroll.v += BIGDOC_FILTER_RECT(pb).top - r.top; |
||
395 | r.top = BIGDOC_FILTER_RECT(pb).top; |
||
396 | } |
||
397 | else if ((double)r.top + scaledh > BIGDOC_FILTER_RECT(pb).bottom) { |
||
398 | preview_scroll.v += (int32)(BIGDOC_FILTER_RECT(pb).bottom - ((double)r.top + scaledh)); |
||
399 | r.top = (int32)((double)BIGDOC_FILTER_RECT(pb).bottom - scaledh); |
||
400 | } |
||
401 | r.bottom = (int32)((double)r.top + scaledh); |
||
402 | preview_pmap.maskPhaseRow = (int32)((preview_scroll.v) / zoomfactor); // phase of the checkerboard |
||
403 | |||
404 | /* if formulae need random access to image - src(), rad() - we must request entire area: */ |
||
405 | if (needall) |
||
406 | SETRECT(BIGDOC_IN_RECT(pb), 0, 0, BIGDOC_IMAGE_SIZE(pb).h, BIGDOC_IMAGE_SIZE(pb).v); |
||
407 | else |
||
408 | BIGDOC_IN_RECT(pb) = r; |
||
409 | |||
410 | BIGDOC_OUT_RECT(pb) = BIGDOC_IN_RECT(pb); |
||
411 | SETRECT(BIGDOC_MASK_RECT(pb), 0, 0, 0, 0); |
||
412 | pb->inLoPlane = pb->outLoPlane = 0; |
||
413 | pb->inHiPlane = pb->outHiPlane = nplanes - 1; |
||
414 | |||
415 | if (!needinput || !(e = pb->advanceState())) { |
||
416 | Ptr outptr = PILOCKHANDLE(preview_handle, false); |
||
417 | int blankrows = (preview_h - imgh) / 2, |
||
418 | blankcols = (preview_w - imgw) / 2, |
||
419 | pmrb = preview_pmap.rowBytes; |
||
420 | |||
421 | evalinit(); |
||
422 | |||
423 | SETRECT(outRect, 0, 0, imgw, imgh); |
||
424 | |||
425 | e = process_scaled_bigdoc(pb, false, r, outRect, |
||
426 | outptr + pmrb * blankrows + nplanes * blankcols, pmrb, zoomfactor); |
||
427 | if (blankrows) { |
||
428 | // blank rows on top of preview: |
||
429 | memset_bgcolor(outptr, pmrb * blankrows); |
||
430 | // blank rows below preview: |
||
431 | n = preview_h - blankrows - imgh; |
||
432 | memset_bgcolor(outptr + pmrb * (blankrows + imgh), pmrb * n); |
||
433 | } |
||
434 | if (blankcols) { |
||
435 | n = preview_w - blankcols - imgw; |
||
436 | outrow = outptr + pmrb * blankrows; |
||
437 | for (j = blankrows; j < preview_h - blankrows; ++j) { |
||
438 | // blank columns on left side of preview (if picture is smaller than the preview area): |
||
439 | memset_bgcolor(outrow, nplanes * blankcols); |
||
440 | // blank columns on right side of preview (if picture is smaller than the preview area): |
||
441 | memset_bgcolor(outrow + nplanes * (blankcols + imgw), nplanes * n); |
||
442 | outrow += pmrb; |
||
443 | } |
||
444 | } |
||
445 | |||
446 | if (!e) { |
||
447 | preview_complete = true; |
||
448 | |||
449 | #ifdef WIN_ENV |
||
450 | { |
||
451 | extern HWND preview_hwnd; |
||
452 | HDC hdc = GetDC(preview_hwnd); |
||
453 | |||
454 | drawpreview(dp, hdc, outptr); |
||
455 | |||
456 | ReleaseDC(preview_hwnd, hdc); |
||
457 | } |
||
458 | #else |
||
459 | { |
||
460 | GrafPtr saveport; |
||
461 | |||
462 | GetPort(&saveport); |
||
463 | SetPortDialogPort(dp); |
||
464 | |||
465 | drawpreview(dp, NULL, outptr); |
||
466 | |||
467 | SetPort(saveport); |
||
468 | } |
||
469 | #endif |
||
470 | } |
||
471 | |||
472 | PIUNLOCKHANDLE(preview_handle); |
||
473 | } |
||
474 | |||
475 | if (e && !previewerr) { |
||
476 | alertuser(_strdup("Could not build preview at chosen zoom level."), |
||
477 | 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("")); |
||
478 | previewerr = true; |
||
479 | } |
||
480 | |||
481 | } |
||
482 | } |
||
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 | |||
2 | toby | 493 | OSErr drawpreview(DIALOGREF dp,void *hdc,Ptr imageptr){ |
114 | dmarschall | 494 | intptr_t watchsusp; |
2 | toby | 495 | OSErr e = noErr; |
496 | VRect srcRect; |
||
497 | UIRECT imagebounds; |
||
498 | |||
499 | if(preview_handle && preview_complete){ |
||
500 | |||
501 | srcRect = preview_pmap.bounds; |
||
502 | |||
53 | toby | 503 | imagebounds.left = (preview_rect.left + preview_rect.right - preview_w)/2; |
504 | imagebounds.top = (preview_rect.top + preview_rect.bottom - preview_h)/2; |
||
2 | toby | 505 | imagebounds.right = imagebounds.left + preview_w; |
506 | imagebounds.bottom = imagebounds.top + preview_h; |
||
507 | |||
89 | toby | 508 | preview_pmap.baseAddr = imageptr; |
94 | toby | 509 | preview_pmask.maskData = imageptr+3; // FIXME: is this offset correct for all modes?! |
2 | toby | 510 | |
511 | if(gpb->propertyProcs->getPropertyProc){ |
||
512 | gpb->propertyProcs->getPropertyProc(kPhotoshopSignature,propWatchSuspension,0,&watchsusp,NULL); |
||
513 | gpb->propertyProcs->setPropertyProc(kPhotoshopSignature,propWatchSuspension,0,watchsusp+1,NULL); |
||
514 | } |
||
89 | toby | 515 | |
2 | toby | 516 | e = gpb->displayPixels(&preview_pmap,&srcRect,imagebounds.top,imagebounds.left,hdc); |
517 | |||
518 | if(gpb->propertyProcs->getPropertyProc) |
||
519 | gpb->propertyProcs->setPropertyProc(kPhotoshopSignature,propWatchSuspension,0,watchsusp,NULL); |
||
520 | } |
||
521 | return e; |
||
522 | } |