⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmsio1.c

📁 Linux下的无线网卡通用驱动程序
💻 C
📖 第 1 页 / 共 5 页
字号:
            if (!wchar) return -1;                        Icc ->Read(wchar, 1, Len, Icc);            AdjustEndianessArray16((LPWORD) wchar, Len / 2);            wchar[Len / 2] = L'\0';            i = wcstombs(Name, wchar, 2047 );              if (i == ((size_t) -1)) {                Name[0] = 0;    // Error            }            free((void*) wchar);            }            break;    default:            cmsSignalError(LCMS_ERRC_ABORTED, "Bad tag signature %lx found.", BaseType);            return -1;    }    return (int) size;}// Take an ASCII itemint LCMSEXPORT cmsReadICCText(cmsHPROFILE hProfile, icTagSignature sig, char *Name){    LPLCMSICCPROFILE    Icc = (LPLCMSICCPROFILE) (LPSTR) hProfile;    size_t              offset, size;    int                 n;    n = _cmsSearchTag(Icc, sig, TRUE);    if (n < 0)                 return -1;        if (!Icc -> stream) {        CopyMemory(Name, Icc -> TagPtrs[n], Icc -> TagSizes[n]);        return (int) Icc -> TagSizes[n];    }    offset = Icc -> TagOffsets[n];    size   = Icc -> TagSizes[n];    if (Icc -> Seek(Icc, offset))            return -1;          return ReadEmbeddedTextTag(Icc, size, Name);}// Take an XYZ itemstaticint ReadICCXYZ(cmsHPROFILE hProfile, icTagSignature sig, LPcmsCIEXYZ Value, BOOL lIsFatal){    LPLCMSICCPROFILE    Icc = (LPLCMSICCPROFILE) (LPSTR) hProfile;    icTagTypeSignature  BaseType;        size_t              offset;    int                 n;    icXYZNumber         XYZ;    n = _cmsSearchTag(Icc, sig, FALSE);    if (n < 0)                return -1;        if (!Icc -> stream) {         CopyMemory(Value, Icc -> TagPtrs[n], Icc -> TagSizes[n]);                return (int) Icc -> TagSizes[n];    }    offset = Icc -> TagOffsets[n];    if (Icc -> Seek(Icc, offset))            return -1;        BaseType = ReadBase(Icc);        switch (BaseType) {            case 0x7c3b10cL:    // Some apple broken embedded profiles does not have correct type       case icSigXYZType:           Icc ->Read(&XYZ, sizeof(icXYZNumber), 1, Icc);           Value -> X = Convert15Fixed16(XYZ.X);           Value -> Y = Convert15Fixed16(XYZ.Y);           Value -> Z = Convert15Fixed16(XYZ.Z);           break;    // Aug/21-2001 - Monaco 2 does have WRONG values.    default:           if (lIsFatal)                cmsSignalError(LCMS_ERRC_ABORTED, "Bad tag signature %lx found.", BaseType);           return -1;    }    return 1;}// Read a icSigS15Fixed16ArrayType (currently only a 3x3 matrix)           staticint ReadICCXYZArray(cmsHPROFILE hProfile, icTagSignature sig, LPMAT3 v){    LPLCMSICCPROFILE    Icc = (LPLCMSICCPROFILE) (LPSTR) hProfile;        icTagTypeSignature  BaseType;     size_t              offset, sz;    int                 i, n;    icXYZNumber         XYZ[3];    cmsCIEXYZ           XYZdbl[3];    n = _cmsSearchTag(Icc, sig, FALSE);    if (n < 0)                  return -1; // Not found        if (!Icc -> stream) {            CopyMemory(v, Icc -> TagPtrs[n], Icc -> TagSizes[n]);            return (int) Icc -> TagSizes[n];    }    offset = Icc -> TagOffsets[n];    if (Icc -> Seek(Icc, offset))            return -1;        BaseType = ReadBase(Icc);       switch (BaseType) {    case icSigS15Fixed16ArrayType:         sz = Icc ->TagSizes[n] / sizeof(icXYZNumber);         if (sz != 3) {             cmsSignalError(LCMS_ERRC_ABORTED, "Bad array size of %d entries.", sz);             return -1;         }                         Icc ->Read(XYZ, sizeof(icXYZNumber), 3, Icc);         for (i=0; i < 3; i++) {            XYZdbl[i].X = Convert15Fixed16(XYZ[i].X);            XYZdbl[i].Y = Convert15Fixed16(XYZ[i].Y);            XYZdbl[i].Z = Convert15Fixed16(XYZ[i].Z);         }         CopyMemory(v, XYZdbl, 3*sizeof(cmsCIEXYZ));         break;    default:         cmsSignalError(LCMS_ERRC_ABORTED, "Bad tag signature %lx found.", BaseType);         return -1;    }   return sizeof(MAT3);}// Primaries are to be in xyY notationBOOL LCMSEXPORT cmsTakeColorants(LPcmsCIEXYZTRIPLE Dest, cmsHPROFILE hProfile){       if (ReadICCXYZ(hProfile, icSigRedColorantTag, &Dest -> Red, TRUE) < 0) return FALSE;       if (ReadICCXYZ(hProfile, icSigGreenColorantTag, &Dest -> Green, TRUE) < 0) return FALSE;       if (ReadICCXYZ(hProfile, icSigBlueColorantTag, &Dest -> Blue, TRUE) < 0) return FALSE;       return TRUE;}BOOL cmsReadICCMatrixRGB2XYZ(LPMAT3 r, cmsHPROFILE hProfile){       cmsCIEXYZTRIPLE Primaries;       if (!cmsTakeColorants(&Primaries, hProfile)) return FALSE;       VEC3init(&r -> v[0], Primaries.Red.X, Primaries.Green.X,  Primaries.Blue.X);       VEC3init(&r -> v[1], Primaries.Red.Y, Primaries.Green.Y,  Primaries.Blue.Y);       VEC3init(&r -> v[2], Primaries.Red.Z, Primaries.Green.Z,  Primaries.Blue.Z);       return TRUE;}// Always return a suitable matrixBOOL cmsReadChromaticAdaptationMatrix(LPMAT3 r, cmsHPROFILE hProfile){              if (ReadICCXYZArray(hProfile, icSigChromaticAdaptationTag, r) < 0) {       LPLCMSICCPROFILE  Icc = (LPLCMSICCPROFILE) (LPSTR) hProfile;       // For display profiles, revert to bradford. Else take identity.       MAT3identity(r);       // Emissive devices have non-identity chad       if ((cmsGetDeviceClass(hProfile) == icSigDisplayClass) ||           cmsTakeHeaderFlags(hProfile) & icTransparency) {            // NULL for cone defaults to Bradford, from media to D50            cmsAdaptationMatrix(r, NULL, &Icc ->MediaWhitePoint, &Icc ->Illuminant);                }    }        return TRUE;}LPGAMMATABLE LCMSEXPORT cmsReadICCGamma(cmsHPROFILE hProfile, icTagSignature sig){       LPLCMSICCPROFILE  Icc = (LPLCMSICCPROFILE) (LPSTR) hProfile;       size_t         offset;       int            n;       n = _cmsSearchTag(Icc, sig, TRUE);       if (n < 0)              return NULL;              if (!Icc -> stream) {            return cmsDupGamma((LPGAMMATABLE) Icc -> TagPtrs[n]);       }       offset = Icc -> TagOffsets[n];       if (Icc -> Seek(Icc, offset))            return NULL;       return ReadCurve(Icc);     }// Some ways have analytical revese. This function accounts for thatLPGAMMATABLE LCMSEXPORT cmsReadICCGammaReversed(cmsHPROFILE hProfile, icTagSignature sig){       LPLCMSICCPROFILE  Icc = (LPLCMSICCPROFILE) (LPSTR) hProfile;       size_t         offset;       int            n;       n = _cmsSearchTag(Icc, sig, TRUE);       if (n < 0)             return NULL;              if (!Icc -> stream) {            return cmsReverseGamma(256, (LPGAMMATABLE) Icc -> TagPtrs[n]);       }       offset = Icc -> TagOffsets[n];       if (Icc -> Seek(Icc, offset))            return NULL;              return ReadCurveReversed(Icc);       }// Check Named color headerstaticBOOL CheckHeader(LPcmsNAMEDCOLORLIST v, icNamedColor2* nc2){    if (v ->Prefix[0] == 0 && v ->Suffix[0] == 0 && v ->ColorantCount == 0) return TRUE;    if (stricmp(v ->Prefix, (const char*) nc2 ->prefix) != 0) return FALSE;    if (stricmp(v ->Suffix, (const char*) nc2 ->suffix) != 0) return FALSE;    return ((int) v ->ColorantCount == (int) nc2 ->nDeviceCoords);}// Read named color listint cmsReadICCnamedColorList(cmsHTRANSFORM xform, cmsHPROFILE hProfile, icTagSignature sig){       _LPcmsTRANSFORM v = (_LPcmsTRANSFORM) xform;       LPLCMSICCPROFILE   Icc = (LPLCMSICCPROFILE) (LPSTR) hProfile;       int                n;              icTagTypeSignature BaseType;       size_t             offset;              n = _cmsSearchTag(Icc, sig, TRUE);       if (n < 0)                         return 0;              if (!Icc -> stream) {                       // This replaces actual named color list.                                   size_t size   = Icc -> TagSizes[n];              if (v ->NamedColorList) cmsFreeNamedColorList(v ->NamedColorList);            v -> NamedColorList = (LPcmsNAMEDCOLORLIST) malloc(size);                       CopyMemory(v -> NamedColorList, Icc ->TagPtrs[n], size);                return v ->NamedColorList->nColors;                  }       offset = Icc -> TagOffsets[n];       if (Icc -> Seek(Icc, offset))            return 0;       BaseType = ReadBase(Icc);              switch (BaseType) {        // I never have seen one of these. Probably is not worth of implementing.       case icSigNamedColorType: {              cmsSignalError(LCMS_ERRC_WARNING, "Ancient named color profiles are not supported.");              return 0;                             }                   // The named color struct               case icSigNamedColor2Type: {                icNamedColor2 nc2;                unsigned int i, j;                                                Icc -> Read(&nc2, sizeof(icNamedColor2) - SIZEOF_UINT8_ALIGNED, 1, Icc);                AdjustEndianess32((LPBYTE) &nc2.vendorFlag);                AdjustEndianess32((LPBYTE) &nc2.count);                AdjustEndianess32((LPBYTE) &nc2.nDeviceCoords);                if (!CheckHeader(v->NamedColorList, &nc2)) {                     cmsSignalError(LCMS_ERRC_WARNING, "prefix/suffix/device for named color profiles mismatch.");                }                strncpy(v ->NamedColorList->Prefix, (const char*) nc2.prefix, 32);                strncpy(v ->NamedColorList->Suffix, (const char*) nc2.suffix, 32);                v ->NamedColorList->Prefix[32] = v->NamedColorList->Suffix[32] = 0;                                v ->NamedColorList ->ColorantCount = nc2.nDeviceCoords;                                for (i=0; i < nc2.count; i++) {                    WORD PCS[3];                    WORD Colorant[MAXCHANNELS];                    char Root[33];                    ZeroMemory(Colorant, sizeof(WORD) * MAXCHANNELS);                    Icc -> Read(Root, 1, 32, Icc);                    Icc -> Read(PCS,  3, sizeof(WORD), Icc);                    for (j=0; j < 3; j++)                        AdjustEndianess16((LPBYTE) &PCS[j]);                                        Icc -> Read(Colorant, sizeof(WORD), nc2.nDeviceCoords, Icc);                    for (j=0; j < nc2.nDeviceCoords; j++)                             AdjustEndianess16((LPBYTE) &Colorant[j]);                                        cmsAppendNamedColor(v, Root, PCS, Colorant);                }            return v ->NamedColorList->nColors;            }            break;       default:              cmsSignalError(LCMS_ERRC_WARNING, "Bad tag signature '%lx' found.", BaseType);              return 0;       }       // It would never reach here       // return 0;}// Read colorant tablesLPcmsNAMEDCOLORLIST LCMSEXPORT cmsReadColorantTable(cmsHPROFILE hProfile, icTagSignature sig){       icInt32Number n, Count, i;    size_t offset;    icTagTypeSignature  BaseType;    LPLCMSICCPROFILE   Icc = (LPLCMSICCPROFILE) (LPSTR) hProfile;    LPcmsNAMEDCOLORLIST List;    n = _cmsSearchTag(Icc, sig, FALSE);    if (n < 0)                  return NULL; // Not found        if (!Icc -> stream) {            size_t size   = Icc -> TagSizes[n];              void* v = malloc(size);            CopyMemory(v, Icc -> TagPtrs[n], size);            return (LPcmsNAMEDCOLORLIST) v;    }    offset = Icc -> TagOffsets[n];    if (Icc -> Seek(Icc, offset))            return NULL;        BaseType = ReadBase(Icc);    if (BaseType != icSigColorantTableType) {            cmsSignalError(LCMS_ERRC_ABORTED, "Bad tag signature '%lx' found.", BaseType);            return NULL;    }    Icc ->Read(&Count, sizeof(icUInt32Number), 1, Icc);    AdjustEndianess32((LPBYTE) &Count);     List = cmsAllocNamedColorList(Count);    for (i=0; i < Count; i++) {        if (!Icc ->Read(List->List[i].Name, 1, 32 , Icc)) goto Error;        if (!Icc ->Read(List->List[i].PCS, sizeof(icUInt16Number), 3, Icc)) goto Error;        AdjustEndianessArray16(List->List[i].PCS, 3);           }    return List;Error:    cmsFreeNamedColorList(List);    return NULL;}// Uncooked manufacturerconst char* LCMSEXPORT cmsTakeManufacturer(cmsHPROFILE hProfile){    static char Manufacturer[512] = "";       Manufacturer[0] = 0;          if (cmsIsTag(hProfile, icSigDeviceMfgDescTag)) {            cmsReadICCText(hProfile, icSigDeviceMfgDescTag, Manufacturer);       }    return Manufacturer;}// Uncooked modelconst char* LCMSEXPORT cmsTakeModel(cmsHPROFILE hProfile){    static char Model[512] = "";       Model[0] = 0;          if (cmsIsTag(hProfile, icSigDeviceModelDescTag)) {            cmsReadICCText(hProfile, icSigDeviceModelDescTag, Model);       }    return Model;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -