Common Files/ImageCompressionUtilities.h

//////////
//
//  File:       ImageCompressionUtilities.h
//
//  Contains:   Image Compression Utilities.
//
//  Written by: Peter Hoddie, Sean Allen, Chris Flick
//  Revised by: Tim Monroe
//
//  Copyright:  © 1998 by Apple Computer, Inc., all rights reserved.
//
//  Change History (most recent first):
//
//     <2>      03/17/00    rtm     moved some things from ImageCompressionUtilities.c to here
//     <1>      03/27/98    rtm     existing file
//
//////////
 
 
#ifndef __IMAGECOMPRESSIONUTILITIES__
#define __IMAGECOMPRESSIONUTILITIES__
 
 
//////////
//
// header files
//
//////////
 
#ifndef __MOVIES__
#include <Movies.h>
#endif
 
#ifndef __COLORPICKER__
#include <ColorPicker.h>
#endif
 
#ifndef __RESOURCES__
#include <Resources.h>
#endif
 
#ifndef __ENDIAN__
#include <Endian.h>
#endif
 
#ifndef __IMAGECOMPRESSION__
#include <ImageCompression.h>
#endif
 
#ifndef __QUICKDRAW__
#include <Quickdraw.h>
#endif
 
#ifndef PASCAL_RTN
#define PASCAL_RTN
#endif
 
 
//////////
//
// compiler macros
//
//////////
 
#define BailIf(a, e)                        {if (a)     { err = e; goto bail; }}
#define BailOSErr(a)                        {if ((err = a) != noErr)    goto bail;}
#define BailMemErr(a)                       {a; if ((err = MemError()) != noErr) goto bail;}
 
#if TARGET_OS_WIN32
#define GetPortGrafProcs(a)                 (CQDProcsPtr)a->grafProcs
#define SetPortGrafProcs(a,b)               a->grafProcs=(CGrafPtr)b
#endif
 
 
//////////
//
// constants
//
//////////
 
#define kCompressDepth                      16          // use the Animation compressor at 16 bit depth in these utilities
#define kThreshold                          (255-16)
 
enum {
    kRecoProcInitMsg = 1,                   // message and refcon are valid
    kRecoProcDisposeMsg = 2,                // message and refcon are valid
    kRecoProcGetBoundsMsg = 3,              // message, bounds and refcon are valid. Proc fills in bounds with rectangle to use for compressed image.
    kRecoProcDrawMsg = 4                    // message, bounds, drawingPort, portType and refcon are valid. portType is 'imag' if drawing into
                                            // image GWorld, 'imap' if drawing into hit testing GWorld.
};
 
enum {
    kRecoProcOriginalImageType          =   FOUR_CHAR_CODE('imag'),
    kRecoProcHitTestingImageType        =   FOUR_CHAR_CODE('imap')
};
 
 
//////////
//
// data types
//
//////////
 
// used for compressing QuickDraw pictures with transparency/hittesting
typedef struct {
    PicHandle                   picture;
} PictureCompressProcData;
 
// used for recompressing QuickTime compressed data with transparency/hittesting
typedef struct {
    ImageDescriptionHandle      imageDesc;
    Handle                      imageData;
} CompressedImageCompressProcData;
 
// used for extracting QuickTime compressed image data and description, if any, from a QuickDraw picture
typedef struct {
    CGrafPtr                    tempPort;
    Handle                      data;
    ImageDescriptionHandle      idh;
} extractPictRecord;
 
// low-level callback procedure based routine to compress with/without transparency & hit-testing
typedef PASCAL_RTN OSErr (*CompressDrawProc)( short message, Rect * bounds, GWorldPtr drawingPort, OSType drawingImageType, void * refcon );
 
 
//////////
//
// function prototypes
//
//////////
 
OSErr                                   ExtractCompressData ( PicHandle thePict, Handle *dataOut, ImageDescriptionHandle *idh );
PASCAL_RTN void                         extractStdPix ( PixMap *src, Rect *srcRect, MatrixRecord *matrix, short mode, RgnHandle mask, PixMap *matte, Rect *matteRect, short flags );
PASCAL_RTN void                         noDitherBitsProc (BitMap *srcBits, Rect *srcRect, Rect *dstRect, short mode, RgnHandle maskRgn);
 
// utilities for compressing from various types of sources
OSErr                                   RecompressWithTransparencyFromProc (
                                                    CompressDrawProc drawProc,
                                                    void * drawProcRefcon, 
                                                    Boolean includeHitTesting,
                                                    RGBColor *keyColor, 
                                                    RgnHandle hitTestRegion,
                                                    ImageDescriptionHandle *idh,
                                                    Handle * imageData );
                                                    
 
OSErr                                   RecompressCompressedImageWithTransparency (
                                                    ImageDescriptionHandle originalDesc,
                                                    Handle originalImageData,
                                                    RGBColor *keyColor, 
                                                    RgnHandle limitHitTestRegion,
                                                    ImageDescriptionHandle *idh,
                                                    Handle * imageData );
                                                    
OSErr                                   RecompressPictureWithTransparency (
                                                    PicHandle originalPicture,
                                                    RGBColor *keyColor, 
                                                    RgnHandle limitHitTestRegion,
                                                    ImageDescriptionHandle *idh,
                                                    Handle * imageData );
                                                    
OSErr                                   RecompressPictureFileWithTransparency (
                                                    FSSpec * spec, 
                                                    RGBColor *keyColor, 
                                                    RgnHandle limitHitTestRegion,
                                                    ImageDescriptionHandle *idh,
                                                    Handle * imageData );
                                                    
 
#endif // __IMAGECOMPRESSIONUTILITIES__