svn path=/Slnkdwf/trunk/; revision=12498

This commit is contained in:
Jos Groot Lipman
2010-12-02 15:53:56 +00:00
parent 30e6ea273c
commit d13438dc0f
3 changed files with 261 additions and 0 deletions

168
SlnkDWFCom/ImageConvert.cpp Normal file
View File

@@ -0,0 +1,168 @@
// ImageConvert.cpp : Implementation of CImageConvert
#include "stdafx.h"
#include "ImageConvert.h"
// CImageConvert
STDMETHODIMP CImageConvert::InterfaceSupportsErrorInfo(REFIID riid)
{
static const IID* arr[] =
{
&IID_IImageConvert
};
for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++)
{
if (InlineIsEqualGUID(*arr[i],riid))
return S_OK;
}
return S_FALSE;
}
CString FindExtension(const CString& name)
{
int len = name.GetLength();
int i;
for (i = len-1; i >= 0; i--){
if (name[i] == '.'){
return name.Mid(i+1);
}
}
return CString("");
}
int FindFormat(const CString& ext)
{
int type = 0;
// if (ext == "bmp") type = CXIMAGE_FORMAT_BMP;
if (0) {}
#if CXIMAGE_SUPPORT_JPG
else if (ext=="jpg"||ext=="jpeg") type = CXIMAGE_FORMAT_JPG;
#endif
#if CXIMAGE_SUPPORT_GIF
else if (ext == "gif") type = CXIMAGE_FORMAT_GIF;
#endif
#if CXIMAGE_SUPPORT_PNG
else if (ext == "png") type = CXIMAGE_FORMAT_PNG;
#endif
#if CXIMAGE_SUPPORT_MNG
else if (ext=="mng"||ext=="jng") type = CXIMAGE_FORMAT_MNG;
#endif
#if CXIMAGE_SUPPORT_ICO
else if (ext == "ico") type = CXIMAGE_FORMAT_ICO;
#endif
#if CXIMAGE_SUPPORT_TIF
else if (ext=="tiff"||ext=="tif") type = CXIMAGE_FORMAT_TIF;
#endif
#if CXIMAGE_SUPPORT_TGA
else if (ext=="tga") type = CXIMAGE_FORMAT_TGA;
#endif
#if CXIMAGE_SUPPORT_PCX
else if (ext=="pcx") type = CXIMAGE_FORMAT_PCX;
#endif
#if CXIMAGE_SUPPORT_WBMP
else if (ext=="wbmp") type = CXIMAGE_FORMAT_WBMP;
#endif
#if CXIMAGE_SUPPORT_WMF
else if (ext=="wmf"||ext=="emf") type = CXIMAGE_FORMAT_WMF;
#endif
#if CXIMAGE_SUPPORT_J2K
else if (ext=="j2k"||ext=="jp2") type = CXIMAGE_FORMAT_J2K;
#endif
#if CXIMAGE_SUPPORT_JBG
else if (ext=="jbg") type = CXIMAGE_FORMAT_JBG;
#endif
#if CXIMAGE_SUPPORT_JP2
else if (ext=="jp2"||ext=="j2k") type = CXIMAGE_FORMAT_JP2;
#endif
#if CXIMAGE_SUPPORT_JPC
else if (ext=="jpc"||ext=="j2c") type = CXIMAGE_FORMAT_JPC;
#endif
#if CXIMAGE_SUPPORT_PGX
else if (ext=="pgx") type = CXIMAGE_FORMAT_PGX;
#endif
#if CXIMAGE_SUPPORT_RAS
else if (ext=="ras") type = CXIMAGE_FORMAT_RAS;
#endif
#if CXIMAGE_SUPPORT_PNM
else if (ext=="pnm"||ext=="pgm"||ext=="ppm") type = CXIMAGE_FORMAT_PNM;
#endif
else type = CXIMAGE_FORMAT_UNKNOWN;
return type;
}
STDMETHODIMP CImageConvert::Open(BSTR IMGPath)
{
CString filein(IMGPath);
CString extin(FindExtension(filein));
extin.MakeLower();
int typein = FindFormat(extin);
if (typein == CXIMAGE_FORMAT_UNKNOWN) {
return myAtlReportError (GetObjectCLSID(), "Unknown extension loading %s", filein);
}
if (!m_image.Load(filein,typein)){
return myAtlReportError (GetObjectCLSID(), "Error loading %s\n%s", filein, m_image.GetLastError());
}
m_height = m_image.GetHeight();
m_width = m_image.GetWidth();
return S_OK;
}
STDMETHODIMP CImageConvert::SaveAs(BSTR IMGPath)
{
if (m_height != m_image.GetHeight() ||
m_width != m_image.GetWidth())
{
// mode 1 for fast (nearest pixel) method, or 2 for accurate (bicubic spline interpolation) method.
if (!m_image.Resample(m_width, m_height, /*mode*/ 2))
return myAtlReportError (GetObjectCLSID(), "Error resizing to w=%d, h=%d\n%s",
m_height, m_width, m_image.GetLastError());
}
CString fileout(IMGPath);
CString extout(FindExtension(fileout));
extout.MakeLower();
int typeout = FindFormat(extout);
if (typeout == CXIMAGE_FORMAT_UNKNOWN) {
return myAtlReportError (GetObjectCLSID(), "Unknown extension saving %s", fileout);
}
if (!m_image.Save(fileout,typeout)){
return myAtlReportError (GetObjectCLSID(), "Error saving %s\n%s", fileout, m_image.GetLastError());
}
return S_OK;
}
STDMETHODIMP CImageConvert::get_Height(LONG* pVal)
{
*pVal = m_height;
return S_OK;
}
STDMETHODIMP CImageConvert::put_Height(LONG newVal)
{
m_height = newVal;
return S_OK;
}
STDMETHODIMP CImageConvert::get_Width(LONG* pVal)
{
*pVal = m_width;
return S_OK;
}
STDMETHODIMP CImageConvert::put_Width(LONG newVal)
{
m_width = newVal;
return S_OK;
}

