home *** CD-ROM | disk | FTP | other *** search
- /*
- File: DemoCMM.c
-
- Contains: Demo CMM Component for ColorSync 2.x
-
- This is a very simple CMM - so simple in fact that the only thing
- it uses from a profile is its colorspace.
-
- If the first (source) profile is RGB and the last (dest) profile
- is CMYK, then this CMM uses the simple "one minus" formula
- to convert from from RGB to CMYK.
-
- If the first (source) profile is CMYK and the last (dest) profile
- is RGB, then this CMM uses the inverse of the "one minus" formula
- to convert from from CMYK to RGB.
-
- If the first and the last profile are RGB or if the first and the
- last profile are CMYK, then this CMM leaves the colors unchanged.
-
- Version: ColorSync 2 or later
-
- Written by: David Hayward
-
- Copyright: © 1998 by Apple Computer, Inc., all rights reserved.
-
- Writers:
- (DH) David Hayward
-
- Change History (most recent first):
-
- <1> 7/16/98 DH First checked in.
-
- */
-
- #include <ConditionalMacros.h>
- #include <MacTypes.h>
- #include <Memory.h>
- #include <Gestalt.h>
- #include <Components.h>
- #include <CMMComponent.h>
-
-
- #ifndef DEBUG
- #define DEBUG 0
- #endif
-
-
- // Component version
- #define CMCodeVersion 1
- #define CMMVersion ((CMMInterfaceVersion << 16) | CMCodeVersion)
-
-
- // Component storage
- typedef struct
- {
- ComponentInstance ci;
- OSType srcSpace;
- OSType srcClass;
- OSType dstSpace;
- OSType dstClass;
- } CMMStorageRec, *CMMStoragePtr, **CMMStorageHdl;
-
- // Match stuff
- typedef struct
- {
- UInt32 height;
- UInt32 width;
-
- OSType srcSpace;
- UInt8* srcBuf[4];
- UInt32 srcChanBits;
- UInt32 srcRowBytes;
- UInt32 srcColBytes;
-
- OSType dstSpace;
- UInt8* dstBuf[4];
- UInt32 dstChanBits;
- UInt32 dstRowBytes;
- UInt32 dstColBytes;
-
- } CMMMatchRec, *CMMMatchPtr, **CMMMatchHdl;
-
-
- // Technique for Native PPC Component function calls from Tech Note "QT05-Component Mgr 3.0"
- #if TARGET_CPU_PPC
- #define CCFWS(storage,params,name) CallComponentFunctionWithStorage(storage, params, &name##RD)
- #define CCF(params,name) CallComponentFunction(params, &name##RD)
- #define INSTANTIATE_RD(name) RoutineDescriptor name##RD = BUILD_ROUTINE_DESCRIPTOR(upp##name##ProcInfo, name)
- #else
- #define CCFWS(storage,params,name) CallComponentFunctionWithStorage(storage, params, (ComponentFunctionUPP)name)
- #define CCF(params,name) CallComponentFunction(params, (ComponentFunctionUPP)name)
- #endif
-
-
- // proc infos
- enum {
- uppDoComponentOpenProcInfo = kPascalStackBased
- | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
- | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(ComponentInstance))),
- uppDoComponentCloseProcInfo = kPascalStackBased
- | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
- | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(Handle)))
- | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(ComponentInstance))),
- uppDoComponentCanDoProcInfo = kPascalStackBased
- | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
- | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(short))),
- uppDoComponentVersionProcInfo = kPascalStackBased
- | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult))),
- uppDoComponentRegisterProcInfo = kPascalStackBased
- | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult))),
- uppDoCMInitProcInfo = kPascalStackBased
- | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
- | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(Handle)))
- | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(CMProfileHandle)))
- | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(CMProfileHandle))),
- uppDoNCMInitProcInfo = kPascalStackBased
- | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
- | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(Handle)))
- | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(CMProfileRef)))
- | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(CMProfileRef))),
- uppDoCMConcatInitProcInfo = kPascalStackBased
- | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
- | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(Handle)))
- | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(CMConcatProfileSet*))),
- uppDoCMMatchColorsProcInfo = kPascalStackBased
- | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
- | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(Handle)))
- | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(CMColor*)))
- | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(unsigned long))),
- uppDoCMCheckColorsProcInfo = kPascalStackBased
- | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
- | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(Handle)))
- | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(CMColor*)))
- | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(unsigned long)))
- | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(long*))),
- uppDoCMMatchBitmapProcInfo = kPascalStackBased
- | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
- | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(Handle)))
- | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(CMBitmap*)))
- | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(CMBitmapCallBackUPP)))
- | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(void*)))
- | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(CMBitmap*))),
- uppDoCMCheckBitmapProcInfo = kPascalStackBased
- | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
- | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(Handle)))
- | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(CMBitmap*)))
- | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(CMBitmapCallBackUPP)))
- | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(void*)))
- | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(CMBitmap*)))
- };
-
-
- // function prototypes
- pascal ComponentResult main (ComponentParameters *params, Handle storage);
- static pascal ComponentResult DoComponentOpen (ComponentInstance self);
- static pascal ComponentResult DoComponentClose (CMMStorageHdl storage, ComponentInstance self);
- static pascal ComponentResult DoComponentCanDo (short selector);
- static pascal ComponentResult DoComponentVersion (void);
- static pascal ComponentResult DoComponentRegister (void);
- static pascal ComponentResult DoCMInit (CMMStorageHdl storage, CMProfileHandle srcProfile, CMProfileHandle dstProfile);
- static pascal ComponentResult DoNCMInit (CMMStorageHdl storage, CMProfileRef srcProfile, CMProfileRef dstProfile);
- static pascal ComponentResult DoCMConcatInit (CMMStorageHdl storage, CMConcatProfileSet* profileSet);
- static pascal ComponentResult DoCMMatchColors (CMMStorageHdl storage, CMColor *colorBuf, unsigned long count);
- static pascal ComponentResult DoCMCheckColors (CMMStorageHdl storage, CMColor *colorBuf, unsigned long count, long *gamutResult);
- static pascal ComponentResult DoCMMatchBitmap (CMMStorageHdl storage, const CMBitmap * srcMap, CMBitmapCallBackUPP progressProc, void* refCon, CMBitmap* dstMap);
- static pascal ComponentResult DoCMCheckBitmap (CMMStorageHdl storage, const CMBitmap * srcMap, CMBitmapCallBackUPP progressProc, void* refCon, CMBitmap* chkMap);
- static ComponentResult CheckStorage (CMMStorageHdl storage);
- static void SimpleMatchAll (CMMMatchPtr pMatchInfo);
- static void SimpleMatchOne (CMMMatchPtr pMatchInfo, UInt16* chan);
-
-
- // RoutineDescriptors
- #if TARGET_CPU_PPC
- // RoutineDescriptors for Component functions
- INSTANTIATE_RD(DoComponentOpen);
- INSTANTIATE_RD(DoComponentClose);
- INSTANTIATE_RD(DoComponentCanDo);
- INSTANTIATE_RD(DoComponentVersion);
- INSTANTIATE_RD(DoComponentRegister);
- INSTANTIATE_RD(DoCMInit);
- INSTANTIATE_RD(DoNCMInit);
- INSTANTIATE_RD(DoCMConcatInit);
- INSTANTIATE_RD(DoCMMatchColors);
- INSTANTIATE_RD(DoCMCheckColors);
- INSTANTIATE_RD(DoCMMatchBitmap);
- INSTANTIATE_RD(DoCMCheckBitmap);
-
- // PowerPC main Component entry point
- RoutineDescriptor mainRD = BUILD_ROUTINE_DESCRIPTOR(uppComponentRoutineProcInfo, main);
- // ProcInfoType __procinfo = uppComponentRoutineProcInfo;
- #endif
-
-
- #if TARGET_CPU_68K
- #pragma code68020 off // this functions must run on all Macs
- #endif
-
- /* ______________________________________________________________________
-
- ComponentResult
-
- Abstract:
- main entry point to CMM Component
-
- Params:
- params (in) Parameters in form used by Component Manager
- storage (in) Handle to memory to be used by CMM
-
- Return:
- noErr If successful
- Otherwise System or ColorSync result code
-
- _____________________________________________________________________ */
-
-
- pascal ComponentResult
- main (ComponentParameters *params, Handle storage)
- {
- ComponentResult result = noErr; /* Init for error handling */
- short message;
-
- message = (*params).what;
-
- /* Selectors < 0 for Component Manager functions */
- if (message < 0)
- {
- switch (message)
- {
- case kComponentOpenSelect :
- result = CCF(params, DoComponentOpen);
- break;
-
- case kComponentCloseSelect :
- result = CCFWS(storage, params, DoComponentClose);
- break;
-
- case kComponentCanDoSelect :
- result = CCF(params, DoComponentCanDo);
- break;
-
- case kComponentVersionSelect :
- result = CCF(params, DoComponentVersion);
- break;
-
- case kComponentRegisterSelect :
- result = CCF(params, DoComponentRegister);
- break;
-
- default :
- result = noErr;
- break;
- }
- }
- else /* Selectors >= 0 for CMM functions */
- {
- switch (message)
- {
- case kCMMInit :
- result = CCFWS(storage, params, DoCMInit);
- break;
-
- case kNCMMInit :
- result = CCFWS(storage, params, DoNCMInit);
- break;
-
- case kCMMConcatInit :
- result = CCFWS(storage, params, DoCMConcatInit);
- break;
-
- case kCMMMatchColors :
- result = CCFWS(storage, params, DoCMMatchColors);
- break;
-
- case kCMMCheckColors :
- result = CCFWS(storage, params, DoCMCheckColors);
- break;
-
- case kCMMMatchBitmap :
- result = CCFWS(storage, params, DoCMMatchBitmap);
- break;
-
- case kCMMCheckBitmap :
- result = CCFWS(storage, params, DoCMCheckBitmap);
- break;
-
- default :
- result = unimpErr;
- break;
- }
- }
- return result ;
- }
-
-
- static pascal ComponentResult
- DoComponentOpen (ComponentInstance self)
- {
- ComponentResult result = noErr; /* Init for error handling */
- CMMStorageHdl h;
-
- h = (CMMStorageHdl) NewHandleClear(sizeof(CMMStorageRec));
- if (h == nil)
- result = MemError();
-
- if (result == noErr)
- {
- (**h).ci = self;
- SetComponentInstanceStorage(self, (Handle) h);
- }
-
- return result ;
- }
-
-
- static pascal
- ComponentResult
- DoComponentClose(CMMStorageHdl storage, ComponentInstance self)
- {
- ComponentResult result = noErr; /* Init for error handling */
-
- if (storage != nil)
- DisposeHandle((Handle)storage);
-
- return result ;
- }
-
- static pascal
- ComponentResult
- DoComponentRegister(void)
- {
- ComponentResult result = noErr; /* Init for error handling */
- long gestaltCPU;
- long gestaltSys;
- long gestaltQD;
-
- // Default -- don't register
- result = 1;
-
- // We require 68020 processor and 32-Bit Color QD 1.2
- // gestalt68020 is returned for gestaltProcessorType on PowerPC
- if ((Gestalt(gestaltProcessorType, &gestaltCPU) == noErr) && (gestaltCPU >= gestalt68020) &&
- (Gestalt(gestaltSystemVersion, &gestaltSys) == noErr) && (gestaltSys >= 0x0700) &&
- (Gestalt(gestaltQuickdrawVersion, &gestaltQD) == noErr) && (gestaltQD >= gestalt32BitQD12))
- {
- // OK to register
- result = 0;
- }
-
- return result ;
- }
-
-
- #if TARGET_CPU_68K
- #pragma code68020 reset
- #endif
-
-
- static pascal
- ComponentResult
- DoComponentCanDo(short selector)
- {
- ComponentResult result = noErr; /* Init for error handling */
-
- switch (selector)
- {
- /* Component Manager functions */
- case kComponentOpenSelect: // -1
- case kComponentCloseSelect: // -2
- case kComponentCanDoSelect: // -3
- case kComponentVersionSelect: // -4
- case kComponentRegisterSelect: // -5
- result = true;
- break;
-
- /* Supported CMM functions */
- case kCMMInit: // 0
- case kNCMMInit: // 6
- case kCMMMatchColors: // 1
- case kCMMCheckColors: // 2
- case kCMMConcatInit: // 7
- case kCMMMatchBitmap: // 9
- case kCMMCheckBitmap: // 10
- result = true;
- break;
-
- /* Unsupported CMM functions */
- case kCMMMatchPixMap: // 3
- case kCMMCheckPixMap: // 4
- case kCMMConcatenateProfiles: // 5
- case kCMMValidateProfile: // 8
- case kCMMGetPS2ColorSpace: // 11
- case kCMMGetPS2ColorRenderingIntent: // 12
- case kCMMGetPS2ColorRendering: // 13
- case kCMMFlattenProfile: // 14
- case kCMMUnflattenProfile: // 15
- case kCMMNewLinkProfile: // 16
- case kCMMGetPS2ColorRenderingVMSize: // 17
- result = false;
- break;
-
- default:
- result = false;
- break;
- }
-
- return result ;
- }
-
-
- static pascal
- ComponentResult
- DoComponentVersion(void)
- {
- return CMMVersion;
- }
-
-
- static pascal
- ComponentResult
- DoCMInit(CMMStorageHdl storage, CMProfileHandle srcProfile, CMProfileHandle dstProfile)
- {
- // Check params
- if ((srcProfile == nil) || (dstProfile == nil))
- return paramErr;
-
- (**storage).srcSpace = (**srcProfile).header.dataType;
- (**storage).srcClass = (**srcProfile).header.deviceType;
-
- (**storage).dstSpace = (**dstProfile).header.dataType;
- (**storage).dstClass = (**dstProfile).header.deviceType;
-
- return CheckStorage(storage);
- }
-
-
- typedef struct CMConcatProfileSet2 {
- unsigned short keyIndex; /* Zero-based */
- unsigned short count; /* Min 1, Max 2 */
- CMProfileRef profileSet[2]; /* Fixed. Source and Dest */
- } CMConcatProfileSet2;
-
- static pascal
- ComponentResult
- DoNCMInit (CMMStorageHdl storage, CMProfileRef srcProfile, CMProfileRef dstProfile)
- {
- CMConcatProfileSet2 set;
-
- set.keyIndex = 0;
- set.count = 2;
- set.profileSet[0] = srcProfile;
- set.profileSet[1] = dstProfile;
-
- return DoCMConcatInit(storage, (CMConcatProfileSet*)&set);
- }
-
-
- static pascal
- ComponentResult
- DoCMConcatInit (CMMStorageHdl storage, CMConcatProfileSet* profileSet)
- {
- ComponentResult result = noErr; /* Init for error handling */
- CMAppleProfileHeader srcHdr;
- CMAppleProfileHeader dstHdr;
- CMProfileRef srcProfile;
- CMProfileRef dstProfile;
-
- // Check params
- if (profileSet==nil)
- return paramErr;
-
- srcProfile = profileSet->profileSet[0];
- dstProfile = profileSet->profileSet[profileSet->count-1];
- if ((srcProfile == nil) || (dstProfile == nil))
- return paramErr;
-
- if (result == noErr)
- result = CMGetProfileHeader(srcProfile, &srcHdr);
-
- if (result == noErr)
- result = CMGetProfileHeader(dstProfile, &dstHdr);
-
- if (result == noErr)
- {
- (**storage).srcSpace = srcHdr.cm2.dataColorSpace;
- (**storage).srcClass = srcHdr.cm2.profileClass;
-
- (**storage).dstSpace = dstHdr.cm2.dataColorSpace;
- (**storage).dstClass = dstHdr.cm2.profileClass;
-
- result = CheckStorage(storage);
- }
-
- return result ;
- }
-
-
-
- static pascal
- ComponentResult
- DoCMMatchColors (CMMStorageHdl storage, CMColor *colorBuf, unsigned long count)
- {
- CMMMatchRec matchInfo;
-
- matchInfo.height = count;
- matchInfo.width = 1;
- matchInfo.srcSpace = (**storage).srcSpace;
- matchInfo.srcBuf[0] = ((UInt8*)colorBuf) + 0;
- matchInfo.srcBuf[1] = ((UInt8*)colorBuf) + 2;
- matchInfo.srcBuf[2] = ((UInt8*)colorBuf) + 4;
- matchInfo.srcBuf[3] = ((UInt8*)colorBuf) + 6;
- matchInfo.srcChanBits = 16;
- matchInfo.srcRowBytes = sizeof(CMColor);
- matchInfo.srcColBytes = sizeof(CMColor);
- matchInfo.dstSpace = (**storage).dstSpace;
- matchInfo.dstBuf[0] = ((UInt8*)colorBuf) + 0;
- matchInfo.dstBuf[1] = ((UInt8*)colorBuf) + 2;
- matchInfo.dstBuf[2] = ((UInt8*)colorBuf) + 4;
- matchInfo.dstBuf[3] = ((UInt8*)colorBuf) + 6;
- matchInfo.dstChanBits = 16;
- matchInfo.dstRowBytes = sizeof(CMColor);
- matchInfo.dstColBytes = sizeof(CMColor);
-
- SimpleMatchAll(&matchInfo);
-
- return noErr;
- }
-
-
- static pascal
- ComponentResult
- DoCMCheckColors (CMMStorageHdl storage, CMColor *colorBuf, unsigned long count, long* gamutResult)
- {
- #pragma unused (storage, colorBuf)
-
- unsigned long longCount;
-
- /* Everything is in gamut. This is just sample code. */
-
- longCount = (count + 31) / 32;
-
- while (longCount--)
- *gamutResult++ = 0xFFFFFFFF;
-
- return noErr;
- }
-
-
- static pascal
- ComponentResult
- DoCMMatchBitmap (CMMStorageHdl storage, const CMBitmap * srcMap,
- CMBitmapCallBackUPP progressProc, void * refCon,
- CMBitmap* dstMap)
- {
- #pragma unused (progressProc, refCon)
-
- CMMMatchRec matchInfo;
-
- // Check params
- if (srcMap==nil || dstMap==nil)
- return paramErr;
-
- matchInfo.height = srcMap->height;
- matchInfo.width = srcMap->width;
- matchInfo.srcRowBytes = srcMap->rowBytes;
- matchInfo.dstRowBytes = dstMap->rowBytes;
-
- switch (srcMap->space)
- {
- case cmRGB24Space:
- matchInfo.srcSpace = cmRGBData;
- matchInfo.srcBuf[0] = (UInt8*)srcMap->image + 0;
- matchInfo.srcBuf[1] = (UInt8*)srcMap->image + 1;
- matchInfo.srcBuf[2] = (UInt8*)srcMap->image + 2;
- matchInfo.srcBuf[3] = nil;
- matchInfo.srcChanBits = 8;
- matchInfo.srcColBytes = 3;
- break;
-
- case cmRGB32Space:
- matchInfo.srcSpace = cmRGBData;
- matchInfo.srcBuf[0] = (UInt8*)srcMap->image + 1;
- matchInfo.srcBuf[1] = (UInt8*)srcMap->image + 2;
- matchInfo.srcBuf[2] = (UInt8*)srcMap->image + 3;
- matchInfo.srcBuf[3] = nil;
- matchInfo.srcChanBits = 8;
- matchInfo.srcColBytes = 4;
- break;
-
- case cmRGB48Space:
- matchInfo.srcSpace = cmRGBData;
- matchInfo.srcBuf[0] = (UInt8*)srcMap->image + 0;
- matchInfo.srcBuf[1] = (UInt8*)srcMap->image + 2;
- matchInfo.srcBuf[2] = (UInt8*)srcMap->image + 4;
- matchInfo.srcBuf[3] = nil;
- matchInfo.srcChanBits = 16;
- matchInfo.srcColBytes = 6;
- break;
-
- case cmCMYK32Space:
- matchInfo.srcSpace = cmCMYKData;
- matchInfo.srcBuf[0] = (UInt8*)srcMap->image + 0;
- matchInfo.srcBuf[1] = (UInt8*)srcMap->image + 1;
- matchInfo.srcBuf[2] = (UInt8*)srcMap->image + 2;
- matchInfo.srcBuf[3] = (UInt8*)srcMap->image + 3;
- matchInfo.srcChanBits = 8;
- matchInfo.srcColBytes = 4;
- break;
-
- case cmCMYK64Space:
- matchInfo.srcSpace = cmCMYKData;
- matchInfo.srcBuf[0] = (UInt8*)srcMap->image + 0;
- matchInfo.srcBuf[1] = (UInt8*)srcMap->image + 2;
- matchInfo.srcBuf[2] = (UInt8*)srcMap->image + 4;
- matchInfo.srcBuf[3] = (UInt8*)srcMap->image + 6;
- matchInfo.srcChanBits = 16;
- matchInfo.srcColBytes = 8;
- break;
-
- default:
- return cmInvalidSrcMap;
- break;
- }
-
-
- switch (dstMap->space)
- {
- case cmRGB24Space:
- matchInfo.dstSpace = cmRGBData;
- matchInfo.dstBuf[0] = (UInt8*)dstMap->image + 0;
- matchInfo.dstBuf[1] = (UInt8*)dstMap->image + 1;
- matchInfo.dstBuf[2] = (UInt8*)dstMap->image + 2;
- matchInfo.dstBuf[3] = nil;
- matchInfo.dstChanBits = 8;
- matchInfo.dstColBytes = 3;
- break;
-
- case cmRGB32Space:
- matchInfo.dstSpace = cmRGBData;
- matchInfo.dstBuf[0] = (UInt8*)dstMap->image + 1;
- matchInfo.dstBuf[1] = (UInt8*)dstMap->image + 2;
- matchInfo.dstBuf[2] = (UInt8*)dstMap->image + 3;
- matchInfo.dstBuf[3] = nil;
- matchInfo.dstChanBits = 8;
- matchInfo.dstColBytes = 4;
- break;
-
- case cmRGB48Space:
- matchInfo.dstSpace = cmRGBData;
- matchInfo.dstBuf[0] = (UInt8*)dstMap->image + 0;
- matchInfo.dstBuf[1] = (UInt8*)dstMap->image + 2;
- matchInfo.dstBuf[2] = (UInt8*)dstMap->image + 4;
- matchInfo.dstBuf[3] = nil;
- matchInfo.dstChanBits = 16;
- matchInfo.dstColBytes = 6;
- break;
-
- case cmCMYK32Space:
- matchInfo.dstSpace = cmCMYKData;
- matchInfo.dstBuf[0] = (UInt8*)dstMap->image + 0;
- matchInfo.dstBuf[1] = (UInt8*)dstMap->image + 1;
- matchInfo.dstBuf[2] = (UInt8*)dstMap->image + 2;
- matchInfo.dstBuf[3] = (UInt8*)dstMap->image + 3;
- matchInfo.dstChanBits = 8;
- matchInfo.dstColBytes = 4;
- break;
-
- case cmCMYK64Space:
- matchInfo.dstSpace = cmCMYKData;
- matchInfo.dstBuf[0] = (UInt8*)dstMap->image + 0;
- matchInfo.dstBuf[1] = (UInt8*)dstMap->image + 2;
- matchInfo.dstBuf[2] = (UInt8*)dstMap->image + 4;
- matchInfo.dstBuf[3] = (UInt8*)dstMap->image + 6;
- matchInfo.dstChanBits = 16;
- matchInfo.dstColBytes = 8;
- break;
-
- default:
- return cmInvalidSrcMap;
- break;
- }
-
-
- if ((**storage).srcSpace != matchInfo.srcSpace)
- return cmInvalidSrcMap;
-
-
- if ((**storage).dstSpace != matchInfo.dstSpace)
- return cmInvalidDstMap;
-
- SimpleMatchAll(&matchInfo);
-
- return noErr;
- }
-
-
- static pascal
- ComponentResult
- DoCMCheckBitmap (CMMStorageHdl storage, const CMBitmap * srcMap,
- CMBitmapCallBackUPP progressProc, void * refCon,
- CMBitmap* chkMap)
- {
- #pragma unused (storage, srcMap, progressProc, refCon, chkMap)
- return paramErr;
- }
-
-
- static
- ComponentResult
- CheckStorage (CMMStorageHdl storage)
- {
- if (((**storage).srcSpace != cmRGBData) &&
- ((**storage).srcSpace != cmCMYKData))
- return cmInvalidProfile;
-
- if (((**storage).dstSpace != cmRGBData) &&
- ((**storage).dstSpace != cmCMYKData))
- return cmInvalidProfile;
-
- return noErr;
- }
-
-
- static
- void
- DebugColor4( UInt16* color)
- {
- Str255 s = "\p 0xXXXX, 0xXXXX, 0xXXXX, 0xXXXX ";
- UInt8* c = &(s[4]);
- int i;
- int v;
-
- for (i=0; i<4; i++)
- {
- v = (((*color)>>12) & 0x000F); *c++ = (v<10) ? (v+'0') : (v+'A'-10);
- v = (((*color)>>8) & 0x000F); *c++ = (v<10) ? (v+'0') : (v+'A'-10);
- v = (((*color)>>4) & 0x000F); *c++ = (v<10) ? (v+'0') : (v+'A'-10);
- v = (((*color)) & 0x000F); *c++ = (v<10) ? (v+'0') : (v+'A'-10);
- c += 4;
- color++;
- }
- DebugStr(s);
- }
-
-
- //
- // Simple conversion of a bunch or colors. This is just sample code.
- //
- static
- void
- SimpleMatchAll (CMMMatchPtr pMatchInfo)
- {
- UInt32 r,c;
- UInt16 chan[4];
- UInt8** sBuf;
- UInt8** dBuf;
-
- sBuf = pMatchInfo->srcBuf;
- dBuf = pMatchInfo->dstBuf;
-
- for (r=0; r < pMatchInfo->height; r++)
- {
- for (c=0; c < pMatchInfo->width; c++)
- {
- // read color in from source buffer
- if (pMatchInfo->srcChanBits==16)
- {
- if (sBuf[0]) chan[0] = *(UInt16*)(sBuf[0] + (r * pMatchInfo->srcRowBytes) + (c * pMatchInfo->srcColBytes));
- if (sBuf[1]) chan[1] = *(UInt16*)(sBuf[1] + (r * pMatchInfo->srcRowBytes) + (c * pMatchInfo->srcColBytes));
- if (sBuf[2]) chan[2] = *(UInt16*)(sBuf[2] + (r * pMatchInfo->srcRowBytes) + (c * pMatchInfo->srcColBytes));
- if (sBuf[3]) chan[3] = *(UInt16*)(sBuf[3] + (r * pMatchInfo->srcRowBytes) + (c * pMatchInfo->srcColBytes));
- }
- else
- {
- if (sBuf[0]) chan[0] = *(UInt8*)(sBuf[0] + (r * pMatchInfo->srcRowBytes) + (c * pMatchInfo->srcColBytes));
- if (sBuf[1]) chan[1] = *(UInt8*)(sBuf[1] + (r * pMatchInfo->srcRowBytes) + (c * pMatchInfo->srcColBytes));
- if (sBuf[2]) chan[2] = *(UInt8*)(sBuf[2] + (r * pMatchInfo->srcRowBytes) + (c * pMatchInfo->srcColBytes));
- if (sBuf[3]) chan[3] = *(UInt8*)(sBuf[3] + (r * pMatchInfo->srcRowBytes) + (c * pMatchInfo->srcColBytes));
- chan[0] = (chan[0] << 8) | chan[0];
- chan[1] = (chan[1] << 8) | chan[1];
- chan[2] = (chan[2] << 8) | chan[2];
- chan[3] = (chan[3] << 8) | chan[3];
- }
-
- // DebugColor4(chan);
-
- // Match the color
- SimpleMatchOne(pMatchInfo, chan);
-
- // DebugColor4(chan);
-
- // Write color to destination buffer
- if (pMatchInfo->dstChanBits==16)
- {
- if (dBuf[0]) *(UInt16*)(dBuf[0] + (r * pMatchInfo->dstRowBytes) + (c * pMatchInfo->dstColBytes)) = chan[0];
- if (dBuf[1]) *(UInt16*)(dBuf[1] + (r * pMatchInfo->dstRowBytes) + (c * pMatchInfo->dstColBytes)) = chan[1];
- if (dBuf[2]) *(UInt16*)(dBuf[2] + (r * pMatchInfo->dstRowBytes) + (c * pMatchInfo->dstColBytes)) = chan[2];
- if (dBuf[3]) *(UInt16*)(dBuf[3] + (r * pMatchInfo->dstRowBytes) + (c * pMatchInfo->dstColBytes)) = chan[3];
- }
- else
- {
- if (dBuf[0]) *(UInt8*)(dBuf[0] + (r * pMatchInfo->dstRowBytes) + (c * pMatchInfo->dstColBytes)) = chan[0] >> 8;
- if (dBuf[1]) *(UInt8*)(dBuf[1] + (r * pMatchInfo->dstRowBytes) + (c * pMatchInfo->dstColBytes)) = chan[1] >> 8;
- if (dBuf[2]) *(UInt8*)(dBuf[2] + (r * pMatchInfo->dstRowBytes) + (c * pMatchInfo->dstColBytes)) = chan[2] >> 8;
- if (dBuf[3]) *(UInt8*)(dBuf[3] + (r * pMatchInfo->dstRowBytes) + (c * pMatchInfo->dstColBytes)) = chan[3] >> 8;
- }
- }
- }
- }
-
-
- //
- // Simple conversion of one color with 16 bits-per-channel
- //
- static
- void
- SimpleMatchOne (CMMMatchPtr pMatchInfo, UInt16* chan)
- {
- if (pMatchInfo->srcSpace != pMatchInfo->dstSpace)
- {
- if ((pMatchInfo->srcSpace == cmRGBData) && (pMatchInfo->dstSpace == cmCMYKData))
- {
- chan[0] = 0xFFFF - chan[0];
- chan[1] = 0xFFFF - chan[1];
- chan[2] = 0xFFFF - chan[2];
- chan[3] = (chan[0] < chan[1]) ?
- ( (chan[0] < chan[2]) ? (chan[0]) : (chan[2]) ) :
- ( (chan[1] < chan[2]) ? (chan[1]) : (chan[2]) );
- chan[0] -= chan[3];
- chan[1] -= chan[3];
- chan[2] -= chan[3];
- }
-
- if ((pMatchInfo->srcSpace == cmCMYKData) && (pMatchInfo->dstSpace == cmRGBData))
- {
- chan[0] = 0xFFFF - chan[0];
- chan[1] = 0xFFFF - chan[1];
- chan[2] = 0xFFFF - chan[2];
- chan[0] = (chan[0] > chan[3]) ? (chan[0] - chan[3]) : 0;
- chan[1] = (chan[1] > chan[3]) ? (chan[1] - chan[3]) : 0;
- chan[2] = (chan[2] > chan[3]) ? (chan[2] - chan[3]) : 0;
- chan[3] = 0;
- }
- }
- }