Rev 503 | Rev 532 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
259 | daniel-mar | 1 | /* |
526 | daniel-mar | 2 | This file is part of "Filter Foundry", a filter plugin for Adobe Photoshop |
259 | daniel-mar | 3 | Copyright (C) 2003-2009 Toby Thain, toby@telegraphics.com.au |
503 | daniel-mar | 4 | Copyright (C) 2018-2022 Daniel Marschall, ViaThinkSoft |
259 | daniel-mar | 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 | |||
486 | daniel-mar | 107 | newBuffer(&preview_handle, (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())) { |
||
486 | 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 | |||
486 | daniel-mar | 334 | unlockBuffer(&preview_handle); |
259 | daniel-mar | 335 | } |
336 | |||
337 | if (e && !previewerr) { |
||
492 | daniel-mar | 338 | simplealert_id(e == memFullErr && !needall ? MSG_CANNOT_ZOOM_MEMFULL_ID : MSG_CANNOT_ZOOM_ID); |
259 | daniel-mar | 339 | previewerr = true; |
340 | } |
||
341 | |||
342 | } |
||
343 | } |
||
344 | |||
345 | void recalc_preview_bigdoc(FilterRecordPtr pb, DIALOGREF dp) { |
||
346 | OSErr e; |
||
347 | double scaledw, scaledh; |
||
348 | int j, n, imgw, imgh; |
||
349 | VRect r, outRect; |
||
350 | Ptr outrow; |
||
351 | |||
352 | preview_complete = false; |
||
353 | |||
485 | daniel-mar | 354 | if (preview_handle.signature != BUFVERSION_NULL) { |
259 | daniel-mar | 355 | /* size of previewed area, of source image; but no larger than filtered area (selection) */ |
356 | scaledw = zoomfactor * preview_w; |
||
357 | if (scaledw > ((double)BIGDOC_FILTER_RECT(pb).right - (double)BIGDOC_FILTER_RECT(pb).left)) |
||
358 | scaledw = (double)BIGDOC_FILTER_RECT(pb).right - (double)BIGDOC_FILTER_RECT(pb).left; |
||
359 | scaledh = zoomfactor * preview_h; |
||
360 | if (scaledh > ((double)BIGDOC_FILTER_RECT(pb).bottom - (double)BIGDOC_FILTER_RECT(pb).top)) |
||
361 | scaledh = (double)BIGDOC_FILTER_RECT(pb).bottom - (double)BIGDOC_FILTER_RECT(pb).top; |
||
362 | |||
363 | /* scale clipped preview area down again - this becomes the pixel size of preview */ |
||
364 | imgw = (int)ceil(scaledw / zoomfactor); |
||
365 | if (imgw > preview_w) |
||
366 | imgw = preview_w; |
||
367 | imgh = (int)ceil(scaledh / zoomfactor); |
||
368 | if (imgh > preview_h) |
||
369 | imgh = preview_h; |
||
370 | |||
371 | /* compute source data rectangle (inRect) */ |
||
372 | |||
373 | /* centre preview on filtered part of input image, adding scroll offset */ |
||
374 | r.left = (int32)(((double)BIGDOC_FILTER_RECT(pb).left + (double)BIGDOC_FILTER_RECT(pb).right - scaledw) / 2 + preview_scroll.h); |
||
375 | /* make sure it does not go outside the input area */ |
||
376 | if (r.left < BIGDOC_FILTER_RECT(pb).left) { |
||
377 | preview_scroll.h += BIGDOC_FILTER_RECT(pb).left - r.left; |
||
378 | r.left = BIGDOC_FILTER_RECT(pb).left; |
||
379 | } |
||
380 | else if ((double)r.left + scaledw > BIGDOC_FILTER_RECT(pb).right) { |
||
381 | preview_scroll.h += (int32)((double)BIGDOC_FILTER_RECT(pb).right - ((double)r.left + scaledw)); |
||
382 | r.left = (int32)((double)BIGDOC_FILTER_RECT(pb).right - scaledw); |
||
383 | } |
||
384 | r.right = (int32)((double)r.left + scaledw); |
||
385 | preview_pmap.maskPhaseCol = (int32)((preview_scroll.h) / zoomfactor); // phase of the checkerboard |
||
386 | |||
387 | /* now compute for vertical */ |
||
388 | r.top = (int32)(((double)BIGDOC_FILTER_RECT(pb).top + (double)BIGDOC_FILTER_RECT(pb).bottom - scaledh) / 2 + preview_scroll.v); |
||
389 | if (r.top < BIGDOC_FILTER_RECT(pb).top) { |
||
390 | preview_scroll.v += BIGDOC_FILTER_RECT(pb).top - r.top; |
||
391 | r.top = BIGDOC_FILTER_RECT(pb).top; |
||
392 | } |
||
393 | else if ((double)r.top + scaledh > BIGDOC_FILTER_RECT(pb).bottom) { |
||
394 | preview_scroll.v += (int32)(BIGDOC_FILTER_RECT(pb).bottom - ((double)r.top + scaledh)); |
||
395 | r.top = (int32)((double)BIGDOC_FILTER_RECT(pb).bottom - scaledh); |
||
396 | } |
||
397 | r.bottom = (int32)((double)r.top + scaledh); |
||
398 | preview_pmap.maskPhaseRow = (int32)((preview_scroll.v) / zoomfactor); // phase of the checkerboard |
||
399 | |||
400 | /* if formulae need random access to image - src(), rad() - we must request entire area: */ |
||
401 | if (needall) |
||
402 | SETRECT(BIGDOC_IN_RECT(pb), 0, 0, BIGDOC_IMAGE_SIZE(pb).h, BIGDOC_IMAGE_SIZE(pb).v); |
||
403 | else |
||
404 | BIGDOC_IN_RECT(pb) = r; |
||
405 | |||
406 | BIGDOC_OUT_RECT(pb) = BIGDOC_IN_RECT(pb); |
||
407 | SETRECT(BIGDOC_MASK_RECT(pb), 0, 0, 0, 0); |
||
408 | pb->inLoPlane = pb->outLoPlane = 0; |
||
409 | pb->inHiPlane = pb->outHiPlane = nplanes - 1; |
||
410 | |||
411 | if (!needinput || !(e = pb->advanceState())) { |
||
486 | daniel-mar | 412 | Ptr outptr = lockBuffer(&preview_handle); |
259 | daniel-mar | 413 | int blankrows = (preview_h - imgh) / 2, |
312 | daniel-mar | 414 | blankcols = (preview_w - imgw) / 2, |
415 | pmrb = preview_pmap.rowBytes; |
||
259 | daniel-mar | 416 | |
417 | evalinit(); |
||
418 | |||
419 | SETRECT(outRect, 0, 0, imgw, imgh); |
||
420 | |||
421 | e = process_scaled_bigdoc(pb, false, r, outRect, |
||
422 | outptr + pmrb * blankrows + nplanes * blankcols, pmrb, zoomfactor); |
||
423 | if (blankrows) { |
||
424 | // blank rows on top of preview: |
||
425 | memset_bgcolor(outptr, pmrb * blankrows); |
||
426 | // blank rows below preview: |
||
427 | n = preview_h - blankrows - imgh; |
||
428 | memset_bgcolor(outptr + pmrb * (blankrows + imgh), pmrb * n); |
||
429 | } |
||
430 | if (blankcols) { |
||
431 | n = preview_w - blankcols - imgw; |
||
432 | outrow = outptr + pmrb * blankrows; |
||
433 | for (j = blankrows; j < preview_h - blankrows; ++j) { |
||
434 | // blank columns on left side of preview (if picture is smaller than the preview area): |
||
435 | memset_bgcolor(outrow, nplanes * blankcols); |
||
436 | // blank columns on right side of preview (if picture is smaller than the preview area): |
||
437 | memset_bgcolor(outrow + nplanes * (blankcols + imgw), nplanes * n); |
||
438 | outrow += pmrb; |
||
439 | } |
||
440 | } |
||
441 | |||
482 | daniel-mar | 442 | if (e == noErr) { |
259 | daniel-mar | 443 | preview_complete = true; |
444 | |||
268 | daniel-mar | 445 | #ifdef WIN_ENV |
259 | daniel-mar | 446 | { |
447 | extern HWND preview_hwnd; |
||
448 | HDC hdc = GetDC(preview_hwnd); |
||
449 | |||
450 | drawpreview(dp, hdc, outptr); |
||
451 | |||
452 | ReleaseDC(preview_hwnd, hdc); |
||
453 | } |
||
268 | daniel-mar | 454 | #else |
259 | daniel-mar | 455 | { |
456 | GrafPtr saveport; |
||
457 | |||
458 | GetPort(&saveport); |
||
459 | SetPortDialogPort(dp); |
||
460 | |||
461 | drawpreview(dp, NULL, outptr); |
||
462 | |||
463 | SetPort(saveport); |
||
464 | } |
||
268 | daniel-mar | 465 | #endif |
259 | daniel-mar | 466 | } |
467 | |||
486 | daniel-mar | 468 | unlockBuffer(&preview_handle); |
259 | daniel-mar | 469 | } |
470 | |||
471 | if (e && !previewerr) { |
||
492 | daniel-mar | 472 | simplealert_id(e == memFullErr && !needall ? MSG_CANNOT_ZOOM_MEMFULL_ID : MSG_CANNOT_ZOOM_ID); |
259 | daniel-mar | 473 | previewerr = true; |
474 | } |
||
475 | |||
476 | } |
||
477 | } |
||
478 | |||
479 | void recalc_preview(FilterRecordPtr pb, DIALOGREF dp) { |
||
445 | daniel-mar | 480 | // TODO? When a formula has an error, the preview should not be changeable |
481 | // (This code does not work because you can still try to zoom) |
||
482 | /* |
||
483 | if (!gdata->standalone) { |
||
484 | int i; |
||
485 | for (i = 0; i < 4; i++) |
||
486 | if (!parseexpr(expr[i])) return; |
||
487 | } |
||
488 | */ |
||
489 | |||
259 | daniel-mar | 490 | if (HAS_BIG_DOC(pb)) { |
491 | recalc_preview_bigdoc(pb, dp); |
||
492 | } |
||
493 | else { |
||
494 | recalc_preview_olddoc(pb, dp); |
||
495 | } |
||
496 | } |
||
497 | |||
498 | OSErr drawpreview(DIALOGREF dp,void *hdc,Ptr imageptr){ |
||
499 | intptr_t watchsusp; |
||
500 | OSErr e = noErr; |
||
501 | VRect srcRect; |
||
502 | UIRECT imagebounds; |
||
503 | |||
433 | daniel-mar | 504 | UNREFERENCED_PARAMETER(dp); |
505 | |||
485 | daniel-mar | 506 | if((preview_handle.signature != BUFVERSION_NULL) && preview_complete){ |
259 | daniel-mar | 507 | |
508 | srcRect = preview_pmap.bounds; |
||
509 | |||
510 | imagebounds.left = (preview_rect.left + preview_rect.right - preview_w)/2; |
||
511 | imagebounds.top = (preview_rect.top + preview_rect.bottom - preview_h)/2; |
||
512 | imagebounds.right = imagebounds.left + preview_w; |
||
513 | imagebounds.bottom = imagebounds.top + preview_h; |
||
514 | |||
515 | preview_pmap.baseAddr = imageptr; |
||
516 | preview_pmask.maskData = imageptr+3; // FIXME: is this offset correct for all modes?! |
||
517 | |||
403 | daniel-mar | 518 | if((gpb->propertyProcs != NULL) && gpb->propertyProcs->getPropertyProc){ |
259 | daniel-mar | 519 | gpb->propertyProcs->getPropertyProc(kPhotoshopSignature,propWatchSuspension,0,&watchsusp,NULL); |
520 | gpb->propertyProcs->setPropertyProc(kPhotoshopSignature,propWatchSuspension,0,watchsusp+1,NULL); |
||
521 | } |
||
522 | |||
523 | e = gpb->displayPixels(&preview_pmap,&srcRect,imagebounds.top,imagebounds.left,hdc); |
||
524 | |||
403 | daniel-mar | 525 | if((gpb->propertyProcs != NULL) && gpb->propertyProcs->getPropertyProc) |
259 | daniel-mar | 526 | gpb->propertyProcs->setPropertyProc(kPhotoshopSignature,propWatchSuspension,0,watchsusp,NULL); |
527 | } |
||
528 | return e; |
||
529 | } |