nsiproxy: Implement IP compartment get_all_paramters.
[wine.git] / dlls / windowscodecs / libtiff.c
blob1489fbe85fabab98609841d063a98e5bf5cd85d1
1 /*
2 * Copyright 2010 Vincent Povirk for CodeWeavers
3 * Copyright 2016 Dmitry Timoshkov
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #if 0
21 #pragma makedep unix
22 #endif
24 #include "config.h"
25 #include "wine/port.h"
27 #include <stdarg.h>
28 #ifdef HAVE_UNISTD_H
29 #include <unistd.h>
30 #endif
31 #ifdef HAVE_TIFFIO_H
32 #include <stdint.h>
33 #include <tiffio.h>
34 #endif
36 #include "ntstatus.h"
37 #define WIN32_NO_STATUS
38 #include "windef.h"
39 #include "winternl.h"
40 #include "winbase.h"
41 #include "objbase.h"
43 #include "wincodecs_private.h"
45 #include "wine/debug.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(wincodecs);
49 #ifdef SONAME_LIBTIFF
51 /* Workaround for broken libtiff 4.x headers on some 64-bit hosts which
52 * define TIFF_UINT64_T/toff_t as 32-bit for 32-bit builds, while they
53 * are supposed to be always 64-bit.
54 * TIFF_UINT64_T doesn't exist in libtiff 3.x, it was introduced in 4.x.
56 #ifdef TIFF_UINT64_T
57 # undef toff_t
58 # define toff_t UINT64
59 #endif
61 static CRITICAL_SECTION init_tiff_cs;
62 static CRITICAL_SECTION_DEBUG init_tiff_cs_debug =
64 0, 0, &init_tiff_cs,
65 { &init_tiff_cs_debug.ProcessLocksList,
66 &init_tiff_cs_debug.ProcessLocksList },
67 0, 0, { (DWORD_PTR)(__FILE__ ": init_tiff_cs") }
69 static CRITICAL_SECTION init_tiff_cs = { &init_tiff_cs_debug, -1, 0, 0, 0, 0 };
71 static void *libtiff_handle;
72 #define MAKE_FUNCPTR(f) static typeof(f) * p##f
73 MAKE_FUNCPTR(TIFFClientOpen);
74 MAKE_FUNCPTR(TIFFClose);
75 MAKE_FUNCPTR(TIFFCurrentDirOffset);
76 MAKE_FUNCPTR(TIFFGetField);
77 MAKE_FUNCPTR(TIFFIsByteSwapped);
78 MAKE_FUNCPTR(TIFFNumberOfDirectories);
79 MAKE_FUNCPTR(TIFFReadDirectory);
80 MAKE_FUNCPTR(TIFFReadEncodedStrip);
81 MAKE_FUNCPTR(TIFFReadEncodedTile);
82 MAKE_FUNCPTR(TIFFSetDirectory);
83 MAKE_FUNCPTR(TIFFSetField);
84 MAKE_FUNCPTR(TIFFWriteDirectory);
85 MAKE_FUNCPTR(TIFFWriteScanline);
86 #undef MAKE_FUNCPTR
88 static void *load_libtiff(void)
90 void *result;
92 RtlEnterCriticalSection(&init_tiff_cs);
94 if (!libtiff_handle &&
95 (libtiff_handle = dlopen(SONAME_LIBTIFF, RTLD_NOW)) != NULL)
97 void * (*pTIFFSetWarningHandler)(void *);
98 void * (*pTIFFSetWarningHandlerExt)(void *);
100 #define LOAD_FUNCPTR(f) \
101 if((p##f = dlsym(libtiff_handle, #f)) == NULL) { \
102 ERR("failed to load symbol %s\n", #f); \
103 libtiff_handle = NULL; \
104 RtlLeaveCriticalSection(&init_tiff_cs); \
105 return NULL; \
107 LOAD_FUNCPTR(TIFFClientOpen);
108 LOAD_FUNCPTR(TIFFClose);
109 LOAD_FUNCPTR(TIFFCurrentDirOffset);
110 LOAD_FUNCPTR(TIFFGetField);
111 LOAD_FUNCPTR(TIFFIsByteSwapped);
112 LOAD_FUNCPTR(TIFFNumberOfDirectories);
113 LOAD_FUNCPTR(TIFFReadDirectory);
114 LOAD_FUNCPTR(TIFFReadEncodedStrip);
115 LOAD_FUNCPTR(TIFFReadEncodedTile);
116 LOAD_FUNCPTR(TIFFSetDirectory);
117 LOAD_FUNCPTR(TIFFSetField);
118 LOAD_FUNCPTR(TIFFWriteDirectory);
119 LOAD_FUNCPTR(TIFFWriteScanline);
120 #undef LOAD_FUNCPTR
122 if ((pTIFFSetWarningHandler = dlsym(libtiff_handle, "TIFFSetWarningHandler")))
123 pTIFFSetWarningHandler(NULL);
124 if ((pTIFFSetWarningHandlerExt = dlsym(libtiff_handle, "TIFFSetWarningHandlerExt")))
125 pTIFFSetWarningHandlerExt(NULL);
128 result = libtiff_handle;
130 RtlLeaveCriticalSection(&init_tiff_cs);
131 return result;
134 static tsize_t tiff_stream_read(thandle_t client_data, tdata_t data, tsize_t size)
136 IStream *stream = (IStream*)client_data;
137 ULONG bytes_read;
138 HRESULT hr;
140 hr = stream_read(stream, data, size, &bytes_read);
141 if (FAILED(hr)) bytes_read = 0;
142 return bytes_read;
145 static tsize_t tiff_stream_write(thandle_t client_data, tdata_t data, tsize_t size)
147 IStream *stream = (IStream*)client_data;
148 ULONG bytes_written;
149 HRESULT hr;
151 hr = stream_write(stream, data, size, &bytes_written);
152 if (FAILED(hr)) bytes_written = 0;
153 return bytes_written;
156 static toff_t tiff_stream_seek(thandle_t client_data, toff_t offset, int whence)
158 IStream *stream = (IStream*)client_data;
159 DWORD origin;
160 ULONGLONG new_position;
161 HRESULT hr;
163 switch (whence)
165 case SEEK_SET:
166 origin = STREAM_SEEK_SET;
167 break;
168 case SEEK_CUR:
169 origin = STREAM_SEEK_CUR;
170 break;
171 case SEEK_END:
172 origin = STREAM_SEEK_END;
173 break;
174 default:
175 ERR("unknown whence value %i\n", whence);
176 return -1;
179 hr = stream_seek(stream, offset, origin, &new_position);
180 if (SUCCEEDED(hr)) return new_position;
181 else return -1;
184 static int tiff_stream_close(thandle_t client_data)
186 /* Caller is responsible for releasing the stream object. */
187 return 0;
190 static toff_t tiff_stream_size(thandle_t client_data)
192 IStream *stream = (IStream*)client_data;
193 ULONGLONG size;
194 HRESULT hr;
196 hr = stream_getsize(stream, &size);
198 if (SUCCEEDED(hr)) return size;
199 else return -1;
202 static int tiff_stream_map(thandle_t client_data, tdata_t *addr, toff_t *size)
204 /* Cannot mmap streams */
205 return 0;
208 static void tiff_stream_unmap(thandle_t client_data, tdata_t addr, toff_t size)
210 /* No need to ever do this, since we can't map things. */
213 static TIFF* tiff_open_stream(IStream *stream, const char *mode)
215 stream_seek(stream, 0, STREAM_SEEK_SET, NULL);
217 return pTIFFClientOpen("<IStream object>", mode, stream, tiff_stream_read,
218 tiff_stream_write, (void *)tiff_stream_seek, tiff_stream_close,
219 (void *)tiff_stream_size, (void *)tiff_stream_map, (void *)tiff_stream_unmap);
222 typedef struct {
223 struct decoder_frame frame;
224 int bps;
225 int samples;
226 int source_bpp;
227 int planar;
228 int indexed;
229 int reverse_bgr;
230 int invert_grayscale;
231 UINT tile_width, tile_height;
232 UINT tile_stride;
233 UINT tile_size;
234 int tiled;
235 UINT tiles_across;
236 } tiff_decode_info;
238 struct tiff_decoder
240 struct decoder decoder;
241 IStream *stream;
242 TIFF *tiff;
243 DWORD frame_count;
244 DWORD cached_frame;
245 tiff_decode_info cached_decode_info;
246 INT cached_tile_x, cached_tile_y;
247 BYTE *cached_tile;
250 static inline struct tiff_decoder *impl_from_decoder(struct decoder* iface)
252 return CONTAINING_RECORD(iface, struct tiff_decoder, decoder);
255 static HRESULT tiff_get_decode_info(TIFF *tiff, tiff_decode_info *decode_info)
257 uint16_t photometric, bps, samples, planar;
258 uint16_t extra_sample_count, extra_sample, *extra_samples;
259 uint16_t *red, *green, *blue;
260 UINT resolution_unit;
261 float xres=0.0, yres=0.0;
262 int ret, i;
263 const BYTE *profile;
264 UINT len;
266 decode_info->indexed = 0;
267 decode_info->reverse_bgr = 0;
268 decode_info->invert_grayscale = 0;
269 decode_info->tiled = 0;
270 decode_info->source_bpp = 0;
272 ret = pTIFFGetField(tiff, TIFFTAG_PHOTOMETRIC, &photometric);
273 if (!ret)
275 WARN("missing PhotometricInterpretation tag\n");
276 return E_FAIL;
279 ret = pTIFFGetField(tiff, TIFFTAG_BITSPERSAMPLE, &bps);
280 if (!ret) bps = 1;
281 decode_info->bps = bps;
283 ret = pTIFFGetField(tiff, TIFFTAG_SAMPLESPERPIXEL, &samples);
284 if (!ret) samples = 1;
285 decode_info->samples = samples;
287 if (samples == 1)
288 planar = 1;
289 else
291 ret = pTIFFGetField(tiff, TIFFTAG_PLANARCONFIG, &planar);
292 if (!ret) planar = 1;
293 if (planar != 1)
295 FIXME("unhandled planar configuration %u\n", planar);
296 return E_FAIL;
299 decode_info->planar = planar;
301 TRACE("planar %u, photometric %u, samples %u, bps %u\n", planar, photometric, samples, bps);
303 switch(photometric)
305 case 0: /* WhiteIsZero */
306 decode_info->invert_grayscale = 1;
307 /* fall through */
308 case 1: /* BlackIsZero */
309 if (samples == 2)
311 ret = pTIFFGetField(tiff, TIFFTAG_EXTRASAMPLES, &extra_sample_count, &extra_samples);
312 if (!ret)
314 extra_sample_count = 1;
315 extra_sample = 0;
316 extra_samples = &extra_sample;
319 else if (samples != 1)
321 FIXME("unhandled %dbpp sample count %u\n", bps, samples);
322 return E_FAIL;
325 decode_info->frame.bpp = bps * samples;
326 decode_info->source_bpp = decode_info->frame.bpp;
327 switch (bps)
329 case 1:
330 if (samples != 1)
332 FIXME("unhandled 1bpp sample count %u\n", samples);
333 return E_FAIL;
335 decode_info->frame.pixel_format = GUID_WICPixelFormatBlackWhite;
336 break;
337 case 4:
338 if (samples != 1)
340 FIXME("unhandled 4bpp grayscale sample count %u\n", samples);
341 return E_FAIL;
343 decode_info->frame.pixel_format = GUID_WICPixelFormat4bppGray;
344 break;
345 case 8:
346 if (samples == 1)
347 decode_info->frame.pixel_format = GUID_WICPixelFormat8bppGray;
348 else
350 decode_info->frame.bpp = 32;
352 switch(extra_samples[0])
354 case 1: /* Associated (pre-multiplied) alpha data */
355 decode_info->frame.pixel_format = GUID_WICPixelFormat32bppPBGRA;
356 break;
357 case 0: /* Unspecified data */
358 case 2: /* Unassociated alpha data */
359 decode_info->frame.pixel_format = GUID_WICPixelFormat32bppBGRA;
360 break;
361 default:
362 FIXME("unhandled extra sample type %u\n", extra_samples[0]);
363 return E_FAIL;
366 break;
367 case 16:
368 if (samples != 1)
370 FIXME("unhandled 16bpp grayscale sample count %u\n", samples);
371 return WINCODEC_ERR_UNSUPPORTEDPIXELFORMAT;
373 decode_info->frame.pixel_format = GUID_WICPixelFormat16bppGray;
374 break;
375 case 32:
376 if (samples != 1)
378 FIXME("unhandled 32bpp grayscale sample count %u\n", samples);
379 return WINCODEC_ERR_UNSUPPORTEDPIXELFORMAT;
381 decode_info->frame.pixel_format = GUID_WICPixelFormat32bppGrayFloat;
382 break;
383 default:
384 WARN("unhandled greyscale bit count %u\n", bps);
385 return WINCODEC_ERR_UNSUPPORTEDPIXELFORMAT;
387 break;
388 case 2: /* RGB */
389 if (samples == 4)
391 ret = pTIFFGetField(tiff, TIFFTAG_EXTRASAMPLES, &extra_sample_count, &extra_samples);
392 if (!ret)
394 extra_sample_count = 1;
395 extra_sample = 0;
396 extra_samples = &extra_sample;
399 else if (samples != 3)
401 FIXME("unhandled RGB sample count %u\n", samples);
402 return E_FAIL;
405 decode_info->frame.bpp = max(bps, 8) * samples;
406 decode_info->source_bpp = bps * samples;
407 switch(bps)
409 case 1:
410 case 4:
411 case 8:
412 decode_info->reverse_bgr = 1;
413 if (samples == 3)
414 decode_info->frame.pixel_format = GUID_WICPixelFormat24bppBGR;
415 else
416 switch(extra_samples[0])
418 case 1: /* Associated (pre-multiplied) alpha data */
419 decode_info->frame.pixel_format = GUID_WICPixelFormat32bppPBGRA;
420 break;
421 case 0: /* Unspecified data */
422 case 2: /* Unassociated alpha data */
423 decode_info->frame.pixel_format = GUID_WICPixelFormat32bppBGRA;
424 break;
425 default:
426 FIXME("unhandled extra sample type %i\n", extra_samples[0]);
427 return E_FAIL;
429 break;
430 case 16:
431 if (samples == 3)
432 decode_info->frame.pixel_format = GUID_WICPixelFormat48bppRGB;
433 else
434 switch(extra_samples[0])
436 case 1: /* Associated (pre-multiplied) alpha data */
437 decode_info->frame.pixel_format = GUID_WICPixelFormat64bppPRGBA;
438 break;
439 case 0: /* Unspecified data */
440 case 2: /* Unassociated alpha data */
441 decode_info->frame.pixel_format = GUID_WICPixelFormat64bppRGBA;
442 break;
443 default:
444 FIXME("unhandled extra sample type %i\n", extra_samples[0]);
445 return E_FAIL;
447 break;
448 case 32:
449 if (samples == 3)
450 decode_info->frame.pixel_format = GUID_WICPixelFormat96bppRGBFloat;
451 else
452 switch(extra_samples[0])
454 case 1: /* Associated (pre-multiplied) alpha data */
455 decode_info->frame.pixel_format = GUID_WICPixelFormat128bppPRGBAFloat;
456 break;
457 case 0: /* Unspecified data */
458 case 2: /* Unassociated alpha data */
459 decode_info->frame.pixel_format = GUID_WICPixelFormat128bppRGBAFloat;
460 break;
461 default:
462 FIXME("unhandled extra sample type %i\n", extra_samples[0]);
463 return E_FAIL;
465 break;
466 default:
467 WARN("unhandled RGB bit count %u\n", bps);
468 return WINCODEC_ERR_UNSUPPORTEDPIXELFORMAT;
470 break;
471 case 3: /* RGB Palette */
472 if (samples != 1)
474 FIXME("unhandled indexed sample count %u\n", samples);
475 return E_FAIL;
478 decode_info->indexed = 1;
479 decode_info->frame.bpp = bps;
480 switch (bps)
482 case 1:
483 decode_info->frame.pixel_format = GUID_WICPixelFormat1bppIndexed;
484 break;
485 case 2:
486 decode_info->frame.pixel_format = GUID_WICPixelFormat2bppIndexed;
487 break;
488 case 4:
489 decode_info->frame.pixel_format = GUID_WICPixelFormat4bppIndexed;
490 break;
491 case 8:
492 decode_info->frame.pixel_format = GUID_WICPixelFormat8bppIndexed;
493 break;
494 default:
495 FIXME("unhandled indexed bit count %u\n", bps);
496 return E_NOTIMPL;
498 break;
500 case 5: /* Separated */
501 if (samples != 4)
503 FIXME("unhandled Separated sample count %u\n", samples);
504 return E_FAIL;
507 decode_info->frame.bpp = bps * samples;
508 switch(bps)
510 case 8:
511 decode_info->frame.pixel_format = GUID_WICPixelFormat32bppCMYK;
512 break;
513 case 16:
514 decode_info->frame.pixel_format = GUID_WICPixelFormat64bppCMYK;
515 break;
517 default:
518 WARN("unhandled Separated bit count %u\n", bps);
519 return WINCODEC_ERR_UNSUPPORTEDPIXELFORMAT;
521 break;
523 case 4: /* Transparency mask */
524 case 6: /* YCbCr */
525 case 8: /* CIELab */
526 default:
527 FIXME("unhandled PhotometricInterpretation %u\n", photometric);
528 return E_FAIL;
531 ret = pTIFFGetField(tiff, TIFFTAG_IMAGEWIDTH, &decode_info->frame.width);
532 if (!ret)
534 WARN("missing image width\n");
535 return E_FAIL;
538 ret = pTIFFGetField(tiff, TIFFTAG_IMAGELENGTH, &decode_info->frame.height);
539 if (!ret)
541 WARN("missing image length\n");
542 return E_FAIL;
545 if ((ret = pTIFFGetField(tiff, TIFFTAG_TILEWIDTH, &decode_info->tile_width)))
547 decode_info->tiled = 1;
549 ret = pTIFFGetField(tiff, TIFFTAG_TILELENGTH, &decode_info->tile_height);
550 if (!ret)
552 WARN("missing tile height\n");
553 return E_FAIL;
556 decode_info->tile_stride = ((decode_info->frame.bpp * decode_info->tile_width + 7)/8);
557 decode_info->tile_size = decode_info->tile_height * decode_info->tile_stride;
558 decode_info->tiles_across = (decode_info->frame.width + decode_info->tile_width - 1) / decode_info->tile_width;
560 else if ((ret = pTIFFGetField(tiff, TIFFTAG_ROWSPERSTRIP, &decode_info->tile_height)))
562 if (decode_info->tile_height > decode_info->frame.height)
563 decode_info->tile_height = decode_info->frame.height;
564 decode_info->tile_width = decode_info->frame.width;
565 decode_info->tile_stride = ((decode_info->frame.bpp * decode_info->tile_width + 7)/8);
566 decode_info->tile_size = decode_info->tile_height * decode_info->tile_stride;
568 else
570 /* Some broken TIFF files have a single strip and lack the RowsPerStrip tag */
571 decode_info->tile_height = decode_info->frame.height;
572 decode_info->tile_width = decode_info->frame.width;
573 decode_info->tile_stride = ((decode_info->frame.bpp * decode_info->tile_width + 7)/8);
574 decode_info->tile_size = decode_info->tile_height * decode_info->tile_stride;
577 resolution_unit = 0;
578 pTIFFGetField(tiff, TIFFTAG_RESOLUTIONUNIT, &resolution_unit);
580 ret = pTIFFGetField(tiff, TIFFTAG_XRESOLUTION, &xres);
581 if (!ret)
583 WARN("missing X resolution\n");
585 /* Emulate the behavior of current libtiff versions (libtiff commit a39f6131)
586 * yielding 0 instead of INFINITY for IFD_RATIONAL fields with denominator 0. */
587 if (!isfinite(xres))
589 xres = 0.0;
592 ret = pTIFFGetField(tiff, TIFFTAG_YRESOLUTION, &yres);
593 if (!ret)
595 WARN("missing Y resolution\n");
597 if (!isfinite(yres))
599 yres = 0.0;
602 if (xres == 0.0 || yres == 0.0)
604 decode_info->frame.dpix = decode_info->frame.dpiy = 96.0;
606 else
608 switch (resolution_unit)
610 default:
611 FIXME("unknown resolution unit %i\n", resolution_unit);
612 /* fall through */
613 case 0: /* Not set */
614 case 1: /* Relative measurements */
615 case 2: /* Inch */
616 decode_info->frame.dpix = xres;
617 decode_info->frame.dpiy = yres;
618 break;
619 case 3: /* Centimeter */
620 decode_info->frame.dpix = xres * 2.54;
621 decode_info->frame.dpiy = yres * 2.54;
622 break;
626 if (decode_info->indexed &&
627 pTIFFGetField(tiff, TIFFTAG_COLORMAP, &red, &green, &blue))
629 decode_info->frame.num_colors = 1 << decode_info->bps;
630 for (i=0; i<decode_info->frame.num_colors; i++)
632 decode_info->frame.palette[i] = 0xff000000 |
633 ((red[i]<<8) & 0xff0000) |
634 (green[i] & 0xff00) |
635 ((blue[i]>>8) & 0xff);
638 else
640 decode_info->frame.num_colors = 0;
643 if (pTIFFGetField(tiff, TIFFTAG_ICCPROFILE, &len, &profile))
644 decode_info->frame.num_color_contexts = 1;
645 else
646 decode_info->frame.num_color_contexts = 0;
648 return S_OK;
651 static HRESULT CDECL tiff_decoder_initialize(struct decoder* iface, IStream *stream, struct decoder_stat *st)
653 struct tiff_decoder *This = impl_from_decoder(iface);
654 HRESULT hr;
656 This->tiff = tiff_open_stream(stream, "r");
657 if (!This->tiff)
658 return E_FAIL;
660 This->frame_count = pTIFFNumberOfDirectories(This->tiff);
661 This->cached_frame = 0;
662 hr = tiff_get_decode_info(This->tiff, &This->cached_decode_info);
663 if (FAILED(hr))
664 goto fail;
666 st->frame_count = This->frame_count;
667 st->flags = WICBitmapDecoderCapabilityCanDecodeAllImages |
668 WICBitmapDecoderCapabilityCanDecodeSomeImages |
669 WICBitmapDecoderCapabilityCanEnumerateMetadata;
670 return S_OK;
672 fail:
673 pTIFFClose(This->tiff);
674 This->tiff = NULL;
675 return hr;
678 static HRESULT tiff_decoder_select_frame(struct tiff_decoder* This, DWORD frame)
680 HRESULT hr;
681 UINT prev_tile_size;
682 int res;
684 if (frame >= This->frame_count)
685 return E_INVALIDARG;
687 if (This->cached_frame == frame)
688 return S_OK;
690 prev_tile_size = This->cached_tile ? This->cached_decode_info.tile_size : 0;
692 res = pTIFFSetDirectory(This->tiff, frame);
693 if (!res)
694 return E_INVALIDARG;
696 hr = tiff_get_decode_info(This->tiff, &This->cached_decode_info);
698 This->cached_tile_x = -1;
700 if (SUCCEEDED(hr))
702 This->cached_frame = frame;
703 if (This->cached_decode_info.tile_size > prev_tile_size)
705 free(This->cached_tile);
706 This->cached_tile = NULL;
709 else
711 /* Set an invalid value to ensure we'll refresh cached_decode_info before using it. */
712 This->cached_frame = This->frame_count;
713 free(This->cached_tile);
714 This->cached_tile = NULL;
717 return hr;
720 static HRESULT CDECL tiff_decoder_get_frame_info(struct decoder* iface, UINT frame, struct decoder_frame *info)
722 struct tiff_decoder *This = impl_from_decoder(iface);
723 HRESULT hr;
725 hr = tiff_decoder_select_frame(This, frame);
726 if (SUCCEEDED(hr))
728 *info = This->cached_decode_info.frame;
731 return hr;
734 static HRESULT tiff_decoder_read_tile(struct tiff_decoder *This, UINT tile_x, UINT tile_y)
736 tsize_t ret;
737 int swap_bytes;
738 tiff_decode_info *info = &This->cached_decode_info;
740 swap_bytes = pTIFFIsByteSwapped(This->tiff);
742 if (info->tiled)
743 ret = pTIFFReadEncodedTile(This->tiff, tile_x + tile_y * info->tiles_across, This->cached_tile, info->tile_size);
744 else
745 ret = pTIFFReadEncodedStrip(This->tiff, tile_y, This->cached_tile, info->tile_size);
747 if (ret == -1)
748 return E_FAIL;
750 /* 3bps RGB */
751 if (info->source_bpp == 3 && info->samples == 3 && info->frame.bpp == 24)
753 BYTE *srcdata, *src, *dst;
754 DWORD x, y, count, width_bytes = (info->tile_width * 3 + 7) / 8;
756 count = width_bytes * info->tile_height;
758 srcdata = malloc(count);
759 if (!srcdata) return E_OUTOFMEMORY;
760 memcpy(srcdata, This->cached_tile, count);
762 for (y = 0; y < info->tile_height; y++)
764 src = srcdata + y * width_bytes;
765 dst = This->cached_tile + y * info->tile_width * 3;
767 for (x = 0; x < info->tile_width; x += 8)
769 dst[2] = (src[0] & 0x80) ? 0xff : 0; /* R */
770 dst[1] = (src[0] & 0x40) ? 0xff : 0; /* G */
771 dst[0] = (src[0] & 0x20) ? 0xff : 0; /* B */
772 if (x + 1 < info->tile_width)
774 dst[5] = (src[0] & 0x10) ? 0xff : 0; /* R */
775 dst[4] = (src[0] & 0x08) ? 0xff : 0; /* G */
776 dst[3] = (src[0] & 0x04) ? 0xff : 0; /* B */
778 if (x + 2 < info->tile_width)
780 dst[8] = (src[0] & 0x02) ? 0xff : 0; /* R */
781 dst[7] = (src[0] & 0x01) ? 0xff : 0; /* G */
782 dst[6] = (src[1] & 0x80) ? 0xff : 0; /* B */
784 if (x + 3 < info->tile_width)
786 dst[11] = (src[1] & 0x40) ? 0xff : 0; /* R */
787 dst[10] = (src[1] & 0x20) ? 0xff : 0; /* G */
788 dst[9] = (src[1] & 0x10) ? 0xff : 0; /* B */
790 if (x + 4 < info->tile_width)
792 dst[14] = (src[1] & 0x08) ? 0xff : 0; /* R */
793 dst[13] = (src[1] & 0x04) ? 0xff : 0; /* G */
794 dst[12] = (src[1] & 0x02) ? 0xff : 0; /* B */
796 if (x + 5 < info->tile_width)
798 dst[17] = (src[1] & 0x01) ? 0xff : 0; /* R */
799 dst[16] = (src[2] & 0x80) ? 0xff : 0; /* G */
800 dst[15] = (src[2] & 0x40) ? 0xff : 0; /* B */
802 if (x + 6 < info->tile_width)
804 dst[20] = (src[2] & 0x20) ? 0xff : 0; /* R */
805 dst[19] = (src[2] & 0x10) ? 0xff : 0; /* G */
806 dst[18] = (src[2] & 0x08) ? 0xff : 0; /* B */
808 if (x + 7 < info->tile_width)
810 dst[23] = (src[2] & 0x04) ? 0xff : 0; /* R */
811 dst[22] = (src[2] & 0x02) ? 0xff : 0; /* G */
812 dst[21] = (src[2] & 0x01) ? 0xff : 0; /* B */
814 src += 3;
815 dst += 24;
819 free(srcdata);
821 /* 12bps RGB */
822 else if (info->source_bpp == 12 && info->samples == 3 && info->frame.bpp == 24)
824 BYTE *srcdata, *src, *dst;
825 DWORD x, y, count, width_bytes = (info->tile_width * 12 + 7) / 8;
827 count = width_bytes * info->tile_height;
829 srcdata = malloc(count);
830 if (!srcdata) return E_OUTOFMEMORY;
831 memcpy(srcdata, This->cached_tile, count);
833 for (y = 0; y < info->tile_height; y++)
835 src = srcdata + y * width_bytes;
836 dst = This->cached_tile + y * info->tile_width * 3;
838 for (x = 0; x < info->tile_width; x += 2)
840 dst[0] = ((src[1] & 0xf0) >> 4) * 17; /* B */
841 dst[1] = (src[0] & 0x0f) * 17; /* G */
842 dst[2] = ((src[0] & 0xf0) >> 4) * 17; /* R */
843 if (x + 1 < info->tile_width)
845 dst[5] = (src[1] & 0x0f) * 17; /* B */
846 dst[4] = ((src[2] & 0xf0) >> 4) * 17; /* G */
847 dst[3] = (src[2] & 0x0f) * 17; /* R */
849 src += 3;
850 dst += 6;
854 free(srcdata);
856 /* 4bps RGBA */
857 else if (info->source_bpp == 4 && info->samples == 4 && info->frame.bpp == 32)
859 BYTE *srcdata, *src, *dst;
860 DWORD x, y, count, width_bytes = (info->tile_width * 3 + 7) / 8;
862 count = width_bytes * info->tile_height;
864 srcdata = malloc(count);
865 if (!srcdata) return E_OUTOFMEMORY;
866 memcpy(srcdata, This->cached_tile, count);
868 for (y = 0; y < info->tile_height; y++)
870 src = srcdata + y * width_bytes;
871 dst = This->cached_tile + y * info->tile_width * 4;
873 /* 1 source byte expands to 2 BGRA samples */
875 for (x = 0; x < info->tile_width; x += 2)
877 dst[0] = (src[0] & 0x20) ? 0xff : 0; /* B */
878 dst[1] = (src[0] & 0x40) ? 0xff : 0; /* G */
879 dst[2] = (src[0] & 0x80) ? 0xff : 0; /* R */
880 dst[3] = (src[0] & 0x10) ? 0xff : 0; /* A */
881 if (x + 1 < info->tile_width)
883 dst[4] = (src[0] & 0x02) ? 0xff : 0; /* B */
884 dst[5] = (src[0] & 0x04) ? 0xff : 0; /* G */
885 dst[6] = (src[0] & 0x08) ? 0xff : 0; /* R */
886 dst[7] = (src[0] & 0x01) ? 0xff : 0; /* A */
888 src++;
889 dst += 8;
893 free(srcdata);
895 /* 16bps RGBA */
896 else if (info->source_bpp == 16 && info->samples == 4 && info->frame.bpp == 32)
898 BYTE *srcdata, *src, *dst;
899 DWORD x, y, count, width_bytes = (info->tile_width * 12 + 7) / 8;
901 count = width_bytes * info->tile_height;
903 srcdata = malloc(count);
904 if (!srcdata) return E_OUTOFMEMORY;
905 memcpy(srcdata, This->cached_tile, count);
907 for (y = 0; y < info->tile_height; y++)
909 src = srcdata + y * width_bytes;
910 dst = This->cached_tile + y * info->tile_width * 4;
912 for (x = 0; x < info->tile_width; x++)
914 dst[0] = ((src[1] & 0xf0) >> 4) * 17; /* B */
915 dst[1] = (src[0] & 0x0f) * 17; /* G */
916 dst[2] = ((src[0] & 0xf0) >> 4) * 17; /* R */
917 dst[3] = (src[1] & 0x0f) * 17; /* A */
918 src += 2;
919 dst += 4;
923 free(srcdata);
925 /* 8bpp grayscale with extra alpha */
926 else if (info->source_bpp == 16 && info->samples == 2 && info->frame.bpp == 32)
928 BYTE *src;
929 DWORD *dst, count = info->tile_width * info->tile_height;
931 src = This->cached_tile + info->tile_width * info->tile_height * 2 - 2;
932 dst = (DWORD *)(This->cached_tile + info->tile_size - 4);
934 while (count--)
936 *dst-- = src[0] | (src[0] << 8) | (src[0] << 16) | (src[1] << 24);
937 src -= 2;
941 if (info->reverse_bgr)
943 if (info->bps == 8)
945 UINT sample_count = info->samples;
947 reverse_bgr8(sample_count, This->cached_tile, info->tile_width,
948 info->tile_height, info->tile_width * sample_count);
952 if (swap_bytes && info->bps > 8)
954 UINT row, i, samples_per_row;
955 BYTE *sample, temp;
957 samples_per_row = info->tile_width * info->samples;
959 switch(info->bps)
961 case 16:
962 for (row=0; row<info->tile_height; row++)
964 sample = This->cached_tile + row * info->tile_stride;
965 for (i=0; i<samples_per_row; i++)
967 temp = sample[1];
968 sample[1] = sample[0];
969 sample[0] = temp;
970 sample += 2;
973 break;
974 default:
975 ERR("unhandled bps for byte swap %u\n", info->bps);
976 return E_FAIL;
980 if (info->invert_grayscale)
982 BYTE *byte, *end;
984 if (info->samples != 1)
986 ERR("cannot invert grayscale image with %u samples\n", info->samples);
987 return E_FAIL;
990 end = This->cached_tile+info->tile_size;
992 for (byte = This->cached_tile; byte != end; byte++)
993 *byte = ~(*byte);
996 This->cached_tile_x = tile_x;
997 This->cached_tile_y = tile_y;
999 return S_OK;
1002 static HRESULT CDECL tiff_decoder_copy_pixels(struct decoder* iface, UINT frame,
1003 const WICRect *prc, UINT stride, UINT buffersize, BYTE *buffer)
1005 struct tiff_decoder *This = impl_from_decoder(iface);
1006 HRESULT hr;
1007 UINT min_tile_x, max_tile_x, min_tile_y, max_tile_y;
1008 UINT tile_x, tile_y;
1009 BYTE *dst_tilepos;
1010 WICRect rc;
1011 tiff_decode_info *info = &This->cached_decode_info;
1013 hr = tiff_decoder_select_frame(This, frame);
1014 if (FAILED(hr))
1015 return hr;
1017 if (!This->cached_tile)
1019 This->cached_tile = malloc(info->tile_size);
1020 if (!This->cached_tile)
1021 return E_OUTOFMEMORY;
1024 min_tile_x = prc->X / info->tile_width;
1025 min_tile_y = prc->Y / info->tile_height;
1026 max_tile_x = (prc->X+prc->Width-1) / info->tile_width;
1027 max_tile_y = (prc->Y+prc->Height-1) / info->tile_height;
1029 for (tile_x=min_tile_x; tile_x <= max_tile_x; tile_x++)
1031 for (tile_y=min_tile_y; tile_y <= max_tile_y; tile_y++)
1033 if (tile_x != This->cached_tile_x || tile_y != This->cached_tile_y)
1035 hr = tiff_decoder_read_tile(This, tile_x, tile_y);
1038 if (SUCCEEDED(hr))
1040 if (prc->X < tile_x * info->tile_width)
1041 rc.X = 0;
1042 else
1043 rc.X = prc->X - tile_x * info->tile_width;
1045 if (prc->Y < tile_y * info->tile_height)
1046 rc.Y = 0;
1047 else
1048 rc.Y = prc->Y - tile_y * info->tile_height;
1050 if (prc->X+prc->Width > (tile_x+1) * info->tile_width)
1051 rc.Width = info->tile_width - rc.X;
1052 else if (prc->X < tile_x * info->tile_width)
1053 rc.Width = prc->Width + prc->X - tile_x * info->tile_width;
1054 else
1055 rc.Width = prc->Width;
1057 if (prc->Y+prc->Height > (tile_y+1) * info->tile_height)
1058 rc.Height = info->tile_height - rc.Y;
1059 else if (prc->Y < tile_y * info->tile_height)
1060 rc.Height = prc->Height + prc->Y - tile_y * info->tile_height;
1061 else
1062 rc.Height = prc->Height;
1064 dst_tilepos = buffer + (stride * ((rc.Y + tile_y * info->tile_height) - prc->Y)) +
1065 ((info->frame.bpp * ((rc.X + tile_x * info->tile_width) - prc->X) + 7) / 8);
1067 hr = copy_pixels(info->frame.bpp, This->cached_tile,
1068 info->tile_width, info->tile_height, info->tile_stride,
1069 &rc, stride, buffersize, dst_tilepos);
1072 if (FAILED(hr))
1074 TRACE("<-- 0x%x\n", hr);
1075 return hr;
1080 return S_OK;
1083 static HRESULT CDECL tiff_decoder_get_color_context(struct decoder *iface,
1084 UINT frame, UINT num, BYTE **data, DWORD *datasize)
1086 struct tiff_decoder *This = impl_from_decoder(iface);
1087 const BYTE *profile;
1088 UINT len;
1089 HRESULT hr;
1091 hr = tiff_decoder_select_frame(This, frame);
1092 if (FAILED(hr))
1093 return hr;
1095 if (!pTIFFGetField(This->tiff, TIFFTAG_ICCPROFILE, &len, &profile))
1097 return E_UNEXPECTED;
1100 *datasize = len;
1101 *data = RtlAllocateHeap(GetProcessHeap(), 0, len);
1102 if (!*data)
1103 return E_OUTOFMEMORY;
1105 memcpy(*data, profile, len);
1107 return S_OK;
1110 static HRESULT CDECL tiff_decoder_get_metadata_blocks(struct decoder *iface,
1111 UINT frame, UINT *count, struct decoder_block **blocks)
1113 struct tiff_decoder *This = impl_from_decoder(iface);
1114 HRESULT hr;
1115 BOOL byte_swapped;
1116 struct decoder_block result;
1118 hr = tiff_decoder_select_frame(This, frame);
1119 if (FAILED(hr))
1120 return hr;
1122 *count = 1;
1124 result.offset = pTIFFCurrentDirOffset(This->tiff);
1125 result.length = 0;
1127 byte_swapped = pTIFFIsByteSwapped(This->tiff);
1128 #ifdef WORDS_BIGENDIAN
1129 result.options = byte_swapped ? WICPersistOptionLittleEndian : WICPersistOptionBigEndian;
1130 #else
1131 result.options = byte_swapped ? WICPersistOptionBigEndian : WICPersistOptionLittleEndian;
1132 #endif
1133 result.options |= WICPersistOptionNoCacheStream|DECODER_BLOCK_FULL_STREAM|DECODER_BLOCK_READER_CLSID;
1134 result.reader_clsid = CLSID_WICIfdMetadataReader;
1136 *blocks = RtlAllocateHeap(GetProcessHeap(), 0, sizeof(**blocks));
1137 **blocks = result;
1139 return S_OK;
1142 static void CDECL tiff_decoder_destroy(struct decoder* iface)
1144 struct tiff_decoder *This = impl_from_decoder(iface);
1145 if (This->tiff) pTIFFClose(This->tiff);
1146 free(This->cached_tile);
1147 RtlFreeHeap(GetProcessHeap(), 0, This);
1150 static const struct decoder_funcs tiff_decoder_vtable = {
1151 tiff_decoder_initialize,
1152 tiff_decoder_get_frame_info,
1153 tiff_decoder_copy_pixels,
1154 tiff_decoder_get_metadata_blocks,
1155 tiff_decoder_get_color_context,
1156 tiff_decoder_destroy
1159 HRESULT CDECL tiff_decoder_create(struct decoder_info *info, struct decoder **result)
1161 struct tiff_decoder *This;
1163 if (!load_libtiff())
1165 ERR("Failed reading TIFF because unable to load %s\n",SONAME_LIBTIFF);
1166 return E_FAIL;
1169 This = RtlAllocateHeap(GetProcessHeap(), 0, sizeof(*This));
1170 if (!This) return E_OUTOFMEMORY;
1172 This->decoder.vtable = &tiff_decoder_vtable;
1173 This->tiff = NULL;
1174 This->cached_tile = NULL;
1175 This->cached_tile_x = -1;
1176 *result = &This->decoder;
1178 info->container_format = GUID_ContainerFormatTiff;
1179 info->block_format = GUID_ContainerFormatTiff;
1180 info->clsid = CLSID_WICTiffDecoder;
1182 return S_OK;
1185 struct tiff_encode_format {
1186 const WICPixelFormatGUID *guid;
1187 int photometric;
1188 int bps;
1189 int samples;
1190 int bpp;
1191 int extra_sample;
1192 int extra_sample_type;
1193 int reverse_bgr;
1194 int indexed;
1197 static const struct tiff_encode_format formats[] = {
1198 {&GUID_WICPixelFormat24bppBGR, 2, 8, 3, 24, 0, 0, 1},
1199 {&GUID_WICPixelFormat24bppRGB, 2, 8, 3, 24, 0, 0, 0},
1200 {&GUID_WICPixelFormatBlackWhite, 1, 1, 1, 1, 0, 0, 0},
1201 {&GUID_WICPixelFormat4bppGray, 1, 4, 1, 4, 0, 0, 0},
1202 {&GUID_WICPixelFormat8bppGray, 1, 8, 1, 8, 0, 0, 0},
1203 {&GUID_WICPixelFormat32bppBGRA, 2, 8, 4, 32, 1, 2, 1},
1204 {&GUID_WICPixelFormat32bppPBGRA, 2, 8, 4, 32, 1, 1, 1},
1205 {&GUID_WICPixelFormat48bppRGB, 2, 16, 3, 48, 0, 0, 0},
1206 {&GUID_WICPixelFormat64bppRGBA, 2, 16, 4, 64, 1, 2, 0},
1207 {&GUID_WICPixelFormat64bppPRGBA, 2, 16, 4, 64, 1, 1, 0},
1208 {&GUID_WICPixelFormat1bppIndexed, 3, 1, 1, 1, 0, 0, 0, 1},
1209 {&GUID_WICPixelFormat4bppIndexed, 3, 4, 1, 4, 0, 0, 0, 1},
1210 {&GUID_WICPixelFormat8bppIndexed, 3, 8, 1, 8, 0, 0, 0, 1},
1214 typedef struct tiff_encoder {
1215 struct encoder encoder;
1216 TIFF *tiff;
1217 const struct tiff_encode_format *format;
1218 struct encoder_frame encoder_frame;
1219 DWORD num_frames;
1220 DWORD lines_written;
1221 } tiff_encoder;
1223 static inline struct tiff_encoder *impl_from_encoder(struct encoder* iface)
1225 return CONTAINING_RECORD(iface, struct tiff_encoder, encoder);
1228 static HRESULT CDECL tiff_encoder_initialize(struct encoder* iface, IStream *stream)
1230 struct tiff_encoder* This = impl_from_encoder(iface);
1231 TIFF *tiff;
1233 tiff = tiff_open_stream(stream, "w");
1235 if (!tiff)
1236 return E_FAIL;
1238 This->tiff = tiff;
1240 return S_OK;
1243 static HRESULT CDECL tiff_encoder_get_supported_format(struct encoder *iface,
1244 GUID *pixel_format, DWORD *bpp, BOOL *indexed)
1246 int i;
1248 if (IsEqualGUID(pixel_format, &GUID_WICPixelFormat2bppIndexed))
1249 *pixel_format = GUID_WICPixelFormat4bppIndexed;
1251 for (i=0; formats[i].guid; i++)
1253 if (IsEqualGUID(formats[i].guid, pixel_format))
1254 break;
1257 if (!formats[i].guid) i = 0;
1259 *pixel_format = *formats[i].guid;
1260 *bpp = formats[i].bpp;
1261 *indexed = formats[i].indexed;
1263 return S_OK;
1266 static HRESULT CDECL tiff_encoder_create_frame(struct encoder* iface, const struct encoder_frame *frame)
1268 struct tiff_encoder* This = impl_from_encoder(iface);
1269 int i;
1271 if (This->num_frames != 0)
1272 pTIFFWriteDirectory(This->tiff);
1274 This->num_frames++;
1275 This->lines_written = 0;
1276 This->encoder_frame = *frame;
1278 for (i=0; formats[i].guid; i++)
1280 if (IsEqualGUID(formats[i].guid, &frame->pixel_format))
1281 break;
1284 This->format = &formats[i];
1286 pTIFFSetField(This->tiff, TIFFTAG_PHOTOMETRIC, (uint16_t)This->format->photometric);
1287 pTIFFSetField(This->tiff, TIFFTAG_PLANARCONFIG, (uint16_t)1);
1288 pTIFFSetField(This->tiff, TIFFTAG_BITSPERSAMPLE, (uint16_t)This->format->bps);
1289 pTIFFSetField(This->tiff, TIFFTAG_SAMPLESPERPIXEL, (uint16_t)This->format->samples);
1291 if (This->format->extra_sample)
1293 uint16_t extra_samples;
1294 extra_samples = This->format->extra_sample_type;
1296 pTIFFSetField(This->tiff, TIFFTAG_EXTRASAMPLES, (uint16_t)1, &extra_samples);
1299 pTIFFSetField(This->tiff, TIFFTAG_IMAGEWIDTH, (uint32_t)frame->width);
1300 pTIFFSetField(This->tiff, TIFFTAG_IMAGELENGTH, (uint32_t)frame->height);
1302 if (frame->dpix != 0.0 && frame->dpiy != 0.0)
1304 pTIFFSetField(This->tiff, TIFFTAG_RESOLUTIONUNIT, (uint16_t)2); /* Inch */
1305 pTIFFSetField(This->tiff, TIFFTAG_XRESOLUTION, (float)frame->dpix);
1306 pTIFFSetField(This->tiff, TIFFTAG_YRESOLUTION, (float)frame->dpiy);
1309 if (This->format->bpp <= 8 && frame->num_colors && This->format->indexed)
1311 uint16_t red[256], green[256], blue[256];
1312 UINT i;
1314 for (i = 0; i < frame->num_colors; i++)
1316 red[i] = (frame->palette[i] >> 8) & 0xff00;
1317 green[i] = frame->palette[i] & 0xff00;
1318 blue[i] = (frame->palette[i] << 8) & 0xff00;
1321 pTIFFSetField(This->tiff, TIFFTAG_COLORMAP, red, green, blue);
1324 return S_OK;
1327 static HRESULT CDECL tiff_encoder_write_lines(struct encoder* iface,
1328 BYTE *data, DWORD line_count, DWORD stride)
1330 struct tiff_encoder* This = impl_from_encoder(iface);
1331 BYTE *row_data, *swapped_data = NULL;
1332 UINT i, j, line_size;
1334 line_size = ((This->encoder_frame.width * This->format->bpp)+7)/8;
1336 if (This->format->reverse_bgr)
1338 swapped_data = malloc(line_size);
1339 if (!swapped_data)
1340 return E_OUTOFMEMORY;
1343 for (i=0; i<line_count; i++)
1345 row_data = data + i * stride;
1347 if (This->format->reverse_bgr && This->format->bps == 8)
1349 memcpy(swapped_data, row_data, line_size);
1350 for (j=0; j<line_size; j += This->format->samples)
1352 BYTE temp;
1353 temp = swapped_data[j];
1354 swapped_data[j] = swapped_data[j+2];
1355 swapped_data[j+2] = temp;
1357 row_data = swapped_data;
1360 pTIFFWriteScanline(This->tiff, (tdata_t)row_data, i+This->lines_written, 0);
1363 This->lines_written += line_count;
1365 return S_OK;
1368 static HRESULT CDECL tiff_encoder_commit_frame(struct encoder* iface)
1370 return S_OK;
1373 static HRESULT CDECL tiff_encoder_commit_file(struct encoder* iface)
1375 struct tiff_encoder* This = impl_from_encoder(iface);
1377 pTIFFClose(This->tiff);
1378 This->tiff = NULL;
1380 return S_OK;
1383 static void CDECL tiff_encoder_destroy(struct encoder* iface)
1385 struct tiff_encoder *This = impl_from_encoder(iface);
1387 if (This->tiff) pTIFFClose(This->tiff);
1388 RtlFreeHeap(GetProcessHeap(), 0, This);
1391 static const struct encoder_funcs tiff_encoder_vtable = {
1392 tiff_encoder_initialize,
1393 tiff_encoder_get_supported_format,
1394 tiff_encoder_create_frame,
1395 tiff_encoder_write_lines,
1396 tiff_encoder_commit_frame,
1397 tiff_encoder_commit_file,
1398 tiff_encoder_destroy
1401 HRESULT CDECL tiff_encoder_create(struct encoder_info *info, struct encoder **result)
1403 struct tiff_encoder *This;
1405 if (!load_libtiff())
1407 ERR("Failed writing TIFF because unable to load %s\n",SONAME_LIBTIFF);
1408 return E_FAIL;
1411 This = RtlAllocateHeap(GetProcessHeap(), 0, sizeof(*This));
1412 if (!This) return E_OUTOFMEMORY;
1414 This->encoder.vtable = &tiff_encoder_vtable;
1415 This->tiff = NULL;
1416 This->num_frames = 0;
1418 info->flags = ENCODER_FLAGS_MULTI_FRAME | ENCODER_FLAGS_SUPPORTS_METADATA;
1419 info->container_format = GUID_ContainerFormatTiff;
1420 info->clsid = CLSID_WICTiffEncoder;
1421 info->encoder_options[0] = ENCODER_OPTION_COMPRESSION_METHOD;
1422 info->encoder_options[1] = ENCODER_OPTION_COMPRESSION_QUALITY;
1423 info->encoder_options[2] = ENCODER_OPTION_END;
1425 *result = &This->encoder;
1427 return S_OK;
1430 #else /* !SONAME_LIBTIFF */
1432 HRESULT CDECL tiff_decoder_create(struct decoder_info *info, struct decoder **result)
1434 ERR("Trying to load TIFF picture, but Wine was compiled without TIFF support.\n");
1435 return E_FAIL;
1438 HRESULT CDECL tiff_encoder_create(struct encoder_info *info, struct encoder **result)
1440 ERR("Trying to save TIFF picture, but Wine was compiled without TIFF support.\n");
1441 return E_FAIL;
1444 #endif