Mercurial > sdl-ios-xcode
annotate src/video/maccommon/SDL_macwm.c @ 4157:baf615f9f2a0 SDL-1.2
Date: Thu, 16 Oct 2008 20:27:34 +0400
From: "Ilya Kasnacheev" <ilya.kasnacheev@gmail.com>
To: sdl@lists.libsdl.org
Subject: [SDL] SDL for Windows CE: a few GAPI patches
Hi *!
I've just ported a POWDER roguelike ( http://www.zincland.com/powder/ ) to
Windows CE (PDAs, Windows Mobile/Pocket PC). To do that, I had to get libsdl
working. Thanks for the awesome project files, it built without a hitch.
Nevertheless, I've found quite a few bugs in Windows CE (GAPI) SDL
implementation, which I've solved and now present as a serie of patches.
I'll try carefully annotate them. Please annotate them so I can work
toward accepting
them into the main source tree since without them SDL isn't really working on
Windows CE (I wonder why nobody fixed them before, btw: why isn't SDL popular as
a way to develop Windows CE games? Where are no ports?)
These changes can't be considered flawless, but they can be considered working
because I've yet to hear complains about things I fixed and POWDER build for
Windows CE is now considered stable.
Note: my comments start with !!, delete them before applying.
diff -bru SDL-1.2.13/src/video/gapi/SDL_gapivideo.c
SDL-1.2.13-new/src/video/gapi/SDL_gapivideo.c
--- SDL-1.2.13/src/video/gapi/SDL_gapivideo.c 2007-12-31
07:48:00.000000000 +0300
+++ SDL-1.2.13-new/src/video/gapi/SDL_gapivideo.c 2008-10-16
20:02:11.000000000 +0400
@@ -643,6 +643,7 @@
}
gapi->userOrientation = SDL_ORIENTATION_UP;
+ gapi->systemOrientation = SDL_ORIENTATION_UP;
video->flags = SDL_FULLSCREEN; /* Clear flags, GAPI supports
fullscreen only */
/* GAPI or VGA? */
@@ -661,18 +662,21 @@
}
/* detect user landscape mode */
- if( (width > height) && (GetSystemMetrics(SM_CXSCREEN) <
GetSystemMetrics(SM_CYSCREEN)))
+ if( (width > height) && (gapi->gxProperties.cxWidth <
gapi->gxProperties.cyHeight))
gapi->userOrientation = SDL_ORIENTATION_RIGHT;
+ if(GetSystemMetrics(SM_CYSCREEN) < GetSystemMetrics(SM_CXSCREEN))
+ gapi->systemOrientation = SDL_ORIENTATION_RIGHT;
+
/* shall we apply hires fix? for example when we do not use
hires resource */
gapi->hiresFix = 0;
- if( gapi->userOrientation == SDL_ORIENTATION_RIGHT )
+ if( gapi->systemOrientation == gapi->userOrientation )
{
- if( (width > GetSystemMetrics(SM_CYSCREEN)) || (height
> GetSystemMetrics(SM_CXSCREEN)))
+ if( (width > GetSystemMetrics(SM_CXSCREEN)) || (height
> GetSystemMetrics(SM_CYSCREEN)))
gapi->hiresFix = 1;
} else
- if( (width > GetSystemMetrics(SM_CXSCREEN)) || (height
> GetSystemMetrics(SM_CYSCREEN)))
- if( !((width == GetSystemMetrics(SM_CYSCREEN))
&& (height == GetSystemMetrics(SM_CXSCREEN)))) // user portrait,
device landscape
+ if( (width > GetSystemMetrics(SM_CYSCREEN)) || (height
> GetSystemMetrics(SM_CXSCREEN)))
+// if( !((width == gapi->gxProperties.cyHeight)
&& (height == gapi->gxProperties.cxWidth))) // user portrait, device
landscape
gapi->hiresFix = 1;
switch( gapi->userOrientation )
!! It used to query system metrics which return dimensions according to screen
!! orientation, which can really be portrait, left landscape or right landscape.
!! This is presumably incorrect because we couldn't care less about user mode
!! dimensions - all we want are the GAPI framebuffer dimensions, which
only match
!! user dimensions in one of possible orientations.
!! There's a fair dose of cargo cult programming involved in this fix, but it
!! used to work only in one orientation (portrait for PDAs, where frame-buffer
!! have same orientation as user screen), and now it works on all orientations.
@@ -742,21 +746,30 @@
WIN_FlushMessageQueue();
/* Open GAPI display */
- if( !gapi->useVga && this->hidden->useGXOpenDisplay )
+ if( !gapi->useVga && this->hidden->useGXOpenDisplay &&
!this->hidden->alreadyGXOpened )
+ {
+ this->hidden->alreadyGXOpened = 1;
if( !gapi->gxFunc.GXOpenDisplay(SDL_Window, GX_FULLSCREEN) )
{
SDL_SetError("Couldn't initialize GAPI");
return(NULL);
}
+ }
#if REPORT_VIDEO_INFO
printf("Video properties:\n");
printf("display bpp: %d\n", gapi->gxProperties.cBPP);
printf("display width: %d\n", gapi->gxProperties.cxWidth);
printf("display height: %d\n", gapi->gxProperties.cyHeight);
+ printf("system display width: %d\n", GetSystemMetrics(SM_CXSCREEN));
+ printf("system display height: %d\n", GetSystemMetrics(SM_CYSCREEN));
printf("x pitch: %d\n", gapi->gxProperties.cbxPitch);
printf("y pitch: %d\n", gapi->gxProperties.cbyPitch);
printf("gapi flags: 0x%x\n", gapi->gxProperties.ffFormat);
+ printf("user orientation: %d\n", gapi->userOrientation);
+ printf("system orientation: %d\n", gapi->userOrientation);
+ printf("gapi orientation: %d\n", gapi->gapiOrientation);
+
if( !gapi->useVga && this->hidden->useGXOpenDisplay && gapi->needUpdate)
{
!! Previous version used to call gapi->gxFunc.GXOpenDisplay each time the video
!! mode would be changed. You shouldn't, because this call has a
meaning "Lock the
!! GAPI framebuffer, designate it as busy", so the second call will fail (it is
!! already locked/busy).
!! Testing might not find that because most programs set up the video mode only
!! once, but POWDER does this once in a while, so it crashed when in
320x240 mode
!! (640x480 mode doesn't use that code, it worked fine).
diff -bru SDL-1.2.13/src/video/gapi/SDL_gapivideo.h
SDL-1.2.13-new/src/video/gapi/SDL_gapivideo.h
--- SDL-1.2.13/src/video/gapi/SDL_gapivideo.h 2007-12-31
07:48:00.000000000 +0300
+++ SDL-1.2.13-new/src/video/gapi/SDL_gapivideo.h 2008-10-16
20:02:11.000000000 +0400
@@ -132,12 +132,17 @@
#define NUM_MODELISTS 4 /* 8, 16, 24, and 32 bits-per-pixel */
int SDL_nummodes[NUM_MODELISTS];
SDL_Rect **SDL_modelist[NUM_MODELISTS];
+ // The orientation of the video mode user wants to get
+ // Probably restricted to UP and RIGHT
enum SDL_ScreenOrientation userOrientation;
int invert;
char hiresFix; // using hires mode without defining hires resource
// --------------
int useGXOpenDisplay; /* use GXOpenDispplay */
+ int alreadyGXOpened;
int w, h;
+ // The orientation of GAPI framebuffer.
+ // Never changes on the same device.
enum SDL_ScreenOrientation gapiOrientation;
void *buffer; // may be 8, 16, 24, 32 bpp
@@ -153,6 +158,10 @@
int startOffset; // in bytes
int useVga;
int suspended; // do not pu anything into video memory
+ // The orientation of the system, as defined by SM_CXSCREEN
and SM_CYSCREEN
+ // User can change it by using 'screen layout' in system options
+ // Restricted to UP or RIGHT
+ enum SDL_ScreenOrientation systemOrientation;
};
!! This is a flag variable, see the previous comment
!! And yet another orientation: now we have to keep three of them in mind.
diff -bru SDL-1.2.13/src/video/wincommon/SDL_sysevents.c
SDL-1.2.13-new/src/video/wincommon/SDL_sysevents.c
--- SDL-1.2.13/src/video/wincommon/SDL_sysevents.c 2007-12-31
07:48:02.000000000 +0300
+++ SDL-1.2.13-new/src/video/wincommon/SDL_sysevents.c 2008-10-16
20:02:12.000000000 +0400
@@ -160,10 +160,22 @@
#endif */
}
break;
+ // FIXME: Older version used just SDL_VideoSurface->(w, h)
+ // w and h are "clipped" while x and y are "raw", which caused
+ // x in former and y in latter case to be clipped in a
wrong direction,
+ // thus offsetting the coordinate on 2 x clip pixels
+ // (like, 128 for 640 -> 512 clipping).
+ // We will now try to extract and use raw values.
+ // The way to do that RIGHT is do
(orientation-dependent) clipping before
+ // doing this transform, but it's hardly possible.
+
+ // SEE SDL_mouse.c /ClipOffset to understand these calculations.
case SDL_ORIENTATION_RIGHT:
if (!SDL_VideoSurface)
break;
- rotatedX = SDL_VideoSurface->w - *y;
+ rotatedX = (2 *
((SDL_VideoSurface->offset%SDL_VideoSurface->pitch)/
+ SDL_VideoSurface->format->BytesPerPixel))
+ + SDL_VideoSurface->w - *y;
rotatedY = *x;
*x = rotatedX;
*y = rotatedY;
@@ -172,7 +184,8 @@
if (!SDL_VideoSurface)
break;
rotatedX = *y;
- rotatedY = SDL_VideoSurface->h - *x;
+ rotatedY = (2 *
(SDL_VideoSurface->offset/SDL_VideoSurface->pitch))
+ + SDL_VideoSurface->h - *x;
*x = rotatedX;
*y = rotatedY;
break;
!! That's the trickest part, hence the long comment.
!! GAPI would really support only 320x240 or 640x480 mode, if application
!! requested the different screen size (as POWDER did, wishing
256x192), then SDL
!! is going to grab the first mode that fits the requested, and pad the screen
!! with black bars (as they do with wide-screen films).
!! It would also get, say, 240x320 mode, and to turn it into 256x192 it would
!! need to rotate mouse clicks.
!! It worked, but one bug slipped through: it would receive mouse clicks
!! unpadded, then rotate them, and then pad the black bars. The
problem is: rotate
!! is done by GAPI driver while padding is done by SDL core. SDL core
doesn't know
!! anything about rotating, so it would pad one of dimensions incorrectly.
I understand that some of my claims (or code) might seem unbacked, but you can
always grab the POWDER binary, compile your own libsdl with one or more of
those fixes turned off, and see how weird it would misbehave. I can even supply
you with those custom builds of libsdl if you don't want to set up the build
environment for windows ce, you'll just need a PDA or a smartphone with it.
I plan to take care of SDL on Windows CE as long as I maintain the POWDER port.
POWDER is good for that because it:
Employs both padded (with centered image, black bars) and unpadded
(image occupies full screen) graphics; initializes video more than
once; uses both 320x240 and 640x480 video; uses both stylus and
buttons.
There's still a list of unresolved issues which I'm planning to fix:
1) Arrow buttons on PDA return weird scancodes compared to PC, this
caused the game to misbehave before I've fixed that. You can see it on
those diagrams:
http://wrar.name/upload/powder-htc.png
http://wrar.name/upload/powder-pda.png
2) SDL (or underlying windows) doesn't care to rotate arrow presses
when we're in a low-res GAPI mode, but it will rotate them in VGA mode
(because of different screen orientations, the same arrow buttons can
suddently mean different directions). Solution: we should stick to
GAPI user orientation (the orientation the program supposedly wants)
and rotate the keys on our own.
_______________________________________________
SDL mailing list
SDL@lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Fri, 07 Nov 2008 04:15:36 +0000 |
parents | 7cdb1d7fc93b |
children | a1b03ba2fcd0 |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1133
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1133
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
0 | 7 License as published by the Free Software Foundation; either |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1133
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
0 | 9 |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1133
diff
changeset
|
13 Lesser General Public License for more details. |
0 | 14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1133
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1133
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1133
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 18 |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
22 #include "SDL_config.h" |
0 | 23 |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
24 #if defined(__APPLE__) && defined(__MACH__) |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
25 #include <Carbon/Carbon.h> |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
26 #elif TARGET_API_MAC_CARBON && (UNIVERSAL_INTERFACES_VERSION > 0x0335) |
0 | 27 #include <Carbon.h> |
28 #else | |
29 #include <Windows.h> | |
30 #include <Strings.h> | |
31 #endif | |
32 | |
3962
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
33 #if SDL_MACCLASSIC_GAMMA_SUPPORT |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
34 #include <Devices.h> |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
35 #include <Files.h> |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
36 #include <MacTypes.h> |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
37 #include <QDOffscreen.h> |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
38 #include <Quickdraw.h> |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
39 #include <Video.h> |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
40 #endif |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
41 |
1358
c71e05b4dc2e
More header massaging... works great on Windows. ;-)
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
42 #include "SDL_stdinc.h" |
0 | 43 #include "SDL_macwm_c.h" |
44 | |
45 void Mac_SetCaption(_THIS, const char *title, const char *icon) | |
46 { | |
47 /* Don't convert C to P string in place, because it may be read-only */ | |
48 Str255 ptitle; /* MJS */ | |
49 ptitle[0] = strlen (title); | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
50 SDL_memcpy(ptitle+1, title, ptitle[0]); /* MJS */ |
0 | 51 if (SDL_Window) |
52 SetWTitle(SDL_Window, ptitle); /* MJS */ | |
53 } | |
3962
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
54 |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
55 #if SDL_MACCLASSIC_GAMMA_SUPPORT |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
56 /* |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
57 * ADC Gamma Ramp support... |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
58 * |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
59 * Mac Gamma Ramp code was originally from sample code provided by |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
60 * Apple Developer Connection, and not written specifically for SDL: |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
61 * "Contains: Functions to enable Mac OS device gamma adjustments using 3 channel 256 element 8 bit gamma ramps |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
62 * Written by: Geoff Stahl (ggs) |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
63 * Copyright: Copyright (c) 1999 Apple Computer, Inc., All Rights Reserved |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
64 * Disclaimer: You may incorporate this sample code into your applications without |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
65 * restriction, though the sample code has been provided "AS IS" and the |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
66 * responsibility for its operation is 100% yours. However, what you are |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
67 * not permitted to do is to redistribute the source as "DSC Sample Code" |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
68 * after having made changes. If you're going to re-distribute the source, |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
69 * we require that you make it clear in the source that the code was |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
70 * descended from Apple Sample Code, but that you've made changes." |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
71 * (The sample code has been integrated into this file, and thus is modified from the original Apple sources.) |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
72 */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
73 |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
74 typedef struct recDeviceGamma /* storage for device handle and gamma table */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
75 { |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
76 GDHandle hGD; /* handle to device */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
77 GammaTblPtr pDeviceGamma; /* pointer to device gamma table */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
78 } recDeviceGamma; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
79 typedef recDeviceGamma * precDeviceGamma; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
80 |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
81 typedef struct recSystemGamma /* storage for system devices and gamma tables */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
82 { |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
83 short numDevices; /* number of devices */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
84 precDeviceGamma * devGamma; /* array of pointers to device gamma records */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
85 } recSystemGamma; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
86 typedef recSystemGamma * precSystemGamma; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
87 |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
88 static Ptr CopyGammaTable (GammaTblPtr pTableGammaIn) |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
89 { |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
90 GammaTblPtr pTableGammaOut = NULL; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
91 short tableSize, dataWidth; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
92 |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
93 if (pTableGammaIn) /* if there is a table to copy */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
94 { |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
95 dataWidth = (pTableGammaIn->gDataWidth + 7) / 8; /* number of bytes per entry */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
96 tableSize = sizeof (GammaTbl) + pTableGammaIn->gFormulaSize + |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
97 (pTableGammaIn->gChanCnt * pTableGammaIn->gDataCnt * dataWidth); |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
98 pTableGammaOut = (GammaTblPtr) NewPtr (tableSize); /* allocate new table */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
99 if (pTableGammaOut) |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
100 BlockMove( (Ptr)pTableGammaIn, (Ptr)pTableGammaOut, tableSize); /* move everything */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
101 } |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
102 return (Ptr)pTableGammaOut; /* return whatever we allocated, could be NULL */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
103 } |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
104 |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
105 static OSErr GetGammaTable (GDHandle hGD, GammaTblPtr * ppTableGammaOut) |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
106 { |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
107 VDGammaRecord DeviceGammaRec; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
108 CntrlParam cParam; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
109 OSErr err; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
110 |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
111 cParam.ioCompletion = NULL; /* set up control params */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
112 cParam.ioNamePtr = NULL; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
113 cParam.ioVRefNum = 0; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
114 cParam.ioCRefNum = (**hGD).gdRefNum; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
115 cParam.csCode = cscGetGamma; /* Get Gamma commnd to device */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
116 *(Ptr *)cParam.csParam = (Ptr) &DeviceGammaRec; /* record for gamma */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
117 |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
118 err = PBStatusSync( (ParmBlkPtr)&cParam ); /* get gamma */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
119 |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
120 *ppTableGammaOut = (GammaTblPtr)(DeviceGammaRec.csGTable); /* pull table out of record */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
121 |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
122 return err; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
123 } |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
124 |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
125 static Ptr GetDeviceGamma (GDHandle hGD) |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
126 { |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
127 GammaTblPtr pTableGammaDevice = NULL; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
128 GammaTblPtr pTableGammaReturn = NULL; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
129 OSErr err; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
130 |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
131 err = GetGammaTable (hGD, &pTableGammaDevice); /* get a pointer to the devices table */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
132 if ((noErr == err) && pTableGammaDevice) /* if succesful */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
133 pTableGammaReturn = (GammaTblPtr) CopyGammaTable (pTableGammaDevice); /* copy to global */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
134 |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
135 return (Ptr) pTableGammaReturn; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
136 } |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
137 |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
138 static void DisposeGammaTable (Ptr pGamma) |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
139 { |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
140 if (pGamma) |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
141 DisposePtr((Ptr) pGamma); /* get rid of it */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
142 } |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
143 |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
144 static void DisposeSystemGammas (Ptr* ppSystemGammas) |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
145 { |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
146 precSystemGamma pSysGammaIn; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
147 if (ppSystemGammas) |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
148 { |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
149 pSysGammaIn = (precSystemGamma) *ppSystemGammas; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
150 if (pSysGammaIn) |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
151 { |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
152 short i; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
153 for (i = 0; i < pSysGammaIn->numDevices; i++) /* for all devices */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
154 if (pSysGammaIn->devGamma [i]) /* if pointer is valid */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
155 { |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
156 DisposeGammaTable ((Ptr) pSysGammaIn->devGamma [i]->pDeviceGamma); /* dump gamma table */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
157 DisposePtr ((Ptr) pSysGammaIn->devGamma [i]); /* dump device info */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
158 } |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
159 DisposePtr ((Ptr) pSysGammaIn->devGamma); /* dump device pointer array */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
160 DisposePtr ((Ptr) pSysGammaIn); /* dump system structure */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
161 *ppSystemGammas = NULL; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
162 } |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
163 } |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
164 } |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
165 |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
166 static Boolean GetDeviceGammaRampGD (GDHandle hGD, Ptr pRamp) |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
167 { |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
168 GammaTblPtr pTableGammaTemp = NULL; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
169 long indexChan, indexEntry; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
170 OSErr err; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
171 |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
172 if (pRamp) /* ensure pRamp is allocated */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
173 { |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
174 err = GetGammaTable (hGD, &pTableGammaTemp); /* get a pointer to the current gamma */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
175 if ((noErr == err) && pTableGammaTemp) /* if successful */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
176 { |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
177 /* fill ramp */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
178 unsigned char * pEntry = (unsigned char *) &pTableGammaTemp->gFormulaData + pTableGammaTemp->gFormulaSize; /* base of table */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
179 short bytesPerEntry = (pTableGammaTemp->gDataWidth + 7) / 8; /* size, in bytes, of the device table entries */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
180 short shiftRightValue = pTableGammaTemp->gDataWidth - 8; /* number of right shifts device -> ramp */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
181 short channels = pTableGammaTemp->gChanCnt; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
182 short entries = pTableGammaTemp->gDataCnt; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
183 if (3 == channels) /* RGB format */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
184 { /* note, this will create runs of entries if dest. is bigger (not linear interpolate) */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
185 for (indexChan = 0; indexChan < channels; indexChan++) |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
186 for (indexEntry = 0; indexEntry < 256; indexEntry++) |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
187 *((unsigned char *) pRamp + (indexChan * 256) + indexEntry) = |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
188 *(pEntry + indexChan * entries * bytesPerEntry + indexEntry * entries * bytesPerEntry / 256) >> shiftRightValue; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
189 } |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
190 else /* single channel format */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
191 { |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
192 for (indexChan = 0; indexChan < 768; indexChan += 256) /* repeat for all 3 channels (step by ramp size) */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
193 for (indexEntry = 0; indexEntry < 256; indexEntry++) /* for all entries set vramp value */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
194 *((unsigned char *) pRamp + indexChan + indexEntry) = |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
195 *(pEntry + indexEntry * entries * bytesPerEntry / 256) >> shiftRightValue; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
196 } |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
197 return true; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
198 } |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
199 } |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
200 return false; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
201 } |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
202 |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
203 static Ptr GetSystemGammas (void) |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
204 { |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
205 precSystemGamma pSysGammaOut; /* return pointer to system device gamma info */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
206 short devCount = 0; /* number of devices attached */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
207 Boolean fail = false; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
208 GDHandle hGDevice; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
209 |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
210 pSysGammaOut = (precSystemGamma) NewPtr (sizeof (recSystemGamma)); /* allocate for structure */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
211 |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
212 hGDevice = GetDeviceList (); /* top of device list */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
213 do /* iterate */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
214 { |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
215 devCount++; /* count devices */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
216 hGDevice = GetNextDevice (hGDevice); /* next device */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
217 } while (hGDevice); |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
218 |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
219 pSysGammaOut->devGamma = (precDeviceGamma *) NewPtr (sizeof (precDeviceGamma) * devCount); /* allocate for array of pointers to device records */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
220 if (pSysGammaOut) |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
221 { |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
222 pSysGammaOut->numDevices = devCount; /* stuff count */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
223 |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
224 devCount = 0; /* reset iteration */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
225 hGDevice = GetDeviceList (); |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
226 do |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
227 { |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
228 pSysGammaOut->devGamma [devCount] = (precDeviceGamma) NewPtr (sizeof (recDeviceGamma)); /* new device record */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
229 if (pSysGammaOut->devGamma [devCount]) /* if we actually allocated memory */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
230 { |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
231 pSysGammaOut->devGamma [devCount]->hGD = hGDevice; /* stuff handle */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
232 pSysGammaOut->devGamma [devCount]->pDeviceGamma = (GammaTblPtr)GetDeviceGamma (hGDevice); /* copy gamma table */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
233 } |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
234 else /* otherwise dump record on exit */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
235 fail = true; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
236 devCount++; /* next device */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
237 hGDevice = GetNextDevice (hGDevice); |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
238 } while (hGDevice); |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
239 } |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
240 if (!fail) /* if we did not fail */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
241 return (Ptr) pSysGammaOut; /* return pointer to structure */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
242 else |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
243 { |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
244 DisposeSystemGammas ((Ptr *) &pSysGammaOut); /* otherwise dump the current structures (dispose does error checking) */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
245 return NULL; /* could not complete */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
246 } |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
247 } |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
248 |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
249 static void RestoreDeviceGamma (GDHandle hGD, Ptr pGammaTable) |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
250 { |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
251 VDSetEntryRecord setEntriesRec; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
252 VDGammaRecord gameRecRestore; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
253 CTabHandle hCTabDeviceColors; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
254 Ptr csPtr; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
255 OSErr err = noErr; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
256 |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
257 if (pGammaTable) /* if we have a table to restore */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
258 { |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
259 gameRecRestore.csGTable = pGammaTable; /* setup restore record */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
260 csPtr = (Ptr) &gameRecRestore; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
261 err = Control((**hGD).gdRefNum, cscSetGamma, (Ptr) &csPtr); /* restore gamma */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
262 |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
263 if ((noErr == err) && (8 == (**(**hGD).gdPMap).pixelSize)) /* if successful and on an 8 bit device */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
264 { |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
265 hCTabDeviceColors = (**(**hGD).gdPMap).pmTable; /* do SetEntries to force CLUT update */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
266 setEntriesRec.csTable = (ColorSpec *) &(**hCTabDeviceColors).ctTable; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
267 setEntriesRec.csStart = 0; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
268 setEntriesRec.csCount = (**hCTabDeviceColors).ctSize; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
269 csPtr = (Ptr) &setEntriesRec; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
270 |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
271 err = Control((**hGD).gdRefNum, cscSetEntries, (Ptr) &csPtr); /* SetEntries in CLUT */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
272 } |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
273 } |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
274 } |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
275 |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
276 static void RestoreSystemGammas (Ptr pSystemGammas) |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
277 { |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
278 short i; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
279 precSystemGamma pSysGammaIn = (precSystemGamma) pSystemGammas; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
280 if (pSysGammaIn) |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
281 for (i = 0; i < pSysGammaIn->numDevices; i++) /* for all devices */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
282 RestoreDeviceGamma (pSysGammaIn->devGamma [i]->hGD, (Ptr) pSysGammaIn->devGamma [i]->pDeviceGamma); /* restore gamma */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
283 } |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
284 |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
285 static Ptr CreateEmptyGammaTable (short channels, short entries, short bits) |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
286 { |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
287 GammaTblPtr pTableGammaOut = NULL; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
288 short tableSize, dataWidth; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
289 |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
290 dataWidth = (bits + 7) / 8; /* number of bytes per entry */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
291 tableSize = sizeof (GammaTbl) + (channels * entries * dataWidth); |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
292 pTableGammaOut = (GammaTblPtr) NewPtrClear (tableSize); /* allocate new tabel */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
293 |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
294 if (pTableGammaOut) /* if we successfully allocated */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
295 { |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
296 pTableGammaOut->gVersion = 0; /* set parameters based on input */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
297 pTableGammaOut->gType = 0; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
298 pTableGammaOut->gFormulaSize = 0; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
299 pTableGammaOut->gChanCnt = channels; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
300 pTableGammaOut->gDataCnt = entries; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
301 pTableGammaOut->gDataWidth = bits; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
302 } |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
303 return (Ptr)pTableGammaOut; /* return whatever we allocated */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
304 } |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
305 |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
306 static Boolean SetDeviceGammaRampGD (GDHandle hGD, Ptr pRamp) |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
307 { |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
308 VDSetEntryRecord setEntriesRec; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
309 VDGammaRecord gameRecRestore; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
310 GammaTblPtr pTableGammaNew; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
311 GammaTblPtr pTableGammaCurrent = NULL; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
312 CTabHandle hCTabDeviceColors; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
313 Ptr csPtr; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
314 OSErr err; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
315 short dataBits, entries, channels = 3; /* force three channels in the gamma table */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
316 |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
317 if (pRamp) /* ensure pRamp is allocated */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
318 { |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
319 err= GetGammaTable (hGD, &pTableGammaCurrent); /* get pointer to current table */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
320 if ((noErr == err) && pTableGammaCurrent) |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
321 { |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
322 dataBits = pTableGammaCurrent->gDataWidth; /* table must have same data width */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
323 entries = pTableGammaCurrent->gDataCnt; /* table must be same size */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
324 pTableGammaNew = (GammaTblPtr) CreateEmptyGammaTable (channels, entries, dataBits); /* our new table */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
325 if (pTableGammaNew) /* if successful fill table */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
326 { |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
327 unsigned char * pGammaBase = (unsigned char *) &pTableGammaNew->gFormulaData + pTableGammaNew->gFormulaSize; /* base of table */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
328 if ((256 == entries) && (8 == dataBits)) /* simple case: direct mapping */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
329 BlockMove ((Ptr)pRamp, (Ptr)pGammaBase, channels * entries); /* move everything */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
330 else /* tough case handle entry, channel and data size disparities */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
331 { |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
332 short indexChan, indexEntry; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
333 short bytesPerEntry = (dataBits + 7) / 8; /* size, in bytes, of the device table entries */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
334 short shiftRightValue = 8 - dataBits; /* number of right shifts ramp -> device */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
335 shiftRightValue += ((bytesPerEntry - 1) * 8); /* multibyte entries and the need to map a byte at a time most sig. to least sig. */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
336 for (indexChan = 0; indexChan < channels; indexChan++) /* for all the channels */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
337 for (indexEntry = 0; indexEntry < entries; indexEntry++) /* for all the entries */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
338 { |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
339 short currentShift = shiftRightValue; /* reset current bit shift */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
340 long temp = *((unsigned char *)pRamp + (indexChan << 8) + (indexEntry << 8) / entries); /* get data from ramp */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
341 short indexByte; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
342 for (indexByte = 0; indexByte < bytesPerEntry; indexByte++) /* for all bytes */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
343 { |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
344 if (currentShift < 0) /* shift data correctly for current byte */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
345 *(pGammaBase++) = temp << -currentShift; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
346 else |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
347 *(pGammaBase++) = temp >> currentShift; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
348 currentShift -= 8; /* increment shift to align to next less sig. byte */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
349 } |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
350 } |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
351 } |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
352 |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
353 /* set gamma */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
354 gameRecRestore.csGTable = (Ptr) pTableGammaNew; /* setup restore record */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
355 csPtr = (Ptr) &gameRecRestore; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
356 err = Control((**hGD).gdRefNum, cscSetGamma, (Ptr) &csPtr); /* restore gamma (note, display drivers may delay returning from this until VBL) */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
357 |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
358 if ((8 == (**(**hGD).gdPMap).pixelSize) && (noErr == err)) /* if successful and on an 8 bit device */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
359 { |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
360 hCTabDeviceColors = (**(**hGD).gdPMap).pmTable; /* do SetEntries to force CLUT update */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
361 setEntriesRec.csTable = (ColorSpec *) &(**hCTabDeviceColors).ctTable; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
362 setEntriesRec.csStart = 0; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
363 setEntriesRec.csCount = (**hCTabDeviceColors).ctSize; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
364 csPtr = (Ptr) &setEntriesRec; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
365 err = Control((**hGD).gdRefNum, cscSetEntries, (Ptr) &csPtr); /* SetEntries in CLUT */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
366 } |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
367 DisposeGammaTable ((Ptr) pTableGammaNew); /* dump table */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
368 if (noErr == err) |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
369 return true; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
370 } |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
371 } |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
372 } |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
373 else /* set NULL gamma -> results in linear map */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
374 { |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
375 gameRecRestore.csGTable = (Ptr) NULL; /* setup restore record */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
376 csPtr = (Ptr) &gameRecRestore; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
377 err = Control((**hGD).gdRefNum, cscSetGamma, (Ptr) &csPtr); /* restore gamma */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
378 |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
379 if ((8 == (**(**hGD).gdPMap).pixelSize) && (noErr == err)) /* if successful and on an 8 bit device */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
380 { |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
381 hCTabDeviceColors = (**(**hGD).gdPMap).pmTable; /* do SetEntries to force CLUT update */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
382 setEntriesRec.csTable = (ColorSpec *) &(**hCTabDeviceColors).ctTable; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
383 setEntriesRec.csStart = 0; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
384 setEntriesRec.csCount = (**hCTabDeviceColors).ctSize; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
385 csPtr = (Ptr) &setEntriesRec; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
386 err = Control((**hGD).gdRefNum, cscSetEntries, (Ptr) &csPtr); /* SetEntries in CLUT */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
387 } |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
388 if (noErr == err) |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
389 return true; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
390 } |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
391 return false; /* memory allocation or device control failed if we get here */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
392 } |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
393 |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
394 /* end of ADC Gamma Ramp support code... */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
395 |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
396 static Ptr systemGammaPtr; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
397 |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
398 void Mac_QuitGamma(_THIS) |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
399 { |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
400 if (systemGammaPtr) |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
401 { |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
402 RestoreSystemGammas(systemGammaPtr); |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
403 DisposeSystemGammas(&systemGammaPtr); |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
404 } |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
405 } |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
406 |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
407 static unsigned char shiftedRamp[3 * 256]; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
408 |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
409 int Mac_SetGammaRamp(_THIS, Uint16 *ramp) |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
410 { |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
411 int i; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
412 if (!systemGammaPtr) |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
413 systemGammaPtr = GetSystemGammas(); |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
414 for (i = 0; i < 3 * 256; i++) |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
415 { |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
416 shiftedRamp[i] = ramp[i] >> 8; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
417 } |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
418 |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
419 if (SetDeviceGammaRampGD(GetMainDevice(), (Ptr) shiftedRamp)) |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
420 return 0; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
421 else |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
422 return -1; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
423 } |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
424 |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
425 int Mac_GetGammaRamp(_THIS, Uint16 *ramp) |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
426 { |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
427 if (GetDeviceGammaRampGD(GetMainDevice(), (Ptr) shiftedRamp)) |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
428 { |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
429 int i; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
430 for (i = 0; i < 3 * 256; i++) |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
431 { |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
432 ramp[i] = shiftedRamp[i] << 8; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
433 } |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
434 return 0; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
435 } |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
436 else |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
437 return -1; |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
438 } |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
439 |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
440 #endif /* SDL_MACCLASSIC_GAMMA_SUPPORT */ |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
441 |
7cdb1d7fc93b
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
442 |