From c64329592d0a8d4eb8587c65aaf4b8cf2d017f70 Mon Sep 17 00:00:00 2001 From: Vincent Povirk Date: Mon, 8 Mar 2010 17:07:29 -0600 Subject: [PATCH 01/11] windowscodecs: Add a stub TIFF decoder. --- configure.ac | 11 ++ dlls/windowscodecs/Makefile.in | 1 + dlls/windowscodecs/clsfactory.c | 1 + dlls/windowscodecs/regsvr.c | 37 +++++ dlls/windowscodecs/tiffformat.c | 270 ++++++++++++++++++++++++++++++++ dlls/windowscodecs/wincodecs_private.h | 1 + include/config.h.in | 6 + 7 files changed, 327 insertions(+), 0 deletions(-) create mode 100644 dlls/windowscodecs/tiffformat.c diff --git a/configure.ac b/configure.ac index 1431a33..29cc0d8 100644 --- a/configure.ac +++ b/configure.ac @@ -69,6 +69,8 @@ AC_ARG_WITH(png, AS_HELP_STRING([--without-png],[do not use PNG]), AC_ARG_WITH(pthread, AS_HELP_STRING([--without-pthread],[do not use the pthread library]), [if test "x$withval" = "xno"; then ac_cv_header_pthread_h=no; fi]) AC_ARG_WITH(sane, AS_HELP_STRING([--without-sane],[do not use SANE (scanner support)])) +AC_ARG_WITH(tiff, AS_HELP_STRING([--without-tiff],[do not use TIFF]), + [if test "x$withval" = "xno"; then ac_cv_header_tiffio_h=no; fi]) AC_ARG_WITH(v4l, AS_HELP_STRING([--without-v4l],[do not use v4l1 (v4l support)])) AC_ARG_WITH(xcomposite,AS_HELP_STRING([--without-xcomposite],[do not use the Xcomposite extension]), [if test "x$withval" = "xno"; then ac_cv_header_X11_extensions_Xcomposite_h=no; fi]) @@ -435,6 +437,7 @@ AC_CHECK_HEADERS(\ sys/wait.h \ syscall.h \ termios.h \ + tiffio.h \ unistd.h \ utime.h \ valgrind/memcheck.h \ @@ -1458,6 +1461,14 @@ fi WINE_WARNING_WITH(png,[test "x$ac_cv_lib_soname_png" = "x"], [libpng ${notice_platform}development files not found, PNG won't be supported.]) +dnl **** Check for libtiff **** +if test "$ac_cv_header_tiffio_h" = "yes" +then + WINE_CHECK_SONAME(tiff,TIFFClientOpen,,,) +fi +WINE_WARNING_WITH(tiff,[test "x$ac_cv_lib_soname_tiff" = "x"], + [libtiff ${notice_platform}development files not found, TIFF won't be supported.]) + dnl **** Check for mpg123 **** if test "$ac_cv_header_mpg123_h" = "yes" then diff --git a/dlls/windowscodecs/Makefile.in b/dlls/windowscodecs/Makefile.in index 83e7935..7ff3ae2 100644 --- a/dlls/windowscodecs/Makefile.in +++ b/dlls/windowscodecs/Makefile.in @@ -23,6 +23,7 @@ C_SRCS = \ propertybag.c \ regsvr.c \ stream.c \ + tiffformat.c \ ungif.c RC_SRCS = version.rc diff --git a/dlls/windowscodecs/clsfactory.c b/dlls/windowscodecs/clsfactory.c index d8d2105..68e0530 100644 --- a/dlls/windowscodecs/clsfactory.c +++ b/dlls/windowscodecs/clsfactory.c @@ -50,6 +50,7 @@ static classinfo wic_classes[] = { {&CLSID_WICGifDecoder, GifDecoder_CreateInstance}, {&CLSID_WICIcoDecoder, IcoDecoder_CreateInstance}, {&CLSID_WICJpegDecoder, JpegDecoder_CreateInstance}, + {&CLSID_WICTiffDecoder, TiffDecoder_CreateInstance}, {&CLSID_WICDefaultFormatConverter, FormatConverter_CreateInstance}, {0}}; diff --git a/dlls/windowscodecs/regsvr.c b/dlls/windowscodecs/regsvr.c index c87aa4b..0061c8e 100644 --- a/dlls/windowscodecs/regsvr.c +++ b/dlls/windowscodecs/regsvr.c @@ -771,6 +771,12 @@ static struct regsvr_coclass const coclass_list[] = { "windowscodecs.dll", "Apartment" }, + { &CLSID_WICTiffDecoder, + "WIC TIFF Decoder", + NULL, + "windowscodecs.dll", + "Both" + }, { &CLSID_WICDefaultFormatConverter, "WIC Default Format Converter", NULL, @@ -868,6 +874,27 @@ static struct decoder_pattern const png_patterns[] = { {0} }; +static const BYTE tiff_magic_le[] = {0x49,0x49,42,0}; +static const BYTE tiff_magic_be[] = {0x4d,0x4d,0,42}; + +static GUID const * const tiff_formats[] = { + &GUID_WICPixelFormatBlackWhite, + &GUID_WICPixelFormat4bppGray, + &GUID_WICPixelFormat8bppGray, + &GUID_WICPixelFormat4bppIndexed, + &GUID_WICPixelFormat8bppIndexed, + &GUID_WICPixelFormat32bppBGR, + &GUID_WICPixelFormat32bppBGRA, + &GUID_WICPixelFormat32bppPBGRA, + NULL +}; + +static struct decoder_pattern const tiff_patterns[] = { + {4,0,tiff_magic_le,mask_all,0}, + {4,0,tiff_magic_be,mask_all,0}, + {0} +}; + static struct regsvr_decoder const decoder_list[] = { { &CLSID_WICBmpDecoder, "The Wine Project", @@ -919,6 +946,16 @@ static struct regsvr_decoder const decoder_list[] = { png_formats, png_patterns }, + { &CLSID_WICTiffDecoder, + "The Wine Project", + "TIFF Decoder", + "1.0.0.0", + &GUID_VendorMicrosoft, + "image/tiff", + ".tif;.tiff", + tiff_formats, + tiff_patterns + }, { NULL } /* list terminator */ }; diff --git a/dlls/windowscodecs/tiffformat.c b/dlls/windowscodecs/tiffformat.c new file mode 100644 index 0000000..1c6b75a --- /dev/null +++ b/dlls/windowscodecs/tiffformat.c @@ -0,0 +1,270 @@ +/* + * Copyright 2010 Vincent Povirk for CodeWeavers + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include "config.h" +#include "wine/port.h" + +#include + +#ifdef HAVE_TIFFIO_H +#include +#endif + +#define COBJMACROS + +#include "windef.h" +#include "winbase.h" +#include "objbase.h" +#include "wincodec.h" + +#include "wincodecs_private.h" + +#include "wine/debug.h" +#include "wine/library.h" + +WINE_DEFAULT_DEBUG_CHANNEL(wincodecs); + +#ifdef SONAME_LIBTIFF + +static CRITICAL_SECTION init_tiff_cs; +static CRITICAL_SECTION_DEBUG init_tiff_cs_debug = +{ + 0, 0, &init_tiff_cs, + { &init_tiff_cs_debug.ProcessLocksList, + &init_tiff_cs_debug.ProcessLocksList }, + 0, 0, { (DWORD_PTR)(__FILE__ ": init_tiff_cs") } +}; +static CRITICAL_SECTION init_tiff_cs = { &init_tiff_cs_debug, -1, 0, 0, 0, 0 }; + +static void *libtiff_handle; +#define MAKE_FUNCPTR(f) static typeof(f) * p##f +MAKE_FUNCPTR(TIFFClientOpen); +#undef MAKE_FUNCPTR + +static void *load_libtiff(void) +{ + void *result; + + EnterCriticalSection(&init_tiff_cs); + + if (!libtiff_handle && + (libtiff_handle = wine_dlopen(SONAME_LIBTIFF, RTLD_NOW, NULL, 0)) != NULL) + { + +#define LOAD_FUNCPTR(f) \ + if((p##f = wine_dlsym(libtiff_handle, #f, NULL, 0)) == NULL) { \ + ERR("failed to load symbol %s\n", #f); \ + libtiff_handle = NULL; \ + LeaveCriticalSection(&init_tiff_cs); \ + return NULL; \ + } + LOAD_FUNCPTR(TIFFClientOpen); +#undef LOAD_FUNCPTR + + } + + result = libtiff_handle; + + LeaveCriticalSection(&init_tiff_cs); + return result; +} + +typedef struct { + const IWICBitmapDecoderVtbl *lpVtbl; + LONG ref; +} TiffDecoder; + +static HRESULT WINAPI TiffDecoder_QueryInterface(IWICBitmapDecoder *iface, REFIID iid, + void **ppv) +{ + TiffDecoder *This = (TiffDecoder*)iface; + TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv); + + if (!ppv) return E_INVALIDARG; + + if (IsEqualIID(&IID_IUnknown, iid) || IsEqualIID(&IID_IWICBitmapDecoder, iid)) + { + *ppv = This; + } + else + { + *ppv = NULL; + return E_NOINTERFACE; + } + + IUnknown_AddRef((IUnknown*)*ppv); + return S_OK; +} + +static ULONG WINAPI TiffDecoder_AddRef(IWICBitmapDecoder *iface) +{ + TiffDecoder *This = (TiffDecoder*)iface; + ULONG ref = InterlockedIncrement(&This->ref); + + TRACE("(%p) refcount=%u\n", iface, ref); + + return ref; +} + +static ULONG WINAPI TiffDecoder_Release(IWICBitmapDecoder *iface) +{ + TiffDecoder *This = (TiffDecoder*)iface; + ULONG ref = InterlockedDecrement(&This->ref); + + TRACE("(%p) refcount=%u\n", iface, ref); + + if (ref == 0) + { + HeapFree(GetProcessHeap(), 0, This); + } + + return ref; +} + +static HRESULT WINAPI TiffDecoder_QueryCapability(IWICBitmapDecoder *iface, IStream *pIStream, + DWORD *pdwCapability) +{ + FIXME("(%p,%p,%p): stub\n", iface, pIStream, pdwCapability); + return E_NOTIMPL; +} + +static HRESULT WINAPI TiffDecoder_Initialize(IWICBitmapDecoder *iface, IStream *pIStream, + WICDecodeOptions cacheOptions) +{ + FIXME("(%p,%p,%x): stub\n", iface, pIStream, cacheOptions); + return E_NOTIMPL; +} + +static HRESULT WINAPI TiffDecoder_GetContainerFormat(IWICBitmapDecoder *iface, + GUID *pguidContainerFormat) +{ + memcpy(pguidContainerFormat, &GUID_ContainerFormatTiff, sizeof(GUID)); + return S_OK; +} + +static HRESULT WINAPI TiffDecoder_GetDecoderInfo(IWICBitmapDecoder *iface, + IWICBitmapDecoderInfo **ppIDecoderInfo) +{ + FIXME("(%p,%p): stub\n", iface, ppIDecoderInfo); + return E_NOTIMPL; +} + +static HRESULT WINAPI TiffDecoder_CopyPalette(IWICBitmapDecoder *iface, + IWICPalette *pIPalette) +{ + FIXME("(%p,%p): stub\n", iface, pIPalette); + return E_NOTIMPL; +} + +static HRESULT WINAPI TiffDecoder_GetMetadataQueryReader(IWICBitmapDecoder *iface, + IWICMetadataQueryReader **ppIMetadataQueryReader) +{ + FIXME("(%p,%p): stub\n", iface, ppIMetadataQueryReader); + return E_NOTIMPL; +} + +static HRESULT WINAPI TiffDecoder_GetPreview(IWICBitmapDecoder *iface, + IWICBitmapSource **ppIBitmapSource) +{ + FIXME("(%p,%p): stub\n", iface, ppIBitmapSource); + return E_NOTIMPL; +} + +static HRESULT WINAPI TiffDecoder_GetColorContexts(IWICBitmapDecoder *iface, + UINT cCount, IWICColorContext **ppIColorContexts, UINT *pcActualCount) +{ + FIXME("(%p,%u,%p,%p)\n", iface, cCount, ppIColorContexts, pcActualCount); + return E_NOTIMPL; +} + +static HRESULT WINAPI TiffDecoder_GetThumbnail(IWICBitmapDecoder *iface, + IWICBitmapSource **ppIThumbnail) +{ + TRACE("(%p,%p)\n", iface, ppIThumbnail); + return WINCODEC_ERR_CODECNOTHUMBNAIL; +} + +static HRESULT WINAPI TiffDecoder_GetFrameCount(IWICBitmapDecoder *iface, + UINT *pCount) +{ + FIXME("(%p,%p)\n", iface, pCount); + return E_NOTIMPL; +} + +static HRESULT WINAPI TiffDecoder_GetFrame(IWICBitmapDecoder *iface, + UINT index, IWICBitmapFrameDecode **ppIBitmapFrame) +{ + FIXME("(%p,%u,%p)\n", iface, index, ppIBitmapFrame); + return E_NOTIMPL; +} + +static const IWICBitmapDecoderVtbl TiffDecoder_Vtbl = { + TiffDecoder_QueryInterface, + TiffDecoder_AddRef, + TiffDecoder_Release, + TiffDecoder_QueryCapability, + TiffDecoder_Initialize, + TiffDecoder_GetContainerFormat, + TiffDecoder_GetDecoderInfo, + TiffDecoder_CopyPalette, + TiffDecoder_GetMetadataQueryReader, + TiffDecoder_GetPreview, + TiffDecoder_GetColorContexts, + TiffDecoder_GetThumbnail, + TiffDecoder_GetFrameCount, + TiffDecoder_GetFrame +}; + +HRESULT TiffDecoder_CreateInstance(IUnknown *pUnkOuter, REFIID iid, void** ppv) +{ + HRESULT ret; + TiffDecoder *This; + + TRACE("(%p,%s,%p)\n", pUnkOuter, debugstr_guid(iid), ppv); + + *ppv = NULL; + + if (pUnkOuter) return CLASS_E_NOAGGREGATION; + + if (!load_libtiff()) + { + ERR("Failed reading TIFF because unable to load %s\n",SONAME_LIBTIFF); + return E_FAIL; + } + + This = HeapAlloc(GetProcessHeap(), 0, sizeof(TiffDecoder)); + if (!This) return E_OUTOFMEMORY; + + This->lpVtbl = &TiffDecoder_Vtbl; + This->ref = 1; + + ret = IUnknown_QueryInterface((IUnknown*)This, iid, ppv); + IUnknown_Release((IUnknown*)This); + + return ret; +} + +#else /* !SONAME_LIBTIFF */ + +HRESULT TiffDecoder_CreateInstance(IUnknown *pUnkOuter, REFIID iid, void** ppv) +{ + ERR("Trying to load TIFF picture, but Wine was compiled without TIFF support.\n"); + return E_FAIL; +} + +#endif diff --git a/dlls/windowscodecs/wincodecs_private.h b/dlls/windowscodecs/wincodecs_private.h index 632f822..0e72793 100644 --- a/dlls/windowscodecs/wincodecs_private.h +++ b/dlls/windowscodecs/wincodecs_private.h @@ -28,6 +28,7 @@ extern HRESULT BmpEncoder_CreateInstance(IUnknown *pUnkOuter, REFIID iid, void** extern HRESULT GifDecoder_CreateInstance(IUnknown *pUnkOuter, REFIID riid, void** ppv); extern HRESULT IcoDecoder_CreateInstance(IUnknown *pUnkOuter, REFIID iid, void** ppv); extern HRESULT JpegDecoder_CreateInstance(IUnknown *pUnkOuter, REFIID iid, void** ppv); +extern HRESULT TiffDecoder_CreateInstance(IUnknown *pUnkOuter, REFIID iid, void** ppv); extern HRESULT PaletteImpl_Create(IWICPalette **palette); extern HRESULT StreamImpl_Create(IWICStream **stream); diff --git a/include/config.h.in b/include/config.h.in index 7feab81..789172a 100644 --- a/include/config.h.in +++ b/include/config.h.in @@ -1021,6 +1021,9 @@ /* Define to 1 if you have the `thr_kill2' function. */ #undef HAVE_THR_KILL2 +/* Define to 1 if you have the header file. */ +#undef HAVE_TIFFIO_H + /* Define to 1 if you have the `timegm' function. */ #undef HAVE_TIMEGM @@ -1216,6 +1219,9 @@ /* Define to the soname of the libssl library. */ #undef SONAME_LIBSSL +/* Define to the soname of the libtiff library. */ +#undef SONAME_LIBTIFF + /* Define to the soname of the libv4l1 library. */ #undef SONAME_LIBV4L1 -- 1.6.3.3