⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 magickimage.cpp

📁 下载来的一个看图软件的源代码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    case EXCEPTION_FLT_DENORMAL_OPERAND:      return "float denormal operand";    case EXCEPTION_FLT_DIVIDE_BY_ZERO:      return "float devide by zero";    case EXCEPTION_FLT_INEXACT_RESULT:      return "float inexact result";    case EXCEPTION_FLT_INVALID_OPERATION:      return "float invalid operation";    case EXCEPTION_FLT_OVERFLOW:      return "float overflow";    case EXCEPTION_FLT_STACK_CHECK:      return "float stack check";    case EXCEPTION_FLT_UNDERFLOW:      return "float underflow";    case EXCEPTION_INT_DIVIDE_BY_ZERO:      return "integer divide by zero";    case EXCEPTION_INT_OVERFLOW:      return "integer overflow";    case EXCEPTION_PRIV_INSTRUCTION:      return "privleged instruction";    case EXCEPTION_IN_PAGE_ERROR:      return "page error";    case EXCEPTION_ILLEGAL_INSTRUCTION:      return "illegal instruction";    case EXCEPTION_NONCONTINUABLE_EXCEPTION:      return "noncontinuable instruction";    case EXCEPTION_STACK_OVERFLOW:      return "stack overflow";    case EXCEPTION_INVALID_DISPOSITION:      return "invalid disosition";    case EXCEPTION_GUARD_PAGE:      return "guard page";    case EXCEPTION_INVALID_HANDLE:      return "invalid handle";    default:      return "operating system exception";  }}STDMETHODIMP CMagickImage::Convert(SAFEARRAY **pArrayVar, VARIANT *pVar){  USES_CONVERSION;  HRESULT hr;  ExceptionInfo    exception;  char    *reason,    *description,    message_text[MaxTextExtent];  __try  {    EmptyArgs();    AddArgs(L"-convert");    GetExceptionInfo(&exception);    reason = "unknown";    description = "unknown";    hr = Perform(ConvertImageCommand,pArrayVar,pVar,&exception);    if (FAILED(hr))    {      if (exception.reason)        reason = exception.reason;      if (exception.description)        description = exception.description;    }  }  __except(1)  {    hr = E_UNEXPECTED;    reason = "exception";    description = translate_exception(_exception_code());  }	if (FAILED(hr))    {      hr = MAKE_HRESULT(SEVERITY_ERROR,FACILITY_ITF,dwErrorBase+1001);      FormatString(message_text,"convert: %d: %.1024s: %.1024s",        exception.severity,reason, description);      Error(A2W(message_text),IID_IMagickImage,hr);    }  DestroyExceptionInfo(&exception);  return hr;}STDMETHODIMP CMagickImage::Composite(SAFEARRAY **pArrayVar, VARIANT *pVar){  USES_CONVERSION;  HRESULT hr;  ExceptionInfo    exception;  char    *reason,    *description,    message_text[MaxTextExtent];  __try  {    EmptyArgs();    AddArgs(L"-convert");    GetExceptionInfo(&exception);    reason = "unknown";    description = "unknown";    hr = Perform(CompositeImageCommand,pArrayVar,pVar,&exception);    if (FAILED(hr))    {      if (exception.reason)        reason = exception.reason;      if (exception.description)        description = exception.description;    }  }  __except(1)  {    hr = E_UNEXPECTED;    reason = "exception";    description = translate_exception(_exception_code());  }	if (FAILED(hr))    {      hr = MAKE_HRESULT(SEVERITY_ERROR,FACILITY_ITF,dwErrorBase+1001);      FormatString(message_text,"composite: %d: %.1024s: %.1024s",        exception.severity,reason, description);      Error(A2W(message_text),IID_IMagickImage,hr);    }  DestroyExceptionInfo(&exception);  return hr;}STDMETHODIMP CMagickImage::Mogrify(SAFEARRAY **pArrayVar, VARIANT *pVar){  USES_CONVERSION;  HRESULT hr;  ExceptionInfo    exception;  char    *reason,    *description,    message_text[MaxTextExtent];  __try  {    EmptyArgs();    AddArgs(L"-convert");    GetExceptionInfo(&exception);    reason = "unknown";    description = "unknown";    hr = Perform(MogrifyImageCommand,pArrayVar,pVar,&exception);    if (FAILED(hr))    {      if (exception.reason)        reason = exception.reason;      if (exception.description)        description = exception.description;    }  }  __except(1)  {    hr = E_UNEXPECTED;    reason = "exception";    description = translate_exception(_exception_code());  }	if (FAILED(hr))    {      hr = MAKE_HRESULT(SEVERITY_ERROR,FACILITY_ITF,dwErrorBase+1001);      FormatString(message_text,"mogrify: %d: %.1024s: %.1024s",        exception.severity,reason, description);      Error(A2W(message_text),IID_IMagickImage,hr);    }  DestroyExceptionInfo(&exception);  return hr;}STDMETHODIMP CMagickImage::Montage(SAFEARRAY **pArrayVar, VARIANT *pVar){  USES_CONVERSION;  HRESULT hr;  ExceptionInfo    exception;  char    *reason,    *description,    message_text[MaxTextExtent];  __try  {    EmptyArgs();    AddArgs(L"-convert");    GetExceptionInfo(&exception);    reason = "unknown";    description = "unknown";    hr = Perform(MontageImageCommand,pArrayVar,pVar,&exception);    if (FAILED(hr))    {      if (exception.reason)        reason = exception.reason;      if (exception.description)        description = exception.description;    }  }  __except(1)  {    hr = E_UNEXPECTED;    reason = "exception";    description = translate_exception(_exception_code());  }	if (FAILED(hr))    {      hr = MAKE_HRESULT(SEVERITY_ERROR,FACILITY_ITF,dwErrorBase+1001);      FormatString(message_text,"montage: %d: %.1024s: %.1024s",        exception.severity,reason, description);      Error(A2W(message_text),IID_IMagickImage,hr);    }  DestroyExceptionInfo(&exception);  return hr;}STDMETHODIMP CMagickImage::Identify(SAFEARRAY **pArrayVar, VARIANT *pVar){  USES_CONVERSION;  HRESULT hr;  ExceptionInfo    exception;  char    *reason,    *description,    message_text[MaxTextExtent];  __try  {    EmptyArgs();    AddArgs(L"-convert");    GetExceptionInfo(&exception);    reason = "unknown";    description = "unknown";    hr = Perform(IdentifyImageCommand,pArrayVar,pVar,&exception);    if (FAILED(hr))    {      if (exception.reason)        reason = exception.reason;      if (exception.description)        description = exception.description;    }  }  __except(1)  {    hr = E_UNEXPECTED;    reason = "exception";    description = translate_exception(_exception_code());  }	if (FAILED(hr))    {      hr = MAKE_HRESULT(SEVERITY_ERROR,FACILITY_ITF,dwErrorBase+1001);      FormatString(message_text,"identify: %d: %.1024s: %.1024s",        exception.severity,reason, description);      Error(A2W(message_text),IID_IMagickImage,hr);    }  DestroyExceptionInfo(&exception);  return hr;}const char *objName = "ImageMagickObject";#define ThrowPerformException(exception,code,reason,description) \{ \	DebugString("%s - %s %s\n",objName,reason,description); \  ThrowException(exception,code,reason,description); \  return E_INVALIDARG; \}#define LogInformation(reason,description) \{ \	DebugString("%s - %s %s\n",objName,reason,description); \}const char *methodName = "Perform";HRESULT CMagickImage::Perform(unsigned int (*func)(ImageInfo *image_info,  const int argc,LPTSTR *argv,LPTSTR *text,ExceptionInfo *exception),  SAFEARRAY **pArrayVar, VARIANT *pVar,ExceptionInfo *exception){  USES_CONVERSION;  bool bDebug = false;  HRESULT hr = E_INVALIDARG;  char *text;#ifdef _DEBUG  //_DbgBreak();#endif	LogInformation(methodName,"enter");  //text = (char *) 0xffffffffL;  //char c = *text;  // causes and access violation  text = (char *)NULL;  m_coll.clear();#ifdef SUPPORT_OBJECTS  CComObject<CMagickImage>* pMagickImage;#endif  if( !pArrayVar )   {    ThrowPerformException(exception,ErrorException,      "Perform","Argument list is NULL");  }  CComVectorData<VARIANT> rg(*pArrayVar);  if( !rg )   {    ThrowPerformException(exception,ErrorException,      "Perform","Argument list is bad");  }  int iLastVal = rg.Length();  bool bFoundOption = false;  for( int i = 0; i < iLastVal; ++i )  {    VARIANT &varIndex = rg[i];    VARIANTARG *pvarIndex = &varIndex;    VARTYPE vt = V_VT(pvarIndex);    while (vt == (VT_VARIANT|VT_BYREF))    {	    pvarIndex = V_VARIANTREF(pvarIndex);	    vt = V_VT(pvarIndex);    }//->    if (V_ISARRAY(pvarIndex))    {      TCHAR sz[128];      SAFEARRAY *psa;      if (V_ISBYREF(pvarIndex))	        psa = *V_ARRAYREF(pvarIndex);      else	        psa = V_ARRAY(pvarIndex);//----->        {//------->          if (psa)            {              VARTYPE vatype = (V_VT(pvarIndex) & ~(VT_ARRAY | VT_BYREF));              int ndim = SafeArrayGetDim(psa);              if (ndim != 1)              {                ThrowPerformException(exception,ErrorException,                  "Perform","Multi-dimensional arrays not supported");              }              if (i < (iLastVal-1))//------------>               {                  bool bFoundIt = false;                  // This is any array that is not the last one in the arg                  // list. This means it must be an input so we just pass                  // it along.                  switch(vatype)//--------------->                  {                    case VT_UI1:                    {                      wsprintf(sz, _T("xtrnarray:0x%lx,"),(unsigned long)(psa));                      hr = AddArgs(sz);                      break;                    }                    default://----------------->                    {                      CComVectorData<VARIANT> vals(psa);                      if (vals)//--------------------->                        {                          VARIANT &varFirst = vals[0];                          VARIANTARG *pvarFirst = &varFirst;                          if (V_VT(pvarFirst) ==  VT_BSTR)//------------------------->                            {                              VARIANT &varSecond = vals[1];                              VARIANTARG *pvarSecond = &varSecond;                              if (V_ISARRAY(pvarSecond))//--------------------------->                              {                                if (V_ISBYREF(pvarSecond))                                  {                                    VARTYPE vatype2 = (V_VT(pvarSecond) & ~(VT_ARRAY | VT_BYREF));                                    if (vatype2 == VT_UI1)                                      {	                                      SAFEARRAY *psax = *V_ARRAYREF(pvarSecond);                                        int ndim2 = SafeArrayGetDim(psax);                                        if (ndim2 != 1)                                        {                                          ThrowPerformException(exception,ErrorException,                                            "Perform","Input blob support requires a 1d array (1)");                                        }                                        LPTSTR lpszVal2 = W2T(pvarFirst->bstrVal);                                        wsprintf(sz, _T("xtrnarray:0x%lx,%s"),                                          (unsigned long)(psax),lpszVal2);                                        hr = AddArgs(sz);                                      }                                  }                                else                                  {                                    VARTYPE vatype2 = (V_VT(pvarSecond) & ~(VT_ARRAY));                                    if (vatype2 == VT_UI1)                                      {	                                      SAFEARRAY *psax = V_ARRAY(pvarSecond);                                        int ndim2 = SafeArrayGetDim(psax);                                        if (ndim2 != 1)                                        {                                          ThrowPerformException(exception,ErrorException,                                            "Perform","Input blob support requires a 1d array (2)");                                        }                                        LPTSTR lpszVal2 = W2T(pvarFirst->bstrVal);                                        wsprintf(sz, _T("xtrnarray:0x%lx,%s"),                                          (unsigned long)(psax),lpszVal2);                                        hr = AddArgs(sz);                                      }                                  }//--------------------------->                              } // end of V_ISARRAY//------------------------->                            } // end of == VT_BSTR                          else                            {                              wsprintf(sz, _T("xtrnarray:0x%lx,"),(unsigned long)(psa));                              hr = AddArgs(sz);                            }                          vals.UnaccessData();                          break;//--------------------->                        } // end of vals not NULL//----------------->                    } // end of default case//--------------->                  } // end of the switch//------------->                }              else                {                  // This is the last thing in the arg list and thus must                  // the output array. We check the contents to a string of                  // characters that says what format to encode the data in.                  if (vatype == VT_UI1)                    {                      // the output is passed as an array of bytes - this                      // is the way that VB does it.                      LPCWSTR pReturnBuffer = NULL;                      long size = SafeArraySize(psa);                      long sizeneeded;                      char *ptrANSI;                      hr = SafeArrayAccessData(psa, (void**)&pReturnBuffer);	                    if(SUCCEEDED(hr))                        {                          sizeneeded = WideCharToMultiByte(                            CP_ACP, 0, pReturnBuffer, size/2, (LPSTR)NULL, 0, NULL, NULL);                          if (sizeneeded)                            {                              ptrANSI = new char [sizeneeded + 1];                              WideCharToMultiByte(                                CP_ACP, 0, pReturnBuffer, size, (LPSTR)ptrANSI, sizeneeded, NULL, NULL);                              ptrANSI[sizeneeded]='\0';                              hr = SafeArrayUnaccessData(psa);                              SafeArrayDestroy(psa);                              SAFEARRAY* pSafeArray = SafeArrayCreateVector(VT_UI1,0,0);                              wsprintf(sz, _T("xtrnarray:0x%lx,%s"),                                (unsigned long)(pSafeArray),ptrANSI);                              hr = AddArgs(sz);                              if (ptrANSI)                                delete ptrANSI;                              if (V_ISBYREF(pvarIndex))                                {                                  V_VT(pvarIndex) = VT_ARRAY | VT_UI1 | VT_BYREF;		                                  *V_ARRAYREF(pvarIndex) = pSafeArray;                                }                              else                                {                                  V_VT(pvarIndex) = VT_ARRAY | VT_UI1;		                                  V_ARRAY(pvarIndex) = pSafeArray;                                }                            }                          else                            {                              ThrowPerformException(exception,ErrorException,                                "Perform","Output array for blob did not specify image format");                            }                        }                      else                      {                        ThrowPerformException(exception,ErrorException,                          "Perform","Output array for blob must be 1d");                      }                    }                  else                    {                      // the output is passed as a variant that is a BSTR                      // - this is the way that VBSCRIPT and ASP does it.                      CComVectorData<VARIANT> vals(psa);                      if (vals)                        {                          VARIANT &varFirst = vals[0];                          VARIANTARG *pvarFirst = &varFirst;                          if (V_VT(pvarFirst) ==  VT_BSTR)                            {                              LPTSTR lpszVal = W2T(pvarFirst->bstrVal);                              vals.UnaccessData();                              SafeArrayDestroy(psa);                              SAFEARRAY* pSafeArray = SafeArrayCreateVector(VT_UI1,0,0);                              wsprintf(sz, _T("xtrnarray:0x%lx,%s"),                                (unsigned long)(pSafeArray),lpszVal);                              hr = AddArgs(sz);                              if (V_ISBYREF(pvarIndex))                                {                                  V_VT(pvarIndex) = VT_ARRAY | VT_UI1 | VT_BYREF;		                                  *V_ARRAYREF(pvarIndex) = pSafeArray;                                }                              else                                {                                  V_VT(pvarIndex) = VT_ARRAY | VT_UI1;		                                  V_ARRAY(pvarIndex) = pSafeArray;                                }                            }                        }                      else                      {                        ThrowPerformException(exception,ErrorException,                          "Perform","Output array for blob is invalid");                      }                    }                }            }          else          {//------->            ThrowPerformException(exception,ErrorException,              "Perform","A passed array is not a vlid array");          }        }//----->    }//->  // V_ISARRAY    else    {      switch(vt)      {        case VT_VARIANT: // invalid, should never happen        case VT_EMPTY:        case VT_NULL:          bFoundOption = false;          break;#ifdef SUPPORT_OBJECTS        case VT_DISPATCH:        {          IDispatch *pDispatch;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -