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

Generated on Sat May 15 19:39:36 2004 for test by doxygen 1.3.7