67
SlnkDWFCom/ImageConvert.h Normal file
View File

@@ -0,0 +1,67 @@
// ImageConvert.h : Declaration of the CImageConvert
#pragma once
#include "resource.h" // main symbols
#include "SLNKDWF.h"
#include "CxImage\CxImage\ximage.h"
#if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA)
#error "Single-threaded COM objects are not properly supported on Windows CE platform, such as the Windows Mobile platforms that do not include full DCOM support. Define _CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA to force ATL to support creating single-thread COM object's and allow use of it's single-threaded COM object implementations. The threading model in your rgs file was set to 'Free' as that is the only threading model supported in non DCOM Windows CE platforms."
#endif
// CImageConvert
class ATL_NO_VTABLE CImageConvert :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CImageConvert, &CLSID_ImageConvert>,
public ISupportErrorInfo,
public IDispatchImpl<IImageConvert, &IID_IImageConvert, &LIBID_SLNKDWFLib, /*wMajor =*/ 1, /*wMinor =*/ 0>
{
public:
CImageConvert()
{
}
DECLARE_REGISTRY_RESOURCEID(IDR_IMAGECONVERT)
BEGIN_COM_MAP(CImageConvert)
COM_INTERFACE_ENTRY(IImageConvert)
COM_INTERFACE_ENTRY(IDispatch)
COM_INTERFACE_ENTRY(ISupportErrorInfo)
END_COM_MAP()
// ISupportsErrorInfo
STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
DECLARE_PROTECT_FINAL_CONSTRUCT()
HRESULT FinalConstruct()
{
return S_OK;
}
void FinalRelease()
{
}
private:
CxImage m_image;
int m_width;
int m_height;
public:
STDMETHOD(Open)(BSTR IMGPath);
STDMETHOD(SaveAs)(BSTR IMGPath);
STDMETHOD(get_Height)(LONG* pVal);
STDMETHOD(put_Height)(LONG newVal);
STDMETHOD(get_Width)(LONG* pVal);
STDMETHOD(put_Width)(LONG newVal);
};
OBJECT_ENTRY_AUTO(__uuidof(ImageConvert), CImageConvert)

View File

@@ -0,0 +1,26 @@
HKCR
{
SLNKDWF.ImageConvert.1 = s 'ImageConvert Class'
{
CLSID = s '{03B0F69B-ABBF-480E-9875-D85598BFBE44}'
}
SLNKDWF.ImageConvert = s 'ImageConvert Class'
{
CLSID = s '{03B0F69B-ABBF-480E-9875-D85598BFBE44}'
CurVer = s 'SLNKDWF.ImageConvert.1'
}
NoRemove CLSID
{
ForceRemove {03B0F69B-ABBF-480E-9875-D85598BFBE44} = s 'ImageConvert Class'
{
ProgID = s 'SLNKDWF.ImageConvert.1'
VersionIndependentProgID = s 'SLNKDWF.ImageConvert'
ForceRemove 'Programmable'
InprocServer32 = s '%MODULE%'
{
val ThreadingModel = s 'Apartment'
}
'TypeLib' = s '{B6FCDE6E-141C-4601-B3AC-4DF4D5F25DF8}'
}
}
}