2009-05-28 20:36:54 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2009 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2012-06-13 19:56:10 +02:00
|
|
|
#define COBJMACROS
|
2009-05-28 20:36:54 +02:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
2020-10-09 21:56:20 +02:00
|
|
|
#include "winternl.h"
|
2009-07-01 22:48:56 +02:00
|
|
|
#include "objbase.h"
|
|
|
|
|
|
|
|
#include "wincodecs_private.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(wincodecs);
|
2009-05-28 20:36:54 +02:00
|
|
|
|
2020-10-09 21:56:16 +02:00
|
|
|
#include "wincodecs_common.h"
|
|
|
|
|
2010-10-22 15:14:40 +02:00
|
|
|
extern BOOL WINAPI WIC_DllMain(HINSTANCE, DWORD, LPVOID) DECLSPEC_HIDDEN;
|
|
|
|
|
2020-10-09 21:56:16 +02:00
|
|
|
HMODULE windowscodecs_module = 0;
|
|
|
|
|
2009-05-28 20:36:54 +02:00
|
|
|
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
|
|
|
|
{
|
|
|
|
|
|
|
|
switch (fdwReason)
|
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH:
|
|
|
|
DisableThreadLibraryCalls(hinstDLL);
|
2020-10-09 21:56:16 +02:00
|
|
|
windowscodecs_module = hinstDLL;
|
2009-05-28 20:36:54 +02:00
|
|
|
break;
|
2018-03-29 20:50:35 +02:00
|
|
|
case DLL_PROCESS_DETACH:
|
|
|
|
ReleaseComponentInfos();
|
|
|
|
break;
|
2009-05-28 20:36:54 +02:00
|
|
|
}
|
|
|
|
|
2010-10-22 15:14:40 +02:00
|
|
|
return WIC_DllMain(hinstDLL, fdwReason, lpvReserved);
|
2009-05-28 20:36:54 +02:00
|
|
|
}
|
2009-07-01 22:48:56 +02:00
|
|
|
|
2012-03-10 20:17:42 +01:00
|
|
|
HRESULT WINAPI DllCanUnloadNow(void)
|
|
|
|
{
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
|
2014-06-13 21:02:23 +02:00
|
|
|
HRESULT configure_write_source(IWICBitmapFrameEncode *iface,
|
|
|
|
IWICBitmapSource *source, const WICRect *prc,
|
|
|
|
const WICPixelFormatGUID *format,
|
|
|
|
INT width, INT height, double xres, double yres)
|
|
|
|
{
|
2020-09-09 08:14:31 +02:00
|
|
|
UINT src_width, src_height;
|
2016-11-23 00:43:37 +01:00
|
|
|
HRESULT hr = S_OK;
|
2014-06-13 21:02:23 +02:00
|
|
|
|
2020-09-09 08:14:31 +02:00
|
|
|
if (width == 0 && height == 0)
|
|
|
|
{
|
|
|
|
if (prc)
|
|
|
|
{
|
|
|
|
if (prc->Width <= 0 || prc->Height <= 0) return E_INVALIDARG;
|
|
|
|
width = prc->Width;
|
|
|
|
height = prc->Height;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hr = IWICBitmapSource_GetSize(source, &src_width, &src_height);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
if (src_width == 0 || src_height == 0) return E_INVALIDARG;
|
|
|
|
width = src_width;
|
|
|
|
height = src_height;
|
|
|
|
}
|
|
|
|
hr = IWICBitmapFrameEncode_SetSize(iface, (UINT)width, (UINT)height);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
}
|
|
|
|
if (width == 0 || height == 0) return E_INVALIDARG;
|
2014-06-13 21:02:23 +02:00
|
|
|
|
|
|
|
if (!format)
|
|
|
|
{
|
2016-11-23 00:43:37 +01:00
|
|
|
WICPixelFormatGUID src_format;
|
2014-06-13 21:02:23 +02:00
|
|
|
|
2016-11-23 00:43:37 +01:00
|
|
|
hr = IWICBitmapSource_GetPixelFormat(source, &src_format);
|
2014-06-13 21:02:23 +02:00
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
2016-11-23 00:43:37 +01:00
|
|
|
hr = IWICBitmapFrameEncode_SetPixelFormat(iface, &src_format);
|
|
|
|
if (FAILED(hr)) return hr;
|
2014-06-13 21:02:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (xres == 0.0 || yres == 0.0)
|
|
|
|
{
|
|
|
|
hr = IWICBitmapSource_GetResolution(source, &xres, &yres);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
hr = IWICBitmapFrameEncode_SetResolution(iface, xres, yres);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT write_source(IWICBitmapFrameEncode *iface,
|
|
|
|
IWICBitmapSource *source, const WICRect *prc,
|
2020-03-05 20:19:52 +01:00
|
|
|
const WICPixelFormatGUID *format, UINT bpp, BOOL need_palette,
|
2014-06-13 21:02:23 +02:00
|
|
|
INT width, INT height)
|
|
|
|
{
|
2016-11-23 00:43:37 +01:00
|
|
|
IWICBitmapSource *converted_source;
|
2014-06-13 21:02:23 +02:00
|
|
|
HRESULT hr=S_OK;
|
|
|
|
WICRect rc;
|
|
|
|
UINT stride;
|
|
|
|
BYTE* pixeldata;
|
|
|
|
|
|
|
|
if (!prc)
|
|
|
|
{
|
|
|
|
UINT src_width, src_height;
|
|
|
|
hr = IWICBitmapSource_GetSize(source, &src_width, &src_height);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
rc.X = 0;
|
|
|
|
rc.Y = 0;
|
|
|
|
rc.Width = src_width;
|
|
|
|
rc.Height = src_height;
|
|
|
|
prc = &rc;
|
|
|
|
}
|
|
|
|
|
2014-06-13 21:39:26 +02:00
|
|
|
if (prc->Width != width || prc->Height <= 0)
|
2014-06-13 21:02:23 +02:00
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2016-11-23 00:43:37 +01:00
|
|
|
hr = WICConvertBitmapSource(format, source, &converted_source);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
ERR("Failed to convert source, target format %s, %#x\n", debugstr_guid(format), hr);
|
2018-12-06 10:05:53 +01:00
|
|
|
return E_NOTIMPL;
|
2016-11-23 00:43:37 +01:00
|
|
|
}
|
|
|
|
|
2020-03-05 20:19:52 +01:00
|
|
|
if (need_palette)
|
|
|
|
{
|
|
|
|
IWICPalette *palette;
|
|
|
|
|
|
|
|
hr = PaletteImpl_Create(&palette);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
hr = IWICBitmapSource_CopyPalette(converted_source, palette);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
hr = IWICBitmapFrameEncode_SetPalette(iface, palette);
|
|
|
|
|
|
|
|
IWICPalette_Release(palette);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
IWICBitmapSource_Release(converted_source);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-13 21:02:23 +02:00
|
|
|
stride = (bpp * width + 7)/8;
|
|
|
|
|
|
|
|
pixeldata = HeapAlloc(GetProcessHeap(), 0, stride * prc->Height);
|
2016-11-23 00:43:37 +01:00
|
|
|
if (!pixeldata)
|
|
|
|
{
|
|
|
|
IWICBitmapSource_Release(converted_source);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
2014-06-13 21:02:23 +02:00
|
|
|
|
2016-11-23 00:43:37 +01:00
|
|
|
hr = IWICBitmapSource_CopyPixels(converted_source, prc, stride,
|
2014-06-13 21:02:23 +02:00
|
|
|
stride*prc->Height, pixeldata);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
hr = IWICBitmapFrameEncode_WritePixels(iface, prc->Height, stride,
|
|
|
|
stride*prc->Height, pixeldata);
|
|
|
|
}
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, pixeldata);
|
2016-11-23 00:43:37 +01:00
|
|
|
IWICBitmapSource_Release(converted_source);
|
2014-06-13 21:02:23 +02:00
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2020-10-27 18:54:42 +01:00
|
|
|
HRESULT CDECL stream_getsize(IStream *stream, ULONGLONG *size)
|
|
|
|
{
|
|
|
|
STATSTG statstg;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = IStream_Stat(stream, &statstg, STATFLAG_NONAME);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
*size = statstg.cbSize.QuadPart;
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2020-10-09 21:56:17 +02:00
|
|
|
HRESULT CDECL stream_read(IStream *stream, void *buffer, ULONG read, ULONG *bytes_read)
|
|
|
|
{
|
|
|
|
return IStream_Read(stream, buffer, read, bytes_read);
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT CDECL stream_seek(IStream *stream, LONGLONG ofs, DWORD origin, ULONGLONG *new_position)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
LARGE_INTEGER ofs_large;
|
|
|
|
ULARGE_INTEGER pos_large;
|
|
|
|
|
|
|
|
ofs_large.QuadPart = ofs;
|
|
|
|
hr = IStream_Seek(stream, ofs_large, origin, &pos_large);
|
|
|
|
if (new_position)
|
|
|
|
*new_position = pos_large.QuadPart;
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2012-06-13 19:56:10 +02:00
|
|
|
HRESULT get_pixelformat_bpp(const GUID *pixelformat, UINT *bpp)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
IWICComponentInfo *info;
|
|
|
|
IWICPixelFormatInfo *formatinfo;
|
|
|
|
|
|
|
|
hr = CreateComponentInfo(pixelformat, &info);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
hr = IWICComponentInfo_QueryInterface(info, &IID_IWICPixelFormatInfo, (void**)&formatinfo);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
hr = IWICPixelFormatInfo_GetBitsPerPixel(formatinfo, bpp);
|
|
|
|
|
|
|
|
IWICPixelFormatInfo_Release(formatinfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
IWICComponentInfo_Release(info);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|