test: icm32.c Source File

Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

# icm32.c

Go to the documentation of this file.

    00001 /*
    00002         File:           MsLinoCMM.c
    00003
    00004         Contains:
    00005                 Interface to MS ICM
    00006         Written by:     U. J. Krabbenhoeft
    00007
    00008         Copyright:      © 1993-1997 by Heidelberger Druckmaschinen AG, all rights reserved.
    00009
    00010         Version:
    00011 */
    00012
    00013 #include "Windef.h"
    00014 #include "WinGdi.h"
    00015 #include <wtypes.h>
    00016 #include <winbase.h>
    00017 #include <WindowsX.h>
    00018 #include "ICM.h"
    00019
    00020 #ifndef LHGeneralIncs_h
    00021 #include "General.h"
    00022 #endif
    00023
    00024 #ifndef MSNewMemProfile_h
    00025 #include "MemProf.h"
    00026 #endif
    00027
    00028 #define CMM_WIN_VERSION         0
    00029 #define CMM_IDENT                       1
    00030 #define CMM_DRIVER_LEVEL        2
    00031 #define CMM_DLL_VERSION         3
    00032 #define CMM_VERSION                     4
    00033 #define CMS_LEVEL_1                     1
    00034
    00035 typedef HANDLE  HCMTRANSFORM;
    00036 typedef LPVOID  LPDEVCHARACTER;
    00037 typedef HANDLE *LPHPROFILE;
    00038 typedef LPVOID  LPARGBQUAD;
    00039 typedef COLORREF FAR *LPCOLORREF;
    00040
    00041 #ifdef _DEBUG
    00042 //#define WRITE_PROFILE
    00043 #endif
    00044 /* ______________________________________________________________________
    00045                         static section for holding the CW pointers
    00046    _____________________________________________________________________ */
    00047
    00048 long IndexTransform=0;
    00049 HCMTRANSFORM TheTransform[1000] = {0};
    00050
    00051 CRITICAL_SECTION GlobalCriticalSection;         /* for multithreaded dll */
    00052
    00053 /* ______________________________________________________________________ */
    00054
    00055 /* ______________________________________________________________________
    00056
    00057 BOOL WINAPI DllMain (   HINSTANCE hinstDLL,
    00058                                                 DWORD fdwReason,
    00059                                                 LPVOID lpvReserved )
    00060
    00061         Abstract:
    00062                 DLL Entrypoint
    00063
    00064         Params:
    00065                 standard
    00066
    00067         Return:
    00068                 TRUE
    00069
    00070    _____________________________________________________________________ */
    00071 BOOL WINAPI DllMain (   HINSTANCE hinstDLL,
    00072                                                 DWORD fdwReason,
    00073                                                 LPVOID lpvReserved )
    00074 {
    00075 switch (fdwReason)
    00076    {
    00077    case DLL_PROCESS_ATTACH:
    00078       DisableThreadLibraryCalls(hinstDLL);
    00079           InitializeCriticalSection(&GlobalCriticalSection);
    00080       break;
    00081    case DLL_PROCESS_DETACH:
    00082       DeleteCriticalSection(&GlobalCriticalSection);
    00083       break;
    00084    }
    00085 return TRUE;
    00086 }
    00087
    00088 #define DllExport       __declspec( dllexport )
    00089
    00090 HCMTRANSFORM  WINAPI CMCreateMultiProfileTransform(     LPHPROFILE      lpahProfiles,
    00091                                                                                                         DWORD           nProfiles,
    00092                                                                                                         DWORD           *aIntentArr,
    00093                                                                                                         DWORD           nIntents,
    00094                                                                                                         DWORD           dwFlags );
    00095 long FillProfileFromLog(        LPLOGCOLORSPACEA        lpColorSpace,
    00096                                                         PPROFILE                        theProf );
    00097 long FillProfileFromLogW(       LPLOGCOLORSPACEW        lpColorSpace,
    00098                                                         PPROFILE                        theProf );
    00099 BOOL  WINAPI CMCreateProfile(   LPLOGCOLORSPACEA        lpColorSpace,
    00100                                                                 LPDEVCHARACTER          *lpProfileData );
    00101 CMWorldRef StoreTransform( CMWorldRef aRef );
    00102 CMBitmapColorSpace CMGetDataColorSpace( BMFORMAT c, long *pixelSize );
    00103 HCMTRANSFORM  WINAPI CMGetTransform( HCMTRANSFORM       hcmTransform );
    00104 long  CMCreateMultiProfileTransformInternal(            CMWorldRef      *cw,
    00105                                                                                                         LPHPROFILE      lpahProfiles,
    00106                                                                                                         DWORD           nProfiles,
    00107                                                                                                         DWORD           *aIntentArr,
    00108                                                                                                         DWORD           nIntents,
    00109                                                                                                         DWORD           dwFlags,
    00110                                                                                                         DWORD           dwCreateLink );
    00111 /* ______________________________________________________________________
    00112
    00113 DWORD WINAPI CMGetInfo( DWORD dwInfo );
    00114
    00115 Abstract:
    00116         The CMGetInfo function retrieves various information about the ICM.
    00117
    00118 Parameter               Description
    00119
    00120         dwInfo          Values that can have the following meaning:
    00121
    00122         Type    Meaning
    00123
    00124         CMS_VERSION     Retrieves the version of Windows supported.
    00125         CMS_IDENT       Retrieves the identifier of the ICMDLL.
    00126         CMS_DRIVER_LEVEL        Retrieves the support level of a device driver.
    00127
    00128 Returns
    00129         CMGetInfo returns zero if an invalid parameter is passed in. If successful it returns a value that depends on the information requested.
    00130         For CMS_VERSION CMGetInfo retrieves the version of Windows ICM interface supported by this module. For Windows 95 this should be 4.0, represented as 0x00040000.
    00131         For CMS_IDENT CMGetInfo retrieves the identifier of the ICMDLL. This is the same as the ICC color profile header identifier.
    00132         For CMS_DRIVER_LEVEL CMGetInfo retrieves the supported level of the device driver. ICMDLLs should return CMS_LEVEL_1. The values have been defined in a previous section.
    00133    _____________________________________________________________________ */
    00134 DWORD WINAPI CMGetInfo( DWORD dwInfo )
    00135 {
    00136         DWORD ret = 0;
    00137         switch( dwInfo ){
    00138         case CMM_VERSION:
    00139                 ret = 0x00050000;
    00140                 break;
    00141         case CMM_WIN_VERSION:
    00142                 ret = 0x00040000;
    00143                 break;
    00144         case CMM_DLL_VERSION:
    00145                 ret = 0x00010000;
    00146                 break;
    00147         case CMM_IDENT:
    00148                 ret = 'Win ';
    00149                 break;
    00150         case CMM_LOGOICON:
    00151                 ret = 100;
    00152                 break;
    00153         case CMM_DESCRIPTION:
    00154                 ret = 100;
    00155                 break;
    00156         case CMM_DRIVER_LEVEL:
    00157                 ret = CMS_LEVEL_1;
    00158                 break;
    00159         default:
    00160                 ret = 0;
    00161                 break;
    00162         }
    00163         return  ret;
    00164 }
    00165
    00166
    00167 long CMCreateTransformExtInternal(      CMWorldRef      *cwOut,
    00168                                                                         UINT32          dwFlags,
    00169                                                                         UINT32          lcsIntent,
    00170                                                                         HPROFILE        aProf,
    00171                                                                         LPBYTE          ptDeRef,
    00172                                                                         LPBYTE          pdDeRef )
    00173 {
    00174         CMWorldRef cw=0;
    00175         CMWorldRef cw2=0;
    00176         long err;
    00177         HPROFILE saveProf;
    00178         HPROFILE hArray[3];
    00179         UINT32 aIntent[3];
    00180         UINT32 aUINT32,count;
    00181         CMMModelPtr theModelPtr;
    00182
    00183         *cwOut = 0;
    00184         aIntent[0] = icRelativeColorimetric;
    00185         switch( lcsIntent ){
    00186           case LCS_GM_BUSINESS:
    00187                 aIntent[1] = icSaturation;
    00188                 break;
    00189           case LCS_GM_GRAPHICS:
    00190                 aIntent[1] = icRelativeColorimetric;
    00191                 break;
    00192           case LCS_GM_ABS_COLORIMETRIC:
    00193                 aIntent[1] = icAbsoluteColorimetric;
    00194                 break;
    00195           default:
    00196                 aIntent[1] = icPerceptual;
    00197                 break;
    00198         }
    00199         if( ptDeRef == 0 ){
    00200                 count = 2;
    00201                 hArray[0] =  aProf;
    00202                 hArray[1] =  pdDeRef;
    00203         }
    00204         else{
    00205                 count = 3;
    00206                 hArray[0] =  aProf;
    00207                 hArray[1] =  ptDeRef;
    00208                 hArray[2] =  pdDeRef;
    00209                 if( dwFlags & USE_RELATIVE_COLORIMETRIC )aIntent[2] = INTENT_RELATIVE_COLORIMETRIC;
    00210                 else aIntent[2] = INTENT_ABSOLUTE_COLORIMETRIC;
    00211         }
    00212
    00213         err = CMCreateMultiProfileTransformInternal( &cw, hArray, count, aIntent, count, dwFlags, 0 );
    00214         if( err ){
    00215                 goto CleanupAndExit;
    00216         }
    00217         if( dwFlags & 0x80000000 ){                             /* this is for the backward transform */
    00218                 count--;
    00219                 saveProf = hArray[count];
    00220                 hArray[count] =  hArray[0];
    00221                 hArray[0] =  saveProf;
    00222                 aUINT32 = aIntent[count];
    00223                 aIntent[count] = aIntent[0];
    00224                 aIntent[0] = aUINT32;
    00225
    00226                 count++;
    00227                 err = CMCreateMultiProfileTransformInternal( &cw2, hArray, count, aIntent, count, dwFlags, 0 );
    00228                 if( err ){
    00229                         CWDisposeColorWorld( cw );      /* delete other cw */
    00230                         goto CleanupAndExit;
    00231                 }
    00232                 LOCK_DATA( cw );
    00233                 theModelPtr = (CMMModelPtr)(DATA_2_PTR( cw ));
    00234                 theModelPtr->pBackwardTransform = cw2;
    00235                 UNLOCK_DATA( aTrans );
    00236         }
    00237
    00238 CleanupAndExit:
    00239         CloseColorProfile( aProf );
    00240         if( err ){
    00241                 SetLastError( err );
    00242                 cw = (CMWorldRef)(ULONG_PTR)(err & 255);
    00243         }
    00244         else{
    00245                 cw = StoreTransform( cw );
    00246         }
    00247         *cwOut = cw;
    00248         return 0;
    00249 }
    00250 /* ______________________________________________________________________
    00251
    00252 HCMTRANSFORM  WINAPI CMCreateTransformExt(      LPLOGCOLORSPACEA        lpColorSpace,
    00253                                                                                         LPDEVCHARACTER          lpDevCharacter,
    00254                                                                                         LPDEVCHARACTER          lpTargetDevCharacter,
    00255                                                                                         UINT32                          dwFlags );
    00256
    00257 Abstract:
    00258         The CMCreateTransformExt function creates a color transform that
    00259         maps from an input LogColorSpace to an optional target to an
    00260         output device.
    00261
    00262 Parameter                                       Description
    00263         lpColorSpace                    Pointer to input color space. If lcsFilename is non-zero,
    00264                                                         it is a pointer to the memory mapped profile.
    00265         LpDevCharacter                  Pointer to memory mapped device profile
    00266         lpTargetDevCharacter    Pointer to memory mapped target profile
    00267         dwFlags                                 Specifies flags to control creation of the transform.
    00268                                                         It is up to the CMM to determine how best to use these flags.
    00269                                                         Set the high-order word to ENABLE_GAMUT_CHECKING if the transform
    00270                                                         will be used for gamut checking.
    00271                                                         The low-order WORD can have one of the following constant values:
    00272                                                         PROOF_MODE, NORMAL_MODE, BEST_MODE.
    00273                                                         Moving from PROOF_MODE to BEST_MODE, output quality generally improves and transform speed declines.
    00274
    00275 Returns
    00276         If the function is successful, it returns a color transform
    00277         in the range 256 to 65535. Otherwise it returns an error code
    00278         (return value < 255).
    00279
    00280   _____________________________________________________________________ */
    00281 void WriteProf( LPSTR name, icProfile *theProf, long currentSize );
    00282 HCMTRANSFORM  WINAPI CMCreateTransformExt(      LPLOGCOLORSPACEA        lpColorSpace,
    00283                                                                                         LPDEVCHARACTER          lpDevCharacter,
    00284                                                                                         LPDEVCHARACTER          lpTargetDevCharacter,
    00285                                                                                         DWORD                           dwFlags )
    00286 {
    00287         CMWorldRef cw=0;
    00288         long err;
    00289         LPBYTE pt,pd, ptDeRef, pdDeRef;
    00290         HPROFILE aProf;
    00291         PROFILE theProf;
    00292     BOOL   bWin95;
    00293     OSVERSIONINFO osvi;
    00294
    00295 #if 0                           /* Test for CMCreateProfile */
    00296         CMCreateProfile( lpColorSpace, &pt );
    00297         err = *(long *)pt;
    00298         SwapLong(&err);
    00299         WriteProf( "CMCreateProfile.icc", (icProfile *)pt, err );
    00300         GlobalFreePtr( pt );
    00301 #endif
    00302
    00303
    00304         err = FillProfileFromLog( lpColorSpace, &theProf );
    00305         if( err ){
    00306                 SetLastError( err );
    00307                 goto CleanupAndExit;
    00308         }
    00309         aProf = OpenColorProfile(&theProf, PROFILE_READ, FILE_SHARE_READ, OPEN_EXISTING );
    00310         if( !aProf ){
    00311                 err = GetLastError();
    00312                 goto CleanupAndExit;
    00313         }
    00314     osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
    00315     GetVersionEx(&osvi);
    00316     bWin95 = osvi.dwMajorVersion == 4 &&
    00317              osvi.dwMinorVersion == 0 &&
    00318              osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS;
    00319
    00320     if (bWin95)
    00321     {
    00322         PROFILE myProf;
    00323         DWORD   l;
    00324
    00325         //
    00326         // Handles are not provided below LCS structure, so create handles
    00327         //
    00328
    00329         myProf.dwType = PROFILE_MEMBUFFER;
    00330         myProf.pProfileData = lpDevCharacter;
    00331         l = *(DWORD *)(myProf.pProfileData);
    00332         myProf.cbDataSize = SwapLong(&l);
    00333         pdDeRef = OpenColorProfile(&myProf, PROFILE_READ, FILE_SHARE_READ, OPEN_EXISTING );
    00334         if( !pdDeRef ){
    00335                 err = GetLastError();
    00336                 goto CleanupAndExit;
    00337         }
    00338
    00339         ptDeRef = 0;
    00340         if (lpTargetDevCharacter)
    00341         {
    00342             myProf.dwType = PROFILE_MEMBUFFER;
    00343             myProf.pProfileData = lpTargetDevCharacter;
    00344             l = *(DWORD *)(myProf.pProfileData);
    00345             myProf.cbDataSize = SwapLong(&l);
    00346             ptDeRef = OpenColorProfile(&myProf, PROFILE_READ, FILE_SHARE_READ, OPEN_EXISTING );
    00347             if( !ptDeRef ){
    00348                     err = GetLastError();
    00349                     goto CleanupAndExit;
    00350             }
    00351         }
    00352     }
    00353     else
    00354     {
    00355                 pd = ((LPBYTE)lpColorSpace+sizeof(LOGCOLORSPACEA));
    00356                 pdDeRef= (LPBYTE)*(PULONG_PTR)pd;
    00357
    00358                 pt = ((LPBYTE)lpColorSpace+sizeof(LOGCOLORSPACEA)+sizeof(HPROFILE));
    00359                 ptDeRef= (LPBYTE)*(PULONG_PTR)pt;
    00360         }
    00361
    00362         err = CMCreateTransformExtInternal(     &cw, dwFlags,
    00363                                 lpColorSpace->lcsIntent, aProf, ptDeRef, pdDeRef );
    00364
    00365 CleanupAndExit:
    00366         if( lpColorSpace->lcsFilename[0] == 0 ){
    00367                 if( theProf.pProfileData )GlobalFreePtr( theProf.pProfileData );
    00368                 theProf.pProfileData = 0;
    00369         }
    00370     if (bWin95)
    00371     {
    00372         if (pdDeRef)
    00373         {
    00374             CloseColorProfile(pdDeRef);
    00375         }
    00376         if (ptDeRef)
    00377         {
    00378             CloseColorProfile(ptDeRef);
    00379         }
    00380     }
    00381         if( err ){
    00382                 return (HCMTRANSFORM)(ULONG_PTR)(err & 255);
    00383         }
    00384         return (HCMTRANSFORM)cw;
    00385 }
    00386
    00387 /* ______________________________________________________________________
    00388
    00389 HCMTRANSFORM  WINAPI CMCreateTransform(         LPLOGCOLORSPACEA        lpColorSpace,
    00390                                                                                         LPDEVCHARACTER          lpDevCharacter,
    00391                                                                                         LPDEVCHARACTER          lpTargetDevCharacter );
    00392
    00393 Abstract:
    00394         The CMCreateTransform function creates a color transform that
    00395         maps from an input LogColorSpace to an optional target to an
    00396         output device.
    00397
    00398 Parameter                                       Description
    00399         lpColorSpace                    Pointer to input color space. If lcsFilename is non-zero,
    00400                                                         it is a pointer to the memory mapped profile.
    00401         LpDevCharacter                  Pointer to memory mapped device profile
    00402         lpTargetDevCharacter    Pointer to memory mapped target profile
    00403
    00404 Returns
    00405         If the function is successful, it returns a color transform
    00406         in the range 256 to 65535. Otherwise it returns an error code
    00407         (return value < 255).
    00408
    00409   _____________________________________________________________________ */
    00410 HCMTRANSFORM  WINAPI CMCreateTransform  (       LPLOGCOLORSPACEA        lpColorSpace,
    00411                                                                                         LPDEVCHARACTER          lpDevCharacter,
    00412                                                                                         LPDEVCHARACTER          lpTargetDevCharacter )
    00413 {
    00414         return CMCreateTransformExt( lpColorSpace, lpDevCharacter, lpTargetDevCharacter, PROOF_MODE | ENABLE_GAMUT_CHECKING | 0x80000000 );
    00415 }
    00416 /* ______________________________________________________________________
    00417
    00418 HCMTRANSFORM  WINAPI CMCreateTransformExtW(     LPLOGCOLORSPACEW        lpColorSpace,
    00419                                                                                         LPDEVCHARACTER          lpDevCharacter,
    00420                                                                                         LPDEVCHARACTER          lpTargetDevCharacter,
    00421                                                                                         DWORD                           dwFlags );
    00422
    00423 Abstract:
    00424         The CMCreateTransformExtW function creates a color transform that
    00425         maps from an input LogColorSpace to an optional target to an
    00426         output device.
    00427
    00428 Parameter                                       Description
    00429         lpColorSpace                    Pointer to input color space. If lcsFilename is non-zero, it is a pointer to the memory mapped profile.
    00430         LpDevCharacter                  Pointer to memory mapped device profile
    00431         lpTargetDevCharacter    Pointer to memory mapped target profile
    00432         dwFlags                                 Specifies flags to control creation of the transform.
    00433                                                         It is up to the CMM to determine how best to use these flags.
    00434                                                         Set the high-order word to ENABLE_GAMUT_CHECKING if the transform
    00435                                                         will be used for gamut checking.
    00436                                                         The low-order WORD can have one of the following constant values:
    00437                                                         PROOF_MODE, NORMAL_MODE, BEST_MODE.
    00438                                                         Moving from PROOF_MODE to BEST_MODE, output quality generally improves and transform speed declines.
    00439
    00440 Returns
    00441         If the function is successful, it returns a color transform
    00442         in the range 256 to 65535. Otherwise it returns an error code
    00443         (return value < 255).
    00444
    00445    _____________________________________________________________________ */
    00446 HCMTRANSFORM  WINAPI CMCreateTransformExtW(     LPLOGCOLORSPACEW        lpColorSpace,
    00447                                                                                         LPDEVCHARACTER          lpDevCharacter,
    00448                                                                                         LPDEVCHARACTER          lpTargetDevCharacter,
    00449                                                                                         DWORD                           dwFlags )
    00450 {
    00451         CMWorldRef cw=0;
    00452         long err;
    00453         LPBYTE pt,pd, ptDeRef, pdDeRef;
    00454         HPROFILE aProf;
    00455         PROFILE theProf;
    00456
    00457         err = FillProfileFromLogW( lpColorSpace, &theProf );
    00458         if( err ){
    00459                 SetLastError( err );
    00460                 goto CleanupAndExit;
    00461         }
    00462         aProf = OpenColorProfileW(&theProf, PROFILE_READ, FILE_SHARE_READ, OPEN_EXISTING );
    00463         if( !aProf ){
    00464                 err = GetLastError();
    00465                 goto CleanupAndExit;
    00466         }
    00467         pd = ((LPBYTE)lpColorSpace+sizeof(LOGCOLORSPACEW));
    00468         pdDeRef= (LPBYTE)*(PULONG_PTR)pd;
    00469
    00470         pt = ((LPBYTE)lpColorSpace+sizeof(LOGCOLORSPACEW)+sizeof(HPROFILE));
    00471         ptDeRef= (LPBYTE)*(PULONG_PTR)pt;
    00472
    00473         err = CMCreateTransformExtInternal(     &cw, dwFlags,
    00474                                 lpColorSpace->lcsIntent, aProf, ptDeRef, pdDeRef );
    00475
    00476 CleanupAndExit:
    00477         if( lpColorSpace->lcsFilename[0] == 0 ){
    00478                 if( theProf.pProfileData )GlobalFreePtr( theProf.pProfileData );
    00479                 theProf.pProfileData = 0;
    00480         }
    00481         if( err ){
    00482                 return (HCMTRANSFORM)(ULONG_PTR)(err & 255);
    00483         }
    00484         return (HCMTRANSFORM)cw;
    00485 }
    00486
    00487 /* ______________________________________________________________________
    00488
    00489 HCMTRANSFORM  WINAPI CMCreateTransformW(        LPLOGCOLORSPACEW        lpColorSpace,
    00490                                                                                         LPDEVCHARACTER          lpDevCharacter,
    00491                                                                                         LPDEVCHARACTER          lpTargetDevCharacter );
    00492
    00493 Abstract:
    00494         The CMCreateTransformW function creates a color transform that
    00495         maps from an input LogColorSpace to an optional target to an
    00496         output device.
    00497
    00498 Parameter                                       Description
    00499         lpColorSpace                    Pointer to input color space. If lcsFilename is non-zero, it is a pointer to the memory mapped profile.
    00500         LpDevCharacter                  Pointer to memory mapped device profile
    00501         lpTargetDevCharacter    Pointer to memory mapped target profile
    00502
    00503 Returns
    00504         If the function is successful, it returns a color transform
    00505         in the range 256 to 65535. Otherwise it returns an error code
    00506         (return value < 255).
    00507
    00508    _____________________________________________________________________ */
    00509 HCMTRANSFORM  WINAPI CMCreateTransformW(        LPLOGCOLORSPACEW        lpColorSpace,
    00510                                                                                         LPDEVCHARACTER          lpDevCharacter,
    00511                                                                                         LPDEVCHARACTER          lpTargetDevCharacter )
    00512 {
    00513         return CMCreateTransformExtW( lpColorSpace, lpDevCharacter, lpTargetDevCharacter, PROOF_MODE | ENABLE_GAMUT_CHECKING );
    00514 }
    00515
    00516 long  CMCreateMultiProfileTransformInternal(            CMWorldRef      *cw,
    00517                                                                                                         LPHPROFILE      lpahProfiles,
    00518                                                                                                         DWORD           nProfiles,
    00519                                                                                                         DWORD           *aIntentArr,
    00520                                                                                                         DWORD           nIntents,
    00521                                                                                                         DWORD           dwFlags,
    00522                                                                                                         DWORD           dwCreateLink )
    00523 {
    00524         CMConcatProfileSet      *profileSet;
    00525         OSErr                           aOSErr;
    00526         DWORD                           i;
    00527         long                            err;
    00528         UINT32                          theFlags;
    00529         UINT32                          *arrIntents = 0;;
    00530
    00531         profileSet = (CMConcatProfileSet *)SmartNewPtrClear( sizeof (CMConcatProfileSet) + (nProfiles)* sizeof(CMProfileRef), &aOSErr );
    00532         if (aOSErr == 0 )
    00533         {
    00534                 profileSet->keyIndex = 0;
    00535                 profileSet->count = (unsigned short)nProfiles;
    00536                 for( i=0; i<nProfiles; i++)
    00537                         profileSet->profileSet[i] = (CMProfileRef)((DWORD *)(((PVOID *)lpahProfiles)[i]));
    00538         }
    00539         else return ERROR_NOT_ENOUGH_MEMORY;
    00540
    00541         switch( dwFlags & 0xffff ){
    00542                 case BEST_MODE:
    00543                         theFlags = cmBestMode;
    00544                         break;
    00545                 case PROOF_MODE:
    00546                         theFlags = cmDraftMode;
    00547                         break;
    00548                 default:
    00549                         theFlags = cmNormalMode;
    00550                         break;
    00551         }
    00552         if( ! (dwFlags & ENABLE_GAMUT_CHECKING) ){
    00553                 theFlags |= kCreateGamutLutMask;
    00554         }
    00555         if( dwFlags & USE_RELATIVE_COLORIMETRIC ){
    00556                 theFlags |= kUseRelColorimetric;
    00557         }
    00558         if( dwFlags & FAST_TRANSLATE ){
    00559                 theFlags |= kLookupOnlyMask;
    00560         }
    00561         if( nProfiles > 1 && nIntents == 1 ){
    00562                 arrIntents = (UINT32 *)SmartNewPtrClear( nProfiles * sizeof (UINT32), &aOSErr);
    00563                 if (aOSErr != 0 ){
    00564                         err = ERROR_NOT_ENOUGH_MEMORY;
    00565                         goto CleanupAndExit;
    00566                 }
    00567                 arrIntents[0] = icPerceptual;
    00568                 arrIntents[1] = aIntentArr[0];
    00569                 for( i=2; i<nProfiles; i++){
    00570                         arrIntents[i] = icAbsoluteColorimetric;
    00571                         if( dwFlags & kUseRelColorimetric ) arrIntents[i] = icRelativeColorimetric;
    00572                 }
    00573                 err = CWConcatColorWorld4MS( cw, profileSet, arrIntents, nProfiles, theFlags );
    00574                 arrIntents= (UINT32 *)DisposeIfPtr( (Ptr) arrIntents );
    00575         }
    00576         else{
    00577                 err = CWConcatColorWorld4MS( cw, profileSet, aIntentArr, nIntents, theFlags );
    00578         }
    00579 #ifdef WRITE_PROFILE
    00580         if( err == 0 ){
    00581                 err = MyNewDeviceLink( *cw, profileSet, "MyCreateTransform.pf" );
    00582                 //goto CleanupAndExit;
    00583         }
    00584 #endif
    00585 CleanupAndExit:
    00586         profileSet= (CMConcatProfileSet *)DisposeIfPtr( (Ptr) profileSet );
    00587         return err;
    00588 }
    00589
    00590 /* ______________________________________________________________________
    00591
    00592 HCMTRANSFORM  WINAPI CMCreateMultiProfileTransform(     LPHPROFILE      lpahProfiles,
    00593                                                                                                         DWORD           nProfiles,
    00594                                                                                                         UINT32          *aIntentArr,
    00595                                                                                                         UINT32          nIntents,
    00596                                                                                                         UINT32          dwFlags );
    00597
    00598 Abstract:
    00599         The CMCreateMultiProfileTransform function accepts
    00600         an array of profiles or a single device link profile
    00601         and creates a color transform.
    00602         This transform is a mapping from the color space specified
    00603         by the first profile to that of the second profile
    00604         and so on until the last one.
    00605
    00606 Parameter                       Description
    00607         lpahProfiles    Pointer to an array of profile handles
    00608         nProfiles               Number of profiles in the array
    00609         padwIntents             (in)            Points to an array of intent structures.
    00610                                                                 0 = default behavior ( intents out of profiles )
    00611
    00612         nIntents                (in)            Specifies the number of intents in the intent array.
    00613                                                                 Can be 1, or the same value as nProfiles.
    00614
    00615         dwFlags                 (in)            Specifies flags to control creation of the transform.
    00616                                                                 These flags are intended only as hints, and it is up to the CMM
    00617                                                                 to determine how best to use these flags.
    00618                                                                 Set the high-order word to ENABLE_GAMUT_CHECKING if the transform will be used
    00619                                                                 for gamut checking.
    00620                                                                 The low-order WORD can have one of the following constant values:
    00621                                                                 PROOF_MODE, NORMAL_MODE, BEST_MODE. Moving from PROOF_MODE to BEST_MODE,
    00622 Returns
    00623         If the function is successful, it returns a color transform.
    00624         Otherwise it returns an error code (return value < 255).
    00625    _____________________________________________________________________ */
    00626 HCMTRANSFORM  WINAPI CMCreateMultiProfileTransform(     LPHPROFILE      lpahProfiles,
    00627                                                                                                         DWORD           nProfiles,
    00628                                                                                                         DWORD           *aIntentArr,
    00629                                                                                                         DWORD           nIntents,
    00630                                                                                                         DWORD           dwFlags )
    00631 {
    00632         long                            err;
    00633         CMWorldRef                      cw;
    00634
    00635         err = CMCreateMultiProfileTransformInternal( &cw, lpahProfiles, nProfiles, aIntentArr, nIntents, dwFlags, 0 );
    00636         if( err ){
    00637                 SetLastError( err );
    00638                 return (HCMTRANSFORM)(ULONG_PTR)(err & 255);
    00639         }
    00640         cw = StoreTransform( cw );
    00641         return (HCMTRANSFORM)cw;
    00642 }
    00643
    00644 /* ______________________________________________________________________
    00645 BOOL  WINAPI CMDeleteTransform( HCMTRANSFORM    hcmTransform );
    00646
    00647 Abstract:
    00648         The CMDeleteTransform function deletes the given color transform,
    00649         and frees any memory associated with it.
    00650
    00651 Parameter                       Description
    00652         hcmTransform    Identifies the color transform
    00653
    00654 Returns
    00655         If the function is successful, the return value is nonzero.
    00656         Otherwise it is zero.
    00657    _____________________________________________________________________ */
    00658 BOOL  WINAPI CMDeleteTransform( HCMTRANSFORM    hcmTransform )
    00659 {
    00660         long actTransform = (long)(ULONG_PTR)hcmTransform - 256;
    00661         HCMTRANSFORM aTrans = NULL;
    00662         CMMModelPtr theModelPtr;
    00663         CMWorldRef theWorldRef;
    00664     BOOL bReturn = 0;
    00665
    00666         __try {
    00667                 EnterCriticalSection(&GlobalCriticalSection);
    00668                 if( actTransform < IndexTransform && actTransform >= 0 ){
    00669                         aTrans = TheTransform[actTransform];
    00670                         TheTransform[ actTransform ] = 0;
    00671                         if( actTransform == IndexTransform-1 )IndexTransform--;
    00672                         bReturn = 1;
    00673                 }
    00674         }
    00675         __finally{
    00676                 LeaveCriticalSection(&GlobalCriticalSection);
    00677
    00678                 LOCK_DATA( aTrans );
    00679                 theModelPtr = (CMMModelPtr)(DATA_2_PTR( aTrans ));
    00680                 theWorldRef = theModelPtr->pBackwardTransform;
    00681                 UNLOCK_DATA( aTrans );
    00682                 if( theWorldRef != 0 ){
    00683                         CWDisposeColorWorld( theWorldRef );
    00684                 }
    00685
    00686                 CWDisposeColorWorld( aTrans );
    00687         }
    00688     return bReturn;
    00689 }
    00690
    00691 /* ______________________________________________________________________
    00692 BOOL  WINAPI CMCreateProfile(   LPLOGCOLORSPACEA                lpColorSpace,
    00693                                                                 LPBYTE                                  *lpProfileData );
    00694
    00695 Abstract:
    00696         The CMCreateProfile function creates a display color profile
    00697         from a LogColorSpace structure.
    00698
    00699 Parameter                       Description
    00700         lpColorSpace    Pointer to color space. lcsFilename field will be NULL.
    00701         pProfileData    Points to a pointer to a buffer.
    00702                                         If successful the function allocates and fills this buffer.
    00703                                         It is then the calling application’s responsibility to
    00704                                         free this buffer with GlobalFreePtr( lpProfileData )
    00705                                         when it is no longer needed.
    00706
    00707 Returns
    00708         If the function is successful, it returns nonzero.
    00709         Otherwise it returns zero.
    00710
    00711    _____________________________________________________________________ */
    00712 BOOL  WINAPI CMCreateProfile(   LPLOGCOLORSPACEA        lpColorSpace,
    00713                                                                 LPBYTE                          *lpProfileData )
    00714 {
    00715         CMWorldRef cw=0;
    00716         long err;
    00717
    00718         if( lpColorSpace->lcsFilename[0] ) return 0;
    00719         err = MyNewAbstract( lpColorSpace, (icProfile **)lpProfileData );
    00720         //err = FillProfileFromLog( lpColorSpace, &theProf );
    00721         if( err ){
    00722                 SetLastError( err );
    00723                 goto CleanupAndExit;
    00724         }
    00725         return 1;
    00726 CleanupAndExit:
    00727         return 0;
    00728 }
    00729
    00730 /* ______________________________________________________________________
    00731 BOOL  WINAPI CMCreateProfileW(  LPLOGCOLORSPACEW        lpColorSpace,
    00732                                                                 LPBYTE                          *lpProfileData );
    00733
    00734 Abstract:
    00735         The CMCreateProfileW function creates a display color profile
    00736         from a LogColorSpace structure.
    00737
    00738 Parameter                       Description
    00739         lpColorSpace    Pointer to color space. lcsFilename field will be NULL.
    00740         pProfileData    Points to a pointer to a buffer.
    00741                                         If successful the function allocates and fills this buffer.
    00742                                         It is then the calling application’s responsibility to
    00743                                         free this buffer with GlobalFreePtr( lpProfileData )
    00744                                         when it is no longer needed.
    00745
    00746 Returns
    00747         If the function is successful, it returns nonzero.
    00748         Otherwise it returns zero.
    00749
    00750    _____________________________________________________________________ */
    00751 BOOL  WINAPI CMCreateProfileW(  LPLOGCOLORSPACEW        lpColorSpace,
    00752                                                                 LPBYTE                          *lpProfileData )
    00753 {
    00754         CMWorldRef cw=0;
    00755         long err;
    00756
    00757         if( lpColorSpace->lcsFilename[0] ) return 0;
    00758         err = MyNewAbstractW( lpColorSpace, (icProfile **)lpProfileData );
    00759         //err = FillProfileFromLogW( lpColorSpace, &theProf );
    00760         if( err ){
    00761                 SetLastError( err );
    00762                 goto CleanupAndExit;
    00763         }
    00764         return 1;
    00765 CleanupAndExit:
    00766         return 0;
    00767 }
    00768
    00769 /* ______________________________________________________________________
    00770 BOOL  WINAPI CMCreateDeviceLinkProfile(         LPHPROFILE      lpahProfiles,
    00771                                                                                         DWORD           nProfiles,
    00772                                                                                         UINT32          *aIntentArr,
    00773                                                                                         UINT32          nIntents,
    00774                                                                                         UINT32          dwFlags,
    00775                                                                                         LPBYTE          *lpProfileData );
    00776
    00777 Abstract:
    00778         The CMCreateDeviceLinkProfile function creates a device link
    00779         profile as specified by the "ICC Profile Format Specification."
    00780
    00781 Parameter                       Description
    00782         lpahProfiles    Pointer to an array of profile handles
    00783         nProfiles               Number of profiles in the array
    00784         padwIntents             Points to an array of rendering intents.
    00785                                         Each rendering intent is represented by one of the following values:
    00786                                                 INTENT_PERCEPTUAL
    00787                                                 INTENT_SATURATION
    00788                                                 INTENT_RELATIVE_COLORIMETRIC
    00789                                                 INTENT_ABSOLUTE_COLORIMETRIC
    00790                                         For more information, see Rendering Intents.
    00791
    00792         nIntents                Specifies the number of intents in the intent array. Can be 1, or the same value as nProfiles.
    00793         dwFlags                 Specifies flags to control creation of the transform. These flags are intended only as hints,
    00794                                         and it is up to the CMM to determine how best to use these flags.
    00795                                         Set the high-order word to ENABLE_GAMUT_CHECKING if the transform will be used for gamut checking.
    00796                                         The low-order WORD can have one of the following constant values:
    00797                                                 PROOF_MODE, NORMAL_MODE, BEST_MODE. Moving from PROOF_MODE to BEST_MODE,
    00798                                                 output quality generally improves.
    00799
    00800         lpProfileData   Points to a pointer to a buffer.
    00801                                         If successful the function allocates and fills this buffer.
    00802                                         It is then the calling application’s responsibility to
    00803                                         free this buffer with GlobalFreePtr( lpProfileData )
    00804                                         when it is no longer needed.
    00805
    00806 Returns
    00807         If the function is successful, it returns nonzero.
    00808         Otherwise it returns zero. SetLastError is used.
    00809
    00810    _____________________________________________________________________ */
    00811
    00812 BOOL  WINAPI CMCreateDeviceLinkProfile( LPHPROFILE      lpahProfiles,
    00813                                                                                 DWORD           nProfiles,
    00814                                                                                 DWORD           *aIntentArr,
    00815                                                                                 DWORD           nIntents,
    00816                                                                                 DWORD           dwFlags,
    00817                                                                                 LPBYTE          *lpProfileData )
    00818 {
    00819         long                            err;
    00820         OSErr                           aOSErr;
    00821         CMWorldRef                      cw;
    00822         CMConcatProfileSet      *profileSet;
    00823         UINT32                          i;
    00824
    00825         *lpProfileData = 0;
    00826
    00827         err = CMCreateMultiProfileTransformInternal( &cw, lpahProfiles, nProfiles, aIntentArr, nIntents, dwFlags, 0 );
    00828         if( err ){
    00829                 SetLastError( err );
    00830                 return 0;
    00831         }
    00832         profileSet = (CMConcatProfileSet *)SmartNewPtrClear(sizeof (CMConcatProfileSet) + (nProfiles)* sizeof(CMProfileRef),&aOSErr);
    00833         err = aOSErr;
    00834         if (aOSErr == 0 )
    00835         {
    00836                 profileSet->keyIndex = 0;
    00837                 profileSet->count = (unsigned short)nProfiles;
    00838                 for( i=0; i<nProfiles; i++)
    00839                         profileSet->profileSet[i] = (CMProfileRef)((DWORD *)(((PVOID *)lpahProfiles)[i]));
    00840         }
    00841         else goto CleanupAndExit;
    00842
    00843         err = DeviceLinkFill( (CMMModelPtr)cw, profileSet, (icProfile **)lpProfileData, aIntentArr[0]  );
    00844         profileSet= (CMConcatProfileSet *)DisposeIfPtr( (Ptr) profileSet );
    00845
    00846         if( err )goto CleanupAndExit;
    00847         CWDisposeColorWorld ( cw );
    00848         return 1;
    00849
    00850 CleanupAndExit:
    00851         CWDisposeColorWorld ( cw );
    00852         SetLastError( err );
    00853         return 0;
    00854 }
    00855
    00856 /* ______________________________________________________________________
    00857 BOOL  WINAPI CMCreateDeviceLinkProfile( LPHPROFILE      lpahProfiles,
    00858                                                                                 DWORD           nProfiles,
    00859                                                                                 LPBYTE          *lpProfileData );
    00860
    00861 Abstract:
    00862         The CMCreateDeviceLinkProfile function creates a device link
    00863         profile as specified by the "ICC Profile Format Specification."
    00864
    00865 Parameter                       Description
    00866         lpahProfiles    Pointer to an array of profile handles
    00867         nProfiles               Number of profiles in the array
    00868         pProfileData    Points to a pointer to a buffer.
    00869                                         If successful the function allocates and fills this buffer.
    00870                                         It is then the calling application’s responsibility to
    00871                                         free this buffer with GlobalFreePtr( lpProfileData )
    00872                                         when it is no longer needed.
    00873
    00874 Returns
    00875         If the function is successful, it returns nonzero.
    00876         Otherwise it returns zero. SetLastError is used.
    00877
    00878    _____________________________________________________________________ */
    00879
    00880 /*BOOL  WINAPI CMCreateDeviceLinkProfile(       LPHPROFILE      lpahProfiles,
    00881                                                                                 DWORD           nProfiles,
    00882                                                                                 LPBYTE          *lpProfileData )
    00883 {
    00884         long                    err;
    00885         UINT32                  *arrIntents = 0;
    00886         OSErr                   aOSErr;
    00887         DWORD                   i;
    00888
    00889         arrIntents = (UINT32 *)SmartNewPtrClear( nProfiles * sizeof (UINT32), &aOSErr);
    00890         if (aOSErr != 0 ) return ERROR_NOT_ENOUGH_MEMORY;
    00891
    00892         for( i=0; i<nProfiles; i++){
    00893                 arrIntents[i] = icPerceptual;
    00894         }
    00895
    00896         err = CMCreateDeviceLinkProfileExt( lpahProfiles, nProfiles, arrIntents, nProfiles, BEST_MODE, lpProfileData );
    00897
    00898         arrIntents = (UINT32 *)DisposeIfPtr( (Ptr)arrIntents );
    00899         return err;
    00900 }
    00901 */
    00902 /* ______________________________________________________________________
    00903 BOOL  WINAPI CMIsProfileValid ( HPROFILE        hProfile,
    00904                                                                 LPBOOL          lpbValid
    00905                                                           );
    00906
    00907 Abstract:
    00908         The CMIsProfileValid function reports if the given profile is a valid ICC profile that can be used for color matching.
    00909
    00910 Parameter                       Description
    00911         lpDevCharacter  Pointer to memory mapped profile
    00912         lpbValid                Points to a variable that is set on exit to TRUE if the profile is a valid ICC profile, or FALSE if not.
    00913
    00914 Returns
    00915         If it is a valid ICC profile that can be used for color matching,
    00916         the return value is nonzero. Otherwise it is zero.
    00917    _____________________________________________________________________ */
    00918 BOOL  WINAPI CMIsProfileValid(  HPROFILE        hProfile,
    00919                                                                 LPBOOL          lpbValid
    00920                                                           )
    00921 {
    00922         Boolean valid;
    00923
    00924         CMValidateProfile( (CMProfileRef)hProfile, &valid );
    00925
    00926         *lpbValid = valid;
    00927         return valid;
    00928 }
    00929
    00930 /* ______________________________________________________________________
    00931 BOOL  WINAPI CMTranslateColors( HCMTRANSFORM    hcmTransform,
    00932                                                                 LPCOLOR                 lpaInputColors,
    00933                                                                 DWORD                   nColors,
    00934                                                                 COLORTYPE               ctInput,
    00935                                                                 LPCOLOR                 lpaOutputColors,
    00936                                                                 COLORTYPE               ctOutput );
    00937 Abstract:
    00938         The CMTranslateColors function translates an array of colors from
    00939         the source colorspace to the destination colorspace as defined by
    00940         the color transform.
    00941
    00942 Parameter                       Description
    00943         hcmTransform    Identifies the color transform to use
    00944         lpaInputColors  Pointer to an array of COLOR structures to translate
    00945         nColors                 Number of elements in the array
    00946         ctInput                 Specifies the input color type
    00947         lpaOutputColors Pointer to an array of COLOR structures that receive the translated colors
    00948         ctOutput                Specifies the output color type
    00949
    00950 Returns
    00951         If the function is successful, the return value is nonzero.
    00952         Otherwise it is zero.
    00953
    00954    _____________________________________________________________________ */
    00955 BOOL  WINAPI CMTranslateColors( HCMTRANSFORM    hcmTransform,
    00956                                                                 LPCOLOR                 lpaInputColors,
    00957                                                                 DWORD                   nColors,
    00958                                                                 COLORTYPE               ctInput,
    00959                                                                 LPCOLOR                 lpaOutputColors,
    00960                                                                 COLORTYPE               ctOutput )
    00961 {
    00962         long matchErr;
    00963         DWORD i;
    00964
    00965     if (lpaOutputColors != lpaInputColors){
    00966         for( i=0; i<nColors; i++) lpaOutputColors[ i ] = lpaInputColors[ i ];
    00967     }
    00968
    00969         matchErr = CWMatchColors( CMGetTransform( hcmTransform ), (CMColor *)lpaOutputColors, nColors );
    00970         if( matchErr ){
    00971                 SetLastError( matchErr );
    00972                 return 0;
    00973         }
    00974         return 1;
    00975 }
    00976
    00977 /* ______________________________________________________________________
    00978 BOOL  WINAPI CMCheckColors(     HCMTRANSFORM    hcmTransform,
    00979                                                         LPCOLOR                 lpaInputColors,
    00980                                                         DWORD                   nColors,
    00981                                                         COLORTYPE               ctInput,
    00982                                                         LPBYTE                  lpaResult );
    00983 Abstract:
    00984         The CMCheckColors function determines if the given colors lie
    00985         within the output gamut of the given transform.
    00986
    00987 Parameter                       Description
    00988         hcmTransform    Identifies the color transform to use
    00989         lpaInputColors  Pointer to an array of COLOR structures
    00990         nColors                 Number of elements in the array
    00991         ctInput                 Input color type
    00992         lpaResult               Pointer to an array of bytes that hold the result
    00993
    00994 Returns
    00995         If the function is successful, the return value is nonzero.
    00996         Otherwise it is zero.
    00997         The lpaResult array holds the results, each byte corresponds to a
    00998         COLOR element and has a value between 0 and 255.
    00999         The value 0 denotes that the color is in gamut; a non-zero value
    01000         implies that it is out of gamut, with the number "n+1" being at
    01001         least as far out of gamut as the number "n". These values are
    01002         usually generated from the gamutTag in the ICC profile.
    01003
    01004    _____________________________________________________________________ */
    01005 BOOL  WINAPI CMCheckColors(     HCMTRANSFORM    hcmTransform,
    01006                                                         LPCOLOR                 lpaInputColors,
    01007                                                         DWORD                   nColors,
    01008                                                         COLORTYPE               ctInput,
    01009                                                         LPBYTE                  lpaResult )
    01010 {
    01011         long matchErr;
    01012
    01013         matchErr = CWCheckColorsMS( CMGetTransform( hcmTransform ), (CMColor *)lpaInputColors, nColors, lpaResult );
    01014         if( matchErr ){
    01015                 SetLastError( matchErr );
    01016                 return 0;
    01017         }
    01018         return 1;
    01019 }
    01020
    01021 /* ______________________________________________________________________
    01022 BOOL  WINAPI CMTranslateRGBs(   HCMTRANSFORM    hcmTransform,
    01023                                                                 LPVOID                  lpSrcBits,
    01024                                                                 BMFORMAT                bmInput,
    01025                                                                 DWORD                   dwWidth,
    01026                                                                 DWORD                   dwHeight,
    01027                                                                 DWORD                   dwStride,
    01028                                                                 LPVOID                  lpDestBits,
    01029                                                                 BMFORMAT                bmOutput,
    01030                                                                 DWORD                   dwTranslateDirection );
    01031 Abstract:
    01032         The CMTranslateRGBs function takes a bitmap in one of the defined
    01033         formats and translates the colors in the bitmap producing another
    01034         bitmap in the requested format.
    01035
    01036 Parameter                                       Description
    01037         hcmTransform                    Identifies the color transform to use
    01038         lpSrcBits                               Pointer to bitmap to translate
    01039         bmInput                                 Input bitmap format
    01040         dwWidth                                 Number of pixels per scanline of input data
    01041         dwHeight                                Number of        scanlines of input data
    01042         dwStride                                Number of bytes from beginning of one scanline to beginning of next
    01043         lpDestBits                              Pointer to buffer to receive translated data
    01044         bmOutput                                Output bitmap format
    01045         dwTranslateDirection    Describes direction of transform
    01046         Value   Meaning
    01047         CMS_FORWARD     Use forward transform
    01048         CMS_BACKWARD    Use reverse transform  // NOT supported
    01049
    01050 Returns
    01051         If the function is successful, the return value is nonzero.
    01052         Otherwise it is zero.
    01053    _____________________________________________________________________ */
    01054 BOOL  WINAPI CMTranslateRGBs(   HCMTRANSFORM    hcmTransform,
    01055                                                                 LPVOID                  lpSrcBits,
    01056                                                                 BMFORMAT                bmInput,
    01057                                                                 DWORD                   dwWidth,
    01058                                                                 DWORD                   dwHeight,
    01059                                                                 DWORD                   dwStride,
    01060                                                                 LPVOID                  lpDestBits,
    01061                                                                 BMFORMAT                bmOutput,
    01062                                                                 DWORD                   dwTranslateDirection )
    01063 {
    01064         CMBitmapColorSpace              spaceIn,spaceOut;
    01065         CMBitmap                                InBitmap,OutBitmap;
    01066         long matchErr, inPixelSize, outPixelSize;
    01067         BOOL aBgrMode = FALSE;
    01068         CMMModelPtr theModelPtr;
    01069         CMWorldRef theWorldRef;
    01070         HCMTRANSFORM theTransform = CMGetTransform( hcmTransform );
    01071
    01072         if( dwTranslateDirection == CMS_BACKWARD ){
    01073                 if( theTransform == 0 ){
    01074                         SetLastError( (DWORD)cmparamErr );
    01075                         return 0;
    01076                 }
    01077                 LOCK_DATA( theTransform );
    01078                 theModelPtr = (CMMModelPtr)(DATA_2_PTR( theTransform ));
    01079                 theWorldRef = theModelPtr->pBackwardTransform;
    01080                 UNLOCK_DATA( theTransform );
    01081                 if( theWorldRef == 0 ){
    01082                         SetLastError( (DWORD)cmparamErr );
    01083                         return 0;
    01084                 }
    01085                 theTransform = (HCMTRANSFORM)theWorldRef;
    01086         }
    01087
    01088         spaceIn = CMGetDataColorSpace( bmInput, &inPixelSize );
    01089         if( spaceIn == 0 ){
    01090                 SetLastError( (DWORD)cmInvalidColorSpace );
    01091                 return 0;
    01092         }
    01093         spaceOut = CMGetDataColorSpace( bmOutput, &outPixelSize );
    01094         if( spaceOut == 0 ){
    01095                 SetLastError( (DWORD)cmInvalidColorSpace );
    01096                 return 0;
    01097         }
    01098         InBitmap.image          = lpSrcBits;
    01099         InBitmap.width          = dwWidth;
    01100         InBitmap.height         = dwHeight;
    01101         if( dwStride == 0 ){
    01102                 InBitmap.rowBytes = ( dwWidth * (inPixelSize / 8) + 3 ) & ~3;
    01103         }
    01104         else{
    01105                 InBitmap.rowBytes       = dwStride;
    01106         }
    01107         InBitmap.pixelSize      = inPixelSize;
    01108         InBitmap.space          = spaceIn;
    01109
    01110         OutBitmap.image         = lpDestBits;
    01111         OutBitmap.width         = dwWidth;
    01112         OutBitmap.height        = dwHeight;
    01113         OutBitmap.rowBytes      = ( dwWidth * (outPixelSize / 8) + 3 ) & ~3;
    01114         OutBitmap.pixelSize     = outPixelSize;
    01115         OutBitmap.space         = spaceOut;
    01116
    01117         matchErr = CWMatchBitmap( theTransform, &InBitmap,
    01118                                                           (CMBitmapCallBackUPP)0,(void *)NULL,&OutBitmap );
    01119         if( matchErr ){
    01120                 SetLastError( matchErr );
    01121                 return 0;
    01122         }
    01123         return 1;
    01124 }
    01125
    01126 /* ______________________________________________________________________
    01127 BOOL  WINAPI CMTranslateRGBsExt(        HCMTRANSFORM    hcmTransform,
    01128                                                                         LPVOID                  lpSrcBits,
    01129                                                                         BMFORMAT                bmInput,
    01130                                                                         DWORD                   dwWidth,
    01131                                                                         DWORD                   dwHeight,
    01132                                                                         DWORD                   dwInputStride,
    01133                                                                         LPVOID                  lpDestBits,
    01134                                                                         BMFORMAT                bmOutput,
    01135                                                                         DWORD                   dwOutputStride,
    01136                                                                         LPBMCALLBACKFN  lpfnCallback,
    01137                                                                         LPARAM                  ulCallbackData )
    01138 Abstract:
    01139         The CMTranslateRGBs function takes a bitmap in one of the defined
    01140         formats and translates the colors in the bitmap producing another
    01141         bitmap in the requested format.
    01142
    01143 Parameter                                       Description
    01144         hcmTransform                    Specifies the color transform to use.
    01145         lpSrcBits                               Points to the bitmap to translate.
    01146         bmInput                                 Specifies the input bitmap format.
    01147         dwWidth                                 Specifies the number of pixels per scanline in the input bitmap.
    01148         dwHeight                                Specifies the number of scanlines in the input bitmap.
    01149         dwInputStride                   Specifies the number of bytes from the beginning of one scanline to
    01150                                                         the beginning of the next in the input bitmap.
    01151                                                         If dwInputStride is set to zero, the CMM should assume that scanlines
    01152                                                         are padded so as to be DWORD aligned.
    01153         lpDestBits                              Points to a destination buffer in which to place the translated bitmap.
    01154         bmOutput                                Specifies the output bitmap format.
    01155         dwOutputStride                  Specifies the number of bytes from the beginning of one scanline to the
    01156                                                         beginning of the next in the input bitmap.
    01157                                                         If dwOutputStride is set to zero, the CMM should pad scanlines so
    01158                                                         that they are DWORD aligned.
    01159         lpfnCallback                    Pointer to an application-supplied callback function called periodically
    01160                                                         by CMTranslateRGBsExt to report progress and allow the calling process
    01161                                                         to cancel the translation. (See ICMProgressProc.)
    01162         ulCallbackData                  Data passed back to the callback function, for example to identify the
    01163                                                         translation that is reporting progress.
    01164
    01165 Returns
    01166         If the function is successful, the return value is nonzero.
    01167         Otherwise it is zero.
    01168    _____________________________________________________________________ */
    01169 BOOL  WINAPI CMTranslateRGBsExt(        HCMTRANSFORM    hcmTransform,
    01170                                                                         LPVOID                  lpSrcBits,
    01171                                                                         BMFORMAT                bmInput,
    01172                                                                         DWORD                   dwWidth,
    01173                                                                         DWORD                   dwHeight,
    01174                                                                         DWORD                   dwInputStride,
    01175                                                                         LPVOID                  lpDestBits,
    01176                                                                         BMFORMAT                bmOutput,
    01177                                                                         DWORD                   dwOutputStride,
    01178                                                                         LPBMCALLBACKFN  lpfnCallback,
    01179                                                                         LPARAM          ulCallbackData )
    01180 {
    01181         CMBitmapColorSpace              spaceIn,spaceOut;
    01182         CMBitmap                                InBitmap,OutBitmap;
    01183         long matchErr, inPixelSize, outPixelSize;
    01184         BOOL aBgrMode = FALSE;
    01185
    01186         spaceIn = CMGetDataColorSpace( bmInput, &inPixelSize );
    01187         if( spaceIn == 0 ){
    01188                 SetLastError( (DWORD)cmInvalidColorSpace );
    01189                 return 0;
    01190         }
    01191         spaceOut = CMGetDataColorSpace( bmOutput, &outPixelSize );
    01192         if( spaceOut == 0 ){
    01193                 SetLastError( (DWORD)cmInvalidColorSpace );
    01194                 return 0;
    01195         }
    01196         InBitmap.image          = lpSrcBits;
    01197         InBitmap.width          = dwWidth;
    01198         InBitmap.height         = dwHeight;
    01199         if( dwInputStride == 0 ){
    01200                 InBitmap.rowBytes = ( dwWidth * (inPixelSize / 8) + 3 ) & ~3;
    01201         }
    01202         else{
    01203                 InBitmap.rowBytes       = dwInputStride;
    01204         }
    01205         InBitmap.pixelSize      = inPixelSize;
    01206         InBitmap.space          = spaceIn;
    01207
    01208         OutBitmap.image         = lpDestBits;
    01209         OutBitmap.width         = dwWidth;
    01210         OutBitmap.height        = dwHeight;
    01211         if( dwOutputStride == 0 ){
    01212                 OutBitmap.rowBytes = ( dwWidth * (outPixelSize / 8) + 3 ) & ~3;
    01213         }
    01214         else{
    01215                 OutBitmap.rowBytes      = dwOutputStride;
    01216         }
    01217         OutBitmap.pixelSize     = outPixelSize;
    01218         OutBitmap.space         = spaceOut;
    01219
    01220         matchErr = CWMatchBitmap( CMGetTransform( hcmTransform ), &InBitmap,
    01221                                                           (CMBitmapCallBackUPP)lpfnCallback,(void *)ulCallbackData,&OutBitmap );
    01222         if( matchErr ){
    01223                 SetLastError( matchErr );
    01224                 return 0;
    01225         }
    01226         return 1;
    01227 }
    01228
    01229 /* ______________________________________________________________________
    01230 BOOL  WINAPI CMCheckRGBs(       HCMTRANSFORM    hcmTransform,
    01231                                                         LPVOID                  lpSrcBits,
    01232                                                         BMFORMAT                bmInput,
    01233                                                         DWORD                   dwWidth,
    01234                                                         DWORD                   dwHeight,
    01235                                                         DWORD                   dwStride,
    01236                                                         LPBYTE                  lpDestBits,
    01237                                                         PBMCALLBACKFN   pfnCallback,
    01238                                                         LPARAM          ulCallbackData );
    01239 Abstract:
    01240         The CMCheckRGBs function checks if the pixels in the bitmap lie
    01241         within the output gamut of the given transform.
    01242
    01243 Parameter                       Description
    01244
    01245         hcmTransform    Specifies the color transform to use.
    01246         lpSrcBits               Points to the bitmap to check against an output gamut.
    01247         bmInput                 Specifies the input bitmap format.
    01248         dwWidth                 Specifies the number of pixels per scanline in the input bitmap.
    01249         dwHeight                Specifies the number of scanlines in the input bitmap.
    01250         dwStride                Specifies the number of bytes from the beginning of one scanline
    01251                                         to the beginning of the next in the input bitmap.
    01252                                         If dwStride is set to zero, the CMM should assume that scanlines
    01253                                         are padded so as to be DWORD-aligned.
    01254         lpaResult               Points to a buffer in which the test results are to be placed.
    01255                                         The results are represented by an array of bytes.
    01256                                         Each byte in the array corresponds to a pixel in the bitmap,
    01257                                         and on exit is set to an unsigned value between 0 and 255.
    01258                                         The value 0 denotes that the color is in gamut,
    01259                                         while a nonzero value denotes that it is out of gamut.
    01260                                         For any integer n such that 0 < n < 255, a result value of n+1
    01261                                         indicates that the corresponding color is at least as far out of
    01262                                         gamut as would be indicated by a result value of n.
    01263                                         These values are usually generated from the gamutTag in the ICC profile.
    01264         pfnCallback             Pointer to an application-supplied callback function called periodically
    01265                                         by CMCheckRGBs to report progress and allow the calling process
    01266                                         to cancel the translation. (See ICMProgressProc.)
    01267         ulCallbackData  Data passed back to the callback function, for example to identify
    01268                                         the bitmap test that is reporting progress.
    01269
    01270 Returns
    01271         If the function is successful, the return value is nonzero.
    01272         Otherwise it is zero.
    01273         The lpaResult array holds the results, each byte corresponds to a pixel
    01274         and has a value between 0 and 255. The value 0 denotes that the color is in gamut;
    01275         a non-zero value implies that it is out of gamut, with the number "n+1" being at
    01276         least as far out of gamut as the number "n". These values are usually generated
    01277         from the gamutTag in the ICC profile.
    01278    _____________________________________________________________________ */
    01279 BOOL  WINAPI CMCheckRGBs(       HCMTRANSFORM    hcmTransform,
    01280                                                         LPVOID                  lpSrcBits,
    01281                                                         BMFORMAT                bmInput,
    01282                                                         DWORD                   dwWidth,
    01283                                                         DWORD                   dwHeight,
    01284                                                         DWORD                   dwStride,
    01285                                                         LPBYTE                  lpDestBits,
    01286                                                         PBMCALLBACKFN   pfnCallback,
    01287                                                         LPARAM          ulCallbackData )
    01288
    01289 {
    01290         CMBitmapColorSpace              spaceIn,spaceOut;
    01291         CMBitmap                                InBitmap,OutBitmap;
    01292         long matchErr, inPixelSize;
    01293         BOOL aBgrMode = FALSE;
    01294
    01295         spaceIn = CMGetDataColorSpace( bmInput, &inPixelSize );
    01296         if( spaceIn == 0 ){
    01297                 SetLastError( (DWORD)cmInvalidColorSpace );
    01298                 return 0;
    01299         }
    01300         spaceOut = cm8PerChannelPacking + cmGraySpace;
    01301
    01302         if( spaceOut == 0 )return 0;
    01303         InBitmap.image          = lpSrcBits;
    01304         InBitmap.width          = dwWidth;
    01305         InBitmap.height         = dwHeight;
    01306         if( dwStride == 0 ){
    01307                 InBitmap.rowBytes = ( dwWidth * (inPixelSize / 8) + 3 ) & ~3;
    01308         }
    01309         else{
    01310                 InBitmap.rowBytes       = dwStride;
    01311         }
    01312         InBitmap.pixelSize      = inPixelSize;
    01313         InBitmap.space          = spaceIn;
    01314
    01315         OutBitmap.image         = lpDestBits;
    01316         OutBitmap.width         = dwWidth;
    01317         OutBitmap.height        = dwHeight;
    01318         OutBitmap.rowBytes      = dwWidth;      // perhaps wrong format?
    01319         OutBitmap.pixelSize     = 8;
    01320         OutBitmap.space         = cmGamutResultSpace;
    01321
    01322         matchErr = CWCheckBitmap(       CMGetTransform( hcmTransform ), &InBitmap,
    01323                                                                 (CMBitmapCallBackUPP)pfnCallback,(void *)ulCallbackData,&OutBitmap );
    01324
    01325         if( matchErr ){
    01326                 SetLastError( matchErr );
    01327                 return 0;
    01328         }
    01329         return 1;
    01330 }
    01331
    01332 /* ______________________________________________________________________
    01333 BOOL WINAPI CMTranslateRGB(     HCMTRANSFORM    hcmTransform,
    01334                                                         COLORREF                colorRef,
    01335                                                         LPCOLORREF              lpColorRef,
    01336                                                         DWORD                   dwFlags );
    01337 Abstract:
    01338         The CMTranslateRGB function translates an application supplied RGBQuad into the
    01339         device color coordinate space.
    01340
    01341 Parameter                       Description
    01342         hcmTransform    Handle of transform to use.
    01343         colorRef                RGBQuad to translate.
    01344         lpColorRef              Pointer to buffer to store result.
    01345         dwFlags                 Flags that can have the following meaning
    01346
    01347         Type                    Meaning
    01348
    01349         CMS_FORWARD             Specifies that the forward transform is to be used.
    01350         CMS_BACKWARD    Specifies that the backward transform is to be used.  // NOT supported
    01351
    01352 Returns
    01353         The return value is TRUE if the function is successful. Otherwise, it is NULL.
    01354
    01355    _____________________________________________________________________ */
    01356 BOOL WINAPI CMTranslateRGB(     HCMTRANSFORM    hcmTransform,
    01357                                                         COLORREF                colorRef,
    01358                                                         LPCOLORREF              lpColorRef,
    01359                                                         DWORD                   dwFlags )
    01360
    01361 {
    01362         CMBitmapColorSpace              spaceIn;
    01363         CMBitmap                                InBitmap,OutBitmap;
    01364         long matchErr;
    01365         COLORREF aColorRef = colorRef;
    01366         BOOL aBgrMode = FALSE;
    01367         CMBitmapColorSpace In,Out;
    01368         CMMModelPtr theModelPtr;
    01369         CMWorldRef theWorldRef;
    01370         HCMTRANSFORM theTransform = CMGetTransform( hcmTransform );
    01371
    01372         if( dwFlags == CMS_BACKWARD ){
    01373                 if( theTransform == 0 ){
    01374                         SetLastError( (DWORD)cmparamErr );
    01375                         return 0;
    01376                 }
    01377                 LOCK_DATA( theTransform );
    01378                 theModelPtr = (CMMModelPtr)(DATA_2_PTR( theTransform ));
    01379                 theWorldRef = theModelPtr->pBackwardTransform;
    01380                 UNLOCK_DATA( theTransform );
    01381                 if( theWorldRef == 0 ){
    01382                         SetLastError( (DWORD)cmparamErr );
    01383                         return 0;
    01384                 }
    01385                 theTransform = (HCMTRANSFORM)theWorldRef;
    01386         }
    01387
    01388         spaceIn = cmRGBA32Space;
    01389         InBitmap.image          = (char *)(&aColorRef);
    01390         InBitmap.width          = 1;
    01391         InBitmap.height         = 1;
    01392         InBitmap.rowBytes       = 4;
    01393         InBitmap.pixelSize      = 32;
    01394         InBitmap.space          = spaceIn;
    01395         OutBitmap = InBitmap;
    01396         OutBitmap.image         = (char *)lpColorRef;
    01397
    01398         matchErr = CWGetColorSpaces( theTransform, &In, &Out );
    01399         if( matchErr ){
    01400                 SetLastError( matchErr );
    01401                 return 0;
    01402         }
    01403         if( Out == icSigCmykData ) OutBitmap.space = cmKYMC32Space;
    01404         matchErr = CWMatchBitmap(       theTransform, &InBitmap,
    01405                                                                 (CMBitmapCallBackUPP)0,(void *)NULL,&OutBitmap );
    01406         if( matchErr ){
    01407                 SetLastError( matchErr );
    01408                 return 0;
    01409         }
    01410         return 1;
    01411 }
    01412
    01413
    01414 /* ______________________________________________________________________
    01415 BOOL WINAPI CMCheckColorsInGamut(       HCMTRANSFORM    hcmTransform,
    01416                                                                         LPARGBQUAD              lpaRGBTriplet,
    01417                                                                         LPBYTE                  lpBuffer,
    01418                                                                         UINT                    nCount );
    01419 Abstract:
    01420         The CMCheckColorInGamut determines if the given RGBs lie in the output gamut of the
    01421         given transform.
    01422
    01423 Parameter                       Description
    01424         hcmTransform    Handle of transform to use.
    01425         lpaRGBTriples   Pointer to array of RGB triples to check.
    01426         lpBuffer                Pointer to buffer to put results.
    01427         nCount                  Count of elements in array.
    01428
    01429
    01430 Returns
    01431         The return value is TRUE if the function is successful. Otherwise, it is NULL.
    01432         The lpBuffer holds the results, each byte corresponding to an RGB triple is a value in
    01433         the range 0 to 255.
    01434    _____________________________________________________________________ */
    01435 BOOL WINAPI CMCheckColorsInGamut(       HCMTRANSFORM    hcmTransform,
    01436                                                                         RGBTRIPLE               *lpaRGBTriplet,
    01437                                                                         LPBYTE                  lpBuffer,
    01438                                                                         UINT                    nCount )
    01439 {
    01440         CMBitmap                                InBitmap,OutBitmap;
    01441         long matchErr;
    01442         BOOL aBgrMode = FALSE;
    01443
    01444         InBitmap.image          = (char *)(lpaRGBTriplet);
    01445         InBitmap.width          = nCount;
    01446         InBitmap.height         = 1;
    01447         InBitmap.rowBytes       = 3*nCount;
    01448         InBitmap.pixelSize      = 24;
    01449         InBitmap.space          = cm8PerChannelPacking + cmRGBSpace;
    01450         OutBitmap = InBitmap;
    01451         OutBitmap.rowBytes      = nCount;       // perhaps wrong format?
    01452         OutBitmap.pixelSize     = 8;
    01453         OutBitmap.image         = (char *)lpBuffer;
    01454
    01455         matchErr = CWCheckBitmap(       CMGetTransform( hcmTransform ), &InBitmap,
    01456                                                                 (CMBitmapCallBackUPP)0,(void *)NULL,&OutBitmap );
    01457         if( matchErr ){
    01458                 SetLastError( matchErr );
    01459                 return 0;
    01460         }
    01461         return 1;
    01462 }
    01463 /* ______________________________________________________________________
    01464 long FillProfileFromLog(        LPLOGCOLORSPACEA        lpColorSpace,
    01465                                                         PPROFILE                        theProf )
    01466 Abstract:
    01467         The FillProfileFromLog function convertes a lpColorSpace to a PROFILE.
    01468         If lpColorSpace has a profile name the function returns a file based profile.
    01469         Else it returns a memory based profile.
    01470
    01471 Parameter                       Description
    01472         lpColorSpace    Handle of transform to use.
    01473         theProf                 Pointer to the profile.
    01474
    01475 Returns
    01476         The return value is 0 if the function is successful. Otherwise, it is an error code.
    01477    _____________________________________________________________________ */
    01478 long FillProfileFromLog(        LPLOGCOLORSPACEA        lpColorSpace,
    01479                                                         PPROFILE                        theProf )
    01480 {
    01481         long l;
    01482         icProfile *aProf;
    01483         CMError  err = -1;
    01484
    01485         if( lpColorSpace->lcsFilename[0] ){
    01486                 theProf->pProfileData = (char *)lpColorSpace->lcsFilename;
    01487                 theProf->dwType = PROFILE_FILENAME;
    01488                 theProf->cbDataSize = lstrlenA((const unsigned char *)theProf->pProfileData) * sizeof(CHAR);
    01489                 err = 0;
    01490         }
    01491         else if( lpColorSpace->lcsCSType == LCS_CALIBRATED_RGB ){
    01492                 err = MyNewAbstract( lpColorSpace, &aProf );
    01493                 theProf->pProfileData = ((PVOID *)aProf);
    01494                 theProf->dwType = PROFILE_MEMBUFFER;
    01495                 l = *(DWORD *)(theProf->pProfileData);
    01496                 theProf->cbDataSize = SwapLong(&l);
    01497         }
    01498         else  theProf->pProfileData = 0;
    01499
    01500         return err;
    01501 }
    01502
    01503 /* ______________________________________________________________________
    01504 long FillProfileFromLogW(       LPLOGCOLORSPACEW        lpColorSpace,
    01505                                                         PPROFILE                        theProf )
    01506 Abstract:
    01507         The FillProfileFromLog function convertes a lpColorSpace to a PROFILE.
    01508         If lpColorSpace has a profile name the function returns a file based profile.
    01509         Else it returns a memory based profile.
    01510
    01511 Parameter                       Description
    01512         lpColorSpace    Handle of transform to use.
    01513         theProf                 Pointer to the profile.
    01514
    01515 Returns
    01516         The return value is 0 if the function is successful. Otherwise, it is an error code.
    01517    _____________________________________________________________________ */
    01518 long FillProfileFromLogW(       LPLOGCOLORSPACEW        lpColorSpace,
    01519                                                         PPROFILE                        theProf )
    01520 {
    01521         long l;
    01522         icProfile *aProf;
    01523         CMError  err = -1;
    01524
    01525         if( lpColorSpace->lcsFilename[0] ){
    01526                 theProf->pProfileData = (char *)lpColorSpace->lcsFilename;
    01527                 theProf->dwType = PROFILE_FILENAME;
    01528                 theProf->cbDataSize = lstrlenW((const unsigned short *)theProf->pProfileData) * sizeof(WCHAR);
    01529                 err = 0;
    01530         }
    01531         else if( lpColorSpace->lcsCSType == LCS_CALIBRATED_RGB ){
    01532                 err = MyNewAbstractW( lpColorSpace, &aProf );
    01533                 theProf->pProfileData = ((PVOID *)aProf);
    01534                 theProf->dwType = PROFILE_MEMBUFFER;
    01535                 l = *(DWORD *)(theProf->pProfileData);
    01536                 theProf->cbDataSize = SwapLong(&l);
    01537         }
    01538         else  theProf->pProfileData = 0;
    01539
    01540         return err;
    01541 }
    01542
    01543 /* ______________________________________________________________________
    01544 CMBitmapColorSpace CMGetDataColorSpace( BMFORMAT bmMode, long *pixelSize );
    01545
    01546 Abstract:
    01547         The CMGetDataColorSpace function retrieves the CMBitmapColorSpace and
    01548         the pixel size from the BMFORMAT.
    01549
    01550 Parameter                       Description
    01551         bmMode                  Identifies the data format.
    01552         pixelSize               Pointer to pixelsize.
    01553
    01554 Returns
    01555         function returns the internal data format
    01556 ________________________________________________________________ */
    01557 CMBitmapColorSpace CMGetDataColorSpace( BMFORMAT bmMode, long *pixelSize )
    01558 {
    01559         switch(  bmMode ){
    01560         case BM_565RGB:
    01561                 *pixelSize = 16;
    01562                 return cmWord565ColorPacking + cmRGBSpace;
    01563                 break;
    01564     case BM_x555RGB:
    01565                 *pixelSize = 16;
    01566                 return cmWord5ColorPacking + cmRGBSpace;
    01567                 break;
    01568         case BM_x555XYZ:
    01569                 *pixelSize = 16;
    01570                 return cmWord5ColorPacking + cmXYZSpace;
    01571                 break;
    01572         case BM_x555Yxy:
    01573                 *pixelSize = 16;
    01574                 return cmWord5ColorPacking + cmYXYSpace;
    01575                 break;
    01576         case BM_x555Lab:
    01577                 *pixelSize = 16;
    01578                 return cmWord5ColorPacking + cmLABSpace;
    01579                 break;
    01580         case BM_x555G3CH:
    01581                 *pixelSize = 16;
    01582                 return cmWord5ColorPacking + cmGenericSpace;
    01583                 break;
    01584         case BM_RGBTRIPLETS:
    01585                 *pixelSize = 24;
    01586                 return cm8PerChannelPacking + cmBGRSpace;
    01587                 break;
    01588         case BM_BGRTRIPLETS:
    01589                 *pixelSize = 24;
    01590                 return cm8PerChannelPacking + cmRGBSpace;
    01591                 break;
    01592         case BM_XYZTRIPLETS:
    01593                 *pixelSize = 24;
    01594                 return cm8PerChannelPacking + cmXYZSpace;
    01595                 break;
    01596         case BM_YxyTRIPLETS:
    01597                 *pixelSize = 24;
    01598                 return cm8PerChannelPacking + cmYXYSpace;
    01599                 break;
    01600         case BM_LabTRIPLETS:
    01601                 *pixelSize = 24;
    01602                 return cm8PerChannelPacking + cmLABSpace;
    01603                 break;
    01604         case BM_G3CHTRIPLETS:
    01605                 *pixelSize = 24;
    01606                 return cm8PerChannelPacking + cmGenericSpace;
    01607                 break;
    01608         case BM_5CHANNEL:
    01609                 *pixelSize = 40;
    01610                 return cmMCFive8Space;
    01611                 break;
    01612         case BM_6CHANNEL:
    01613                 *pixelSize = 48;
    01614                 return cmMCSix8Space;
    01615                 break;
    01616         case BM_7CHANNEL:
    01617                 *pixelSize = 56;
    01618                 return cmMCSeven8Space;
    01619                 break;
    01620         case BM_8CHANNEL:
    01621                 *pixelSize = 64;
    01622                 return cmMCEight8Space;
    01623                 break;
    01624         case BM_GRAY:
    01625                 *pixelSize = 8;
    01626                 return cm8PerChannelPacking + cmGraySpace;
    01627                 break;
    01628         case BM_xRGBQUADS:
    01629                 *pixelSize = 32;
    01630                 return cmBGR32Space;
    01631                 break;
    01632         case BM_xBGRQUADS:
    01633                 *pixelSize = 32;
    01634                 return cmRGBA32Space;
    01635                 break;
    01636 #if 0
    01637         case BM_xXYZQUADS:
    01638                 *pixelSize = 32;
    01639                 return cmLong8ColorPacking + cmXYZSpace;
    01640                 break;
    01641         case BM_xYxyQUADS:
    01642                 *pixelSize = 32;
    01643                 return cmLong8ColorPacking + cmYXYSpace;
    01644                 break;
    01645         case BM_xLabQUADS:
    01646                 *pixelSize = 32;
    01647                 return cmLong8ColorPacking + cmLABSpace;
    01648                 break;
    01649 #endif
    01650     case BM_xG3CHQUADS:
    01651                 *pixelSize = 32;
    01652                 return cmLong8ColorPacking + cmGenericSpace;
    01653                 break;
    01654         case BM_CMYKQUADS:
    01655                 *pixelSize = 32;
    01656                 return cmLong8ColorPacking + cmKYMCSpace;
    01657                 break;
    01658         case BM_KYMCQUADS:
    01659                 *pixelSize = 32;
    01660                 return cmLong8ColorPacking + cmCMYKSpace;
    01661                 break;
    01662         case BM_10b_RGB:
    01663                 *pixelSize = 32;
    01664                 return cmLong10ColorPacking + cmRGBSpace;
    01665                 break;
    01666         case BM_10b_XYZ:
    01667                 *pixelSize = 32;
    01668                 return cmLong10ColorPacking + cmXYZSpace;
    01669                 break;
    01670         case BM_10b_Yxy:
    01671                 *pixelSize = 32;
    01672                 return cmLong10ColorPacking + cmYXYSpace;
    01673                 break;
    01674         case BM_10b_Lab:
    01675                 *pixelSize = 32;
    01676                 return cmLong10ColorPacking + cmLABSpace;
    01677                 break;
    01678         case BM_10b_G3CH:
    01679                 *pixelSize = 32;
    01680                 return cmLong10ColorPacking + cmGenericSpace;
    01681                 break;
    01682         case BM_16b_RGB:
    01683                 *pixelSize = 48;
    01684                 return cm16PerChannelPacking + cmBGRSpace;
    01685                 break;
    01686         case BM_16b_XYZ:
    01687                 *pixelSize = 48;
    01688                 return cm16PerChannelPacking + cmXYZSpace;
    01689                 break;
    01690         case BM_16b_Yxy:
    01691                 *pixelSize = 48;
    01692                 return cm16PerChannelPacking + cmYXYSpace;
    01693                 break;
    01694         case BM_16b_Lab:
    01695                 *pixelSize = 48;
    01696                 return cm16PerChannelPacking + cmLABSpace;
    01697                 break;
    01698         case BM_16b_G3CH:
    01699                 *pixelSize = 48;
    01700                 return cm16PerChannelPacking + cmGenericSpace;
    01701                 break;
    01702         case BM_16b_GRAY:
    01703                 *pixelSize = 16;
    01704                 return cmGraySpace;
    01705                 break;
    01706         case BM_NAMED_INDEX:
    01707                 *pixelSize = 32;
    01708                 return cmNamedIndexed32Space;
    01709                 break;
    01710         default:
    01711                 *pixelSize = 0;
    01712                 return 0;
    01713         }
    01714 }
    01715
    01716 /* ______________________________________________________________________
    01717 HCMTRANSFORM  WINAPI CMGetTransform( HCMTRANSFORM       hcmTransform );
    01718
    01719 Abstract:
    01720         The CMGetTransform function retrieves the actual transform out of the static array
    01721         in the critical section.
    01722
    01723 Parameter                       Description
    01724         hcmTransform    Handle to the transform.
    01725
    01726 Returns
    01727         the actual pointer to the transform
    01728 ________________________________________________________________ */
    01729 HCMTRANSFORM  WINAPI CMGetTransform( HCMTRANSFORM       hcmTransform )
    01730 {
    01731         long actTransform = (long)(ULONG_PTR)hcmTransform - 256;
    01732         HCMTRANSFORM aTrans = NULL;
    01733
    01734         __try {
    01735                 EnterCriticalSection(&GlobalCriticalSection);
    01736                 if( actTransform < IndexTransform && actTransform >= 0 ){
    01737                         aTrans = TheTransform[actTransform];
    01738                 }
    01739         }
    01740         __finally{
    01741                 LeaveCriticalSection(&GlobalCriticalSection);
    01742         }
    01743     return aTrans;
    01744 }
    01745
    01746 /* ______________________________________________________________________
    01747 CMWorldRef StoreTransform( CMWorldRef aRef );
    01748
    01749 Abstract:
    01750         The StoreTransform function stores the actual transform in the static array
    01751         in the critical section.
    01752
    01753 Parameter               Description
    01754         aRef            Ptr to the transform.
    01755
    01756 Returns
    01757         valid (255 < handle < 65536 ) handle of the transform
    01758 ________________________________________________________________ */
    01759 CMWorldRef StoreTransform( CMWorldRef aRef )
    01760 {
    01761         long i;
    01762     CMWorldRef cw = NULL;
    01763
    01764         __try {
    01765                 EnterCriticalSection(&GlobalCriticalSection);
    01766
    01767                 if( IndexTransform >= 1000 )return (HCMTRANSFORM)ERROR_NOT_ENOUGH_MEMORY;
    01768                 for( i = 0; i<IndexTransform ; i++ ){
    01769                         if( TheTransform[i] == 0 ){
    01770                                 TheTransform[i] = aRef;
    01771                                 cw = (CMWorldRef)(ULONG_PTR)(i + 256 );
    01772                         }
    01773                 }
    01774                 if( i >= IndexTransform ){
    01775                         TheTransform[IndexTransform] = aRef;
    01776                         IndexTransform++;
    01777                         cw = (CMWorldRef)(ULONG_PTR)(IndexTransform - 1 + 256);
    01778                 }
    01779         }
    01780         __finally{
    01781                 LeaveCriticalSection(&GlobalCriticalSection);
    01782         }
    01783
    01784    return cw;
    01785 }
    01786
    01787 BOOL  WINAPI CMConvertColorNameToIndex( HPROFILE aProf, LPCOLOR_NAME aColorNameArr, LPDWORD aDWordArr, DWORD count )
    01788 {
    01789         CMError err;
    01790
    01791         err = CMConvNameToIndexProfile( aProf, aColorNameArr, aDWordArr, count );
    01792         if( err ){
    01793                 SetLastError( err );
    01794                 return 0;
    01795         }
    01796         return 1;
    01797 }
    01798
    01799 BOOL  WINAPI CMConvertIndexToColorName( HPROFILE aProf, LPDWORD aDWordArr, LPCOLOR_NAME aColorNameArr, DWORD count )
    01800 {
    01801         long matchErr;
    01802
    01803         matchErr = CMConvIndexToNameProfile( aProf, aDWordArr, aColorNameArr, count );
    01804         if( matchErr ){
    01805                 SetLastError( matchErr );
    01806                 return 0;
    01807         }
    01808         return 1;
    01809 }
    01810
    01811 BOOL  WINAPI CMGetNamedProfileInfo( HPROFILE aProf, LPNAMED_PROFILE_INFO Info )
    01812 {
    01813         long matchErr;
    01814
    01815         matchErr = CMGetNamedProfileInfoProfile( aProf, (pCMNamedProfileInfo)Info );
    01816         if( matchErr ){
    01817                 SetLastError( matchErr );
    01818                 return 0;
    01819         }
    01820         return 1;
    01821 }
    01822
    01823 /*
    01824 CMBitmapColorSpace CMGetColorType( COLORTYPE bmMode, long *pixelSize )
    01825 {
    01826         switch(  bmMode ){
    01827         case COLOR_GRAY:
    01828                 *pixelSize = 16;
    01829                 return cm16PerChannelPacking + cmGraySpace;
    01830                 break;
    01831         case COLOR_     :
    01832         case COLOR_XYZ:
    01833         case COLOR_Yxy:
    01834         case COLOR_Lab:
    01835         case COLOR_3_CHANNEL:
    01836         case COLOR_CMYK:
    01837                 *pixelSize = 64;
    01838                 return cm16PerChannelPacking + cmRGBSpace;
    01839                 break;
    01840         case COLOR_5_CHANNEL:
    01841         case COLOR_6_CHANNEL:
    01842         case COLOR_7_CHANNEL:
    01843         case COLOR_8_CHANNEL:
    01844                 *pixelSize = 64;
    01845                 return cm8PerChannelPacking + cmMCFiveSpace + bmMode - COLOR_5_CHANNEL;
    01846                 break;
    01847         default:
    01848                 *pixelSize = 0;
    01849                 return 0;
    01850         }
    01851 }
    01852
    01853 #define CMS_x555WORD      0x00000000
    01854 #define CMS_565WORD       0x00000001
    01855 #define CMS_RGBTRIPLETS   0x00000002
    01856 #define CMS_BGRTRIPLETS   0x00000004
    01857 #define CMS_XRGBQUADS     0x00000008
    01858 #define CMS_XBGRQUADS     0x00000010
    01859 #define CMS_QUADS         0x00000020
    01860
    01861 CMBitmapColorSpace CMGetCMSType( DWORD bmMode, long *pixelSize )
    01862 {
    01863         if(  bmMode & CMS_x555WORD ){
    01864                 *pixelSize = 16;
    01865                 return cmWord5ColorPacking + cmRGBSpace;
    01866         }
    01867         else if( bmMode & CMS_RGBTRIPLETS ){
    01868                 *pixelSize = 24;
    01869                 return cm8PerChannelPacking + cmRGBSpace;
    01870         }
    01871         else if( bmMode &  CMS_BGRTRIPLETS ){
    01872                 *pixelSize = 24;
    01873                 return cm8PerChannelPacking + cmBGRSpace;
    01874         }
    01875         else if( bmMode &  CMS_XRGBQUADS ){
    01876                 *pixelSize = 32;
    01877                 return cmLong8ColorPacking + cmRGBSpace;
    01878         }
    01879         else if( bmMode &  CMS_XBGRQUADS ){
    01880                 *pixelSize = 32;
    01881                 return cmLong8ColorPacking + cmBGRSpace;
    01882         }
    01883         else if( bmMode &  CMS_QUADS     ){
    01884                 *pixelSize = 32;
    01885                 return cmLong8ColorPacking + cmCMYKSpace;
    01886         }
    01887         else{
    01888                 *pixelSize = 0;
    01889                 return 0;
    01890         }
    01891 }
    01892 */
    01893
    01894
    01895