TestFunctions.c

/*
    File:       TestFunctions.c
 
    Contains:   Test functions for Sequence grabber and vdig tests.
 
    Written by:     
 
    Copyright:  Copyright © 1995-1999 by Apple Computer, Inc., All Rights Reserved.
 
                You may incorporate this Apple sample source code into your program(s) without
                restriction. This Apple sample source code has been provided "AS IS" and the
                responsibility for its operation is yours. You are not permitted to redistribute
                this Apple sample source code as "Apple sample source code" after having made
                changes. If you're going to re-distribute the source, we require that you make
                it clear in the source that the code was descended from Apple sample source
                code, but that you've made changes.
 
    Change History (most recent first):
                7/28/1999   Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
                
 
*/
 
 
// INCLUDES
#include "TestFunctions.h"
 
#include "DTSQTUtilities.h"
#include "MacFramework.h"
 
extern WindowPtr gCaptureWindow;
 
// FUNCTIONS
// ______________________________________________________________________
//¥ Dump vdig information from the currently selected vdig (used by the sequence grabber).
OSErr ShowVDIGInfo(void)
{
    OSErr anErr = noErr;
    VideoDigitizerComponent vd = NULL;
    DigitizerInfo                     digInfo;
    
    printf("\nINFORMATION: Video Digitizer (default component):\n");
    
    //¥ Get access to the sequence grabber's vdig.
    vd = SGGetVideoDigitizerComponent( GetDefaultVideoChannel() ); DebugAssert(vd != NULL);
    if(vd == NULL)
    {
        printf("ERROR: Problems getting the vdig component instance from video channel.\n");
        goto Closure;
    }
 
    //¥ Test for live incoming video signal.
    if(QTUDoesVDIGReceiveVideo(vd))
        printf("Vdig is currently receiving a video signal.\n");
    else
        printf("Vdig is currently NOT receiving a video signal.\n");
    
    //¥ Get access to the video digitizer information data structure.
    anErr = VDGetDigitizerInfo(vd, &digInfo); DebugAssert(anErr == noErr);
    if(anErr != noErr)
    {
        printf("ERROR: Problems getting Digitizer Information.\n");
        goto Closure;
    }
 
    //¥ Get information about the vdig type.
    printf("\nVdig Type = ");
    switch (digInfo.vdigType)
    {
        case vdTypeBasic:
            printf("vdTypeBasic (basic video digitizer, does not support any clipping.\n");
            break;
 
        case vdTypeAlpha:
            printf("vdTypeAlpha (supports clipping by means of an alpha channel).\n");
            break;
 
        case vdTypeMask:
            printf("vdTypeMask (supports clipping by means of a mask plane).\n");
            break;
 
        case vdTypeKey:
            printf("vdTypeKey (supports clipping by means of key colors).\n");
            break;
    }
    
    //¥ Get information about the vdig input capabilities (default ones).
    printf("\nThe vdig handles the following inputs:\n");
    if(digInfo.inputCapabilityFlags & digiInDoesNTSC)
        printf("\tNTSC\n");     
    if(digInfo.inputCapabilityFlags & digiInDoesPAL)
        printf("\tPAL\n");
    if(digInfo.inputCapabilityFlags & digiInDoesSECAM)
        printf("\tSECAM\n");
    if(digInfo.inputCapabilityFlags & digiInDoesGenLock)
        printf("\tGenlock\n");
    if(digInfo.inputCapabilityFlags & digiInDoesComposite)
        printf("\tComposite Video\n");
    if(digInfo.inputCapabilityFlags & digiInDoesSVideo)
        printf("\tS-Video\n");
    if(digInfo.inputCapabilityFlags & digiInDoesComponent)
        printf("\tRGB input video\n");
    if(digInfo.inputCapabilityFlags & digiInDoesColor)
        printf("\tColor input\n");
    if(digInfo.inputCapabilityFlags & digiInDoesBW)
        printf("\tGrayScale input\n");
    
    if(digInfo.inputCurrentFlags & digiInSignalLock)
        printf("\tCurrently the vdig is locked onto the input signal.\n");
        
        
    //¥ Get information about the vdig output capabilities (default ones).
        printf("\nThe vdig handles the following output cases:\n");
        printf("Pixel Maps of size (bit): ");
    if(digInfo.outputCapabilityFlags & digiOutDoes1)
        printf("1 ");       
    if(digInfo.outputCapabilityFlags & digiOutDoes2)
        printf("2 ");       
    if(digInfo.outputCapabilityFlags & digiOutDoes4)
        printf("4 ");       
    if(digInfo.outputCapabilityFlags & digiOutDoes8)
        printf("8 ");       
    if(digInfo.outputCapabilityFlags & digiOutDoes16)
        printf("16 ");      
    if(digInfo.outputCapabilityFlags & digiOutDoes32)
        printf("32 ");      
 
    printf("\n");
    
    if(digInfo.outputCapabilityFlags & digiOutDoesDither)
        printf("Handles dithering out.\n");
    if(digInfo.outputCapabilityFlags & digiOutDoesStretch)
        printf("Handles stretching of images.\n");
    if(digInfo.outputCapabilityFlags & digiOutDoesShrink)
        printf("Handles shrinking of images.\n");
    if(digInfo.outputCapabilityFlags & digiOutDoesDouble)
        printf("Handles doubling (stretching to quadruple size) of images.\n");
    if(digInfo.outputCapabilityFlags & digiOutDoesQuad)
        printf("Handles stretching image to 16 times original size.\n");
    if(digInfo.outputCapabilityFlags & digiOutDoesQuarter)
        printf("Handles shrinking image to 1/4 times original size.\n");
    if(digInfo.outputCapabilityFlags & digiOutDoesSixteenth)
        printf("Handles shrinking image to 1/16 times original size.\n");
    if(digInfo.outputCapabilityFlags & digiOutDoesRotate)
        printf("Handles rotation of image displayed.\n");
    if(digInfo.outputCapabilityFlags & digiOutDoesHorizFlip)
        printf("Handles horizontal flip of image displayed.\n");
    if(digInfo.outputCapabilityFlags & digiOutDoesVertFlip)
        printf("Handles vertical flip of image displayed.\n");
    if(digInfo.outputCapabilityFlags & digiOutDoesSkew)
        printf("Handles skew of image displayed.\n");
    if(digInfo.outputCapabilityFlags & digiOutDoesBlend)
        printf("Handles blend of image with matte.\n");
    if(digInfo.outputCapabilityFlags & digiOutDoesWarp)
        printf("Handles warp of image (distortion along an axis).\n");
    if(digInfo.outputCapabilityFlags & digiOutDoesHW_DMA)
        printf("Handles DMA writes to screen or offscreen memory.\n");
    if(digInfo.outputCapabilityFlags & digiOutDoesHWPlayThru)
        printf("Handles Playthrough mode (no need for idle time).\n");
    if(digInfo.outputCapabilityFlags & digiOutDoesILUT)
        printf("Handles inverse lookup tables for indexed color modes.\n");
    if(digInfo.outputCapabilityFlags & digiOutDoesKeyColor)
        printf("Handles clipping by using key colors.\n");
    if(digInfo.outputCapabilityFlags & digiOutDoesAsyncGrabs)
        printf("Can operate asynchronously.\n");
    
    if(digInfo.outputCapabilityFlags & digiOutDoesUnreadableScreenBits)
        printf("Vdig might place pixels on the screeen that can't be used when compressing images.\n");
    if(digInfo.outputCapabilityFlags & digiOutDoesCompress)
        printf("Vdig supports compressed source devices.\n");
    if(digInfo.outputCapabilityFlags & digiOutDoesCompressOnly)
        printf("Vdig only provides compressed image data.\n");
    if(digInfo.outputCapabilityFlags & digiOutDoesPlayThruDuringCompress)
        printf("Vdig can't draw images on the screen while it's delivering compressed images.\n");
    
 
    //¥ Get information about the sizes this vdig could handle.
    printf("\n\nSmallest resizable height = \t%d.\n", digInfo.minDestHeight);
    printf("Smallest resizable width = \t%d.\n", digInfo.minDestWidth);
    printf("Largest resizable height = \t%d.\n", digInfo.maxDestHeight);
    printf("Largest resizable width = \t%d.\n", digInfo.maxDestWidth);
    
    
    //¥ Get information about the vdig blending capabilities.
    printf("\nBlend level = \t%d (2 if 1-bit mask).\n", digInfo.blendLevels);
 
Closure:
    return anErr;
}
 
 
// ______________________________________________________________________
//¥ Call the video settings dialog box for the particular sequence grabber.
void SetMyVideoChannelSettings(void)
{
    OSErr anErr = noErr;
    
    anErr = SGSettingsDialog( GetDefaultSGInstance(), GetDefaultVideoChannel(), 0, NULL,
                                            DoTheRightThing, NULL, 0); DebugAssert(anErr == noErr);
}
 
 
// ______________________________________________________________________
//¥ Call the audio settings dialog box for the particular sequence grabber.
void SetMyAudioChannelSettings(void)
{
    OSErr anErr = noErr;
    
    anErr = SGSettingsDialog( GetDefaultSGInstance(), GetDefaultAudioChannel(), 0, NULL,
                                            DoTheRightThing, NULL, 0); DebugAssert(anErr == noErr);
}
 
 
// ______________________________________________________________________
//¥ Record to file using a sequence grabber.
void RecordSamplesToFile(void)
{
    OSErr                       anErr = noErr;
    StandardFileReply   reply;
    ComponentInstance   sg = GetDefaultSGInstance();
    
    //¥ Create file used.
    StandardPutFile("\pName of the movie file:", "\pMOVIE.MOV", &reply);
    if(!reply.sfGood) goto Closure;
    
    //¥ Tell SG what file we will use.
    anErr = SGSetDataOutput(sg, &reply.sfFile, seqGrabToDisk); 
    DebugAssert(anErr == noErr); if(anErr) goto Closure;
    
    SetWTitle(gCaptureWindow, "\pRecording. Click Mouse  to Stop!");
    
    //¥ Record until mouse click.
    anErr = SGStartRecord(sg); DebugAssert(anErr == noErr); if(anErr) goto Closure;
    
    while( !Button() )
        SGIdle(sg);
 
    DebugAssert(anErr == noErr); 
    
    //¥ Stop recording, flush events, start the normal preview mode again.
    anErr = SGStop(sg); DebugAssert(anErr == noErr);
    SetWTitle(gCaptureWindow, "\pMovie captured...");
    
    anErr = SGStartPreview(sg); DebugAssert(anErr == noErr);
    FlushEvents(mDownMask | mUpMask, 0);
    SetWTitle(gCaptureWindow,"\pCapture Window");
    
Closure:
    return;
}