test: csprof.c Source File

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

# csprof.c

Go to the documentation of this file.

    00001 #include "generic.h"
    00002
    00003 //#pragma code_seg(_ICM2SEG)
    00004 #pragma optimize("",off)
    00005
    00006 #define TempBfSize 128
    00007 #define LINELENG   128
    00008
    00009 static  char    NewLine[]       = "\n" ;
    00010 static  char    ASCII85DecodeBegine[] = "<~";
    00011 static  char    ASCII85DecodeEnd[] = "~> cvx exec ";
    00012
    00013 //******************************************************************
    00014 //   Local functions to deal with output to the memory buffer
    00015
    00016 static  SINT    CPLastError;
    00017
    00018 BOOL    EXTERN     SetCPLastError(SINT LastError)
    00019 {
    00020     CPLastError = LastError;
    00021     return(TRUE);
    00022 }
    00023
    00024 SINT    EXTERN     GetCPLastError()
    00025 {
    00026     return(CPLastError);
    00027 }
    00028
    00029 BOOL    EXTERN MemAlloc(SINT Size, HGLOBAL FAR *hMemory, LPMEMPTR lpMH)
    00030 {
    00031     HGLOBAL hMem;
    00032     LPVOID  lpMem;
    00033
    00034     *hMemory = 0;
    00035     if(lpMH == NULL )
    00036     {
    00037         SetCPLastError(CP_NULL_POINTER_ERR);
    00038         return(FALSE);
    00039     }
    00040
    00041     hMem = GlobalAlloc(GHND, Size) ;
    00042     if(hMem == 0 )
    00043     {
    00044         SetCPLastError(CP_MEMORY_ALLOC_ERR);
    00045         return(FALSE);
    00046     }
    00047
    00048     lpMem = GlobalLock(hMem);
    00049     if(lpMem == NULL )
    00050     {
    00051         GlobalFree(hMem);
    00052         SetCPLastError(CP_MEMORY_ALLOC_ERR);
    00053         return(FALSE);
    00054     }
    00055     *lpMH = (MEMPTR)lpMem ;
    00056     *hMemory = hMem;
    00057     return (TRUE);
    00058 }
    00059
    00060 BOOL    EXTERN MemFree(HGLOBAL hMem)
    00061 {
    00062     if(hMem == NULL )
    00063     {
    00064         SetCPLastError(CP_NULL_POINTER_ERR);
    00065         return(FALSE);
    00066     }
    00067
    00068     GlobalUnlock(hMem);
    00069     GlobalFree(hMem) ;
    00070     return(TRUE);
    00071 }
    00072
    00073 //******************************************************************
    00074 //      Low-level Profile functions - used for individual tag access
    00075 //******************************************************************
    00076
    00077 BOOL    EXTERN LoadCP(LPCSTR filename, HGLOBAL FAR *phMem, LPCHANDLE lpCP)
    00078 {
    00079     icHeader    CPHeader;
    00080     HFILE       hFile;
    00081     SINT        Res, CPSize;
    00082     MEMPTR      mpCP;
    00083     OFSTRUCT    OFStruct;
    00084
    00085     *phMem = 0;
    00086     if (lpCP == NULL)
    00087     {
    00088         SetCPLastError(CP_NULL_POINTER_ERR);
    00089         return(FALSE);
    00090     }
    00091
    00092     hFile = OpenFile(filename, &OFStruct, OF_READ );
    00093     if( hFile == HFILE_ERROR )
    00094     {
    00095         SetCPLastError(CP_FILE_OPEN_ERR);
    00096         return(FALSE);
    00097     }
    00098
    00099     Res = _lread(hFile, (LPVOID) &CPHeader, sizeof(CPHeader));
    00100     if( (Res == HFILE_ERROR) ||
    00101         (Res != sizeof(CPHeader)) )
    00102     {
    00103         _close(hFile);
    00104         SetCPLastError(CP_FILE_READ_ERR);
    00105         return(FALSE);
    00106     }
    00107
    00108     // Make the initial check for validity of the profile
    00109     if( SigtoCSIG(CPHeader.magic) != icMagicNumber )
    00110     {
    00111         _close(hFile);
    00112         SetCPLastError(CP_FORMAT_ERR);
    00113         return(FALSE);
    00114     }
    00115
    00116     CPSize = ui32toSINT(CPHeader.size);
    00117     if( MemAlloc(CPSize, phMem, (LPMEMPTR) &mpCP) )
    00118     {
    00119
    00120         *lpCP = (CHANDLE) mpCP;  // Put the memory pointer as  handle
    00121         // Read profile into  memory
    00122          _lseek(hFile, 0L, SEEK_SET);
    00123
    00124         while(CPSize)
    00125         {
    00126             Res = _lread(hFile, (LPVOID) mpCP, 4096);
    00127             if (Res == HFILE_ERROR)
    00128             {
    00129                 _close(hFile);
    00130                 SetCPLastError(CP_FILE_READ_ERR);
    00131                 return(FALSE);
    00132             }
    00133             mpCP    += Res;
    00134             CPSize  -= Res;
    00135         }
    00136     }else
    00137     {
    00138         *phMem = 0;
    00139         _close(hFile);
    00140         return(FALSE);
    00141     }
    00142     _close(hFile);
    00143     return (TRUE);
    00144 }
    00145
    00146 #ifdef ICMDLL
    00147 //******************************************************************
    00148 //      Low-level Profile functions - used for individual tag access
    00149 //******************************************************************
    00150 BOOL    EXTERN LoadCP32(LPCSTR filename, HGLOBAL *phMem, LPCHANDLE lpCP)
    00151 {
    00152     icHeader    CPHeader;
    00153     HANDLE      hFile;
    00154     SINT        Res, CPSize;
    00155     MEMPTR      mpCP;
    00156     BOOL        Success;
    00157
    00158     if (lpCP == NULL)
    00159     {
    00160         SetCPLastError(CP_NULL_POINTER_ERR);
    00161         return(FALSE);
    00162     }
    00163     hFile = CreateFile(filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
    00164     if( hFile == INVALID_HANDLE_VALUE )
    00165     {
    00166         SetCPLastError(CP_FILE_OPEN_ERR);
    00167         return(FALSE);
    00168     }
    00169
    00170     Success = ReadFile(hFile, (LPVOID) &CPHeader, sizeof(CPHeader), &Res, NULL);
    00171     if( ( !Success ) || (Res != sizeof(CPHeader)) )
    00172     {
    00173         CloseHandle(hFile);
    00174         SetCPLastError(CP_FILE_READ_ERR);
    00175         return(FALSE);
    00176     }
    00177
    00178     // Make the initial check for validity of the profile
    00179     if( SigtoCSIG(CPHeader.magic) != icMagicNumber )
    00180     {
    00181         CloseHandle(hFile);
    00182         SetCPLastError(CP_FORMAT_ERR);
    00183         return(FALSE);
    00184     }
    00185
    00186     CPSize = ui32toSINT(CPHeader.size);
    00187     if( MemAlloc(CPSize, phMem, (LPMEMPTR) &mpCP) )
    00188     {
    00189
    00190         *lpCP = (CHANDLE) mpCP;  // Put the memory pointer as  handle
    00191         // Read profile into  memory
    00192         SetFilePointer(hFile, 0L, NULL, FILE_BEGIN);
    00193         Success = ReadFile(hFile, (LPVOID) (LPVOID)mpCP, CPSize, &Res, NULL);
    00194         if (!Success)
    00195         {
    00196             CloseHandle(hFile);
    00197             SetCPLastError(CP_FILE_READ_ERR);
    00198             return(FALSE);
    00199         }
    00200     }else
    00201     {
    00202         CloseHandle(hFile);
    00203         return(FALSE);
    00204     }
    00205     CloseHandle(hFile);
    00206     return (TRUE);
    00207 }
    00208 #endif
    00209
    00210 BOOL    EXTERN FreeCP(HGLOBAL hMem)
    00211 {
    00212     return( MemFree(hMem) );
    00213 }
    00214
    00215
    00216 BOOL    EXTERN GetCPElementCount(CHANDLE CP, LPSINT lpCount)
    00217 {
    00218     lpcpTagList lpTL;
    00219     if (lpCount == NULL)
    00220     {
    00221         SetCPLastError(CP_NULL_POINTER_ERR);
    00222         return(FALSE);
    00223     }
    00224     lpTL = (lpcpTagList) &(((lpcpProfile)CP)->count);
    00225     *lpCount = ui32toSINT(lpTL->count);
    00226     return(TRUE);
    00227 }
    00228
    00229
    00230 BOOL    EXTERN GetCPElementInfo(CHANDLE CP, SINT Index,
    00231                                 LPMEMPTR lpTagData, LPMEMPTR lpElemData)
    00232 {
    00233     SINT    Count;
    00234     lpcpTagList lpTL;
    00235
    00236     if ( (lpTagData == NULL) || (lpElemData == NULL) )
    00237     {
    00238         SetCPLastError(CP_NULL_POINTER_ERR);
    00239         return(FALSE);
    00240     }
    00241
    00242     lpTL = (lpcpTagList) &(((lpcpProfile)CP)->count);
    00243     Count   = ui32toSINT(lpTL->count);
    00244     if ( Count <= Index )
    00245     {
    00246         SetCPLastError(CP_OUT_OF_RANGE_ERR);
    00247         return(FALSE);
    00248     }
    00249     *lpTagData      = ((MEMPTR) &(lpTL->tags[0])) + (Index * sizeof(icTag)) ;
    00250     *lpElemData     = ((MEMPTR) CP) +
    00251                                 ui32toSINT( ((lpcpTag)*lpTagData)->offset);
    00252     return(TRUE);
    00253 }
    00254
    00255
    00256 /* Checks if the profile has all required fields  for
    00257     this specific type of the color profile             */
    00258 BOOL    EXTERN ValidateCP(CHANDLE CP)
    00259 {
    00260     BOOL    Result;
    00261     CSIG    ProfileClass;
    00262
    00263     if(GetCPClass(CP, (LPCSIG) &ProfileClass) )
    00264     {
    00265         // All profiles must have a ProfileDescription and
    00266         //  a Copyright  tags.
    00267
    00268         if( !DoesCPTagExist(CP, icSigProfileDescriptionTag) ||
    00269             !DoesCPTagExist(CP, icSigCopyrightTag ) )
    00270         {
    00271             SetCPLastError(CP_NOT_FOUND_ERR);
    00272             return(FALSE);
    00273         }
    00274
    00275         // All profiles, except Device-link, must have a mediaWhitePoint Tag
    00276         switch( ProfileClass )
    00277         {
    00278             case     icSigLinkClass :        /* 'link' */
    00279                 if( DoesCPTagExist(CP, icSigAToB0Tag) &&
    00280                     DoesCPTagExist(CP, icSigProfileSequenceDescTag)
    00281                   )
    00282                 {
    00283                     Result = TRUE;
    00284                 }else
    00285                 {
    00286                     Result = FALSE;
    00287                 }
    00288                 break;
    00289
    00290             case     icSigInputClass:       /* 'scnr' */
    00291                 if( DoesCPTagExist(CP, icSigGrayTRCTag) ||
    00292                     DoesCPTagExist(CP, icSigAToB0Tag)      )
    00293                 {
    00294                     Result = TRUE;
    00295                 }else if( DoesCPTagExist(CP, icSigGreenColorantTag) )
    00296                 {
    00297                     if( DoesCPTagExist(CP, icSigRedColorantTag) &&
    00298                         DoesCPTagExist(CP, icSigBlueColorantTag) &&
    00299                         DoesCPTagExist(CP, icSigRedTRCTag) &&
    00300                         DoesCPTagExist(CP, icSigGreenTRCTag) &&
    00301                         DoesCPTagExist(CP, icSigBlueTRCTag)
    00302                       )
    00303                     {
    00304                         Result = TRUE;
    00305                     }else
    00306                     {
    00307                         Result = FALSE;
    00308                     }
    00309                 }else
    00310                 {
    00311                     Result = FALSE;
    00312                 }
    00313                 Result  &= DoesCPTagExist(CP, icSigMediaWhitePointTag);
    00314                 break;
    00315
    00316             case     icSigDisplayClass:     /* 'mntr' */
    00317                 if( DoesCPTagExist(CP, icSigGrayTRCTag) )
    00318                 {
    00319                     Result = TRUE;
    00320                 }else if( DoesCPTagExist(CP, icSigGreenColorantTag) )
    00321                 {
    00322                     if( DoesCPTagExist(CP, icSigRedColorantTag) &&
    00323                         DoesCPTagExist(CP, icSigBlueColorantTag) &&
    00324                         DoesCPTagExist(CP, icSigRedTRCTag) &&
    00325                         DoesCPTagExist(CP, icSigGreenTRCTag) &&
    00326                         DoesCPTagExist(CP, icSigBlueTRCTag)
    00327                       )
    00328                     {
    00329                         Result = TRUE;
    00330                     }else
    00331                     {
    00332                         Result = FALSE;
    00333                     }
    00334                 }else
    00335                 {
    00336                     Result = FALSE;
    00337                 }
    00338                 Result  &= DoesCPTagExist(CP, icSigMediaWhitePointTag);
    00339                 break;
    00340
    00341             case     icSigOutputClass:      /* 'prtr' */
    00342                 if( DoesCPTagExist(CP, icSigGrayTRCTag) )
    00343                 {
    00344                     Result = TRUE;
    00345                 }else if( DoesCPTagExist(CP, icSigAToB0Tag) &&
    00346                           DoesCPTagExist(CP, icSigAToB1Tag) &&
    00347                           DoesCPTagExist(CP, icSigAToB2Tag) &&
    00348                           DoesCPTagExist(CP, icSigBToA0Tag) &&
    00349                           DoesCPTagExist(CP, icSigBToA1Tag) &&
    00350                           DoesCPTagExist(CP, icSigBToA2Tag) &&
    00351                           DoesCPTagExist(CP, icSigGamutTag)
    00352                         )
    00353                 {
    00354                     Result = TRUE;
    00355                 }else
    00356                 {
    00357                     Result = FALSE;
    00358                 }
    00359                 Result  &= DoesCPTagExist(CP, icSigMediaWhitePointTag);
    00360                 break;
    00361
    00362             case     icSigAbstractClass:    /* 'abst' */
    00363                 if( DoesCPTagExist(CP, icSigAToB0Tag) )
    00364                 {
    00365                     Result = TRUE;
    00366                 }else
    00367                 {
    00368                     Result = FALSE;
    00369                 }
    00370                 Result  &= DoesCPTagExist(CP, icSigMediaWhitePointTag);
    00371                 break;
    00372
    00373             case     icSigColorSpaceClass:  /* 'spac' */
    00374                 if( DoesCPTagExist(CP, icSigAToB0Tag) &&
    00375                     DoesCPTagExist(CP, icSigBToA0Tag)
    00376                   )
    00377                 {
    00378                     Result = TRUE;
    00379                 }else
    00380                 {
    00381                     Result = FALSE;
    00382                 }
    00383                 Result  &= DoesCPTagExist(CP, icSigMediaWhitePointTag);
    00384                 break;
    00385
    00386             default:
    00387                 Result = FALSE;
    00388                 break;
    00389         }
    00390     }else
    00391     {
    00392         return(FALSE);
    00393     }
    00394     if( Result == FALSE )
    00395     {
    00396         SetCPLastError(CP_NOT_FOUND_ERR);
    00397     }
    00398     return(Result);
    00399 }
    00400
    00401 BOOL    EXTERN DoesCPTagExist(CHANDLE CP, CSIG CPTag)
    00402 {
    00403     SINT    Count;
    00404     MEMPTR   Data;
    00405     lpcpTagList lpTL;
    00406
    00407     lpTL = (lpcpTagList) &(((lpcpProfile)CP)->count);
    00408     Count   = ui32toSINT(lpTL->count);
    00409     Data    = (MEMPTR)  &(lpTL->tags[0]) ;
    00410     while ( Count-- )
    00411     {
    00412         if(  SigtoCSIG( ((lpcpTag)Data)->sig) == CPTag )
    00413         {
    00414             return(TRUE);
    00415         }else
    00416         {
    00417             Data    += sizeof(icTag);   // Bump pointer to the next tag
    00418         }
    00419     }
    00420     return(FALSE);
    00421 }
    00422
    00423
    00424 BOOL    EXTERN GetCPTagIndex(CHANDLE CP, CSIG CPTag, LPSINT lpIndex)
    00425 {
    00426     SINT    Count;
    00427     MEMPTR   Data;
    00428     SINT    i;
    00429     lpcpTagList lpTL;
    00430
    00431     if (lpIndex == NULL)
    00432     {
    00433         SetCPLastError(CP_NULL_POINTER_ERR);
    00434         return(FALSE);
    00435     }
    00436
    00437     lpTL = (lpcpTagList) &(((lpcpProfile)CP)->count);
    00438     Count   = ui32toSINT(lpTL->count);
    00439     Data    = (MEMPTR)  &(lpTL->tags[0]) ;
    00440
    00441     for (i = 0; i < Count; i++ )
    00442     {
    00443         if(  SigtoCSIG( ((lpcpTag)Data)->sig) == CPTag )
    00444         {
    00445             *lpIndex = i;
    00446             return(TRUE);
    00447         }else
    00448         {
    00449             Data    += sizeof(icTag);   // Bump pointer to the next tag
    00450         }
    00451     }
    00452
    00453     SetCPLastError(CP_NOT_FOUND_ERR);
    00454     return(FALSE);
    00455 }
    00456
    00457
    00458
    00459 BOOL    EXTERN GetCPTagSig(CHANDLE CP, SINT Index, LPCSIG lpCPTag)
    00460 {
    00461     MEMPTR   TagData, ElemData;
    00462     if (lpCPTag == NULL)
    00463     {
    00464         SetCPLastError(CP_NULL_POINTER_ERR);
    00465         return(FALSE);
    00466     }
    00467     if ( GetCPElementInfo(CP, Index, (LPMEMPTR) &TagData,
    00468             (LPMEMPTR) &ElemData) )
    00469     {
    00470         *lpCPTag    = SigtoCSIG( ((lpcpTag)TagData)->sig ) ;
    00471     }else
    00472     {
    00473         return(FALSE);
    00474     }
    00475     return(TRUE);
    00476 }
    00477
    00478 //***************************************************************
    00479 //      Function applicable to the elements
    00480 //
    00481 //***************************************************************
    00482
    00483 BOOL    EXTERN GetCPElementType(CHANDLE CP, SINT Index, LPCSIG lpCSig)
    00484 {
    00485     MEMPTR   TagData, ElemData;
    00486     if ( GetCPElementInfo(CP, Index, (LPMEMPTR) &TagData,
    00487             (LPMEMPTR) &ElemData) )
    00488     {
    00489         *lpCSig    = SigtoCSIG( ((lpcpTagBase)ElemData)->sig ) ;
    00490     }else
    00491     {
    00492         return(FALSE);
    00493     }
    00494     return(TRUE);
    00495 }
    00496
    00497
    00498
    00499 BOOL    EXTERN GetCPElementSize(CHANDLE CP, SINT Index, LPSINT lpSize)
    00500 {
    00501     MEMPTR   TagData, ElemData;
    00502     if (lpSize == NULL)
    00503     {
    00504         SetCPLastError(CP_NULL_POINTER_ERR);
    00505         return(FALSE);
    00506     }
    00507
    00508     if ( GetCPElementInfo(CP, Index, (LPMEMPTR) &TagData,
    00509             (LPMEMPTR) &ElemData) )
    00510     {
    00511         *lpSize     = ui32toSINT( ((lpcpTag)TagData)->size );
    00512     }else
    00513     {
    00514         return(FALSE);
    00515     }
    00516
    00517     return(TRUE);
    00518 }
    00519
    00520 BOOL    EXTERN GetCPElementDataSize(CHANDLE CP, SINT Index, LPSINT lpSize)
    00521 {
    00522     MEMPTR  TagData, ElemData;
    00523     if (lpSize == NULL)
    00524     {
    00525         SetCPLastError(CP_NULL_POINTER_ERR);
    00526         return(FALSE);
    00527     }
    00528
    00529     if ( GetCPElementInfo(CP, Index, (LPMEMPTR) &TagData,
    00530             (LPMEMPTR) &ElemData) )
    00531     {
    00532 //  Changed by jjia 8/24/95
    00533 //        *lpSize     = ui32toSINT( ((lpcpTag)TagData)->size ) -
    00534 //                                             sizeof(lpcpTagBase);
    00535     *lpSize    = ui32toSINT( ((lpcpTag)TagData)->size) -
    00536                     sizeof(icTagBase) - sizeof(icUInt32Number);
    00537     }else
    00538     {
    00539         return(FALSE);
    00540     }
    00541
    00542     return(TRUE);
    00543 }
    00544
    00545 //***************************************************************
    00546 //  The difference between GetCPElement and GetCPElementData
    00547 //  is that GetCPElement reads all fields of the element,
    00548 //  including the data tag, reserved fields and element data,
    00549 //  while GetCPElementData only reads the actual data.
    00550 //  Number of bytes that are required to hold the whole data element can be
    00551 //  obtained by calling the function GetCPElementSize().
    00552 //  The actulal number of data bytes is determined by
    00553 //  the call to GetCPElementDataSize().
    00554 //***************************************************************
    00555 BOOL    EXTERN GetCPElement(CHANDLE CP, SINT Index,
    00556                                MEMPTR lpData, SINT Size)
    00557 {
    00558     SINT        ElemSize;
    00559     MEMPTR      TagData, ElemData;
    00560     if (lpData == NULL)
    00561     {
    00562         SetCPLastError(CP_NULL_POINTER_ERR);
    00563         return(FALSE);
    00564     }
    00565
    00566     if ( !GetCPElementInfo(CP, Index, (LPMEMPTR) &TagData,
    00567             (LPMEMPTR) &ElemData) )
    00568     {
    00569         return(FALSE);
    00570     }
    00571     ElemSize    = ui32toSINT( ((lpcpTag)TagData)->size);
    00572     if(ElemSize > Size )
    00573     {
    00574         SetCPLastError(CP_NO_MEMORY_ERR);
    00575         return(FALSE);
    00576     }
    00577     MemCopy(lpData, ElemData, ElemSize);
    00578     return(TRUE);
    00579
    00580 }
    00581
    00582
    00583 BOOL    EXTERN GetCPElementData(CHANDLE CP, SINT Index,
    00584                                 MEMPTR lpData, SINT Size)
    00585 {
    00586     SINT     ElemSize;
    00587     MEMPTR   TagData, ElemData;
    00588     if (lpData == NULL)
    00589     {
    00590         SetCPLastError(CP_NULL_POINTER_ERR);
    00591         return(FALSE);
    00592     }
    00593
    00594     if ( !GetCPElementInfo(CP, Index, (LPMEMPTR) &TagData,
    00595             (LPMEMPTR) &ElemData) )
    00596     {
    00597         return(FALSE);
    00598     }
    00599 //  Changed by jjia 8/24/95
    00600 //    ElemData    +=  sizeof(lpcpTagBase);
    00601 //    ElemSize    = ui32toSINT( ((lpcpTag)TagData)->size) -
    00602 //                     sizeof(lpcpTagBase);
    00603     ElemData    +=  sizeof(icTagBase) + sizeof(icUInt32Number);
    00604     ElemSize    = ui32toSINT( ((lpcpTag)TagData)->size) -
    00605                     sizeof(icTagBase) - sizeof(icUInt32Number);
    00606
    00607     if(ElemSize > Size )
    00608     {
    00609         SetCPLastError(CP_NO_MEMORY_ERR);
    00610         return(FALSE);
    00611     }
    00612
    00613     MemCopy(lpData, ElemData, ElemSize);
    00614     return(TRUE);
    00615 }
    00616
    00617 // Check the data format is binary or ascii    8/22/95  jjia
    00618
    00619 BOOL    EXTERN GetCPElementDataType(CHANDLE CP, SINT Index, long far *lpDataType)
    00620 {
    00621     MEMPTR   TagData, ElemData;
    00622
    00623     if (lpDataType == NULL)
    00624     {
    00625         SetCPLastError(CP_NULL_POINTER_ERR);
    00626         return(FALSE);
    00627     }
    00628
    00629     if ( !GetCPElementInfo(CP, Index, (LPMEMPTR) &TagData,
    00630             (LPMEMPTR) &ElemData) )
    00631     {
    00632         return(FALSE);
    00633     }
    00634     ElemData    +=  sizeof(icTagBase);
    00635     *lpDataType = ui32toSINT( ((icData __huge *)ElemData)->dataFlag);
    00636     return (TRUE);
    00637 }
    00638
    00639 BOOL    EXTERN ValidateCPElement(CHANDLE CP, SINT Index)
    00640 {
    00641     CSIG    TagSig, DataSig;
    00642     BOOL    Result;
    00643     if( GetCPTagSig(CP, Index, (LPCSIG) &TagSig) &&
    00644         GetCPElementType(CP, Index, (LPCSIG) &DataSig) )
    00645     {
    00646         switch(TagSig)
    00647         {
    00648             case     icSigAToB0Tag:
    00649             case     icSigAToB1Tag:
    00650             case     icSigAToB2Tag:
    00651             case     icSigBToA0Tag:
    00652             case     icSigBToA1Tag:
    00653             case     icSigBToA2Tag:
    00654             case     icSigGamutTag:
    00655             case     icSigPreview0Tag:
    00656             case     icSigPreview1Tag:
    00657             case     icSigPreview2Tag:
    00658                 Result = (DataSig == icSigLut16Type) ||
    00659                          (DataSig == icSigLut8Type) ;
    00660                 break;
    00661
    00662             case     icSigRedColorantTag:
    00663             case     icSigGreenColorantTag:
    00664             case     icSigBlueColorantTag:
    00665             case     icSigLuminanceTag:
    00666             case     icSigMediaBlackPointTag:
    00667             case     icSigMediaWhitePointTag:
    00668                 Result = (DataSig == icSigXYZType);
    00669                 break;
    00670
    00671             case     icSigRedTRCTag:
    00672             case     icSigGreenTRCTag:
    00673             case     icSigBlueTRCTag:
    00674             case     icSigGrayTRCTag:
    00675                 Result = (DataSig == icSigCurveType);
    00676                 break;
    00677
    00678             case     icSigPs2CRD0Tag:
    00679             case     icSigPs2CRD1Tag:
    00680             case     icSigPs2CRD2Tag:
    00681             case     icSigPs2CRD3Tag:
    00682             case     icSigPs2CSATag:
    00683             case     icSigPs2Intent0Tag:
    00684             case     icSigPs2Intent1Tag:
    00685             case     icSigPs2Intent2Tag:
    00686             case     icSigPs2Intent3Tag:
    00687                 Result = (DataSig == icSigDataType);
    00688                 break;
    00689
    00690             case     icSigCharTargetTag:
    00691             case     icSigCopyrightTag:
    00692                 Result = (DataSig == icSigTextType);
    00693                 break;
    00694
    00695             case     icSigCalibrationDateTimeTag:
    00696                 Result = (DataSig == icSigDateTimeType);
    00697                 break;
    00698
    00699             case     icSigDeviceMfgDescTag:
    00700             case     icSigDeviceModelDescTag:
    00701             case     icSigProfileDescriptionTag:
    00702             case     icSigScreeningDescTag:
    00703             case     icSigViewingCondDescTag:
    00704                 Result = (DataSig == icSigTextDescriptionType);
    00705                 break;
    00706
    00707             case     icSigMeasurementTag:
    00708                 Result = (DataSig == icSigMeasurementTag);
    00709                 break;
    00710
    00711             case     icSigNamedColorTag:
    00712                 Result = (DataSig == icSigNamedColorTag);
    00713                 break;
    00714
    00715             case      icSigProfileSequenceDescTag:
    00716                 Result = (DataSig == icSigProfileSequenceDescTag);
    00717                 break;
    00718
    00719             case     icSigScreeningTag:
    00720                 Result = (DataSig == icSigScreeningTag);
    00721                 break;
    00722
    00723             case     icSigTechnologyTag:
    00724                 Result = (DataSig == icSigSignatureType);
    00725                 break;
    00726
    00727             case     icSigUcrBgTag:
    00728                 Result = (DataSig == icSigUcrBgTag);
    00729                 break;
    00730
    00731             case     icSigViewingConditionsTag:
    00732                 Result = (DataSig == icSigViewingConditionsTag);
    00733                 break;
    00734
    00735             default:
    00736                 Result = TRUE;
    00737                 break;
    00738         }
    00739     }else
    00740     {
    00741         Result = FALSE;
    00742     }
    00743     return(Result);
    00744 }
    00745
    00746 //******************************************************************
    00747 // Functions that get all information from the Color Profile Header
    00748 //******************************************************************
    00749 BOOL    EXTERN GetCPSize(CHANDLE CP, LPSINT lpSize)
    00750 {
    00751     if (lpSize == NULL)
    00752     {
    00753         SetCPLastError(CP_NULL_POINTER_ERR);
    00754         return(FALSE);
    00755     }
    00756     *lpSize    = ui32toSINT( ((lpcpHeader)CP)->size);
    00757     return(TRUE);
    00758 }
    00759
    00760 BOOL    EXTERN GetCPCMMType(CHANDLE CP, LPCSIG lpType)
    00761 {
    00762     if (lpType == NULL)
    00763     {
    00764         SetCPLastError(CP_NULL_POINTER_ERR);
    00765         return(FALSE);
    00766     }
    00767     *lpType    = SigtoCSIG( ((lpcpHeader)CP)->cmmId);
    00768     return(TRUE);
    00769 }
    00770
    00771 BOOL    EXTERN GetCPVersion(CHANDLE CP, LPSINT lpVers)
    00772 {
    00773     if (lpVers == NULL)
    00774     {
    00775         SetCPLastError(CP_NULL_POINTER_ERR);
    00776         return(FALSE);
    00777     }
    00778     *lpVers    = ui32toSINT( ((lpcpHeader)CP)->version);
    00779     return(TRUE);
    00780 }
    00781
    00782 BOOL    EXTERN GetCPClass(CHANDLE CP, LPCSIG lpClass)
    00783 {
    00784     if (lpClass == NULL)
    00785     {
    00786         SetCPLastError(CP_NULL_POINTER_ERR);
    00787         return(FALSE);
    00788     }
    00789     *lpClass    = SigtoCSIG( ((lpcpHeader)CP)->deviceClass);
    00790     return(TRUE);
    00791 }
    00792
    00793 BOOL    EXTERN GetCPDevSpace(CHANDLE CP, LPCSIG lpInSpace)
    00794 {
    00795     if (lpInSpace == NULL)
    00796     {
    00797         SetCPLastError(CP_NULL_POINTER_ERR);
    00798         return(FALSE);
    00799     }
    00800     *lpInSpace    = SigtoCSIG( ((lpcpHeader)CP)->colorSpace);
    00801     return(TRUE);
    00802 }
    00803
    00804 BOOL    EXTERN GetCPConnSpace(CHANDLE CP, LPCSIG lpOutSpace)
    00805 {
    00806     if (lpOutSpace == NULL)
    00807     {
    00808         SetCPLastError(CP_NULL_POINTER_ERR);
    00809         return(FALSE);
    00810     }
    00811     *lpOutSpace    = SigtoCSIG( ((lpcpHeader)CP)->pcs);
    00812     return(TRUE);
    00813 }
    00814
    00815 BOOL    EXTERN GetCPTarget(CHANDLE CP, LPCSIG lpTarget)
    00816 {
    00817     if (lpTarget == NULL)
    00818     {
    00819         SetCPLastError(CP_NULL_POINTER_ERR);
    00820         return(FALSE);
    00821     }
    00822     *lpTarget    = SigtoCSIG( ((lpcpHeader)CP)->platform);
    00823     return(TRUE);
    00824 }
    00825
    00826 BOOL    EXTERN GetCPManufacturer(CHANDLE CP, LPCSIG lpManuf)
    00827 {
    00828     if (lpManuf == NULL)
    00829     {
    00830         SetCPLastError(CP_NULL_POINTER_ERR);
    00831         return(FALSE);
    00832     }
    00833     *lpManuf    = SigtoCSIG( ((lpcpHeader)CP)->manufacturer);
    00834     return(TRUE);
    00835 }
    00836
    00837 BOOL    EXTERN GetCPModel(CHANDLE CP, LPCSIG lpModel)
    00838 {
    00839     if (lpModel == NULL)
    00840     {
    00841         SetCPLastError(CP_NULL_POINTER_ERR);
    00842         return(FALSE);
    00843     }
    00844     *lpModel    = SigtoCSIG( ((lpcpHeader)CP)->model);
    00845     return(TRUE);
    00846 }
    00847
    00848 BOOL    EXTERN GetCPFlags(CHANDLE CP, LPSINT lpFlags)
    00849 {
    00850     if (lpFlags == NULL)
    00851     {
    00852         SetCPLastError(CP_NULL_POINTER_ERR);
    00853         return(FALSE);
    00854     }
    00855     *lpFlags    = ui32toSINT( ((lpcpHeader)CP)->flags);
    00856     return(TRUE);
    00857 }
    00858
    00859 BOOL    EXTERN GetCPRenderIntent(CHANDLE CP, LPSINT lpIntent)
    00860 {
    00861     if (lpIntent == NULL)
    00862     {
    00863         SetCPLastError(CP_NULL_POINTER_ERR);
    00864         return(FALSE);
    00865     }
    00866     *lpIntent    = ui32toSINT( ((lpcpHeader)CP)->renderingIntent);
    00867     return(TRUE);
    00868 }
    00869
    00870 BOOL    EXTERN GetCPWhitePoint(CHANDLE CP,  LPSFLOAT lpWP)
    00871 {
    00872     if (lpWP == NULL)
    00873     {
    00874         SetCPLastError(CP_NULL_POINTER_ERR);
    00875         return(FALSE);
    00876     }
    00877     lpWP[0]    = (SFLOAT) si16f16toSFLOAT( ((lpcpHeader)CP)->illuminant.X);
    00878     lpWP[1]    = (SFLOAT) si16f16toSFLOAT( ((lpcpHeader)CP)->illuminant.Y);
    00879     lpWP[2]    = (SFLOAT) si16f16toSFLOAT( ((lpcpHeader)CP)->illuminant.Z);
    00880     return(TRUE);
    00881 }
    00882
    00883 BOOL    EXTERN GetCPAttributes(CHANDLE CP, LPATTRIB lpAttributes)
    00884 {
    00885     return(TRUE);
    00886 }
    00887
    00888 BOOL    EXTERN GetCPMediaWhitePoint(CHANDLE cp,  LPSFLOAT lpMediaWP)
    00889 {
    00890     HGLOBAL   hTempMem;
    00891     SINT      TempSize;
    00892     MEMPTR    TempBuff;
    00893     MEMPTR    lpTable;
    00894     SINT      i, Index;
    00895
    00896     if (DoesCPTagExist (cp, icSigMediaWhitePointTag) &&
    00897         GetCPTagIndex (cp, icSigMediaWhitePointTag, (LPSINT) & Index) &&
    00898         GetCPElementSize (cp, Index, (LPSINT) & TempSize) &&
    00899         MemAlloc (TempSize, (HGLOBAL *) & hTempMem, (LPMEMPTR) & TempBuff) &&
    00900         GetCPElement (cp, Index, TempBuff, TempSize))
    00901     {
    00902         lpTable = (MEMPTR) & (((lpcpXYZType) TempBuff)->data);
    00903         for (i = 0; i < 3; i++)
    00904         {
    00905             lpMediaWP[i] = (SFLOAT) si16f16toSFLOAT (lpTable);
    00906             lpTable += sizeof (icS15Fixed16Number);
    00907         }
    00908         MemFree (hTempMem);
    00909         return (TRUE);
    00910     }
    00911     return (FALSE);
    00912 }
    00913
    00914 /***************************************************************************
    00915 *                               GetPS2ColorRenderingIntent
    00916 *  function:
    00917 *    this is the function which creates the Intent string
    00918 *    from the data supplied in the Profile that can be used
    00919 *    in --findcolorrendering-- operator.
    00920 *  prototype:
    00921 *       BOOL EXTERN GetPS2ColorRenderingIntent(
    00922 *                          char         *FileName,
    00923 *                          DWORD        Intent,
    00924 *                          MEMPTR       lpMem,
    00925 *                          LPDWORD      lpcbSize )
    00926 *  parameters:
    00927 *       FileName    --  Color Profile Filename
    00928 *       Intent      --  Intent
    00929 *       lpMem       --  Pointer to the memory block
    00930 *       lpcbSize        --  Size of the memory block
    00931 *                       Returns number of bytes required/transferred
    00932 *  returns:
    00933 *       BOOL        --  TRUE   if the function was successful,
    00934 *                       FALSE  otherwise.
    00935 ***************************************************************************/
    00936 BOOL EXTERN GetPS2ColorRenderingIntent(CHANDLE cp, DWORD Intent,
    00937                                        MEMPTR lpMem, LPDWORD lpcbSize)
    00938 {
    00939     SINT       Index;
    00940     SINT       Size;
    00941
    00942     if (!cp)
    00943         return FALSE;
    00944
    00945     Size = (SINT) *lpcbSize;
    00946     if( ( lpMem == NULL ) || ( Size == 0 ) )
    00947     {
    00948         lpMem = NULL;
    00949         Size = 0;
    00950         *lpcbSize = 0;
    00951     }
    00952
    00953     switch(Intent)
    00954     {
    00955         case icPerceptual:
    00956         if( DoesCPTagExist(cp, icSigPs2Intent0Tag) &&
    00957             GetCPTagIndex(cp, icSigPs2Intent0Tag, (LPSINT) &Index) &&
    00958             GetCPElementDataSize(cp, Index, (LPSINT) &Size) &&
    00959             ( ( lpMem == NULL ) ||
    00960                 GetCPElementData(cp, Index, lpMem, Size) ) )
    00961         {
    00962         }
    00963         break;
    00964
    00965         case icRelativeColorimetric:
    00966         if( DoesCPTagExist(cp, icSigPs2Intent1Tag) &&
    00967             GetCPTagIndex(cp, icSigPs2Intent1Tag, (LPSINT) &Index) &&
    00968             GetCPElementDataSize(cp, Index, (LPSINT) &Size) &&
    00969             ( ( lpMem == NULL ) ||
    00970                 GetCPElementData(cp, Index, lpMem, Size) ) )
    00971         {
    00972         }
    00973         break;
    00974
    00975         case icSaturation:
    00976         if( DoesCPTagExist(cp, icSigPs2Intent2Tag) &&
    00977             GetCPTagIndex(cp, icSigPs2Intent2Tag, (LPSINT) &Index) &&
    00978             GetCPElementDataSize(cp, Index, (LPSINT) &Size) &&
    00979             ( ( lpMem == NULL ) ||
    00980                 GetCPElementData(cp, Index, lpMem, Size ) )
    00981           )
    00982         {
    00983         }
    00984         break;
    00985         case icAbsoluteColorimetric:
    00986         if( DoesCPTagExist(cp, icSigPs2Intent3Tag) &&
    00987             GetCPTagIndex(cp, icSigPs2Intent3Tag, (LPSINT) &Index) &&
    00988             GetCPElementDataSize(cp, Index, (LPSINT) &Size) &&
    00989             ( ( lpMem == NULL ) ||
    00990                 GetCPElementData(cp, Index, lpMem, Size) ) )
    00991         {
    00992         }
    00993         break;
    00994         default:
    00995             Size = 0 ;
    00996         break;
    00997     }
    00998
    00999     if (Size != 0)
    01000     {
    01001         if (lpMem)
    01002         {
    01003             lpMem[Size] = '\0';
    01004         }
    01005         Size ++;
    01006         *lpcbSize = (DWORD) Size;
    01007         return (TRUE);
    01008     }
    01009     else
    01010     {
    01011         return(FALSE);
    01012     }
    01013 }
    01014
    01015 /***************************************************************************
    01016 *
    01017 *  Function to check if color matching mathod and icc profile type is
    01018 *       supported by driver.
    01019 *  parameters:
    01020 *
    01021 *  returns:
    01022 *       BOOL:   TRUE or FALSE.
    01023 *
    01024 ***************************************************************************/
    01025
    01026 #ifndef ICMDLL
    01027 BOOL EXTERN ValidColorSpace(LPPDEVICE lppd, LPICMINFO lpICMI)
    01028 {
    01029     icHeader    CPHeader;
    01030     HFILE       hFile;
    01031     SINT        Res;
    01032     CSIG        CPColorSpaceTag;
    01033
    01034     if (NULL == lpICMI)
    01035     {
    01036         return(FALSE);
    01037     }
    01038     hFile = _lopen(lpICMI->lcsDestFilename, READ);
    01039     if( hFile == HFILE_ERROR )
    01040     {
    01041         return(FALSE);
    01042     }
    01043
    01044     Res = _lread(hFile, (LPVOID) &CPHeader, sizeof(CPHeader));
    01045     _lclose(hFile);
    01046     if( (Res == HFILE_ERROR) || (Res != sizeof(CPHeader)) )
    01047     {
    01048         return(FALSE);
    01049     }
    01050
    01051     // Make the initial check for validity of the profile
    01052     if( SigtoCSIG(CPHeader.magic) != icMagicNumber )
    01053     {
    01054         return(FALSE);
    01055     }
    01056     // Make sure the profile is 'prtr'
    01057     if( SigtoCSIG(CPHeader.deviceClass) != icSigOutputClass )
    01058     {
    01059         return(FALSE);
    01060     }
    01061     CPColorSpaceTag = SigtoCSIG(CPHeader.colorSpace);
    01062
    01063     switch ( lppd->lpPSExtDevmode->dm.iColorMatchingMethod )
    01064     {
    01065         case COLOR_MATCHING_ON_HOST:
    01066             if ((CPColorSpaceTag == icSigCmyData) ||
    01067                 (CPColorSpaceTag == icSigRgbData))
    01068 //                (CPColorSpaceTag == icSigGrayData))
    01069             {
    01070                 return(FALSE);
    01071             }
    01072             break;
    01073             case COLOR_MATCHING_ON_PRINTER:
    01074             if ((CPColorSpaceTag == icSigCmyData))
    01075 //                (CPColorSpaceTag == icSigGrayData))
    01076             {
    01077                 return(FALSE);
    01078             }
    01079             break;
    01080         case COLOR_MATCHING_PRINTER_CALIBRATION:
    01081         default:
    01082             break;
    01083     }
    01084     return (TRUE);
    01085 }
    01086 #endif
    01087
    01088 //***************************************************************************
    01089 //
    01090 //      Set of functions to output data into memory buffer
    01091 //
    01092 //***************************************************************************
    01093
    01094
    01095 /***************************************************************************
    01096 *
    01097 *   Function to put the chunk of memory as string of Hex
    01098 *
    01099 ***************************************************************************/
    01100 SINT    WriteHexBuffer(MEMPTR lpMem, MEMPTR lpBuff, MEMPTR lpLineStart, DWORD dwBytes)
    01101 {
    01102     SINT    Res;
    01103     char    TempArray[TempBfSize];
    01104     MEMPTR  lpOldPtr = lpMem;
    01105
    01106     for ( ; dwBytes ; dwBytes-- )
    01107     {
    01108         Res = wsprintf( (MEMPTR)TempArray, (LPSTR) "%2.2x", *lpBuff );
    01109         *lpMem++ = TempArray[0];
    01110         *lpMem++ = TempArray[1];
    01111         lpBuff++;
    01112         if (((SINT)(lpMem - lpLineStart)) > MAX_LINELENG)
    01113         {
    01114             lpLineStart = lpMem;
    01115             lpMem += WriteObject(lpMem,  NewLine);
    01116         }
    01117     }
    01118     return( (SINT)(lpMem - lpOldPtr));
    01119 }
    01120
    01121 /***************************************************************************
    01122 *
    01123 *   Function to put the string into the buffer
    01124 *
    01125 ***************************************************************************/
    01126 SINT    WriteObject(MEMPTR lpMem, MEMPTR Obj)
    01127 {
    01128     SINT    Res;
    01129
    01130     Res = lstrlen(Obj);
    01131     MemCopy(lpMem, Obj, Res);
    01132     return( Res );
    01133 }
    01134
    01135 SINT    WriteObjectN(MEMPTR lpMem, MEMPTR Obj, SINT n)
    01136 {
    01137     MemCopy(lpMem, Obj, n);
    01138     return( n );
    01139 }
    01140 /***************************************************************************
    01141 *
    01142 *   Function to write the integer into the buffer
    01143 *
    01144 ***************************************************************************/
    01145 SINT WriteInt(MEMPTR lpMem, SINT Number)
    01146 {
    01147     SINT    Res;
    01148     char    TempArray[TempBfSize];
    01149
    01150     Res = wsprintf( (MEMPTR)TempArray, "%lu ", Number );
    01151     MemCopy(lpMem, TempArray, lstrlen(TempArray));
    01152     return( Res );
    01153 }
    01154
    01155 /***************************************************************************
    01156 *
    01157 *   Function to write the integer into the buffer as hex
    01158 *
    01159 ***************************************************************************/
    01160 SINT WriteHex(MEMPTR lpMem, SINT Number)
    01161 {
    01162     SINT    Res;
    01163     char    TempArray[TempBfSize];
    01164
    01165     Res = wsprintf( TempArray, "%2.2x", (int)(Number & 0x00FF) );
    01166     MemCopy(lpMem, TempArray, lstrlen(TempArray));
    01167     return( Res );
    01168 }
    01169
    01170 /***************************************************************************
    01171 *
    01172 *   Function to write the float into the buffer
    01173 *
    01174 ***************************************************************************/
    01175
    01176 SINT WriteFloat(MEMPTR lpMem, double dFloat)
    01177 {
    01178     char    cSign;
    01179     double  dInt ;
    01180     double  dFract ;
    01181     LONG    lFloat ;
    01182     SINT    Res;
    01183     char    TempArray[TempBfSize];
    01184
    01185     lFloat = (LONG) floor( dFloat * 10000.0 + 0.5);
    01186
    01187     dFloat = lFloat  / 10000.0 ;
    01188
    01189     dInt = floor(fabs(dFloat));
    01190     dFract =  fabs(dFloat) - dInt ;
    01191
    01192     cSign   = ' ' ;
    01193     if ( dFloat < 0 )
    01194     {
    01195         cSign   = '-' ;
    01196     }
    01197
    01198     Res = wsprintf( (LPSTR) TempArray, (LPSTR) "%c%d.%0.4lu ",
    01199        cSign, (WORD) dInt , (DWORD) (dFract *10000.0)  );
    01200     MemCopy(lpMem, TempArray, lstrlen(TempArray));
    01201     return ( Res );
    01202 }
    01203
    01204 /***************************************************************************
    01205 *
    01206 *   Function to write the string token into the buffer
    01207 *
    01208 ***************************************************************************/
    01209
    01210 SINT    WriteStringToken(MEMPTR lpMem, BYTE Token, SINT sNum)
    01211 {
    01212     *lpMem++ = Token;
    01213     *lpMem++ = (BYTE)((sNum & 0xFF00) >> 8);
    01214     *lpMem++ = (BYTE)(sNum & 0x00FF);
    01215     return (3);
    01216 }
    01217
    01218 /***************************************************************************
    01219 *
    01220 *   Function to write the Homogeneous Number Array token into the buffer
    01221 *
    01222 ***************************************************************************/
    01223
    01224 SINT    WriteHNAToken(MEMPTR lpMem, BYTE Token, SINT sNum)
    01225 {
    01226     *lpMem++ = Token;
    01227     *lpMem++ = 32;       // 16-bit fixed integer, high-order byte first
    01228     *lpMem++ = (BYTE)((sNum & 0xFF00) >> 8);
    01229     *lpMem++ = (BYTE)(sNum & 0x00FF);
    01230     return (4);
    01231 }
    01232
    01233 /***************************************************************************
    01234 *
    01235 *   Function to convert 2-bytes unsigned integer to 2-bytes signed
    01236 *   integer(-32768) and write them to the buffer. High byte first.
    01237 *
    01238 ***************************************************************************/
    01239
    01240 SINT    WriteIntStringU2S(MEMPTR lpMem, MEMPTR lpBuff, SINT sNum)
    01241 {
    01242     SINT    i;
    01243     SINT    Temp;
    01244
    01245     for (i = 0; i < sNum; i ++)
    01246     {
    01247         Temp = ui16toSINT( lpBuff) - 32768;
    01248         *lpMem++ = (BYTE)((Temp & 0xFF00) >> 8);
    01249         *lpMem++ = (BYTE)(Temp & 0x00FF);
    01250         lpBuff += sizeof(icUInt16Number);
    01251     }
    01252     return(sNum * 2);
    01253 }
    01254
    01255 /***************************************************************************
    01256 *
    01257 *   Function to convert 2-bytes unsigned integer to 2-bytes signed
    01258 *   integer(-32768) and write them to the buffer. Low-order byte first.
    01259 *
    01260 ***************************************************************************/
    01261
    01262 SINT    WriteIntStringU2S_L(MEMPTR lpMem, MEMPTR lpBuff, SINT sNum)
    01263 {
    01264     SINT    i;
    01265     SINT    Temp;
    01266
    01267     for (i = 0; i < sNum; i ++)
    01268     {
    01269         Temp = (SINT)*((PUSHORT)lpBuff) - 32768;
    01270         *lpMem++ = (BYTE)((Temp & 0xFF00) >> 8);
    01271         *lpMem++ = (BYTE)(Temp & 0x00FF);
    01272         lpBuff += sizeof(icUInt16Number);
    01273     }
    01274     return(sNum * 2);
    01275 }
    01276
    01277 /***************************************************************************
    01278 *
    01279 *   Function to put the chunk of memory into buffer
    01280 *
    01281 ***************************************************************************/
    01282 SINT    WriteByteString(MEMPTR lpMem, MEMPTR lpBuff, SINT sBytes)
    01283 {
    01284     SINT    i;
    01285
    01286     for (i = 0; i < sBytes; i ++)
    01287         *lpMem++ = *lpBuff++;
    01288
    01289     return(sBytes);
    01290 }
    01291
    01292 /***************************************************************************
    01293 *
    01294 *   Function to put the chunk of memory into buffer
    01295 *
    01296 ***************************************************************************/
    01297 SINT    WriteInt2ByteString(MEMPTR lpMem, MEMPTR lpBuff, SINT sBytes)
    01298 {
    01299     SINT    i;
    01300
    01301        for( i = 0; i < sBytes ; i++)
    01302     {
    01303         *lpMem++ = (BYTE)(ui16toSINT( lpBuff)/256) ;
    01304         lpBuff += sizeof(icUInt16Number);
    01305     }
    01306     return(sBytes);
    01307 }
    01308
    01309 /***************************************************************************
    01310 *
    01311 *  Function to control ascii85 encoding.
    01312 *  parameters:
    01313 *       lpDest      --  Pointer to the encording result buffer.
    01314 *       BufSize     --  Size of encording result buffer.
    01315 *       lpSource    --  Pointer to the input buffer
    01316 *       DataSize    --  Size of the input buffer
    01317 *  returns:
    01318 *       SINT        --  Number of bytes actually outputed.
    01319 *
    01320 ****************************************************************************/
    01321
    01322 SINT    WriteASCII85Cont(MEMPTR lpDest, SINT BufSize, MEMPTR lpSource, SINT DataSize)
    01323 {
    01324    SINT     incount;
    01325    MEMPTR   lpPtr, lpSave;
    01326    SINT     rem;
    01327    SINT     bcount;
    01328    SINT     dex;
    01329    unsigned long word;
    01330
    01331    /* encode the initial 4-tuples */
    01332    lpSave = lpDest;
    01333    lpPtr  = lpSource;
    01334    word   = 0UL;
    01335    bcount = 0;
    01336
    01337    for (incount = 0; incount < DataSize; incount ++)
    01338    {
    01339       if ( incount  && ((incount % LINELENG) == 0) )
    01340       lpDest += WriteObject(lpDest,  NewLine);
    01341       word = (word<<8);
    01342       word |= (BYTE)*lpPtr++;
    01343       if (bcount == 3)
    01344       {
    01345          lpDest += WriteAscii85(lpDest, word, 5);
    01346          word = 0UL;
    01347          bcount = 0;
    01348       }
    01349       else
    01350       {
    01351          bcount ++;
    01352       }
    01353    }
    01354
    01355    /* now do the last partial 4-tuple -- if there is one */
    01356    /* see the Red Book spec for the rules on how this is done */
    01357    if (bcount > 0)
    01358    {
    01359       rem = 4 - bcount;  /* count the remaining bytes */
    01360       for (dex = 0; dex < rem; dex ++) /* shift left for each of them */
    01361       {
    01362          word = (word<<8);      /* (equivalent to adding in ZERO's)*/
    01363          word |= (BYTE)32;
    01364       }
    01365 //      lpDest += WriteAscii85(lpDest, word, (bcount + 1));  /* output only meaningful
    01366       lpDest += WriteAscii85(lpDest, word, 5);               /* output only meaningful bytes + 1 */
    01367    }
    01368    return (lpDest - lpSave);
    01369 }
    01370
    01371 /************************************************************************
    01372 *
    01373 *  Function to convert 4 bytes binary data to 5 bytes ascii85 encorded data.
    01374 *  parameters:
    01375 *       lpDest      --  Pointer to the encording result buffer.
    01376 *       inWord      --  Input word (4-bytes)
    01377 *       nBytes      --  Number of bytes should be outputed.
    01378 *  returns:
    01379 *       SINT        --  Number of bytes actually outputed.
    01380 *
    01381 *************************************************************************/
    01382
    01383 SINT    WriteAscii85(MEMPTR lpDest, unsigned long inWord, SINT nBytes)
    01384 {
    01385     unsigned long divisor;
    01386     int      bcount;
    01387     BYTE     outchar;
    01388     MEMPTR   lpSave = lpDest;
    01389
    01390     if ((inWord == 0UL) && (nBytes == 5))
    01391         *lpDest++ = 'z';
    01392     else
    01393     {
    01394         divisor = 52200625UL;
    01395         for (bcount = 0; bcount < nBytes; bcount ++)
    01396         {
    01397             outchar = (BYTE)((int)(inWord/divisor) + (int)'!');
    01398             *lpDest++ = outchar;
    01399             if (bcount < 4)
    01400             {
    01401                 inWord = (inWord % divisor);
    01402                 divisor =(divisor / 85);
    01403             }
    01404         }
    01405     }
    01406     return (SINT)(lpDest - lpSave);
    01407 }
    01408
    01409 /***************************************************************************
    01410 *
    01411 *  Function to convert binary data to ascii by performing ASCII85 encording
    01412 *  parameters:
    01413 *       lpMem       --  A pointer to the buffer.
    01414 *                       as input: contains binary data;
    01415 *                       as output: contains ascii data.
    01416 *       DataSize    --  The size of input binary data.
    01417 *       BufSize     --  The size of buffer pointed by lpMem.
    01418 *  returns:
    01419 *       SINT        --  Number of bytes actually outputed.
    01420 *
    01421 ***************************************************************************/
    01422
    01423 SINT    ConvertBinaryData2Ascii(MEMPTR lpMem, SINT DataSize, SINT BufSize)
    01424 {
    01425     MEMPTR      intrbuf, Temp;
    01426     HANDLE      intrhandle;
    01427     SINT        AsciiDataSize = 0;
    01428
    01429     if (BufSize >= (SINT)(DataSize/4*5 + sizeof(ASCII85DecodeBegine)+sizeof(ASCII85DecodeEnd) + 2048))
    01430     {
    01431         if ((intrhandle = GlobalAlloc(GHND, BufSize)) != NULL)
    01432         {
    01433             if ((intrbuf = (MEMPTR) GlobalLock(intrhandle)) != NULL)
    01434             {
    01435                 Temp = intrbuf;
    01436                 Temp += WriteObject(Temp,  NewLine);
    01437                 Temp += WriteObject(Temp,  ASCII85DecodeBegine);
    01438                 Temp += WriteObject(Temp,  NewLine);
    01439                 Temp += WriteASCII85Cont(Temp, BufSize, lpMem, DataSize);
    01440                 Temp += WriteObject(Temp,  ASCII85DecodeEnd);
    01441                 AsciiDataSize = (SINT)(Temp - intrbuf);
    01442                 lstrcpyn(lpMem, intrbuf, (WORD)AsciiDataSize);
    01443                 GlobalUnlock(intrhandle);
    01444             }
    01445         }
    01446         GlobalFree(intrhandle);
    01447    }
    01448    return (AsciiDataSize);
    01449 }
    01450
    01451 /***************************************************************************
    01452 *
    01453 *  Function to check if it is need to convert a CRD from binary to ascii
    01454 *  parameters:
    01455 *       CP          --  Handle of memory block which contains icm profile.
    01456 *       Index       --  Index of the element data of the profile.
    01457 *       lpData      --  A pointer to the buffer.
    01458 *                       as input: contains binary data;
    01459 *                       as output: contains ascii data.
    01460 *       BufSize     --  The size of the buffer pointed by lpData.
    01461 *       DataSize    --  The size of input binary data.
    01462 *       AllowBinary --  Allow binary or not(1/0).
    01463 *  returns:
    01464 *       SINT        --  Number of bytes required/actually outputed.
    01465 *
    01466 ***************************************************************************/
    01467
    01468 SINT    Convert2Ascii(CHANDLE CP, SINT Index,
    01469                       MEMPTR lpData, SINT BufSize,
    01470                       SINT DataSize, BOOL AllowBinary)
    01471 {
    01472     long    DataType;
    01473
    01474     GetCPElementDataType(CP, Index, &DataType);
    01475     if (BufSize == 0)
    01476     {
    01477         if (AllowBinary)
    01478             return (DataSize);
    01479         else if (DataType == 0)    // Ascii data in Profile
    01480             return (DataSize);
    01481         else                       // Keep space for ascii85 encoding.
    01482             return (DataSize / 4 * 5 + sizeof(ASCII85DecodeBegine)+sizeof(ASCII85DecodeEnd) + 2048);
    01483     }
    01484     else
    01485     {
    01486         if (AllowBinary)
    01487             return (DataSize);
    01488         else if(DataType == 0)
    01489             return (DataSize);
    01490         else
    01491             return (ConvertBinaryData2Ascii(lpData, DataSize, BufSize) );
    01492     }
    01493 }
    01494
    01495 #ifdef ICMDLL
    01496 SINT    MemCopy(MEMPTR Dest, MEMPTR Source, SINT Length)
    01497 {
    01498     SINT    i;
    01499
    01500     for (i = 0; i < Length; i++)
    01501     {
    01502         Dest[i] = Source[i];
    01503     }
    01504     return( Length );
    01505 }
    01506 #endif
    01507