-
Notifications
You must be signed in to change notification settings - Fork 3
/
listing3.html
executable file
·817 lines (657 loc) · 27.8 KB
/
listing3.html
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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<!-- BEGIN META TAG INFO -->
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link rel="home" href="http://developer.apple.com/">
<link rel="find" href="http://developer.apple.com/search/">
<link rel="stylesheet" type="text/css" href="../../documentation/css/adcstyle.css" title="fonts">
<script language="JavaScript" src="../../documentation/js/adc.js" type="text/javascript"></script>
<!-- END META TAG INFO -->
<!-- BEGIN TITLE -->
<title>QuickDraw FX - /CodeWarrior (OS 9)/FX.c</title>
<!-- END TITLE -->
<script language="JavaScript">
function JumpToNewPage() {
window.location=document.scpopupmenu.gotop.value;
return true;
}
</script>
</head>
<!-- BEGIN BODY OPEN -->
<body>
<!--END BODY OPEN -->
<!-- START CENTER OPEN -->
<center>
<!-- END CENTER OPEN -->
<!-- BEGIN LOGO AND SEARCH -->
<!--#include virtual="/includes/adcnavbar"-->
<!-- END LOGO AND SEARCH -->
<!-- START BREADCRUMB -->
<div id="breadcrumb">
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr>
<td scope="row"><img width="340" height="10" src="images/1dot.gif" alt=""></td>
<td><img width="340" height="10" src="images/1dot.gif" alt=""></td>
</tr>
<tr valign="middle">
<td align="left" colspan="2">
<a href="http://developer.apple.com/">ADC Home</a> > <a href="../../referencelibrary/index.html">Reference Library</a> > <a href="../../samplecode/index.html">Sample Code</a> > <a href="../../samplecode/LegacyTechnologies/index.html">Legacy Documents</a> > <a href="../../samplecode/LegacyTechnologies/idxGraphicsImaging-date.html">Graphics & Imaging</a> > <A HREF="javascript:location.replace('index.html');">QuickDraw FX</A> >
</td>
</tr>
<tr>
<td colspan="2" scope="row"><img width="680" height="35" src="images/1dot.gif" alt=""></td>
</tr>
</table>
</div>
<!-- END BREADCRUMB -->
<div style="width:100%; position:fixed;"><div align="center" id="watermark" style="position: relative; margin-left:auto; margin-right:auto; z-index:20; width:500px;"><div class="legacybox"><h1>Legacy Document<span class=closebutton><a href="javascript:closeWatermark()"><img src="../../images/closebutton.png" width="14" height="14" border="0" alt="close button"></a></span></h1>
<p><strong>Important: </strong>This document is part of the Legacy section of the ADC Reference Library. This information should not be used for new development.</p>
<div class="reflibtopic">
<p>Current information on this Reference Library topic can be found here:</p>
<ul>
<li><a href="http://developer.apple.com/referencelibrary/GraphicsImaging/index.html" target="_blank">Reference Library > Graphics & Imaging</a></li>
</ul>
</div>
</div></div></div>
<!-- START MAIN CONTENT -->
<!-- START TITLE GRAPHIC AND INTRO-->
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr align="left" valign="top">
<td><h1><div id="pagehead">QuickDraw FX</div></h1></td>
</tr>
</table>
<!-- END TITLE GRAPHIC AND INTRO -->
<!-- START WIDE COLUMN -->
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr align="left" valign="top">
<td id="scdetails">
<h2>/CodeWarrior (OS 9)/FX.c</h2>
<form name="scpopupmenu" onSubmit="return false;" method=post>
<p><strong>View Source Code:</strong>
<select name="gotop" onChange="JumpToNewPage();" style="width:340px"><option selected value="ingnore">Select File</option>
<option value="listing1.html">/CodeWarrior (OS 9)/CarbonPrefix.h</option>
<option value="listing2.html">/CodeWarrior (OS 9)/events.c</option>
<option value="listing3.html">/CodeWarrior (OS 9)/FX.c</option>
<option value="listing4.html">/CodeWarrior (OS 9)/FX.h</option>
<option value="listing5.html">/CodeWarrior (OS 9)/main.c</option>
<option value="listing6.html">/CodeWarrior (OS 9)/menu.c</option>
<option value="listing7.html">/ProjectBuilder (OS X)/CarbonPrefix.h</option>
<option value="listing8.html">/ProjectBuilder (OS X)/events.c</option>
<option value="listing9.html">/ProjectBuilder (OS X)/FX.c</option>
<option value="listing10.html">/ProjectBuilder (OS X)/FX.h</option>
<option value="listing11.html">/ProjectBuilder (OS X)/main.c</option>
<option value="listing12.html">/ProjectBuilder (OS X)/menu.c</option>
<option value="listing13.html">/ProjectBuilder (OS X)/QuickDraw_FX_Prefix.h</option></select>
</p>
</form>
<p><strong><a href="QuickDraw_FX.zip">Download Sample</a></strong> (“QuickDraw_FX.zip”, 156.4K)<BR>
<strong><a href="QuickDraw_FX.dmg">Download Sample</a></strong> (“QuickDraw_FX.dmg”, 214.1K)</p>
<!--
<p><strong><a href="#">Download Sample</a></strong> (“filename.sit”, 500K)</p>
-->
</td>
</tr>
<tr>
<td scope="row"><img width="680" height="10" src="images/1dot.gif" alt=""><br>
<img height="1" width="680" src="images/1dot_919699.gif" alt=""><br>
<img width="680" height="20" src="images/1dot.gif" alt=""></td>
</tr>
<tr>
<td scope="row">
<!--googleon: index -->
<pre class="sourcecodebox">/* File: FX.c Contains: Written by: EL Copyright: Copyright © 1992-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/13/1999 KG Updated for Metrowerks Codewarror Pro 2.1 */#include "FX.h"long drawFXImage(){ int exampleNumber, exampleItem; Rect rect, rect2; Rect outlineRect; long startTicks, endTicks; Point point = { 0, 0 }; Rect frame; Rect windowRect, gWorldRect; /*SetRect( &rect, (*gWindow).portRect.right - (*gGWorld).portRect.right - 20, 37, (*gWindow).portRect.right - 20, 37 + (*gGWorld).portRect.bottom );*/ GetPortBounds(GetWindowPort(gWindow), &windowRect); GetPortBounds(gGWorld, &gWorldRect); SetRect( &rect, windowRect.right - gWorldRect.right - 20, 37, windowRect.right - 20, 37 + gWorldRect.bottom ); outlineRect = rect; InsetRect( &outlineRect, -5, -5 ); drawDeepBox( &outlineRect ); frame = rect; if (settings.bItem == 1) { ForeColor( whiteColor ); PaintRect( &rect ); } else if (settings.bItem == 2) { ForeColor( blackColor ); PaintRect( &rect ); } else { rect2 = rect; rect2.right = (rect2.right - rect2.left) / 2 + rect2.left; ForeColor( whiteColor ); PaintRect( &rect2 ); rect2.left = rect2.right; rect2.right = rect.right; ForeColor( blackColor ); PaintRect( &rect2 ); } ForeColor( blackColor ); BackColor( whiteColor ); exampleNumber = gCurrentExample / 10; exampleItem = gCurrentExample % 10; startTicks = TickCount(); if (exampleNumber == 1) transferExample( &rect, exampleItem ); else if (exampleNumber == 2) arithmeticExample( &rect, exampleItem ); else if (exampleNumber == 3) ditherExample( &rect, exampleItem ); else if (exampleNumber == 4) colorizationExample( &rect, exampleItem ); else if (exampleNumber == 5) mappingExample( &rect, exampleItem ); else if (exampleNumber == 6) paintBucketExample( &rect, exampleItem, point ); else if (exampleNumber == 7) lassoToolExample( &rect, exampleItem, &frame ); else if (exampleNumber == 8) pixelAverageExample( &rect, exampleItem ); else if (exampleNumber == 9) customExample( &rect, exampleItem ); endTicks = TickCount(); return (endTicks - startTicks);}void transferExample( Rect *rect, int item ){ int transferMode; resetItems(); settings.tItem = item; transferMode = setTransferMode( item ); /*CopyBits( (BitMap *)(*(*gGWorld).portPixMap), &gWindow->portBits, &(**(*gGWorld).portPixMap).bounds, rect, transferMode, nil );*/ CopyBits( (BitMap *)(*(GetPortPixMap(gGWorld))), GetPortBitMapForCopyBits(GetWindowPort(gWindow)), &((**(GetPortPixMap(gGWorld))).bounds), rect, transferMode, nil );}int setTransferMode(int item ){ item--; return item;}void arithmeticExample( Rect *rect, int item ){ int arithmeticMode; RGBColor color; resetItems(); settings.aItem = item; arithmeticMode = setArithmeticMode( item ); /*CopyBits( (BitMap *)(*(*gGWorld).portPixMap), &gWindow->portBits, &(**(*gGWorld).portPixMap).bounds, rect, arithmeticMode, nil );*/ CopyBits( (BitMap *)(*(GetPortPixMap(gGWorld))), GetPortBitMapForCopyBits(GetWindowPort(gWindow)), &((**(GetPortPixMap(gGWorld))).bounds), rect, arithmeticMode, nil ); color.red = color.green = color.blue = 0; OpColor( &color );}int setArithmeticMode(int item){ RGBColor color; if (item <= 4) item = 31 + item; else if (item == 9) item = transparent; else item = 32 + item; color.red = color.green = color.blue = 0xffff / 2; OpColor( &color ); return item;}void colorizationExample(Rect *rect, int item ){ int i; Rect srcRect, dstRect; RGBColor color; resetItems(); settings.cItem = item; //srcRect = (**(*gGWorld).portPixMap).bounds; srcRect = (**(GetPortPixMap(gGWorld))).bounds; srcRect.right = srcRect.left + (srcRect.right - srcRect.left) / 3; dstRect = *rect; dstRect.right = dstRect.left + (dstRect.right - dstRect.left) / 3; for (i = 0; i < 3; i++) { if (item == 1) { ForeColor( blackColor ); BackColor( whiteColor ); } else if (item == 2) { ForeColor( whiteColor ); BackColor( blackColor ); } else { color.red = color.green = color.blue = 0; if (i == 0) color.red = 0xffff; else if (i == 1) color.green = 0xffff; else if (i == 2) color.blue = 0xffff; if (item == 3) { RGBForeColor( &color ); BackColor( whiteColor ); } else { RGBBackColor( &color ); ForeColor( blackColor ); } } /*CopyBits( (BitMap *)(*(*gGWorld).portPixMap), &gWindow->portBits, &srcRect, &dstRect, srcCopy, nil );*/ CopyBits( (BitMap *)(*(GetPortPixMap(gGWorld))), GetPortBitMapForCopyBits(GetWindowPort(gWindow)), &srcRect, &dstRect, srcCopy, nil ); OffsetRect( &srcRect, srcRect.right - srcRect.left, 0 ); OffsetRect( &dstRect, dstRect.right - dstRect.left, 0 ); }}void ditherExample(Rect * rect,int item ){ #pragma unused(rect) int ditherMode; /* This function shows an example of using copybits with the dithering. */ resetItems(); settings.dItem = item; ditherMode = setDitherMode( item ); /*CopyBits( (BitMap *)(*(*gGWorld).portPixMap), &gWindow->portBits, &(**(*gGWorld).portPixMap).bounds, rect, srcCopy + ditherMode, nil );*/ CopyBits( (BitMap *)(*(GetPortPixMap(gGWorld))), GetPortBitMapForCopyBits(GetWindowPort(gWindow)), &(**(GetPortPixMap(gGWorld))).bounds, rect, srcCopy + ditherMode, nil );}int setDitherMode(int item){ if (item == 1) return 0; else return ditherCopy;}void mappingExample(Rect * rect, int item ){ int i; GWorldPtr gworld; CTabHandle ictable; Rect tempRect1; resetItems(); settings.mItem = item; if (item == 1) /*CopyBits( (BitMap *)(*(*gGWorld).portPixMap), &gWindow->portBits, &(**(*gGWorld).portPixMap).bounds, rect, srcCopy, nil );*/ CopyBits( (BitMap *)(*(GetPortPixMap(gGWorld))), GetPortBitMapForCopyBits(GetWindowPort(gWindow)), &((**(GetPortPixMap(gGWorld))).bounds), rect, srcCopy, nil ); else if (item == 2) { ColorSearchUPP searchProcUPP=NewColorSearchProc(searchProc); AddSearch(searchProcUPP); /*CopyBits( (BitMap *)(*(*gGWorld).portPixMap), &gWindow->portBits, &(**(*gGWorld).portPixMap).bounds, rect, srcCopy, nil );*/ CopyBits( (BitMap *)(*(GetPortPixMap(gGWorld))), GetPortBitMapForCopyBits(GetWindowPort(gWindow)), &((**(GetPortPixMap(gGWorld))).bounds), rect, srcCopy, nil ); DelSearch(searchProcUPP); } else if (item == 3) { //NewGWorld( &gworld, 8, &(*gGWorld).portRect, GetCTable( 8 + 64 ), nil, 0 ); NewGWorld( &gworld, 8, GetPortBounds(gGWorld, &tempRect1), GetCTable( 8 + 64 ), nil, 0 ); /*CopyBits( (BitMap *)(*(*gGWorld).portPixMap), (BitMap *)(*(*gworld).portPixMap), &(**(*gGWorld).portPixMap).bounds, &(**(*gworld).portPixMap).bounds, srcCopy, nil );*/ CopyBits( (BitMap *)(*(GetPortPixMap(gGWorld))), (BitMap *)(*(GetPortPixMap(gworld))), &((**(GetPortPixMap(gGWorld))).bounds), &((**(GetPortPixMap(gworld))).bounds), srcCopy, nil ); ictable = GetCTable( 8 ); /*for (i = 0; i <= (**(**(*gworld).portPixMap).pmTable).ctSize; i++) (**(**(*gworld).portPixMap).pmTable).ctTable[i].rgb = (**ictable).ctTable[255 - i].rgb; (**(**(*gworld).portPixMap).pmTable).ctSeed = 67; // (**(**(*(CGrafPtr)gWindow).portPixMap).pmTable).ctSeed; CopyBits( (BitMap *)(*(*gworld).portPixMap), &gWindow->portBits, &(**(*gworld).portPixMap).bounds, rect, srcCopy, nil );*/ for (i = 0; i <= (**(**(GetPortPixMap(gworld))).pmTable).ctSize; i++) (**(**(GetPortPixMap(gworld))).pmTable).ctTable[i].rgb = (**ictable).ctTable[255 - i].rgb; (**(**(GetPortPixMap(gworld))).pmTable).ctSeed = 67; CopyBits( (BitMap *)(*(GetPortPixMap(gworld))), GetPortBitMapForCopyBits(GetWindowPort(gWindow)), &(**(GetPortPixMap(gworld))).bounds, rect, srcCopy, nil ); DisposeGWorld( gworld ); }}pascal Boolean searchProc( RGBColor * color, long *position ){ #pragma unused(position) (*color).red = 0; return false;}void paintBucketExample(Rect *rect, int exampleItem, Point point ){ #pragma unused(exampleItem) GrafPtr mask; Point newPoint; GWorldPtr gworld; Rect tempRect1; resetItems(); newPoint.h = point.h - 20; newPoint.v = point.v - 37; /*if (newPoint.h < 0 || newPoint.v < 0 || newPoint.h > ((**(*gGWorld).portPixMap).bounds.right - (**(*gGWorld).portPixMap).bounds.left) || newPoint.v > ((**(*gGWorld).portPixMap).bounds.bottom - (**(*gGWorld).portPixMap).bounds.top)) return;*/ tempRect1 = (**(GetPortPixMap(gGWorld))).bounds; if (newPoint.h < 0 || newPoint.v < 0 || newPoint.h > tempRect1.right - tempRect1.left || newPoint.v > tempRect1.bottom - tempRect1.top) return; //mask = CreateGrafPort( &(*gGWorld).portRect ); mask = CreateGrafPort(GetPortBounds(gGWorld, &tempRect1)); ForeColor( redColor ); MoveTo( point.h - 2, point.v ); LineTo( point.h + 2, point.v ); MoveTo( point.h, point.v - 2 ); LineTo( point.h, point.v + 2 ); ForeColor( blackColor ); //NewGWorld( &gworld, 8, &(*gGWorld).portRect, GetCTable( 8 + 64 ), nil, 0 ); NewGWorld( &gworld, 8, GetPortBounds(gGWorld, &tempRect1), GetCTable( 8 + 64 ), nil, 0 ); /*CopyBits( (BitMap *)(*(*gGWorld).portPixMap), (BitMap *)(*(*gworld).portPixMap), &(**(*gGWorld).portPixMap).bounds, &(**(*gworld).portPixMap).bounds, srcCopy, nil );*/ CopyBits( (BitMap *)(*(GetPortPixMap(gGWorld))), (BitMap *)(*(GetPortPixMap(gworld))), &((**(GetPortPixMap(gGWorld))).bounds), &((**(GetPortPixMap(gworld))).bounds), srcCopy, nil ); // GetGWorld( &currentPort, &currentDevice );// SetGWorld( gworld, nil ); /*SeedCFill( (BitMap *)(*(*gworld).portPixMap), &mask->portBits, &(**(*gworld).portPixMap).bounds, &mask->portRect, newPoint.h, newPoint.v, nil, 0 );*/ SeedCFill( (BitMap *)(*(GetPortPixMap(gworld))), GetPortBitMapForCopyBits(mask), &((**(GetPortPixMap(gworld))).bounds), GetPortBounds(mask, &tempRect1), newPoint.h, newPoint.v, nil, 0 );// SetGWorld( currentPort, currentDevice ); /*CopyMask( (BitMap *)(*(*gworld).portPixMap), &mask->portBits, &gWindow->portBits, &(**(*gworld).portPixMap).bounds, &mask->portRect, rect );*/ CopyMask( (BitMap *)(*(GetPortPixMap(gworld))), GetPortBitMapForCopyBits(mask), GetPortBitMapForCopyBits(GetWindowPort(gWindow)), &(**(GetPortPixMap(gworld))).bounds, GetPortBounds(mask, &tempRect1), rect ); DisposeGrafPort( mask );}void lassoToolExample(Rect * rect, int exampleItem,Rect *frame ){ #pragma unused(exampleItem,frame) GrafPtr mask; RGBColor color; CGrafPtr currentPort; GDHandle currentDevice; Rect tempRect1; pascal Boolean matchProc(); resetItems(); //mask = CreateGrafPort( &(*gGWorld).portRect ); mask = CreateGrafPort(GetPortBounds(gGWorld, &tempRect1)); GetGWorld( &currentPort, &currentDevice ); SetGWorld( gGWorld, nil ); color.red = color.green = color.blue = 0; /*CalcCMask( (BitMap *)(*(*gGWorld).portPixMap), &mask->portBits, &(**(*gGWorld).portPixMap).bounds, &mask->portRect, &color, NewColorSearchProc(matchProc), 0 );*/ CalcCMask( (BitMap *)(*(GetPortPixMap(gGWorld))),GetPortBitMapForCopyBits(mask), &(**(GetPortPixMap(gGWorld))).bounds, GetPortBounds(mask, &tempRect1), &color, NewColorSearchProc(matchProc), 0 ); SetGWorld( currentPort, currentDevice ); /*CopyMask( (BitMap *)(*(*gGWorld).portPixMap), &mask->portBits, &gWindow->portBits, &(**(*gGWorld).portPixMap).bounds, &mask->portRect, rect );*/ CopyMask( (BitMap *)(*(GetPortPixMap(gGWorld))), GetPortBitMapForCopyBits(mask), GetPortBitMapForCopyBits(GetWindowPort(gWindow)), &(**(GetPortPixMap(gGWorld))).bounds, GetPortBounds(mask, &tempRect1), rect ); /* bounds = *frame; OffsetRect( &bounds, -bounds.left, -bounds.top ); mask = CreateGrafPort( &bounds ); GetGWorld( &currentPort, &currentDevice ); SetGWorld( gGWorld, nil ); color.red = color.green = color.blue = 0; CalcCMask( (BitMap *)(*(*gGWorld).portPixMap), &mask->portBits, &bounds, &mask->portRect, &color, matchProc, 0 ); SetGWorld( currentPort, currentDevice ); CopyMask( (BitMap *)(*(*gGWorld).portPixMap), &mask->portBits, &gWindow->portBits, &bounds, &mask->portRect, frame );*/ DisposeGrafPort( mask );}pascal Boolean matchProc(RGBColor *color, long *position ){ GDHandle currDevice; MatchRec *matchInfo; currDevice = GetGDevice(); matchInfo = (MatchRec *)(**currDevice).gdRefCon; if (matchInfo->red == color->red && matchInfo->green == color->green && matchInfo->blue == color->blue) *position = 0; else *position = 1; return true;}void pixelAverageExample(Rect *rect, int item ){ #pragma unused(item) Rect bounds; GWorldPtr gworld; GWorldPtr source; Rect tempRect1; resetItems(); /* Create 8-bit gworld from 32-bit original. */ //NewGWorld( &source, 8, &(*gGWorld).portRect, GetCTable( 8 + 64 ), nil, 0 ); NewGWorld( &source, 8, GetPortBounds(gGWorld, &tempRect1), GetCTable( 8 + 64 ), nil, 0 ); /*CopyBits( (BitMap *)(*(*gGWorld).portPixMap), (BitMap *)(*(*source).portPixMap), &(**(*gGWorld).portPixMap).bounds, &(**(*source).portPixMap).bounds, srcCopy, nil );*/ CopyBits( (BitMap *)(*(GetPortPixMap(gGWorld))), (BitMap *)(*(GetPortPixMap(source))), &((**(GetPortPixMap(gGWorld))).bounds), &((**(GetPortPixMap(source))).bounds), srcCopy, nil ); /* Create another 8-bit gworld at quarter size of original. */ /*SetRect( &bounds, 0, 0, (*gGWorld).portRect.right / 4, (*gGWorld).portRect.bottom / 4 );*/ GetPortBounds(gGWorld, &tempRect1); SetRect( &bounds, 0, 0, tempRect1.right / 4, tempRect1.bottom / 4); NewGWorld( &gworld, 8, &bounds, GetCTable( 8 + 64 ), nil, 0 ); /* Copy the 8-bit original to 8-bit quarter image without pixel averaging. */ //bounds = (*source).portRect; GetPortBounds(source, &bounds); /*CopyBits( (BitMap *)(*(*source).portPixMap), (BitMap *)(*(*gworld).portPixMap), &(**(*source).portPixMap).bounds, &(**(*gworld).portPixMap).bounds, srcCopy, nil );*/ CopyBits( (BitMap *)(*(GetPortPixMap(source))), (BitMap *)(*(GetPortPixMap(gworld))), &((**(GetPortPixMap(source))).bounds), &((**(GetPortPixMap(gworld))).bounds), srcCopy, nil ); /* Copy the quarter image to screen. */ OffsetRect( &bounds, 20, 37 ); /*CopyBits( (BitMap *)(*(*gworld).portPixMap), &(*gWindow).portBits, &(**(*gworld).portPixMap).bounds, &bounds, srcCopy, nil );*/ CopyBits( (BitMap *)(*(GetPortPixMap(gworld))), GetPortBitMapForCopyBits(GetWindowPort(gWindow)), &(**(GetPortPixMap(gworld))).bounds, &bounds, srcCopy, nil ); /* Now, copy the 8-bit original to 8-bit quarter image with pixel averaging. */ //bounds = (*source).portRect; GetPortBounds(source, &bounds); /*CopyBits( (BitMap *)(*(*source).portPixMap), (BitMap *)(*(*gworld).portPixMap), &(**(*source).portPixMap).bounds, &(**(*gworld).portPixMap).bounds, srcCopy + ditherCopy, nil );*/ CopyBits( (BitMap *)(*(GetPortPixMap(source))), (BitMap *)(*(GetPortPixMap(gworld))), &((**(GetPortPixMap(source))).bounds), &((**(GetPortPixMap(gworld))).bounds), srcCopy + ditherCopy, nil ); /* Finally, copy pixel averaged quarter image to screen. */ OffsetRect( &bounds, (*rect).left, (*rect).top ); /*CopyBits( (BitMap *)(*(*gworld).portPixMap), &(*gWindow).portBits, &(**(*gworld).portPixMap).bounds, &bounds, srcCopy, nil );*/ CopyBits( (BitMap *)(*(GetPortPixMap(gworld))), GetPortBitMapForCopyBits(GetWindowPort(gWindow)), &(**(GetPortPixMap(gworld))).bounds, &bounds, srcCopy, nil ); DisposeGWorld( source ); DisposeGWorld( gworld );}void customExample(Rect * rect,int item ){ #pragma unused(item) int transferMode; int ditherMode; RGBColor color; ColorSearchUPP searchProcUPP=NewColorSearchProc(searchProc); transferMode = setTransferMode( settings.tItem ); ditherMode = setDitherMode( settings.dItem ); if (settings.cItem == 1) { ForeColor( blackColor ); BackColor( whiteColor ); } else if (settings.cItem == 2) { ForeColor( whiteColor ); BackColor( blackColor ); } else if (settings.cItem == 3) { color.green = 0xffff; color.red = color.blue = 0; RGBForeColor( &color ); BackColor( whiteColor ); } else if (settings.cItem == 4) { color.green = 0xffff; color.red = color.blue = 0; ForeColor( blackColor ); RGBBackColor( &color ); } if (settings.mItem == 2) AddSearch(searchProcUPP); /*CopyBits( (BitMap *)(*(*gGWorld).portPixMap), &gWindow->portBits, &(**(*gGWorld).portPixMap).bounds, rect, transferMode + ditherMode, nil );*/ CopyBits( (BitMap *)(*(GetPortPixMap(gGWorld))), GetPortBitMapForCopyBits(GetWindowPort(gWindow)), &(**(GetPortPixMap(gGWorld))).bounds, rect, transferMode + ditherMode, nil ); if (settings.mItem == 2) DelSearch(searchProcUPP);}GrafPtr CreateGrafPort( Rect *bounds ) /* CreateGrafPort originally written by Forrest Tanaka. */{ GrafPtr savedPort; /* Saved GrafPtr for later restore. */ GrafPtr newPort; /* New GrafPort. */ Rect localBounds; /* Local copy of bounds. */ RgnHandle rgnHandle = NewRgn(); // Used for carbonization GetPort( &savedPort ); /* Set the top-left corner of bounds to (0,0). */ localBounds = *bounds; OffsetRect( &localBounds, -bounds->left, -bounds->top ); /* Allocate a new GrafPort. */ //newPort = (GrafPtr)NewPtrClear( sizeof( GrafPort ) ); newPort = CreateNewPort(); if (newPort != nil) { /* Initialize the new port and make the current port. */ //OpenPort( newPort ); SetPort( newPort); /* Initialize and allocate the bitmap. */ /*newPort->portBits.bounds = localBounds; newPort->portBits.rowBytes = ((localBounds.right + 15) >> 4) << 1; newPort->portBits.baseAddr = NewPtrClear( newPort->portBits.rowBytes * (long)localBounds.bottom );*/ (*(GetPortPixMap(newPort)))->bounds = localBounds; (*(GetPortPixMap(newPort)))->rowBytes = ((localBounds.right + 15) >> 4) <<1; (*(GetPortPixMap(newPort)))->baseAddr = NewPtrClear(GetPortBitMapForCopyBits(newPort)->rowBytes * (long)localBounds.bottom ); //if (newPort->portBits.baseAddr != nil) if (GetPortBitMapForCopyBits(newPort)->baseAddr != nil) { /* Clean up the new port. */ //newPort->portRect = localBounds; SetPortBounds(newPort, &localBounds); ClipRect( &localBounds ); //RectRgn( newPort->visRgn, &localBounds ); RectRgn( GetPortVisibleRegion(newPort, rgnHandle), &localBounds ); EraseRect( &localBounds ); } else { /* Allocation failed; deallocate the port. */ /*ClosePort( newPort ); DisposePtr( (Ptr)newPort );*/ DisposePort( newPort ); newPort = nil; } } DisposeRgn(rgnHandle); SetPort( savedPort ); return newPort;}void DisposeGrafPort( GrafPtr doomedPort ) /* DisposeGrafPort originally written by Forrest Tanaka. */{ //ClosePort( doomedPort ); //DisposePtr( doomedPort->portBits.baseAddr ); DisposePtr( GetPortBitMapForCopyBits(doomedPort)->baseAddr ); //DisposePtr( (Ptr)doomedPort ); DisposePort( doomedPort );}</pre>
<!--googleoff: index -->
</td>
</tr>
</table>
<!-- END WIDE COLUMN -->
<!-- END MAIN CONTENT -->
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><div style="width: 100%; height: 1px; background-color: #919699; margin-top: 5px; margin-bottom: 15px"></div></td>
</tr>
<tr>
<td align="center"><br/>
<table border="0" cellpadding="0" cellspacing="0" class="graybox">
<tr>
<th>Did this document help you?</th>
</tr>
<tr>
<td>
<div style="margin-bottom: 8px"><a href="http://developer.apple.com/feedback/?v=1&url=/samplecode/QuickDraw_FX/listing3.html%3Fid%3DDTS10000148-1.0&media=dvd" target=_new>Yes</a>: Tell us what works for you.</div>
<div style="margin-bottom: 8px"><a href="http://developer.apple.com/feedback/?v=2&url=/samplecode/QuickDraw_FX/listing3.html%3Fid%3DDTS10000148-1.0&media=dvd" target=_new>It’s good, but:</a> Report typos, inaccuracies, and so forth.</div>
<div><a href="http://developer.apple.com/feedback/?v=3&url=/samplecode/QuickDraw_FX/listing3.html%3Fid%3DDTS10000148-1.0&media=dvd" target=_new>It wasn’t helpful</a>: Tell us what would have helped.</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
<!-- START BOTTOM APPLE NAVIGATION -->
<!--#include virtual="/includes/footer"-->
<!-- END BOTTOM APPLE NAVIGATION -->
<!-- START CENTER CLOSE -->
</center>
<!-- END CENTER CLOSE -->
</body>
</html>