2010-03-09 00:07:29 +01:00
|
|
|
/*
|
|
|
|
* 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 <stdarg.h>
|
2010-03-17 21:44:28 +01:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
2010-03-09 00:07:29 +01:00
|
|
|
#ifdef HAVE_TIFFIO_H
|
|
|
|
#include <tiffio.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "objbase.h"
|
|
|
|
|
|
|
|
#include "wincodecs_private.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
#include "wine/library.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(wincodecs);
|
|
|
|
|
|
|
|
#ifdef SONAME_LIBTIFF
|
|
|
|
|
2013-08-01 15:04:28 +02:00
|
|
|
/* Workaround for broken libtiff 4.x headers on some 64-bit hosts which
|
|
|
|
* define TIFF_UINT64_T/toff_t as 32-bit for 32-bit builds, while they
|
|
|
|
* are supposed to be always 64-bit.
|
|
|
|
* TIFF_UINT64_T doesn't exist in libtiff 3.x, it was introduced in 4.x.
|
|
|
|
*/
|
|
|
|
#ifdef TIFF_UINT64_T
|
|
|
|
# undef toff_t
|
|
|
|
# define toff_t UINT64
|
|
|
|
#endif
|
|
|
|
|
2010-03-09 00:07:29 +01:00
|
|
|
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 };
|
|
|
|
|
2013-04-01 22:28:12 +02:00
|
|
|
static const WCHAR wszTiffCompressionMethod[] = {'T','i','f','f','C','o','m','p','r','e','s','s','i','o','n','M','e','t','h','o','d',0};
|
|
|
|
static const WCHAR wszCompressionQuality[] = {'C','o','m','p','r','e','s','s','i','o','n','Q','u','a','l','i','t','y',0};
|
|
|
|
|
2010-03-09 00:07:29 +01:00
|
|
|
static void *libtiff_handle;
|
|
|
|
#define MAKE_FUNCPTR(f) static typeof(f) * p##f
|
|
|
|
MAKE_FUNCPTR(TIFFClientOpen);
|
2010-03-17 21:44:28 +01:00
|
|
|
MAKE_FUNCPTR(TIFFClose);
|
2012-06-19 04:40:10 +02:00
|
|
|
MAKE_FUNCPTR(TIFFCurrentDirOffset);
|
2010-03-17 22:25:12 +01:00
|
|
|
MAKE_FUNCPTR(TIFFGetField);
|
2010-05-29 17:43:30 +02:00
|
|
|
MAKE_FUNCPTR(TIFFIsByteSwapped);
|
2012-06-19 04:40:10 +02:00
|
|
|
MAKE_FUNCPTR(TIFFNumberOfDirectories);
|
2010-03-17 22:00:33 +01:00
|
|
|
MAKE_FUNCPTR(TIFFReadDirectory);
|
2010-03-19 22:35:07 +01:00
|
|
|
MAKE_FUNCPTR(TIFFReadEncodedStrip);
|
2011-03-25 21:59:41 +01:00
|
|
|
MAKE_FUNCPTR(TIFFReadEncodedTile);
|
2010-03-17 22:25:12 +01:00
|
|
|
MAKE_FUNCPTR(TIFFSetDirectory);
|
2011-04-05 22:55:16 +02:00
|
|
|
MAKE_FUNCPTR(TIFFSetField);
|
2011-03-29 23:24:19 +02:00
|
|
|
MAKE_FUNCPTR(TIFFWriteDirectory);
|
2011-04-05 22:55:16 +02:00
|
|
|
MAKE_FUNCPTR(TIFFWriteScanline);
|
2010-03-09 00:07:29 +01:00
|
|
|
#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)
|
|
|
|
{
|
2012-07-02 11:19:18 +02:00
|
|
|
void * (*pTIFFSetWarningHandler)(void *);
|
|
|
|
void * (*pTIFFSetWarningHandlerExt)(void *);
|
2010-03-09 00:07:29 +01:00
|
|
|
|
|
|
|
#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);
|
2010-03-17 21:44:28 +01:00
|
|
|
LOAD_FUNCPTR(TIFFClose);
|
2012-06-19 04:40:10 +02:00
|
|
|
LOAD_FUNCPTR(TIFFCurrentDirOffset);
|
2010-03-17 22:25:12 +01:00
|
|
|
LOAD_FUNCPTR(TIFFGetField);
|
2010-05-29 17:43:30 +02:00
|
|
|
LOAD_FUNCPTR(TIFFIsByteSwapped);
|
2012-06-19 04:40:10 +02:00
|
|
|
LOAD_FUNCPTR(TIFFNumberOfDirectories);
|
2010-03-17 22:00:33 +01:00
|
|
|
LOAD_FUNCPTR(TIFFReadDirectory);
|
2010-03-19 22:35:07 +01:00
|
|
|
LOAD_FUNCPTR(TIFFReadEncodedStrip);
|
2011-03-25 21:59:41 +01:00
|
|
|
LOAD_FUNCPTR(TIFFReadEncodedTile);
|
2010-03-17 22:25:12 +01:00
|
|
|
LOAD_FUNCPTR(TIFFSetDirectory);
|
2011-04-05 22:55:16 +02:00
|
|
|
LOAD_FUNCPTR(TIFFSetField);
|
2011-03-29 23:24:19 +02:00
|
|
|
LOAD_FUNCPTR(TIFFWriteDirectory);
|
2011-04-05 22:55:16 +02:00
|
|
|
LOAD_FUNCPTR(TIFFWriteScanline);
|
2010-03-09 00:07:29 +01:00
|
|
|
#undef LOAD_FUNCPTR
|
|
|
|
|
2012-07-02 11:19:18 +02:00
|
|
|
if ((pTIFFSetWarningHandler = wine_dlsym(libtiff_handle, "TIFFSetWarningHandler", NULL, 0)))
|
|
|
|
pTIFFSetWarningHandler(NULL);
|
|
|
|
if ((pTIFFSetWarningHandlerExt = wine_dlsym(libtiff_handle, "TIFFSetWarningHandlerExt", NULL, 0)))
|
|
|
|
pTIFFSetWarningHandlerExt(NULL);
|
2010-03-09 00:07:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
result = libtiff_handle;
|
|
|
|
|
|
|
|
LeaveCriticalSection(&init_tiff_cs);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-03-17 21:44:28 +01:00
|
|
|
static tsize_t tiff_stream_read(thandle_t client_data, tdata_t data, tsize_t size)
|
|
|
|
{
|
|
|
|
IStream *stream = (IStream*)client_data;
|
|
|
|
ULONG bytes_read;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = IStream_Read(stream, data, size, &bytes_read);
|
|
|
|
if (FAILED(hr)) bytes_read = 0;
|
|
|
|
return bytes_read;
|
|
|
|
}
|
|
|
|
|
|
|
|
static tsize_t tiff_stream_write(thandle_t client_data, tdata_t data, tsize_t size)
|
|
|
|
{
|
|
|
|
IStream *stream = (IStream*)client_data;
|
|
|
|
ULONG bytes_written;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = IStream_Write(stream, data, size, &bytes_written);
|
|
|
|
if (FAILED(hr)) bytes_written = 0;
|
|
|
|
return bytes_written;
|
|
|
|
}
|
|
|
|
|
|
|
|
static toff_t tiff_stream_seek(thandle_t client_data, toff_t offset, int whence)
|
|
|
|
{
|
|
|
|
IStream *stream = (IStream*)client_data;
|
|
|
|
LARGE_INTEGER move;
|
|
|
|
DWORD origin;
|
|
|
|
ULARGE_INTEGER new_position;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
move.QuadPart = offset;
|
|
|
|
switch (whence)
|
|
|
|
{
|
|
|
|
case SEEK_SET:
|
|
|
|
origin = STREAM_SEEK_SET;
|
|
|
|
break;
|
|
|
|
case SEEK_CUR:
|
|
|
|
origin = STREAM_SEEK_CUR;
|
|
|
|
break;
|
|
|
|
case SEEK_END:
|
|
|
|
origin = STREAM_SEEK_END;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERR("unknown whence value %i\n", whence);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IStream_Seek(stream, move, origin, &new_position);
|
|
|
|
if (SUCCEEDED(hr)) return new_position.QuadPart;
|
|
|
|
else return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int tiff_stream_close(thandle_t client_data)
|
|
|
|
{
|
|
|
|
/* Caller is responsible for releasing the stream object. */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static toff_t tiff_stream_size(thandle_t client_data)
|
|
|
|
{
|
|
|
|
IStream *stream = (IStream*)client_data;
|
|
|
|
STATSTG statstg;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = IStream_Stat(stream, &statstg, STATFLAG_NONAME);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr)) return statstg.cbSize.QuadPart;
|
|
|
|
else return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int tiff_stream_map(thandle_t client_data, tdata_t *addr, toff_t *size)
|
|
|
|
{
|
|
|
|
/* Cannot mmap streams */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tiff_stream_unmap(thandle_t client_data, tdata_t addr, toff_t size)
|
|
|
|
{
|
|
|
|
/* No need to ever do this, since we can't map things. */
|
|
|
|
}
|
|
|
|
|
|
|
|
static TIFF* tiff_open_stream(IStream *stream, const char *mode)
|
|
|
|
{
|
2010-10-20 19:54:08 +02:00
|
|
|
LARGE_INTEGER zero;
|
|
|
|
|
|
|
|
zero.QuadPart = 0;
|
|
|
|
IStream_Seek(stream, zero, STREAM_SEEK_SET, NULL);
|
|
|
|
|
2010-03-17 21:44:28 +01:00
|
|
|
return pTIFFClientOpen("<IStream object>", mode, stream, tiff_stream_read,
|
2013-08-01 15:04:28 +02:00
|
|
|
tiff_stream_write, (void *)tiff_stream_seek, tiff_stream_close,
|
|
|
|
(void *)tiff_stream_size, (void *)tiff_stream_map, (void *)tiff_stream_unmap);
|
2010-03-17 21:44:28 +01:00
|
|
|
}
|
|
|
|
|
2010-03-09 00:07:29 +01:00
|
|
|
typedef struct {
|
2010-11-29 00:58:20 +01:00
|
|
|
IWICBitmapDecoder IWICBitmapDecoder_iface;
|
2010-03-09 00:07:29 +01:00
|
|
|
LONG ref;
|
2010-03-17 21:44:28 +01:00
|
|
|
IStream *stream;
|
2015-08-17 15:11:55 +02:00
|
|
|
CRITICAL_SECTION lock; /* Must be held when tiff is used or initialized is set */
|
2010-03-17 21:44:28 +01:00
|
|
|
TIFF *tiff;
|
|
|
|
BOOL initialized;
|
2010-03-09 00:07:29 +01:00
|
|
|
} TiffDecoder;
|
|
|
|
|
2010-03-17 22:25:12 +01:00
|
|
|
typedef struct {
|
|
|
|
const WICPixelFormatGUID *format;
|
2010-05-29 17:43:30 +02:00
|
|
|
int bps;
|
|
|
|
int samples;
|
2015-07-13 08:46:41 +02:00
|
|
|
int bpp, source_bpp;
|
2010-05-29 17:58:05 +02:00
|
|
|
int planar;
|
2010-03-17 22:25:12 +01:00
|
|
|
int indexed;
|
|
|
|
int reverse_bgr;
|
2010-05-29 18:27:31 +02:00
|
|
|
int invert_grayscale;
|
2010-03-19 21:27:51 +01:00
|
|
|
UINT width, height;
|
2010-03-19 22:35:07 +01:00
|
|
|
UINT tile_width, tile_height;
|
|
|
|
UINT tile_stride;
|
|
|
|
UINT tile_size;
|
2011-03-25 21:59:41 +01:00
|
|
|
int tiled;
|
|
|
|
UINT tiles_across;
|
2011-04-05 23:42:44 +02:00
|
|
|
UINT resolution_unit;
|
|
|
|
float xres, yres;
|
2010-03-17 22:25:12 +01:00
|
|
|
} tiff_decode_info;
|
|
|
|
|
|
|
|
typedef struct {
|
2010-11-29 00:58:20 +01:00
|
|
|
IWICBitmapFrameDecode IWICBitmapFrameDecode_iface;
|
2012-06-06 11:44:11 +02:00
|
|
|
IWICMetadataBlockReader IWICMetadataBlockReader_iface;
|
2010-03-17 22:25:12 +01:00
|
|
|
LONG ref;
|
|
|
|
TiffDecoder *parent;
|
|
|
|
UINT index;
|
|
|
|
tiff_decode_info decode_info;
|
2010-03-19 22:35:07 +01:00
|
|
|
INT cached_tile_x, cached_tile_y;
|
|
|
|
BYTE *cached_tile;
|
2010-03-17 22:25:12 +01:00
|
|
|
} TiffFrameDecode;
|
|
|
|
|
|
|
|
static const IWICBitmapFrameDecodeVtbl TiffFrameDecode_Vtbl;
|
2012-06-06 11:44:11 +02:00
|
|
|
static const IWICMetadataBlockReaderVtbl TiffFrameDecode_BlockVtbl;
|
2010-03-17 22:25:12 +01:00
|
|
|
|
2010-11-29 00:58:20 +01:00
|
|
|
static inline TiffDecoder *impl_from_IWICBitmapDecoder(IWICBitmapDecoder *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, TiffDecoder, IWICBitmapDecoder_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline TiffFrameDecode *impl_from_IWICBitmapFrameDecode(IWICBitmapFrameDecode *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, TiffFrameDecode, IWICBitmapFrameDecode_iface);
|
|
|
|
}
|
|
|
|
|
2012-06-06 11:44:11 +02:00
|
|
|
static inline TiffFrameDecode *impl_from_IWICMetadataBlockReader(IWICMetadataBlockReader *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, TiffFrameDecode, IWICMetadataBlockReader_iface);
|
|
|
|
}
|
|
|
|
|
2010-03-17 22:25:12 +01:00
|
|
|
static HRESULT tiff_get_decode_info(TIFF *tiff, tiff_decode_info *decode_info)
|
|
|
|
{
|
2010-05-29 17:58:05 +02:00
|
|
|
uint16 photometric, bps, samples, planar;
|
2011-04-25 11:02:48 +02:00
|
|
|
uint16 extra_sample_count, extra_sample, *extra_samples;
|
2010-03-17 22:25:12 +01:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
decode_info->indexed = 0;
|
|
|
|
decode_info->reverse_bgr = 0;
|
2010-05-29 18:27:31 +02:00
|
|
|
decode_info->invert_grayscale = 0;
|
2011-03-25 21:59:41 +01:00
|
|
|
decode_info->tiled = 0;
|
2010-03-17 22:25:12 +01:00
|
|
|
|
|
|
|
ret = pTIFFGetField(tiff, TIFFTAG_PHOTOMETRIC, &photometric);
|
|
|
|
if (!ret)
|
|
|
|
{
|
|
|
|
WARN("missing PhotometricInterpretation tag\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = pTIFFGetField(tiff, TIFFTAG_BITSPERSAMPLE, &bps);
|
|
|
|
if (!ret) bps = 1;
|
2010-05-29 17:43:30 +02:00
|
|
|
decode_info->bps = bps;
|
|
|
|
|
2010-05-29 17:58:05 +02:00
|
|
|
ret = pTIFFGetField(tiff, TIFFTAG_SAMPLESPERPIXEL, &samples);
|
|
|
|
if (!ret) samples = 1;
|
|
|
|
decode_info->samples = samples;
|
|
|
|
|
|
|
|
if (samples == 1)
|
|
|
|
planar = 1;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = pTIFFGetField(tiff, TIFFTAG_PLANARCONFIG, &planar);
|
|
|
|
if (!ret) planar = 1;
|
|
|
|
if (planar != 1)
|
|
|
|
{
|
|
|
|
FIXME("unhandled planar configuration %u\n", planar);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
decode_info->planar = planar;
|
|
|
|
|
2010-03-17 22:25:12 +01:00
|
|
|
switch(photometric)
|
|
|
|
{
|
2010-05-29 18:27:31 +02:00
|
|
|
case 0: /* WhiteIsZero */
|
|
|
|
decode_info->invert_grayscale = 1;
|
2011-10-10 23:47:15 +02:00
|
|
|
/* fall through */
|
2010-03-17 22:25:12 +01:00
|
|
|
case 1: /* BlackIsZero */
|
2015-07-13 08:46:41 +02:00
|
|
|
if (samples == 2)
|
|
|
|
{
|
|
|
|
ret = pTIFFGetField(tiff, TIFFTAG_EXTRASAMPLES, &extra_sample_count, &extra_samples);
|
|
|
|
if (!ret)
|
|
|
|
{
|
|
|
|
extra_sample_count = 1;
|
|
|
|
extra_sample = 0;
|
|
|
|
extra_samples = &extra_sample;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (samples != 1)
|
2010-05-29 17:58:05 +02:00
|
|
|
{
|
2015-07-13 08:46:41 +02:00
|
|
|
FIXME("unhandled %dbpp sample count %u\n", bps, samples);
|
2010-05-29 17:58:05 +02:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2015-07-13 08:46:41 +02:00
|
|
|
decode_info->bpp = bps * samples;
|
|
|
|
decode_info->source_bpp = decode_info->bpp;
|
2010-03-17 22:25:12 +01:00
|
|
|
switch (bps)
|
|
|
|
{
|
|
|
|
case 1:
|
2015-07-13 08:46:41 +02:00
|
|
|
if (samples != 1)
|
|
|
|
{
|
|
|
|
FIXME("unhandled 1bpp sample count %u\n", samples);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
2010-03-17 22:25:12 +01:00
|
|
|
decode_info->format = &GUID_WICPixelFormatBlackWhite;
|
|
|
|
break;
|
|
|
|
case 4:
|
2015-07-13 08:46:41 +02:00
|
|
|
if (samples != 1)
|
|
|
|
{
|
|
|
|
FIXME("unhandled 4bpp grayscale sample count %u\n", samples);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
2010-03-17 22:25:12 +01:00
|
|
|
decode_info->format = &GUID_WICPixelFormat4bppGray;
|
|
|
|
break;
|
|
|
|
case 8:
|
2015-07-13 08:46:41 +02:00
|
|
|
if (samples == 1)
|
|
|
|
decode_info->format = &GUID_WICPixelFormat8bppGray;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
decode_info->bpp = 32;
|
|
|
|
|
|
|
|
switch(extra_samples[0])
|
|
|
|
{
|
|
|
|
case 1: /* Associated (pre-multiplied) alpha data */
|
|
|
|
decode_info->format = &GUID_WICPixelFormat32bppPBGRA;
|
|
|
|
break;
|
|
|
|
case 0: /* Unspecified data */
|
|
|
|
case 2: /* Unassociated alpha data */
|
|
|
|
decode_info->format = &GUID_WICPixelFormat32bppBGRA;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FIXME("unhandled extra sample type %u\n", extra_samples[0]);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
}
|
2010-03-17 22:25:12 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FIXME("unhandled greyscale bit count %u\n", bps);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
break;
|
2010-03-19 23:11:50 +01:00
|
|
|
case 2: /* RGB */
|
2010-05-29 17:58:05 +02:00
|
|
|
decode_info->bpp = bps * samples;
|
|
|
|
|
2010-05-29 19:32:32 +02:00
|
|
|
if (samples == 4)
|
|
|
|
{
|
|
|
|
ret = pTIFFGetField(tiff, TIFFTAG_EXTRASAMPLES, &extra_sample_count, &extra_samples);
|
|
|
|
if (!ret)
|
|
|
|
{
|
2011-04-25 11:02:48 +02:00
|
|
|
extra_sample_count = 1;
|
|
|
|
extra_sample = 0;
|
|
|
|
extra_samples = &extra_sample;
|
2010-05-29 19:32:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (samples != 3)
|
2010-03-19 23:11:50 +01:00
|
|
|
{
|
|
|
|
FIXME("unhandled RGB sample count %u\n", samples);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
2010-05-29 17:43:02 +02:00
|
|
|
|
|
|
|
switch(bps)
|
2010-03-19 23:11:50 +01:00
|
|
|
{
|
2010-05-29 17:43:02 +02:00
|
|
|
case 8:
|
|
|
|
decode_info->reverse_bgr = 1;
|
2010-05-29 19:32:32 +02:00
|
|
|
if (samples == 3)
|
|
|
|
decode_info->format = &GUID_WICPixelFormat24bppBGR;
|
|
|
|
else
|
|
|
|
switch(extra_samples[0])
|
|
|
|
{
|
|
|
|
case 1: /* Associated (pre-multiplied) alpha data */
|
|
|
|
decode_info->format = &GUID_WICPixelFormat32bppPBGRA;
|
|
|
|
break;
|
2011-06-14 21:30:26 +02:00
|
|
|
case 0: /* Unspecified data */
|
2010-05-29 19:32:32 +02:00
|
|
|
case 2: /* Unassociated alpha data */
|
|
|
|
decode_info->format = &GUID_WICPixelFormat32bppBGRA;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FIXME("unhandled extra sample type %i\n", extra_samples[0]);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
2010-05-29 17:43:02 +02:00
|
|
|
break;
|
|
|
|
case 16:
|
2010-05-29 19:32:32 +02:00
|
|
|
if (samples == 3)
|
|
|
|
decode_info->format = &GUID_WICPixelFormat48bppRGB;
|
|
|
|
else
|
|
|
|
switch(extra_samples[0])
|
|
|
|
{
|
|
|
|
case 1: /* Associated (pre-multiplied) alpha data */
|
|
|
|
decode_info->format = &GUID_WICPixelFormat64bppPRGBA;
|
|
|
|
break;
|
2011-06-14 21:30:26 +02:00
|
|
|
case 0: /* Unspecified data */
|
2010-05-29 19:32:32 +02:00
|
|
|
case 2: /* Unassociated alpha data */
|
|
|
|
decode_info->format = &GUID_WICPixelFormat64bppRGBA;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FIXME("unhandled extra sample type %i\n", extra_samples[0]);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
2010-05-29 17:43:02 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FIXME("unhandled RGB bit count %u\n", bps);
|
2010-03-19 23:11:50 +01:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
break;
|
2010-03-17 22:25:12 +01:00
|
|
|
case 3: /* RGB Palette */
|
2010-05-29 17:58:05 +02:00
|
|
|
if (samples != 1)
|
|
|
|
{
|
|
|
|
FIXME("unhandled indexed sample count %u\n", samples);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2010-03-17 22:25:12 +01:00
|
|
|
decode_info->indexed = 1;
|
|
|
|
decode_info->bpp = bps;
|
|
|
|
switch (bps)
|
|
|
|
{
|
|
|
|
case 4:
|
|
|
|
decode_info->format = &GUID_WICPixelFormat4bppIndexed;
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
decode_info->format = &GUID_WICPixelFormat8bppIndexed;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FIXME("unhandled indexed bit count %u\n", bps);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 4: /* Transparency mask */
|
|
|
|
case 5: /* CMYK */
|
|
|
|
case 6: /* YCbCr */
|
|
|
|
case 8: /* CIELab */
|
|
|
|
default:
|
|
|
|
FIXME("unhandled PhotometricInterpretation %u\n", photometric);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2010-03-19 21:27:51 +01:00
|
|
|
ret = pTIFFGetField(tiff, TIFFTAG_IMAGEWIDTH, &decode_info->width);
|
|
|
|
if (!ret)
|
|
|
|
{
|
|
|
|
WARN("missing image width\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = pTIFFGetField(tiff, TIFFTAG_IMAGELENGTH, &decode_info->height);
|
|
|
|
if (!ret)
|
|
|
|
{
|
|
|
|
WARN("missing image length\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2011-03-25 21:59:41 +01:00
|
|
|
if ((ret = pTIFFGetField(tiff, TIFFTAG_TILEWIDTH, &decode_info->tile_width)))
|
|
|
|
{
|
|
|
|
decode_info->tiled = 1;
|
|
|
|
|
|
|
|
ret = pTIFFGetField(tiff, TIFFTAG_TILELENGTH, &decode_info->tile_height);
|
|
|
|
if (!ret)
|
|
|
|
{
|
|
|
|
WARN("missing tile height\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
decode_info->tile_stride = ((decode_info->bpp * decode_info->tile_width + 7)/8);
|
|
|
|
decode_info->tile_size = decode_info->tile_height * decode_info->tile_stride;
|
|
|
|
decode_info->tiles_across = (decode_info->width + decode_info->tile_width - 1) / decode_info->tile_width;
|
|
|
|
}
|
|
|
|
else if ((ret = pTIFFGetField(tiff, TIFFTAG_ROWSPERSTRIP, &decode_info->tile_height)))
|
2010-03-19 22:35:07 +01:00
|
|
|
{
|
2010-05-29 18:47:49 +02:00
|
|
|
if (decode_info->tile_height > decode_info->height)
|
|
|
|
decode_info->tile_height = decode_info->height;
|
2010-03-19 22:35:07 +01:00
|
|
|
decode_info->tile_width = decode_info->width;
|
|
|
|
decode_info->tile_stride = ((decode_info->bpp * decode_info->tile_width + 7)/8);
|
|
|
|
decode_info->tile_size = decode_info->tile_height * decode_info->tile_stride;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-04-21 08:17:07 +02:00
|
|
|
/* Some broken TIFF files have a single strip and lack the RowsPerStrip tag */
|
|
|
|
decode_info->tile_height = decode_info->height;
|
|
|
|
decode_info->tile_width = decode_info->width;
|
|
|
|
decode_info->tile_stride = ((decode_info->bpp * decode_info->tile_width + 7)/8);
|
|
|
|
decode_info->tile_size = decode_info->tile_height * decode_info->tile_stride;
|
2010-03-19 22:35:07 +01:00
|
|
|
}
|
|
|
|
|
2011-04-05 23:42:44 +02:00
|
|
|
decode_info->resolution_unit = 0;
|
|
|
|
pTIFFGetField(tiff, TIFFTAG_RESOLUTIONUNIT, &decode_info->resolution_unit);
|
2018-02-05 20:34:59 +01:00
|
|
|
|
|
|
|
ret = pTIFFGetField(tiff, TIFFTAG_XRESOLUTION, &decode_info->xres);
|
|
|
|
if (!ret)
|
2011-04-05 23:42:44 +02:00
|
|
|
{
|
2018-02-05 20:34:59 +01:00
|
|
|
WARN("missing X resolution\n");
|
|
|
|
}
|
|
|
|
/* Emulate the behavior of current libtiff versions (libtiff commit a39f6131)
|
|
|
|
* yielding 0 instead of INFINITY for IFD_RATIONAL fields with denominator 0. */
|
|
|
|
if (!isfinite(decode_info->xres))
|
|
|
|
{
|
|
|
|
decode_info->xres = 0.0;
|
|
|
|
}
|
2011-04-05 23:42:44 +02:00
|
|
|
|
2018-02-05 20:34:59 +01:00
|
|
|
ret = pTIFFGetField(tiff, TIFFTAG_YRESOLUTION, &decode_info->yres);
|
|
|
|
if (!ret)
|
|
|
|
{
|
|
|
|
WARN("missing Y resolution\n");
|
|
|
|
}
|
|
|
|
if (!isfinite(decode_info->yres))
|
|
|
|
{
|
|
|
|
decode_info->yres = 0.0;
|
2011-04-05 23:42:44 +02:00
|
|
|
}
|
|
|
|
|
2010-03-17 22:25:12 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2010-03-09 00:07:29 +01:00
|
|
|
static HRESULT WINAPI TiffDecoder_QueryInterface(IWICBitmapDecoder *iface, REFIID iid,
|
|
|
|
void **ppv)
|
|
|
|
{
|
2010-11-29 00:58:20 +01:00
|
|
|
TiffDecoder *This = impl_from_IWICBitmapDecoder(iface);
|
2010-03-09 00:07:29 +01:00
|
|
|
TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
|
|
|
|
|
|
|
|
if (!ppv) return E_INVALIDARG;
|
|
|
|
|
2012-07-24 08:18:16 +02:00
|
|
|
if (IsEqualIID(&IID_IUnknown, iid) ||
|
|
|
|
IsEqualIID(&IID_IWICBitmapDecoder, iid))
|
2010-03-09 00:07:29 +01:00
|
|
|
{
|
2012-07-24 08:18:16 +02:00
|
|
|
*ppv = &This->IWICBitmapDecoder_iface;
|
2010-03-09 00:07:29 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*ppv = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
IUnknown_AddRef((IUnknown*)*ppv);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI TiffDecoder_AddRef(IWICBitmapDecoder *iface)
|
|
|
|
{
|
2010-11-29 00:58:20 +01:00
|
|
|
TiffDecoder *This = impl_from_IWICBitmapDecoder(iface);
|
2010-03-09 00:07:29 +01:00
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p) refcount=%u\n", iface, ref);
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI TiffDecoder_Release(IWICBitmapDecoder *iface)
|
|
|
|
{
|
2010-11-29 00:58:20 +01:00
|
|
|
TiffDecoder *This = impl_from_IWICBitmapDecoder(iface);
|
2010-03-09 00:07:29 +01:00
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p) refcount=%u\n", iface, ref);
|
|
|
|
|
|
|
|
if (ref == 0)
|
|
|
|
{
|
2010-03-17 21:44:28 +01:00
|
|
|
if (This->tiff) pTIFFClose(This->tiff);
|
|
|
|
if (This->stream) IStream_Release(This->stream);
|
|
|
|
This->lock.DebugInfo->Spare[0] = 0;
|
|
|
|
DeleteCriticalSection(&This->lock);
|
2010-03-09 00:07:29 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
2012-11-21 10:12:47 +01:00
|
|
|
static HRESULT WINAPI TiffDecoder_QueryCapability(IWICBitmapDecoder *iface, IStream *stream,
|
|
|
|
DWORD *capability)
|
2010-03-09 00:07:29 +01:00
|
|
|
{
|
2012-11-21 10:12:47 +01:00
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("(%p,%p,%p)\n", iface, stream, capability);
|
|
|
|
|
|
|
|
if (!stream || !capability) return E_INVALIDARG;
|
|
|
|
|
|
|
|
hr = IWICBitmapDecoder_Initialize(iface, stream, WICDecodeMetadataCacheOnDemand);
|
|
|
|
if (hr != S_OK) return hr;
|
|
|
|
|
|
|
|
*capability = WICBitmapDecoderCapabilityCanDecodeAllImages |
|
|
|
|
WICBitmapDecoderCapabilityCanDecodeSomeImages |
|
|
|
|
WICBitmapDecoderCapabilityCanEnumerateMetadata;
|
|
|
|
return S_OK;
|
2010-03-09 00:07:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI TiffDecoder_Initialize(IWICBitmapDecoder *iface, IStream *pIStream,
|
|
|
|
WICDecodeOptions cacheOptions)
|
|
|
|
{
|
2010-11-29 00:58:20 +01:00
|
|
|
TiffDecoder *This = impl_from_IWICBitmapDecoder(iface);
|
2010-03-17 21:44:28 +01:00
|
|
|
TIFF *tiff;
|
|
|
|
HRESULT hr=S_OK;
|
|
|
|
|
2016-10-25 07:18:40 +02:00
|
|
|
TRACE("(%p,%p,%x)\n", iface, pIStream, cacheOptions);
|
2010-03-17 21:44:28 +01:00
|
|
|
|
|
|
|
EnterCriticalSection(&This->lock);
|
|
|
|
|
|
|
|
if (This->initialized)
|
|
|
|
{
|
|
|
|
hr = WINCODEC_ERR_WRONGSTATE;
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
tiff = tiff_open_stream(pIStream, "r");
|
|
|
|
|
|
|
|
if (!tiff)
|
|
|
|
{
|
|
|
|
hr = E_FAIL;
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
This->tiff = tiff;
|
|
|
|
This->stream = pIStream;
|
|
|
|
IStream_AddRef(pIStream);
|
|
|
|
This->initialized = TRUE;
|
|
|
|
|
|
|
|
exit:
|
|
|
|
LeaveCriticalSection(&This->lock);
|
|
|
|
return hr;
|
2010-03-09 00:07:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI TiffDecoder_GetContainerFormat(IWICBitmapDecoder *iface,
|
|
|
|
GUID *pguidContainerFormat)
|
|
|
|
{
|
2012-09-12 08:10:26 +02:00
|
|
|
if (!pguidContainerFormat) return E_INVALIDARG;
|
|
|
|
|
2010-03-09 00:07:29 +01:00
|
|
|
memcpy(pguidContainerFormat, &GUID_ContainerFormatTiff, sizeof(GUID));
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI TiffDecoder_GetDecoderInfo(IWICBitmapDecoder *iface,
|
|
|
|
IWICBitmapDecoderInfo **ppIDecoderInfo)
|
|
|
|
{
|
2011-07-27 23:03:09 +02:00
|
|
|
HRESULT hr;
|
|
|
|
IWICComponentInfo *compinfo;
|
|
|
|
|
|
|
|
TRACE("(%p,%p)\n", iface, ppIDecoderInfo);
|
|
|
|
|
|
|
|
hr = CreateComponentInfo(&CLSID_WICTiffDecoder, &compinfo);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
hr = IWICComponentInfo_QueryInterface(compinfo, &IID_IWICBitmapDecoderInfo,
|
|
|
|
(void**)ppIDecoderInfo);
|
|
|
|
|
|
|
|
IWICComponentInfo_Release(compinfo);
|
|
|
|
|
|
|
|
return hr;
|
2010-03-09 00:07:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI TiffDecoder_CopyPalette(IWICBitmapDecoder *iface,
|
2017-09-13 22:12:40 +02:00
|
|
|
IWICPalette *palette)
|
2010-03-09 00:07:29 +01:00
|
|
|
{
|
2017-09-13 22:12:40 +02:00
|
|
|
TRACE("(%p,%p)\n", iface, palette);
|
|
|
|
return WINCODEC_ERR_PALETTEUNAVAILABLE;
|
2010-03-09 00:07:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2012-06-25 05:27:12 +02:00
|
|
|
TRACE("(%p,%p)\n", iface, ppIBitmapSource);
|
|
|
|
|
|
|
|
if (!ppIBitmapSource) return E_INVALIDARG;
|
|
|
|
|
|
|
|
*ppIBitmapSource = NULL;
|
|
|
|
return WINCODEC_ERR_UNSUPPORTEDOPERATION;
|
2010-03-09 00:07:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI TiffDecoder_GetColorContexts(IWICBitmapDecoder *iface,
|
|
|
|
UINT cCount, IWICColorContext **ppIColorContexts, UINT *pcActualCount)
|
|
|
|
{
|
|
|
|
FIXME("(%p,%u,%p,%p)\n", iface, cCount, ppIColorContexts, pcActualCount);
|
2012-09-25 23:34:59 +02:00
|
|
|
return WINCODEC_ERR_UNSUPPORTEDOPERATION;
|
2010-03-09 00:07:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI TiffDecoder_GetThumbnail(IWICBitmapDecoder *iface,
|
|
|
|
IWICBitmapSource **ppIThumbnail)
|
|
|
|
{
|
|
|
|
TRACE("(%p,%p)\n", iface, ppIThumbnail);
|
2012-06-25 05:26:56 +02:00
|
|
|
|
|
|
|
if (!ppIThumbnail) return E_INVALIDARG;
|
|
|
|
|
|
|
|
*ppIThumbnail = NULL;
|
2010-03-09 00:07:29 +01:00
|
|
|
return WINCODEC_ERR_CODECNOTHUMBNAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI TiffDecoder_GetFrameCount(IWICBitmapDecoder *iface,
|
|
|
|
UINT *pCount)
|
|
|
|
{
|
2010-11-29 00:58:20 +01:00
|
|
|
TiffDecoder *This = impl_from_IWICBitmapDecoder(iface);
|
2010-03-17 22:00:33 +01:00
|
|
|
|
2012-11-21 10:11:15 +01:00
|
|
|
if (!pCount) return E_INVALIDARG;
|
2010-03-17 22:00:33 +01:00
|
|
|
|
|
|
|
EnterCriticalSection(&This->lock);
|
2012-11-21 10:11:15 +01:00
|
|
|
*pCount = This->tiff ? pTIFFNumberOfDirectories(This->tiff) : 0;
|
2010-03-17 22:00:33 +01:00
|
|
|
LeaveCriticalSection(&This->lock);
|
|
|
|
|
|
|
|
TRACE("(%p) <-- %i\n", iface, *pCount);
|
|
|
|
|
|
|
|
return S_OK;
|
2010-03-09 00:07:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI TiffDecoder_GetFrame(IWICBitmapDecoder *iface,
|
|
|
|
UINT index, IWICBitmapFrameDecode **ppIBitmapFrame)
|
|
|
|
{
|
2010-11-29 00:58:20 +01:00
|
|
|
TiffDecoder *This = impl_from_IWICBitmapDecoder(iface);
|
2010-03-17 22:25:12 +01:00
|
|
|
TiffFrameDecode *result;
|
|
|
|
int res;
|
|
|
|
tiff_decode_info decode_info;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("(%p,%u,%p)\n", iface, index, ppIBitmapFrame);
|
|
|
|
|
|
|
|
if (!This->tiff)
|
2012-11-23 08:40:37 +01:00
|
|
|
return WINCODEC_ERR_FRAMEMISSING;
|
2010-03-17 22:25:12 +01:00
|
|
|
|
|
|
|
EnterCriticalSection(&This->lock);
|
|
|
|
res = pTIFFSetDirectory(This->tiff, index);
|
|
|
|
if (!res) hr = E_INVALIDARG;
|
|
|
|
else hr = tiff_get_decode_info(This->tiff, &decode_info);
|
|
|
|
LeaveCriticalSection(&This->lock);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
result = HeapAlloc(GetProcessHeap(), 0, sizeof(TiffFrameDecode));
|
|
|
|
|
|
|
|
if (result)
|
|
|
|
{
|
2010-11-29 00:58:20 +01:00
|
|
|
result->IWICBitmapFrameDecode_iface.lpVtbl = &TiffFrameDecode_Vtbl;
|
2012-06-06 11:44:11 +02:00
|
|
|
result->IWICMetadataBlockReader_iface.lpVtbl = &TiffFrameDecode_BlockVtbl;
|
2010-03-17 22:25:12 +01:00
|
|
|
result->ref = 1;
|
|
|
|
result->parent = This;
|
|
|
|
result->index = index;
|
|
|
|
result->decode_info = decode_info;
|
2010-03-19 22:35:07 +01:00
|
|
|
result->cached_tile_x = -1;
|
|
|
|
result->cached_tile = HeapAlloc(GetProcessHeap(), 0, decode_info.tile_size);
|
|
|
|
|
|
|
|
if (result->cached_tile)
|
2012-07-24 08:18:16 +02:00
|
|
|
*ppIBitmapFrame = &result->IWICBitmapFrameDecode_iface;
|
2010-03-19 22:35:07 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
hr = E_OUTOFMEMORY;
|
|
|
|
HeapFree(GetProcessHeap(), 0, result);
|
|
|
|
}
|
2010-03-17 22:25:12 +01:00
|
|
|
}
|
|
|
|
else hr = E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FAILED(hr)) *ppIBitmapFrame = NULL;
|
|
|
|
|
|
|
|
return hr;
|
2010-03-09 00:07:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
};
|
|
|
|
|
2010-03-17 22:25:12 +01:00
|
|
|
static HRESULT WINAPI TiffFrameDecode_QueryInterface(IWICBitmapFrameDecode *iface, REFIID iid,
|
|
|
|
void **ppv)
|
|
|
|
{
|
2010-11-29 00:58:20 +01:00
|
|
|
TiffFrameDecode *This = impl_from_IWICBitmapFrameDecode(iface);
|
2010-03-17 22:25:12 +01:00
|
|
|
TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
|
|
|
|
|
|
|
|
if (!ppv) return E_INVALIDARG;
|
|
|
|
|
|
|
|
if (IsEqualIID(&IID_IUnknown, iid) ||
|
|
|
|
IsEqualIID(&IID_IWICBitmapSource, iid) ||
|
|
|
|
IsEqualIID(&IID_IWICBitmapFrameDecode, iid))
|
|
|
|
{
|
2012-07-24 08:18:16 +02:00
|
|
|
*ppv = &This->IWICBitmapFrameDecode_iface;
|
2010-03-17 22:25:12 +01:00
|
|
|
}
|
2012-06-06 11:44:11 +02:00
|
|
|
else if (IsEqualIID(&IID_IWICMetadataBlockReader, iid))
|
|
|
|
{
|
|
|
|
*ppv = &This->IWICMetadataBlockReader_iface;
|
|
|
|
}
|
2010-03-17 22:25:12 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
*ppv = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
IUnknown_AddRef((IUnknown*)*ppv);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI TiffFrameDecode_AddRef(IWICBitmapFrameDecode *iface)
|
|
|
|
{
|
2010-11-29 00:58:20 +01:00
|
|
|
TiffFrameDecode *This = impl_from_IWICBitmapFrameDecode(iface);
|
2010-03-17 22:25:12 +01:00
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p) refcount=%u\n", iface, ref);
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI TiffFrameDecode_Release(IWICBitmapFrameDecode *iface)
|
|
|
|
{
|
2010-11-29 00:58:20 +01:00
|
|
|
TiffFrameDecode *This = impl_from_IWICBitmapFrameDecode(iface);
|
2010-03-17 22:25:12 +01:00
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p) refcount=%u\n", iface, ref);
|
|
|
|
|
|
|
|
if (ref == 0)
|
|
|
|
{
|
2010-03-19 22:35:07 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, This->cached_tile);
|
2010-03-17 22:25:12 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI TiffFrameDecode_GetSize(IWICBitmapFrameDecode *iface,
|
|
|
|
UINT *puiWidth, UINT *puiHeight)
|
|
|
|
{
|
2010-11-29 00:58:20 +01:00
|
|
|
TiffFrameDecode *This = impl_from_IWICBitmapFrameDecode(iface);
|
2010-03-19 21:27:51 +01:00
|
|
|
|
|
|
|
*puiWidth = This->decode_info.width;
|
|
|
|
*puiHeight = This->decode_info.height;
|
|
|
|
|
|
|
|
TRACE("(%p) <-- %ux%u\n", iface, *puiWidth, *puiHeight);
|
|
|
|
|
|
|
|
return S_OK;
|
2010-03-17 22:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI TiffFrameDecode_GetPixelFormat(IWICBitmapFrameDecode *iface,
|
|
|
|
WICPixelFormatGUID *pPixelFormat)
|
|
|
|
{
|
2010-11-29 00:58:20 +01:00
|
|
|
TiffFrameDecode *This = impl_from_IWICBitmapFrameDecode(iface);
|
2010-03-19 21:20:52 +01:00
|
|
|
|
|
|
|
memcpy(pPixelFormat, This->decode_info.format, sizeof(GUID));
|
|
|
|
|
|
|
|
TRACE("(%p) <-- %s\n", This, debugstr_guid(This->decode_info.format));
|
|
|
|
|
|
|
|
return S_OK;
|
2010-03-17 22:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI TiffFrameDecode_GetResolution(IWICBitmapFrameDecode *iface,
|
|
|
|
double *pDpiX, double *pDpiY)
|
|
|
|
{
|
2011-04-05 23:42:44 +02:00
|
|
|
TiffFrameDecode *This = impl_from_IWICBitmapFrameDecode(iface);
|
|
|
|
|
2018-02-05 20:34:59 +01:00
|
|
|
if (This->decode_info.xres == 0 || This->decode_info.yres == 0)
|
2011-04-05 23:42:44 +02:00
|
|
|
{
|
|
|
|
*pDpiX = *pDpiY = 96.0;
|
2018-02-05 20:34:59 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (This->decode_info.resolution_unit)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
FIXME("unknown resolution unit %i\n", This->decode_info.resolution_unit);
|
|
|
|
/* fall through */
|
|
|
|
case 0: /* Not set */
|
|
|
|
case 1: /* Relative measurements */
|
|
|
|
case 2: /* Inch */
|
|
|
|
*pDpiX = This->decode_info.xres;
|
|
|
|
*pDpiY = This->decode_info.yres;
|
|
|
|
break;
|
|
|
|
case 3: /* Centimeter */
|
|
|
|
*pDpiX = This->decode_info.xres * 2.54;
|
|
|
|
*pDpiY = This->decode_info.yres * 2.54;
|
|
|
|
break;
|
|
|
|
}
|
2011-04-05 23:42:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("(%p) <-- %f,%f unit=%i\n", iface, *pDpiX, *pDpiY, This->decode_info.resolution_unit);
|
|
|
|
|
|
|
|
return S_OK;
|
2010-03-17 22:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI TiffFrameDecode_CopyPalette(IWICBitmapFrameDecode *iface,
|
|
|
|
IWICPalette *pIPalette)
|
|
|
|
{
|
2010-11-29 00:58:20 +01:00
|
|
|
TiffFrameDecode *This = impl_from_IWICBitmapFrameDecode(iface);
|
2010-05-29 19:09:56 +02:00
|
|
|
uint16 *red, *green, *blue;
|
|
|
|
WICColor colors[256];
|
|
|
|
int color_count, ret, i;
|
|
|
|
|
|
|
|
TRACE("(%p,%p)\n", iface, pIPalette);
|
|
|
|
|
|
|
|
color_count = 1<<This->decode_info.bps;
|
|
|
|
|
|
|
|
EnterCriticalSection(&This->parent->lock);
|
|
|
|
ret = pTIFFGetField(This->parent->tiff, TIFFTAG_COLORMAP, &red, &green, &blue);
|
|
|
|
LeaveCriticalSection(&This->parent->lock);
|
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
{
|
|
|
|
WARN("Couldn't read color map\n");
|
2012-07-12 12:13:22 +02:00
|
|
|
return WINCODEC_ERR_PALETTEUNAVAILABLE;
|
2010-05-29 19:09:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i=0; i<color_count; i++)
|
|
|
|
{
|
|
|
|
colors[i] = 0xff000000 |
|
|
|
|
((red[i]<<8) & 0xff0000) |
|
|
|
|
(green[i] & 0xff00) |
|
|
|
|
((blue[i]>>8) & 0xff);
|
|
|
|
}
|
|
|
|
|
|
|
|
return IWICPalette_InitializeCustom(pIPalette, colors, color_count);
|
2010-03-17 22:25:12 +01:00
|
|
|
}
|
|
|
|
|
2010-03-19 22:35:07 +01:00
|
|
|
static HRESULT TiffFrameDecode_ReadTile(TiffFrameDecode *This, UINT tile_x, UINT tile_y)
|
|
|
|
{
|
|
|
|
HRESULT hr=S_OK;
|
|
|
|
tsize_t ret;
|
2010-05-29 17:43:30 +02:00
|
|
|
int swap_bytes;
|
|
|
|
|
|
|
|
swap_bytes = pTIFFIsByteSwapped(This->parent->tiff);
|
2010-03-19 22:35:07 +01:00
|
|
|
|
|
|
|
ret = pTIFFSetDirectory(This->parent->tiff, This->index);
|
|
|
|
|
|
|
|
if (ret == -1)
|
|
|
|
hr = E_FAIL;
|
|
|
|
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
2011-03-25 21:59:41 +01:00
|
|
|
if (This->decode_info.tiled)
|
|
|
|
{
|
|
|
|
ret = pTIFFReadEncodedTile(This->parent->tiff, tile_x + tile_y * This->decode_info.tiles_across, This->cached_tile, This->decode_info.tile_size);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = pTIFFReadEncodedStrip(This->parent->tiff, tile_y, This->cached_tile, This->decode_info.tile_size);
|
|
|
|
}
|
2010-03-19 22:35:07 +01:00
|
|
|
|
|
|
|
if (ret == -1)
|
|
|
|
hr = E_FAIL;
|
|
|
|
}
|
|
|
|
|
2015-07-13 08:46:41 +02:00
|
|
|
/* 8bpp grayscale with extra alpha */
|
|
|
|
if (hr == S_OK && This->decode_info.source_bpp == 16 && This->decode_info.samples == 2 && This->decode_info.bpp == 32)
|
|
|
|
{
|
|
|
|
BYTE *src;
|
|
|
|
DWORD *dst, count = This->decode_info.tile_width * This->decode_info.tile_height;
|
|
|
|
|
|
|
|
src = This->cached_tile + This->decode_info.tile_width * This->decode_info.tile_height * 2 - 2;
|
|
|
|
dst = (DWORD *)(This->cached_tile + This->decode_info.tile_size - 4);
|
|
|
|
|
|
|
|
while (count--)
|
|
|
|
{
|
|
|
|
*dst-- = src[0] | (src[0] << 8) | (src[0] << 16) | (src[1] << 24);
|
|
|
|
src -= 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-19 23:11:50 +01:00
|
|
|
if (hr == S_OK && This->decode_info.reverse_bgr)
|
|
|
|
{
|
2010-05-29 19:32:32 +02:00
|
|
|
if (This->decode_info.bps == 8)
|
2010-03-19 23:11:50 +01:00
|
|
|
{
|
2011-01-10 22:23:17 +01:00
|
|
|
UINT sample_count = This->decode_info.samples;
|
2010-03-19 23:11:50 +01:00
|
|
|
|
2011-01-10 22:23:17 +01:00
|
|
|
reverse_bgr8(sample_count, This->cached_tile, This->decode_info.tile_width,
|
|
|
|
This->decode_info.tile_height, This->decode_info.tile_width * sample_count);
|
2010-03-19 23:11:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-29 17:43:30 +02:00
|
|
|
if (hr == S_OK && swap_bytes && This->decode_info.bps > 8)
|
|
|
|
{
|
|
|
|
UINT row, i, samples_per_row;
|
|
|
|
BYTE *sample, temp;
|
|
|
|
|
|
|
|
samples_per_row = This->decode_info.tile_width * This->decode_info.samples;
|
|
|
|
|
|
|
|
switch(This->decode_info.bps)
|
|
|
|
{
|
|
|
|
case 16:
|
|
|
|
for (row=0; row<This->decode_info.tile_height; row++)
|
|
|
|
{
|
|
|
|
sample = This->cached_tile + row * This->decode_info.tile_stride;
|
|
|
|
for (i=0; i<samples_per_row; i++)
|
|
|
|
{
|
|
|
|
temp = sample[1];
|
|
|
|
sample[1] = sample[0];
|
|
|
|
sample[0] = temp;
|
|
|
|
sample += 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERR("unhandled bps for byte swap %u\n", This->decode_info.bps);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-29 18:27:31 +02:00
|
|
|
if (hr == S_OK && This->decode_info.invert_grayscale)
|
|
|
|
{
|
|
|
|
BYTE *byte, *end;
|
|
|
|
|
|
|
|
if (This->decode_info.samples != 1)
|
|
|
|
{
|
|
|
|
ERR("cannot invert grayscale image with %u samples\n", This->decode_info.samples);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
end = This->cached_tile+This->decode_info.tile_size;
|
|
|
|
|
|
|
|
for (byte = This->cached_tile; byte != end; byte++)
|
|
|
|
*byte = ~(*byte);
|
|
|
|
}
|
|
|
|
|
2010-03-19 22:35:07 +01:00
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
This->cached_tile_x = tile_x;
|
|
|
|
This->cached_tile_y = tile_y;
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2010-03-17 22:25:12 +01:00
|
|
|
static HRESULT WINAPI TiffFrameDecode_CopyPixels(IWICBitmapFrameDecode *iface,
|
|
|
|
const WICRect *prc, UINT cbStride, UINT cbBufferSize, BYTE *pbBuffer)
|
|
|
|
{
|
2010-11-29 00:58:20 +01:00
|
|
|
TiffFrameDecode *This = impl_from_IWICBitmapFrameDecode(iface);
|
2010-03-19 22:35:07 +01:00
|
|
|
UINT min_tile_x, max_tile_x, min_tile_y, max_tile_y;
|
|
|
|
UINT tile_x, tile_y;
|
|
|
|
WICRect rc;
|
|
|
|
HRESULT hr=S_OK;
|
|
|
|
BYTE *dst_tilepos;
|
|
|
|
UINT bytesperrow;
|
2010-10-19 18:50:36 +02:00
|
|
|
WICRect rect;
|
2010-03-19 22:35:07 +01:00
|
|
|
|
|
|
|
TRACE("(%p,%p,%u,%u,%p)\n", iface, prc, cbStride, cbBufferSize, pbBuffer);
|
|
|
|
|
2010-10-19 18:50:36 +02:00
|
|
|
if (!prc)
|
|
|
|
{
|
|
|
|
rect.X = 0;
|
|
|
|
rect.Y = 0;
|
|
|
|
rect.Width = This->decode_info.width;
|
|
|
|
rect.Height = This->decode_info.height;
|
|
|
|
prc = ▭
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (prc->X < 0 || prc->Y < 0 || prc->X+prc->Width > This->decode_info.width ||
|
|
|
|
prc->Y+prc->Height > This->decode_info.height)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
2010-03-19 22:35:07 +01:00
|
|
|
|
|
|
|
bytesperrow = ((This->decode_info.bpp * prc->Width)+7)/8;
|
|
|
|
|
|
|
|
if (cbStride < bytesperrow)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
if ((cbStride * prc->Height) > cbBufferSize)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
min_tile_x = prc->X / This->decode_info.tile_width;
|
|
|
|
min_tile_y = prc->Y / This->decode_info.tile_height;
|
|
|
|
max_tile_x = (prc->X+prc->Width-1) / This->decode_info.tile_width;
|
|
|
|
max_tile_y = (prc->Y+prc->Height-1) / This->decode_info.tile_height;
|
|
|
|
|
|
|
|
EnterCriticalSection(&This->parent->lock);
|
|
|
|
|
|
|
|
for (tile_x=min_tile_x; tile_x <= max_tile_x; tile_x++)
|
|
|
|
{
|
|
|
|
for (tile_y=min_tile_y; tile_y <= max_tile_y; tile_y++)
|
|
|
|
{
|
|
|
|
if (tile_x != This->cached_tile_x || tile_y != This->cached_tile_y)
|
|
|
|
{
|
|
|
|
hr = TiffFrameDecode_ReadTile(This, tile_x, tile_y);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
if (prc->X < tile_x * This->decode_info.tile_width)
|
|
|
|
rc.X = 0;
|
|
|
|
else
|
|
|
|
rc.X = prc->X - tile_x * This->decode_info.tile_width;
|
|
|
|
|
|
|
|
if (prc->Y < tile_y * This->decode_info.tile_height)
|
|
|
|
rc.Y = 0;
|
|
|
|
else
|
|
|
|
rc.Y = prc->Y - tile_y * This->decode_info.tile_height;
|
|
|
|
|
|
|
|
if (prc->X+prc->Width > (tile_x+1) * This->decode_info.tile_width)
|
|
|
|
rc.Width = This->decode_info.tile_width - rc.X;
|
2010-05-29 17:07:17 +02:00
|
|
|
else if (prc->X < tile_x * This->decode_info.tile_width)
|
|
|
|
rc.Width = prc->Width + prc->X - tile_x * This->decode_info.tile_width;
|
2010-03-19 22:35:07 +01:00
|
|
|
else
|
2010-05-29 17:07:17 +02:00
|
|
|
rc.Width = prc->Width;
|
2010-03-19 22:35:07 +01:00
|
|
|
|
|
|
|
if (prc->Y+prc->Height > (tile_y+1) * This->decode_info.tile_height)
|
|
|
|
rc.Height = This->decode_info.tile_height - rc.Y;
|
2010-05-29 17:07:17 +02:00
|
|
|
else if (prc->Y < tile_y * This->decode_info.tile_height)
|
|
|
|
rc.Height = prc->Height + prc->Y - tile_y * This->decode_info.tile_height;
|
2010-03-19 22:35:07 +01:00
|
|
|
else
|
2010-05-29 17:07:17 +02:00
|
|
|
rc.Height = prc->Height;
|
2010-03-19 22:35:07 +01:00
|
|
|
|
2010-05-29 17:07:17 +02:00
|
|
|
dst_tilepos = pbBuffer + (cbStride * ((rc.Y + tile_y * This->decode_info.tile_height) - prc->Y)) +
|
|
|
|
((This->decode_info.bpp * ((rc.X + tile_x * This->decode_info.tile_width) - prc->X) + 7) / 8);
|
2010-03-19 22:35:07 +01:00
|
|
|
|
|
|
|
hr = copy_pixels(This->decode_info.bpp, This->cached_tile,
|
|
|
|
This->decode_info.tile_width, This->decode_info.tile_height, This->decode_info.tile_stride,
|
|
|
|
&rc, cbStride, cbBufferSize, dst_tilepos);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
LeaveCriticalSection(&This->parent->lock);
|
|
|
|
TRACE("<-- 0x%x\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LeaveCriticalSection(&This->parent->lock);
|
|
|
|
|
|
|
|
return S_OK;
|
2010-03-17 22:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI TiffFrameDecode_GetMetadataQueryReader(IWICBitmapFrameDecode *iface,
|
|
|
|
IWICMetadataQueryReader **ppIMetadataQueryReader)
|
|
|
|
{
|
2016-03-14 19:47:00 +01:00
|
|
|
TiffFrameDecode *This = impl_from_IWICBitmapFrameDecode(iface);
|
|
|
|
|
|
|
|
TRACE("(%p,%p)\n", iface, ppIMetadataQueryReader);
|
|
|
|
|
|
|
|
if (!ppIMetadataQueryReader)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2017-06-22 05:38:56 +02:00
|
|
|
return MetadataQueryReader_CreateInstance(&This->IWICMetadataBlockReader_iface, NULL, ppIMetadataQueryReader);
|
2010-03-17 22:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI TiffFrameDecode_GetColorContexts(IWICBitmapFrameDecode *iface,
|
|
|
|
UINT cCount, IWICColorContext **ppIColorContexts, UINT *pcActualCount)
|
|
|
|
{
|
2013-02-11 14:30:35 +01:00
|
|
|
TiffFrameDecode *This = impl_from_IWICBitmapFrameDecode(iface);
|
|
|
|
const BYTE *profile;
|
|
|
|
UINT len;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("(%p,%u,%p,%p)\n", iface, cCount, ppIColorContexts, pcActualCount);
|
|
|
|
|
|
|
|
EnterCriticalSection(&This->parent->lock);
|
|
|
|
|
|
|
|
if (pTIFFGetField(This->parent->tiff, TIFFTAG_ICCPROFILE, &len, &profile))
|
|
|
|
{
|
|
|
|
if (cCount && ppIColorContexts)
|
|
|
|
{
|
|
|
|
hr = IWICColorContext_InitializeFromMemory(*ppIColorContexts, profile, len);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
LeaveCriticalSection(&This->parent->lock);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*pcActualCount = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*pcActualCount = 0;
|
|
|
|
|
|
|
|
LeaveCriticalSection(&This->parent->lock);
|
|
|
|
|
|
|
|
return S_OK;
|
2010-03-17 22:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI TiffFrameDecode_GetThumbnail(IWICBitmapFrameDecode *iface,
|
|
|
|
IWICBitmapSource **ppIThumbnail)
|
|
|
|
{
|
2012-06-25 05:27:22 +02:00
|
|
|
TRACE("(%p,%p)\n", iface, ppIThumbnail);
|
|
|
|
|
|
|
|
if (!ppIThumbnail) return E_INVALIDARG;
|
|
|
|
|
|
|
|
*ppIThumbnail = NULL;
|
|
|
|
return WINCODEC_ERR_CODECNOTHUMBNAIL;
|
2010-03-17 22:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static const IWICBitmapFrameDecodeVtbl TiffFrameDecode_Vtbl = {
|
|
|
|
TiffFrameDecode_QueryInterface,
|
|
|
|
TiffFrameDecode_AddRef,
|
|
|
|
TiffFrameDecode_Release,
|
|
|
|
TiffFrameDecode_GetSize,
|
|
|
|
TiffFrameDecode_GetPixelFormat,
|
|
|
|
TiffFrameDecode_GetResolution,
|
|
|
|
TiffFrameDecode_CopyPalette,
|
|
|
|
TiffFrameDecode_CopyPixels,
|
|
|
|
TiffFrameDecode_GetMetadataQueryReader,
|
|
|
|
TiffFrameDecode_GetColorContexts,
|
|
|
|
TiffFrameDecode_GetThumbnail
|
|
|
|
};
|
|
|
|
|
2012-06-06 11:44:11 +02:00
|
|
|
static HRESULT WINAPI TiffFrameDecode_Block_QueryInterface(IWICMetadataBlockReader *iface,
|
|
|
|
REFIID iid, void **ppv)
|
|
|
|
{
|
|
|
|
TiffFrameDecode *This = impl_from_IWICMetadataBlockReader(iface);
|
|
|
|
return IWICBitmapFrameDecode_QueryInterface(&This->IWICBitmapFrameDecode_iface, iid, ppv);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI TiffFrameDecode_Block_AddRef(IWICMetadataBlockReader *iface)
|
|
|
|
{
|
|
|
|
TiffFrameDecode *This = impl_from_IWICMetadataBlockReader(iface);
|
|
|
|
return IWICBitmapFrameDecode_AddRef(&This->IWICBitmapFrameDecode_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI TiffFrameDecode_Block_Release(IWICMetadataBlockReader *iface)
|
|
|
|
{
|
|
|
|
TiffFrameDecode *This = impl_from_IWICMetadataBlockReader(iface);
|
|
|
|
return IWICBitmapFrameDecode_Release(&This->IWICBitmapFrameDecode_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI TiffFrameDecode_Block_GetContainerFormat(IWICMetadataBlockReader *iface,
|
|
|
|
GUID *guid)
|
|
|
|
{
|
2012-09-12 08:09:56 +02:00
|
|
|
TRACE("(%p,%p)\n", iface, guid);
|
|
|
|
|
|
|
|
if (!guid) return E_INVALIDARG;
|
|
|
|
|
|
|
|
*guid = GUID_ContainerFormatTiff;
|
|
|
|
return S_OK;
|
2012-06-06 11:44:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI TiffFrameDecode_Block_GetCount(IWICMetadataBlockReader *iface,
|
|
|
|
UINT *count)
|
|
|
|
{
|
2012-06-19 04:40:10 +02:00
|
|
|
TRACE("%p,%p\n", iface, count);
|
|
|
|
|
|
|
|
if (!count) return E_INVALIDARG;
|
|
|
|
|
|
|
|
*count = 1;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT create_metadata_reader(TiffFrameDecode *This, IWICMetadataReader **reader)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
LARGE_INTEGER dir_offset;
|
|
|
|
IWICMetadataReader *metadata_reader;
|
|
|
|
IWICPersistStream *persist;
|
|
|
|
|
|
|
|
/* FIXME: Use IWICComponentFactory_CreateMetadataReader once it's implemented */
|
|
|
|
|
2015-03-05 12:13:00 +01:00
|
|
|
hr = IfdMetadataReader_CreateInstance(&IID_IWICMetadataReader, (void **)&metadata_reader);
|
2012-06-19 04:40:10 +02:00
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
hr = IWICMetadataReader_QueryInterface(metadata_reader, &IID_IWICPersistStream, (void **)&persist);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
IWICMetadataReader_Release(metadata_reader);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
EnterCriticalSection(&This->parent->lock);
|
|
|
|
|
|
|
|
dir_offset.QuadPart = pTIFFCurrentDirOffset(This->parent->tiff);
|
|
|
|
hr = IStream_Seek(This->parent->stream, dir_offset, STREAM_SEEK_SET, NULL);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
BOOL byte_swapped = pTIFFIsByteSwapped(This->parent->tiff);
|
|
|
|
#ifdef WORDS_BIGENDIAN
|
2017-05-10 18:20:10 +02:00
|
|
|
DWORD persist_options = byte_swapped ? WICPersistOptionLittleEndian : WICPersistOptionBigEndian;
|
2012-06-19 04:40:10 +02:00
|
|
|
#else
|
2017-05-10 18:20:10 +02:00
|
|
|
DWORD persist_options = byte_swapped ? WICPersistOptionBigEndian : WICPersistOptionLittleEndian;
|
2012-06-19 04:40:10 +02:00
|
|
|
#endif
|
2017-05-10 18:20:10 +02:00
|
|
|
persist_options |= WICPersistOptionNoCacheStream;
|
2012-06-19 04:40:10 +02:00
|
|
|
hr = IWICPersistStream_LoadEx(persist, This->parent->stream, NULL, persist_options);
|
|
|
|
if (FAILED(hr))
|
|
|
|
ERR("IWICPersistStream_LoadEx error %#x\n", hr);
|
|
|
|
}
|
|
|
|
|
|
|
|
LeaveCriticalSection(&This->parent->lock);
|
|
|
|
|
|
|
|
IWICPersistStream_Release(persist);
|
|
|
|
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
IWICMetadataReader_Release(metadata_reader);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
*reader = metadata_reader;
|
|
|
|
return S_OK;
|
2012-06-06 11:44:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI TiffFrameDecode_Block_GetReaderByIndex(IWICMetadataBlockReader *iface,
|
|
|
|
UINT index, IWICMetadataReader **reader)
|
|
|
|
{
|
2012-06-19 04:40:10 +02:00
|
|
|
TiffFrameDecode *This = impl_from_IWICMetadataBlockReader(iface);
|
|
|
|
|
|
|
|
TRACE("(%p,%u,%p)\n", iface, index, reader);
|
|
|
|
|
|
|
|
if (!reader || index != 0) return E_INVALIDARG;
|
|
|
|
|
|
|
|
return create_metadata_reader(This, reader);
|
2012-06-06 11:44:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI TiffFrameDecode_Block_GetEnumerator(IWICMetadataBlockReader *iface,
|
|
|
|
IEnumUnknown **enum_metadata)
|
|
|
|
{
|
|
|
|
FIXME("(%p,%p): stub\n", iface, enum_metadata);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IWICMetadataBlockReaderVtbl TiffFrameDecode_BlockVtbl =
|
|
|
|
{
|
|
|
|
TiffFrameDecode_Block_QueryInterface,
|
|
|
|
TiffFrameDecode_Block_AddRef,
|
|
|
|
TiffFrameDecode_Block_Release,
|
|
|
|
TiffFrameDecode_Block_GetContainerFormat,
|
|
|
|
TiffFrameDecode_Block_GetCount,
|
|
|
|
TiffFrameDecode_Block_GetReaderByIndex,
|
|
|
|
TiffFrameDecode_Block_GetEnumerator
|
|
|
|
};
|
|
|
|
|
2014-01-14 12:18:11 +01:00
|
|
|
HRESULT TiffDecoder_CreateInstance(REFIID iid, void** ppv)
|
2010-03-09 00:07:29 +01:00
|
|
|
{
|
|
|
|
HRESULT ret;
|
|
|
|
TiffDecoder *This;
|
|
|
|
|
2014-01-14 12:18:11 +01:00
|
|
|
TRACE("(%s,%p)\n", debugstr_guid(iid), ppv);
|
2010-03-09 00:07:29 +01:00
|
|
|
|
|
|
|
*ppv = NULL;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2010-11-29 00:58:20 +01:00
|
|
|
This->IWICBitmapDecoder_iface.lpVtbl = &TiffDecoder_Vtbl;
|
2010-03-09 00:07:29 +01:00
|
|
|
This->ref = 1;
|
2010-03-17 21:44:28 +01:00
|
|
|
This->stream = NULL;
|
|
|
|
InitializeCriticalSection(&This->lock);
|
|
|
|
This->lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": TiffDecoder.lock");
|
|
|
|
This->tiff = NULL;
|
|
|
|
This->initialized = FALSE;
|
2010-03-09 00:07:29 +01:00
|
|
|
|
2012-07-24 08:18:16 +02:00
|
|
|
ret = IWICBitmapDecoder_QueryInterface(&This->IWICBitmapDecoder_iface, iid, ppv);
|
|
|
|
IWICBitmapDecoder_Release(&This->IWICBitmapDecoder_iface);
|
2010-03-09 00:07:29 +01:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-04-05 19:09:25 +02:00
|
|
|
struct tiff_encode_format {
|
|
|
|
const WICPixelFormatGUID *guid;
|
|
|
|
int photometric;
|
|
|
|
int bps;
|
|
|
|
int samples;
|
|
|
|
int bpp;
|
|
|
|
int extra_sample;
|
|
|
|
int extra_sample_type;
|
|
|
|
int reverse_bgr;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct tiff_encode_format formats[] = {
|
|
|
|
{&GUID_WICPixelFormat24bppBGR, 2, 8, 3, 24, 0, 0, 1},
|
2013-01-04 20:21:34 +01:00
|
|
|
{&GUID_WICPixelFormat24bppRGB, 2, 8, 3, 24, 0, 0, 0},
|
2011-04-05 19:09:25 +02:00
|
|
|
{&GUID_WICPixelFormatBlackWhite, 1, 1, 1, 1, 0, 0, 0},
|
|
|
|
{&GUID_WICPixelFormat4bppGray, 1, 4, 1, 4, 0, 0, 0},
|
|
|
|
{&GUID_WICPixelFormat8bppGray, 1, 8, 1, 8, 0, 0, 0},
|
|
|
|
{&GUID_WICPixelFormat32bppBGRA, 2, 8, 4, 32, 1, 2, 1},
|
|
|
|
{&GUID_WICPixelFormat32bppPBGRA, 2, 8, 4, 32, 1, 1, 1},
|
|
|
|
{&GUID_WICPixelFormat48bppRGB, 2, 16, 3, 48, 0, 0, 0},
|
|
|
|
{&GUID_WICPixelFormat64bppRGBA, 2, 16, 4, 64, 1, 2, 0},
|
|
|
|
{&GUID_WICPixelFormat64bppPRGBA, 2, 16, 4, 64, 1, 1, 0},
|
|
|
|
{0}
|
|
|
|
};
|
|
|
|
|
2011-03-29 21:56:30 +02:00
|
|
|
typedef struct TiffEncoder {
|
|
|
|
IWICBitmapEncoder IWICBitmapEncoder_iface;
|
|
|
|
LONG ref;
|
2011-03-29 22:04:26 +02:00
|
|
|
IStream *stream;
|
2011-03-29 23:24:19 +02:00
|
|
|
CRITICAL_SECTION lock; /* Must be held when tiff is used or fields below are set */
|
2011-03-29 22:04:26 +02:00
|
|
|
TIFF *tiff;
|
|
|
|
BOOL initialized;
|
2011-04-05 23:27:28 +02:00
|
|
|
BOOL committed;
|
2011-03-29 23:24:19 +02:00
|
|
|
ULONG num_frames;
|
|
|
|
ULONG num_frames_committed;
|
2011-03-29 21:56:30 +02:00
|
|
|
} TiffEncoder;
|
|
|
|
|
|
|
|
static inline TiffEncoder *impl_from_IWICBitmapEncoder(IWICBitmapEncoder *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, TiffEncoder, IWICBitmapEncoder_iface);
|
|
|
|
}
|
|
|
|
|
2011-03-29 23:24:19 +02:00
|
|
|
typedef struct TiffFrameEncode {
|
|
|
|
IWICBitmapFrameEncode IWICBitmapFrameEncode_iface;
|
|
|
|
LONG ref;
|
|
|
|
TiffEncoder *parent;
|
2011-03-29 23:30:59 +02:00
|
|
|
/* fields below are protected by parent->lock */
|
|
|
|
BOOL initialized;
|
2011-04-05 19:09:25 +02:00
|
|
|
BOOL info_written;
|
2011-04-05 23:06:54 +02:00
|
|
|
BOOL committed;
|
2011-04-05 19:09:25 +02:00
|
|
|
const struct tiff_encode_format *format;
|
2011-04-05 19:15:42 +02:00
|
|
|
UINT width, height;
|
2011-04-05 21:37:05 +02:00
|
|
|
double xres, yres;
|
2011-04-05 22:55:16 +02:00
|
|
|
UINT lines_written;
|
2017-09-13 22:12:41 +02:00
|
|
|
WICColor palette[256];
|
|
|
|
UINT colors;
|
2011-03-29 23:24:19 +02:00
|
|
|
} TiffFrameEncode;
|
|
|
|
|
|
|
|
static inline TiffFrameEncode *impl_from_IWICBitmapFrameEncode(IWICBitmapFrameEncode *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, TiffFrameEncode, IWICBitmapFrameEncode_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI TiffFrameEncode_QueryInterface(IWICBitmapFrameEncode *iface, REFIID iid,
|
|
|
|
void **ppv)
|
|
|
|
{
|
|
|
|
TiffFrameEncode *This = impl_from_IWICBitmapFrameEncode(iface);
|
|
|
|
TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
|
|
|
|
|
|
|
|
if (!ppv) return E_INVALIDARG;
|
|
|
|
|
|
|
|
if (IsEqualIID(&IID_IUnknown, iid) ||
|
|
|
|
IsEqualIID(&IID_IWICBitmapFrameEncode, iid))
|
|
|
|
{
|
|
|
|
*ppv = &This->IWICBitmapFrameEncode_iface;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*ppv = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
IUnknown_AddRef((IUnknown*)*ppv);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI TiffFrameEncode_AddRef(IWICBitmapFrameEncode *iface)
|
|
|
|
{
|
|
|
|
TiffFrameEncode *This = impl_from_IWICBitmapFrameEncode(iface);
|
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p) refcount=%u\n", iface, ref);
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI TiffFrameEncode_Release(IWICBitmapFrameEncode *iface)
|
|
|
|
{
|
|
|
|
TiffFrameEncode *This = impl_from_IWICBitmapFrameEncode(iface);
|
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p) refcount=%u\n", iface, ref);
|
|
|
|
|
|
|
|
if (ref == 0)
|
|
|
|
{
|
|
|
|
IWICBitmapEncoder_Release(&This->parent->IWICBitmapEncoder_iface);
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI TiffFrameEncode_Initialize(IWICBitmapFrameEncode *iface,
|
|
|
|
IPropertyBag2 *pIEncoderOptions)
|
|
|
|
{
|
2011-03-29 23:30:59 +02:00
|
|
|
TiffFrameEncode *This = impl_from_IWICBitmapFrameEncode(iface);
|
|
|
|
TRACE("(%p,%p)\n", iface, pIEncoderOptions);
|
|
|
|
|
|
|
|
EnterCriticalSection(&This->parent->lock);
|
|
|
|
|
|
|
|
if (This->initialized)
|
|
|
|
{
|
|
|
|
LeaveCriticalSection(&This->parent->lock);
|
|
|
|
return WINCODEC_ERR_WRONGSTATE;
|
|
|
|
}
|
|
|
|
|
|
|
|
This->initialized = TRUE;
|
|
|
|
|
|
|
|
LeaveCriticalSection(&This->parent->lock);
|
|
|
|
|
|
|
|
return S_OK;
|
2011-03-29 23:24:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI TiffFrameEncode_SetSize(IWICBitmapFrameEncode *iface,
|
|
|
|
UINT uiWidth, UINT uiHeight)
|
|
|
|
{
|
2011-04-05 19:15:42 +02:00
|
|
|
TiffFrameEncode *This = impl_from_IWICBitmapFrameEncode(iface);
|
|
|
|
TRACE("(%p,%u,%u)\n", iface, uiWidth, uiHeight);
|
|
|
|
|
|
|
|
EnterCriticalSection(&This->parent->lock);
|
|
|
|
|
|
|
|
if (!This->initialized || This->info_written)
|
|
|
|
{
|
|
|
|
LeaveCriticalSection(&This->parent->lock);
|
|
|
|
return WINCODEC_ERR_WRONGSTATE;
|
|
|
|
}
|
|
|
|
|
|
|
|
This->width = uiWidth;
|
|
|
|
This->height = uiHeight;
|
|
|
|
|
|
|
|
LeaveCriticalSection(&This->parent->lock);
|
|
|
|
|
|
|
|
return S_OK;
|
2011-03-29 23:24:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI TiffFrameEncode_SetResolution(IWICBitmapFrameEncode *iface,
|
|
|
|
double dpiX, double dpiY)
|
|
|
|
{
|
2011-04-05 21:37:05 +02:00
|
|
|
TiffFrameEncode *This = impl_from_IWICBitmapFrameEncode(iface);
|
|
|
|
TRACE("(%p,%0.2f,%0.2f)\n", iface, dpiX, dpiY);
|
|
|
|
|
|
|
|
EnterCriticalSection(&This->parent->lock);
|
|
|
|
|
|
|
|
if (!This->initialized || This->info_written)
|
|
|
|
{
|
|
|
|
LeaveCriticalSection(&This->parent->lock);
|
|
|
|
return WINCODEC_ERR_WRONGSTATE;
|
|
|
|
}
|
|
|
|
|
|
|
|
This->xres = dpiX;
|
|
|
|
This->yres = dpiY;
|
|
|
|
|
|
|
|
LeaveCriticalSection(&This->parent->lock);
|
|
|
|
|
|
|
|
return S_OK;
|
2011-03-29 23:24:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI TiffFrameEncode_SetPixelFormat(IWICBitmapFrameEncode *iface,
|
|
|
|
WICPixelFormatGUID *pPixelFormat)
|
|
|
|
{
|
2011-04-05 19:09:25 +02:00
|
|
|
TiffFrameEncode *This = impl_from_IWICBitmapFrameEncode(iface);
|
|
|
|
int i;
|
|
|
|
|
|
|
|
TRACE("(%p,%s)\n", iface, debugstr_guid(pPixelFormat));
|
|
|
|
|
|
|
|
EnterCriticalSection(&This->parent->lock);
|
|
|
|
|
|
|
|
if (!This->initialized || This->info_written)
|
|
|
|
{
|
|
|
|
LeaveCriticalSection(&This->parent->lock);
|
|
|
|
return WINCODEC_ERR_WRONGSTATE;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i=0; formats[i].guid; i++)
|
|
|
|
{
|
|
|
|
if (memcmp(formats[i].guid, pPixelFormat, sizeof(GUID)) == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!formats[i].guid) i = 0;
|
|
|
|
|
|
|
|
This->format = &formats[i];
|
|
|
|
memcpy(pPixelFormat, This->format->guid, sizeof(GUID));
|
|
|
|
|
|
|
|
LeaveCriticalSection(&This->parent->lock);
|
|
|
|
|
|
|
|
return S_OK;
|
2011-03-29 23:24:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI TiffFrameEncode_SetColorContexts(IWICBitmapFrameEncode *iface,
|
|
|
|
UINT cCount, IWICColorContext **ppIColorContext)
|
|
|
|
{
|
|
|
|
FIXME("(%p,%u,%p): stub\n", iface, cCount, ppIColorContext);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI TiffFrameEncode_SetPalette(IWICBitmapFrameEncode *iface,
|
2017-09-13 22:12:41 +02:00
|
|
|
IWICPalette *palette)
|
2011-03-29 23:24:19 +02:00
|
|
|
{
|
2017-09-13 22:12:41 +02:00
|
|
|
TiffFrameEncode *This = impl_from_IWICBitmapFrameEncode(iface);
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("(%p,%p)\n", iface, palette);
|
|
|
|
|
|
|
|
if (!palette) return E_INVALIDARG;
|
|
|
|
|
|
|
|
EnterCriticalSection(&This->parent->lock);
|
|
|
|
|
|
|
|
if (This->initialized)
|
|
|
|
hr = IWICPalette_GetColors(palette, 256, This->palette, &This->colors);
|
|
|
|
else
|
|
|
|
hr = WINCODEC_ERR_NOTINITIALIZED;
|
|
|
|
|
|
|
|
LeaveCriticalSection(&This->parent->lock);
|
|
|
|
return hr;
|
2011-03-29 23:24:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI TiffFrameEncode_SetThumbnail(IWICBitmapFrameEncode *iface,
|
|
|
|
IWICBitmapSource *pIThumbnail)
|
|
|
|
{
|
|
|
|
FIXME("(%p,%p): stub\n", iface, pIThumbnail);
|
|
|
|
return WINCODEC_ERR_UNSUPPORTEDOPERATION;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI TiffFrameEncode_WritePixels(IWICBitmapFrameEncode *iface,
|
|
|
|
UINT lineCount, UINT cbStride, UINT cbBufferSize, BYTE *pbPixels)
|
|
|
|
{
|
2011-04-05 22:55:16 +02:00
|
|
|
TiffFrameEncode *This = impl_from_IWICBitmapFrameEncode(iface);
|
|
|
|
BYTE *row_data, *swapped_data = NULL;
|
|
|
|
UINT i, j, line_size;
|
|
|
|
|
|
|
|
TRACE("(%p,%u,%u,%u,%p)\n", iface, lineCount, cbStride, cbBufferSize, pbPixels);
|
|
|
|
|
|
|
|
EnterCriticalSection(&This->parent->lock);
|
|
|
|
|
|
|
|
if (!This->initialized || !This->width || !This->height || !This->format)
|
|
|
|
{
|
|
|
|
LeaveCriticalSection(&This->parent->lock);
|
|
|
|
return WINCODEC_ERR_WRONGSTATE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lineCount == 0 || lineCount + This->lines_written > This->height)
|
|
|
|
{
|
|
|
|
LeaveCriticalSection(&This->parent->lock);
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
line_size = ((This->width * This->format->bpp)+7)/8;
|
|
|
|
|
|
|
|
if (This->format->reverse_bgr)
|
|
|
|
{
|
|
|
|
swapped_data = HeapAlloc(GetProcessHeap(), 0, line_size);
|
|
|
|
if (!swapped_data)
|
|
|
|
{
|
|
|
|
LeaveCriticalSection(&This->parent->lock);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!This->info_written)
|
|
|
|
{
|
|
|
|
pTIFFSetField(This->parent->tiff, TIFFTAG_PHOTOMETRIC, (uint16)This->format->photometric);
|
|
|
|
pTIFFSetField(This->parent->tiff, TIFFTAG_PLANARCONFIG, (uint16)1);
|
|
|
|
pTIFFSetField(This->parent->tiff, TIFFTAG_BITSPERSAMPLE, (uint16)This->format->bps);
|
|
|
|
pTIFFSetField(This->parent->tiff, TIFFTAG_SAMPLESPERPIXEL, (uint16)This->format->samples);
|
|
|
|
|
|
|
|
if (This->format->extra_sample)
|
|
|
|
{
|
|
|
|
uint16 extra_samples;
|
|
|
|
extra_samples = This->format->extra_sample_type;
|
|
|
|
|
|
|
|
pTIFFSetField(This->parent->tiff, TIFFTAG_EXTRASAMPLES, (uint16)1, &extra_samples);
|
|
|
|
}
|
|
|
|
|
|
|
|
pTIFFSetField(This->parent->tiff, TIFFTAG_IMAGEWIDTH, (uint32)This->width);
|
|
|
|
pTIFFSetField(This->parent->tiff, TIFFTAG_IMAGELENGTH, (uint32)This->height);
|
|
|
|
|
|
|
|
if (This->xres != 0.0 && This->yres != 0.0)
|
|
|
|
{
|
|
|
|
pTIFFSetField(This->parent->tiff, TIFFTAG_RESOLUTIONUNIT, (uint16)2); /* Inch */
|
|
|
|
pTIFFSetField(This->parent->tiff, TIFFTAG_XRESOLUTION, (float)This->xres);
|
|
|
|
pTIFFSetField(This->parent->tiff, TIFFTAG_YRESOLUTION, (float)This->yres);
|
|
|
|
}
|
|
|
|
|
|
|
|
This->info_written = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i=0; i<lineCount; i++)
|
|
|
|
{
|
|
|
|
row_data = pbPixels + i * cbStride;
|
|
|
|
|
|
|
|
if (This->format->reverse_bgr && This->format->bps == 8)
|
|
|
|
{
|
|
|
|
memcpy(swapped_data, row_data, line_size);
|
|
|
|
for (j=0; j<line_size; j += This->format->samples)
|
|
|
|
{
|
|
|
|
BYTE temp;
|
|
|
|
temp = swapped_data[j];
|
|
|
|
swapped_data[j] = swapped_data[j+2];
|
|
|
|
swapped_data[j+2] = temp;
|
|
|
|
}
|
|
|
|
row_data = swapped_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
pTIFFWriteScanline(This->parent->tiff, (tdata_t)row_data, i+This->lines_written, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
This->lines_written += lineCount;
|
|
|
|
|
|
|
|
LeaveCriticalSection(&This->parent->lock);
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, swapped_data);
|
|
|
|
|
|
|
|
return S_OK;
|
2011-03-29 23:24:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI TiffFrameEncode_WriteSource(IWICBitmapFrameEncode *iface,
|
|
|
|
IWICBitmapSource *pIBitmapSource, WICRect *prc)
|
|
|
|
{
|
2011-04-05 21:41:45 +02:00
|
|
|
TiffFrameEncode *This = impl_from_IWICBitmapFrameEncode(iface);
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("(%p,%p,%p)\n", iface, pIBitmapSource, prc);
|
|
|
|
|
2014-06-13 21:02:23 +02:00
|
|
|
if (!This->initialized)
|
2011-04-05 21:41:45 +02:00
|
|
|
return WINCODEC_ERR_WRONGSTATE;
|
|
|
|
|
2014-06-13 21:02:23 +02:00
|
|
|
hr = configure_write_source(iface, pIBitmapSource, prc,
|
|
|
|
This->format ? This->format->guid : NULL, This->width, This->height,
|
|
|
|
This->xres, This->yres);
|
2011-04-05 21:41:45 +02:00
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
2014-06-13 21:02:23 +02:00
|
|
|
hr = write_source(iface, pIBitmapSource, prc,
|
|
|
|
This->format->guid, This->format->bpp, This->width, This->height);
|
2011-04-05 21:41:45 +02:00
|
|
|
}
|
|
|
|
|
2014-06-13 21:02:23 +02:00
|
|
|
return hr;
|
2011-03-29 23:24:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI TiffFrameEncode_Commit(IWICBitmapFrameEncode *iface)
|
|
|
|
{
|
2011-04-05 23:06:54 +02:00
|
|
|
TiffFrameEncode *This = impl_from_IWICBitmapFrameEncode(iface);
|
|
|
|
|
|
|
|
TRACE("(%p)\n", iface);
|
|
|
|
|
|
|
|
EnterCriticalSection(&This->parent->lock);
|
|
|
|
|
|
|
|
if (!This->info_written || This->lines_written != This->height || This->committed)
|
|
|
|
{
|
|
|
|
LeaveCriticalSection(&This->parent->lock);
|
|
|
|
return WINCODEC_ERR_WRONGSTATE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* libtiff will commit the data when creating a new frame or closing the file */
|
|
|
|
|
|
|
|
This->committed = TRUE;
|
|
|
|
This->parent->num_frames_committed++;
|
|
|
|
|
|
|
|
LeaveCriticalSection(&This->parent->lock);
|
|
|
|
|
|
|
|
return S_OK;
|
2011-03-29 23:24:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI TiffFrameEncode_GetMetadataQueryWriter(IWICBitmapFrameEncode *iface,
|
|
|
|
IWICMetadataQueryWriter **ppIMetadataQueryWriter)
|
|
|
|
{
|
|
|
|
FIXME("(%p, %p): stub\n", iface, ppIMetadataQueryWriter);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IWICBitmapFrameEncodeVtbl TiffFrameEncode_Vtbl = {
|
|
|
|
TiffFrameEncode_QueryInterface,
|
|
|
|
TiffFrameEncode_AddRef,
|
|
|
|
TiffFrameEncode_Release,
|
|
|
|
TiffFrameEncode_Initialize,
|
|
|
|
TiffFrameEncode_SetSize,
|
|
|
|
TiffFrameEncode_SetResolution,
|
|
|
|
TiffFrameEncode_SetPixelFormat,
|
|
|
|
TiffFrameEncode_SetColorContexts,
|
|
|
|
TiffFrameEncode_SetPalette,
|
|
|
|
TiffFrameEncode_SetThumbnail,
|
|
|
|
TiffFrameEncode_WritePixels,
|
|
|
|
TiffFrameEncode_WriteSource,
|
|
|
|
TiffFrameEncode_Commit,
|
|
|
|
TiffFrameEncode_GetMetadataQueryWriter
|
|
|
|
};
|
|
|
|
|
2011-03-29 21:56:30 +02:00
|
|
|
static HRESULT WINAPI TiffEncoder_QueryInterface(IWICBitmapEncoder *iface, REFIID iid,
|
|
|
|
void **ppv)
|
|
|
|
{
|
|
|
|
TiffEncoder *This = impl_from_IWICBitmapEncoder(iface);
|
|
|
|
TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
|
|
|
|
|
|
|
|
if (!ppv) return E_INVALIDARG;
|
|
|
|
|
|
|
|
if (IsEqualIID(&IID_IUnknown, iid) ||
|
|
|
|
IsEqualIID(&IID_IWICBitmapEncoder, iid))
|
|
|
|
{
|
2012-07-24 08:18:16 +02:00
|
|
|
*ppv = &This->IWICBitmapEncoder_iface;
|
2011-03-29 21:56:30 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*ppv = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
IUnknown_AddRef((IUnknown*)*ppv);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI TiffEncoder_AddRef(IWICBitmapEncoder *iface)
|
|
|
|
{
|
|
|
|
TiffEncoder *This = impl_from_IWICBitmapEncoder(iface);
|
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p) refcount=%u\n", iface, ref);
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI TiffEncoder_Release(IWICBitmapEncoder *iface)
|
|
|
|
{
|
|
|
|
TiffEncoder *This = impl_from_IWICBitmapEncoder(iface);
|
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p) refcount=%u\n", iface, ref);
|
|
|
|
|
|
|
|
if (ref == 0)
|
|
|
|
{
|
2011-03-29 22:04:26 +02:00
|
|
|
if (This->tiff) pTIFFClose(This->tiff);
|
|
|
|
if (This->stream) IStream_Release(This->stream);
|
|
|
|
This->lock.DebugInfo->Spare[0] = 0;
|
|
|
|
DeleteCriticalSection(&This->lock);
|
2011-03-29 21:56:30 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI TiffEncoder_Initialize(IWICBitmapEncoder *iface,
|
|
|
|
IStream *pIStream, WICBitmapEncoderCacheOption cacheOption)
|
|
|
|
{
|
2011-03-29 22:04:26 +02:00
|
|
|
TiffEncoder *This = impl_from_IWICBitmapEncoder(iface);
|
|
|
|
TIFF *tiff;
|
|
|
|
HRESULT hr=S_OK;
|
|
|
|
|
|
|
|
TRACE("(%p,%p,%u)\n", iface, pIStream, cacheOption);
|
|
|
|
|
|
|
|
EnterCriticalSection(&This->lock);
|
|
|
|
|
2011-04-05 23:27:28 +02:00
|
|
|
if (This->initialized || This->committed)
|
2011-03-29 22:04:26 +02:00
|
|
|
{
|
|
|
|
hr = WINCODEC_ERR_WRONGSTATE;
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
tiff = tiff_open_stream(pIStream, "w");
|
|
|
|
|
|
|
|
if (!tiff)
|
|
|
|
{
|
|
|
|
hr = E_FAIL;
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
This->tiff = tiff;
|
|
|
|
This->stream = pIStream;
|
|
|
|
IStream_AddRef(pIStream);
|
|
|
|
This->initialized = TRUE;
|
|
|
|
|
|
|
|
exit:
|
|
|
|
LeaveCriticalSection(&This->lock);
|
|
|
|
return hr;
|
2011-03-29 21:56:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI TiffEncoder_GetContainerFormat(IWICBitmapEncoder *iface,
|
|
|
|
GUID *pguidContainerFormat)
|
|
|
|
{
|
2011-07-27 22:54:07 +02:00
|
|
|
memcpy(pguidContainerFormat, &GUID_ContainerFormatTiff, sizeof(GUID));
|
|
|
|
return S_OK;
|
2011-03-29 21:56:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI TiffEncoder_GetEncoderInfo(IWICBitmapEncoder *iface,
|
|
|
|
IWICBitmapEncoderInfo **ppIEncoderInfo)
|
|
|
|
{
|
|
|
|
FIXME("(%p,%p): stub\n", iface, ppIEncoderInfo);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI TiffEncoder_SetColorContexts(IWICBitmapEncoder *iface,
|
|
|
|
UINT cCount, IWICColorContext **ppIColorContext)
|
|
|
|
{
|
|
|
|
FIXME("(%p,%u,%p): stub\n", iface, cCount, ppIColorContext);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2017-09-13 22:12:42 +02:00
|
|
|
static HRESULT WINAPI TiffEncoder_SetPalette(IWICBitmapEncoder *iface, IWICPalette *palette)
|
2011-03-29 21:56:30 +02:00
|
|
|
{
|
2017-09-13 22:12:42 +02:00
|
|
|
TiffEncoder *This = impl_from_IWICBitmapEncoder(iface);
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("(%p,%p)\n", iface, palette);
|
|
|
|
|
|
|
|
EnterCriticalSection(&This->lock);
|
|
|
|
|
|
|
|
hr = This->stream ? WINCODEC_ERR_UNSUPPORTEDOPERATION : WINCODEC_ERR_NOTINITIALIZED;
|
|
|
|
|
|
|
|
LeaveCriticalSection(&This->lock);
|
|
|
|
|
|
|
|
return hr;
|
2011-03-29 21:56:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI TiffEncoder_SetThumbnail(IWICBitmapEncoder *iface, IWICBitmapSource *pIThumbnail)
|
|
|
|
{
|
|
|
|
TRACE("(%p,%p)\n", iface, pIThumbnail);
|
|
|
|
return WINCODEC_ERR_UNSUPPORTEDOPERATION;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI TiffEncoder_SetPreview(IWICBitmapEncoder *iface, IWICBitmapSource *pIPreview)
|
|
|
|
{
|
|
|
|
TRACE("(%p,%p)\n", iface, pIPreview);
|
|
|
|
return WINCODEC_ERR_UNSUPPORTEDOPERATION;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI TiffEncoder_CreateNewFrame(IWICBitmapEncoder *iface,
|
|
|
|
IWICBitmapFrameEncode **ppIFrameEncode, IPropertyBag2 **ppIEncoderOptions)
|
|
|
|
{
|
2011-03-29 23:24:19 +02:00
|
|
|
TiffEncoder *This = impl_from_IWICBitmapEncoder(iface);
|
|
|
|
TiffFrameEncode *result;
|
2018-02-05 17:59:32 +01:00
|
|
|
static const PROPBAG2 opts[2] =
|
|
|
|
{
|
|
|
|
{ PROPBAG2_TYPE_DATA, VT_UI1, 0, 0, (LPOLESTR)wszTiffCompressionMethod },
|
|
|
|
{ PROPBAG2_TYPE_DATA, VT_R4, 0, 0, (LPOLESTR)wszCompressionQuality },
|
|
|
|
};
|
2011-03-29 23:24:19 +02:00
|
|
|
HRESULT hr=S_OK;
|
|
|
|
|
|
|
|
TRACE("(%p,%p,%p)\n", iface, ppIFrameEncode, ppIEncoderOptions);
|
|
|
|
|
|
|
|
EnterCriticalSection(&This->lock);
|
|
|
|
|
2011-04-05 23:27:28 +02:00
|
|
|
if (!This->initialized || This->committed)
|
|
|
|
{
|
|
|
|
hr = WINCODEC_ERR_WRONGSTATE;
|
|
|
|
}
|
|
|
|
else if (This->num_frames != This->num_frames_committed)
|
2011-03-29 23:24:19 +02:00
|
|
|
{
|
|
|
|
FIXME("New frame created before previous frame was committed\n");
|
|
|
|
hr = E_FAIL;
|
|
|
|
}
|
|
|
|
|
2018-02-05 17:59:33 +01:00
|
|
|
if (ppIEncoderOptions && SUCCEEDED(hr))
|
2011-03-29 23:24:19 +02:00
|
|
|
{
|
2018-02-05 17:59:32 +01:00
|
|
|
hr = CreatePropertyBag2(opts, sizeof(opts)/sizeof(opts[0]), ppIEncoderOptions);
|
2013-04-01 22:28:12 +02:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
VARIANT v;
|
|
|
|
VariantInit(&v);
|
|
|
|
V_VT(&v) = VT_UI1;
|
|
|
|
V_UNION(&v, bVal) = WICTiffCompressionDontCare;
|
2018-02-05 17:59:32 +01:00
|
|
|
hr = IPropertyBag2_Write(*ppIEncoderOptions, 1, (PROPBAG2 *)opts, &v);
|
2013-04-01 22:28:12 +02:00
|
|
|
VariantClear(&v);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
IPropertyBag2_Release(*ppIEncoderOptions);
|
|
|
|
*ppIEncoderOptions = NULL;
|
|
|
|
}
|
|
|
|
}
|
2011-03-29 23:24:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
result = HeapAlloc(GetProcessHeap(), 0, sizeof(*result));
|
|
|
|
|
|
|
|
if (result)
|
|
|
|
{
|
|
|
|
result->IWICBitmapFrameEncode_iface.lpVtbl = &TiffFrameEncode_Vtbl;
|
|
|
|
result->ref = 1;
|
|
|
|
result->parent = This;
|
2011-03-29 23:30:59 +02:00
|
|
|
result->initialized = FALSE;
|
2011-04-05 19:09:25 +02:00
|
|
|
result->info_written = FALSE;
|
2011-04-05 23:06:54 +02:00
|
|
|
result->committed = FALSE;
|
2011-04-05 19:09:25 +02:00
|
|
|
result->format = NULL;
|
2011-04-05 19:15:42 +02:00
|
|
|
result->width = 0;
|
|
|
|
result->height = 0;
|
2011-04-05 21:37:05 +02:00
|
|
|
result->xres = 0.0;
|
|
|
|
result->yres = 0.0;
|
2011-04-05 22:55:16 +02:00
|
|
|
result->lines_written = 0;
|
2017-09-13 22:12:41 +02:00
|
|
|
result->colors = 0;
|
2011-03-29 23:24:19 +02:00
|
|
|
|
|
|
|
IWICBitmapEncoder_AddRef(iface);
|
|
|
|
*ppIFrameEncode = &result->IWICBitmapFrameEncode_iface;
|
|
|
|
|
|
|
|
if (This->num_frames != 0)
|
|
|
|
pTIFFWriteDirectory(This->tiff);
|
|
|
|
|
|
|
|
This->num_frames++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
hr = E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
IPropertyBag2_Release(*ppIEncoderOptions);
|
|
|
|
*ppIEncoderOptions = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LeaveCriticalSection(&This->lock);
|
|
|
|
|
|
|
|
return hr;
|
2011-03-29 21:56:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI TiffEncoder_Commit(IWICBitmapEncoder *iface)
|
|
|
|
{
|
2011-04-05 23:27:28 +02:00
|
|
|
TiffEncoder *This = impl_from_IWICBitmapEncoder(iface);
|
|
|
|
|
|
|
|
TRACE("(%p)\n", iface);
|
|
|
|
|
|
|
|
EnterCriticalSection(&This->lock);
|
|
|
|
|
|
|
|
if (!This->initialized || This->committed)
|
|
|
|
{
|
|
|
|
LeaveCriticalSection(&This->lock);
|
|
|
|
return WINCODEC_ERR_WRONGSTATE;
|
|
|
|
}
|
|
|
|
|
|
|
|
pTIFFClose(This->tiff);
|
|
|
|
IStream_Release(This->stream);
|
|
|
|
This->stream = NULL;
|
|
|
|
This->tiff = NULL;
|
|
|
|
|
|
|
|
This->committed = TRUE;
|
|
|
|
|
|
|
|
LeaveCriticalSection(&This->lock);
|
|
|
|
|
|
|
|
return S_OK;
|
2011-03-29 21:56:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI TiffEncoder_GetMetadataQueryWriter(IWICBitmapEncoder *iface,
|
|
|
|
IWICMetadataQueryWriter **ppIMetadataQueryWriter)
|
|
|
|
{
|
|
|
|
FIXME("(%p,%p): stub\n", iface, ppIMetadataQueryWriter);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IWICBitmapEncoderVtbl TiffEncoder_Vtbl = {
|
|
|
|
TiffEncoder_QueryInterface,
|
|
|
|
TiffEncoder_AddRef,
|
|
|
|
TiffEncoder_Release,
|
|
|
|
TiffEncoder_Initialize,
|
|
|
|
TiffEncoder_GetContainerFormat,
|
|
|
|
TiffEncoder_GetEncoderInfo,
|
|
|
|
TiffEncoder_SetColorContexts,
|
|
|
|
TiffEncoder_SetPalette,
|
|
|
|
TiffEncoder_SetThumbnail,
|
|
|
|
TiffEncoder_SetPreview,
|
|
|
|
TiffEncoder_CreateNewFrame,
|
|
|
|
TiffEncoder_Commit,
|
|
|
|
TiffEncoder_GetMetadataQueryWriter
|
|
|
|
};
|
|
|
|
|
2014-01-14 12:18:11 +01:00
|
|
|
HRESULT TiffEncoder_CreateInstance(REFIID iid, void** ppv)
|
2011-03-29 21:56:30 +02:00
|
|
|
{
|
|
|
|
TiffEncoder *This;
|
|
|
|
HRESULT ret;
|
|
|
|
|
2014-01-14 12:18:11 +01:00
|
|
|
TRACE("(%s,%p)\n", debugstr_guid(iid), ppv);
|
2011-03-29 21:56:30 +02:00
|
|
|
|
|
|
|
*ppv = NULL;
|
|
|
|
|
|
|
|
if (!load_libtiff())
|
|
|
|
{
|
|
|
|
ERR("Failed writing TIFF because unable to load %s\n",SONAME_LIBTIFF);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
This = HeapAlloc(GetProcessHeap(), 0, sizeof(TiffEncoder));
|
|
|
|
if (!This) return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
This->IWICBitmapEncoder_iface.lpVtbl = &TiffEncoder_Vtbl;
|
|
|
|
This->ref = 1;
|
2011-03-29 22:04:26 +02:00
|
|
|
This->stream = NULL;
|
|
|
|
InitializeCriticalSection(&This->lock);
|
|
|
|
This->lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": TiffEncoder.lock");
|
|
|
|
This->tiff = NULL;
|
|
|
|
This->initialized = FALSE;
|
2011-03-29 23:24:19 +02:00
|
|
|
This->num_frames = 0;
|
|
|
|
This->num_frames_committed = 0;
|
2011-04-05 23:27:28 +02:00
|
|
|
This->committed = FALSE;
|
2011-03-29 21:56:30 +02:00
|
|
|
|
2012-07-24 08:18:16 +02:00
|
|
|
ret = IWICBitmapEncoder_QueryInterface(&This->IWICBitmapEncoder_iface, iid, ppv);
|
|
|
|
IWICBitmapEncoder_Release(&This->IWICBitmapEncoder_iface);
|
2011-03-29 21:56:30 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-03-09 00:07:29 +01:00
|
|
|
#else /* !SONAME_LIBTIFF */
|
|
|
|
|
2014-01-14 12:18:11 +01:00
|
|
|
HRESULT TiffDecoder_CreateInstance(REFIID iid, void** ppv)
|
2010-03-09 00:07:29 +01:00
|
|
|
{
|
|
|
|
ERR("Trying to load TIFF picture, but Wine was compiled without TIFF support.\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2014-01-14 12:18:11 +01:00
|
|
|
HRESULT TiffEncoder_CreateInstance(REFIID iid, void** ppv)
|
2011-03-29 21:56:30 +02:00
|
|
|
{
|
|
|
|
ERR("Trying to save TIFF picture, but Wine was compiled without TIFF support.\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2010-03-09 00:07:29 +01:00
|
|
|
#endif
|