[comp.sys.mac.programmer] New SetDepth call

rick@jessica.Stanford.EDU (Rick Wong) (07/27/90)

Tech Note 276 details a new call available in System 6.0.5 to set the
bit-depth of a device, called SetDepth.  The TN gives the following example:

	someResult := SetDepth(myGDevice, {newDepth:} 8,
			{whichFlags:} 1, {newFlags:} 0);

    In this call, newDepth = 8 sets an eight-bit depth, whichFlags = 1
    indicates that only bit one of newFlags is important, and newFlags = 0
    clears the gdDevType flag in the device record (0 = monochrome, 
    1 = color).  SetDepth returns zero if successful or a non-zero value
    if it cannot impose the desired depth on the requested device.

Armed with this information, I tried to write an FKEY to toggle the depth
of my main screen between one-bit and eight-bit.  Can anyone explain why
the following does not work?  My system has all the necessary hardware, etc.


#include <Types.h>
#include <OSUtils.h>
#include <Devices.h>


pascal short SetDepth(GDHandle gd, short newDepth,
    short whichFlags, short newFlags)
    = {0x203C, 0x000A, 0x0013, 0xAB1D};

pascal short HasDepth(GDHandle gd, short newDepth,
    short whichFlags, short newFlags)
    = {0x203C, 0x000A, 0x0014, 0xAB1D};


#define    kSysEnvVersion    1
#define    kSystem6_0_5    0x0605


int
main()
{
SysEnvRec gWorld;
GDHandle  mainDev;
int       oldDepth;
Boolean   successful;

    successful = false;
    (void) SysEnvirons(kSysEnvVersion, &gWorld);
    if (gWorld.systemVersion >= kSystem6_0_5 && gWorld.hasColorQD)    {
        mainDev = GetMainDevice();
        oldDepth = (**(**mainDev).gdPMap).pixelSize;
        if (oldDepth == 1)    {
            successful = (SetDepth(mainDev, 8, 0, 0) == noErr);
        } else {
            successful = (SetDepth(mainDev, 1, 0, 0) == noErr);
        }
    }
    if (!successful)    {
        SysBeep(1);
    }
    return 0;
}

When I try to set the depth to one-bit, the result code returned is 257;
eight-bit, 264.

Thanks,

Rick Wong
rick@jessica.stanford.edu

russotto@eng.umd.edu (Matthew T. Russotto) (07/27/90)

In article <1990Jul26.183633.10926@portia.Stanford.EDU> rick@jessica.Stanford.EDU (Rick Wong) writes:
>Tech Note 276 details a new call available in System 6.0.5 to set the
>bit-depth of a device, called SetDepth.

>pascal short SetDepth(GDHandle gd, short newDepth,
>    short whichFlags, short newFlags)
>    = {0x203C, 0x000A, 0x0013, 0xAB1D};
>
>#define    kSysEnvVersion    1
>#define    kSystem6_0_5    0x0605

>    if (gWorld.systemVersion >= kSystem6_0_5 && gWorld.hasColorQD)    {

Do you have 32-bit Quickdraw installed?  'AB1D' is a trap implemented by
32-bit quickdraw, not (I don't think) System 6.05 itself.
--
Matthew T. Russotto	russotto@eng.umd.edu	russotto@wam.umd.edu
][, ][+, ///, ///+, //e, //c, IIGS, //c+ --- Any questions?
		Hey!  Bush has NO LIPS!

mjohnson@Apple.COM (Mark B. Johnson) (07/27/90)

Oops.  We revised #276 in June because we had a few errors in the original
Note.  The inline traps had an error as well as the selector in HasDepth.
Following is the correct syntax of these calls, as found in the latest
version of #276:

FUNCTION SetDepth(gd:GDHandle; newDepth,whichFlags, newFlags: Integer):Integer;
    INLINE $203C,$000A, $0013,$AAA2; { Move.L #$000A0013,D0
                                      _PMgrDispatch
                                    }

pascal short SetDepth(GDHandle gd, short  newDepth,short whichFlags,
                      short newFlags)
                      = {0x203C, 0x000A, 0x0013, 0xAAA2};
 

FUNCTION HasDepth(gd:GDHandle; newDepth,whichFlags, newFlags: Integer):Integer;
    INLINE $203C,$000A $0014,$AAA2; { Move.L #$000A0014,D0
                                      _PMgrDispatch
                                    }

pascal short HasDepth(GDHandle gd, short  newDepth,short whichFlags,
                      short newFlags)
                      = {0x203C,0x000A 0x0014,0xAAA2};


Sorry for any confusion our error caused.

-- 
Mark B. Johnson                                            AppleLink: mjohnson
Developer Technical Support                         domain: mjohnson@Apple.com
Apple Computer, Inc.         UUCP:  {amdahl,decwrl,sun,unisoft}!apple!mjohnson

"You gave your life to become the person you are right now.  Was it worth it?"
                                                         - Richard Bach, _One_

rick@jessica.stanford.edu (Rick Wong) (07/28/90)

Thanks to all who replied to my query about SetDepth.  (I was using the
tech notes that were in the Inside Mac VI stack on the Sys 7.0a9 CD.)
Using the corrected inline definition almost works, except . . .

My machine crashes when I try to use it.  (Waaaaahhhhhhh!)  The symptoms
are as follows:

    Going from 8 -> 1-bit:
	-- my screen blanks out
	-- I drop into MacsBug with a bus error
	-- when I do an ExitToShell, the screen is in 1-bit mode

    Going from 1 -> 8-bit:
	-- my screen blanks out	
	-- I drop into MacsBug with a bus error
	-- when I do an ExitToShell, the screen is in 8-bit mode
	-- when I reboot, the screen is changed from color to grayscale

The calls I make to SetDepth are:

    if (oldDepth == 1) {
	successful = (SetDepth(mainDev, 8, 0, 0) == noErr);
    } else {
	successful = (SetDepth(mainDev, 1, 0, 0) == noErr);
    }

I am doing this on a IIfx with System 6.0.5.  The crashes occur even when
I have removed all skanky inits from my system folder.

Once again, thanks for any help.

Rick Wong
rick@jessica.stanford.edu