/
preview.c
564 lines (458 loc) · 15.3 KB
/
preview.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
/*
PROJECT: PPT
MODULE: preview.c
$Id: preview.c,v 6.2 1999/12/27 21:59:27 jj Exp $
*/
#include "defs.h"
#include "misc.h"
#define PPTMSG_PREVIEW_REDRAW 0x300
struct PreviewMessage {
struct PPTMessage msg;
struct RastPort *rp;
struct IBox area;
WORD MouseX,MouseY;
WORD FrameX,FrameY;
};
/*
* Returns TRUE if this frame has a preview frame attached,
* i.e. it is being processed and the module wishes to show the
* preview.
*/
Prototype BOOL HasPreview( FRAME *frame );
BOOL HasPreview( FRAME *frame )
{
if( frame ) {
if(frame->parent)
return (BOOL) (frame->parent->preview.pf_Frame ? TRUE : FALSE);
else
return (BOOL) (frame->preview.pf_Frame ? TRUE : FALSE);
} else {
return FALSE;
}
}
/*
* Returns TRUE if the frame that was called is actually a preview
* frame.
*/
Prototype BOOL IsPreview( FRAME *frame );
BOOL IsPreview( FRAME *frame )
{
if( frame ) {
return frame->preview.pf_IsPreview;
} else {
return FALSE;
}
}
Prototype PERROR DoPreview( FRAME *frame );
PERROR DoPreview( FRAME *frame )
{
PERROR res = PERR_OK;
D(bug("DoPreview(%08X)\n",frame));
if( frame->preview.pf_Hook ) {
struct PreviewMessage *pm;
struct IBox *bounds;
/*
* Request a full redraw from the main object
*/
pm = (struct PreviewMessage *)AllocPPTMsg( sizeof(struct PreviewMessage), globxd );
pm->msg.code = PPTMSG_PREVIEW_REDRAW;
pm->msg.frame = frame;
pm->rp = frame->disp->win->RPort;
GetAttr( AREA_AreaBox, frame->disp->RenderArea, (ULONG *)&bounds);
pm->area = *bounds;
SendPPTMsg( frame->selection.selectport,pm,globxd );
} else {
#if 0
res = QuickDisplayFrame( frame->pf_Frame );
#endif
}
return res;
}
/*
BUG: Redraws false stuff
*/
Prototype VOID RedrawPreview( FRAME *pwframe, EXTBASE *PPTBase );
VOID RedrawPreview( FRAME *pwframe, EXTBASE *PPTBase )
{
D(bug("RedrawPreview( %08X, xb=%08X )\n",pwframe, PPTBase ));
if( pwframe->preview.pf_Hook ) {
CallHook( pwframe->preview.pf_Hook, (Object *)pwframe, ~0 );
} else {
/*
* Send message to the main window
*/
struct IBox *ibox;
GetAttr(AREA_AreaBox, pwframe->preview.pf_RenderArea, (ULONG *)&ibox );
QuickRender( pwframe, pwframe->preview.pf_win->RPort,
ibox->Top, ibox->Left,
ibox->Height, ibox->Width, PPTBase );
#if 0
DoMethod( pwframe->parent->disp->Win, WM_REPORT_ID, GID_DW_AREA,
WMRIF_TASK, globals->maintask, TAG_DONE );
#endif
}
}
Prototype VOID RedrawPreviewRow( FRAME *pwframe, ULONG row, EXTBASE *PPTBase );
VOID RedrawPreviewRow( FRAME *pwframe, ULONG row, EXTBASE *PPTBase )
{
D(bug("RedrawPreviewRow( %08X, xb=%08X )\n",pwframe, PPTBase ));
if( pwframe->preview.pf_Hook ) {
// BUG: Not the proper msg
CallHook( pwframe->preview.pf_Hook, (Object *)pwframe, row );
} else {
struct IBox *ibox;
GetAttr(AREA_AreaBox, pwframe->preview.pf_RenderArea, (ULONG *)&ibox );
QuickRender( pwframe, pwframe->preview.pf_win->RPort,
ibox->Top, ibox->Left,
ibox->Height, ibox->Width, PPTBase );
#if 0
/*
* Send message to the main window
*/
DoMethod( pwframe->parent->disp->Win, WM_REPORT_ID, GID_DW_AREA,
WMRIF_TASK, globals->maintask, TAG_DONE );
#endif
}
}
/*
Frames must be of the same colorspace!
Make sure frames have their sizes correctly.
BUG: Does not check it.
BUG: No error checks
BUG: Does not really belong here
*/
SAVEDS ASM
PERROR ScaleFrame( REG(a0) FRAME *src, REG(a1) FRAME *dst,
REG(d0) ULONG opts,
REG(a6) EXTBASE *PPTBase )
{
WORD row, col;
WORD orow, ocol;
WORD comps = src->pix->components;
if(!CheckPtr(src,"ScaleFrame(): illegal src")) return PERR_ERROR;
if(!CheckPtr(dst,"ScaleFrame(): illegal dst")) return PERR_ERROR;
for( row = 0; row < dst->pix->height; row++ ) {
ROWPTR cp, dcp;
orow = row * src->pix->height / dst->pix->height;
cp = GetPixelRow(src, orow, PPTBase);
dcp = GetPixelRow(dst,row, PPTBase);
if( !cp || !dcp ) {
SetErrorCode( src, PERR_NOTINIMAGE );
return PERR_NOTINIMAGE;
}
for( col = 0; col < dst->pix->width; col++ ) {
int i;
ocol = col * src->pix->width / dst->pix->width;
for( i = 0; i < comps; i++ ) {
dcp[comps*col+i] = cp[comps*ocol+i];
}
}
PutPixelRow( dst, row, dcp, PPTBase );
}
return PERR_OK;
}
/****u* pptsupport/ObtainPreviewFrameA ******************************************
*
* NAME
* ObtainPreviewFrameA - Create a preview frame for an external.
* ObtainPreviewFrame - varargs version.
*
* SYNOPSIS
* preview = ObtainPreviewFrameA( frame, tags );
* D0 A0 A1
*
* FRAME *ObtainPreviewFrameA( FRAME *, struct TagItem * );
*
* FUNCTION
* Obtains a preview frame (a small version of the original image,
* also known as a thumbnail).
*
* The size of the thumbnail depends on the preferences set
* by the user.
*
* INPUTS
* Available tags are:
*
* PREV_PreviewHook (struct Hook *) - Specifying this tag means
* that the external module is prepared to handle the entire
* drawing of the preview by itself. Don't do this unless
* you really know what you're doing.
*
* RESULT
* preview - the preview frame.
*
* EXAMPLE
*
* NOTES
*
* BUGS
* This entry incomplete.
*
* SEE ALSO
* ReleasePreviewFrame(), example code in externals/src/,
* AskReqA()
*
*****************************************************************************
*
*
* Creates a preview frame, when used, will be rendered in stead
* of the actual frame.
*
* Tags:
* PREV_PreviewHook (HOOKPTR) - The external will completely take care
* of rendering the imagery.
*/
Prototype FRAME * ASM ObtainPreviewFrameA( REG(a0) FRAME *,REG(a1) struct TagItem *,REG(a6) EXTBASE * );
SAVEDS ASM
FRAME *ObtainPreviewFrameA( REG(a0) FRAME *frame,
REG(a1) struct TagItem *tags,
REG(a6) EXTBASE *PPTBase )
{
FRAME *pwframe, *tmpframe;
struct Library *UtilityBase = PPTBase->lb_Utility;
WORD pw = globals->userprefs->previewwidth,
ph = globals->userprefs->previewheight;
D(bug("ObtainPreviewFrameA( frame=%08X, tags=%08X )\n",frame,tags));
if(!CheckPtr(frame,"ObtainPreviewFrame():frame"))
return NULL;
/*
* Check for current preview mode and preview size validity
*/
if( ph <= 0 || pw <= 0 || globals->userprefs->previewmode == PWMODE_OFF )
return NULL; /* Previews are disabled or broken */
/*
* Temporary frames cannot have previews either
* (they contain no data and have zero size.)
*/
if( frame->istemporary ) return NULL;
if(pwframe = MakeFrame( frame->parent ? frame->parent : frame, PPTBase )) {
/*
* Set up the preview frame to be a bit smaller than
* what we used to have.
*
* Note that the frame->parent is the old frame and shall
* always be used.
*/
pwframe->pix->width = pw;
if( frame->pix->DPIX && frame->pix->DPIY ) {
pwframe->pix->height = (pwframe->pix->width * frame->pix->height * frame->pix->DPIY / (frame->pix->width * frame->pix->DPIX) );
} else {
pwframe->pix->height = (pwframe->pix->width * frame->pix->height / (frame->pix->width) );
}
#if 0
if( pwframe->pix->height < ph/2 ) {
pwframe->pix->height = ph;
pwframe->pix->width = (pwframe->pix->height * frame->pix->width / frame->pix->height );
}
#endif
D(bug("\tPreview frame is %dx%d\n",pwframe->pix->width,pwframe->pix->height ));
pwframe->preview.pf_IsPreview = TRUE;
SetVMemMode( pwframe, VMEM_NEVER, PPTBase );
if( InitFrame( pwframe, PPTBase ) == PERR_OK ) {
if(ScaleFrame( frame, pwframe, 0L, PPTBase ) == PERR_OK ) {
struct Hook *hook;
struct PPTMessage *pmsg;
/*
* Make a copy to the tmpframe
*/
if(tmpframe = DupFrame( pwframe, DFF_COPYDATA, PPTBase )) {
/*
* Calculate the new selbox size and save it.
*/
CopySelection( frame, pwframe );
if( IsAreaSelected(frame) ) {
RescaleSelection( frame, pwframe );
} else {
SelectWholeImage( pwframe );
}
CopySelection( pwframe, tmpframe );
/*
* Set up the frame for PW frame
*/
LOCK(frame);
ChangeBusyStatus(pwframe,BUSY_READONLY);
if( hook = (struct Hook *)GetTagData( PREV_PreviewHook, NULL, tags ) ) {
pwframe->preview.pf_Hook = hook;
}
if( frame->parent ) {
LOCK(frame->parent);
frame->parent->preview.pf_Frame = pwframe;
frame->parent->preview.pf_TempFrame = tmpframe;
UNLOCK(frame->parent);
} else {
frame->preview.pf_Frame = pwframe;
frame->preview.pf_TempFrame = tmpframe;
}
UNLOCK(frame);
pmsg = AllocPPTMsg( sizeof(struct PPTMessage), PPTBase );
pmsg->code = PPTMSG_START_PREVIEW;
if( frame->parent )
pmsg->frame = frame->parent;
else
pmsg->frame = frame;
SendPPTMsg( globxd->mport, pmsg, PPTBase );
WaitForReply( PPTMSG_START_PREVIEW, PPTBase );
} else {
RemFrame( pwframe, PPTBase );
pwframe = NULL;
}
} else {
RemFrame(pwframe, PPTBase);
pwframe = NULL;
}
} else {
RemFrame(pwframe, PPTBase);
pwframe = NULL;
}
}
D(bug("\tReturning preview frame at %08X\n",pwframe));
return pwframe;
}
/****u* pptsupport/ReleasePreviewFrame ******************************************
*
* NAME
* ReleasePreviewFrame - releases a preview frame.
*
* SYNOPSIS
* ReleasePreviewFrame( preview );
* A0
*
* VOID ReleasePreviewFrame( FRAME * );
*
* FUNCTION
* Releases the small image acquired by ObtainPreviewFrame().
*
* INPUTS
* preview - The preview frame.
*
* RESULT
* N/A
*
* EXAMPLE
*
* NOTES
* The frame is freed completely after this call, so you'd better
* not access the memory in any way.
*
* BUGS
*
* SEE ALSO
* ObtainPreviewFrameA()
*
*****************************************************************************
*
*
* Release preview frame obtained by ObtainPreviewFrame()
*/
Prototype VOID ASM ReleasePreviewFrame( REG(a0) FRAME *, REG(a6) EXTBASE *);
SAVEDS ASM
VOID ReleasePreviewFrame( REG(a0) FRAME *pwframe,
REG(a6) EXTBASE *PPTBase )
{
FRAME *frame;
struct PPTMessage *pmsg;
D(bug("ReleasePreviewFrame( %08X )\n",pwframe));
if( !CheckPtr(pwframe,"ReleasePreviewFrame(): pwframe")) return;
frame = pwframe->parent;
if( !CheckPtr(frame,"ReleasePreviewFrame(): parent frame")) return;
pmsg = AllocPPTMsg( sizeof(struct PPTMessage), PPTBase );
pmsg->code = PPTMSG_STOP_PREVIEW;
if( frame->parent )
pmsg->frame = frame->parent;
else
pmsg->frame = frame;
SendPPTMsg( globxd->mport, pmsg, PPTBase );
WaitForReply( PPTMSG_STOP_PREVIEW, PPTBase );
LOCK(pwframe);
RemFrame( pwframe, PPTBase );
LOCK(frame->preview.pf_TempFrame);
RemFrame( frame->preview.pf_TempFrame, PPTBase );
LOCK(frame);
frame->preview.pf_Hook = NULL;
frame->preview.pf_Frame = NULL;
frame->preview.pf_TempFrame = NULL;
frame->preview.pf_IsPreview = FALSE;
UNLOCK(frame);
}
/****u* pptsupport/RenderFrame ******************************************
*
* NAME
* RenderFrame - renders a frame to the specified rastport. (V4)
*
* SYNOPSIS
* error = RenderFrame( frame, rport, location, flags );
* D0 A0 A1 A2 D0
*
* PERROR RenderFrame( FRAME *, struct RastPort *, struct IBox *, ULONG );
*
* FUNCTION
* Use this function to render the frame into a RastPort. PPT will
* automatically use the correct coloring routine.
*
* This is the internal previewing routine, so the results may not be
* very accurate. Also, the current previewing preferences may
* change the result.
*
* INPUTS
* frame - the usual.
* rport - the RastPort of the window you want the frame to be rendered
* into.
* location - the location and size of the image.
* flags - reserved for future use.
*
* RESULT
* Standard error code.
*
* EXAMPLE
*
* NOTES
*
* BUGS
* Does not do very extensive error checking at the moment.
*
* SEE ALSO
*
*****************************************************************************
*
* A simple interface to the QuickRender() routines.
* BUG: Should do a bit more error checking.
*/
Prototype PERROR ASM RenderFrame( REG(a0) FRAME *, REG(a1) struct RastPort *, REG(a2) struct IBox *, REG(d0) ULONG, REG(a6) EXTBASE * );
SAVEDS ASM
PERROR RenderFrame( REG(a0) FRAME *frame,
REG(a1) struct RastPort *rport,
REG(a2) struct IBox *loc,
REG(d0) ULONG flags,
REG(a6) EXTBASE *PPTBase )
{
D(bug("QuickRender( %08X, rp=%08X, Top=%d, Left=%d, Ht=%d, Wt=%d )\n",
frame, rport, loc->Top, loc->Left, loc->Height, loc->Width ));
return QuickRender( frame, rport, loc->Top, loc->Left, loc->Height, loc->Width, PPTBase );
}
/*
* Currently these two just lock the main window, nothing else.
*
* Actually, they don't even do that, thanks to the small
* window previews we use, since locking the windows will
* cause severe problems with externals that expect to get
* messages from the windows...
*/
Prototype VOID SetupFrameForPreview( struct PPTMessage *pmsg );
VOID SetupFrameForPreview( struct PPTMessage *pmsg )
{
FRAME *frame = pmsg->frame;
LOCK(frame);
EraseSelection( frame );
// WindowBusy( frame->disp->Win );
UNLOCK(frame);
pmsg->data = PERR_OK; /* Signal: successful */
}
Prototype VOID FinishFramePreview( struct PPTMessage *pmsg );
VOID FinishFramePreview( struct PPTMessage *pmsg )
{
FRAME *frame = pmsg->frame;
LOCK(frame);
// WindowReady( frame->disp->Win );
UNLOCK(frame);
pmsg->data = PERR_OK;
}