📄 profman.cpp
字号:
/*++
Copyright (c) 2005 Microsoft Corporation
All rights reserved.
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
File Name:
profman.cpp
Abstract:
Color profile class implementation. The CProfileManager class represents
a color profile and provides a transform from the system default profile
to the supplied profile.
--*/
#include "precomp.h"
#include "debug.h"
#include "globals.h"
#include "xdstring.h"
#include "xdexcept.h"
#include "profman.h"
using XDPrintSchema::JobOptimalDestinationColorProfile::JobOptimalDestinationColorProfileData;
using XDPrintSchema::JobOptimalDestinationColorProfile::EProfileOption;
using XDPrintSchema::JobOptimalDestinationColorProfile::RGB;
using XDPrintSchema::JobOptimalDestinationColorProfile::CMYK;
using XDPrintSchema::PageICMRenderingIntent::PageICMRenderingIntentData;
using XDPrintSchema::PageICMRenderingIntent::AbsoluteColorimetric;
using XDPrintSchema::PageICMRenderingIntent::RelativeColorimetric;
using XDPrintSchema::PageICMRenderingIntent::Photographs;
using XDPrintSchema::PageICMRenderingIntent::BusinessGraphics;
/*++
Routine Name:
CProfileManager::CProfileManager
Routine Description:
Constructor for the CProfileManager class which records internally the device name,
color profile structure, color intents data and initialises the CProfileManager
ready to supply suitable color transforms
Arguments:
pszDeviceName - Pointer to a string containing the device name
cmProfData - Structure containing color profile settings from the PrintTicket
cmIntData - Structure containing color intents settings from the PrintTicket
Return Value:
None
Throws CXDException(HRESULT) on an error
--*/
CProfileManager::CProfileManager(
__in LPCWSTR pszDeviceName,
__in JobOptimalDestinationColorProfileData cmProfData,
__in PageICMRenderingIntentData cmIntData,
__in IFixedPage* pFP
) :
m_strDeviceName(pszDeviceName),
m_cmProfData(cmProfData),
m_cmIntData(cmIntData),
m_pFixedPage(pFP)
{
HRESULT hr = S_OK;
if (SUCCEEDED(hr = CHECK_POINTER(pszDeviceName, E_POINTER)) ||
SUCCEEDED(hr = CHECK_POINTER(m_pFixedPage, E_POINTER)))
{
if(m_strDeviceName.GetLength() <= 0)
{
hr = E_INVALIDARG;
}
}
if (FAILED(hr))
{
throw CXDException(E_INVALIDARG);
}
}
/*++
Routine Name:
CProfileManager::~CProfileManager
Routine Description:
Default destructor for the CProfileManager class which performs and clean up
Arguments:
None
Return Value:
None
--*/
CProfileManager::~CProfileManager()
{
}
/*++
Routine Name:
CProfileManager::GetColorTransform
Routine Description:
Method which supplies a color transform based on the settings in the PrintTicket
Arguments:
phColorTrans - Pointer to a color transform handle which will contain
a transform based off the settings in the PrintTicket
Return Value:
HRESULT
S_OK - On success
E_* - On error
--*/
HRESULT
CProfileManager::GetColorTransform(
__out HTRANSFORM* phColorTrans,
__out BOOL* pbUseWCS
)
{
HRESULT hr = S_OK;
if (SUCCEEDED(hr = CHECK_POINTER(pbUseWCS, E_POINTER)) &&
SUCCEEDED(hr = CHECK_HANDLE(phColorTrans, E_POINTER)) &&
SUCCEEDED(hr = m_dstProfile.SetProfile(m_cmProfData.cmProfileName)))
{
*pbUseWCS = IsVista();
try
{
//
// Construct and populate a profile list for the transform object
//
ProfileList profileList;
//
// Check the source profile has been set. GetProfileHandle will return an error
// if it has not been.
//
HPROFILE hProfile = NULL;
if (SUCCEEDED(hr = m_srcProfile.GetProfileHandle(&hProfile)))
{
profileList.push_back(&m_srcProfile);
profileList.push_back(&m_dstProfile);
//
// Map the PrintTicket intents option to the ICM option
//
DWORD intents = INTENT_ABSOLUTE_COLORIMETRIC;
switch (m_cmIntData.cmOption)
{
case AbsoluteColorimetric:
{
intents = INTENT_ABSOLUTE_COLORIMETRIC;
}
break;
case RelativeColorimetric:
{
intents = INTENT_RELATIVE_COLORIMETRIC;
}
break;
case Photographs:
{
intents = INTENT_PERCEPTUAL;
}
break;
case BusinessGraphics:
default:
{
intents = INTENT_SATURATION;
}
break;
}
DWORD flRender = BEST_MODE;
//
// Check if the source and destination profiles are compatible with WCS
//
if (*pbUseWCS &&
SUCCEEDED(hr = m_srcProfile.IsWCSCompatible(pbUseWCS)))
{
if (*pbUseWCS)
{
hr = m_dstProfile.IsWCSCompatible(pbUseWCS);
}
}
if (SUCCEEDED(hr) &&
*pbUseWCS)
{
//
// Everything is in place for using WCS
//
flRender |= WCS_ALWAYS;
}
if (SUCCEEDED(hr) &&
SUCCEEDED(hr = m_colorTrans.CreateTransform(&profileList, intents, flRender)))
{
hr = m_colorTrans.GetTransformHandle(phColorTrans);
}
}
}
catch (CXDException& e)
{
hr = e;
}
catch (exception& DBG_ONLY(e))
{
ERR(e.what());
hr = E_FAIL;
}
}
ERR_ON_HR(hr);
return hr;
}
/*++
Routine Name:
CProfileManager::GetDstProfileType
Routine Description:
Method to return the color profile type as read from the PrintTicket
Arguments:
pType - Pointer to the profile type to be filled in
Return Value:
HRESULT
S_OK - On success
E_* - On error
--*/
HRESULT
CProfileManager::GetDstProfileType(
__out EProfileOption* pType
)
{
HRESULT hr = S_OK;
if (SUCCEEDED(hr = CHECK_POINTER(pType, E_POINTER)))
{
*pType = m_cmProfData.cmProfile;
}
ERR_ON_HR(hr);
return hr;
}
/*++
Routine Name:
CProfileManager::GetDstProfileName
Routine Description:
Method which returns the systems default colour profile name
Arguments:
pbstrProfileName - Pointer to string to hold the profile name
Return Value:
HRESULT
S_OK - On success
E_* - On error
--*/
HRESULT
CProfileManager::GetDstProfileName(
__out BSTR* pbstrProfileName
)
{
HRESULT hr = S_OK;
if (SUCCEEDED(hr = CHECK_POINTER(pbstrProfileName, E_POINTER)))
{
try
{
CStringXDW cstrURI;
if (m_cmProfData.cmProfile == RGB ||
m_cmProfData.cmProfile == CMYK)
{
if (SUCCEEDED(hr = GetColDir(&cstrURI)))
{
cstrURI += L"\\";
cstrURI += m_cmProfData.cmProfileName;
}
}
else
{
hr = E_NOTIMPL;
}
SysFreeString(*pbstrProfileName);
*pbstrProfileName = cstrURI.AllocSysString();
}
catch (CXDException& e)
{
hr = e;
}
}
ERR_ON_HR(hr);
return hr;
}
/*++
Routine Name:
CProfileManager::SetSrcProfileFromContainer
Routine Description:
Method which sets the source colour profile from a profile within the
XPS container
Arguments:
pszProfileURI - Pointer to string holding the profile URI
Return Value:
HRESULT
S_OK - On success
E_* - On error
--*/
HRESULT
CProfileManager::SetSrcProfileFromContainer(
__in LPWSTR szProfileURI
)
{
HRESULT hr = S_OK;
if (SUCCEEDED(hr = CHECK_POINTER(szProfileURI, E_POINTER)))
{
hr = m_srcProfile.SetProfile(m_pFixedPage, szProfileURI);
}
ERR_ON_HR(hr);
return hr;
}
/*++
Routine Name:
CProfileManager::SetSrcProfileFromColDir
Routine Description:
Method which sets the source colour profile from the color directory
Arguments:
pszProfile - Pointer to string holding the profile name
Return Value:
HRESULT
S_OK - On success
E_* - On error
--*/
HRESULT
CProfileManager::SetSrcProfileFromColDir(
__in LPWSTR szProfile
)
{
HRESULT hr = S_OK;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -