windowscodecs: Add support for palette image formats to TIFF encoder.

Signed-off-by: Dmitry Timoshkov <dmitry@baikal.ru>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Dmitry Timoshkov 2018-12-06 12:05:53 +03:00 committed by Alexandre Julliard
parent 1d7da01ff1
commit d13d34d101
4 changed files with 36 additions and 6 deletions

View File

@ -182,7 +182,7 @@ HRESULT write_source(IWICBitmapFrameEncode *iface,
if (FAILED(hr))
{
ERR("Failed to convert source, target format %s, %#x\n", debugstr_guid(format), hr);
return hr;
return E_NOTIMPL;
}
stride = (bpp * width + 7)/8;

View File

@ -1211,6 +1211,8 @@ static GUID const * const tiff_decode_formats[] = {
&GUID_WICPixelFormatBlackWhite,
&GUID_WICPixelFormat4bppGray,
&GUID_WICPixelFormat8bppGray,
&GUID_WICPixelFormat1bppIndexed,
&GUID_WICPixelFormat2bppIndexed,
&GUID_WICPixelFormat4bppIndexed,
&GUID_WICPixelFormat8bppIndexed,
&GUID_WICPixelFormat24bppBGR,
@ -1370,6 +1372,9 @@ static GUID const * const tiff_encode_formats[] = {
&GUID_WICPixelFormatBlackWhite,
&GUID_WICPixelFormat4bppGray,
&GUID_WICPixelFormat8bppGray,
&GUID_WICPixelFormat1bppIndexed,
&GUID_WICPixelFormat4bppIndexed,
&GUID_WICPixelFormat8bppIndexed,
&GUID_WICPixelFormat24bppBGR,
&GUID_WICPixelFormat32bppBGRA,
&GUID_WICPixelFormat32bppPBGRA,

View File

@ -1510,8 +1510,6 @@ if (!strcmp(winetest_platform, "windows")) /* FIXME: enable once implemented in
test_encoder(&testdata_BlackWhite, &CLSID_WICTiffEncoder,
&testdata_BlackWhite, &CLSID_WICTiffDecoder, "TIFF encoder BlackWhite");
if (!strcmp(winetest_platform, "windows")) /* FIXME: enable once implemented in Wine */
{
test_encoder(&testdata_1bppIndexed, &CLSID_WICTiffEncoder,
&testdata_1bppIndexed, &CLSID_WICTiffDecoder, "TIFF encoder 1bppIndexed");
test_encoder(&testdata_2bppIndexed, &CLSID_WICTiffEncoder,
@ -1520,7 +1518,6 @@ if (!strcmp(winetest_platform, "windows")) /* FIXME: enable once implemented in
&testdata_4bppIndexed, &CLSID_WICTiffDecoder, "TIFF encoder 4bppIndexed");
test_encoder(&testdata_8bppIndexed, &CLSID_WICTiffEncoder,
&testdata_8bppIndexed, &CLSID_WICTiffDecoder, "TIFF encoder 8bppIndexed");
}
test_encoder(&testdata_24bppBGR, &CLSID_WICTiffEncoder,
&testdata_24bppBGR, &CLSID_WICTiffDecoder, "TIFF encoder 24bppBGR");

View File

@ -1,5 +1,6 @@
/*
* Copyright 2010 Vincent Povirk for CodeWeavers
* Copyright 2016 Dmitry Timoshkov
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -461,6 +462,12 @@ static HRESULT tiff_get_decode_info(TIFF *tiff, tiff_decode_info *decode_info)
decode_info->bpp = bps;
switch (bps)
{
case 1:
decode_info->format = &GUID_WICPixelFormat1bppIndexed;
break;
case 2:
decode_info->format = &GUID_WICPixelFormat2bppIndexed;
break;
case 4:
decode_info->format = &GUID_WICPixelFormat4bppIndexed;
break;
@ -469,7 +476,7 @@ static HRESULT tiff_get_decode_info(TIFF *tiff, tiff_decode_info *decode_info)
break;
default:
FIXME("unhandled indexed bit count %u\n", bps);
return E_FAIL;
return E_NOTIMPL;
}
break;
case 4: /* Transparency mask */
@ -1408,6 +1415,9 @@ static const struct tiff_encode_format formats[] = {
{&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},
{&GUID_WICPixelFormat1bppIndexed, 3, 1, 1, 1, 0, 0, 0},
{&GUID_WICPixelFormat4bppIndexed, 3, 4, 1, 4, 0, 0, 0},
{&GUID_WICPixelFormat8bppIndexed, 3, 8, 1, 8, 0, 0, 0},
{0}
};
@ -1579,9 +1589,12 @@ static HRESULT WINAPI TiffFrameEncode_SetPixelFormat(IWICBitmapFrameEncode *ifac
return WINCODEC_ERR_WRONGSTATE;
}
if (IsEqualGUID(pPixelFormat, &GUID_WICPixelFormat2bppIndexed))
*pPixelFormat = GUID_WICPixelFormat4bppIndexed;
for (i=0; formats[i].guid; i++)
{
if (memcmp(formats[i].guid, pPixelFormat, sizeof(GUID)) == 0)
if (IsEqualGUID(formats[i].guid, pPixelFormat))
break;
}
@ -1690,6 +1703,21 @@ static HRESULT WINAPI TiffFrameEncode_WritePixels(IWICBitmapFrameEncode *iface,
pTIFFSetField(This->parent->tiff, TIFFTAG_YRESOLUTION, (float)This->yres);
}
if (This->format->bpp <= 8 && This->colors && !IsEqualGUID(This->format->guid, &GUID_WICPixelFormatBlackWhite))
{
uint16 red[256], green[256], blue[256];
UINT i;
for (i = 0; i < This->colors; i++)
{
red[i] = (This->palette[i] >> 8) & 0xff00;
green[i] = This->palette[i] & 0xff00;
blue[i] = (This->palette[i] << 8) & 0xff00;
}
pTIFFSetField(This->parent->tiff, TIFFTAG_COLORMAP, red, green, blue);
}
This->info_written = TRUE;
}