qcms_profile * gfxPlatform::GetCMSOutputProfile() { if (!gCMSOutputProfile) { NS_TIME_FUNCTION; nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID); if (prefs) { nsresult rv; /* Determine if we're using the internal override to force sRGB as an output profile for reftests. See Bug 452125. Note that we don't normally (outside of tests) set a default value of this preference, which means GetBoolPref will typically throw (and leave its out-param untouched). */ PRBool doSRGBOverride; rv = prefs->GetBoolPref(CMForceSRGBPrefName, &doSRGBOverride); if (NS_SUCCEEDED(rv) && doSRGBOverride) gCMSOutputProfile = GetCMSsRGBProfile(); if (!gCMSOutputProfile) { nsXPIDLCString fname; rv = prefs->GetCharPref(CMProfilePrefName, getter_Copies(fname)); if (NS_SUCCEEDED(rv) && !fname.IsEmpty()) { gCMSOutputProfile = qcms_profile_from_path(fname); } } } if (!gCMSOutputProfile) { gCMSOutputProfile = gfxPlatform::GetPlatform()->GetPlatformCMSOutputProfile(); } /* Determine if the profile looks bogus. If so, close the profile * and use sRGB instead. See bug 460629, */ if (gCMSOutputProfile && qcms_profile_is_bogus(gCMSOutputProfile)) { NS_ASSERTION(gCMSOutputProfile != GetCMSsRGBProfile(), "Builtin sRGB profile tagged as bogus!!!"); qcms_profile_release(gCMSOutputProfile); gCMSOutputProfile = nsnull; } if (!gCMSOutputProfile) { gCMSOutputProfile = GetCMSsRGBProfile(); } /* Precache the LUT16 Interpolations for the output profile. See bug 444661 for details. */ qcms_profile_precache_output_transform(gCMSOutputProfile); } return gCMSOutputProfile; }
void do_test(void) { unsigned char srct[4] = { 221, 79, 129, 92}; unsigned char outt[4]; qcms_transform *transform; qcms_profile *input_profile, *output_profile, *rgb; qcms_CIE_xyY white_point = { 0, 0, 1.}; qcms_CIE_xyYTRIPLE primaries = { {.9, .3, 1.}, {.2, .4, 1.}, {.7, .4, 1.}}; rgb = qcms_profile_create_rgb_with_gamma(white_point, primaries, 1.8); input_profile = qcms_profile_sRGB(); output_profile = qcms_profile_sRGB(); if (output_profile) { test_gray(output_profile); test_gray_precache(output_profile); qcms_profile_release(output_profile); } if (input_profile) qcms_profile_release(input_profile); if (rgb) qcms_profile_release(rgb); rgb = qcms_profile_from_path("sample-trunc.icc"); if (rgb) qcms_profile_release(rgb); }
qcms_profile * gfxPlatformMac::GetPlatformCMSOutputProfile() { qcms_profile *profile = nsnull; CMProfileRef cmProfile; CMProfileLocation *location; UInt32 locationSize; /* There a number of different ways that we could try to get a color profile to use. On 10.5 all of these methods seem to give the same results. On 10.6, the results are different and the following method, using CGMainDisplayID() seems to best match what we are looking for. Currently, both Google Chrome and Qt4 use a similar method. CMTypes.h describes CMDisplayIDType: "Data type for ColorSync DisplayID reference On 8 & 9 this is a AVIDType On X this is a CGSDisplayID" CGMainDisplayID gives us a CGDirectDisplayID which presumeably corresponds directly to a CGSDisplayID */ CGDirectDisplayID displayID = CGMainDisplayID(); CMError err = CMGetProfileByAVID(static_cast<CMDisplayIDType>(displayID), &cmProfile); if (err != noErr) return nsnull; // get the size of location err = NCMGetProfileLocation(cmProfile, NULL, &locationSize); if (err != noErr) return nsnull; // allocate enough room for location location = static_cast<CMProfileLocation*>(malloc(locationSize)); if (!location) goto fail_close; err = NCMGetProfileLocation(cmProfile, location, &locationSize); if (err != noErr) goto fail_location; switch (location->locType) { #ifndef __LP64__ case cmFileBasedProfile: { FSRef fsRef; if (!FSpMakeFSRef(&location->u.fileLoc.spec, &fsRef)) { char path[512]; if (!FSRefMakePath(&fsRef, reinterpret_cast<UInt8*>(path), sizeof(path))) { profile = qcms_profile_from_path(path); #ifdef DEBUG_tor if (profile) fprintf(stderr, "ICM profile read from %s fileLoc successfully\n", path); #endif } } break; } #endif case cmPathBasedProfile: profile = qcms_profile_from_path(location->u.pathLoc.path); #ifdef DEBUG_tor if (profile) fprintf(stderr, "ICM profile read from %s pathLoc successfully\n", device.u.pathLoc.path); #endif break; default: #ifdef DEBUG_tor fprintf(stderr, "Unhandled ColorSync profile location\n"); #endif break; } fail_location: free(location); fail_close: CMCloseProfile(cmProfile); return profile; }