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