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

getcrd.c

Go to the documentation of this file.
00001 #include "generic.h" 00002 00003 //#pragma code_seg(_ICMSEG) 00004 00005 #define REVCURVE_RATIO 2 00006 00007 char ICMSEG BeginString[] = "<"; 00008 char ICMSEG EndString[] = ">"; 00009 char ICMSEG BeginArray[] = "["; 00010 char ICMSEG EndArray[] = "]"; 00011 char ICMSEG BeginFunction[] = "{"; 00012 char ICMSEG EndFunction[] = "}bind "; 00013 char ICMSEG BeginDict[] = "<<" ; 00014 char ICMSEG EndDict[] = ">>" ; 00015 char ICMSEG BlackPoint[] = "[0 0 0]" ; 00016 char ICMSEG DictType[] = "/ColorRenderingType 1 "; 00017 00018 char ICMSEG WhitePointTag[] = "/WhitePoint " ; 00019 char ICMSEG BlackPointTag[] = "/BlackPoint " ; 00020 char ICMSEG RangePQRTag[] = "/RangePQR " ; 00021 char ICMSEG TransformPQRTag[] = "/TransformPQR " ; 00022 char ICMSEG MatrixPQRTag[] = "/MatrixPQR " ; 00023 00024 char ICMSEG RangeABCTag[] = "/RangeABC " ; 00025 char ICMSEG MatrixATag[] = "/MatrixA "; 00026 char ICMSEG MatrixABCTag[] = "/MatrixABC "; 00027 char ICMSEG EncodeABCTag[] = "/EncodeABC " ; 00028 char ICMSEG RangeLMNTag[] = "/RangeLMN " ; 00029 char ICMSEG MatrixLMNTag[] = "/MatrixLMN " ; 00030 char ICMSEG EncodeLMNTag[] = "/EncodeLMN " ; 00031 char ICMSEG RenderTableTag[] = "/RenderTable " ; 00032 char ICMSEG CIEBasedATag[] = "/CIEBasedA " ; 00033 char ICMSEG CIEBasedABCTag[] = "/CIEBasedABC " ; 00034 char ICMSEG CIEBasedDEFGTag[] = "/CIEBasedDEFG " ; 00035 char ICMSEG CIEBasedDEFTag[] = "/CIEBasedDEF " ; 00036 char ICMSEG DecodeATag[] = "/DecodeA " ; 00037 char ICMSEG DecodeABCTag[] = "/DecodeABC " ; 00038 char ICMSEG DecodeLMNTag[] = "/DecodeLMN " ; 00039 char ICMSEG DeviceRGBTag[] = "/DeviceRGB " ; 00040 char ICMSEG DeviceCMYKTag[] = "/DeviceCMYK " ; 00041 char ICMSEG DeviceGrayTag[] = "/DeviceGray " ; 00042 char ICMSEG TableTag[] = "/Table " ; 00043 char ICMSEG DecodeDEFGTag[] = "/DecodeDEFG " ; 00044 char ICMSEG DecodeDEFTag[] = "/DecodeDEF " ; 00045 00046 char ICMSEG NullOp[] = ""; 00047 char ICMSEG DupOp[] = "dup "; 00048 char ICMSEG UserDictOp[] = "userdict "; 00049 char ICMSEG GlobalDictOp[] = "globaldict "; 00050 char ICMSEG CurrentGlobalOp[] = "currentglobal "; 00051 char ICMSEG SetGlobalOp[] = "setglobal "; 00052 char ICMSEG DefOp[] = "def "; 00053 char ICMSEG BeginOp[] = "begin "; 00054 char ICMSEG EndOp[] = "end "; 00055 char ICMSEG TrueOp[] = "true "; 00056 char ICMSEG FalseOp[] = "false "; 00057 char ICMSEG MulOp[] = "mul "; 00058 char ICMSEG DivOp[] = "div "; 00059 00060 char ICMSEG NewLine[] = "\n" ; 00061 char ICMSEG Slash[] = "/" ; 00062 char ICMSEG Space[] = " " ; 00063 char ICMSEG CRDBegin[] = "%** CRD Begin "; 00064 char ICMSEG CRDEnd[] = "%** CRD End "; 00065 char ICMSEG CieBasedDEFGBegin[] = "%** CieBasedDEFG CSA Begin "; 00066 char ICMSEG CieBasedDEFBegin[] = "%** CieBasedDEF CSA Begin "; 00067 char ICMSEG CieBasedABCBegin[] = "%** CieBasedABC CSA Begin "; 00068 char ICMSEG CieBasedABegin[] = "%** CieBasedA CSA Begin "; 00069 char ICMSEG CieBasedDEFGEnd[] = "%** CieBasedDEFG CSA End "; 00070 char ICMSEG CieBasedDEFEnd[] = "%** CieBasedDEF CSA End "; 00071 char ICMSEG CieBasedABCEnd[] = "%** CieBasedABC CSA End "; 00072 char ICMSEG CieBasedAEnd[] = "%** CieBasedA CSA End "; 00073 char ICMSEG RangeABC[] = "[ 0 1 0 1 0 1 ] "; 00074 char ICMSEG RangeLMN[] = "[ 0 2 0 2 0 2 ] "; 00075 char ICMSEG Identity[] = "[1 0 0 0 1 0 0 0 1]"; 00076 char ICMSEG RangeABC_Lab[] = "[0 100 -128 127 -128 127]"; 00077 00078 /********** This PostScript code clips incoming value between 0.0 and 1.0 00079 Use: x <clip> -- <clipped x> */ 00080 char ICMSEG Clip01[] = "dup 1.0 ge{pop 1.0}{dup 0.0 lt{pop 0.0}if}ifelse " ; 00081 char ICMSEG DecodeA3[] = "256 div exp "; 00082 char ICMSEG DecodeA3Rev[] = "256 div 1.0 exch div exp "; 00083 char ICMSEG DecodeABCArray[] = "DecodeABC_"; 00084 char ICMSEG InputArray[] = "Inp_"; 00085 char ICMSEG OutputArray[] = "Out_"; 00086 char ICMSEG PreViewInArray[] = "IPV_"; 00087 char ICMSEG PreViewOutArray[] = "OPV_"; 00088 00089 00090 // This PostScript segment takes value in range from 0.0 to 1.0 and 00091 // interpolates the result using array supplied. 00092 // x [array] -- <interpolated value> 00093 00094 char ICMSEG IndexArray16b[] = \ 00095 " dup length 1 sub 3 -1 roll mul dup dup floor cvi \ 00096 exch ceiling cvi 3 index exch get 32768 add 4 -1 roll 3 -1 roll get 32768 add \ 00097 dup 3 1 roll sub 3 -1 roll dup floor cvi sub mul add "; 00098 00099 char ICMSEG IndexArray[] = \ 00100 " dup length 1 sub 3 -1 roll mul dup dup floor cvi \ 00101 exch ceiling cvi 3 index exch get 4 -1 roll 3 -1 roll get \ 00102 dup 3 1 roll sub 3 -1 roll dup floor cvi sub mul add "; 00103 00104 char ICMSEG TestingDEFG[] = \ 00105 "/SupportDEFG? {/CIEBasedDEFG /ColorSpaceFamily resourcestatus { pop pop true}{false} ifelse} def"; 00106 00107 char ICMSEG SupportDEFG_S[] = "SupportDEFG? { "; 00108 char ICMSEG NotSupportDEFG_S[] = "SupportDEFG? not { "; 00109 char ICMSEG SupportDEFG_E[] = "}if "; 00110 00111 char ICMSEG StartClip[] = "dup 1.0 le{dup 0.0 ge{" ; 00112 char ICMSEG EndClip[] = "}if}if " ; 00113 00114 char ICMSEG Scale8[] = "255 div " ; 00115 char ICMSEG Scale16[] = "65535 div " ; 00116 char ICMSEG Scale16XYZ[] = "32768 div " ; 00117 char ICMSEG TFunction8[] = "exch 255 mul round cvi get 255 div " ; 00118 char ICMSEG TFunction8XYZ[] = "exch 255 mul round cvi get 128 div " ; 00119 char ICMSEG MatrixABCLab[] = "[1 1 1 1 0 0 0 0 -1]" ; 00120 char ICMSEG DecodeABCLab1[] = "[{16 add 116 div} bind {500 div} bind {200 div} bind]"; 00121 char ICMSEG DecodeALab[] = " 50 mul 16 add 116 div "; 00122 char ICMSEG DecodeLMNLab[] = \ 00123 "dup 0.206897 ge{dup dup mul mul}{0.137931 sub 0.128419 mul} ifelse "; 00124 00125 char ICMSEG RangeLMNLab[] = "[0 1 0 1 0 1]" ; 00126 char ICMSEG EncodeLMNLab[] = "\ 00127 dup 0.008856 le{7.787 mul 0.13793 add}{0.3333 exp}ifelse " ; 00128 00129 char ICMSEG MatrixABCLabCRD[] = "[0 500 0 116 -500 200 0 0 -200]" ; 00130 char ICMSEG MatrixABCXYZCRD[] = "[0 1 0 1 0 0 0 0 1]" ; 00131 char ICMSEG EncodeABCLab1[] = "16 sub 100 div " ; 00132 char ICMSEG EncodeABCLab2[] = "128 add 255 div " ; 00133 char *TransformPQR[3] = { 00134 "4 index 0 get div 2 index 0 get mul 4 {exch pop} repeat ", 00135 "4 index 1 get div 2 index 1 get mul 4 {exch pop} repeat ", 00136 "4 index 2 get div 2 index 2 get mul 4 {exch pop} repeat " }; 00137 00138 #pragma optimize("",off) 00139 00140 /*************************************************************************** 00141 * CreateLutCRD 00142 * function: 00143 * this is the function which creates the Color Rendering Dictionary (CRD) 00144 * from the data supplied in the ColorProfile's LUT8 or LUT16 tag. 00145 * prototype: 00146 * SINT EXTERN CreateLutCRD( 00147 * CHANDLE cp, 00148 * SINT Index, 00149 * MEMPTR lpMem, 00150 * BOOL AllowBinary) 00151 * parameters: 00152 * cp -- Color Profile handle 00153 * Index -- Index of the tag 00154 * lpMem -- Pointer to the memory block 00155 * AllowBinary -- 1: binary CRD allowed, 0: only ascii CRD allowed. 00156 * 00157 * returns: 00158 * SINT -- !=0 if the function was successful, 00159 * 0 otherwise. 00160 * Returns number of bytes required/transferred 00161 ***************************************************************************/ 00162 00163 SINT EXTERN 00164 CreateLutCRD (CHANDLE cp, SINT Index, MEMPTR lpMem, DWORD InputIntent, BOOL AllowBinary) 00165 { 00166 SINT nInputCh, nOutputCh, nGrids; 00167 SINT nInputTable, nOutputTable, nNumbers; 00168 CSIG Tag, PCS; 00169 CSIG IntentSig; 00170 00171 SINT Ret; 00172 SINT i, j; 00173 MEMPTR lpTable; 00174 00175 SFLOAT IlluminantWP[3]; 00176 SFLOAT MediaWP[3]; 00177 MEMPTR Buff = NULL; 00178 SINT MemSize = 0; 00179 MEMPTR lpOldMem = lpMem; 00180 char PublicArrayName[TempBfSize]; 00181 HGLOBAL hMem; 00182 MEMPTR lpLineStart; 00183 // Check if we can generate the CRD 00184 if (!GetCPTagSig (cp, Index, (LPCSIG) & IntentSig) || 00185 !GetCPElementType (cp, Index, (LPCSIG) & Tag) || 00186 ((Tag != icSigLut8Type) && (Tag != icSigLut16Type)) || 00187 !GetCPConnSpace (cp, (LPCSIG) & PCS) || 00188 !GetCPElementSize (cp, Index, (LPSINT) & MemSize) || 00189 !MemAlloc (MemSize, (HGLOBAL FAR *)&hMem, (LPMEMPTR) & Buff) || 00190 !GetCPElement (cp, Index, Buff, MemSize)) 00191 { 00192 if (NULL != Buff) 00193 { 00194 MemFree (hMem); 00195 } 00196 return (0); 00197 } 00198 GetCLUTinfo(Tag, Buff, &nInputCh, &nOutputCh, 00199 &nGrids, &nInputTable, &nOutputTable, &i); 00200 // Level 2 printers support only tri-component CIEBasedABC input, 00201 // but can have either 3 or 4 output channels. 00202 if (((nOutputCh != 3) && 00203 (nOutputCh != 4)) || 00204 (nInputCh != 3)) 00205 { 00206 SetCPLastError (CP_POSTSCRIPT_ERR); 00207 MemFree (hMem); 00208 return (0); 00209 } 00210 Ret = nInputCh * nInputTable * 6 + 00211 nOutputCh * nOutputTable * 6 + // Number of INT bytes 00212 nOutputCh * nGrids * nGrids * nGrids * 2 + // LUT HEX bytes 00213 nInputCh * (lstrlen (IndexArray) + 00214 lstrlen (StartClip) + 00215 lstrlen (EndClip)) + 00216 nOutputCh * (lstrlen (IndexArray) + 00217 lstrlen (StartClip) + 00218 lstrlen (EndClip)) + 00219 2048; // + other PS stuff 00220 00221 if (lpMem == NULL) // This is a size request 00222 { 00223 MemFree (hMem); 00224 return (Ret); 00225 } 00226 // Get all necessary params from the header 00227 // GetCPRenderIntent (cp, (LPCSIG) & Intent); // Get Intent 00228 GetCPWhitePoint (cp, (LPSFLOAT) & IlluminantWP); // .. Illuminant 00229 00230 // Support absolute whitePoint 00231 if (InputIntent == icAbsoluteColorimetric) 00232 { 00233 if (!GetCPMediaWhitePoint (cp, (LPSFLOAT) & MediaWP)) // .. Media WhitePoint 00234 { 00235 MediaWP[0] = IlluminantWP[0]; 00236 MediaWP[1] = IlluminantWP[1]; 00237 MediaWP[2] = IlluminantWP[2]; 00238 } 00239 } 00240 00241 //******** Define golbal array used in EncodeABC and RenderTaber 00242 GetPublicArrayName (cp, IntentSig, PublicArrayName); 00243 lpMem += WriteObject (lpMem, NewLine); 00244 lpMem += WriteObject (lpMem, CRDBegin); 00245 00246 lpMem += EnableGlobalDict(lpMem); 00247 00248 lpMem += CreateInputArray (lpMem, nInputCh, nInputTable, 00249 (MEMPTR) PublicArrayName, Tag, Buff, AllowBinary, NULL); 00250 00251 i = nInputTable * nInputCh + 00252 nGrids * nGrids * nGrids * nOutputCh; 00253 lpMem += CreateOutputArray (lpMem, nOutputCh, nOutputTable, i, 00254 (MEMPTR) PublicArrayName, Tag, Buff, AllowBinary, NULL); 00255 00256 lpMem += WriteObject (lpMem, NewLine); 00257 lpMem += WriteObject (lpMem, SetGlobalOp); 00258 lpMem += WriteObject (lpMem, EndOp); 00259 00260 00261 //************* Start writing CRD **************************** 00262 lpMem += WriteObject (lpMem, NewLine); 00263 lpMem += WriteObject (lpMem, BeginDict); // Begin dictionary 00264 lpMem += WriteObject (lpMem, DictType); // Dictionary type 00265 00266 //********** Send Black/White Point. 00267 lpMem += SendCRDBWPoint(lpMem, IlluminantWP); 00268 00269 //********** Send PQR - used for Absolute Colorimetric ***** 00270 lpMem += SendCRDPQR(lpMem, InputIntent, IlluminantWP); 00271 00272 //********** Send LMN - For Absolute Colorimetric use WhitePoint's XYZs 00273 lpMem += SendCRDLMN(lpMem, InputIntent, IlluminantWP, MediaWP, PCS); 00274 00275 // ******** Create MatrixABC and EncodeABC stuff 00276 lpMem += SendCRDABC(lpMem, PublicArrayName, 00277 PCS, nInputCh, Buff, NULL, Tag, AllowBinary); 00278 00279 //********** /RenderTable 00280 lpMem += WriteObject (lpMem, NewLine); 00281 lpMem += WriteObject (lpMem, RenderTableTag); 00282 lpMem += WriteObject (lpMem, BeginArray); 00283 00284 lpMem += WriteInt (lpMem, nGrids); // Send down Na 00285 lpMem += WriteInt (lpMem, nGrids); // Send down Nb 00286 lpMem += WriteInt (lpMem, nGrids); // Send down Nc 00287 00288 lpLineStart = lpMem; 00289 lpMem += WriteObject (lpMem, NewLine); 00290 lpMem += WriteObject (lpMem, BeginArray); 00291 nNumbers = nGrids * nGrids * nOutputCh; 00292 for (i = 0; i < nGrids; i++) // Na strings should be sent 00293 { 00294 lpMem += WriteObject (lpMem, NewLine); 00295 lpLineStart = lpMem; 00296 if (Tag == icSigLut8Type) 00297 { 00298 lpTable = (MEMPTR) (((lpcpLut8Type) Buff)->lut.data) + 00299 nInputTable * nInputCh + 00300 nNumbers * i; 00301 } else 00302 { 00303 lpTable = (MEMPTR) (((lpcpLut16Type) Buff)->lut.data) + 00304 2 * nInputTable * nInputCh + 00305 2 * nNumbers * i; 00306 } 00307 if (!AllowBinary) // Output ASCII CRD 00308 { 00309 lpMem += WriteObject (lpMem, BeginString); 00310 if (Tag == icSigLut8Type) 00311 lpMem += WriteHexBuffer (lpMem, lpTable, lpLineStart, nNumbers); 00312 else 00313 { 00314 for (j = 0; j < nNumbers; j++) 00315 { 00316 lpMem += WriteHex (lpMem, ui16toSINT (lpTable) / 256); 00317 lpTable += sizeof (icUInt16Number); 00318 if (((SINT) (lpMem - lpLineStart)) > MAX_LINELENG) 00319 { 00320 lpLineStart = lpMem; 00321 lpMem += WriteObject (lpMem, NewLine); 00322 } 00323 } 00324 } 00325 lpMem += WriteObject (lpMem, EndString); 00326 } else 00327 { // Output BINARY CRD 00328 lpMem += WriteStringToken (lpMem, 143, nNumbers); 00329 if (Tag == icSigLut8Type) 00330 lpMem += WriteByteString (lpMem, lpTable, nNumbers); 00331 else 00332 lpMem += WriteInt2ByteString (lpMem, lpTable, nNumbers); 00333 } 00334 } 00335 00336 lpMem += WriteObject (lpMem, EndArray); // End array 00337 lpMem += WriteInt (lpMem, nOutputCh); // Send down m 00338 00339 //********** Send Output Table. 00340 lpMem += SendCRDOutputTable(lpMem, PublicArrayName, 00341 nOutputCh, Tag, FALSE, AllowBinary); 00342 00343 lpMem += WriteObject (lpMem, EndArray); // End array 00344 lpMem += WriteObject (lpMem, EndDict); // End dictionary definition 00345 00346 lpMem += WriteObject (lpMem, NewLine); 00347 lpMem += WriteObject (lpMem, CRDEnd); 00348 00349 // Testing Convert binary to ascii 00350 // i = ConvertBinaryData2Ascii(lpOldMem, (SINT)(lpMem - lpOldMem), Ret); 00351 // lpMem = lpOldMem + i; 00352 // Testing Convert binary to ascii 00353 00354 MemFree (hMem); 00355 return ((SINT) ((unsigned long) (lpMem - lpOldMem))); 00356 } 00357 /*************************************************************************** 00358 * GetRevCurve 00359 * function: 00360 * prototype: 00361 * BOOL GetRevCurve( 00362 * MEMPTR Buff, 00363 * MEMPTR lpRevCurve) 00364 * parameters: 00365 * Buff -- 00366 * lpRevCurve -- 00367 * returns: 00368 * BOOL -- TRUE: successful, 00369 * FALSE: otherwise. 00370 ***************************************************************************/ 00371 00372 static BOOL 00373 GetRevCurve (MEMPTR lpBuff, MEMPTR lpCurve, MEMPTR lpRevCurve) 00374 { 00375 SINT i, j, nCount; 00376 MEMPTR lpTable; 00377 PUSHORT lpInput, lpOutput; 00378 SFLOAT fTemp; 00379 SINT iBegin, iEnd, iTemp; 00380 nCount = ui32toSINT (((lpcpCurveType) lpBuff)->curve.count); 00381 lpTable = (MEMPTR) (((lpcpCurveType) lpBuff)->curve.data); 00382 lpOutput = (PUSHORT) lpRevCurve; 00383 lpInput = (PUSHORT) lpCurve; 00384 00385 for (i = 0; i < nCount; i++) 00386 { 00387 lpInput[i] = (USHORT) (ui16toSINT (lpTable)); 00388 lpTable += sizeof (icUInt16Number); 00389 } 00390 00391 j = nCount * REVCURVE_RATIO; 00392 for (i = 0; i < j; i++) 00393 { 00394 fTemp = (SFLOAT) i *65535 / (j - 1); 00395 lpOutput[i] = (fTemp < 65535) ? (USHORT) fTemp : (USHORT) 65535; 00396 } 00397 00398 for (i = 0; i < j; i++) 00399 { 00400 iBegin = 0; 00401 iEnd = nCount - 1; 00402 for (;;) 00403 { 00404 if ((iEnd - iBegin) <= 1) 00405 break; 00406 iTemp = (iEnd + iBegin) / 2; 00407 if (lpOutput[i] < lpInput[iTemp]) 00408 iEnd = iTemp; 00409 else 00410 iBegin = iTemp; 00411 } 00412 if (lpOutput[i] <= lpInput[iBegin]) 00413 fTemp = (SFLOAT) iBegin; 00414 else if (lpOutput[i] >= lpInput[iEnd]) 00415 fTemp = (SFLOAT) iEnd; 00416 else 00417 { 00418 fTemp = ((SFLOAT) (lpInput[iEnd] - lpOutput[i])) / 00419 (lpOutput[i] - lpInput[iBegin]); 00420 fTemp = (iBegin * fTemp + iEnd) / (fTemp + 1); 00421 } 00422 fTemp = (fTemp / (nCount - 1)) * 65535; 00423 lpOutput[i] = (fTemp < 65535) ? (USHORT) fTemp : (USHORT) 65535; 00424 } 00425 00426 return TRUE; 00427 } 00428 /*************************************************************************** 00429 * CreateMonoCRD 00430 * function: 00431 * this is the function which creates the Color Rendering Dictionary (CRD) 00432 * from the data supplied in the GrayTRC tag. 00433 * prototype: 00434 * BOOL EXTERN CreateMonoCRD( 00435 * CHANDLE cp, 00436 * SINT Index, 00437 * MEMPTR lpMem) 00438 * parameters: 00439 * cp -- Color Profile handle 00440 * Index -- Index of the tag 00441 * lpMem -- Pointer to the memory block 00442 * returns: 00443 * SINT -- !=0 if the function was successful, 00444 * 0 otherwise. 00445 * Returns number of bytes required/transferred 00446 ***************************************************************************/ 00447 // According to the spec this tag-based function only converts from 00448 // Device to PCS, so we need to create an inverse function to perform 00449 // PCS->device conversion. By definition the CRD is only 00450 // for XYZ->DeviceRGB/CMYK conversion. 00451 SINT EXTERN 00452 CreateMonoCRD (CHANDLE cp, SINT Index, MEMPTR lpMem, DWORD InputIntent) 00453 { 00454 SINT nCount; 00455 CSIG Tag, PCS; 00456 00457 MEMPTR Buff = NULL; 00458 SINT MemSize = 0; 00459 MEMPTR lpOldMem = lpMem; 00460 MEMPTR lpCurve, lpRevCurve; 00461 HGLOBAL hRevCurve; 00462 SINT Ret = 0; 00463 HGLOBAL hMem; 00464 SINT i; 00465 MEMPTR lpTable; 00466 SFLOAT IlluminantWP[3]; 00467 SFLOAT MediaWP[3]; 00468 MEMPTR lpLineStart; 00469 // Check if we can generate the CRD 00470 if (!GetCPElementType (cp, Index, (LPCSIG) & Tag) || 00471 (Tag != icSigCurveType) || 00472 !GetCPConnSpace (cp, (LPCSIG) & PCS) || 00473 !GetCPElementSize (cp, Index, (LPSINT) & MemSize) || 00474 !MemAlloc (MemSize, (HGLOBAL FAR *)&hMem, (LPMEMPTR) & Buff) || 00475 !GetCPElement (cp, Index, Buff, MemSize)) 00476 { 00477 if (NULL != Buff) 00478 { 00479 MemFree (hMem); 00480 } 00481 return (0); 00482 } 00483 nCount = ui32toSINT (((lpcpCurveType) Buff)->curve.count); 00484 00485 // Estimate the memory size required to hold CRD 00486 Ret = nCount * 6 * 2 + // Number of INT elements 00487 2048; // + other PS stuff 00488 if (lpMem == NULL) // This is a size request 00489 { 00490 MemFree (hMem); 00491 return (Ret); 00492 } 00493 if (!MemAlloc (nCount * 2 * (REVCURVE_RATIO + 1), 00494 (HGLOBAL FAR *) &hRevCurve, (LPMEMPTR) & lpRevCurve)) 00495 { 00496 MemFree (hMem); 00497 return (FALSE); 00498 } 00499 lpCurve = lpRevCurve + 2 * REVCURVE_RATIO * nCount; 00500 GetRevCurve (Buff, lpCurve, lpRevCurve); 00501 00502 // GetCPCMMType (cp, (LPCSIG) & Intent); // Get Intent 00503 GetCPWhitePoint (cp, (LPSFLOAT) & IlluminantWP); // .. Illuminant 00504 00505 // Support absolute whitePoint 00506 if (InputIntent == icAbsoluteColorimetric) 00507 { 00508 if (!GetCPMediaWhitePoint (cp, (LPSFLOAT) & MediaWP)) // .. Media WhitePoint 00509 { 00510 MediaWP[0] = IlluminantWP[0]; 00511 MediaWP[1] = IlluminantWP[1]; 00512 MediaWP[2] = IlluminantWP[2]; 00513 } 00514 } 00515 00516 //************* Start writing CRD **************************** 00517 lpMem += WriteObject (lpMem, NewLine); 00518 lpMem += WriteObject (lpMem, BeginDict); // Begin dictionary 00519 lpMem += WriteObject (lpMem, DictType); // Dictionary type 00520 00521 //********** Send Black/White Point. 00522 lpMem += SendCRDBWPoint(lpMem, IlluminantWP); 00523 00524 //********** /TransformPQR 00525 lpMem += SendCRDPQR(lpMem, InputIntent, IlluminantWP); 00526 00527 //********** /MatrixLMN 00528 lpMem += SendCRDLMN(lpMem, InputIntent, IlluminantWP, MediaWP, PCS); 00529 00530 //********** /MatrixABC 00531 if (PCS == icSigXYZData) 00532 { // Switch ABC to BAC, since we want to output B which is converted from Y. 00533 lpMem += WriteObject (lpMem, NewLine); 00534 lpMem += WriteObject (lpMem, MatrixABCTag); 00535 lpMem += WriteObject (lpMem, MatrixABCXYZCRD); 00536 } 00537 else if (PCS == icSigLabData) 00538 { 00539 lpMem += WriteObject (lpMem, NewLine); 00540 lpMem += WriteObject (lpMem, MatrixABCTag); 00541 lpMem += WriteObject (lpMem, MatrixABCLabCRD); 00542 } 00543 //********** /EncodeABC 00544 if (nCount != 0) 00545 { 00546 lpMem += WriteObject (lpMem, NewLine); 00547 lpLineStart = lpMem; 00548 lpMem += WriteObject (lpMem, EncodeABCTag); 00549 lpMem += WriteObject (lpMem, BeginArray); 00550 lpMem += WriteObject (lpMem, BeginFunction); 00551 if (nCount == 1) // Gamma supplied in ui16 format 00552 { 00553 lpTable = (MEMPTR) (((lpcpCurveType) Buff)->curve.data); 00554 lpMem += WriteInt (lpMem, ui16toSINT (lpTable)); 00555 lpMem += WriteObject (lpMem, DecodeA3Rev); 00556 } else 00557 { 00558 if (PCS == icSigLabData) 00559 { 00560 lpMem += WriteObject (lpMem, EncodeABCLab1); 00561 } 00562 lpMem += WriteObject (lpMem, StartClip); 00563 lpMem += WriteObject (lpMem, BeginArray); 00564 for (i = 0; i < nCount * REVCURVE_RATIO; i++) 00565 { 00566 lpMem += WriteInt (lpMem, (SINT) (*((PUSHORT) lpRevCurve))); 00567 lpRevCurve += sizeof (icUInt16Number); 00568 if (((SINT) (lpMem - lpLineStart)) > MAX_LINELENG) 00569 { 00570 lpLineStart = lpMem; 00571 lpMem += WriteObject (lpMem, NewLine); 00572 } 00573 } 00574 lpMem += WriteObject (lpMem, EndArray); 00575 lpLineStart = lpMem; 00576 lpMem += WriteObject (lpMem, NewLine); 00577 00578 lpMem += WriteObject (lpMem, IndexArray); 00579 lpMem += WriteObject (lpMem, Scale16); 00580 lpMem += WriteObject (lpMem, EndClip); 00581 } 00582 lpMem += WriteObject (lpMem, EndFunction); 00583 lpMem += WriteObject (lpMem, DupOp); 00584 lpMem += WriteObject (lpMem, DupOp); 00585 lpMem += WriteObject (lpMem, EndArray); 00586 } 00587 lpMem += WriteObject (lpMem, EndDict); // End dictionary definition 00588 00589 MemFree (hRevCurve); 00590 MemFree (hMem); 00591 return ((SINT) ((unsigned long) (lpMem - lpOldMem))); 00592 } 00593 00594 00595 BOOL EXTERN 00596 GetPS2ColorRenderingDictionary ( 00597 CHANDLE cp, 00598 DWORD Intent, 00599 MEMPTR lpMem, 00600 LPDWORD lpcbSize, 00601 BOOL AllowBinary) 00602 { 00603 SINT Index; 00604 SINT Ret, Size; 00605 CSIG icSigPs2CRDx, icSigBToAx; 00606 00607 if (!cp) 00608 return FALSE; 00609 00610 if ((lpMem == NULL) || (*lpcbSize == 0)) 00611 { 00612 lpMem = NULL; 00613 *lpcbSize = 0; 00614 } 00615 Ret = 0; 00616 Size = (SINT) * lpcbSize; 00617 00618 switch (Intent) 00619 { 00620 case icPerceptual: 00621 icSigPs2CRDx = icSigPs2CRD0Tag; 00622 icSigBToAx = icSigBToA0Tag; 00623 break; 00624 00625 case icRelativeColorimetric: 00626 icSigPs2CRDx = icSigPs2CRD1Tag; 00627 icSigBToAx = icSigBToA1Tag; 00628 break; 00629 00630 case icSaturation: 00631 icSigPs2CRDx = icSigPs2CRD2Tag; 00632 icSigBToAx = icSigBToA2Tag; 00633 break; 00634 00635 case icAbsoluteColorimetric: 00636 icSigPs2CRDx = icSigPs2CRD3Tag; 00637 icSigBToAx = icSigBToA1Tag; 00638 break; 00639 00640 default: 00641 *lpcbSize = (DWORD) Ret; 00642 return (Ret > 0); 00643 } 00644 00645 if ( 00646 (DoesCPTagExist (cp, icSigPs2CRDx) && 00647 GetCPTagIndex (cp, icSigPs2CRDx, (LPSINT) & Index) && 00648 GetCPElementDataSize (cp, Index, (LPSINT) & Ret) && 00649 ((Size == 0) || 00650 GetCPElementData (cp, Index, lpMem, Size)) && 00651 (Ret = Convert2Ascii (cp, Index, lpMem, Size, Ret, AllowBinary)) 00652 ) || 00653 (DoesCPTagExist (cp, icSigBToAx) && 00654 GetCPTagIndex (cp, icSigBToAx, (LPSINT) & Index) && 00655 (Ret = CreateLutCRD (cp, Index, lpMem, Intent, AllowBinary)) 00656 ) || 00657 (DoesCPTagExist (cp, icSigGrayTRCTag) && 00658 GetCPTagIndex (cp, icSigGrayTRCTag, (LPSINT) & Index) && 00659 (Ret = CreateMonoCRD (cp, Index, lpMem, Intent)) 00660 ) 00661 ) 00662 { 00663 } 00664 00665 *lpcbSize = (DWORD) Ret; 00666 return (Ret > 0); 00667 }

Generated on Sat May 15 19:40:11 2004 for test by doxygen 1.3.7