2002-10-18 02:24:41 +02:00
|
|
|
/*
|
2008-10-18 19:19:02 +02:00
|
|
|
* Copyright 2002-2003 Michael Günnewig
|
2002-10-18 02:24:41 +02:00
|
|
|
*
|
|
|
|
* 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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-10-18 02:24:41 +02:00
|
|
|
*/
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2002-10-18 02:24:41 +02:00
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2002-10-18 02:24:41 +02:00
|
|
|
#include "winbase.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "wingdi.h"
|
2003-09-09 21:39:31 +02:00
|
|
|
#include "winuser.h"
|
2002-10-18 02:24:41 +02:00
|
|
|
#include "vfw.h"
|
|
|
|
|
|
|
|
#include "avifile_private.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(avifile);
|
|
|
|
|
|
|
|
#ifndef DIBPTR
|
|
|
|
#define DIBPTR(lp) ((LPBYTE)(lp) + (lp)->biSize + \
|
|
|
|
(lp)->biClrUsed * sizeof(RGBQUAD))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
|
|
|
|
typedef struct _IGetFrameImpl {
|
|
|
|
/* IUnknown stuff */
|
2010-12-27 23:18:54 +01:00
|
|
|
IGetFrame IGetFrame_iface;
|
2005-07-05 16:26:54 +02:00
|
|
|
LONG ref;
|
2002-10-18 02:24:41 +02:00
|
|
|
|
|
|
|
/* IGetFrame stuff */
|
|
|
|
BOOL bFixedStream;
|
|
|
|
PAVISTREAM pStream;
|
|
|
|
|
|
|
|
LPVOID lpInBuffer;
|
2003-06-23 20:10:06 +02:00
|
|
|
LONG cbInBuffer;
|
2002-10-18 02:24:41 +02:00
|
|
|
LPBITMAPINFOHEADER lpInFormat;
|
2003-06-23 20:10:06 +02:00
|
|
|
LONG cbInFormat;
|
2002-10-18 02:24:41 +02:00
|
|
|
|
|
|
|
LONG lCurrentFrame;
|
|
|
|
LPBITMAPINFOHEADER lpOutFormat;
|
|
|
|
LPVOID lpOutBuffer;
|
|
|
|
|
|
|
|
HIC hic;
|
|
|
|
BOOL bResize;
|
|
|
|
DWORD x;
|
|
|
|
DWORD y;
|
|
|
|
DWORD dx;
|
|
|
|
DWORD dy;
|
|
|
|
|
|
|
|
BOOL bFormatChanges;
|
|
|
|
DWORD dwFormatChangeCount;
|
|
|
|
DWORD dwEditCount;
|
|
|
|
} IGetFrameImpl;
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
|
2010-12-27 23:18:54 +01:00
|
|
|
static inline IGetFrameImpl *impl_from_IGetFrame(IGetFrame *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, IGetFrameImpl, IGetFrame_iface);
|
|
|
|
}
|
|
|
|
|
2002-10-18 02:24:41 +02:00
|
|
|
static void AVIFILE_CloseCompressor(IGetFrameImpl *This)
|
|
|
|
{
|
2006-06-12 00:11:36 +02:00
|
|
|
if (This->lpInFormat != This->lpOutFormat) {
|
2006-03-10 16:21:42 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, This->lpOutFormat);
|
2002-10-18 02:24:41 +02:00
|
|
|
This->lpOutFormat = NULL;
|
|
|
|
}
|
2006-06-12 00:11:36 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, This->lpInFormat);
|
|
|
|
This->lpInFormat = NULL;
|
2002-12-02 19:10:57 +01:00
|
|
|
if (This->hic != NULL) {
|
2002-10-18 02:24:41 +02:00
|
|
|
if (This->bResize)
|
|
|
|
ICDecompressExEnd(This->hic);
|
|
|
|
else
|
|
|
|
ICDecompressEnd(This->hic);
|
|
|
|
ICClose(This->hic);
|
2002-12-02 19:10:57 +01:00
|
|
|
This->hic = NULL;
|
2002-10-18 02:24:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI IGetFrame_fnQueryInterface(IGetFrame *iface,
|
|
|
|
REFIID refiid, LPVOID *obj)
|
|
|
|
{
|
2010-12-27 23:18:54 +01:00
|
|
|
IGetFrameImpl *This = impl_from_IGetFrame(iface);
|
2002-10-18 02:24:41 +02:00
|
|
|
|
|
|
|
TRACE("(%p,%s,%p)\n", This, debugstr_guid(refiid), obj);
|
|
|
|
|
|
|
|
if (IsEqualGUID(&IID_IUnknown, refiid) ||
|
|
|
|
IsEqualGUID(&IID_IGetFrame, refiid)) {
|
|
|
|
*obj = iface;
|
2009-03-10 12:39:09 +01:00
|
|
|
IGetFrame_AddRef(iface);
|
2002-10-18 02:24:41 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OLE_E_ENUM_NOMORE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI IGetFrame_fnAddRef(IGetFrame *iface)
|
|
|
|
{
|
2010-12-27 23:18:54 +01:00
|
|
|
IGetFrameImpl *This = impl_from_IGetFrame(iface);
|
2005-01-14 16:10:52 +01:00
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
2002-10-18 02:24:41 +02:00
|
|
|
|
|
|
|
TRACE("(%p)\n", iface);
|
|
|
|
|
2005-01-14 16:10:52 +01:00
|
|
|
return ref;
|
2002-10-18 02:24:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI IGetFrame_fnRelease(IGetFrame *iface)
|
|
|
|
{
|
2010-12-27 23:18:54 +01:00
|
|
|
IGetFrameImpl *This = impl_from_IGetFrame(iface);
|
2005-01-14 16:10:52 +01:00
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
2002-10-18 02:24:41 +02:00
|
|
|
|
|
|
|
TRACE("(%p)\n", iface);
|
|
|
|
|
2005-01-14 16:10:52 +01:00
|
|
|
if (!ref) {
|
2002-10-18 02:24:41 +02:00
|
|
|
AVIFILE_CloseCompressor(This);
|
|
|
|
if (This->pStream != NULL) {
|
2003-10-04 05:05:25 +02:00
|
|
|
IAVIStream_Release(This->pStream);
|
2002-10-18 02:24:41 +02:00
|
|
|
This->pStream = NULL;
|
|
|
|
}
|
|
|
|
|
2006-03-10 16:21:42 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, iface);
|
2002-10-18 02:24:41 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-01-14 16:10:52 +01:00
|
|
|
return ref;
|
2002-10-18 02:24:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static LPVOID WINAPI IGetFrame_fnGetFrame(IGetFrame *iface, LONG lPos)
|
|
|
|
{
|
2010-12-27 23:18:54 +01:00
|
|
|
IGetFrameImpl *This = impl_from_IGetFrame(iface);
|
2002-10-18 02:24:41 +02:00
|
|
|
|
|
|
|
LONG readBytes;
|
|
|
|
LONG readSamples;
|
|
|
|
|
2006-10-10 01:07:06 +02:00
|
|
|
TRACE("(%p,%d)\n", iface, lPos);
|
2002-10-18 02:24:41 +02:00
|
|
|
|
2003-10-04 05:05:25 +02:00
|
|
|
/* We don't want negative start values! -- marks invalid buffer content */
|
|
|
|
if (lPos < 0)
|
|
|
|
return NULL;
|
|
|
|
|
2002-10-18 02:24:41 +02:00
|
|
|
/* check state */
|
|
|
|
if (This->pStream == NULL)
|
|
|
|
return NULL;
|
|
|
|
if (This->lpInFormat == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* Could stream have changed? */
|
|
|
|
if (! This->bFixedStream) {
|
|
|
|
AVISTREAMINFOW sInfo;
|
|
|
|
|
|
|
|
IAVIStream_Info(This->pStream, &sInfo, sizeof(sInfo));
|
|
|
|
|
|
|
|
if (sInfo.dwEditCount != This->dwEditCount) {
|
|
|
|
This->dwEditCount = sInfo.dwEditCount;
|
|
|
|
This->lCurrentFrame = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sInfo.dwFormatChangeCount != This->dwFormatChangeCount) {
|
|
|
|
/* stream has changed */
|
|
|
|
if (This->lpOutFormat != NULL) {
|
|
|
|
BITMAPINFOHEADER bi;
|
|
|
|
|
2008-02-11 21:48:51 +01:00
|
|
|
bi = *This->lpOutFormat;
|
2002-10-18 02:24:41 +02:00
|
|
|
AVIFILE_CloseCompressor(This);
|
|
|
|
|
|
|
|
if (FAILED(IGetFrame_SetFormat(iface, &bi, NULL, 0, 0, -1, -1))) {
|
|
|
|
if (FAILED(IGetFrame_SetFormat(iface, NULL, NULL, 0, 0, -1, -1)))
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
} else if (FAILED(IGetFrame_SetFormat(iface, NULL, NULL, 0, 0, -1, -1)))
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lPos != This->lCurrentFrame) {
|
2003-10-04 05:05:25 +02:00
|
|
|
LONG lNext = IAVIStream_FindSample(This->pStream,lPos,FIND_KEY|FIND_PREV);
|
2002-10-18 02:24:41 +02:00
|
|
|
|
|
|
|
if (lNext == -1)
|
2003-10-04 05:05:25 +02:00
|
|
|
return NULL; /* frame doesn't exist */
|
2002-10-18 02:24:41 +02:00
|
|
|
if (lNext <= This->lCurrentFrame && This->lCurrentFrame < lPos)
|
2003-09-02 02:54:30 +02:00
|
|
|
lNext = This->lCurrentFrame + 1;
|
2002-10-18 02:24:41 +02:00
|
|
|
|
2003-09-02 02:54:30 +02:00
|
|
|
for (; lNext <= lPos; lNext++) {
|
2002-10-18 02:24:41 +02:00
|
|
|
/* new format for this frame? */
|
|
|
|
if (This->bFormatChanges) {
|
2003-10-04 05:05:25 +02:00
|
|
|
IAVIStream_ReadFormat(This->pStream, lNext,
|
|
|
|
This->lpInFormat, &This->cbInFormat);
|
2002-10-18 02:24:41 +02:00
|
|
|
if (This->lpOutFormat != NULL) {
|
|
|
|
if (This->lpOutFormat->biBitCount <= 8)
|
|
|
|
ICDecompressGetPalette(This->hic, This->lpInFormat,
|
|
|
|
This->lpOutFormat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read input frame */
|
|
|
|
while (FAILED(AVIStreamRead(This->pStream, lNext, 1, This->lpInBuffer,
|
|
|
|
This->cbInBuffer, &readBytes, &readSamples))) {
|
|
|
|
/* not enough memory for input buffer? */
|
|
|
|
readBytes = 0;
|
|
|
|
if (FAILED(AVIStreamSampleSize(This->pStream, lNext, &readBytes)))
|
2003-10-04 05:05:25 +02:00
|
|
|
return NULL; /* bad thing, but bad things will happen */
|
|
|
|
if (readBytes <= 0) {
|
|
|
|
ERR(": IAVIStream::REad doesn't return needed bytes!\n");
|
2002-10-18 02:24:41 +02:00
|
|
|
return NULL;
|
2003-10-04 05:05:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* IAVIStream::Read failed because of other reasons not buffersize? */
|
2002-10-18 02:24:41 +02:00
|
|
|
if (This->cbInBuffer >= readBytes)
|
|
|
|
break;
|
2003-10-04 05:05:25 +02:00
|
|
|
This->cbInBuffer = This->cbInFormat + readBytes;
|
2006-03-10 16:21:42 +01:00
|
|
|
This->lpInFormat = HeapReAlloc(GetProcessHeap(), 0, This->lpInFormat, This->cbInBuffer);
|
2002-10-18 02:24:41 +02:00
|
|
|
if (This->lpInFormat == NULL)
|
2003-10-04 05:05:25 +02:00
|
|
|
return NULL; /* out of memory */
|
2002-10-18 02:24:41 +02:00
|
|
|
This->lpInBuffer = (BYTE*)This->lpInFormat + This->cbInFormat;
|
|
|
|
}
|
|
|
|
|
2003-10-04 05:05:25 +02:00
|
|
|
if (readSamples != 1) {
|
|
|
|
ERR(": no frames read\n");
|
2002-10-18 02:24:41 +02:00
|
|
|
return NULL;
|
2003-10-04 05:05:25 +02:00
|
|
|
}
|
2002-10-18 02:24:41 +02:00
|
|
|
if (readBytes != 0) {
|
|
|
|
This->lpInFormat->biSizeImage = readBytes;
|
|
|
|
|
|
|
|
/* nothing to decompress? */
|
2002-12-02 19:10:57 +01:00
|
|
|
if (This->hic == NULL) {
|
2002-10-18 02:24:41 +02:00
|
|
|
This->lCurrentFrame = lPos;
|
|
|
|
return This->lpInFormat;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (This->bResize) {
|
|
|
|
ICDecompressEx(This->hic,0,This->lpInFormat,This->lpInBuffer,0,0,
|
|
|
|
This->lpInFormat->biWidth,This->lpInFormat->biHeight,
|
|
|
|
This->lpOutFormat,This->lpOutBuffer,This->x,This->y,
|
|
|
|
This->dx,This->dy);
|
|
|
|
} else {
|
|
|
|
ICDecompress(This->hic, 0, This->lpInFormat, This->lpInBuffer,
|
|
|
|
This->lpOutFormat, This->lpOutBuffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} /* for (lNext < lPos) */
|
|
|
|
} /* if (This->lCurrentFrame != lPos) */
|
|
|
|
|
2002-12-02 19:10:57 +01:00
|
|
|
return (This->hic == NULL ? This->lpInFormat : This->lpOutFormat);
|
2002-10-18 02:24:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI IGetFrame_fnBegin(IGetFrame *iface, LONG lStart,
|
|
|
|
LONG lEnd, LONG lRate)
|
|
|
|
{
|
2010-12-27 23:18:54 +01:00
|
|
|
IGetFrameImpl *This = impl_from_IGetFrame(iface);
|
2002-10-18 02:24:41 +02:00
|
|
|
|
2006-10-10 01:07:06 +02:00
|
|
|
TRACE("(%p,%d,%d,%d)\n", iface, lStart, lEnd, lRate);
|
2002-10-18 02:24:41 +02:00
|
|
|
|
|
|
|
This->bFixedStream = TRUE;
|
|
|
|
|
|
|
|
return (IGetFrame_GetFrame(iface, lStart) ? AVIERR_OK : AVIERR_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI IGetFrame_fnEnd(IGetFrame *iface)
|
|
|
|
{
|
2010-12-27 23:18:54 +01:00
|
|
|
IGetFrameImpl *This = impl_from_IGetFrame(iface);
|
2002-10-18 02:24:41 +02:00
|
|
|
|
|
|
|
TRACE("(%p)\n", iface);
|
|
|
|
|
|
|
|
This->bFixedStream = FALSE;
|
|
|
|
|
|
|
|
return AVIERR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI IGetFrame_fnSetFormat(IGetFrame *iface,
|
|
|
|
LPBITMAPINFOHEADER lpbiWanted,
|
|
|
|
LPVOID lpBits, INT x, INT y,
|
|
|
|
INT dx, INT dy)
|
|
|
|
{
|
2010-12-27 23:18:54 +01:00
|
|
|
IGetFrameImpl *This = impl_from_IGetFrame(iface);
|
2002-10-18 02:24:41 +02:00
|
|
|
|
|
|
|
AVISTREAMINFOW sInfo;
|
|
|
|
LPBITMAPINFOHEADER lpbi = lpbiWanted;
|
|
|
|
BOOL bBestDisplay = FALSE;
|
|
|
|
|
|
|
|
TRACE("(%p,%p,%p,%d,%d,%d,%d)\n", iface, lpbiWanted, lpBits,
|
|
|
|
x, y, dx, dy);
|
|
|
|
|
|
|
|
if (This->pStream == NULL)
|
|
|
|
return AVIERR_ERROR;
|
|
|
|
|
2005-09-12 17:14:06 +02:00
|
|
|
if (lpbiWanted == (LPBITMAPINFOHEADER)AVIGETFRAMEF_BESTDISPLAYFMT) {
|
2002-10-18 02:24:41 +02:00
|
|
|
lpbi = NULL;
|
|
|
|
bBestDisplay = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
IAVIStream_Info(This->pStream, &sInfo, sizeof(sInfo));
|
|
|
|
if (sInfo.fccType != streamtypeVIDEO)
|
|
|
|
return AVIERR_UNSUPPORTED;
|
|
|
|
|
|
|
|
This->bFormatChanges =
|
|
|
|
(sInfo.dwFlags & AVISTREAMINFO_FORMATCHANGES ? TRUE : FALSE );
|
|
|
|
This->dwFormatChangeCount = sInfo.dwFormatChangeCount;
|
|
|
|
This->dwEditCount = sInfo.dwEditCount;
|
|
|
|
This->lCurrentFrame = -1;
|
|
|
|
|
|
|
|
/* get input format from stream */
|
|
|
|
if (This->lpInFormat == NULL) {
|
2002-10-23 20:47:20 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
2003-06-23 20:10:06 +02:00
|
|
|
This->cbInBuffer = (LONG)sInfo.dwSuggestedBufferSize;
|
2002-10-18 02:24:41 +02:00
|
|
|
if (This->cbInBuffer == 0)
|
|
|
|
This->cbInBuffer = 1024;
|
|
|
|
|
2003-10-04 05:05:25 +02:00
|
|
|
IAVIStream_ReadFormat(This->pStream, sInfo.dwStart,
|
|
|
|
NULL, &This->cbInFormat);
|
2002-10-18 02:24:41 +02:00
|
|
|
|
2006-04-12 12:32:22 +02:00
|
|
|
This->lpInFormat = HeapAlloc(GetProcessHeap(), 0, This->cbInFormat + This->cbInBuffer);
|
2002-10-18 02:24:41 +02:00
|
|
|
if (This->lpInFormat == NULL) {
|
|
|
|
AVIFILE_CloseCompressor(This);
|
|
|
|
return AVIERR_MEMORY;
|
|
|
|
}
|
|
|
|
|
2003-10-04 05:05:25 +02:00
|
|
|
hr = IAVIStream_ReadFormat(This->pStream, sInfo.dwStart, This->lpInFormat, &This->cbInFormat);
|
2002-10-23 20:47:20 +02:00
|
|
|
if (FAILED(hr)) {
|
|
|
|
AVIFILE_CloseCompressor(This);
|
|
|
|
return hr;
|
|
|
|
}
|
2002-10-18 02:24:41 +02:00
|
|
|
|
|
|
|
This->lpInBuffer = ((LPBYTE)This->lpInFormat) + This->cbInFormat;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check input format */
|
|
|
|
if (This->lpInFormat->biClrUsed == 0 && This->lpInFormat->biBitCount <= 8)
|
|
|
|
This->lpInFormat->biClrUsed = 1u << This->lpInFormat->biBitCount;
|
|
|
|
if (This->lpInFormat->biSizeImage == 0 &&
|
|
|
|
This->lpInFormat->biCompression == BI_RGB) {
|
|
|
|
This->lpInFormat->biSizeImage =
|
|
|
|
DIBWIDTHBYTES(*This->lpInFormat) * This->lpInFormat->biHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* only to pass through? */
|
|
|
|
if (This->lpInFormat->biCompression == BI_RGB && lpBits == NULL) {
|
|
|
|
if (lpbi == NULL ||
|
|
|
|
(lpbi->biCompression == BI_RGB &&
|
|
|
|
lpbi->biWidth == This->lpInFormat->biWidth &&
|
|
|
|
lpbi->biHeight == This->lpInFormat->biHeight &&
|
|
|
|
lpbi->biBitCount == This->lpInFormat->biBitCount)) {
|
|
|
|
This->lpOutFormat = This->lpInFormat;
|
|
|
|
This->lpOutBuffer = DIBPTR(This->lpInFormat);
|
|
|
|
return AVIERR_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* need memory for output format? */
|
|
|
|
if (This->lpOutFormat == NULL) {
|
|
|
|
This->lpOutFormat =
|
2006-04-12 12:32:22 +02:00
|
|
|
HeapAlloc(GetProcessHeap(), 0, sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
|
2002-10-18 02:24:41 +02:00
|
|
|
if (This->lpOutFormat == NULL) {
|
|
|
|
AVIFILE_CloseCompressor(This);
|
|
|
|
return AVIERR_MEMORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* need handle to video compressor */
|
2002-12-02 19:10:57 +01:00
|
|
|
if (This->hic == NULL) {
|
2002-10-18 02:24:41 +02:00
|
|
|
FOURCC fccHandler;
|
|
|
|
|
|
|
|
if (This->lpInFormat->biCompression == BI_RGB)
|
|
|
|
fccHandler = comptypeDIB;
|
|
|
|
else if (This->lpInFormat->biCompression == BI_RLE8)
|
|
|
|
fccHandler = mmioFOURCC('R','L','E',' ');
|
|
|
|
else
|
|
|
|
fccHandler = sInfo.fccHandler;
|
|
|
|
|
|
|
|
if (lpbi != NULL) {
|
|
|
|
if (lpbi->biWidth == 0)
|
|
|
|
lpbi->biWidth = This->lpInFormat->biWidth;
|
|
|
|
if (lpbi->biHeight == 0)
|
|
|
|
lpbi->biHeight = This->lpInFormat->biHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
This->hic = ICLocate(ICTYPE_VIDEO, fccHandler, This->lpInFormat, lpbi, ICMODE_DECOMPRESS);
|
2002-12-02 19:10:57 +01:00
|
|
|
if (This->hic == NULL) {
|
2002-10-18 02:24:41 +02:00
|
|
|
AVIFILE_CloseCompressor(This);
|
|
|
|
return AVIERR_NOCOMPRESSOR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* output format given? */
|
|
|
|
if (lpbi != NULL) {
|
|
|
|
/* check the given output format ... */
|
|
|
|
if (lpbi->biClrUsed == 0 && lpbi->biBitCount <= 8)
|
|
|
|
lpbi->biClrUsed = 1u << lpbi->biBitCount;
|
|
|
|
|
|
|
|
/* ... and remember it */
|
|
|
|
memcpy(This->lpOutFormat, lpbi,
|
|
|
|
lpbi->biSize + lpbi->biClrUsed * sizeof(RGBQUAD));
|
|
|
|
if (lpbi->biBitCount <= 8)
|
|
|
|
ICDecompressGetPalette(This->hic, This->lpInFormat, This->lpOutFormat);
|
|
|
|
|
|
|
|
return AVIERR_OK;
|
|
|
|
} else {
|
|
|
|
if (bBestDisplay) {
|
|
|
|
ICGetDisplayFormat(This->hic, This->lpInFormat,
|
|
|
|
This->lpOutFormat, 0, dx, dy);
|
|
|
|
} else if (ICDecompressGetFormat(This->hic, This->lpInFormat,
|
|
|
|
This->lpOutFormat) < 0) {
|
|
|
|
AVIFILE_CloseCompressor(This);
|
|
|
|
return AVIERR_NOCOMPRESSOR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check output format */
|
|
|
|
if (This->lpOutFormat->biClrUsed == 0 &&
|
|
|
|
This->lpOutFormat->biBitCount <= 8)
|
|
|
|
This->lpOutFormat->biClrUsed = 1u << This->lpOutFormat->biBitCount;
|
|
|
|
if (This->lpOutFormat->biSizeImage == 0 &&
|
|
|
|
This->lpOutFormat->biCompression == BI_RGB) {
|
|
|
|
This->lpOutFormat->biSizeImage =
|
|
|
|
DIBWIDTHBYTES(*This->lpOutFormat) * This->lpOutFormat->biHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lpBits == NULL) {
|
|
|
|
register DWORD size = This->lpOutFormat->biClrUsed * sizeof(RGBQUAD);
|
|
|
|
|
|
|
|
size += This->lpOutFormat->biSize + This->lpOutFormat->biSizeImage;
|
2006-03-10 16:21:42 +01:00
|
|
|
This->lpOutFormat = HeapReAlloc(GetProcessHeap(), 0, This->lpOutFormat, size);
|
2002-10-18 02:24:41 +02:00
|
|
|
if (This->lpOutFormat == NULL) {
|
|
|
|
AVIFILE_CloseCompressor(This);
|
|
|
|
return AVIERR_MEMORY;
|
|
|
|
}
|
|
|
|
This->lpOutBuffer = DIBPTR(This->lpOutFormat);
|
|
|
|
} else
|
|
|
|
This->lpOutBuffer = lpBits;
|
|
|
|
|
|
|
|
/* for user size was irrelevant */
|
|
|
|
if (dx == -1)
|
|
|
|
dx = This->lpOutFormat->biWidth;
|
|
|
|
if (dy == -1)
|
|
|
|
dy = This->lpOutFormat->biHeight;
|
|
|
|
|
|
|
|
/* need to resize? */
|
|
|
|
if (x != 0 || y != 0) {
|
|
|
|
if (dy == This->lpOutFormat->biHeight &&
|
|
|
|
dx == This->lpOutFormat->biWidth)
|
|
|
|
This->bResize = FALSE;
|
|
|
|
else
|
|
|
|
This->bResize = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (This->bResize) {
|
|
|
|
This->x = x;
|
|
|
|
This->y = y;
|
|
|
|
This->dx = dx;
|
|
|
|
This->dy = dy;
|
|
|
|
|
|
|
|
if (ICDecompressExBegin(This->hic,0,This->lpInFormat,This->lpInBuffer,0,
|
|
|
|
0,This->lpInFormat->biWidth,
|
|
|
|
This->lpInFormat->biHeight,This->lpOutFormat,
|
|
|
|
This->lpOutBuffer, x, y, dx, dy) == ICERR_OK)
|
|
|
|
return AVIERR_OK;
|
|
|
|
} else if (ICDecompressBegin(This->hic, This->lpInFormat,
|
|
|
|
This->lpOutFormat) == ICERR_OK)
|
|
|
|
return AVIERR_OK;
|
|
|
|
|
|
|
|
AVIFILE_CloseCompressor(This);
|
|
|
|
|
|
|
|
return AVIERR_COMPRESSOR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-27 23:26:23 +01:00
|
|
|
static const struct IGetFrameVtbl igetframeVtbl = {
|
|
|
|
IGetFrame_fnQueryInterface,
|
|
|
|
IGetFrame_fnAddRef,
|
|
|
|
IGetFrame_fnRelease,
|
|
|
|
IGetFrame_fnGetFrame,
|
|
|
|
IGetFrame_fnBegin,
|
|
|
|
IGetFrame_fnEnd,
|
|
|
|
IGetFrame_fnSetFormat
|
|
|
|
};
|
|
|
|
|
|
|
|
PGETFRAME AVIFILE_CreateGetFrame(PAVISTREAM pStream)
|
|
|
|
{
|
|
|
|
IGetFrameImpl *pg;
|
|
|
|
|
|
|
|
/* check parameter */
|
|
|
|
if (pStream == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
pg = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IGetFrameImpl));
|
|
|
|
if (pg != NULL) {
|
|
|
|
pg->IGetFrame_iface.lpVtbl = &igetframeVtbl;
|
|
|
|
pg->ref = 1;
|
|
|
|
pg->lCurrentFrame = -1;
|
|
|
|
pg->pStream = pStream;
|
|
|
|
IAVIStream_AddRef(pStream);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (PGETFRAME)pg;
|
|
|
|
}
|
|
|
|
|
2002-10-18 02:24:41 +02:00
|
|
|
/***********************************************************************/
|