// This example gets the progressive options for the LEAD JPEG encoder.
// Then it displays the friendly names.
// See the following Example Requirements for help in running this sample
// MyGetSubFormatFriendlyName gets the friendly name of the subformat
CString MyGetSubFormatFriendlyName(IWICLeadBitmapEncoder *piLeadBitmapEncoder, WICPixelFormatGUID guidPixelFormat, UINT uSubformatIndex)
{
CString csRet;
HRESULT hr = S_OK;
UINT uActual = 0;
WCHAR *pwzFriendlyName = NULL;
if (piLeadBitmapEncoder)
{
IWICBitmapEncoder *piBitmapEncoder = NULL;
// Get friendly name for the subformat
IFS(piLeadBitmapEncoder->GetSubFormatFriendlyName(guidPixelFormat, uSubformatIndex, 0, NULL, &uActual));
if (uActual > 0)
{
pwzFriendlyName = new WCHAR[uActual];
if (pwzFriendlyName)
{
IFS(piLeadBitmapEncoder->GetSubFormatFriendlyName(guidPixelFormat, uSubformatIndex, uActual, pwzFriendlyName, &uActual));
if (SUCCEEDED(hr))
csRet = pwzFriendlyName;
}
}
}
DELETE_POINTER(pwzFriendlyName);
return csRet;
}
// Gets the friendly name for a progressive option (nProgressiveOption)
CString MyGetProgressiveOptionsFriendlyName(IWICLeadBitmapEncoder *piLeadBitmapEncoder, INT nProgressiveOption)
{
CString csRet;
HRESULT hr = S_OK;
UINT uActual = 0;
WCHAR *pwzFriendlyName = NULL;
if (piLeadBitmapEncoder)
{
IFS(piLeadBitmapEncoder->GetProgressiveOptionsFriendlyName (nProgressiveOption, 0, NULL, &uActual));
if (uActual > 0)
{
pwzFriendlyName = new WCHAR[uActual];
if (pwzFriendlyName)
{
IFS(piLeadBitmapEncoder->GetProgressiveOptionsFriendlyName (nProgressiveOption, uActual, pwzFriendlyName, &uActual));
if (SUCCEEDED(hr))
csRet = pwzFriendlyName;
}
}
}
DELETE_POINTER(pwzFriendlyName);
return csRet;
}
HRESULT IWICLeadBitmapEncoder_GetProgressiveOptions(HWND hWnd)
{
HRESULT hr = S_OK;
IWICImagingFactory *piImagingFactory = NULL;
IWICBitmapEncoder *piBitmapEncoder = NULL;
IWICLeadBitmapEncoder *piLeadBitmapEncoder = NULL;
CString csExampleName = L"IWICLeadBitmapEncoder_GetProgressiveOptions";
CString csMsg = csExampleName + "\n\n";
// Create a LEAD Jpeg Bitmap Encoder
IFS(CoCreateInstance(CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_IWICImagingFactory, (LPVOID*) &piImagingFactory));
IFS(piImagingFactory->CreateEncoder(GUID_ContainerFormatLeadJpeg, NULL, &piBitmapEncoder));
// QueryInterface on the encoder to get the IWICLeadBitmapEncoder interface
IFS(piBitmapEncoder->QueryInterface(IID_WICLeadBitmapEncoder, reinterpret_cast < void**> (&piLeadBitmapEncoder)));
// **************************************************************************
// First get the sub formats for the LEAD Jpeg Encoder with 24 bits per pixel
// **************************************************************************
WICPixelFormatGUID guidPixelFormat = GUID_WICPixelFormat24bppBGR;
UINT uSubFormats = 0;
WICLeadSubFormat *pSubFormats = NULL;
WICLeadSubFormatFlags uFlags = WICLeadFlagNone;
INT nIndexProgressive = -1;
// first call, to get number of subformats
IFS(piLeadBitmapEncoder->GetSubFormats(guidPixelFormat, 0, NULL, &uSubFormats));
if (SUCCEEDED(hr))
{
pSubFormats = new WICLeadSubFormat[uSubFormats];
if (pSubFormats)
{
// second call, to get the subformats
IFS(piLeadBitmapEncoder->GetSubFormats(guidPixelFormat, uSubFormats, pSubFormats, &uSubFormats));
}
}
// **************************************************************************
// Next, get the sub formats flags for the sub-formats.
// Continue this until we find a subformat that supports WICLeadFlagProgressive
// **************************************************************************
for (UINT i=0; i < uSubFormats; i++)
{
IFS(piLeadBitmapEncoder->GetSubFormatFlags(guidPixelFormat, i, &uFlags));
if (uFlags & WICLeadFlagProgressive)
nIndexProgressive = i;
}
// **************************************************************************
// If we found a subformat that supports WICLeadFlagProgressive,
// * print the the friendly name for the subformat
// * get the progressive options
// * print the friendly name for the progressive option
// **************************************************************************
UINT uProgressiveOptions = 0;
INT *pProgressiveOptions = NULL;
if (nIndexProgressive >= 0)
{
csMsg = csMsg + L"LEAD Jpeg Encoder sub-format: " + MyGetSubFormatFriendlyName(piLeadBitmapEncoder, guidPixelFormat, nIndexProgressive) + L"\n";
IFS(piLeadBitmapEncoder->GetProgressiveOptions(guidPixelFormat, nIndexProgressive, 0, NULL, &uProgressiveOptions));
if (SUCCEEDED(hr))
{
pProgressiveOptions = new INT[uProgressiveOptions];
if (pProgressiveOptions)
{
csMsg = csMsg + L"ProgressiveOptions\n";
IFS(piLeadBitmapEncoder->GetProgressiveOptions(guidPixelFormat, nIndexProgressive, uProgressiveOptions, pProgressiveOptions, &uProgressiveOptions));
for (UINT i=0; i < uProgressiveOptions; i++)
{
csMsg = csMsg + MyGetProgressiveOptionsFriendlyName(piLeadBitmapEncoder, pProgressiveOptions[i]) + L"\n";
}
}
}
}
// Cleanup
RELEASE_INTERFACE(piLeadBitmapEncoder);
RELEASE_INTERFACE(piBitmapEncoder);
RELEASE_INTERFACE(piImagingFactory);
DELETE_POINTER(pProgressiveOptions);
DELETE_POINTER(pSubFormats);
MessageBox(hWnd, csMsg, csExampleName, MB_OK);
return hr;
}