mirror of
https://github.com/aaronsgiles/JPEGView.git
synced 2024-06-06 21:29:27 +00:00
1 line
16 KiB
C
1 line
16 KiB
C
|
/*********************************************************/
/* This source code copyright (c) 1991-2001, Aaron Giles */
/* See the Read Me file for licensing information. */
/* Contact email: mac@aarongiles.com */
/*********************************************************/
#define SystemSevenOrLater 1
#include <Aliases.h>
#include <Components.h>
#include <Errors.h>
#include <ImageCompression.h>
#include <QuickTimeComponents.h>
#include <Memory.h>
#include <MixedMode.h>
#include <QuickDraw.h>
/*
* Macros and typedefs
*
*/
#define JFIFPreviewVersion 0x00010001
#define kBufferSize 20
#define Height(r) ((r)->bottom - (r)->top)
#define Width(r) ((r)->right - (r)->left)
#define pnotDisplayPreview 1
typedef unsigned char uchar;
typedef unsigned short ushort;
typedef unsigned long ulong;
enum {
uppPreviewOpenProcInfo = kPascalStackBased
| RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
| STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(ComponentInstance))),
uppPreviewCloseProcInfo = kPascalStackBased
| RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
| STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(Handle)))
| STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(ComponentInstance))),
uppPreviewCanDoProcInfo = kPascalStackBased
| RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
| STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(short))),
uppPreviewDisplayProcInfo = kPascalStackBased
| RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
| STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(Handle)))
| STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(OSType)))
| STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(Handle)))
| STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(const Rect *)))
};
/*
* Function prototypes
*
*/
extern pascal ComponentResult EntryPoint(ComponentParameters *params, Handle storage);
pascal ComponentResult JFIFPreviewOpen(ComponentInstance self);
pascal ComponentResult JFIFPreviewClose(Handle theBuffer, ComponentInstance self);
pascal ComponentResult JFIFPreviewCanDo(short selector);
pascal ComponentResult JFIFPreviewShow(Handle theBuffer, OSType dataType, Handle data,
const Rect *inHere);
OSErr LoadPreview(Handle *theData, short theFile, uchar *buffer, short width, short height);
OSErr LoadPreviewExtension(Handle *theData, short theFile, long theSize);
OSErr MakePreviewGWorld(GWorldPtr *theGWorld, const Rect *inHere, short width, short height);
OSErr DrawPreview(Handle previewData, const Rect *inHere, short width, short height);
uchar *ParseJPEG(uchar *theAdr, long theLen, uchar theCode);
OSErr MakeImageDescription(ImageDescriptionHandle *theDesc, Handle previewData);
OSErr DrawJPEGPreview(Handle previewData, const Rect *inHere);
OSErr Draw1CompPreview(Handle previewData, const Rect *inHere);
OSErr Draw3CompPreview(Handle previewData, const Rect *inHere);
#if defined(powerc) || defined(__powerc)
enum {
uppMainProcInfo = kPascalStackBased
| RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
| STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(ComponentParameters *)))
| STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(Handle)))
};
RoutineDescriptor EntryPointRD = BUILD_ROUTINE_DESCRIPTOR(uppMainProcInfo, EntryPoint);
#endif
/*
* This is the entry point where we dispatch the request to the appropriate function
*
*/
extern pascal ComponentResult EntryPoint(ComponentParameters *params, Handle storage)
{
ComponentFunctionUPP theRoutine = nil;
ComponentResult theResult = noErr;
switch (params->what) {
case kComponentOpenSelect:
if (theRoutine = NewRoutineDescriptor((ProcPtr)JFIFPreviewOpen,
uppPreviewOpenProcInfo, GetCurrentISA()))
theResult = CallComponentFunction(params, theRoutine);
break;
case kComponentCloseSelect:
if (theRoutine = NewRoutineDescriptor((ProcPtr)JFIFPreviewClose,
uppPreviewCloseProcInfo, GetCurrentISA()))
theResult = CallComponentFunctionWithStorage(storage, params, theRoutine);
break;
case kComponentCanDoSelect:
if (theRoutine = NewRoutineDescriptor((ProcPtr)JFIFPreviewCanDo,
uppPreviewCanDoProcInfo, GetCurrent
|