windowscodecs: Combine the bitmap decoder and bitmap decoder frame objects.

This commit is contained in:
Vincent Povirk 2010-04-09 12:41:17 -05:00 committed by Alexandre Julliard
parent 7ce7ce8266
commit 3d914c4f8d

View File

@ -58,12 +58,14 @@ typedef struct {
DWORD bc2AppData; DWORD bc2AppData;
} BITMAPCOREHEADER2; } BITMAPCOREHEADER2;
struct BmpFrameDecode; struct BmpDecoder;
typedef HRESULT (*ReadDataFunc)(struct BmpFrameDecode* This); typedef HRESULT (*ReadDataFunc)(struct BmpDecoder* This);
typedef struct BmpFrameDecode { typedef struct BmpDecoder {
const IWICBitmapFrameDecodeVtbl *lpVtbl; const IWICBitmapDecoderVtbl *lpVtbl;
const IWICBitmapFrameDecodeVtbl *lpFrameVtbl;
LONG ref; LONG ref;
BOOL initialized;
IStream *stream; IStream *stream;
BITMAPFILEHEADER bfh; BITMAPFILEHEADER bfh;
BITMAPV5HEADER bih; BITMAPV5HEADER bih;
@ -73,12 +75,16 @@ typedef struct BmpFrameDecode {
INT stride; INT stride;
BYTE *imagedata; BYTE *imagedata;
BYTE *imagedatastart; BYTE *imagedatastart;
} BmpFrameDecode; } BmpDecoder;
static inline BmpDecoder *impl_from_frame(IWICBitmapFrameDecode *iface)
{
return CONTAINING_RECORD(iface, BmpDecoder, lpFrameVtbl);
}
static HRESULT WINAPI BmpFrameDecode_QueryInterface(IWICBitmapFrameDecode *iface, REFIID iid, static HRESULT WINAPI BmpFrameDecode_QueryInterface(IWICBitmapFrameDecode *iface, REFIID iid,
void **ppv) void **ppv)
{ {
BmpFrameDecode *This = (BmpFrameDecode*)iface;
TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv); TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
if (!ppv) return E_INVALIDARG; if (!ppv) return E_INVALIDARG;
@ -87,7 +93,7 @@ static HRESULT WINAPI BmpFrameDecode_QueryInterface(IWICBitmapFrameDecode *iface
IsEqualIID(&IID_IWICBitmapSource, iid) || IsEqualIID(&IID_IWICBitmapSource, iid) ||
IsEqualIID(&IID_IWICBitmapFrameDecode, iid)) IsEqualIID(&IID_IWICBitmapFrameDecode, iid))
{ {
*ppv = This; *ppv = iface;
} }
else else
{ {
@ -101,35 +107,22 @@ static HRESULT WINAPI BmpFrameDecode_QueryInterface(IWICBitmapFrameDecode *iface
static ULONG WINAPI BmpFrameDecode_AddRef(IWICBitmapFrameDecode *iface) static ULONG WINAPI BmpFrameDecode_AddRef(IWICBitmapFrameDecode *iface)
{ {
BmpFrameDecode *This = (BmpFrameDecode*)iface; BmpDecoder *This = impl_from_frame(iface);
ULONG ref = InterlockedIncrement(&This->ref);
TRACE("(%p) refcount=%u\n", iface, ref); return IUnknown_AddRef((IUnknown*)This);
return ref;
} }
static ULONG WINAPI BmpFrameDecode_Release(IWICBitmapFrameDecode *iface) static ULONG WINAPI BmpFrameDecode_Release(IWICBitmapFrameDecode *iface)
{ {
BmpFrameDecode *This = (BmpFrameDecode*)iface; BmpDecoder *This = impl_from_frame(iface);
ULONG ref = InterlockedDecrement(&This->ref);
TRACE("(%p) refcount=%u\n", iface, ref); return IUnknown_Release((IUnknown*)This);
if (ref == 0)
{
IStream_Release(This->stream);
HeapFree(GetProcessHeap(), 0, This->imagedata);
HeapFree(GetProcessHeap(), 0, This);
}
return ref;
} }
static HRESULT WINAPI BmpFrameDecode_GetSize(IWICBitmapFrameDecode *iface, static HRESULT WINAPI BmpFrameDecode_GetSize(IWICBitmapFrameDecode *iface,
UINT *puiWidth, UINT *puiHeight) UINT *puiWidth, UINT *puiHeight)
{ {
BmpFrameDecode *This = (BmpFrameDecode*)iface; BmpDecoder *This = impl_from_frame(iface);
TRACE("(%p,%p,%p)\n", iface, puiWidth, puiHeight); TRACE("(%p,%p,%p)\n", iface, puiWidth, puiHeight);
if (This->bih.bV5Size == sizeof(BITMAPCOREHEADER)) if (This->bih.bV5Size == sizeof(BITMAPCOREHEADER))
@ -149,7 +142,7 @@ static HRESULT WINAPI BmpFrameDecode_GetSize(IWICBitmapFrameDecode *iface,
static HRESULT WINAPI BmpFrameDecode_GetPixelFormat(IWICBitmapFrameDecode *iface, static HRESULT WINAPI BmpFrameDecode_GetPixelFormat(IWICBitmapFrameDecode *iface,
WICPixelFormatGUID *pPixelFormat) WICPixelFormatGUID *pPixelFormat)
{ {
BmpFrameDecode *This = (BmpFrameDecode*)iface; BmpDecoder *This = impl_from_frame(iface);
TRACE("(%p,%p)\n", iface, pPixelFormat); TRACE("(%p,%p)\n", iface, pPixelFormat);
memcpy(pPixelFormat, This->pixelformat, sizeof(GUID)); memcpy(pPixelFormat, This->pixelformat, sizeof(GUID));
@ -180,7 +173,7 @@ static HRESULT BmpHeader_GetResolution(BITMAPV5HEADER *bih, double *pDpiX, doubl
static HRESULT WINAPI BmpFrameDecode_GetResolution(IWICBitmapFrameDecode *iface, static HRESULT WINAPI BmpFrameDecode_GetResolution(IWICBitmapFrameDecode *iface,
double *pDpiX, double *pDpiY) double *pDpiX, double *pDpiY)
{ {
BmpFrameDecode *This = (BmpFrameDecode*)iface; BmpDecoder *This = impl_from_frame(iface);
TRACE("(%p,%p,%p)\n", iface, pDpiX, pDpiY); TRACE("(%p,%p,%p)\n", iface, pDpiX, pDpiY);
return BmpHeader_GetResolution(&This->bih, pDpiX, pDpiY); return BmpHeader_GetResolution(&This->bih, pDpiX, pDpiY);
@ -190,7 +183,7 @@ static HRESULT WINAPI BmpFrameDecode_CopyPalette(IWICBitmapFrameDecode *iface,
IWICPalette *pIPalette) IWICPalette *pIPalette)
{ {
HRESULT hr; HRESULT hr;
BmpFrameDecode *This = (BmpFrameDecode*)iface; BmpDecoder *This = impl_from_frame(iface);
int count; int count;
WICColor *wiccolors=NULL; WICColor *wiccolors=NULL;
RGBTRIPLE *bgrcolors=NULL; RGBTRIPLE *bgrcolors=NULL;
@ -290,7 +283,7 @@ end:
static HRESULT WINAPI BmpFrameDecode_CopyPixels(IWICBitmapFrameDecode *iface, static HRESULT WINAPI BmpFrameDecode_CopyPixels(IWICBitmapFrameDecode *iface,
const WICRect *prc, UINT cbStride, UINT cbBufferSize, BYTE *pbBuffer) const WICRect *prc, UINT cbStride, UINT cbBufferSize, BYTE *pbBuffer)
{ {
BmpFrameDecode *This = (BmpFrameDecode*)iface; BmpDecoder *This = impl_from_frame(iface);
HRESULT hr; HRESULT hr;
UINT width, height; UINT width, height;
TRACE("(%p,%p,%u,%u,%p)\n", iface, prc, cbStride, cbBufferSize, pbBuffer); TRACE("(%p,%p,%u,%u,%p)\n", iface, prc, cbStride, cbBufferSize, pbBuffer);
@ -330,7 +323,7 @@ static HRESULT WINAPI BmpFrameDecode_GetThumbnail(IWICBitmapFrameDecode *iface,
return WINCODEC_ERR_CODECNOTHUMBNAIL; return WINCODEC_ERR_CODECNOTHUMBNAIL;
} }
static HRESULT BmpFrameDecode_ReadUncompressed(BmpFrameDecode* This) static HRESULT BmpFrameDecode_ReadUncompressed(BmpDecoder* This)
{ {
UINT bytesperrow; UINT bytesperrow;
UINT width, height; UINT width, height;
@ -387,7 +380,7 @@ fail:
return hr; return hr;
} }
static HRESULT BmpFrameDecode_ReadRLE8(BmpFrameDecode* This) static HRESULT BmpFrameDecode_ReadRLE8(BmpDecoder* This)
{ {
UINT bytesperrow; UINT bytesperrow;
UINT width, height; UINT width, height;
@ -493,7 +486,7 @@ fail:
return hr; return hr;
} }
static HRESULT BmpFrameDecode_ReadRLE4(BmpFrameDecode* This) static HRESULT BmpFrameDecode_ReadRLE4(BmpDecoder* This)
{ {
UINT bytesperrow; UINT bytesperrow;
UINT width, height; UINT width, height;
@ -614,7 +607,7 @@ fail:
return hr; return hr;
} }
static HRESULT BmpFrameDecode_ReadUnsupported(BmpFrameDecode* This) static HRESULT BmpFrameDecode_ReadUnsupported(BmpDecoder* This)
{ {
return E_FAIL; return E_FAIL;
} }
@ -637,7 +630,7 @@ static const struct bitfields_format bitfields_formats[] = {
{0} {0}
}; };
static const IWICBitmapFrameDecodeVtbl BmpFrameDecode_Vtbl = { static const IWICBitmapFrameDecodeVtbl BmpDecoder_FrameVtbl = {
BmpFrameDecode_QueryInterface, BmpFrameDecode_QueryInterface,
BmpFrameDecode_AddRef, BmpFrameDecode_AddRef,
BmpFrameDecode_Release, BmpFrameDecode_Release,
@ -651,19 +644,6 @@ static const IWICBitmapFrameDecodeVtbl BmpFrameDecode_Vtbl = {
BmpFrameDecode_GetThumbnail BmpFrameDecode_GetThumbnail
}; };
typedef struct {
const IWICBitmapDecoderVtbl *lpVtbl;
LONG ref;
BOOL initialized;
IStream *stream;
BITMAPFILEHEADER bfh;
BITMAPV5HEADER bih;
BmpFrameDecode *framedecode;
const WICPixelFormatGUID *pixelformat;
int bitsperpixel;
ReadDataFunc read_data_func;
} BmpDecoder;
static HRESULT BmpDecoder_ReadHeaders(BmpDecoder* This, IStream *stream) static HRESULT BmpDecoder_ReadHeaders(BmpDecoder* This, IStream *stream)
{ {
HRESULT hr; HRESULT hr;
@ -873,7 +853,7 @@ static ULONG WINAPI BmpDecoder_Release(IWICBitmapDecoder *iface)
if (ref == 0) if (ref == 0)
{ {
if (This->stream) IStream_Release(This->stream); if (This->stream) IStream_Release(This->stream);
if (This->framedecode) IUnknown_Release((IUnknown*)This->framedecode); HeapFree(GetProcessHeap(), 0, This->imagedata);
HeapFree(GetProcessHeap(), 0, This); HeapFree(GetProcessHeap(), 0, This);
} }
@ -992,25 +972,8 @@ static HRESULT WINAPI BmpDecoder_GetFrame(IWICBitmapDecoder *iface,
if (!This->stream) return WINCODEC_ERR_WRONGSTATE; if (!This->stream) return WINCODEC_ERR_WRONGSTATE;
if (!This->framedecode) *ppIBitmapFrame = (IWICBitmapFrameDecode*)&This->lpFrameVtbl;
{ IWICBitmapDecoder_AddRef(iface);
This->framedecode = HeapAlloc(GetProcessHeap(), 0, sizeof(BmpFrameDecode));
if (!This->framedecode) return E_OUTOFMEMORY;
This->framedecode->lpVtbl = &BmpFrameDecode_Vtbl;
This->framedecode->ref = 1;
This->framedecode->stream = This->stream;
IStream_AddRef(This->stream);
This->framedecode->bfh = This->bfh;
This->framedecode->bih = This->bih;
This->framedecode->pixelformat = This->pixelformat;
This->framedecode->bitsperpixel = This->bitsperpixel;
This->framedecode->read_data_func = This->read_data_func;
This->framedecode->imagedata = NULL;
}
*ppIBitmapFrame = (IWICBitmapFrameDecode*)This->framedecode;
IWICBitmapFrameDecode_AddRef((IWICBitmapFrameDecode*)This->framedecode);
return S_OK; return S_OK;
} }
@ -1047,10 +1010,11 @@ HRESULT BmpDecoder_CreateInstance(IUnknown *pUnkOuter, REFIID iid, void** ppv)
if (!This) return E_OUTOFMEMORY; if (!This) return E_OUTOFMEMORY;
This->lpVtbl = &BmpDecoder_Vtbl; This->lpVtbl = &BmpDecoder_Vtbl;
This->lpFrameVtbl = &BmpDecoder_FrameVtbl;
This->ref = 1; This->ref = 1;
This->initialized = FALSE; This->initialized = FALSE;
This->stream = NULL; This->stream = NULL;
This->framedecode = NULL; This->imagedata = NULL;
ret = IUnknown_QueryInterface((IUnknown*)This, iid, ppv); ret = IUnknown_QueryInterface((IUnknown*)This, iid, ppv);
IUnknown_Release((IUnknown*)This); IUnknown_Release((IUnknown*)This);