Retired Document
Important: This sample code may not represent best practices for current development. The project may use deprecated symbols and illustrate technologies and techniques that are no longer recommended.
Test Main.cp
/* |
File: Test Main.cp |
Contains: Mac OS gamma test harness |
Written by: Geoff Stahl (ggs) |
Copyright: Copyright © 1999 Apple Computer, Inc., All Rights Reserved |
Change History (most recent first): |
<5> 8/25/99 ggs Added Gestalt for color QD |
<4> 8/25/99 ggs Tested changes in MacGamma code |
<3> 5/20/99 ggs Increased randomness |
<2> 5/20/99 ggs Modified demo to be something at least a little intersting and |
to utilize the new get/restore functions |
<1> 5/20/99 ggs Initial Add |
Disclaimer: You may incorporate this sample code into your applications without |
restriction, though the sample code has been provided "AS IS" and the |
responsibility for its operation is 100% yours. However, what you are |
not permitted to do is to redistribute the source as "DSC Sample 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 Code, but that you've made changes. |
*/ |
#include <Types.h> |
#include <Gestalt.h> |
#include <Memory.h> |
#include <Quickdraw.h> |
#include <Fonts.h> |
#include <Events.h> |
#include <Menus.h> |
#include <Windows.h> |
#include <TextEdit.h> |
#include <Dialogs.h> |
#include <OSUtils.h> |
#include <ToolUtils.h> |
#include <SegLoad.h> |
#include <Sound.h> |
#include "MacGamma.h" |
/* Prototypes */ |
void Initialize(void); |
int main(void) |
{ |
Initialize(); |
Ptr pGammaSave = GetSystemGammas (); |
short x [3], y [3]; |
short devCount = 0; |
GDHandle hGDevice = GetDeviceList (); // top of device list |
do // iterate |
{ |
hGDevice = GetNextDevice (hGDevice); // next device |
devCount++; |
} while (hGDevice); |
short devices = devCount; |
short entries = devices * 3 * 256; |
unsigned char * pOrigRamp = (unsigned char * ) NewPtr (entries); |
unsigned char * pRamp = (unsigned char * ) NewPtr (entries); |
devCount = 0; |
hGDevice = GetDeviceList (); // top of device list |
do // iterate |
{ |
GetDeviceGammaRampGD (hGDevice, (Ptr)(pOrigRamp + devCount * 3 * 256)); // retrieves the gamma ramp from a graphics device (pRamp: 3 arrays of 256 elements each) |
hGDevice = GetNextDevice (hGDevice); // next device |
devCount++; |
} while (hGDevice); |
for (short j = 0; j < 3; j++) |
{ |
x [j] = (TickCount () + j * 120) % 256; |
y [j] = 255; |
} |
do { |
for (short i = 0; i < 256 ; i++) |
for (short j = 0; j < 3; j++) |
for (short k = 0; k < devices; k++) |
*(pRamp + k * 3 * 256 + j * 256 + i) = *(pOrigRamp + k * 3 * 256 + j * 256 + i) * (y [j] % 256) / 256; |
devCount = 0; |
hGDevice = GetDeviceList (); // top of device list |
do // iterate |
{ |
SetDeviceGammaRampGD (hGDevice, (Ptr)(pRamp + devCount * 3 * 256)); |
hGDevice = GetNextDevice (hGDevice); // next device |
devCount++; |
} while (hGDevice); |
for (short j = 0; j < 3; j++) |
{ |
(x [j] > y [j]) ? y [j]++ : y [j]--; |
if (x [j] == y [j]) |
x [j] = ((TickCount () % (1457 * j)) + j * 97) % 256; |
} |
} while (!Button()); |
RestoreSystemGammas (pGammaSave); |
DisposeSystemGammas (&pGammaSave); |
return 0; |
} |
void Initialize(void) |
{ |
OSErr err; |
long response = 0; |
MaxApplZone (); |
err = Gestalt (gestaltQuickdrawFeatures, &response); |
if ((noErr != err ) || !((1 << gestaltHasColor) & response)) |
{ |
SysBeep(30); |
ExitToShell(); /* If no color QD, we must leave. */ |
} |
/* Initialize all the needed managers. */ |
InitGraf(&qd.thePort); |
InitFonts(); |
InitWindows(); |
InitMenus(); |
TEInit(); |
InitDialogs(nil); |
InitCursor(); |
} |
Copyright © 2003 Apple Computer, Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2003-07-22