-
Notifications
You must be signed in to change notification settings - Fork 0
/
CopyBitsSpeedPalette.c
executable file
·456 lines (392 loc) · 12.5 KB
/
CopyBitsSpeedPalette.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
/*
File: CopyBitsSpeedPalette.c
Contains: This program demostrates ways to increase copybits speed when using palettes.
Written by: JW
Copyright: Copyright © 1991-1999 by Apple Computer, Inc., All Rights Reserved.
You may incorporate this Apple sample source code into your program(s) without
restriction. This Apple sample source code has been provided "AS IS" and the
responsibility for its operation is yours. You are not permitted to redistribute
this Apple sample source code as "Apple sample source code" after having made
changes. If you're going to re-distribute the source, we require that you make
it clear in the source that the code was descended from Apple sample source
code, but that you've made changes.
Change History (most recent first):
08/2000 JM Carbonized, non-Carbon code is commented out
for demonstration purposes.
7/9/1999 KG Updated for Metrowerks Codewarror Pro 2.1
*/
#ifdef __MWERKS__
// includes for MetroWerks CodeWarrior
#include "CarbonPrefix.h"
#include <Dialogs.h>
#include <Resources.h>
#include <Menus.h>
#include <Devices.h>
#include <ToolUtils.h>
//#include <GestaltEqu.h>
#include <Gestalt.h>
#include <Palettes.h>
#include <QDOffscreen.h>
#include <Processes.h>
#include <OSUtils.h>
#else
#ifdef __APPLE_CC__
// includes for ProjectBuilder
#include <Carbon/Carbon.h>
#else
// includes for MPW
#include <Carbon.h>
#endif
#endif
#define Gestalttest 0xA1AD
#define NoTrap 0xA89F
#define appleID 128
#define appleMenu 0
#define aboutMeCommand 1
#define fileID 129
#define quitCommand 1
#define PictID 128
#define clutID 150
#define aboutMeDLOG 128
#define okButton 1
#ifndef topLeft
#define topLeft(r) (((Point *) &(r))[0])
#endif
#ifndef botRight
#define botRight(r) (((Point *) &(r))[1])
#endif
/*------------------------------------------------------*/
/* Global Variables. */
/*------------------------------------------------------*/
Rect TotalRect, minRect, WinMinusScroll, InitWindowSize;
WindowPtr myWindow;
CTabHandle mycolors;
PaletteHandle srcPalette;
Boolean DoneFlag;
MenuHandle mymenu0, mymenu1;
PicHandle ThePict;
GWorldPtr offscreenGWorld;
//enum PointSelector {topLeft, botRight};
void draw();
void doCommand(long mResult);
void showAboutMeDialog();
void init();
/*------------------------------------------------------*/
/* showAboutMeDialog(). */
/*------------------------------------------------------*/
void showAboutMeDialog()
{
GrafPtr savePort;
DialogPtr theDialog;
short itemHit;
GetPort(&savePort);
theDialog = GetNewDialog(aboutMeDLOG, nil, (WindowPtr) -1);
//SetPort(theDialog);
SetPortDialogPort(theDialog);
do {
ModalDialog(nil, &itemHit);
} while (itemHit != okButton);
//CloseDialog(theDialog);
DisposeDialog(theDialog);
SetPort(savePort);
return;
}
/*------------------------------------------------------*/
/* init(). */
/*------------------------------------------------------*/
void init()
{
RgnHandle tempRgn;
Rect BaseRect;
OSErr err;
long QDfeature/*, OSfeature*/;
GDHandle SaveGD;
CGrafPtr SavePort;
/* Initialize Managaer. */
//InitGraf(&qd.thePort);
//InitWindows();
//InitDialogs(nil);
InitCursor();
FlushEvents(everyEvent, 0);
/* Set up menus. */
mymenu0 = GetMenu(appleID);
//AppendResMenu(mymenu0, 'DRVR');
InsertMenu(mymenu0,0);
mymenu1 = GetMenu(fileID);
InsertMenu(mymenu1,0);
DrawMenuBar();
DoneFlag = false;
ThePict = GetPicture(PictID);
if (ThePict == nil)
DoneFlag = true;
/* Use Gestalt to find is QuickDraw is avaiable. */
/*if ((GetOSTrapAddress(Gestalttest) != GetOSTrapAddress(NoTrap))) {
err = Gestalt(gestaltQuickdrawVersion, &QDfeature);
if (err)
DoneFlag = true;
err = Gestalt(gestaltSystemVersion, &OSfeature);
if (err)
DoneFlag = true;
if (!DoneFlag && (QDfeature & 0x0f00) != 0x0200 && OSfeature < 0x0605)
DoneFlag = true;
}
else
DoneFlag = true;*/
err = Gestalt(gestaltQuickdrawVersion, &QDfeature);
if (err != noErr || QDfeature < gestalt32BitQD)
DoneFlag = true;
/* Set Rects. */
SetRect(&BaseRect, 40, 60, 472, 282);
SetRect(&WinMinusScroll, BaseRect.left-40, BaseRect.top-60, BaseRect.right-60,
BaseRect.bottom - 80);
SetRect(&InitWindowSize, WinMinusScroll.left, WinMinusScroll.top,
WinMinusScroll.right, WinMinusScroll.bottom);
tempRgn = GetGrayRgn();
HLock ((Handle) tempRgn);
//TotalRect = (**tempRgn).rgnBBox;
GetRegionBounds(tempRgn, &TotalRect);
/*SetRect(&minRect, 80, 80, (**tempRgn).rgnBBox.right - 40,
(**tempRgn).rgnBBox.bottom - 40);*/
SetRect(&minRect, 80, 80, TotalRect.right - 40, TotalRect.bottom - 40);
HUnlock ((Handle) tempRgn);
/* Open window and set up picture. */
GetGWorld (&SavePort, &SaveGD);
mycolors = GetCTable (clutID);
(*mycolors)->ctFlags |= 0x4000;
myWindow = NewCWindow(nil, &BaseRect, (ConstStr255Param)"", true, zoomDocProc,
(WindowPtr) -1, true, 150);
SetGWorld(GetWindowPort(myWindow), SaveGD);
DrawGrowIcon (myWindow);
srcPalette = NewPalette (((**mycolors).ctSize)+1, mycolors,
pmTolerant + pmExplicit + pmAnimated, 0);
SetPalette ((WindowPtr) myWindow, srcPalette, true);
GetGWorld (&SavePort, &SaveGD);
err = NewGWorld (&offscreenGWorld, 8, &InitWindowSize, mycolors, nil, 0);
if (err)
Debugger();
SetGWorld (offscreenGWorld, nil);
EraseRect (&InitWindowSize);
DrawPicture (ThePict, &InitWindowSize);
SetGWorld (SavePort, SaveGD);
}
/*------------------------------------------------------*/
/* doCommand(). */
/*------------------------------------------------------*/
void doCommand(mResult)
long mResult;
{
int theMenu, theItem;
//Str255 daName;
//GrafPtr savePort;
theItem = LoWord(mResult);
theMenu = HiWord(mResult);
switch (theMenu) {
case appleID:
if (theItem == aboutMeCommand)
showAboutMeDialog();
else {
/*GetMenuItemText(mymenu0, theItem, daName);
GetPort(&savePort);
(void) OpenDeskAcc((ConstStr255Param)daName);
SetPort(savePort);*/
}
break;
case fileID:
switch (theItem) {
case quitCommand:
DoneFlag = true;
break;
default:
break;
}
break;
}
HiliteMenu(0);
return;
}
/*------------------------------------------------------*/
/* draw. */
/*------------------------------------------------------*/
void draw()
{
RGBColor black = {0,0,0}, White = {65535,65535,65535};
long before, delay;
//char theString[255];
GDHandle screensDevice;
Rect area;
RGBForeColor (&black);
RGBBackColor (&White);
SetPortWindowPort(myWindow);
EraseRect(&WinMinusScroll);
/* This is the only change made to support a faster copybits on one screen.
ctFlags is still set above. */
area = WinMinusScroll;
/*LocalToGlobal(topLeft);
LocalToGlobal((Point*)botRight);*/
LocalToGlobal(&topLeft(area));
LocalToGlobal(&botRight(area));
screensDevice = GetMaxDevice(&area);
if (screensDevice != nil)
//(**(**offscreenGWorld->portPixMap).pmTable).ctSeed = (**(**(**screensDevice).gdPMap).pmTable).ctSeed;
(**(**(GetPortPixMap(offscreenGWorld))).pmTable).ctSeed = (**(**(**screensDevice).gdPMap).pmTable).ctSeed;
/*CopyBits ((BitMap *) *offscreenGWorld->portPixMap, &myWindow->portBits,
&InitWindowSize, &WinMinusScroll, srcCopy, nil);*/
CopyBits ((BitMap *) *(GetPortPixMap(offscreenGWorld)), GetPortBitMapForCopyBits(GetWindowPort(myWindow)),
&InitWindowSize, &WinMinusScroll, srcCopy, nil);
EraseRect(&WinMinusScroll);
/*CopyBits ((BitMap *) *offscreenGWorld->portPixMap, &myWindow->portBits,
&InitWindowSize, &WinMinusScroll, srcCopy, nil);*/
CopyBits ((BitMap *) *(GetPortPixMap(offscreenGWorld)), GetPortBitMapForCopyBits(GetWindowPort(myWindow)),
&InitWindowSize, &WinMinusScroll, srcCopy, nil);
EraseRect(&WinMinusScroll);
/*CopyBits ((BitMap *) *offscreenGWorld->portPixMap, &myWindow->portBits,
&InitWindowSize, &WinMinusScroll, srcCopy, nil);*/
CopyBits ((BitMap *) *(GetPortPixMap(offscreenGWorld)), GetPortBitMapForCopyBits(GetWindowPort(myWindow)),
&InitWindowSize, &WinMinusScroll, srcCopy, nil);
EraseRect(&WinMinusScroll);
/*CopyBits ((BitMap *) *offscreenGWorld->portPixMap, &myWindow->portBits,
&InitWindowSize, &WinMinusScroll, srcCopy, nil);*/
CopyBits ((BitMap *) *(GetPortPixMap(offscreenGWorld)), GetPortBitMapForCopyBits(GetWindowPort(myWindow)),
&InitWindowSize, &WinMinusScroll, srcCopy, nil);
EraseRect(&WinMinusScroll);
before = TickCount();
/*CopyBits ((BitMap *) *offscreenGWorld->portPixMap, &myWindow->portBits,
&InitWindowSize, &WinMinusScroll, srcCopy, nil);*/
CopyBits ((BitMap *) *(GetPortPixMap(offscreenGWorld)), GetPortBitMapForCopyBits(GetWindowPort(myWindow)),
&InitWindowSize, &WinMinusScroll, srcCopy, nil);
delay = TickCount() - before;
/* DebugStr("\PIt's me!!!"); */
}
/*------------------------------------------------------*/
/* main(). */
/*------------------------------------------------------*/
main()
{
char key;
Boolean track;
long growResult;
EventRecord myEvent;
WindowPtr whichWindow;
int yieldTime;
Rect tempRect1;
init();
yieldTime = 0;
for ( ;; ) {
if (DoneFlag)
ExitToShell();
if (WaitNextEvent(everyEvent, &myEvent, yieldTime, nil)) {
switch (myEvent.what) {
case mouseDown:
switch (FindWindow(myEvent.where, &whichWindow)) {
case inSysWindow:
//SystemClick(&myEvent, whichWindow);
break;
case inMenuBar:
doCommand(MenuSelect(myEvent.where));
break;
case inContent:
break;
case inDrag:
DragWindow (whichWindow, myEvent.where, &TotalRect);
draw();
DrawGrowIcon (whichWindow);
break;
case inGrow:
growResult = GrowWindow (whichWindow, myEvent.where,
&minRect);
SizeWindow(whichWindow, LoWord(growResult),
HiWord(growResult), true);
/*EraseRect(&whichWindow->portRect);
SetRect(&WinMinusScroll, whichWindow->portRect.left,
whichWindow->portRect.top,
whichWindow->portRect.right-20,
whichWindow->portRect.bottom - 20);*/
EraseRect(GetPortBounds(GetWindowPort(whichWindow), &tempRect1));
SetRect(&WinMinusScroll, tempRect1.left,
tempRect1.top,
tempRect1.right-20,
tempRect1.bottom - 20);
draw();
DrawGrowIcon (whichWindow);
break;
case inGoAway:
track = TrackGoAway (whichWindow, myEvent.where);
if (track) {
//CloseWindow (whichWindow);
DoneFlag = true;
}
break;
case inZoomIn:
track = TrackBox (whichWindow, myEvent.where, inZoomIn);
if (track) {
ZoomWindow (whichWindow, inZoomIn, true);
/*EraseRect(&whichWindow->portRect);
SetRect(&WinMinusScroll, whichWindow->portRect.left,
whichWindow->portRect.top,
whichWindow->portRect.right-20,
whichWindow->portRect.bottom - 20);*/
EraseRect(GetPortBounds(GetWindowPort(whichWindow), &tempRect1));
SetRect(&WinMinusScroll, tempRect1.left,
tempRect1.top,
tempRect1.right-20,
tempRect1.bottom - 20);
draw();
DrawGrowIcon (whichWindow);
}
break;
case inZoomOut:
track = TrackBox (whichWindow, myEvent.where, inZoomOut);
if (track) {
ZoomWindow (whichWindow, inZoomOut, true);
/*EraseRect(&whichWindow->portRect);
SetRect(&WinMinusScroll, whichWindow->portRect.left,
whichWindow->portRect.top,
whichWindow->portRect.right-20,
whichWindow->portRect.bottom - 20);*/
EraseRect(GetPortBounds(GetWindowPort(whichWindow), &tempRect1));
SetRect(&WinMinusScroll, tempRect1.left,
tempRect1.top,
tempRect1.right-20,
tempRect1.bottom - 20);
draw();
DrawGrowIcon (whichWindow);
}
break;
default:
break;
}
break;
case keyDown:
case autoKey:
key = myEvent.message & charCodeMask;
if ( myEvent.modifiers & cmdKey )
if ( myEvent.what == keyDown )
doCommand(MenuKey(key));
break;
case updateEvt:
if ((WindowPtr) myEvent.message == myWindow) {
BeginUpdate((WindowPtr) myWindow);
EndUpdate((WindowPtr) myWindow);
draw();
}
break;
case diskEvt:
break;
case activateEvt:
break;
case 15:
if ((myEvent.message << 31) == 0) {
yieldTime = 30;
}
else {
yieldTime = 0;
//SetPort((WindowPtr) myWindow);
SetPortWindowPort(myWindow);
}
break;
default:
break;
}
}
}
}