2009-08-11 20:47:29 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winreg.h"
|
|
|
|
#include "wingdi.h"
|
|
|
|
#include "objbase.h"
|
|
|
|
|
|
|
|
#include "wincodecs_private.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(wincodecs);
|
|
|
|
|
2009-08-11 23:35:20 +02:00
|
|
|
struct bmp_pixelformat {
|
|
|
|
const WICPixelFormatGUID *guid;
|
|
|
|
UINT bpp;
|
|
|
|
DWORD compression;
|
|
|
|
DWORD redmask;
|
|
|
|
DWORD greenmask;
|
|
|
|
DWORD bluemask;
|
|
|
|
DWORD alphamask;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct bmp_pixelformat formats[] = {
|
|
|
|
{&GUID_WICPixelFormat24bppBGR, 24, BI_RGB},
|
2009-09-23 20:26:25 +02:00
|
|
|
{&GUID_WICPixelFormat16bppBGR555, 16, BI_RGB},
|
|
|
|
{&GUID_WICPixelFormat16bppBGR565, 16, BI_BITFIELDS, 0xf800, 0x7e0, 0x1f, 0},
|
|
|
|
{&GUID_WICPixelFormat32bppBGR, 32, BI_RGB},
|
|
|
|
#if 0
|
|
|
|
/* Windows doesn't seem to support this one. */
|
|
|
|
{&GUID_WICPixelFormat32bppBGRA, 32, BI_BITFIELDS, 0xff0000, 0xff00, 0xff, 0xff000000},
|
|
|
|
#endif
|
2009-08-11 23:35:20 +02:00
|
|
|
{NULL}
|
|
|
|
};
|
|
|
|
|
2009-08-11 23:10:12 +02:00
|
|
|
typedef struct BmpFrameEncode {
|
2011-01-05 00:46:15 +01:00
|
|
|
IWICBitmapFrameEncode IWICBitmapFrameEncode_iface;
|
2009-08-11 23:10:12 +02:00
|
|
|
LONG ref;
|
|
|
|
IStream *stream;
|
2009-08-11 23:18:40 +02:00
|
|
|
BOOL initialized;
|
2009-08-11 23:23:41 +02:00
|
|
|
UINT width, height;
|
|
|
|
BYTE *bits;
|
2009-08-11 23:35:20 +02:00
|
|
|
const struct bmp_pixelformat *format;
|
2009-08-11 23:38:11 +02:00
|
|
|
double xres, yres;
|
2009-08-11 23:55:59 +02:00
|
|
|
UINT lineswritten;
|
|
|
|
UINT stride;
|
2017-09-13 22:12:39 +02:00
|
|
|
WICColor palette[256];
|
|
|
|
UINT colors;
|
2009-08-12 00:17:31 +02:00
|
|
|
BOOL committed;
|
2009-08-11 23:10:12 +02:00
|
|
|
} BmpFrameEncode;
|
|
|
|
|
2011-01-05 00:46:15 +01:00
|
|
|
static inline BmpFrameEncode *impl_from_IWICBitmapFrameEncode(IWICBitmapFrameEncode *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, BmpFrameEncode, IWICBitmapFrameEncode_iface);
|
|
|
|
}
|
|
|
|
|
2009-08-11 23:10:12 +02:00
|
|
|
static HRESULT WINAPI BmpFrameEncode_QueryInterface(IWICBitmapFrameEncode *iface, REFIID iid,
|
|
|
|
void **ppv)
|
|
|
|
{
|
2011-01-05 00:46:15 +01:00
|
|
|
BmpFrameEncode *This = impl_from_IWICBitmapFrameEncode(iface);
|
2009-08-11 23:10:12 +02:00
|
|
|
TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
|
|
|
|
|
|
|
|
if (!ppv) return E_INVALIDARG;
|
|
|
|
|
|
|
|
if (IsEqualIID(&IID_IUnknown, iid) ||
|
|
|
|
IsEqualIID(&IID_IWICBitmapFrameEncode, iid))
|
|
|
|
{
|
2012-07-24 08:02:20 +02:00
|
|
|
*ppv = &This->IWICBitmapFrameEncode_iface;
|
2009-08-11 23:10:12 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*ppv = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
IUnknown_AddRef((IUnknown*)*ppv);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI BmpFrameEncode_AddRef(IWICBitmapFrameEncode *iface)
|
|
|
|
{
|
2011-01-05 00:46:15 +01:00
|
|
|
BmpFrameEncode *This = impl_from_IWICBitmapFrameEncode(iface);
|
2009-08-11 23:10:12 +02:00
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p) refcount=%u\n", iface, ref);
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI BmpFrameEncode_Release(IWICBitmapFrameEncode *iface)
|
|
|
|
{
|
2011-01-05 00:46:15 +01:00
|
|
|
BmpFrameEncode *This = impl_from_IWICBitmapFrameEncode(iface);
|
2009-08-11 23:10:12 +02:00
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p) refcount=%u\n", iface, ref);
|
|
|
|
|
|
|
|
if (ref == 0)
|
|
|
|
{
|
|
|
|
if (This->stream) IStream_Release(This->stream);
|
2009-08-11 23:55:59 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, This->bits);
|
2009-08-11 23:10:12 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI BmpFrameEncode_Initialize(IWICBitmapFrameEncode *iface,
|
|
|
|
IPropertyBag2 *pIEncoderOptions)
|
|
|
|
{
|
2011-01-05 00:46:15 +01:00
|
|
|
BmpFrameEncode *This = impl_from_IWICBitmapFrameEncode(iface);
|
2009-08-11 23:18:40 +02:00
|
|
|
TRACE("(%p,%p)\n", iface, pIEncoderOptions);
|
|
|
|
|
|
|
|
if (This->initialized) return WINCODEC_ERR_WRONGSTATE;
|
|
|
|
|
|
|
|
This->initialized = TRUE;
|
|
|
|
|
|
|
|
return S_OK;
|
2009-08-11 23:10:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI BmpFrameEncode_SetSize(IWICBitmapFrameEncode *iface,
|
|
|
|
UINT uiWidth, UINT uiHeight)
|
|
|
|
{
|
2011-01-05 00:46:15 +01:00
|
|
|
BmpFrameEncode *This = impl_from_IWICBitmapFrameEncode(iface);
|
2009-08-11 23:23:41 +02:00
|
|
|
TRACE("(%p,%u,%u)\n", iface, uiWidth, uiHeight);
|
|
|
|
|
|
|
|
if (!This->initialized || This->bits) return WINCODEC_ERR_WRONGSTATE;
|
|
|
|
|
|
|
|
This->width = uiWidth;
|
|
|
|
This->height = uiHeight;
|
|
|
|
|
|
|
|
return S_OK;
|
2009-08-11 23:10:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI BmpFrameEncode_SetResolution(IWICBitmapFrameEncode *iface,
|
|
|
|
double dpiX, double dpiY)
|
|
|
|
{
|
2011-01-05 00:46:15 +01:00
|
|
|
BmpFrameEncode *This = impl_from_IWICBitmapFrameEncode(iface);
|
2009-08-11 23:38:11 +02:00
|
|
|
TRACE("(%p,%0.2f,%0.2f)\n", iface, dpiX, dpiY);
|
|
|
|
|
|
|
|
if (!This->initialized || This->bits) return WINCODEC_ERR_WRONGSTATE;
|
|
|
|
|
|
|
|
This->xres = dpiX;
|
|
|
|
This->yres = dpiY;
|
|
|
|
|
|
|
|
return S_OK;
|
2009-08-11 23:10:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI BmpFrameEncode_SetPixelFormat(IWICBitmapFrameEncode *iface,
|
|
|
|
WICPixelFormatGUID *pPixelFormat)
|
|
|
|
{
|
2011-01-05 00:46:15 +01:00
|
|
|
BmpFrameEncode *This = impl_from_IWICBitmapFrameEncode(iface);
|
2009-08-11 23:35:20 +02:00
|
|
|
int i;
|
|
|
|
TRACE("(%p,%s)\n", iface, debugstr_guid(pPixelFormat));
|
|
|
|
|
|
|
|
if (!This->initialized || This->bits) 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));
|
|
|
|
|
|
|
|
return S_OK;
|
2009-08-11 23:10:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI BmpFrameEncode_SetColorContexts(IWICBitmapFrameEncode *iface,
|
|
|
|
UINT cCount, IWICColorContext **ppIColorContext)
|
|
|
|
{
|
|
|
|
FIXME("(%p,%u,%p): stub\n", iface, cCount, ppIColorContext);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI BmpFrameEncode_SetPalette(IWICBitmapFrameEncode *iface,
|
2017-09-13 22:12:39 +02:00
|
|
|
IWICPalette *palette)
|
2009-08-11 23:10:12 +02:00
|
|
|
{
|
2017-09-13 22:12:39 +02:00
|
|
|
BmpFrameEncode *This = impl_from_IWICBitmapFrameEncode(iface);
|
|
|
|
|
|
|
|
TRACE("(%p,%p)\n", iface, palette);
|
|
|
|
|
|
|
|
if (!palette) return E_INVALIDARG;
|
|
|
|
|
|
|
|
if (!This->initialized)
|
|
|
|
return WINCODEC_ERR_NOTINITIALIZED;
|
|
|
|
|
|
|
|
return IWICPalette_GetColors(palette, 256, This->palette, &This->colors);
|
2009-08-11 23:10:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI BmpFrameEncode_SetThumbnail(IWICBitmapFrameEncode *iface,
|
|
|
|
IWICBitmapSource *pIThumbnail)
|
|
|
|
{
|
|
|
|
FIXME("(%p,%p): stub\n", iface, pIThumbnail);
|
|
|
|
return WINCODEC_ERR_UNSUPPORTEDOPERATION;
|
|
|
|
}
|
|
|
|
|
2009-08-11 23:55:59 +02:00
|
|
|
static HRESULT BmpFrameEncode_AllocateBits(BmpFrameEncode *This)
|
|
|
|
{
|
|
|
|
if (!This->bits)
|
|
|
|
{
|
|
|
|
if (!This->initialized || !This->width || !This->height || !This->format)
|
|
|
|
return WINCODEC_ERR_WRONGSTATE;
|
|
|
|
|
|
|
|
This->stride = (((This->width * This->format->bpp)+31)/32)*4;
|
|
|
|
This->bits = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, This->stride * This->height);
|
|
|
|
if (!This->bits) return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2009-08-11 23:10:12 +02:00
|
|
|
static HRESULT WINAPI BmpFrameEncode_WritePixels(IWICBitmapFrameEncode *iface,
|
|
|
|
UINT lineCount, UINT cbStride, UINT cbBufferSize, BYTE *pbPixels)
|
|
|
|
{
|
2011-01-05 00:46:15 +01:00
|
|
|
BmpFrameEncode *This = impl_from_IWICBitmapFrameEncode(iface);
|
2009-08-11 23:55:59 +02:00
|
|
|
HRESULT hr;
|
|
|
|
WICRect rc;
|
|
|
|
TRACE("(%p,%u,%u,%u,%p)\n", iface, lineCount, cbStride, cbBufferSize, pbPixels);
|
|
|
|
|
|
|
|
if (!This->initialized || !This->width || !This->height || !This->format)
|
|
|
|
return WINCODEC_ERR_WRONGSTATE;
|
|
|
|
|
|
|
|
hr = BmpFrameEncode_AllocateBits(This);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
rc.X = 0;
|
|
|
|
rc.Y = 0;
|
|
|
|
rc.Width = This->width;
|
|
|
|
rc.Height = lineCount;
|
|
|
|
|
|
|
|
hr = copy_pixels(This->format->bpp, pbPixels, This->width, lineCount, cbStride,
|
|
|
|
&rc, This->stride, This->stride*(This->height-This->lineswritten),
|
|
|
|
This->bits + This->stride*This->lineswritten);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
This->lineswritten += lineCount;
|
|
|
|
|
|
|
|
return hr;
|
2009-08-11 23:10:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI BmpFrameEncode_WriteSource(IWICBitmapFrameEncode *iface,
|
|
|
|
IWICBitmapSource *pIBitmapSource, WICRect *prc)
|
|
|
|
{
|
2011-01-05 00:46:15 +01:00
|
|
|
BmpFrameEncode *This = impl_from_IWICBitmapFrameEncode(iface);
|
2009-08-12 00:32:51 +02:00
|
|
|
HRESULT hr;
|
|
|
|
TRACE("(%p,%p,%p)\n", iface, pIBitmapSource, prc);
|
|
|
|
|
2014-06-13 21:02:23 +02:00
|
|
|
if (!This->initialized)
|
2009-08-12 00:32:51 +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);
|
2009-08-12 00:32:51 +02:00
|
|
|
|
2014-06-13 21:02:23 +02:00
|
|
|
if (SUCCEEDED(hr))
|
2009-08-12 00:32:51 +02:00
|
|
|
{
|
2014-06-13 21:02:23 +02:00
|
|
|
hr = write_source(iface, pIBitmapSource, prc,
|
|
|
|
This->format->guid, This->format->bpp, This->width, This->height);
|
2009-08-12 00:32:51 +02:00
|
|
|
}
|
|
|
|
|
2014-06-13 21:02:23 +02:00
|
|
|
return hr;
|
2009-08-11 23:10:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI BmpFrameEncode_Commit(IWICBitmapFrameEncode *iface)
|
|
|
|
{
|
2011-01-05 00:46:15 +01:00
|
|
|
BmpFrameEncode *This = impl_from_IWICBitmapFrameEncode(iface);
|
2009-08-12 00:17:31 +02:00
|
|
|
BITMAPFILEHEADER bfh;
|
|
|
|
BITMAPV5HEADER bih;
|
|
|
|
UINT info_size;
|
|
|
|
LARGE_INTEGER pos;
|
|
|
|
ULONG byteswritten;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("(%p)\n", iface);
|
|
|
|
|
|
|
|
if (!This->bits || This->committed || This->height != This->lineswritten)
|
|
|
|
return WINCODEC_ERR_WRONGSTATE;
|
|
|
|
|
|
|
|
bfh.bfType = 0x4d42; /* "BM" */
|
|
|
|
bfh.bfReserved1 = 0;
|
|
|
|
bfh.bfReserved2 = 0;
|
|
|
|
|
|
|
|
bih.bV5Size = info_size = sizeof(BITMAPINFOHEADER);
|
|
|
|
bih.bV5Width = This->width;
|
|
|
|
bih.bV5Height = -This->height; /* top-down bitmap */
|
|
|
|
bih.bV5Planes = 1;
|
|
|
|
bih.bV5BitCount = This->format->bpp;
|
|
|
|
bih.bV5Compression = This->format->compression;
|
|
|
|
bih.bV5SizeImage = This->stride*This->height;
|
2009-08-24 21:03:28 +02:00
|
|
|
bih.bV5XPelsPerMeter = (This->xres+0.0127) / 0.0254;
|
|
|
|
bih.bV5YPelsPerMeter = (This->yres+0.0127) / 0.0254;
|
2009-08-12 00:17:31 +02:00
|
|
|
bih.bV5ClrUsed = 0;
|
|
|
|
bih.bV5ClrImportant = 0;
|
|
|
|
|
2009-09-23 20:26:25 +02:00
|
|
|
if (This->format->compression == BI_BITFIELDS)
|
|
|
|
{
|
|
|
|
if (This->format->alphamask)
|
|
|
|
bih.bV5Size = info_size = sizeof(BITMAPV4HEADER);
|
|
|
|
else
|
|
|
|
info_size = sizeof(BITMAPINFOHEADER)+12;
|
|
|
|
bih.bV5RedMask = This->format->redmask;
|
|
|
|
bih.bV5GreenMask = This->format->greenmask;
|
|
|
|
bih.bV5BlueMask = This->format->bluemask;
|
|
|
|
bih.bV5AlphaMask = This->format->alphamask;
|
2013-04-04 02:07:36 +02:00
|
|
|
bih.bV5CSType = LCS_DEVICE_RGB;
|
2009-09-23 20:26:25 +02:00
|
|
|
}
|
|
|
|
|
2009-08-12 00:17:31 +02:00
|
|
|
bfh.bfSize = sizeof(BITMAPFILEHEADER) + info_size + bih.bV5SizeImage;
|
|
|
|
bfh.bfOffBits = sizeof(BITMAPFILEHEADER) + info_size;
|
|
|
|
|
|
|
|
pos.QuadPart = 0;
|
2009-09-29 15:55:42 +02:00
|
|
|
hr = IStream_Seek(This->stream, pos, STREAM_SEEK_SET, NULL);
|
2009-08-12 00:17:31 +02:00
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
hr = IStream_Write(This->stream, &bfh, sizeof(BITMAPFILEHEADER), &byteswritten);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
if (byteswritten != sizeof(BITMAPFILEHEADER)) return E_FAIL;
|
|
|
|
|
|
|
|
hr = IStream_Write(This->stream, &bih, info_size, &byteswritten);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
if (byteswritten != info_size) return E_FAIL;
|
|
|
|
|
|
|
|
hr = IStream_Write(This->stream, This->bits, bih.bV5SizeImage, &byteswritten);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
if (byteswritten != bih.bV5SizeImage) return E_FAIL;
|
|
|
|
|
|
|
|
This->committed = TRUE;
|
|
|
|
|
|
|
|
return S_OK;
|
2009-08-11 23:10:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI BmpFrameEncode_GetMetadataQueryWriter(IWICBitmapFrameEncode *iface,
|
|
|
|
IWICMetadataQueryWriter **ppIMetadataQueryWriter)
|
|
|
|
{
|
|
|
|
FIXME("(%p, %p): stub\n", iface, ppIMetadataQueryWriter);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IWICBitmapFrameEncodeVtbl BmpFrameEncode_Vtbl = {
|
|
|
|
BmpFrameEncode_QueryInterface,
|
|
|
|
BmpFrameEncode_AddRef,
|
|
|
|
BmpFrameEncode_Release,
|
|
|
|
BmpFrameEncode_Initialize,
|
|
|
|
BmpFrameEncode_SetSize,
|
|
|
|
BmpFrameEncode_SetResolution,
|
|
|
|
BmpFrameEncode_SetPixelFormat,
|
|
|
|
BmpFrameEncode_SetColorContexts,
|
|
|
|
BmpFrameEncode_SetPalette,
|
|
|
|
BmpFrameEncode_SetThumbnail,
|
|
|
|
BmpFrameEncode_WritePixels,
|
|
|
|
BmpFrameEncode_WriteSource,
|
|
|
|
BmpFrameEncode_Commit,
|
|
|
|
BmpFrameEncode_GetMetadataQueryWriter
|
|
|
|
};
|
|
|
|
|
2009-08-11 20:47:29 +02:00
|
|
|
typedef struct BmpEncoder {
|
2011-01-11 00:43:15 +01:00
|
|
|
IWICBitmapEncoder IWICBitmapEncoder_iface;
|
2009-08-11 20:47:29 +02:00
|
|
|
LONG ref;
|
2009-08-11 21:42:08 +02:00
|
|
|
IStream *stream;
|
2011-01-04 21:01:45 +01:00
|
|
|
BmpFrameEncode *frame;
|
2009-08-11 20:47:29 +02:00
|
|
|
} BmpEncoder;
|
|
|
|
|
2011-01-11 00:43:15 +01:00
|
|
|
static inline BmpEncoder *impl_from_IWICBitmapEncoder(IWICBitmapEncoder *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, BmpEncoder, IWICBitmapEncoder_iface);
|
|
|
|
}
|
|
|
|
|
2009-08-11 20:47:29 +02:00
|
|
|
static HRESULT WINAPI BmpEncoder_QueryInterface(IWICBitmapEncoder *iface, REFIID iid,
|
|
|
|
void **ppv)
|
|
|
|
{
|
2011-01-11 00:43:15 +01:00
|
|
|
BmpEncoder *This = impl_from_IWICBitmapEncoder(iface);
|
2009-08-11 20:47:29 +02:00
|
|
|
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:02:20 +02:00
|
|
|
*ppv = &This->IWICBitmapEncoder_iface;
|
2009-08-11 20:47:29 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*ppv = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
IUnknown_AddRef((IUnknown*)*ppv);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI BmpEncoder_AddRef(IWICBitmapEncoder *iface)
|
|
|
|
{
|
2011-01-11 00:43:15 +01:00
|
|
|
BmpEncoder *This = impl_from_IWICBitmapEncoder(iface);
|
2009-08-11 20:47:29 +02:00
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p) refcount=%u\n", iface, ref);
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI BmpEncoder_Release(IWICBitmapEncoder *iface)
|
|
|
|
{
|
2011-01-11 00:43:15 +01:00
|
|
|
BmpEncoder *This = impl_from_IWICBitmapEncoder(iface);
|
2009-08-11 20:47:29 +02:00
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p) refcount=%u\n", iface, ref);
|
|
|
|
|
|
|
|
if (ref == 0)
|
|
|
|
{
|
2009-08-11 21:42:08 +02:00
|
|
|
if (This->stream) IStream_Release(This->stream);
|
2011-01-05 00:46:15 +01:00
|
|
|
if (This->frame) IWICBitmapFrameEncode_Release(&This->frame->IWICBitmapFrameEncode_iface);
|
2009-08-11 20:47:29 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI BmpEncoder_Initialize(IWICBitmapEncoder *iface,
|
|
|
|
IStream *pIStream, WICBitmapEncoderCacheOption cacheOption)
|
|
|
|
{
|
2011-01-11 00:43:15 +01:00
|
|
|
BmpEncoder *This = impl_from_IWICBitmapEncoder(iface);
|
2009-08-11 21:42:08 +02:00
|
|
|
|
|
|
|
TRACE("(%p,%p,%u)\n", iface, pIStream, cacheOption);
|
|
|
|
|
|
|
|
IStream_AddRef(pIStream);
|
|
|
|
This->stream = pIStream;
|
|
|
|
|
|
|
|
return S_OK;
|
2009-08-11 20:47:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI BmpEncoder_GetContainerFormat(IWICBitmapEncoder *iface,
|
|
|
|
GUID *pguidContainerFormat)
|
|
|
|
{
|
2011-07-27 22:54:07 +02:00
|
|
|
memcpy(pguidContainerFormat, &GUID_ContainerFormatBmp, sizeof(GUID));
|
|
|
|
return S_OK;
|
2009-08-11 20:47:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI BmpEncoder_GetEncoderInfo(IWICBitmapEncoder *iface,
|
|
|
|
IWICBitmapEncoderInfo **ppIEncoderInfo)
|
|
|
|
{
|
|
|
|
FIXME("(%p,%p): stub\n", iface, ppIEncoderInfo);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI BmpEncoder_SetColorContexts(IWICBitmapEncoder *iface,
|
|
|
|
UINT cCount, IWICColorContext **ppIColorContext)
|
|
|
|
{
|
|
|
|
FIXME("(%p,%u,%p): stub\n", iface, cCount, ppIColorContext);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2017-09-13 22:12:38 +02:00
|
|
|
static HRESULT WINAPI BmpEncoder_SetPalette(IWICBitmapEncoder *iface, IWICPalette *palette)
|
2009-08-11 20:47:29 +02:00
|
|
|
{
|
2017-09-13 22:12:38 +02:00
|
|
|
BmpEncoder *This = impl_from_IWICBitmapEncoder(iface);
|
|
|
|
|
|
|
|
TRACE("(%p,%p)\n", iface, palette);
|
|
|
|
return This->stream ? WINCODEC_ERR_UNSUPPORTEDOPERATION : WINCODEC_ERR_NOTINITIALIZED;
|
2009-08-11 20:47:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI BmpEncoder_SetThumbnail(IWICBitmapEncoder *iface, IWICBitmapSource *pIThumbnail)
|
|
|
|
{
|
|
|
|
TRACE("(%p,%p)\n", iface, pIThumbnail);
|
|
|
|
return WINCODEC_ERR_UNSUPPORTEDOPERATION;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI BmpEncoder_SetPreview(IWICBitmapEncoder *iface, IWICBitmapSource *pIPreview)
|
|
|
|
{
|
|
|
|
TRACE("(%p,%p)\n", iface, pIPreview);
|
|
|
|
return WINCODEC_ERR_UNSUPPORTEDOPERATION;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI BmpEncoder_CreateNewFrame(IWICBitmapEncoder *iface,
|
|
|
|
IWICBitmapFrameEncode **ppIFrameEncode, IPropertyBag2 **ppIEncoderOptions)
|
|
|
|
{
|
2011-01-11 00:43:15 +01:00
|
|
|
BmpEncoder *This = impl_from_IWICBitmapEncoder(iface);
|
2009-08-11 23:10:12 +02:00
|
|
|
BmpFrameEncode *encode;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("(%p,%p,%p)\n", iface, ppIFrameEncode, ppIEncoderOptions);
|
|
|
|
|
|
|
|
if (This->frame) return WINCODEC_ERR_UNSUPPORTEDOPERATION;
|
|
|
|
|
|
|
|
if (!This->stream) return WINCODEC_ERR_NOTINITIALIZED;
|
|
|
|
|
2013-01-29 19:50:36 +01:00
|
|
|
hr = CreatePropertyBag2(NULL, 0, ppIEncoderOptions);
|
2009-08-11 23:10:12 +02:00
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
encode = HeapAlloc(GetProcessHeap(), 0, sizeof(BmpFrameEncode));
|
|
|
|
if (!encode)
|
|
|
|
{
|
|
|
|
IPropertyBag2_Release(*ppIEncoderOptions);
|
|
|
|
*ppIEncoderOptions = NULL;
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
2011-01-05 00:46:15 +01:00
|
|
|
encode->IWICBitmapFrameEncode_iface.lpVtbl = &BmpFrameEncode_Vtbl;
|
2009-08-11 23:10:12 +02:00
|
|
|
encode->ref = 2;
|
|
|
|
IStream_AddRef(This->stream);
|
|
|
|
encode->stream = This->stream;
|
2009-08-11 23:18:40 +02:00
|
|
|
encode->initialized = FALSE;
|
2009-08-11 23:23:41 +02:00
|
|
|
encode->width = 0;
|
|
|
|
encode->height = 0;
|
|
|
|
encode->bits = NULL;
|
2009-08-11 23:35:20 +02:00
|
|
|
encode->format = NULL;
|
2009-08-11 23:38:11 +02:00
|
|
|
encode->xres = 0.0;
|
|
|
|
encode->yres = 0.0;
|
2009-08-11 23:55:59 +02:00
|
|
|
encode->lineswritten = 0;
|
2017-09-13 22:12:39 +02:00
|
|
|
encode->colors = 0;
|
2009-08-12 00:17:31 +02:00
|
|
|
encode->committed = FALSE;
|
2009-08-11 23:10:12 +02:00
|
|
|
|
2011-01-05 00:46:15 +01:00
|
|
|
*ppIFrameEncode = &encode->IWICBitmapFrameEncode_iface;
|
2011-01-04 21:01:45 +01:00
|
|
|
This->frame = encode;
|
2009-08-11 23:10:12 +02:00
|
|
|
|
|
|
|
return S_OK;
|
2009-08-11 20:47:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI BmpEncoder_Commit(IWICBitmapEncoder *iface)
|
|
|
|
{
|
2011-01-11 00:43:15 +01:00
|
|
|
BmpEncoder *This = impl_from_IWICBitmapEncoder(iface);
|
2009-08-12 00:19:32 +02:00
|
|
|
TRACE("(%p)\n", iface);
|
|
|
|
|
2011-01-04 21:01:45 +01:00
|
|
|
if (!This->frame || !This->frame->committed) return WINCODEC_ERR_WRONGSTATE;
|
2009-08-12 00:19:32 +02:00
|
|
|
|
|
|
|
return S_OK;
|
2009-08-11 20:47:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI BmpEncoder_GetMetadataQueryWriter(IWICBitmapEncoder *iface,
|
|
|
|
IWICMetadataQueryWriter **ppIMetadataQueryWriter)
|
|
|
|
{
|
|
|
|
FIXME("(%p,%p): stub\n", iface, ppIMetadataQueryWriter);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IWICBitmapEncoderVtbl BmpEncoder_Vtbl = {
|
|
|
|
BmpEncoder_QueryInterface,
|
|
|
|
BmpEncoder_AddRef,
|
|
|
|
BmpEncoder_Release,
|
|
|
|
BmpEncoder_Initialize,
|
|
|
|
BmpEncoder_GetContainerFormat,
|
|
|
|
BmpEncoder_GetEncoderInfo,
|
|
|
|
BmpEncoder_SetColorContexts,
|
|
|
|
BmpEncoder_SetPalette,
|
|
|
|
BmpEncoder_SetThumbnail,
|
|
|
|
BmpEncoder_SetPreview,
|
|
|
|
BmpEncoder_CreateNewFrame,
|
|
|
|
BmpEncoder_Commit,
|
|
|
|
BmpEncoder_GetMetadataQueryWriter
|
|
|
|
};
|
|
|
|
|
2014-01-14 12:18:11 +01:00
|
|
|
HRESULT BmpEncoder_CreateInstance(REFIID iid, void** ppv)
|
2009-08-11 20:47:29 +02:00
|
|
|
{
|
|
|
|
BmpEncoder *This;
|
|
|
|
HRESULT ret;
|
|
|
|
|
2014-01-14 12:18:11 +01:00
|
|
|
TRACE("(%s,%p)\n", debugstr_guid(iid), ppv);
|
2009-08-11 20:47:29 +02:00
|
|
|
|
|
|
|
*ppv = NULL;
|
|
|
|
|
|
|
|
This = HeapAlloc(GetProcessHeap(), 0, sizeof(BmpEncoder));
|
|
|
|
if (!This) return E_OUTOFMEMORY;
|
|
|
|
|
2011-01-11 00:43:15 +01:00
|
|
|
This->IWICBitmapEncoder_iface.lpVtbl = &BmpEncoder_Vtbl;
|
2009-08-11 20:47:29 +02:00
|
|
|
This->ref = 1;
|
2009-08-11 21:42:08 +02:00
|
|
|
This->stream = NULL;
|
2009-08-11 23:10:12 +02:00
|
|
|
This->frame = NULL;
|
2009-08-11 20:47:29 +02:00
|
|
|
|
2011-01-11 00:43:15 +01:00
|
|
|
ret = IWICBitmapEncoder_QueryInterface(&This->IWICBitmapEncoder_iface, iid, ppv);
|
|
|
|
IWICBitmapEncoder_Release(&This->IWICBitmapEncoder_iface);
|
2009-08-11 20:47:29 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|