< prev index next >

src/java.desktop/share/native/liblcms/cmsio0.c

Print this page

 543     _cmsICCPROFILE* Icc = (_cmsICCPROFILE*)hProfile;
 544 
 545     if (Icc == NULL) return NULL;
 546     return Icc->IOhandler;
 547 }
 548 
 549 // Creates an empty structure holding all required parameters
 550 cmsHPROFILE CMSEXPORT cmsCreateProfilePlaceholder(cmsContext ContextID)
 551 {
 552     _cmsICCPROFILE* Icc = (_cmsICCPROFILE*) _cmsMallocZero(ContextID, sizeof(_cmsICCPROFILE));
 553     if (Icc == NULL) return NULL;
 554 
 555     Icc ->ContextID = ContextID;
 556 
 557     // Set it to empty
 558     Icc -> TagCount   = 0;
 559 
 560     // Set default version
 561     Icc ->Version =  0x02100000;
 562 














 563     // Set default device class
 564     Icc->DeviceClass = cmsSigDisplayClass;
 565 
 566     // Set creation date/time
 567     if (!_cmsGetTime(&Icc->Created))
 568         goto Error;
 569 
 570     // Create a mutex if the user provided proper plugin. NULL otherwise
 571     Icc ->UsrMutex = _cmsCreateMutex(ContextID);
 572 
 573     // Return the handle
 574     return (cmsHPROFILE) Icc;
 575 
 576 Error:
 577     _cmsFree(ContextID, Icc);
 578     return NULL;
 579 }
 580 
 581 cmsContext CMSEXPORT cmsGetProfileContextID(cmsHPROFILE hProfile)
 582 {

 796     cmsTagEntry Tag;
 797     cmsICCHeader Header;
 798     cmsUInt32Number i, j;
 799     cmsUInt32Number HeaderSize;
 800     cmsIOHANDLER* io = Icc ->IOhandler;
 801     cmsUInt32Number TagCount;
 802 
 803 
 804     // Read the header
 805     if (io -> Read(io, &Header, sizeof(cmsICCHeader), 1) != 1) {
 806         return FALSE;
 807     }
 808 
 809     // Validate file as an ICC profile
 810     if (_cmsAdjustEndianess32(Header.magic) != cmsMagicNumber) {
 811         cmsSignalError(Icc ->ContextID, cmsERROR_BAD_SIGNATURE, "not an ICC profile, invalid signature");
 812         return FALSE;
 813     }
 814 
 815     // Adjust endianness of the used parameters

 816     Icc -> DeviceClass     = (cmsProfileClassSignature) _cmsAdjustEndianess32(Header.deviceClass);
 817     Icc -> ColorSpace      = (cmsColorSpaceSignature)   _cmsAdjustEndianess32(Header.colorSpace);
 818     Icc -> PCS             = (cmsColorSpaceSignature)   _cmsAdjustEndianess32(Header.pcs);
 819 
 820     Icc -> RenderingIntent = _cmsAdjustEndianess32(Header.renderingIntent);

 821     Icc -> flags           = _cmsAdjustEndianess32(Header.flags);
 822     Icc -> manufacturer    = _cmsAdjustEndianess32(Header.manufacturer);
 823     Icc -> model           = _cmsAdjustEndianess32(Header.model);
 824     Icc -> creator         = _cmsAdjustEndianess32(Header.creator);
 825 
 826     _cmsAdjustEndianess64(&Icc -> attributes, &Header.attributes);
 827     Icc -> Version         = _cmsAdjustEndianess32(_validatedVersion(Header.version));
 828 
 829     if (Icc->Version > 0x5000000) {
 830         cmsSignalError(Icc->ContextID, cmsERROR_UNKNOWN_EXTENSION, "Unsupported profile version '0x%x'", Icc->Version);
 831         return FALSE;
 832     }
 833 
 834     if (!validDeviceClass(Icc->DeviceClass)) {
 835         cmsSignalError(Icc->ContextID, cmsERROR_UNKNOWN_EXTENSION, "Unsupported device class '0x%x'", Icc->DeviceClass);
 836         return FALSE;
 837     }
 838 
 839     // Get size as reported in header
 840     HeaderSize = _cmsAdjustEndianess32(Header.size);

 905             if ((i != j) && (Icc->TagNames[i] == Icc->TagNames[j])) {
 906                 cmsSignalError(Icc->ContextID, cmsERROR_RANGE, "Duplicate tag found");
 907                 return FALSE;
 908             }
 909 
 910         }
 911     }
 912 
 913     return TRUE;
 914 }
 915 
 916 // Saves profile header
 917 cmsBool _cmsWriteHeader(_cmsICCPROFILE* Icc, cmsUInt32Number UsedSpace)
 918 {
 919     cmsICCHeader Header;
 920     cmsUInt32Number i;
 921     cmsTagEntry Tag;
 922     cmsUInt32Number Count;
 923 
 924     Header.size        = _cmsAdjustEndianess32(UsedSpace);
 925     Header.cmmId       = _cmsAdjustEndianess32(lcmsSignature);
 926     Header.version     = _cmsAdjustEndianess32(Icc ->Version);
 927 
 928     Header.deviceClass = (cmsProfileClassSignature) _cmsAdjustEndianess32(Icc -> DeviceClass);
 929     Header.colorSpace  = (cmsColorSpaceSignature) _cmsAdjustEndianess32(Icc -> ColorSpace);
 930     Header.pcs         = (cmsColorSpaceSignature) _cmsAdjustEndianess32(Icc -> PCS);
 931 
 932     //   NOTE: in v4 Timestamp must be in UTC rather than in local time
 933     _cmsEncodeDateTimeNumber(&Header.date, &Icc ->Created);
 934 
 935     Header.magic       = _cmsAdjustEndianess32(cmsMagicNumber);
 936 
 937 #ifdef CMS_IS_WINDOWS_
 938     Header.platform    = (cmsPlatformSignature) _cmsAdjustEndianess32(cmsSigMicrosoft);
 939 #else
 940     Header.platform    = (cmsPlatformSignature) _cmsAdjustEndianess32(cmsSigMacintosh);
 941 #endif
 942 
 943     Header.flags        = _cmsAdjustEndianess32(Icc -> flags);
 944     Header.manufacturer = _cmsAdjustEndianess32(Icc -> manufacturer);
 945     Header.model        = _cmsAdjustEndianess32(Icc -> model);
 946 
 947     _cmsAdjustEndianess64(&Header.attributes, &Icc -> attributes);
 948 
 949     // Rendering intent in the header (for embedded profiles)
 950     Header.renderingIntent = _cmsAdjustEndianess32(Icc -> RenderingIntent);
 951 
 952     // Illuminant is always D50
 953     Header.illuminant.X = (cmsS15Fixed16Number) _cmsAdjustEndianess32((cmsUInt32Number) _cmsDoubleTo15Fixed16(cmsD50_XYZ()->X));
 954     Header.illuminant.Y = (cmsS15Fixed16Number) _cmsAdjustEndianess32((cmsUInt32Number) _cmsDoubleTo15Fixed16(cmsD50_XYZ()->Y));
 955     Header.illuminant.Z = (cmsS15Fixed16Number) _cmsAdjustEndianess32((cmsUInt32Number) _cmsDoubleTo15Fixed16(cmsD50_XYZ()->Z));
 956 
 957     // Created by LittleCMS (that's me!)
 958     Header.creator      = _cmsAdjustEndianess32(lcmsSignature);
 959 
 960     memset(&Header.reserved, 0, sizeof(Header.reserved));
 961 
 962     // Set profile ID. Endianness is always big endian
 963     memmove(&Header.profileID, &Icc ->ProfileID, 16);
 964 
 965     // Dump the header
 966     if (!Icc -> IOhandler->Write(Icc->IOhandler, sizeof(cmsICCHeader), &Header)) return FALSE;
 967 
 968     // Saves Tag directory
 969 
 970     // Get true count
 971     Count = 0;
 972     for (i=0;  i < Icc -> TagCount; i++) {
 973         if (Icc ->TagNames[i] != (cmsTagSignature) 0)
 974             Count++;
 975     }
 976 
 977     // Store number of tags
 978     if (!_cmsWriteUInt32Number(Icc ->IOhandler, Count)) return FALSE;

 543     _cmsICCPROFILE* Icc = (_cmsICCPROFILE*)hProfile;
 544 
 545     if (Icc == NULL) return NULL;
 546     return Icc->IOhandler;
 547 }
 548 
 549 // Creates an empty structure holding all required parameters
 550 cmsHPROFILE CMSEXPORT cmsCreateProfilePlaceholder(cmsContext ContextID)
 551 {
 552     _cmsICCPROFILE* Icc = (_cmsICCPROFILE*) _cmsMallocZero(ContextID, sizeof(_cmsICCPROFILE));
 553     if (Icc == NULL) return NULL;
 554 
 555     Icc ->ContextID = ContextID;
 556 
 557     // Set it to empty
 558     Icc -> TagCount   = 0;
 559 
 560     // Set default version
 561     Icc ->Version =  0x02100000;
 562 
 563     // Set default CMM (that's me!)
 564     Icc ->CMM = lcmsSignature;
 565 
 566     // Set default creator
 567     // Created by LittleCMS (that's me!)
 568     Icc ->creator = lcmsSignature;
 569 
 570     // Set default platform
 571 #ifdef CMS_IS_WINDOWS_
 572     Icc ->platform = cmsSigMicrosoft;
 573 #else
 574     Icc ->platform = cmsSigMacintosh;
 575 #endif
 576 
 577     // Set default device class
 578     Icc->DeviceClass = cmsSigDisplayClass;
 579 
 580     // Set creation date/time
 581     if (!_cmsGetTime(&Icc->Created))
 582         goto Error;
 583 
 584     // Create a mutex if the user provided proper plugin. NULL otherwise
 585     Icc ->UsrMutex = _cmsCreateMutex(ContextID);
 586 
 587     // Return the handle
 588     return (cmsHPROFILE) Icc;
 589 
 590 Error:
 591     _cmsFree(ContextID, Icc);
 592     return NULL;
 593 }
 594 
 595 cmsContext CMSEXPORT cmsGetProfileContextID(cmsHPROFILE hProfile)
 596 {

 810     cmsTagEntry Tag;
 811     cmsICCHeader Header;
 812     cmsUInt32Number i, j;
 813     cmsUInt32Number HeaderSize;
 814     cmsIOHANDLER* io = Icc ->IOhandler;
 815     cmsUInt32Number TagCount;
 816 
 817 
 818     // Read the header
 819     if (io -> Read(io, &Header, sizeof(cmsICCHeader), 1) != 1) {
 820         return FALSE;
 821     }
 822 
 823     // Validate file as an ICC profile
 824     if (_cmsAdjustEndianess32(Header.magic) != cmsMagicNumber) {
 825         cmsSignalError(Icc ->ContextID, cmsERROR_BAD_SIGNATURE, "not an ICC profile, invalid signature");
 826         return FALSE;
 827     }
 828 
 829     // Adjust endianness of the used parameters
 830     Icc -> CMM             = _cmsAdjustEndianess32(Header.cmmId);
 831     Icc -> DeviceClass     = (cmsProfileClassSignature) _cmsAdjustEndianess32(Header.deviceClass);
 832     Icc -> ColorSpace      = (cmsColorSpaceSignature)   _cmsAdjustEndianess32(Header.colorSpace);
 833     Icc -> PCS             = (cmsColorSpaceSignature)   _cmsAdjustEndianess32(Header.pcs);
 834 
 835     Icc -> RenderingIntent = _cmsAdjustEndianess32(Header.renderingIntent);
 836     Icc -> platform        = (cmsPlatformSignature)_cmsAdjustEndianess32(Header.platform);
 837     Icc -> flags           = _cmsAdjustEndianess32(Header.flags);
 838     Icc -> manufacturer    = _cmsAdjustEndianess32(Header.manufacturer);
 839     Icc -> model           = _cmsAdjustEndianess32(Header.model);
 840     Icc -> creator         = _cmsAdjustEndianess32(Header.creator);
 841 
 842     _cmsAdjustEndianess64(&Icc -> attributes, &Header.attributes);
 843     Icc -> Version         = _cmsAdjustEndianess32(_validatedVersion(Header.version));
 844 
 845     if (Icc->Version > 0x5000000) {
 846         cmsSignalError(Icc->ContextID, cmsERROR_UNKNOWN_EXTENSION, "Unsupported profile version '0x%x'", Icc->Version);
 847         return FALSE;
 848     }
 849 
 850     if (!validDeviceClass(Icc->DeviceClass)) {
 851         cmsSignalError(Icc->ContextID, cmsERROR_UNKNOWN_EXTENSION, "Unsupported device class '0x%x'", Icc->DeviceClass);
 852         return FALSE;
 853     }
 854 
 855     // Get size as reported in header
 856     HeaderSize = _cmsAdjustEndianess32(Header.size);

 921             if ((i != j) && (Icc->TagNames[i] == Icc->TagNames[j])) {
 922                 cmsSignalError(Icc->ContextID, cmsERROR_RANGE, "Duplicate tag found");
 923                 return FALSE;
 924             }
 925 
 926         }
 927     }
 928 
 929     return TRUE;
 930 }
 931 
 932 // Saves profile header
 933 cmsBool _cmsWriteHeader(_cmsICCPROFILE* Icc, cmsUInt32Number UsedSpace)
 934 {
 935     cmsICCHeader Header;
 936     cmsUInt32Number i;
 937     cmsTagEntry Tag;
 938     cmsUInt32Number Count;
 939 
 940     Header.size        = _cmsAdjustEndianess32(UsedSpace);
 941     Header.cmmId       = _cmsAdjustEndianess32(Icc ->CMM);
 942     Header.version     = _cmsAdjustEndianess32(Icc ->Version);
 943 
 944     Header.deviceClass = (cmsProfileClassSignature) _cmsAdjustEndianess32(Icc -> DeviceClass);
 945     Header.colorSpace  = (cmsColorSpaceSignature) _cmsAdjustEndianess32(Icc -> ColorSpace);
 946     Header.pcs         = (cmsColorSpaceSignature) _cmsAdjustEndianess32(Icc -> PCS);
 947 
 948     //   NOTE: in v4 Timestamp must be in UTC rather than in local time
 949     _cmsEncodeDateTimeNumber(&Header.date, &Icc ->Created);
 950 
 951     Header.magic       = _cmsAdjustEndianess32(cmsMagicNumber);
 952 
 953     Header.platform    = (cmsPlatformSignature) _cmsAdjustEndianess32(Icc -> platform);




 954 
 955     Header.flags        = _cmsAdjustEndianess32(Icc -> flags);
 956     Header.manufacturer = _cmsAdjustEndianess32(Icc -> manufacturer);
 957     Header.model        = _cmsAdjustEndianess32(Icc -> model);
 958 
 959     _cmsAdjustEndianess64(&Header.attributes, &Icc -> attributes);
 960 
 961     // Rendering intent in the header (for embedded profiles)
 962     Header.renderingIntent = _cmsAdjustEndianess32(Icc -> RenderingIntent);
 963 
 964     // Illuminant is always D50
 965     Header.illuminant.X = (cmsS15Fixed16Number) _cmsAdjustEndianess32((cmsUInt32Number) _cmsDoubleTo15Fixed16(cmsD50_XYZ()->X));
 966     Header.illuminant.Y = (cmsS15Fixed16Number) _cmsAdjustEndianess32((cmsUInt32Number) _cmsDoubleTo15Fixed16(cmsD50_XYZ()->Y));
 967     Header.illuminant.Z = (cmsS15Fixed16Number) _cmsAdjustEndianess32((cmsUInt32Number) _cmsDoubleTo15Fixed16(cmsD50_XYZ()->Z));
 968 
 969     Header.creator      = _cmsAdjustEndianess32(Icc ->creator);

 970 
 971     memset(&Header.reserved, 0, sizeof(Header.reserved));
 972 
 973     // Set profile ID. Endianness is always big endian
 974     memmove(&Header.profileID, &Icc ->ProfileID, 16);
 975 
 976     // Dump the header
 977     if (!Icc -> IOhandler->Write(Icc->IOhandler, sizeof(cmsICCHeader), &Header)) return FALSE;
 978 
 979     // Saves Tag directory
 980 
 981     // Get true count
 982     Count = 0;
 983     for (i=0;  i < Icc -> TagCount; i++) {
 984         if (Icc ->TagNames[i] != (cmsTagSignature) 0)
 985             Count++;
 986     }
 987 
 988     // Store number of tags
 989     if (!_cmsWriteUInt32Number(Icc ->IOhandler, Count)) return FALSE;
< prev index next >