test: getcsa.c Source File

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

# getcsa.c

Go to the documentation of this file.

    00001 #include "generic.h"
    00002 #include "icmstr.h"
    00003
    00004 #pragma code_seg(_ICMSEG)
    00005
    00006 static char  *DecodeABCLab[] = {"50 mul 16 add 116 div ",
    00007                                "128 mul 128 sub 500 div",
    00008                                "128 mul 128 sub 200 div"};
    00009
    00010 #pragma optimize("",off)
    00011
    00012 BOOL IsSRGB( CHANDLE cp );
    00013
    00014 /**************************************************************************/
    00015
    00016 SINT CreateColSpArray (CHANDLE cp, MEMPTR lpMem, CSIG CPTag, BOOL AllowBinary);
    00017 SINT CreateColSpProc (CHANDLE cp, MEMPTR lpMem, CSIG CPTag, BOOL AllowBinary);
    00018 SINT CreateFloatString (CHANDLE cp, MEMPTR lpMem, CSIG CPTag);
    00019 static SINT SendCSABWPoint(MEMPTR lpMem, CSIG Intent,
    00020     LPSFLOAT IlluminantWP, LPSFLOAT MediaWP);
    00021 static void GetMediaWP(CHANDLE cp, CSIG InputIntent,
    00022     LPSFLOAT IlluminantWP, LPSFLOAT MediaWP);
    00023
    00024 /***************************************************************************
    00025 *                           GetDevideRGB
    00026 *  function:
    00027 *    this is the function which creates the DeviceRGB ColorSpace (CS)
    00028 *  prototype:
    00029 *       BOOL EXTERN GetDeviceRGB(
    00030 *                          MEMPTR       lpMem,
    00031 *                          BOOL         AllowBinary)
    00032 *  parameters:
    00033 *       lpMem       --  Pointer to the memory block
    00034 *       AllowBinary --  1: binary CS allowed,  0: only ascii CS allowed.
    00035 *  returns:
    00036 *  returns:
    00037 *       BOOL        --  TRUE if the function was successful,
    00038 *                       FALSE otherwise.
    00039 ***************************************************************************/
    00040 static BOOL
    00041 GetDeviceRGB (
    00042               MEMPTR lpMem,
    00043               LPDWORD lpcbSize,
    00044               DWORD InpDrvClrSp,
    00045               BOOL  BackupCSA)
    00046 {
    00047     MEMPTR lpOldMem = lpMem;
    00048     if ((InpDrvClrSp != icSigRgbData) &&
    00049         (InpDrvClrSp != icSigDefData) &&
    00050         (InpDrvClrSp != 0))
    00051         return FALSE;
    00052
    00053     if (lpMem == NULL)
    00054     {
    00055         *lpcbSize = lstrlen (DeviceRGBTag) + 8;
    00056         return (TRUE);
    00057     }
    00058
    00059     if (BackupCSA)
    00060     {
    00061         lpMem += WriteNewLineObject (lpMem, NotSupportDEFG_S);
    00062     }
    00063
    00064     lpMem += WriteNewLineObject (lpMem, DeviceRGBTag);
    00065
    00066     if (BackupCSA)
    00067     {
    00068         lpMem += WriteNewLineObject (lpMem, SupportDEFG_E);
    00069     }
    00070
    00071     *lpcbSize = (DWORD) (lpMem - lpOldMem);
    00072     return (TRUE);
    00073 }
    00074 /***************************************************************************
    00075 *                           GetDevideCMYK
    00076 *  function:
    00077 *    this is the function which creates the DeviceCMYK ColorSpace (CS)
    00078 *  prototype:
    00079 *       BOOL EXTERN GetDeviceCMYK(
    00080 *                          MEMPTR       lpMem,
    00081 *                          BOOL         AllowBinary)
    00082 *  parameters:
    00083 *       lpMem       --  Pointer to the memory block
    00084 *       AllowBinary --  1: binary CS allowed,  0: only ascii CS allowed.
    00085 *  returns:
    00086 *  returns:
    00087 *       BOOL        --  TRUE if the function was successful,
    00088 *                       FALSE otherwise.
    00089 ***************************************************************************/
    00090
    00091 static BOOL
    00092 GetDeviceCMYK (
    00093                MEMPTR lpMem,
    00094                LPDWORD lpcbSize,
    00095                DWORD InpDrvClrSp)
    00096 {
    00097     MEMPTR lpOldMem = lpMem;
    00098     if ((InpDrvClrSp != icSigCmykData) &&
    00099         (InpDrvClrSp != 0))
    00100         return FALSE;
    00101     if (lpMem == NULL)
    00102     {
    00103         *lpcbSize = lstrlen (DeviceCMYKTag) + 8;
    00104         return (TRUE);
    00105     }
    00106     lpMem += WriteNewLineObject (lpMem, DeviceCMYKTag);
    00107
    00108     *lpcbSize = (DWORD) (lpMem - lpOldMem);
    00109     return (TRUE);
    00110
    00111 }
    00112 /***************************************************************************
    00113 *                           GetDeviceGray
    00114 ***************************************************************************/
    00115
    00116 static BOOL
    00117 GetDeviceGray (
    00118                MEMPTR lpMem,
    00119                LPDWORD lpcbSize,
    00120                DWORD InpDrvClrSp)
    00121 {
    00122     MEMPTR lpOldMem = lpMem;
    00123     if ((InpDrvClrSp == icSigRgbData) ||
    00124         (InpDrvClrSp == icSigDefData) ||
    00125         (InpDrvClrSp == 0))
    00126     {
    00127         if (lpMem == NULL)
    00128         {
    00129             *lpcbSize = lstrlen (DeviceRGBTag) + 8;
    00130             return (TRUE);
    00131         }
    00132         lpMem += WriteNewLineObject (lpMem, DeviceRGBTag);
    00133
    00134         *lpcbSize = (DWORD) (lpMem - lpOldMem);
    00135         return (TRUE);
    00136     } else if (InpDrvClrSp == icSigGrayData)
    00137     {
    00138         if (lpMem == NULL)
    00139         {
    00140             *lpcbSize = lstrlen (DeviceGrayTag) + 8;
    00141             return (TRUE);
    00142         }
    00143         lpMem += WriteNewLineObject (lpMem, DeviceGrayTag);
    00144
    00145         *lpcbSize = (DWORD) (lpMem - lpOldMem);
    00146         return (TRUE);
    00147     }
    00148 }
    00149 /***************************************************************************
    00150 *                           GetPublicArrayName
    00151 ***************************************************************************/
    00152
    00153 SINT
    00154 GetPublicArrayName (CHANDLE cp, CSIG IntentSig, MEMPTR PublicArrayName)
    00155 {
    00156     MEMPTR OldPtr;
    00157     OldPtr = PublicArrayName;
    00158     PublicArrayName[0] = 0;
    00159     MemCopy (PublicArrayName, (MEMPTR) & IntentSig, sizeof (CSIG));
    00160     PublicArrayName += sizeof (CSIG);
    00161     PublicArrayName[0] = 0;
    00162     return (PublicArrayName - OldPtr);
    00163 }
    00164
    00165 static SINT SendCSABWPoint(MEMPTR lpMem, CSIG Intent,
    00166                     LPSFLOAT IlluminantWP, LPSFLOAT MediaWP)
    00167 {
    00168     SINT   i;
    00169     MEMPTR lpOldMem = lpMem;
    00170
    00171  //********** /BlackPoint
    00172     lpMem += WriteNewLineObject (lpMem, BlackPointTag);
    00173     lpMem += WriteObject (lpMem, BlackPoint);
    00174
    00175  //********** /WhitePoint
    00176     lpMem += WriteNewLineObject (lpMem, WhitePointTag);
    00177     lpMem += WriteObject (lpMem, BeginArray);
    00178     for (i = 0; i < 3; i++)
    00179     {
    00180         if (Intent == icAbsoluteColorimetric)
    00181         {
    00182             lpMem += WriteFloat (lpMem, (double) MediaWP[i]);
    00183         }
    00184         else
    00185         {
    00186             lpMem += WriteFloat (lpMem, (double) IlluminantWP[i]);
    00187         }
    00188     }
    00189     lpMem += WriteObject (lpMem, EndArray);
    00190     return (SINT)(lpMem - lpOldMem);
    00191 }
    00192
    00193 static void GetMediaWP(CHANDLE cp, CSIG InputIntent,
    00194                        LPSFLOAT IlluminantWP, LPSFLOAT MediaWP)
    00195 {
    00196     if (InputIntent == icAbsoluteColorimetric)
    00197     {
    00198         if (!GetCPMediaWhitePoint (cp, (LPSFLOAT) & MediaWP)) // .. Media WhitePoint
    00199         {
    00200             MediaWP[0] = IlluminantWP[0];
    00201             MediaWP[1] = IlluminantWP[1];
    00202             MediaWP[2] = IlluminantWP[2];
    00203         }
    00204     }
    00205 }
    00206
    00207 SINT  BeginGlobalDict(MEMPTR lpMem)
    00208 {
    00209     MEMPTR lpOldMem = lpMem;
    00210
    00211     lpMem += WriteNewLineObject (lpMem, GlobalDictOp);
    00212     lpMem += WriteObject (lpMem, BeginOp);
    00213
    00214     return (lpMem - lpOldMem);
    00215 }
    00216
    00217 SINT  EndGlobalDict(MEMPTR lpMem)
    00218 {
    00219     MEMPTR lpOldMem = lpMem;
    00220
    00221     lpMem += WriteNewLineObject (lpMem, EndOp);
    00222     lpMem += WriteObject (lpMem, SetGlobalOp);
    00223
    00224     return (lpMem - lpOldMem);
    00225 }
    00226
    00227 SINT  EnableGlobalDict(MEMPTR lpMem)
    00228 {
    00229     MEMPTR lpOldMem = lpMem;
    00230
    00231     lpMem += WriteNewLineObject (lpMem, CurrentGlobalOp);
    00232     lpMem += WriteObject (lpMem, TrueOp);
    00233     lpMem += WriteObject (lpMem, SetGlobalOp);
    00234     return (lpMem - lpOldMem);
    00235 }
    00236
    00237 /***************************************************************************
    00238 *                           GetPS2CSA_DEFG
    00239 *  function:
    00240 *    this is the function which creates the CIEBasedDEF(G) ColorSpace (CS)
    00241 *    from the data supplied in the RGB or CMYK Input Profile.
    00242 *  prototype:
    00243 *       GetPS2CSA_DEFG(
    00244 *                       CHANDLE     cp,
    00245 *                       MEMPTR      lpMem,
    00246 *                       LPDWORD     lpcbSize,
    00247 *                       int         Type
    00248 *                       BOOL        AllowBinary)
    00249 *  parameters:
    00250 *       cp          --  Color Profile handle
    00251 *       lpMem       --  Pointer to the memory block. If this point is NULL,
    00252 *                       require buffer size.
    00253 *       lpcbSize    --  Size of the memory block
    00254 *       Type        --  CieBasedDEF or CieBasedDEFG.
    00255 *       AllowBinary --  1: binary CSA allowed,  0: only ascii CSA allowed.
    00256 *  returns:
    00257 *       BOOL        --  TRUE if the function was successful,
    00258 *                       FALSE otherwise.
    00259 ***************************************************************************/
    00260 static BOOL
    00261 GetPS2CSA_DEFG (
    00262                 CHANDLE cp,
    00263                 MEMPTR lpMem,
    00264                 LPDWORD lpcbSize,
    00265                 CSIG InputIntent,
    00266                 SINT Index,
    00267                 int Type,
    00268                 BOOL AllowBinary)
    00269 {
    00270     CSIG PCS, LutTag;
    00271     CSIG IntentSig;
    00272     SFLOAT IlluminantWP[3];
    00273     SFLOAT MediaWP[3];
    00274     SINT nInputCh, nOutputCh, nGrids, SecondGrids;
    00275     SINT nInputTable, nOutputTable, nNumbers;
    00276     SINT i, j, k;
    00277     MEMPTR lpTable;
    00278     MEMPTR lpOldMem = lpMem;
    00279     MEMPTR lpLut = NULL;
    00280     MEMPTR lpLineStart;
    00281     HGLOBAL hLut = 0;
    00282     SINT LutSize;
    00283     char PublicArrayName[TempBfSize];
    00284  // Check if we can generate the CS.
    00285  // Required  tags are: red, green and blue Colorants.
    00286  // As for TRC tags - we are quite flexible here - if we cannot find the
    00287  // required tag - we assume the linear responce
    00288     if (!GetCPConnSpace (cp, (LPCSIG) & PCS) ||
    00289         (PCS != icSigLabData) && (PCS != icSigXYZData) ||
    00290         !GetCPTagSig (cp, Index, (LPCSIG) & IntentSig))
    00291     {
    00292         return (FALSE);
    00293     }
    00294     if (!GetCPElementType (cp, Index, (LPCSIG) & LutTag) ||
    00295         ((LutTag != icSigLut8Type) && (LutTag != icSigLut16Type)) ||
    00296         !GetCPElementSize (cp, Index, (LPSINT) & LutSize) ||
    00297         !MemAlloc (LutSize, (HGLOBAL FAR *) &hLut, (LPMEMPTR) & lpLut) ||
    00298         !GetCPElement (cp, Index, lpLut, LutSize))
    00299     {
    00300         if (0 != hLut)
    00301         {
    00302             MemFree (hLut);
    00303         }
    00304         return (FALSE);
    00305     }
    00306  // Estimate the memory size required to hold CS
    00307
    00308     GetCLUTinfo(LutTag, lpLut, &nInputCh, &nOutputCh,
    00309         &nGrids, &nInputTable, &nOutputTable, &i);
    00310
    00311  // Level 2 printers support only tri-component CIEBasedABC input,
    00312  // but can have either 3 or 4 output channels.
    00313     if (!(nOutputCh == 3) ||
    00314         !((nInputCh == 3) && (Type == TYPE_CIEBASEDDEF)) &&
    00315         !((nInputCh == 4) && (Type == TYPE_CIEBASEDDEFG)))
    00316     {
    00317         SetCPLastError (CP_POSTSCRIPT_ERR);
    00318         MemFree (hLut);
    00319         return (FALSE);
    00320     }
    00321     if (lpMem == NULL)                  // This is a size request
    00322     {
    00323         if (Type == TYPE_CIEBASEDDEFG)
    00324             *lpcbSize = nOutputCh * nGrids * nGrids * nGrids * nGrids * 2;  // LUT HEX bytes
    00325         else
    00326             *lpcbSize = nOutputCh * nGrids * nGrids * nGrids * 2;   // LUT HEX bytes
    00327
    00328         *lpcbSize = *lpcbSize +
    00329             nInputCh * nInputTable * 6 +
    00330             nOutputCh * nOutputTable * 6 +  // Number of INT bytes
    00331             nInputCh * (lstrlen (IndexArray) +
    00332                         lstrlen (StartClip) +
    00333                         lstrlen (EndClip)) +
    00334             nOutputCh * (lstrlen (IndexArray) +
    00335                          lstrlen (StartClip) +
    00336                          lstrlen (EndClip)) +
    00337             4096;                       // + other PS stuff
    00338
    00339
    00340         return (TRUE);
    00341     }
    00342  // Get info about Illuminant White Point from the header
    00343     GetCPWhitePoint (cp, (LPSFLOAT) & IlluminantWP);          // .. Illuminant
    00344
    00345  // Support absolute whitePoint
    00346     GetMediaWP(cp, InputIntent, IlluminantWP, MediaWP);
    00347
    00348  //*********** Testing CieBasedDEFG support
    00349     lpMem += WriteNewLineObject (lpMem, TestingDEFG);
    00350
    00351  //*********** Creating global data
    00352     GetPublicArrayName (cp, IntentSig, PublicArrayName);
    00353     if (Type == TYPE_CIEBASEDDEFG)
    00354         lpMem += WriteNewLineObject (lpMem, CieBasedDEFGBegin);
    00355     else
    00356         lpMem += WriteNewLineObject (lpMem, CieBasedDEFBegin);
    00357
    00358     lpMem += EnableGlobalDict(lpMem);
    00359     lpMem += WriteNewLineObject (lpMem, SupportDEFG_S);
    00360     lpMem += BeginGlobalDict(lpMem);
    00361
    00362     lpMem += CreateInputArray (lpMem, nInputCh, nInputTable,
    00363              (MEMPTR) PublicArrayName, LutTag, lpLut, AllowBinary, NULL);
    00364
    00365     if (Type == TYPE_CIEBASEDDEFG)
    00366     {
    00367         i = nInputTable * nInputCh +
    00368             nGrids * nGrids * nGrids * nGrids * nOutputCh;
    00369     } else
    00370     {
    00371         i = nInputTable * nInputCh +
    00372             nGrids * nGrids * nGrids * nOutputCh;
    00373     }
    00374     lpMem += CreateOutputArray (lpMem, nOutputCh, nOutputTable, i,
    00375              (MEMPTR) PublicArrayName, LutTag, lpLut, AllowBinary, NULL);
    00376
    00377     lpMem += WriteNewLineObject (lpMem, EndOp);
    00378     lpMem += WriteNewLineObject (lpMem, SupportDEFG_E);
    00379     lpMem += WriteNewLineObject (lpMem, SetGlobalOp);
    00380     lpMem += WriteNewLineObject (lpMem, SupportDEFG_S);
    00381
    00382  //*********** Start creating the ColorSpace
    00383     lpMem += WriteNewLineObject (lpMem, BeginArray);   // Begin array
    00384
    00385  //********** /CIEBasedDEF(G)
    00386     if (Type == TYPE_CIEBASEDDEFG)
    00387         lpMem += WriteObject (lpMem, CIEBasedDEFGTag);
    00388     else
    00389         lpMem += WriteObject (lpMem, CIEBasedDEFTag);
    00390     lpMem += WriteObject (lpMem, BeginDict);    // Begin dictionary
    00391
    00392  //********** Black/White Point
    00393     lpMem += SendCSABWPoint(lpMem, InputIntent, IlluminantWP, MediaWP);
    00394
    00395  //********** /DecodeDEF(G)
    00396     lpLineStart = lpMem;
    00397     if (Type == TYPE_CIEBASEDDEFG)
    00398         lpMem += WriteNewLineObject (lpMem, DecodeDEFGTag);
    00399     else
    00400         lpMem += WriteNewLineObject (lpMem, DecodeDEFTag);
    00401
    00402     lpMem += WriteObject (lpMem, BeginArray);
    00403     for (i = 0; i < nInputCh; i++)
    00404     {
    00405         lpLineStart = lpMem;
    00406
    00407         lpMem += WriteNewLineObject (lpMem, BeginFunction);
    00408 #if 0
    00409         if (PCS == icSigLabData)
    00410         {
    00411             lpMem += WriteObject (lpMem,
    00412                                   (0 == i) ? EncodeABCLab1 : EncodeABCLab2);
    00413         }
    00414 #endif
    00415         lpMem += WriteObject (lpMem, StartClip);
    00416         lpMem += WriteObject (lpMem, InputArray);
    00417         lpMem += WriteObjectN (lpMem, (MEMPTR) PublicArrayName, lstrlen (PublicArrayName));
    00418         lpMem += WriteInt (lpMem, i);
    00419
    00420         if (!AllowBinary)               // Output ASCII
    00421         {
    00422             lpMem += WriteObject (lpMem, IndexArray);
    00423         } else
    00424         {                               // Output BINARY
    00425             if (LutTag == icSigLut8Type)
    00426             {
    00427                 lpMem += WriteObject (lpMem, IndexArray);
    00428             } else
    00429             {
    00430                 lpMem += WriteObject (lpMem, IndexArray16b);
    00431             }
    00432         }
    00433         lpMem += WriteObject (lpMem, (LutTag == icSigLut8Type) ? Scale8 : Scale16);
    00434         lpMem += WriteObject (lpMem, EndClip);
    00435         lpMem += WriteObject (lpMem, EndFunction);
    00436     }
    00437     lpMem += WriteObject (lpMem, EndArray);
    00438
    00439  //********** /Table
    00440     lpMem += WriteNewLineObject (lpMem, TableTag);
    00441     lpMem += WriteObject (lpMem, BeginArray);
    00442
    00443     lpMem += WriteInt (lpMem, nGrids);  // Send down Nh
    00444     lpMem += WriteInt (lpMem, nGrids);  // Send down Ni
    00445     lpMem += WriteInt (lpMem, nGrids);  // Send down Nj
    00446     nNumbers = nGrids * nGrids * nOutputCh;
    00447     SecondGrids = 1;
    00448     if (Type == TYPE_CIEBASEDDEFG)
    00449     {
    00450         lpMem += WriteInt (lpMem, nGrids);  // Send down Nk
    00451 //       nNumbers = nGrids * nGrids * nGrids * nOutputCh ;
    00452         SecondGrids = nGrids;
    00453     }
    00454     lpMem += WriteNewLineObject (lpMem, BeginArray);
    00455     for (i = 0; i < nGrids; i++)        // Nh strings should be sent
    00456     {
    00457         if (Type == TYPE_CIEBASEDDEFG)
    00458         {
    00459             lpMem += WriteNewLineObject (lpMem, BeginArray);
    00460         }
    00461         for (k = 0; k < SecondGrids; k++)
    00462         {
    00463             lpLineStart = lpMem;
    00464             lpMem += WriteObject (lpMem, NewLine);
    00465             if (LutTag == icSigLut8Type)
    00466             {
    00467                 lpTable = (MEMPTR) (((lpcpLut8Type) lpLut)->lut.data) +
    00468                     nInputTable * nInputCh +
    00469                     nNumbers * (i * SecondGrids + k);
    00470             } else
    00471             {
    00472                 lpTable = (MEMPTR) (((lpcpLut16Type) lpLut)->lut.data) +
    00473                     2 * nInputTable * nInputCh +
    00474                     2 * nNumbers * (i * SecondGrids + k);
    00475             }
    00476
    00477             if (!AllowBinary)           // Output ASCII
    00478             {
    00479                 lpMem += WriteObject (lpMem, BeginString);
    00480                 if (LutTag == icSigLut8Type)
    00481                     lpMem += WriteHexBuffer (lpMem, lpTable, lpLineStart, nNumbers);
    00482                 else
    00483                 {
    00484                     for (j = 0; j < nNumbers; j++)
    00485                     {
    00486                         lpMem += WriteHex (lpMem, ui16toSINT (lpTable) / 256);
    00487                         lpTable += sizeof (icUInt16Number);
    00488                         if (((SINT) (lpMem - lpLineStart)) > MAX_LINELENG)
    00489                         {
    00490                             lpLineStart = lpMem;
    00491                             lpMem += WriteObject (lpMem, NewLine);
    00492                         }
    00493                     }
    00494                 }
    00495                 lpMem += WriteObject (lpMem, EndString);
    00496             } else
    00497             {                           // Output BINARY
    00498                 lpMem += WriteStringToken (lpMem, 143, nNumbers);
    00499                 if (LutTag == icSigLut8Type)
    00500                     lpMem += WriteByteString (lpMem, lpTable, nNumbers);
    00501                 else
    00502                     lpMem += WriteInt2ByteString (lpMem, lpTable, nNumbers);
    00503             }
    00504             lpMem += WriteObject (lpMem, NewLine);
    00505         }
    00506         if (Type == TYPE_CIEBASEDDEFG)
    00507         {
    00508             lpMem += WriteObject (lpMem, EndArray);
    00509         }
    00510     }
    00511     lpMem += WriteObject (lpMem, EndArray);
    00512     lpMem += WriteObject (lpMem, EndArray); // End array
    00513
    00514  //********** /DecodeABC
    00515     lpLineStart = lpMem;
    00516     lpMem += WriteNewLineObject (lpMem, DecodeABCTag);
    00517     lpMem += WriteObject (lpMem, BeginArray);
    00518     for (i = 0; i < nOutputCh; i++)
    00519     {
    00520         lpLineStart = lpMem;
    00521         lpMem += WriteNewLineObject (lpMem, BeginFunction);
    00522         lpMem += WriteObject (lpMem, Clip01);
    00523         lpMem += WriteObject (lpMem, OutputArray);
    00524         lpMem += WriteObjectN (lpMem, (MEMPTR) PublicArrayName, lstrlen (PublicArrayName));
    00525         lpMem += WriteInt (lpMem, i);
    00526
    00527         if (!AllowBinary)               // Output ASCII CRD
    00528         {
    00529             lpMem += WriteObject (lpMem, NewLine);
    00530
    00531             if (LutTag == icSigLut8Type)
    00532             {
    00533                 lpMem += WriteObject (lpMem, TFunction8XYZ);
    00534             } else
    00535             {
    00536                 lpMem += WriteObject (lpMem, IndexArray);
    00537                 lpMem += WriteObject (lpMem, Scale16XYZ);
    00538             }
    00539         } else
    00540         {                               // Output BINARY CRD
    00541             if (LutTag == icSigLut8Type)
    00542             {
    00543                 lpMem += WriteObject (lpMem, TFunction8XYZ);
    00544             } else
    00545             {
    00546                 lpMem += WriteObject (lpMem, IndexArray16b);
    00547                 lpMem += WriteObject (lpMem, Scale16XYZ);
    00548             }
    00549         }
    00550
    00551  // Now, We get CieBasedXYZ output. Output range 0 --> 1.99997
    00552  // If the connection space is absolute XYZ, We need to convert
    00553  // from relative XYZ to absolute XYZ.
    00554         if ((PCS == icSigXYZData) &&
    00555             (InputIntent == icAbsoluteColorimetric))
    00556         {
    00557             lpMem += WriteFloat (lpMem, (double)MediaWP[i]/IlluminantWP[i]);
    00558             lpMem += WriteObject (lpMem, MulOp);
    00559         }
    00560  // If the connection space is Lab, We need to convert XYZ to Lab.
    00561         else if (PCS == icSigLabData)
    00562             lpMem += WriteObject (lpMem, DecodeABCLab[i]);
    00563         lpMem += WriteObject (lpMem, EndFunction);
    00564     }
    00565     lpMem += WriteObject (lpMem, EndArray);
    00566
    00567     if (PCS == icSigLabData)
    00568     {
    00569  //********** /MatrixABC
    00570         lpMem += WriteNewLineObject (lpMem, MatrixABCTag);
    00571         lpMem += WriteObject (lpMem, MatrixABCLab);
    00572
    00573  //********** /DecodeLMN
    00574         lpLineStart = lpMem;
    00575         lpMem += WriteNewLineObject (lpMem, DecodeLMNTag);
    00576         lpMem += WriteObject (lpMem, BeginArray);
    00577         for (i = 0; i < 3; i++)
    00578         {
    00579             lpLineStart = lpMem;
    00580             lpMem += WriteNewLineObject (lpMem, BeginFunction);
    00581             lpMem += WriteObject (lpMem, DecodeLMNLab);
    00582             if (InputIntent == icAbsoluteColorimetric)
    00583                 lpMem += WriteFloat (lpMem, (double) MediaWP[i]);
    00584             else
    00585                 lpMem += WriteFloat (lpMem, (double) IlluminantWP[i]);
    00586             lpMem += WriteObject (lpMem, MulOp);
    00587             lpMem += WriteObject (lpMem, EndFunction);
    00588         }
    00589         lpMem += WriteObject (lpMem, EndArray);
    00590     } else
    00591     {
    00592  //********** /RangeLMN
    00593         lpMem += WriteNewLineObject (lpMem, RangeLMNTag);
    00594         lpMem += WriteObject (lpMem, RangeLMN);
    00595     }
    00596
    00597  //********** End dictionary definition
    00598     lpMem += WriteNewLineObject (lpMem, EndDict);
    00599     lpMem += WriteObject (lpMem, EndArray);
    00600
    00601     if (Type == TYPE_CIEBASEDDEFG)
    00602         lpMem += WriteNewLineObject (lpMem, CieBasedDEFGEnd);
    00603     else
    00604         lpMem += WriteNewLineObject (lpMem, CieBasedDEFEnd);
    00605
    00606     lpMem += WriteNewLineObject (lpMem, SupportDEFG_E);
    00607
    00608     *lpcbSize = (DWORD) (lpMem - lpOldMem);
    00609
    00610     MemFree (hLut);
    00611     return (TRUE);
    00612 }
    00613
    00614 /***************************************************************************
    00615 *                           GetPS2CSA_ABC
    00616 *  function:
    00617 *    this is the function which creates the CIEBasedABC ColorSpace (CS)
    00618 *    from the data supplied in the RGB Input Profile.
    00619 *  prototype:
    00620 *       GetPS2CSA_ABC(
    00621 *                       CHANDLE     cp,
    00622 *                       MEMPTR      lpMem,
    00623 *                       LPDWORD     lpcbSize,
    00624 *                       BOOL        AllowBinary)
    00625 *  parameters:
    00626 *       cp          --  Color Profile handle
    00627 *       lpMem       --  Pointer to the memory block. If this point is NULL,
    00628 *                       require buffer size.
    00629 *       lpcbSize    --  Size of the memory block
    00630 *       InputIntent --
    00631 *       InpDrvClrSp --
    00632 *       AllowBinary --  1: binary CSA allowed,  0: only ascii CSA allowed.
    00633 *       BackupCSA   --  1: A CIEBasedDEF has been created, this CSA is a backup
    00634 *                          in case some old printer can not support CIEBasedDEF.
    00635 *                       0: No CIEBasedDEF. This is the only CSA.
    00636 *  returns:
    00637 *       BOOL        --  TRUE if the function was successful,
    00638 *                       FALSE otherwise.
    00639 ***************************************************************************/
    00640
    00641 BOOL
    00642 GetPS2CSA_ABC (CHANDLE cp, MEMPTR lpMem, LPDWORD lpcbSize,
    00643                CSIG InputIntent, DWORD InpDrvClrSp,
    00644                BOOL AllowBinary, BOOL BackupCSA)
    00645 {
    00646     CSIG PCS, Dev;
    00647     SFLOAT IlluminantWP[3];
    00648     SFLOAT MediaWP[3];
    00649
    00650     SINT i;
    00651     MEMPTR lpOldMem = lpMem;
    00652     SINT Ret = 0;
    00653
    00654  // Check if we can generate the CS.
    00655  // Required  tags are: red, green and blue Colorants.
    00656  // As for TRC tags - we are quite flexible here - if we cannot find the
    00657  // required tag - we assume the linear responce
    00658     if (!GetCPConnSpace (cp, (LPCSIG) & PCS) ||
    00659         !GetCPDevSpace (cp, (LPCSIG) & Dev) ||
    00660         (Dev != icSigRgbData) ||
    00661         !DoesTRCAndColorantTagExist(cp))
    00662     {
    00663         return (FALSE);
    00664     }
    00665     if ((InpDrvClrSp != icSigRgbData) &&
    00666         (InpDrvClrSp != icSigDefData) &&
    00667         (InpDrvClrSp != 0))
    00668     {
    00669         return (FALSE);
    00670     }
    00671  // Estimate the memory size required to hold CS
    00672
    00673     if (lpMem == NULL)                  // This is a size request
    00674     {
    00675         *lpcbSize = 65530;
    00676         return (TRUE);
    00677     }
    00678
    00679  // Get info about Illuminant White Point from the header
    00680     GetCPWhitePoint (cp, (LPSFLOAT) & IlluminantWP);     // .. Illuminant
    00681
    00682  // Support absolute whitePoint
    00683     GetMediaWP(cp, InputIntent, IlluminantWP, MediaWP);
    00684
    00685  //*********** Creating global data
    00686
    00687     lpMem += WriteNewLineObject (lpMem, CieBasedABCBegin);
    00688
    00689     if (IsSRGB(cp))
    00690     {
    00691        lpMem += WriteNewLineObject (lpMem, AdobeCSA);
    00692     }
    00693     else
    00694     {
    00695        lpMem += EnableGlobalDict(lpMem);
    00696
    00697        if (BackupCSA)
    00698        {
    00699            lpMem += WriteNewLineObject (lpMem, NotSupportDEFG_S);
    00700        }
    00701
    00702        lpMem += BeginGlobalDict(lpMem);
    00703
    00704        lpMem += CreateColSpArray (cp, lpMem, icSigRedTRCTag, AllowBinary);
    00705        lpMem += CreateColSpArray (cp, lpMem, icSigGreenTRCTag, AllowBinary);
    00706        lpMem += CreateColSpArray (cp, lpMem, icSigBlueTRCTag, AllowBinary);
    00707
    00708        lpMem += WriteNewLineObject (lpMem, EndOp);
    00709
    00710        if (BackupCSA)
    00711        {
    00712            lpMem += WriteNewLineObject (lpMem, SupportDEFG_E);
    00713        }
    00714        lpMem += WriteNewLineObject (lpMem, SetGlobalOp);
    00715
    00716        if (BackupCSA)
    00717        {
    00718            lpMem += WriteNewLineObject (lpMem, NotSupportDEFG_S);
    00719        }
    00720
    00721     //*********** Start creating the ColorSpace
    00722        lpMem += WriteNewLineObject (lpMem, BeginArray);   // Begin array
    00723     //********** /CIEBasedABC
    00724        lpMem += WriteObject (lpMem, CIEBasedABCTag);   // Create entry
    00725        lpMem += WriteObject (lpMem, BeginDict);    // Begin dictionary
    00726
    00727     //********** Black/White Point
    00728        lpMem += SendCSABWPoint(lpMem, InputIntent, IlluminantWP, MediaWP);
    00729
    00730     //********** /DecodeABC
    00731        lpMem += WriteNewLineObject (lpMem, DecodeABCTag);
    00732        lpMem += WriteObject (lpMem, BeginArray);
    00733
    00734        lpMem += WriteObject (lpMem, NewLine);
    00735        lpMem += CreateColSpProc (cp, lpMem, icSigRedTRCTag, AllowBinary);
    00736        lpMem += WriteObject (lpMem, NewLine);
    00737        lpMem += CreateColSpProc (cp, lpMem, icSigGreenTRCTag, AllowBinary);
    00738        lpMem += WriteObject (lpMem, NewLine);
    00739        lpMem += CreateColSpProc (cp, lpMem, icSigBlueTRCTag, AllowBinary);
    00740        lpMem += WriteObject (lpMem, EndArray);
    00741
    00742     //********** /MatrixABC
    00743        lpMem += WriteNewLineObject (lpMem, MatrixABCTag);
    00744        lpMem += WriteObject (lpMem, BeginArray);
    00745
    00746        lpMem += CreateFloatString (cp, lpMem, icSigRedColorantTag);
    00747        lpMem += CreateFloatString (cp, lpMem, icSigGreenColorantTag);
    00748        lpMem += CreateFloatString (cp, lpMem, icSigBlueColorantTag);
    00749
    00750        lpMem += WriteObject (lpMem, EndArray);
    00751
    00752     //********** /RangeLMN
    00753        lpMem += WriteNewLineObject (lpMem, RangeLMNTag);
    00754        lpMem += WriteObject (lpMem, RangeLMN);
    00755
    00756     //********** /DecodeLMN
    00757        if (InputIntent == icAbsoluteColorimetric)
    00758        {
    00759            // Support absolute whitePoint
    00760            lpMem += WriteNewLineObject (lpMem, DecodeLMNTag);
    00761            lpMem += WriteObject (lpMem, BeginArray);
    00762            for (i = 0; i < 3; i ++)
    00763            {
    00764                lpMem += WriteObject (lpMem, BeginFunction);
    00765                lpMem += WriteFloat (lpMem, (double)MediaWP[i]/IlluminantWP[i]);
    00766                lpMem += WriteObject (lpMem, MulOp);
    00767                lpMem += WriteObject (lpMem, EndFunction);
    00768            }
    00769            lpMem += WriteObject (lpMem, EndArray);
    00770        }
    00771
    00772     //********** End dictionary definition
    00773        lpMem += WriteNewLineObject (lpMem, EndDict);
    00774        lpMem += WriteObject (lpMem, EndArray);
    00775
    00776        if (BackupCSA)
    00777        {
    00778            lpMem += WriteNewLineObject (lpMem, SupportDEFG_E);
    00779        }
    00780
    00781     }
    00782     lpMem += WriteNewLineObject (lpMem, CieBasedABCEnd);
    00783     *lpcbSize = (DWORD) ((lpMem - lpOldMem));
    00784     return (TRUE);
    00785 }
    00786
    00787 /***************************************************************************
    00788 *                           GetPS2CSA_ABC_LAB
    00789 *  function:
    00790 *    this is the function which creates the CIEBasedABC ColorSpace (CS)
    00791 *    from the data supplied in the LAB Input Profile.
    00792 *  prototype:
    00793 *       GetPS2CSA_ABC(
    00794 *                       CHANDLE     cp,
    00795 *                       MEMPTR      lpMem,
    00796 *                       LPDWORD     lpcbSize,
    00797 *                       BOOL        AllowBinary)
    00798 *  parameters:
    00799 *       cp          --  Color Profile handle
    00800 *       lpMem       --  Pointer to the memory block. If this point is NULL,
    00801 *                       require buffer size.
    00802 *       lpcbSize    --  Size of the memory block
    00803 *       InputIntent --
    00804 *       InpDrvClrSp --
    00805 *       AllowBinary --  1: binary CSA allowed,  0: only ascii CSA allowed.
    00806 *  returns:
    00807 *       BOOL        --  TRUE if the function was successful,
    00808 *                       FALSE otherwise.
    00809 ***************************************************************************/
    00810
    00811 BOOL
    00812 GetPS2CSA_ABC_LAB (CHANDLE cp, MEMPTR lpMem, LPDWORD lpcbSize,
    00813                CSIG InputIntent, DWORD InpDrvClrSp, BOOL AllowBinary)
    00814 {
    00815     CSIG PCS, Dev;
    00816     SFLOAT IlluminantWP[3];
    00817     SFLOAT MediaWP[3];
    00818
    00819     SINT i;
    00820     MEMPTR lpOldMem = lpMem;
    00821     SINT Ret = 0;
    00822  // Check if we can generate the CS.
    00823  // Required  tags are: red, green and blue Colorants.
    00824  // As for TRC tags - we are quite flexible here - if we cannot find the
    00825  // required tag - we assume the linear responce
    00826     if (!GetCPConnSpace (cp, (LPCSIG) & PCS) ||
    00827         !GetCPDevSpace (cp, (LPCSIG) & Dev) ||
    00828         (Dev != icSigLabData))
    00829     {
    00830         return (FALSE);
    00831     }
    00832     if ((InpDrvClrSp != icSigLabData) &&
    00833         (InpDrvClrSp != icSigDefData) &&
    00834         (InpDrvClrSp != 0))
    00835     {
    00836         return (FALSE);
    00837     }
    00838  // Estimate the memory size required to hold CS
    00839
    00840     if (lpMem == NULL)                  // This is a size request
    00841     {
    00842         *lpcbSize = 65530;
    00843         return (TRUE);
    00844     }
    00845  // Get info about Illuminant White Point from the header
    00846     GetCPWhitePoint (cp, (LPSFLOAT) & IlluminantWP);     // .. Illuminant
    00847
    00848  // Support absolute whitePoint
    00849     GetMediaWP(cp, InputIntent, IlluminantWP, MediaWP);
    00850
    00851  //*********** Start creating the ColorSpace
    00852     lpMem += WriteNewLineObject (lpMem, BeginArray);   // Begin array
    00853
    00854  //********** /CIEBasedABC
    00855     lpMem += WriteObject (lpMem, CIEBasedABCTag);   // Create entry
    00856     lpMem += WriteObject (lpMem, BeginDict);    // Begin dictionary
    00857
    00858  //********** Black/White Point
    00859     lpMem += SendCSABWPoint(lpMem, InputIntent, IlluminantWP, MediaWP);
    00860
    00861  //********** /RangeABC
    00862     lpMem += WriteNewLineObject (lpMem, RangeABCTag);
    00863     lpMem += WriteObject (lpMem, RangeABC_Lab);
    00864
    00865  //********** /DecodeABC
    00866     lpMem += WriteNewLineObject (lpMem, DecodeABCTag);
    00867     lpMem += WriteObject (lpMem, DecodeABCLab1);
    00868
    00869  //********** /MatrixABC
    00870     lpMem += WriteNewLineObject (lpMem, MatrixABCTag);
    00871     lpMem += WriteObject (lpMem, MatrixABCLab);
    00872
    00873  //********** /DecodeLMN
    00874     lpMem += WriteNewLineObject (lpMem, DecodeLMNTag);
    00875     lpMem += WriteObject (lpMem, BeginArray);
    00876     for (i = 0; i < 3; i ++)
    00877     {
    00878         lpMem += WriteObject (lpMem, BeginFunction);
    00879         lpMem += WriteObject (lpMem, DecodeLMNLab);
    00880         if (InputIntent == icAbsoluteColorimetric)
    00881         {
    00882             lpMem += WriteFloat (lpMem, (double) MediaWP[i]);
    00883         }
    00884         else
    00885         {
    00886             lpMem += WriteFloat (lpMem, (double) IlluminantWP[i]);
    00887         }
    00888         lpMem += WriteObject (lpMem, MulOp);
    00889         lpMem += WriteObject (lpMem, EndFunction);
    00890         lpMem += WriteObject (lpMem, NewLine);
    00891     }
    00892     lpMem += WriteObject (lpMem, EndArray);
    00893
    00894
    00895  //********** End dictionary definition
    00896     lpMem += WriteNewLineObject (lpMem, EndDict);
    00897     lpMem += WriteObject (lpMem, EndArray);
    00898
    00899     lpMem += WriteNewLineObject (lpMem, CieBasedABCEnd);
    00900     *lpcbSize = (DWORD) ((lpMem - lpOldMem));
    00901     return (TRUE);
    00902 }
    00903
    00904 /***************************************************************************
    00905 *                           GetPS2CSA_MONO_ABC
    00906 *  function:
    00907 *    this is the function which creates the CIEBasedABC ColorSpace (CS)
    00908 *    from the data supplied in the GRAY Input Profile.
    00909 *  prototype:
    00910 *       GetPS2CSA_MONO_ABC(
    00911 *                       CHANDLE     cp,
    00912 *                       MEMPTR      lpMem,
    00913 *                       LPDWORD     lpcbSize,
    00914 *                       BOOL        AllowBinary)
    00915 *  parameters:
    00916 *       cp          --  Color Profile handle
    00917 *       lpMem       --  Pointer to the memory block. If this point is NULL,
    00918 *                       require buffer size.
    00919 *       lpcbSize    --  Size of the memory block
    00920 *       AllowBinary --  1: binary CSA allowed,  0: only ascii CSA allowed.
    00921 *  returns:
    00922 *       BOOL        --  TRUE if the function was successful,
    00923 *                       FALSE otherwise.
    00924 ***************************************************************************/
    00925
    00926 static BOOL
    00927 GetPS2CSA_MONO_ABC (CHANDLE cp, MEMPTR lpMem, LPDWORD lpcbSize,
    00928                     CSIG InputIntent, BOOL AllowBinary)
    00929 {
    00930     SINT nCount;
    00931     CSIG Tag, PCS;
    00932     SINT i, j, Index;
    00933     MEMPTR lpTable;
    00934     SFLOAT IlluminantWP[3];
    00935     SFLOAT MediaWP[3];
    00936     MEMPTR lpBuff = NULL;
    00937     SINT MemSize = 0;
    00938     MEMPTR lpOldMem = lpMem;
    00939     HGLOBAL hBuff;
    00940     MEMPTR lpLineStart;
    00941  // Check if we can generate the CS
    00942     if (!DoesCPTagExist (cp, icSigGrayTRCTag) ||
    00943         !GetCPTagIndex (cp, icSigGrayTRCTag, &Index) ||
    00944         !GetCPElementType (cp, Index, (LPCSIG) & Tag) ||
    00945         (Tag != icSigCurveType) ||
    00946         !GetCPConnSpace (cp, (LPCSIG) & PCS) ||
    00947         !GetCPElementSize (cp, Index, (LPSINT) & MemSize) ||
    00948         !MemAlloc (MemSize, (HGLOBAL FAR *)&hBuff, (LPMEMPTR) & lpBuff) ||
    00949         !GetCPElement (cp, Index, lpBuff, MemSize))
    00950     {
    00951         if (NULL != lpBuff)
    00952         {
    00953             MemFree (hBuff);
    00954         }
    00955         return (FALSE);
    00956     }
    00957     nCount = ui32toSINT (((lpcpCurveType) lpBuff)->curve.count);
    00958
    00959  // Estimate the memory size required to hold CS
    00960     *lpcbSize = nCount * 6 +            // Number of INT elements
    00961         3 * (lstrlen (IndexArray) +
    00962              lstrlen (StartClip) +
    00963              lstrlen (EndClip)) +
    00964         2048;                           // + other PS stuff
    00965     if (lpMem == NULL)                  // This is a size request
    00966     {
    00967         MemFree (hBuff);
    00968         return (TRUE);
    00969     }
    00970  // Get info about Illuminant White Point from the header
    00971     GetCPWhitePoint (cp, (LPSFLOAT) & IlluminantWP);          // .. Illuminant
    00972
    00973  // Support absolute whitePoint
    00974     GetMediaWP(cp, InputIntent, IlluminantWP, MediaWP);
    00975
    00976  //*********** Start creating the ColorSpace
    00977     lpMem += WriteNewLineObject (lpMem, CieBasedABCBegin);
    00978
    00979     lpMem += WriteNewLineObject (lpMem, BeginArray);   // Begin array
    00980  //********** /CIEBasedABC
    00981     lpMem += WriteObject (lpMem, CIEBasedABCTag);   // Create entry
    00982     lpMem += WriteObject (lpMem, BeginDict);    // Begin dictionary
    00983
    00984  //********** Black/White Point
    00985     lpMem += SendCSABWPoint(lpMem, InputIntent, IlluminantWP, MediaWP);
    00986
    00987  //********** /DecodeABC
    00988     lpMem += WriteObject (lpMem, NewLine);
    00989     lpLineStart = lpMem;
    00990
    00991     if (nCount != 0)
    00992     {
    00993         lpMem += WriteObject (lpMem, DecodeABCTag);
    00994         lpMem += WriteObject (lpMem, BeginArray);
    00995
    00996         lpMem += WriteObject (lpMem, BeginFunction);
    00997         if (nCount == 1)                // Gamma supplied in ui16 format
    00998         {
    00999             lpTable = (MEMPTR) (((lpcpCurveType) lpBuff)->curve.data);
    01000             lpMem += WriteInt (lpMem, ui16toSINT (lpTable));
    01001             lpMem += WriteObject (lpMem, DecodeA3);
    01002         } else
    01003         {
    01004             lpMem += WriteObject (lpMem, StartClip);
    01005             lpTable = (MEMPTR) (((lpcpCurveType) lpBuff)->curve.data);
    01006             lpMem += WriteObject (lpMem, BeginArray);
    01007             for (i = 0; i < nCount; i++)
    01008             {
    01009                 lpMem += WriteInt (lpMem, ui16toSINT (lpTable));
    01010                 lpTable += sizeof (icUInt16Number);
    01011                 if (((SINT) (lpMem - lpLineStart)) > MAX_LINELENG)
    01012                 {
    01013                     lpLineStart = lpMem;
    01014                     lpMem += WriteObject (lpMem, NewLine);
    01015                 }
    01016             }
    01017             lpMem += WriteObject (lpMem, EndArray);
    01018             lpLineStart = lpMem;
    01019             lpMem += WriteObject (lpMem, NewLine);
    01020
    01021             lpMem += WriteObject (lpMem, IndexArray);
    01022             lpMem += WriteObject (lpMem, Scale16);
    01023             lpMem += WriteObject (lpMem, EndClip);
    01024         }
    01025         lpMem += WriteObject (lpMem, EndFunction);
    01026         lpMem += WriteObject (lpMem, DupOp);
    01027         lpMem += WriteObject (lpMem, DupOp);
    01028         lpMem += WriteObject (lpMem, EndArray);
    01029     }
    01030  //********** /MatrixABC
    01031     lpMem += WriteNewLineObject (lpMem, MatrixABCTag);
    01032     lpMem += WriteObject (lpMem, BeginArray);
    01033     for (i = 0; i < 3; i ++)
    01034     {
    01035         for (j = 0; j < 3; j++)
    01036         {
    01037             if (i != j)
    01038                 lpMem += WriteFloat (lpMem, (double)0);
    01039             else
    01040             {
    01041                 if (InputIntent == icAbsoluteColorimetric)
    01042                     lpMem += WriteFloat (lpMem, (double)MediaWP[i]);
    01043                 else
    01044                     lpMem += WriteFloat (lpMem, (double)IlluminantWP[i]);
    01045             }
    01046         }
    01047     }
    01048     lpMem += WriteObject (lpMem, EndArray);
    01049
    01050  //********** /RangeLMN
    01051     lpMem += WriteNewLineObject (lpMem, RangeLMNTag);
    01052     lpMem += WriteObject (lpMem, RangeLMN);
    01053
    01054
    01055     lpMem += WriteObject (lpMem, EndDict);  // End dictionary definition
    01056     lpMem += WriteObject (lpMem, EndArray);
    01057
    01058     MemFree (hBuff);
    01059
    01060     lpMem += WriteNewLineObject (lpMem, CieBasedABCEnd);
    01061     *lpcbSize = (DWORD) (lpMem - lpOldMem);
    01062     return (TRUE);
    01063 }
    01064 /***************************************************************************
    01065 *                           GetPS2CSA_MONO_A
    01066 *  function:
    01067 *    this is the function which creates the CIEBasedA ColorSpace (CS)
    01068 *    from the data supplied in the GRAY Input Profile.
    01069 *  prototype:
    01070 *       GetPS2CSA_MONO_A(
    01071 *                       CHANDLE     cp,
    01072 *                       MEMPTR      lpMem,
    01073 *                       LPDWORD     lpcbSize,
    01074 *                       BOOL        AllowBinary)
    01075 *  parameters:
    01076 *       cp          --  Color Profile handle
    01077 *       lpMem       --  Pointer to the memory block. If this point is NULL,
    01078 *                       require buffer size.
    01079 *       lpcbSize    --  Size of the memory block
    01080 *       AllowBinary --  1: binary CSA allowed,  0: only ascii CSA allowed.
    01081 *  returns:
    01082 *       BOOL        --  TRUE if the function was successful,
    01083 *                       FALSE otherwise.
    01084 ***************************************************************************/
    01085
    01086 static BOOL
    01087 GetPS2CSA_MONO_A (CHANDLE cp, MEMPTR lpMem, LPDWORD lpcbSize,
    01088                   CSIG InputIntent, BOOL AllowBinary)
    01089 {
    01090     SINT nCount;
    01091     CSIG Tag, PCS;
    01092     SINT i, Index;
    01093     MEMPTR lpTable;
    01094     SFLOAT IlluminantWP[3];
    01095     SFLOAT MediaWP[3];
    01096     MEMPTR lpBuff = NULL;
    01097     SINT MemSize = 0;
    01098     MEMPTR lpOldMem = lpMem;
    01099     HGLOBAL hBuff;
    01100     MEMPTR lpLineStart;
    01101  // Check if we can generate the CS
    01102     if (!DoesCPTagExist (cp, icSigGrayTRCTag) ||
    01103         !GetCPTagIndex (cp, icSigGrayTRCTag, &Index) ||
    01104         !GetCPElementType (cp, Index, (LPCSIG) & Tag) ||
    01105         (Tag != icSigCurveType) ||
    01106         !GetCPConnSpace (cp, (LPCSIG) & PCS) ||
    01107         !GetCPElementSize (cp, Index, (LPSINT) & MemSize) ||
    01108         !MemAlloc (MemSize, (HGLOBAL FAR *)&hBuff, (LPMEMPTR) & lpBuff) ||
    01109         !GetCPElement (cp, Index, lpBuff, MemSize))
    01110     {
    01111         if (NULL != lpBuff)
    01112         {
    01113             MemFree (hBuff);
    01114         }
    01115         return (FALSE);
    01116     }
    01117     nCount = ui32toSINT (((lpcpCurveType) lpBuff)->curve.count);
    01118
    01119  // Estimate the memory size required to hold CS
    01120     *lpcbSize = nCount * 6 +            // Number of INT elements
    01121         3 * (lstrlen (IndexArray) +
    01122              lstrlen (StartClip) +
    01123              lstrlen (EndClip)) +
    01124         2048;                           // + other PS stuff
    01125     if (lpMem == NULL)                  // This is a size request
    01126     {
    01127         MemFree (hBuff);
    01128         return (TRUE);
    01129     }
    01130  // Get info about Illuminant White Point from the header
    01131     GetCPWhitePoint (cp, (LPSFLOAT) & IlluminantWP);          // .. Illuminant
    01132
    01133  // Support absolute whitePoint
    01134     GetMediaWP(cp, InputIntent, IlluminantWP, MediaWP);
    01135
    01136  //*********** Start creating the ColorSpace
    01137     lpMem += WriteNewLineObject (lpMem, CieBasedABegin);
    01138
    01139     lpMem += WriteNewLineObject (lpMem, BeginArray);   // Begin array
    01140  //********** /CIEBasedA
    01141     lpMem += WriteObject (lpMem, CIEBasedATag); // Create entry
    01142     lpMem += WriteObject (lpMem, BeginDict);    // Begin dictionary
    01143
    01144  //********** Black/White Point
    01145     lpMem += SendCSABWPoint(lpMem, InputIntent, IlluminantWP, MediaWP);
    01146
    01147  //********** /DecodeA
    01148     lpMem += WriteObject (lpMem, NewLine);
    01149     lpLineStart = lpMem;
    01150
    01151     if (nCount != 0)
    01152     {
    01153         lpMem += WriteObject (lpMem, DecodeATag);
    01154
    01155         lpMem += WriteObject (lpMem, BeginFunction);
    01156         if (nCount == 1)                // Gamma supplied in ui16 format
    01157         {
    01158             lpTable = (MEMPTR) (((lpcpCurveType) lpBuff)->curve.data);
    01159             lpMem += WriteInt (lpMem, ui16toSINT (lpTable));
    01160             lpMem += WriteObject (lpMem, DecodeA3);
    01161     // If the PCS is Lab, we need to convert Lab to XYZ
    01162     // Now, the range is from 0 --> 0.99997.
    01163     // Actually, the conversion from Lab to XYZ is not needed.
    01164             if (PCS == icSigLabData)
    01165             {
    01166                 lpMem += WriteObject (lpMem, DecodeALab);
    01167                 lpMem += WriteObject (lpMem, DecodeLMNLab);
    01168             }
    01169         } else
    01170         {
    01171             lpMem += WriteObject (lpMem, StartClip);
    01172             lpTable = (MEMPTR) (((lpcpCurveType) lpBuff)->curve.data);
    01173             lpMem += WriteObject (lpMem, BeginArray);
    01174             for (i = 0; i < nCount; i++)
    01175             {
    01176                 lpMem += WriteInt (lpMem, ui16toSINT (lpTable));
    01177                 lpTable += sizeof (icUInt16Number);
    01178                 if (((SINT) (lpMem - lpLineStart)) > MAX_LINELENG)
    01179                 {
    01180                     lpLineStart = lpMem;
    01181                     lpMem += WriteObject (lpMem, NewLine);
    01182                 }
    01183             }
    01184             lpMem += WriteObject (lpMem, EndArray);
    01185             lpLineStart = lpMem;
    01186             lpMem += WriteObject (lpMem, NewLine);
    01187
    01188             lpMem += WriteObject (lpMem, IndexArray);
    01189             lpMem += WriteObject (lpMem, Scale16);
    01190     // If the PCS is Lab, we need to convert Lab to XYZ
    01191     // Now, the range is from 0 --> .99997.
    01192     // Actually, the conversion from Lab to XYZ is not needed.
    01193             if (PCS == icSigLabData)
    01194             {
    01195                 lpMem += WriteObject (lpMem, DecodeALab);
    01196                 lpMem += WriteObject (lpMem, DecodeLMNLab);
    01197             }
    01198             lpMem += WriteObject (lpMem, EndClip);
    01199         }
    01200         lpMem += WriteObject (lpMem, EndFunction);
    01201     }
    01202
    01203  //********** /MatrixA
    01204     lpMem += WriteNewLineObject (lpMem, MatrixATag);
    01205     lpMem += WriteObject (lpMem, BeginArray);
    01206     for (i = 0; i < 3; i++)
    01207     {
    01208         if (InputIntent == icAbsoluteColorimetric)
    01209             lpMem += WriteFloat (lpMem, (double) MediaWP[i]);
    01210         else
    01211             lpMem += WriteFloat (lpMem, (double) IlluminantWP[i]);
    01212     }
    01213     lpMem += WriteObject (lpMem, EndArray);
    01214
    01215  //********** /RangeLMN
    01216     lpMem += WriteNewLineObject (lpMem, RangeLMNTag);
    01217     lpMem += WriteObject (lpMem, RangeLMN);
    01218
    01219  //********** /End dictionary
    01220     lpMem += WriteObject (lpMem, EndDict);  // End dictionary definition
    01221     lpMem += WriteObject (lpMem, EndArray);
    01222
    01223     MemFree (hBuff);
    01224
    01225     lpMem += WriteNewLineObject (lpMem, CieBasedAEnd);
    01226     *lpcbSize = (DWORD) (lpMem - lpOldMem);
    01227     return (TRUE);
    01228 }
    01229 /***************************************************************************
    01230 *                           GetPS2CSA_MONO
    01231 *  function:
    01232 *    this is the function which creates the MONO ColorSpace (CS)
    01233 *    from the data supplied in the GRAY Input Profile.
    01234 *  prototype:
    01235 *       GetPS2CSA_MONO(
    01236 *                       CHANDLE     cp,
    01237 *                       MEMPTR      lpMem,
    01238 *                       LPDWORD     lpcbSize,
    01239 *                       WORD        InpDrvClrSp
    01240 *                       BOOL        AllowBinary)
    01241 *  parameters:
    01242 *       cp          --  Color Profile handle
    01243 *       lpMem       --  Pointer to the memory block. If this point is NULL,
    01244 *                       require buffer size.
    01245 *       lpcbSize    --  Size of the memory block
    01246 *       InpDrvClrSp --  Device color type (RGB or GRAY).
    01247 *       AllowBinary --  1: binary CSA allowed,  0: only ascii CSA allowed.
    01248 *  returns:
    01249 *       BOOL        --  TRUE if the function was successful,
    01250 *                       FALSE otherwise.
    01251 ***************************************************************************/
    01252 static BOOL
    01253 GetPS2CSA_MONO (CHANDLE cp, MEMPTR lpMem, LPDWORD lpcbSize,
    01254                 DWORD InpDrvClrSp, CSIG InputIntent, BOOL AllowBinary)
    01255 {
    01256     BOOL Success = FALSE;
    01257 #if 0
    01258     if ((InpDrvClrSp == icSigRgbData) ||
    01259         (InpDrvClrSp == icSigDefData) ||
    01260         (InpDrvClrSp == 0))
    01261     {
    01262         Success = GetPS2CSA_MONO_ABC (cp, lpMem, lpcbSize, InputIntent, AllowBinary);
    01263     } else if (InpDrvClrSp == icSigGrayData)
    01264     {
    01265         Success = GetPS2CSA_MONO_A (cp, lpMem, lpcbSize, InputIntent, AllowBinary);
    01266     }
    01267 #else
    01268     if ((InpDrvClrSp == icSigGrayData) ||
    01269         (InpDrvClrSp == 0))
    01270     {
    01271         Success = GetPS2CSA_MONO_A (cp, lpMem, lpcbSize, InputIntent, AllowBinary);
    01272     }
    01273     else
    01274     {
    01275         Success = FALSE;
    01276     }
    01277 #endif
    01278     return Success;
    01279 }
    01280 /***************************************************************************
    01281 *
    01282 *   Function to create a procedure for Color space.
    01283 *
    01284 ***************************************************************************/
    01285
    01286 SINT
    01287 CreateColSpProc (CHANDLE cp, MEMPTR lpMem, CSIG CPTag, BOOL AllowBinary)
    01288 {
    01289     SINT nCount, Index;
    01290     MEMPTR lpTable;
    01291     MEMPTR Buff = NULL;
    01292     SINT MemSize = 0;
    01293     MEMPTR lpOldMem;
    01294     HGLOBAL hBuff;
    01295     lpOldMem = lpMem;
    01296     lpMem += WriteObject (lpMem, BeginFunction);
    01297     if (DoesCPTagExist (cp, CPTag) &&
    01298         GetCPTagIndex (cp, CPTag, (LPSINT) & Index) &&
    01299         GetCPElementSize (cp, Index, (LPSINT) & MemSize) &&
    01300         MemAlloc (MemSize, (HGLOBAL FAR *)&hBuff, (LPMEMPTR) & Buff) &&
    01301         GetCPElement (cp, Index, Buff, MemSize))
    01302     {
    01303         nCount = ui32toSINT (((lpcpCurveType) Buff)->curve.count);
    01304         if (nCount != 0)
    01305         {
    01306             if (nCount == 1)            // Gamma supplied in ui16 format
    01307             {
    01308                 lpTable = (MEMPTR) (((lpcpCurveType) Buff)->curve.data);
    01309                 lpMem += WriteInt (lpMem, ui16toSINT (lpTable));
    01310                 lpMem += WriteObject (lpMem, DecodeA3);
    01311             } else
    01312             {
    01313                 lpMem += WriteObject (lpMem, StartClip);
    01314                 lpTable = (MEMPTR) (((lpcpCurveType) Buff)->curve.data);
    01315                 lpMem += WriteObject (lpMem, DecodeABCArray);
    01316                 lpMem += WriteInt (lpMem, (SINT) CPTag);
    01317
    01318                 if (!AllowBinary)       // Output ASCII CS
    01319                 {
    01320                     lpMem += WriteObject (lpMem, IndexArray);
    01321                 } else
    01322                 {                       // Output BINARY CS
    01323                     lpMem += WriteObject (lpMem, IndexArray16b);
    01324                 }
    01325                 lpMem += WriteObject (lpMem, Scale16);
    01326                 lpMem += WriteObject (lpMem, EndClip);
    01327             }
    01328         }
    01329         MemFree (hBuff);
    01330     }
    01331     lpMem += WriteObject (lpMem, EndFunction);
    01332     return ((SINT) (lpMem - lpOldMem));
    01333 }
    01334 /***************************************************************************
    01335 *
    01336 *   Function to create a procedure for Color space.
    01337 *
    01338 ***************************************************************************/
    01339
    01340 SINT
    01341 CreateFloatString (CHANDLE cp, MEMPTR lpMem, CSIG CPTag)
    01342 {
    01343     SINT i, Index;
    01344     MEMPTR lpTable;
    01345     MEMPTR Buff = NULL;
    01346     SINT MemSize = 0;
    01347     MEMPTR lpOldMem;
    01348     HGLOBAL hBuff;
    01349     lpOldMem = lpMem;
    01350     if (GetCPTagIndex (cp, CPTag, (LPSINT) & Index) &&
    01351         GetCPElementSize (cp, Index, (LPSINT) & MemSize) &&
    01352         MemAlloc (MemSize, (HGLOBAL FAR *)&hBuff, (LPMEMPTR) & Buff) &&
    01353         GetCPElement (cp, Index, Buff, MemSize))
    01354     {
    01355         lpTable = (MEMPTR) & (((lpcpXYZType) Buff)->data);
    01356         for (i = 0; i < 3; i++)
    01357         {
    01358             lpMem += WriteFloat (lpMem, si16f16toSFLOAT (lpTable));
    01359             lpTable += sizeof (icS15Fixed16Number);
    01360         }
    01361         MemFree (hBuff);
    01362     }
    01363     return ((SINT) (lpMem - lpOldMem));
    01364 }
    01365 /***************************************************************************
    01366 *
    01367 *   Function to create a array later to be used in ColorSpace's DecodeABC.
    01368 *
    01369 ***************************************************************************/
    01370
    01371 SINT
    01372 CreateColSpArray (CHANDLE cp, MEMPTR lpMem, CSIG CPTag, BOOL AllowBinary)
    01373 {
    01374     SINT i, nCount, Index;
    01375     MEMPTR lpTable;
    01376     MEMPTR Buff = NULL;
    01377     SINT MemSize = 0;
    01378     MEMPTR lpOldMem, lpLineStart;
    01379     HGLOBAL hBuff;
    01380     lpOldMem = lpMem;
    01381
    01382     lpLineStart = lpMem;
    01383
    01384     if (DoesCPTagExist (cp, CPTag) &&
    01385         GetCPTagIndex (cp, CPTag, (LPSINT) & Index) &&
    01386         GetCPElementSize (cp, Index, (LPSINT) & MemSize) &&
    01387         MemAlloc (MemSize, (HGLOBAL FAR *)&hBuff, (LPMEMPTR) & Buff) &&
    01388         GetCPElement (cp, Index, Buff, MemSize))
    01389     {
    01390         nCount = ui32toSINT (((lpcpCurveType) Buff)->curve.count);
    01391         if (nCount > 1)
    01392         {
    01393             lpMem += WriteNewLineObject (lpMem, Slash);
    01394             lpMem += WriteObject (lpMem, DecodeABCArray);
    01395             lpMem += WriteInt (lpMem, (SINT) CPTag);
    01396
    01397             lpTable = (MEMPTR) (((lpcpCurveType) Buff)->curve.data);
    01398             if (!AllowBinary)           // Output ASCII CS
    01399             {
    01400                 lpMem += WriteObject (lpMem, BeginArray);
    01401                 for (i = 0; i < nCount; i++)
    01402                 {
    01403                     lpMem += WriteInt (lpMem, ui16toSINT (lpTable));
    01404                     lpTable += sizeof (icUInt16Number);
    01405                     if (((SINT) (lpMem - lpLineStart)) > MAX_LINELENG)
    01406                     {
    01407                         lpLineStart = lpMem;
    01408                         lpMem += WriteObject (lpMem, NewLine);
    01409                     }
    01410                 }
    01411                 lpMem += WriteObject (lpMem, EndArray);
    01412             } else
    01413             {                           // Output BINARY CS
    01414                 lpMem += WriteHNAToken (lpMem, 149, nCount);
    01415                 lpMem += WriteIntStringU2S (lpMem, lpTable, nCount);
    01416             }
    01417             lpMem += WriteObject (lpMem, DefOp);
    01418         }
    01419         MemFree (hBuff);
    01420     }
    01421     return ((SINT) (lpMem - lpOldMem));
    01422 }
    01423 /***************************************************************************
    01424 *                               GetCSAFromProfile
    01425 *  function:
    01426 *    this is the function which gets the ColorSpace dictionary array
    01427 *    from the the Profile.
    01428 *  prototype:
    01429 *       static BOOL GetCSAFromProfile(
    01430 *                       CHANDLE     cp,
    01431 *                       MEMPTR      lpMem,
    01432 *                       LPDWORD     lpcbSize,
    01433 *                       WORD        InpDrvClrSp,
    01434 *                       CSIG        DrvColorSpace,
    01435 *                       BOOL        AllowBinary)
    01436 *  parameters:
    01437 *       cp          --  Color Profile handle
    01438 *       lpBuffer    --  Pointer to the memory block. If this point is NULL,
    01439 *                       require buffer size.
    01440 *       lpcbSize    --  Size of the memory block
    01441 *       InpDrvClrSp --  Input device color space.
    01442 *       DrvColorSpace --  Profile device color space.
    01443 *       AllowBinary --  1: binary CS allowed,  0: only ascii CS allowed.
    01444 *  returns:
    01445 *       BOOL        --  TRUE if the function was successful,
    01446 *                       FALSE otherwise.
    01447 ***************************************************************************/
    01448
    01449 static BOOL
    01450 GetCSAFromProfile (
    01451                    CHANDLE cp,
    01452                    MEMPTR lpMem,
    01453                    LPDWORD lpcbSize,
    01454                    DWORD InpDrvClrSp,
    01455                    CSIG DrvColorSpace,
    01456                    BOOL AllowBinary)
    01457 {
    01458     SINT Index;
    01459     SINT Size;
    01460     if ((DrvColorSpace == icSigGrayData) && (InpDrvClrSp != icSigGrayData))
    01461         return FALSE;
    01462
    01463     if (DoesCPTagExist (cp, icSigPs2CSATag) &&
    01464         GetCPTagIndex (cp, icSigPs2CSATag, (LPSINT) & Index) &&
    01465         GetCPElementDataSize (cp, Index, (LPSINT) & Size) &&
    01466         ((lpMem == NULL) || GetCPElementData (cp, Index, lpMem, Size)) &&
    01467         (*lpcbSize = Convert2Ascii (cp, Index, lpMem, *lpcbSize, Size, AllowBinary)))
    01468     {
    01469         return TRUE;
    01470     } else
    01471     {
    01472         return FALSE;
    01473     }
    01474 }
    01475 /***************************************************************************
    01476 *                           GetPS2CSA_DEFG_Intent
    01477 *  function:
    01478 *    This is the function which creates the CieBasedDEF(G)ColorSpace array
    01479 *    based on Intent.
    01480 *  prototype:
    01481 *       static BOOL GetPS2CSA_DEFG_Intent(
    01482 *                   CHANDLE     cp,
    01483 *                   MEMPTR      lpBuffer,
    01484 *                   LPDWORD     lpcbSize,
    01485 *                   CSIG        Intent,
    01486 *                   int         Type,
    01487 *                   BOOL        AllowBinary)
    01488 *  parameters:
    01489 *       cp          --  Color Profile handle
    01490 *       lpBuffer    --  Pointer to the memory block. If this point is NULL,
    01491 *                       require buffer size.
    01492 *       lpcbSize    --  Size of the memory block
    01493 *       Intent      --  Intent.
    01494 *       Type        --  CieBasedDEF or CieBasedDEF.
    01495 *       AllowBinary --  1: binary CS allowed,  0: only ascii CS allowed.
    01496 *  returns:
    01497 *       BOOL        --  TRUE if the function was successful,
    01498 *                       FALSE otherwise.
    01499 ***************************************************************************/
    01500
    01501 BOOL
    01502 GetPS2CSA_DEFG_Intent (
    01503                        CHANDLE cp,
    01504                        MEMPTR lpBuffer,
    01505                        LPDWORD lpcbSize,
    01506                        DWORD InpDrvClrSp,
    01507                        CSIG Intent,
    01508                        int Type,
    01509                        BOOL AllowBinary)
    01510 {
    01511     SINT Index;
    01512     BOOL Success = FALSE;
    01513     CSIG icSigAToBx;
    01514
    01515  // Try to create CieBasedDEFG CSA first.
    01516     if (((Type == TYPE_CIEBASEDDEFG) && (InpDrvClrSp != icSigCmykData) ||
    01517          (Type == TYPE_CIEBASEDDEF) && (InpDrvClrSp != icSigDefData)) &&
    01518         (InpDrvClrSp != 0))
    01519     {
    01520         return (FALSE);
    01521     }
    01522     switch (Intent)
    01523     {
    01524         case icPerceptual:
    01525             icSigAToBx = icSigAToB0Tag;
    01526             break;
    01527         case icRelativeColorimetric:
    01528             icSigAToBx = icSigAToB1Tag;
    01529             break;
    01530         case icSaturation:
    01531             icSigAToBx = icSigAToB2Tag;
    01532             break;
    01533         case icAbsoluteColorimetric:
    01534             icSigAToBx = icSigAToB1Tag;
    01535             break;
    01536         default:
    01537             return Success;
    01538     }
    01539
    01540     if (DoesCPTagExist (cp, icSigAToBx) &&
    01541         GetCPTagIndex (cp, icSigAToBx, (LPSINT) & Index))
    01542     {
    01543         Success = GetPS2CSA_DEFG (cp, lpBuffer, lpcbSize, Intent, Index, Type, AllowBinary);
    01544     }
    01545
    01546     return Success;
    01547 }
    01548 /***************************************************************************
    01549 *                               GetPS2ColorSpaceArray
    01550 *  function:
    01551 *    This is the main function which creates the ColorSpace array
    01552 *    from the data supplied in the Profile.
    01553 *  prototype:
    01554 *       BOOL GetPS2ColorSpaceArray(
    01555 *               CHANDLE     cp,
    01556 *               CSIG        InputIntent,
    01557 *               WORD        InpDrvClrSp,
    01558 *               MEMPTR      lpBuffer,
    01559 *               LPDWORD     lpcbSize,
    01560 *               BOOL        AllowBinary)
    01561 *  parameters:
    01562 *       cp          --  Color Profile handle
    01563 *       lpBuffer    --  Pointer to the memory block. If this point is NULL,
    01564 *                       require buffer size.
    01565 *       lpcbSize    --  Size of the memory block
    01566 *       InpDrvClrSp --  Input device color space.
    01567 *                       icSigCmykData: input data is cmyk, create CiebasedDEFG CSA.
    01568 *                       icSigRgbData : input data is rgb, create CieBasedABC CSA.
    01569 *                       icSigDefData : input data is rgb or lab, create CiebasedDEF CSA.
    01570 *                       isSigGrayData: input data is gray, create CieBasedA CSA.
    01571 *                       0            : Auto. Create CSA depends on profile color space.
    01572 *       InputIntent --  Intent.
    01573 *       AllowBinary --  1: binary CS allowed,  0: only ascii CS allowed.
    01574 *  returns:
    01575 *       BOOL        --  TRUE if the function was successful,
    01576 *                       FALSE otherwise.
    01577 ***************************************************************************/
    01578 BOOL EXTERN
    01579 GetPS2ColorSpaceArray (
    01580                        CHANDLE cp,
    01581                        DWORD InputIntent,
    01582                        DWORD InpDrvClrSp,
    01583                        MEMPTR lpBuffer,
    01584                        LPDWORD lpcbSize,
    01585                        BOOL AllowBinary)
    01586 {
    01587     CSIG ColorSpace, Intent;
    01588     BOOL Success = FALSE;
    01589     DWORD dwSaveSize;
    01590     if (!cp)
    01591         return Success;
    01592
    01593     if (!GetCPDevSpace (cp, (LPCSIG) & ColorSpace) ||
    01594         !GetCPRenderIntent (cp, (LPCSIG) & Intent))
    01595     {
    01596         return Success;
    01597     }
    01598     dwSaveSize = *lpcbSize;
    01599     if (InputIntent == icUseRenderingIntent)
    01600         InputIntent = (DWORD)Intent;
    01601
    01602  // Get ColorSpace from Profile.
    01603     if ((CSIG) InputIntent == Intent)
    01604     {
    01605         Success = GetCSAFromProfile (cp, lpBuffer, lpcbSize,
    01606                                      InpDrvClrSp, ColorSpace, AllowBinary);
    01607     }
    01608     if (!Success)
    01609     {
    01610         switch (ColorSpace)
    01611         {
    01612             case icSigRgbData:
    01613                 Success = GetPS2CSA_DEFG_Intent (cp, lpBuffer, lpcbSize,
    01614                                                  InpDrvClrSp, (CSIG) InputIntent,
    01615                                                  TYPE_CIEBASEDDEF, AllowBinary);
    01616                 if (Success)
    01617                 {                       // Create CieBasedABC or DeviceRGB
    01618                                         // for the printer
    01619                                         // which does not support CieBasedDEF(G).
    01620                     DWORD cbNewSize = 0;
    01621                     MEMPTR lpNewBuffer;
    01622                     MEMPTR lpOldBuffer;
    01623                     if (lpBuffer)
    01624                     {
    01625                         lpNewBuffer = lpBuffer + *lpcbSize;
    01626                         lpOldBuffer = lpNewBuffer;
    01627                         lpNewBuffer += WriteObject (lpNewBuffer, NewLine);
    01628                         cbNewSize = dwSaveSize - (DWORD) (lpNewBuffer - lpBuffer);
    01629                     } else
    01630                         lpNewBuffer = NULL;
    01631
    01632                     if (!GetPS2CSA_ABC (cp, lpNewBuffer, &cbNewSize,
    01633                                         (CSIG)InputIntent, InpDrvClrSp,
    01634                                         AllowBinary, 1))   // create a backup CSA
    01635                         GetDeviceRGB (lpNewBuffer, &cbNewSize, InpDrvClrSp, 1);
    01636
    01637                     if (lpBuffer)
    01638                     {
    01639                         lpNewBuffer += cbNewSize;
    01640                         *lpcbSize += (DWORD) (lpNewBuffer - lpOldBuffer);
    01641                     } else
    01642                         *lpcbSize += cbNewSize;
    01643
    01644                 }
    01645                 if (!Success)
    01646                 {                           // Create CieBasedABC
    01647                     Success = GetPS2CSA_ABC (cp, lpBuffer, lpcbSize,
    01648                                          (CSIG)InputIntent, InpDrvClrSp,
    01649                                          AllowBinary, 0);
    01650                 }
    01651                 if (!Success)
    01652                 {                           // Create DeviceRGB
    01653                     Success = GetDeviceRGB (lpBuffer, lpcbSize, InpDrvClrSp, 0);
    01654                     Success = FALSE;
    01655                 }
    01656                 break;
    01657             case icSigCmykData:
    01658                 Success = GetPS2CSA_DEFG_Intent (cp, lpBuffer, lpcbSize,
    01659                                                  InpDrvClrSp, (CSIG) InputIntent,
    01660                                                  TYPE_CIEBASEDDEFG, AllowBinary);
    01661                 if (Success)
    01662                 {                       // Create DeviceCMYK for the printer
    01663                                         // which does not support CieBasedDEF(G).
    01664                     DWORD cbNewSize = 0;
    01665                     MEMPTR lpNewBuffer;
    01666                     MEMPTR lpOldBuffer;
    01667                     if (lpBuffer)
    01668                     {
    01669                         lpNewBuffer = lpBuffer + *lpcbSize;
    01670                         lpOldBuffer = lpNewBuffer;
    01671                         lpNewBuffer += WriteObject (lpNewBuffer, NewLine);
    01672                         lpNewBuffer += WriteNewLineObject (lpNewBuffer, NotSupportDEFG_S);
    01673                         cbNewSize = dwSaveSize - (DWORD) (lpNewBuffer - lpBuffer);
    01674                     } else
    01675                         lpNewBuffer = NULL;
    01676
    01677                     GetDeviceCMYK (lpNewBuffer, &cbNewSize, InpDrvClrSp);
    01678
    01679                     if (lpBuffer)
    01680                     {
    01681                         lpNewBuffer += cbNewSize;
    01682                         lpNewBuffer += WriteNewLineObject (lpNewBuffer, SupportDEFG_E);
    01683                         *lpcbSize += (DWORD) (lpNewBuffer - lpOldBuffer);
    01684                     } else
    01685                         *lpcbSize += cbNewSize;
    01686                 }
    01687                 if (!Success)
    01688                 {                           // Create DeviceCMYK
    01689                     Success = GetDeviceCMYK (lpBuffer, lpcbSize, InpDrvClrSp);
    01690                     Success = FALSE;
    01691                 }
    01692                 break;
    01693             case icSigGrayData:
    01694                 Success = GetPS2CSA_MONO (cp, lpBuffer, lpcbSize, InpDrvClrSp,
    01695                                           (CSIG)InputIntent, AllowBinary);
    01696                 if (!Success)
    01697                 {                           // Create DeviceGray
    01698                     Success = GetDeviceGray (lpBuffer, lpcbSize, InpDrvClrSp);
    01699                     Success = FALSE;
    01700                 }
    01701                 break;
    01702             case icSigLabData:
    01703                 Success = GetPS2CSA_DEFG_Intent (cp, lpBuffer, lpcbSize,
    01704                                                  InpDrvClrSp, (CSIG) InputIntent,
    01705                                                  TYPE_CIEBASEDDEF, AllowBinary);
    01706                 if (Success)
    01707                 {                       // Create CieBasedABC or DeviceRGB
    01708                                         // for the printer
    01709                                         // which does not support CieBasedDEF(G).
    01710                     DWORD cbNewSize = 0;
    01711                     MEMPTR lpNewBuffer;
    01712                     MEMPTR lpOldBuffer;
    01713                     if (lpBuffer)
    01714                     {
    01715                         lpNewBuffer = lpBuffer + *lpcbSize;
    01716                         lpOldBuffer = lpNewBuffer;
    01717                         lpNewBuffer += WriteObject (lpNewBuffer, NewLine);
    01718                         lpNewBuffer += WriteNewLineObject (lpNewBuffer, NotSupportDEFG_S);
    01719                         cbNewSize = dwSaveSize - (DWORD) (lpNewBuffer - lpBuffer);
    01720                     } else
    01721                         lpNewBuffer = NULL;
    01722
    01723                     GetPS2CSA_ABC_LAB (cp, lpNewBuffer, &cbNewSize,
    01724                                         (CSIG)InputIntent, InpDrvClrSp, AllowBinary);
    01725
    01726                     if (lpBuffer)
    01727                     {
    01728                         lpNewBuffer += cbNewSize;
    01729                         lpNewBuffer += WriteNewLineObject (lpNewBuffer, SupportDEFG_E);
    01730                         *lpcbSize += (DWORD) (lpNewBuffer - lpOldBuffer);
    01731                     } else
    01732                         *lpcbSize += cbNewSize;
    01733                 }
    01734                 if (!Success)
    01735                 {                           // Create CieBasedABC
    01736                     Success = GetPS2CSA_ABC_LAB (cp, lpBuffer, lpcbSize,
    01737                                          (CSIG)InputIntent, InpDrvClrSp, AllowBinary);
    01738                 }
    01739                 break;
    01740
    01741             default:
    01742                 break;
    01743         }
    01744     }
    01745     return Success;
    01746 }