2013-07-18 15:30:54 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Nikolay Sivov 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 <stdarg.h>
|
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "objbase.h"
|
|
|
|
|
|
|
|
#include "wincodecs_private.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(wincodecs);
|
|
|
|
|
|
|
|
typedef struct BitmapClipper {
|
|
|
|
IWICBitmapClipper IWICBitmapClipper_iface;
|
|
|
|
LONG ref;
|
2013-07-18 22:21:33 +02:00
|
|
|
IWICBitmapSource *source;
|
|
|
|
WICRect rect;
|
|
|
|
CRITICAL_SECTION lock; /* must be held when initialized */
|
2013-07-18 15:30:54 +02:00
|
|
|
} BitmapClipper;
|
|
|
|
|
|
|
|
static inline BitmapClipper *impl_from_IWICBitmapClipper(IWICBitmapClipper *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, BitmapClipper, IWICBitmapClipper_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI BitmapClipper_QueryInterface(IWICBitmapClipper *iface, REFIID iid,
|
|
|
|
void **ppv)
|
|
|
|
{
|
|
|
|
BitmapClipper *This = impl_from_IWICBitmapClipper(iface);
|
|
|
|
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_IWICBitmapClipper, iid))
|
|
|
|
{
|
|
|
|
*ppv = &This->IWICBitmapClipper_iface;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*ppv = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
IUnknown_AddRef((IUnknown*)*ppv);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI BitmapClipper_AddRef(IWICBitmapClipper *iface)
|
|
|
|
{
|
|
|
|
BitmapClipper *This = impl_from_IWICBitmapClipper(iface);
|
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
|
2022-02-22 09:42:16 +01:00
|
|
|
TRACE("(%p) refcount=%lu\n", iface, ref);
|
2013-07-18 15:30:54 +02:00
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI BitmapClipper_Release(IWICBitmapClipper *iface)
|
|
|
|
{
|
|
|
|
BitmapClipper *This = impl_from_IWICBitmapClipper(iface);
|
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
2022-02-22 09:42:16 +01:00
|
|
|
TRACE("(%p) refcount=%lu\n", iface, ref);
|
2013-07-18 15:30:54 +02:00
|
|
|
|
|
|
|
if (ref == 0)
|
|
|
|
{
|
2013-07-18 22:21:33 +02:00
|
|
|
This->lock.DebugInfo->Spare[0] = 0;
|
|
|
|
DeleteCriticalSection(&This->lock);
|
|
|
|
if (This->source) IWICBitmapSource_Release(This->source);
|
2013-07-18 15:30:54 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI BitmapClipper_GetSize(IWICBitmapClipper *iface,
|
2013-07-18 22:21:33 +02:00
|
|
|
UINT *width, UINT *height)
|
2013-07-18 15:30:54 +02:00
|
|
|
{
|
2013-07-18 22:21:33 +02:00
|
|
|
BitmapClipper *This = impl_from_IWICBitmapClipper(iface);
|
|
|
|
|
|
|
|
TRACE("(%p,%p,%p)\n", iface, width, height);
|
|
|
|
|
|
|
|
if (!width || !height)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
if (!This->source)
|
|
|
|
return WINCODEC_ERR_WRONGSTATE;
|
|
|
|
|
|
|
|
*width = This->rect.Width;
|
|
|
|
*height = This->rect.Height;
|
|
|
|
|
|
|
|
return S_OK;
|
2013-07-18 15:30:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI BitmapClipper_GetPixelFormat(IWICBitmapClipper *iface,
|
|
|
|
WICPixelFormatGUID *format)
|
|
|
|
{
|
2013-07-18 22:29:18 +02:00
|
|
|
BitmapClipper *This = impl_from_IWICBitmapClipper(iface);
|
|
|
|
TRACE("(%p,%p)\n", iface, format);
|
|
|
|
|
|
|
|
if (!format)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
if (!This->source)
|
|
|
|
return WINCODEC_ERR_WRONGSTATE;
|
|
|
|
|
|
|
|
return IWICBitmapSource_GetPixelFormat(This->source, format);
|
2013-07-18 15:30:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI BitmapClipper_GetResolution(IWICBitmapClipper *iface,
|
2013-07-18 22:31:09 +02:00
|
|
|
double *dpiX, double *dpiY)
|
2013-07-18 15:30:54 +02:00
|
|
|
{
|
2013-07-18 22:31:09 +02:00
|
|
|
BitmapClipper *This = impl_from_IWICBitmapClipper(iface);
|
|
|
|
|
|
|
|
TRACE("(%p,%p,%p)\n", iface, dpiX, dpiY);
|
|
|
|
|
|
|
|
if (!dpiX || !dpiY)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
if (!This->source)
|
|
|
|
return WINCODEC_ERR_WRONGSTATE;
|
|
|
|
|
|
|
|
return IWICBitmapSource_GetResolution(This->source, dpiX, dpiY);
|
2013-07-18 15:30:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI BitmapClipper_CopyPalette(IWICBitmapClipper *iface,
|
|
|
|
IWICPalette *palette)
|
|
|
|
{
|
2013-07-21 21:42:48 +02:00
|
|
|
BitmapClipper *This = impl_from_IWICBitmapClipper(iface);
|
|
|
|
|
|
|
|
TRACE("(%p,%p)\n", iface, palette);
|
|
|
|
|
|
|
|
if (!palette)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
if (!This->source)
|
|
|
|
return WINCODEC_ERR_WRONGSTATE;
|
|
|
|
|
|
|
|
return IWICBitmapSource_CopyPalette(This->source, palette);
|
2013-07-18 15:30:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI BitmapClipper_CopyPixels(IWICBitmapClipper *iface,
|
|
|
|
const WICRect *rc, UINT stride, UINT buffer_size, BYTE *buffer)
|
|
|
|
{
|
2013-07-22 07:19:26 +02:00
|
|
|
BitmapClipper *This = impl_from_IWICBitmapClipper(iface);
|
|
|
|
WICRect rect;
|
|
|
|
|
2018-11-09 12:26:45 +01:00
|
|
|
TRACE("(%p,%s,%u,%u,%p)\n", iface, debug_wic_rect(rc), stride, buffer_size, buffer);
|
2013-07-22 07:19:26 +02:00
|
|
|
|
|
|
|
if (!This->source)
|
|
|
|
return WINCODEC_ERR_WRONGSTATE;
|
|
|
|
|
|
|
|
if (rc)
|
|
|
|
{
|
|
|
|
rect = *rc;
|
|
|
|
|
|
|
|
/* transform to source coordinates */
|
|
|
|
rect.X += This->rect.X;
|
|
|
|
rect.Y += This->rect.Y;
|
|
|
|
|
|
|
|
if ((rect.X + rect.Width > This->rect.X + This->rect.Width) ||
|
|
|
|
(rect.Y + rect.Height > This->rect.Y + This->rect.Height))
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
rc = ▭
|
|
|
|
}
|
|
|
|
else
|
|
|
|
rc = &This->rect;
|
|
|
|
|
|
|
|
return IWICBitmapSource_CopyPixels(This->source, rc, stride, buffer_size, buffer);
|
2013-07-18 15:30:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI BitmapClipper_Initialize(IWICBitmapClipper *iface,
|
|
|
|
IWICBitmapSource *source, const WICRect *rc)
|
|
|
|
{
|
2013-07-18 22:21:33 +02:00
|
|
|
BitmapClipper *This = impl_from_IWICBitmapClipper(iface);
|
|
|
|
UINT width, height;
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
2018-11-09 12:26:45 +01:00
|
|
|
TRACE("(%p,%p,%s)\n", iface, source, debug_wic_rect(rc));
|
2013-07-18 22:21:33 +02:00
|
|
|
|
|
|
|
EnterCriticalSection(&This->lock);
|
|
|
|
|
|
|
|
if (This->source)
|
|
|
|
{
|
|
|
|
hr = WINCODEC_ERR_WRONGSTATE;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IWICBitmapSource_GetSize(source, &width, &height);
|
|
|
|
if (FAILED(hr)) goto end;
|
|
|
|
|
|
|
|
if ((rc->X + rc->Width > width) || (rc->Y + rc->Height > height))
|
|
|
|
{
|
|
|
|
hr = E_INVALIDARG;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
This->rect = *rc;
|
|
|
|
This->source = source;
|
|
|
|
IWICBitmapSource_AddRef(This->source);
|
|
|
|
|
|
|
|
end:
|
|
|
|
LeaveCriticalSection(&This->lock);
|
|
|
|
|
|
|
|
return hr;
|
2013-07-18 15:30:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const IWICBitmapClipperVtbl BitmapClipper_Vtbl = {
|
|
|
|
BitmapClipper_QueryInterface,
|
|
|
|
BitmapClipper_AddRef,
|
|
|
|
BitmapClipper_Release,
|
|
|
|
BitmapClipper_GetSize,
|
|
|
|
BitmapClipper_GetPixelFormat,
|
|
|
|
BitmapClipper_GetResolution,
|
|
|
|
BitmapClipper_CopyPalette,
|
|
|
|
BitmapClipper_CopyPixels,
|
|
|
|
BitmapClipper_Initialize
|
|
|
|
};
|
|
|
|
|
|
|
|
HRESULT BitmapClipper_Create(IWICBitmapClipper **clipper)
|
|
|
|
{
|
|
|
|
BitmapClipper *This;
|
|
|
|
|
|
|
|
This = HeapAlloc(GetProcessHeap(), 0, sizeof(BitmapClipper));
|
|
|
|
if (!This) return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
This->IWICBitmapClipper_iface.lpVtbl = &BitmapClipper_Vtbl;
|
|
|
|
This->ref = 1;
|
2013-07-18 22:21:33 +02:00
|
|
|
This->source = NULL;
|
|
|
|
InitializeCriticalSection(&This->lock);
|
|
|
|
This->lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": BitmapClipper.lock");
|
2013-07-18 15:30:54 +02:00
|
|
|
|
|
|
|
*clipper = &This->IWICBitmapClipper_iface;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|