/*
 *  MyTI_AECoercions.h
 *  TI Connect X CommMgr
 *
 *  Created by Stephen L. Reid on Wed Sep 25 2002.
 *  Copyright (c) 2002-2003 Texas Instruments Incorporated. All rights reserved.
 *
 * ----------------------------
 *	This set of routines provides a "workaround" to an Applescipt system
 *	defect that was found in OS X 10.2, 10.2.1 by me and reported to
 *	Apple as bug report #3055279.
 *
 *	The basic problem is, that under OS X 10.2, the AECoercePtr()
 *	call does not properly handle the coercion when the target coercion
 *	handler is a "descriptor"-style coercion handler.  This "glue"
 *	overrides the system mapping routines and provides our own mapping
 *	routines to perform the requisite interface between the various
 *	type of calls (AECoercePtr or AECoerceDesc) and the various handler
 *	types (Ptr or Desc style handlers).    Sep 26, 2002
 *
 */
 #include "TIDirectoryObject.h"

#ifndef __MYTI_AECOERCEDEFECT__
#define __MYTI_AECOERCEDEFECT__

#if PRAGMA_ONCE
#pragma once
#endif

#ifdef __cplusplus
extern "C" {
#endif

#if PRAGMA_STRUCT_ALIGN
    #pragma options align=mac68k
#elif PRAGMA_STRUCT_PACKPUSH
    #pragma pack(push, 2)
#elif PRAGMA_STRUCT_PACK
    #pragma pack(2)
#endif

#if __LP64__
    void BlockMoveData( void *s, void *d, long len );
    void BlockZero( void *d, long len );
#endif

long MyTI_FindChar( Handle        inHandle,
                   long          inOffset,
                   char          inChar );

long MyTI_FindString( Handle        inHandle,
                      long          inOffset,
                      char          *inString,
                      long          inLength );

/**************************************************************************
  The following calls provide for a coercion interface (which will work
  under 10.2/10.2.1 -slr
**************************************************************************/
/*
 *  MyTI_AECoercePtr()
 *  
 *  Availability:
 *    Mac OS X:         in version 10.0 and later in TIConnectAE.framework
 */
extern OSErr    MyTI_AECoercePtr(  DescType     typeCode,
                            const void *  dataPtr,
                            Size          dataSize,
                            DescType      toType,
                            AEDesc *      result);


extern OSErr    MyTI_SafeAECoercePtr(  MPCriticalRegionID criticalRegion,
                            DescType     typeCode,
                            const void *  dataPtr,
                            Size          dataSize,
                            DescType      toType,
                            AEDesc *      result);

/*
 *  MyTI_AECoerceDesc()
 *  
 *  Availability:
 *    Mac OS X:         in version 10.0 and later in TIConnectAE.framework
 */
extern OSErr    MyTI_AECoerceDesc( const AEDesc *  inAEDesc,
                            DescType      toType,
                            AEDesc *      result);



extern OSErr    MyTI_SafeAECoerceDesc( MPCriticalRegionID criticalRegion,
                            const AEDesc *  inAEDesc,
                            DescType      toType,
                            AEDesc *      result);


//void		MyTI_SwapDirectoryObjectHostToBig( TIDirectoryObject *inoutObject );
//void		MyTI_SwapDirectoryObjectBigToHost( TIDirectoryObject *inoutObject );
void		MyTI_GetIndString( Handle strResHandle, Str255 buffer, UInt16 strResNum, UInt16 strIndex );
// Generic Quickdraw calc screen to PICT translation
OSErr		MyTI_PictureToPICT( UInt8 *inData, SInt16 nCols, SInt16 nRows, DescType desiredType, Boolean colorBackground, AEDesc *outResult );

uint32_t TI_DecompressImageData( uint8_t *incomingData, uint32_t incomingSize, uint16_t *outgoingRGB565_Buffer, uint32_t *outgoingSize );

    
    
    
#if PRAGMA_STRUCT_ALIGN
    #pragma options align=reset
#elif PRAGMA_STRUCT_PACKPUSH
    #pragma pack(pop)
#elif PRAGMA_STRUCT_PACK
    #pragma pack()
#endif

#ifdef __cplusplus
}
#endif

#endif /* __MYTI_AECOERCEDEFECT__ */
