home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-12-06 | 3.2 KB | 122 lines | [TEXT/MMCC] |
- // depth.c
- //
- // Library routines for getting and setting the color depth for monitors.
- // All of the code originated from Kenneth Worley's Monitor Tricks 1.51 in C++.
- // Changed to C by Mark Womack.
- //
- // 12/07/95 1.0 release
- //
-
- #include "depth.h"
- #include <palettes.h>
-
- // MaxScreenDepth returns the maximum bit depth that the monitor is capable of
- // (i.e. 8 for 256 colors).
- pascal short MaxScreenDepth( GDHandle theGDevice )
- {
- short x;
- short hasThisDepth=1;
-
- for ( x=2; x<=32; x*=2 )
- if ( HasDepth( theGDevice, x, gdDevType, 1 ) )
- hasThisDepth = x;
- else
- break;
-
- return hasThisDepth;
- }
-
- // Returns true if the monitor supports the given depth
- pascal Boolean SupportsDepth( GDHandle theGDevice, short aDepth)
- {
- GDHandle savedDevice;
- Boolean val;
-
- savedDevice = GetGDevice();
- SetGDevice( theGDevice );
-
- val = HasDepth( theGDevice, aDepth, 1 << gdDevType, GetScreenMode(theGDevice) );
-
- SetGDevice( savedDevice );
-
- return val;
- }
-
- // GetScreenDepth returns the current bit depth of this monitor.
- pascal short GetScreenDepth( GDHandle theGDevice )
- {
- return ((**((**(theGDevice)).gdPMap)).pixelSize);
- }
-
- // SetScreenDepth changes the bit depth of the screen (the number of colors that it can
- // display at once).
- pascal void SetScreenDepth( GDHandle theGDevice, short newDepth )
- {
- GDHandle savedDevice;
-
- savedDevice = GetGDevice();
- SetGDevice( theGDevice );
-
- if ( newDepth != GetScreenDepth(theGDevice) )
- if ( HasDepth( theGDevice, newDepth, 1 << gdDevType, GetScreenMode(theGDevice) ) )
- SetDepth( theGDevice, newDepth, 1 << gdDevType, GetScreenMode(theGDevice) );
-
- SetGDevice( savedDevice );
- }
-
- // Returns true if the monitor supports the given mode
- pascal Boolean SupportsMode( GDHandle theGDevice, short aMode)
- {
- GDHandle savedDevice;
- Boolean val;
-
- savedDevice = GetGDevice();
- SetGDevice( theGDevice );
-
- val = HasDepth( theGDevice, GetScreenDepth(theGDevice), 1 << gdDevType, aMode );
-
- SetGDevice( savedDevice );
-
- return val;
- }
-
- // GetScreenMode returns one if the monitor is displaying colors, zero if it's displaying in grays.
- pascal short GetScreenMode( GDHandle theGDevice )
- {
- if ( TestDeviceAttribute( theGDevice, gdDevType ) )
- return 1; //colors
- else
- return 0; //grays
- }
-
- // SetScreenMode sets this monitor to color if 1 is sent, or grays if zero is sent.
- pascal void SetScreenMode( GDHandle theGDevice, short newMode )
- {
- GDHandle savedDevice;
-
- savedDevice = GetGDevice();
- SetGDevice( theGDevice );
-
- if ( newMode != GetScreenMode(theGDevice) )
- if ( HasDepth( theGDevice, GetScreenDepth(theGDevice), 1 << gdDevType, newMode ) )
- SetDepth( theGDevice, GetScreenDepth(theGDevice), 1 << gdDevType, newMode );
-
- SetGDevice( savedDevice );
- }
-
- // SetScreenModeDepth sets the monitor to the color mode and depth specified.
- pascal void SetScreenModeDepth( GDHandle theGDevice, short newDepth, short newMode )
- {
- GDHandle savedDevice;
-
- savedDevice = GetGDevice();
- SetGDevice( theGDevice );
-
- if ( (newDepth != GetScreenDepth(theGDevice)) || (newMode != GetScreenMode(theGDevice)) )
- if ( HasDepth( theGDevice, newDepth, 1 << gdDevType, newMode ) )
- SetDepth( theGDevice, newDepth, 1 << gdDevType, newMode );
-
- SetGDevice( savedDevice );
- }
-
-