imageprop.cpp
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 24k
Category:

Windows Kernel

Development Platform:

Visual C++

  1. //-------------------------------------------------------------------------//
  2. #include "pch.h"
  3. #if 0
  4. #   ifdef _X86_
  5. #       define _USE_OFFICE_TEXT_
  6. #       define _USE_OFFICE_TIFF_
  7. #   endif _X86_
  8. #else 0
  9. #   define _USE_MSFAX_TEXT_
  10. #   define _USE_MSFAX_TIFF_
  11. #endif 0
  12. #include "imageprop.h"
  13. #include "tiff.h"
  14. // {E2300424-8950-11d2-BE79-00A0C9A83DA1}
  15. static const GUID FMTID_FaxSummaryInformation = 
  16.     { 0xe2300424, 0x8950, 0x11d2, { 0xbe, 0x79, 0x0, 0xa0, 0xc9, 0xa8, 0x3d, 0xa1 } };
  17. #ifdef _X86_
  18. #define IFLSUCCEEDED( iflErr )  (iflErr==IFLERR_NONE)
  19. #define IFLFAILED( iflErr )     (iflErr!=IFLERR_NONE)
  20. //-------------------------------------------------------------------------//
  21. BOOL InitIflProperties( IFLPROPERTIES* pIP )
  22. {
  23.     if( !pIP ) return FALSE ;
  24.     memset( pIP, 0, sizeof(*pIP) ) ;
  25.     pIP->cbStruct = sizeof(*pIP) ;      
  26.     
  27.     pIP->mask       = 0L ;
  28.     pIP->type       = IFLT_UNKNOWN  ;
  29.     pIP->imageclass = IFLCL_NONE ;
  30.     
  31.     /*
  32.     pIP->width      = 0L ;
  33.     pIP->height     = 0L ;
  34.     pIP->linecount  = 0L ;
  35.     pIP->bpp        = 0L ;
  36.     pIP->bpc        = 0L ;
  37.     pIP->dpm        = 0L ;
  38.     pIP->imagecount = 0L ;
  39.     */
  40.     pIP->tilefmt    = IFLTF_NONE ;
  41.     pIP->lineseq    = IFLSEQ_TOPDOWN ;
  42.     pIP->compression= IFLCOMP_NONE ;
  43.     return TRUE ;
  44. }
  45. //-------------------------------------------------------------------------//
  46. BOOL ClearIflProperties( IFLPROPERTIES* pIP )
  47. {
  48.     if( !pIP ) return FALSE ;
  49.     return InitIflProperties( pIP ) ;   
  50. }
  51. #ifdef _USE_OFFICE_TEXT_
  52. //-------------------------------------------------------------------------//
  53. //  Retrieves text metadata from image file using office graphics import filters.
  54. BOOL GetImageDescription( IFLHANDLE iflHandle, IFLDESC iflSupported, IFLDESC iflDesc, 
  55.                           LPSTR pszBuf, int cchBuf )
  56. {
  57.     ASSERT( pszBuf ) ;
  58.     *pszBuf = 0 ;
  59.     CHAR*    pszDesc = NULL ;
  60.     IFLERROR iflErr = iflGetDesc( iflHandle, iflDesc, &pszDesc ) ;
  61.     if( IFLERR_NONE == iflErr )
  62.     {
  63.         lstrcpynA( pszBuf, pszDesc, cchBuf ) ;
  64.         return TRUE ;
  65.     }
  66.     return FALSE ;
  67. }
  68. //-------------------------------------------------------------------------//
  69. //  Acquires text metadata properties using office graphics import filters
  70. static HRESULT AcquireTextProperties( IFLHANDLE iflHandle, IFLPROPERTIES* pIP, ULONG* pcProps )
  71. {
  72.     IFLDESC     iflSupported ;
  73.     IFLERROR    iflErr    = IFLERR_NONE ;
  74.     CHAR        szText[MAX_METADATA_TEXT] ;
  75.     HRESULT     hr ;
  76.     
  77.     if( (iflErr = iflSupportedDesc( iflHandle, &iflSupported )) == IFLERR_NONE )
  78.     {
  79.         USES_CONVERSION ;
  80.         if( (pIP->textmask & ITPF_TITLE) == 0 &&
  81.                 GetImageDescription( iflHandle, iflSupported, IFLDESC_DOCUMENTNAME, 
  82.                                  szText, ARRAYSIZE(szText) ) )
  83.         {
  84.             lstrcpynW( pIP->szTitle, A2W(szText), ARRAYSIZE(pIP->szTitle) ) ;
  85.             (*pcProps)++ ;
  86.             pIP->mask |= IPF_TEXT ;
  87.             pIP->textmask |= ITPF_TITLE ;
  88.         }
  89.         if( (pIP->textmask & ITPF_AUTHOR) == 0 &&
  90.             GetImageDescription( iflHandle, iflSupported, IFLDESC_ARTISTNAME, 
  91.                                  szText, ARRAYSIZE(szText) ) )
  92.         {
  93.             lstrcpynW( pIP->szAuthor, A2W(szText), ARRAYSIZE(pIP->szAuthor) ) ;
  94.             (*pcProps)++ ;
  95.             pIP->mask |= IPF_TEXT ;
  96.             pIP->textmask |= ITPF_AUTHOR ;
  97.         }
  98.         if( (pIP->textmask & ITPF_DESCRIPTION) == 0 &&
  99.             GetImageDescription( iflHandle, iflSupported, IFLDESC_DESCRIPTION, 
  100.                                  szText, ARRAYSIZE(szText) ) )
  101.         {
  102.             lstrcpynW( pIP->szDescription, A2W(szText), ARRAYSIZE(pIP->szDescription) ) ;
  103.             (*pcProps)++ ;
  104.             pIP->mask |= IPF_TEXT ;
  105.             pIP->textmask |= ITPF_DESCRIPTION ;
  106.         }
  107.         if( (pIP->textmask & ITPF_COMMENTS) == 0 &&
  108.             GetImageDescription( iflHandle, iflSupported, IFLDESC_COMMENT, 
  109.                                  szText, ARRAYSIZE(szText) ) )
  110.         {
  111.             lstrcpynW( pIP->szComments, A2W(szText), ARRAYSIZE(pIP->szComments) ) ;
  112.             (*pcProps)++ ;
  113.             pIP->mask |= IPF_TEXT ;
  114.             pIP->textmask |= ITPF_COMMENTS ;
  115.         }
  116.         if( (pIP->textmask & ITPF_SOFTWARE) == 0 &&
  117.             GetImageDescription( iflHandle, iflSupported, IFLDESC_SOFTWARENAME, 
  118.                                  szText, ARRAYSIZE(szText) ) )
  119.         {
  120.             lstrcpynW( pIP->szSoftware, A2W(szText), ARRAYSIZE(pIP->szSoftware) ) ;
  121.             (*pcProps)++ ;
  122.             pIP->mask |= IPF_TEXT ;
  123.             pIP->textmask |= ITPF_SOFTWARE ;
  124.         }
  125.         if( (pIP->textmask & ITPF_COPYRIGHT) == 0 &&
  126.             GetImageDescription( iflHandle, iflSupported, IFLDESC_COPYRIGHT, 
  127.                                  szText, ARRAYSIZE(szText) ) )
  128.         {
  129.             lstrcpynW( pIP->szCopyright, A2W(szText), ARRAYSIZE(pIP->szCopyright) ) ;
  130.             (*pcProps)++ ;
  131.             pIP->mask |= IPF_TEXT ;
  132.             pIP->textmask |= ITPF_COPYRIGHT ;
  133.         }
  134.         hr = (pIP->mask & IPF_TEXT) != 0 ? S_OK : S_FALSE ;
  135.     }
  136.     else
  137.         hr = IflErrorToHResult( iflErr, FALSE ) ;
  138.     return hr ;
  139. }
  140. #endif _USE_OFFICE_TEXT_
  141. #ifdef  _USE_OFFICE_TIFF_
  142. //-------------------------------------------------------------------------//
  143. //  retrieves a tiff metadata string value using office graphics import filters.
  144. BOOL GetTiffTagString( IN IFLHANDLE iflHandle, IN WORD tagID, OUT LPWSTR pszBuf, IN OUT DWORD* pcchBuf )
  145. {
  146.     IFLERROR iflErr ;
  147.     TIFF_TAG tag ;
  148.     BOOL     bRet = FALSE ;
  149.     ASSERT( pszBuf ) ;
  150.     ASSERT( pcchBuf && *pcchBuf ) ;
  151.     
  152.     if( (iflErr = iflControl( iflHandle, IFLCMD_TIFFTAG, tagID, 0L, &tag )) == IFLERR_NONE )
  153.     {
  154.         if( TIFF_ASCII == tag.DataType )
  155.         {
  156.             if( tag.DataCount <= *pcchBuf )
  157.             {
  158.                 CHAR* pszBufA = new CHAR[tag.DataCount] ;
  159.                 if( pszBufA )
  160.                 {
  161.                     if( iflControl( iflHandle, IFLCMD_TIFFTAGDATA, tagID, 0L, pszBufA ) == IFLERR_NONE )
  162.                     {
  163.                         USES_CONVERSION ;
  164.                         lstrcpynW( pszBuf, A2W( pszBufA ), *pcchBuf ) ;
  165.                         bRet = TRUE ;
  166.                     }
  167.                     delete [] pszBufA ;
  168.                 }
  169.             }
  170.             *pcchBuf = tag.DataCount ;
  171.         }
  172.     }
  173.     return bRet ;
  174. }
  175. //-------------------------------------------------------------------------//
  176. //  retrieves a tiff metadata time value using office graphics import filters.
  177. BOOL GetTiffTagTime( IN IFLHANDLE iflHandle, IN WORD tagID, OUT FILETIME* pft )
  178. {
  179.     IFLERROR iflErr ;
  180.     TIFF_TAG tag ;
  181.     ASSERT( pszBuf ) ;
  182.     ASSERT( pcchBuf && *pcchBuf ) ;
  183.     
  184.     if( (iflErr = iflControl( iflHandle, IFLCMD_TIFFTAG, tagID, 0L, &tag )) == IFLERR_NONE )
  185.     {
  186.         if( TIFF_SRATIONAL == tag.DataType )
  187.         {
  188.             BYTE ull[256] ;
  189.             ZeroMemory( ull, ARRAYSIZE(ull) ) ;
  190.             if( iflControl( iflHandle, IFLCMD_TIFFTAGDATA, tagID, 0L, ull ) == IFLERR_NONE )
  191.             {
  192.                 *pft = *((FILETIME*)ull) ;
  193.                 //pft->dwLowDateTime  = *((DWORD*)&ull[0]) ;
  194.                 //pft->dwHighDateTime = *((DWORD*)&ull[4]) ;
  195.                 return TRUE ;
  196.             }
  197.         }
  198.     }
  199.     return FALSE ;
  200. }
  201. //-------------------------------------------------------------------------//
  202. //  Acquires TIFF fax properties using office TIFF import filter
  203. static HRESULT AcquireFaxProperties( IFLHANDLE iflHandle, IFLPROPERTIES* pIP, ULONG* pcProps )
  204. {
  205.     ASSERT( iflHandle ) ;
  206.     ASSERT( pIP ) ;
  207.     ASSERT( sizeof(*pIP) == pIP->cbStruct ) ;
  208.     ULONG cch ;
  209.     
  210.     cch = ARRAYSIZE(pIP->szFaxRecipName) ;
  211.     if( GetTiffTagString( iflHandle, TIFFTAG_RECIP_NAME, pIP->szFaxRecipName, &cch ) )
  212.     {
  213.         (*pcProps)++ ;
  214.         pIP->mask |= IPF_FAX ;
  215.         pIP->faxmask |= IFPF_RECIPIENTNAME ;
  216.     }
  217.     cch = ARRAYSIZE(pIP->szFaxRecipNumber) ;
  218.     if( GetTiffTagString( iflHandle, TIFFTAG_RECIP_NUMBER, pIP->szFaxRecipNumber, &cch ) )
  219.     {
  220.         (*pcProps)++ ;
  221.         pIP->mask |= IPF_FAX ;
  222.         pIP->faxmask |= IFPF_RECIPIENTNUMBER ;
  223.     }
  224.     cch = ARRAYSIZE(pIP->szFaxSenderName) ;
  225.     if( GetTiffTagString( iflHandle, TIFFTAG_SENDER_NAME, pIP->szFaxSenderName, &cch ) )
  226.     {
  227.         (*pcProps)++ ;
  228.         pIP->mask |= IPF_FAX ;
  229.         pIP->faxmask |= IFPF_SENDERNAME ;
  230.     }
  231.     cch = ARRAYSIZE(pIP->szFaxRouting) ;
  232.     if( GetTiffTagString( iflHandle, TIFFTAG_ROUTING, pIP->szFaxRouting, &cch ) )
  233.     {
  234.         (*pcProps)++ ;
  235.         pIP->mask |= IPF_FAX ;
  236.         pIP->faxmask |= IFPF_ROUTING ;
  237.     }
  238.     cch = ARRAYSIZE(pIP->szFaxCallerID) ;
  239.     if( GetTiffTagString( iflHandle, TIFFTAG_CALLERID, pIP->szFaxCallerID, &cch ) )
  240.     {
  241.         (*pcProps)++ ;
  242.         pIP->mask |= IPF_FAX ;
  243.         pIP->faxmask |= IFPF_CALLERID ;
  244.     }
  245.     cch = ARRAYSIZE(pIP->szFaxTSID) ;
  246.     if( GetTiffTagString( iflHandle, TIFFTAG_TSID, pIP->szFaxTSID, &cch ) )
  247.     {
  248.         (*pcProps)++ ;
  249.         pIP->mask |= IPF_FAX ;
  250.         pIP->faxmask |= IFPF_TSID ;
  251.     }
  252.     cch = ARRAYSIZE(pIP->szFaxCSID) ;
  253.     if( GetTiffTagString( iflHandle, TIFFTAG_CSID, pIP->szFaxCSID, &cch ) )
  254.     {
  255.         (*pcProps)++ ;
  256.         pIP->mask |= IPF_FAX ;
  257.         pIP->faxmask |= IFPF_CSID ;
  258.     }
  259.     FILETIME ft ;
  260.     if( GetTiffTagTime( iflHandle, TIFFTAG_FAX_TIME, &ft ) )
  261.     {
  262.         pIP->ftFaxTime = ft ;
  263.         (*pcProps)++ ;
  264.         pIP->mask |= IPF_FAX ;
  265.         pIP->faxmask |= IFPF_FAXTIME ;
  266.     }
  267.     return HasFaxProperties( pIP ) ? S_OK : S_FALSE ;
  268. }
  269. #endif  _USE_OFFICE_TIFF_
  270. #if defined (_USE_MSFAX_TIFF_) || defined(_USE_MSFAX_TEXT_)
  271. //-------------------------------------------------------------------------//
  272. #include "faxcom.h"
  273. static const IID IID_IFaxTiff  = { 0xb19bb45f, 0xb91c, 0x11d1, {0x83,0xe1,0x00,0xc0,0x4f,0xb6,0xe9,0x84} };
  274. static const IID CLSID_FaxTiff = { 0x87099231, 0xC7AF, 0x11D0, {0xB2,0x25,0x00,0xC0,0x4F,0xB6,0xC2,0xF5 } } ;
  275. #endif //(_USE_MSFAX_TIFF_) || defined(_USE_MSFAX_TEXT_)
  276. //-------------------------------------------------------------------------//
  277. //  Acquires metadata properties using MSFax FaxCom object
  278. #ifdef _USE_MSFAX_TEXT_
  279. static HRESULT AcquireTextProperties( const WCHAR* pwszFileName, IFLPROPERTIES* pIP, ULONG* pcProps )
  280. {
  281.     HRESULT hr = S_FALSE ;
  282.     ASSERT( pIP ) ;
  283.     ASSERT( sizeof(*pIP) == pIP->cbStruct ) ;
  284.     
  285.     pIP->mask &= ~IPF_TEXT ;
  286.     IFaxTiff* pft ;
  287.     if( SUCCEEDED( (hr = CoCreateInstance( CLSID_FaxTiff, NULL, CLSCTX_INPROC_SERVER, IID_IFaxTiff, (void**)&pft )) ) )
  288.     {
  289.         BSTR    bstrImage = SysAllocString( pwszFileName ) ;
  290.         //  CR: ActiveFaxfaxtiff.cpp: CFaxTiff::put_Image should free bstrImage.
  291.         if( SUCCEEDED( pft->put_Image( bstrImage ) ) )
  292.         {
  293.             VARIANT var ;
  294.             BSTR    bstr ;
  295.             if( S_OK == pft->get_TiffTagString( TIFFTAG_DOCUMENTNAME, &bstr ) )
  296.             {
  297.                 lstrcpynW( pIP->szTitle, bstr, ARRAYSIZE(pIP->szTitle) ) ;
  298.                 SysFreeString( bstr ) ;
  299.                 (*pcProps)++ ;
  300.                 pIP->mask |= IPF_TEXT ;
  301.                 pIP->textmask |= ITPF_TITLE ;
  302.             }
  303.             if( S_OK == pft->get_TiffTagString( TIFFTAG_ARTIST, &bstr ) )
  304.             {
  305.                 lstrcpynW( pIP->szAuthor, bstr, ARRAYSIZE(pIP->szAuthor) ) ;
  306.                 SysFreeString( bstr ) ;
  307.                 (*pcProps)++ ;
  308.                 pIP->mask |= IPF_TEXT ;
  309.                 pIP->textmask |= ITPF_AUTHOR ;
  310.             }
  311.             if( S_OK == pft->get_TiffTagString( TIFFTAG_IMAGEDESCRIPTION, &bstr ) )
  312.             {
  313.                 lstrcpynW( pIP->szDescription, bstr, ARRAYSIZE(pIP->szDescription) ) ;
  314.                 SysFreeString( bstr ) ;
  315.                 (*pcProps)++ ;
  316.                 pIP->mask |= IPF_TEXT ;
  317.                 pIP->textmask |= ITPF_DESCRIPTION ;
  318.             }
  319.             if( S_OK == pft->get_TiffTagString( TIFFTAG_SOFTWARE, &bstr ) )
  320.             {
  321.                 lstrcpynW( pIP->szSoftware, bstr, ARRAYSIZE(pIP->szSoftware) ) ;
  322.                 SysFreeString( bstr ) ;
  323.                 (*pcProps)++ ;
  324.                 pIP->mask |= IPF_TEXT ;
  325.                 pIP->textmask |= ITPF_SOFTWARE ;
  326.             }
  327.             if( S_OK == pft->get_TiffTagString( TIFFTAG_COPYRIGHT, &bstr ) )
  328.             {
  329.                 lstrcpynW( pIP->szCopyright, bstr, ARRAYSIZE(pIP->szCopyright) ) ;
  330.                 SysFreeString( bstr ) ;
  331.                 (*pcProps)++ ;
  332.                 pIP->mask |= IPF_TEXT ;
  333.                 pIP->textmask |= ITPF_COPYRIGHT ;
  334.             }
  335.         }
  336.         hr = (pIP->mask & IPF_TEXT) != 0 ? S_OK : S_FALSE ;
  337.         pft->Release() ;
  338.     }
  339.     return hr ;
  340. }
  341. #endif //_USE_MSFAX_TEXT_
  342. //-------------------------------------------------------------------------//
  343. //  Acquires TIFF fax properties using MSFax FaxCom object
  344. #ifdef _USE_MSFAX_TIFF_
  345. HRESULT AcquireFaxProperties( const WCHAR* pwszFileName, IFLPROPERTIES* pIP, ULONG* pcProps )
  346. {
  347.     HRESULT hr = S_FALSE ;
  348.     ASSERT( pIP ) ;
  349.     ASSERT( sizeof(*pIP) == pIP->cbStruct ) ;
  350.     
  351.     IFaxTiff* pft ;
  352.     if( SUCCEEDED( (hr = CoCreateInstance( CLSID_FaxTiff, NULL, CLSCTX_INPROC_SERVER, IID_IFaxTiff, (void**)&pft )) ) )
  353.     {
  354.         BSTR    bstrImage = SysAllocString( pwszFileName ) ;
  355.         //  CR: ActiveFaxfaxtiff.cpp: CFaxTiff::put_Image should free bstrImage.
  356.         if( SUCCEEDED( pft->put_Image( bstrImage ) ) )
  357.         {
  358.             VARIANT var ;
  359.             BSTR    bstr ;
  360.             if( S_OK == (hr = pft->get_RecipientName( &bstr )) )
  361.             {
  362.                 lstrcpyW( pIP->szFaxRecipName, bstr ) ;
  363.                 SysFreeString( bstr ) ;
  364.                 (*pcProps)++ ;
  365.                 pIP->mask |= IPF_FAX ;
  366.                 pIP->faxmask |= IFPF_RECIPIENTNAME ;
  367.             }
  368.             if( S_OK == (hr = pft->get_SenderName( &bstr )) )
  369.             {
  370.                 lstrcpyW( pIP->szFaxSenderName, bstr ) ;
  371.                 SysFreeString( bstr ) ;
  372.                 (*pcProps)++ ;
  373.                 pIP->mask |= IPF_FAX ;
  374.                 pIP->faxmask |= IFPF_SENDERNAME ;
  375.             }
  376.             if( S_OK == (hr = pft->get_Routing( &bstr )) )
  377.             {
  378.                 lstrcpyW( pIP->szFaxRouting, bstr ) ;
  379.                 SysFreeString( bstr ) ;
  380.                 (*pcProps)++ ;
  381.                 pIP->mask |= IPF_FAX ;
  382.                 pIP->faxmask |= IFPF_ROUTING ;
  383.             }
  384.             if( S_OK == (hr = pft->get_CallerId( &bstr )) )
  385.             {
  386.                 lstrcpyW( pIP->szFaxCallerID, bstr ) ;
  387.                 SysFreeString( bstr ) ;
  388.                 (*pcProps)++ ;
  389.                 pIP->mask |= IPF_FAX ;
  390.                 pIP->faxmask |= IFPF_CALLERID ;
  391.             }
  392.             if( S_OK == (hr = pft->get_Csid( &bstr )) )
  393.             {
  394.                 lstrcpyW( pIP->szFaxCSID, bstr ) ;
  395.                 SysFreeString( bstr ) ;
  396.                 (*pcProps)++ ;
  397.                 pIP->mask |= IPF_FAX ;
  398.                 pIP->faxmask |= IFPF_CSID ;
  399.             }
  400.             if( S_OK == (hr = pft->get_Tsid( &bstr )) )
  401.             {
  402.                 lstrcpyW( pIP->szFaxTSID, bstr ) ;
  403.                 SysFreeString( bstr ) ;
  404.                 (*pcProps)++ ;
  405.                 pIP->mask |= IPF_FAX ;
  406.                 pIP->faxmask |= IFPF_TSID ;
  407.             }
  408.             if( S_OK == (hr = pft->get_RecipientNumber( &bstr )) )
  409.             {
  410.                 lstrcpyW( pIP->szFaxRecipNumber, bstr ) ;
  411.                 SysFreeString( bstr ) ;
  412.                 (*pcProps)++ ;
  413.                 pIP->mask |= IPF_FAX ;
  414.                 pIP->faxmask |= IFPF_RECIPIENTNUMBER ;
  415.             }
  416.             if( S_OK == (hr = pft->get_RawReceiveTime( &var )) )
  417.             {
  418.                 FILETIME    ft, ftLocal ;
  419.                 SYSTEMTIME  st ;
  420.                 BOOL        bConverted = FALSE ;
  421.                 if( VT_CY == var.vt )
  422.                 {
  423.                     pIP->ftFaxTime = *((FILETIME*)&var.cyVal) ;
  424.                     bConverted = TRUE ;
  425.                 }
  426.                 else if( VT_DATE == var.vt )
  427.                 {
  428.                     //  do the conversion dance
  429.                     SYSTEMTIME st ;
  430.                     bConverted = VariantTimeToSystemTime( var.date, &st ) &&
  431.                                  SystemTimeToFileTime( &st, &pIP->ftFaxTime ) ;
  432.                 }
  433.                 if( bConverted )
  434.                 {
  435.                     (*pcProps)++ ;
  436.                     pIP->mask |= IPF_FAX ;
  437.                     pIP->faxmask |= IFPF_FAXTIME ;
  438.                 }
  439.             }
  440.         }
  441.         pft->Release() ;
  442.         hr = HasFaxProperties( pIP ) ? S_OK : S_FALSE ;
  443.     }
  444.     
  445.     return hr ;
  446. }
  447. #endif //_USE_MSFAX_TIFF_
  448. #if defined(_X86_)  // as long as we're using office graphics filters, this is X86 only.
  449. //-------------------------------------------------------------------------//
  450. HRESULT AcquireImageProperties( const WCHAR* pwszFileName, IFLPROPERTIES* pIP, ULONG* pcProps )
  451. {
  452.     IFLHANDLE iflHandle = NULL ;
  453.     IFLTYPE   iflType   = IFLT_UNKNOWN ;
  454.     IFLERROR  iflErr    = IFLERR_NONE ;
  455.     ULONG     cProps    = 0 ;
  456.     ULONG     dwRequested    = 0 ;
  457.     USES_CONVERSION ;
  458.     //  Validate args
  459.     if( !( pwszFileName && *pwszFileName && pIP && pIP->cbStruct==sizeof(*pIP) ) )
  460.         return E_INVALIDARG ;
  461.     if( pcProps ) 
  462.         *pcProps = 0 ;
  463.     else
  464.         pcProps = &cProps ;
  465.     //  Save request bits and clear for output.
  466.     dwRequested = pIP->mask ;
  467.     pIP->mask = 0 ;
  468.     //  Determine image type
  469.     if( IFLFAILED( (iflErr = iflImageType( W2A( pwszFileName ), &pIP->type )) ) )
  470.         return IflErrorToHResult( iflErr, FALSE ) ;
  471.     //  Not an image; abort.
  472.     if( pIP->type == IFLT_UNKNOWN )
  473.         return E_ABORT ;
  474.     (*pcProps)++ ;
  475.     pIP->mask |= IPF_TYPE ;
  476.     
  477.     //  Allocate memory block for image data
  478.     if( (iflHandle = iflCreateReadHandle( pIP->type ))==NULL )
  479.         return E_OUTOFMEMORY ;
  480.     //  Open the file
  481.     if( (iflErr = iflOpen( iflHandle, W2A( pwszFileName ), IFLM_READ )) != IFLERR_NONE )
  482.     {
  483.         iflFreeHandle( iflHandle ) ;
  484.         return IflErrorToHResult( iflErr, FALSE ) ;
  485.     }
  486.     if( dwRequested & IPF_IMAGE )
  487.     {
  488.         //  Image type
  489.         if( pIP->type != IFLT_UNKNOWN )
  490.         {
  491.             //  BMP version
  492.             if( pIP->type == IFLT_BMP &&
  493.                 iflControl( iflHandle, IFLCMD_BMP_VERSION, 0, 0L, 
  494.                             &pIP->bmpver ) == IFLERR_NONE )
  495.             {
  496.                 (*pcProps)++ ;
  497.                 pIP->mask |= IPF_BMPVER ;
  498.             }
  499.             else
  500.             {
  501.                 pIP->bmpver = (IFLBMPVERSION)0 ;
  502.             }
  503.         
  504.             //  Image count
  505.             if( iflControl( iflHandle, IFLCMD_GETNUMIMAGES, (SHORT)pIP->type, 0L,
  506.                             &pIP->imagecount ) != IFLERR_NONE )
  507.                 pIP->imagecount = 0 ;
  508.             else
  509.             {
  510.                 (*pcProps)++ ;
  511.                 pIP->mask |= IPF_IMAGECOUNT ;
  512.             }
  513.         }
  514.         //  Image class
  515.         if( (pIP->imageclass = iflGetClass( iflHandle )) != IFLCL_NONE )
  516.         {
  517.             (*pcProps)++ ;
  518.             pIP->mask |= IPF_CLASS ;
  519.         }
  520.         //  Width
  521.         pIP->cx = iflGetWidth( iflHandle ) ;
  522.         (*pcProps)++ ;
  523.         pIP->mask |= IPF_CX ;
  524.         //  Height
  525.         pIP->cy = iflGetHeight( iflHandle ) ;
  526.         (*pcProps)++ ;
  527.         pIP->mask |= IPF_CY ;
  528.         //  Horiz resolution
  529.         if( iflControl( iflHandle, IFLCMD_RESOLUTION, 1, 0L, &pIP->dpmX ) != IFLERR_NONE )
  530.             pIP->dpmX = 0 ;
  531.         else
  532.         {
  533.             (*pcProps)++ ;
  534.             pIP->mask |= IPF_DPMX ;
  535.         }
  536.         //  Vert resolution
  537.         if( iflControl( iflHandle, IFLCMD_RESOLUTION, 2, 0L, &pIP->dpmY ) != IFLERR_NONE )
  538.             pIP->dpmY = 0 ;
  539.         else
  540.         {
  541.             (*pcProps)++ ;
  542.             pIP->mask |= IPF_DPMY ;
  543.         }
  544.         //  Gamma correction value
  545.         if( (iflErr = iflControl( iflHandle, IFLCMD_GAMMA_VALUE, 0, 0L, &pIP->gamma )) != IFLERR_NONE )
  546.             pIP->gamma = 0 ;
  547.         else
  548.         {
  549.             (*pcProps)++ ;
  550.             pIP->mask |= IPF_GAMMA ;
  551.         }
  552.         //  Raster linecount
  553.         pIP->linecount = iflGetRasterLineCount( iflHandle ) ;
  554.         (*pcProps)++ ;
  555.         pIP->mask |= IPF_LINECOUNT ;
  556.         //  Raster line sequence
  557.         pIP->lineseq = iflGetSequence( iflHandle ) ;
  558.         (*pcProps)++ ;
  559.         pIP->mask |= IPF_LINESEQ ;
  560.         //  Compression mode
  561.         pIP->compression = iflGetCompression( iflHandle ) ;
  562.         (*pcProps)++ ;
  563.         pIP->mask |= IPF_COMPRESSION ;
  564.     
  565.         //  Bit depth
  566.         pIP->bpp = iflGetBitsPerPixel( iflHandle ) ;
  567.         (*pcProps)++ ;
  568.         pIP->mask |= IPF_BPP ;
  569.         //  Bits per channel
  570.         pIP->bpc = iflGetBitsPerChannel( iflHandle ) ;
  571.         (*pcProps)++ ;
  572.         pIP->mask |= IPF_BPC ;
  573.         if( iflControl( iflHandle, IFLCMD_TILEFORMAT, 0, 0L, &pIP->tilefmt )!=IFLERR_NONE )
  574.             pIP->tilefmt = IFLTF_NONE ;
  575.         else
  576.         {
  577.             (*pcProps)++ ;
  578.             pIP->mask |= IPF_TILEFMT ;
  579.         }
  580.     }
  581.     if( dwRequested & IPF_FAX )
  582.     {
  583.         if( IFLT_TIFF == pIP->type )
  584.         {
  585. #ifdef  _USE_MSFAX_TIFF_
  586.             AcquireFaxProperties( pwszFileName, pIP, pcProps ) ;
  587. #endif  _USE_MSFAX_TIFF_
  588. #ifdef _USE_OFFICE_TIFF_
  589.             AcquireFaxProperties( iflHandle, pIP, pcProps ) ;
  590. #endif _USE_OFFICE_TIFF_
  591.         }
  592.     }
  593.     if( dwRequested & IPF_TEXT )
  594.     {
  595.         if( IFLT_TIFF == pIP->type )
  596.         {
  597. #ifdef  _USE_MSFAX_TEXT_
  598.             AcquireTextProperties( pwszFileName, pIP, pcProps ) ;
  599. #endif  _USE_MSFAX_TEXT_
  600.         }
  601. #ifdef _X86_
  602. #   ifdef _USE_OFFICE_TEXT_
  603.         //  Fill in any holes using office filters.
  604.         AcquireTextProperties( iflHandle, pIP, pcProps ) ;
  605. #   endif 
  606. #endif _X86_
  607.     }
  608.     //  Clean up.
  609.     iflClose( iflHandle ) ;
  610.     iflFreeHandle( iflHandle ) ;
  611.     return S_OK ;
  612. }
  613. #endif _X86_
  614. //-------------------------------------------------------------------------//
  615. #if defined(_X86_)
  616. BOOL HasFaxProperties( IFLPROPERTIES* pIP )
  617. {
  618.     return pIP && 
  619.            pIP->cbStruct == sizeof(*pIP) && 
  620.            (pIP->mask & IPF_FAX) !=0 && 
  621.            pIP->faxmask != 0 ;
  622. }
  623. #endif //defined(_X86_)
  624. //-------------------------------------------------------------------------//
  625. #if defined(_X86_)
  626. BOOL HasImageProperties( IFLPROPERTIES* pIP )
  627. {
  628.     return pIP && 
  629.            pIP->cbStruct == sizeof(*pIP) && 
  630.            (pIP->mask & IPF_IMAGE) !=0 ;
  631. }
  632. #endif //defined(_X86_)
  633. //-------------------------------------------------------------------------//
  634. HRESULT IflErrorToHResult( IFLERROR iflError, BOOL bExtended )
  635. {
  636.     if( bExtended )
  637.     {
  638.     }
  639.     else
  640.     {
  641.         switch( iflError )
  642.         {
  643.             case IFLERR_NONE:           return S_OK ;
  644.             case IFLERR_HANDLELIMIT:    return E_HANDLE ;
  645.             case IFLERR_PARAMETER:      return E_INVALIDARG ;
  646.             case IFLERR_NOTSUPPORTED:   return E_NOTIMPL ;
  647.             case IFLERR_NOTAVAILABLE:   return E_NOTIMPL ;
  648.             case IFLERR_MEMORY:         return E_OUTOFMEMORY ;
  649.             
  650.             case IFLERR_IMAGE:          
  651.             case IFLERR_HEADER:         
  652.             case IFLERR_IO_OPEN:        
  653.             case IFLERR_IO_CLOSE:
  654.             case IFLERR_IO_READ:
  655.             case IFLERR_IO_WRITE:
  656.             case IFLERR_IO_SEEK:
  657.             default:
  658.                 break ;
  659.         }
  660.     }
  661.     return E_FAIL ;
  662. }
  663. //-------------------------------------------------------------------------//
  664. //  BUGBUG: image.lib calls strcmpi, which is obsolete, and no longer
  665. //          in the runtime library.  So we'll provide a shim to its replacement...
  666. int __cdecl strcmpi( const char *string1, const char *string2 )
  667. {
  668.     return _stricmp( string1, string2 ) ;
  669. }
  670. #endif _X86_