Ignore:
Timestamp:
Sep 5, 2001, 4:16:46 PM (24 years ago)
Author:
bird
Message:

Added $Id:$ keyword.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/avifil32/igframe.c

    r6386 r6652  
     1/* $Id: igframe.c,v 1.2 2001-09-05 14:16:45 bird Exp $ */
    12/*
    23 * Copyright 2001 Hidenori TAKESHIMA <hidenori@a2.ctktv.ne.jp>
     
    2930struct ICOM_VTABLE(IGetFrame) igetfrm = {
    3031    ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
    31         IGetFrame_fnQueryInterface,
    32         IGetFrame_fnAddRef,
    33         IGetFrame_fnRelease,
    34         IGetFrame_fnGetFrame,
    35         IGetFrame_fnBegin,
    36         IGetFrame_fnEnd,
    37         IGetFrame_fnSetFormat,
     32    IGetFrame_fnQueryInterface,
     33    IGetFrame_fnAddRef,
     34    IGetFrame_fnRelease,
     35    IGetFrame_fnGetFrame,
     36    IGetFrame_fnBegin,
     37    IGetFrame_fnEnd,
     38    IGetFrame_fnSetFormat,
    3839};
    3940
    4041typedef struct IGetFrameImpl
    4142{
    42         ICOM_VFIELD(IGetFrame);
    43         /* IUnknown stuff */
    44         DWORD                   ref;
    45         /* IGetFrame stuff */
    46         IAVIStream*             pas;
    47         HIC                     hIC;
    48         LONG                    lCachedFrame;
    49         BITMAPINFO*             pbiICIn;
    50         BITMAPINFO*             pbiICOut;
    51         LPVOID                  pvICOutBits;
    52         LPVOID                  pvICInFmtBuf;
    53         DWORD                   dwICInDataBufSize;
    54         LPVOID                  pvICInDataBuf;
    55         LPVOID                  pvICOutBuf;
     43    ICOM_VFIELD(IGetFrame);
     44    /* IUnknown stuff */
     45    DWORD           ref;
     46    /* IGetFrame stuff */
     47    IAVIStream*     pas;
     48    HIC         hIC;
     49    LONG            lCachedFrame;
     50    BITMAPINFO*     pbiICIn;
     51    BITMAPINFO*     pbiICOut;
     52    LPVOID          pvICOutBits;
     53    LPVOID          pvICInFmtBuf;
     54    DWORD           dwICInDataBufSize;
     55    LPVOID          pvICInDataBuf;
     56    LPVOID          pvICOutBuf;
    5657} IGetFrameImpl;
    5758
    5859static HRESULT IGetFrame_Construct( IGetFrameImpl* This,
    59                                     IAVIStream* pstr,
    60                                     LPBITMAPINFOHEADER lpbi );
     60                    IAVIStream* pstr,
     61                    LPBITMAPINFOHEADER lpbi );
    6162static void IGetFrame_Destruct( IGetFrameImpl* This );
    6263
     
    6667static LPVOID AVIFILE_IGetFrame_DecodeFrame(IGetFrameImpl* This,LONG lPos)
    6768{
    68         HRESULT hr;
    69         DWORD   dwRes;
    70         LONG    lFrameLength;
    71         LONG    lSampleCount;
    72         ICDECOMPRESS    icd;
    73 
    74         if ( This->hIC == (HIC)NULL )
    75                 return NULL;
    76 
    77         hr = IAVIStream_Read(This->pas,lPos,1,NULL,0,
    78                              &lFrameLength,&lSampleCount);
    79         if ( hr != S_OK || lSampleCount <= 0 )
    80         {
    81                 FIXME( "IAVIStream_Read failed! res = %08lx\n", hr );
    82                 return NULL;
    83         }
    84         TRACE( "frame length = %ld\n", lFrameLength );
    85 
    86         if ( This->dwICInDataBufSize < lFrameLength )
    87         {
    88                 LPVOID  lpv;
    89 
    90                 if ( This->pvICInDataBuf == NULL )
    91                 {
    92                         lpv = HeapAlloc(
    93                                 AVIFILE_data.hHeap,HEAP_ZERO_MEMORY,
    94                                 lFrameLength );
    95                 }
    96                 else
    97                 {
    98                         lpv = HeapReAlloc(
    99                                 AVIFILE_data.hHeap,HEAP_ZERO_MEMORY,
    100                                 This->pvICInDataBuf,lFrameLength );
    101                 }
    102                 if ( lpv == NULL )
    103                 {
    104                         ERR( "out of memory!\n" );
    105                         return NULL;
    106                 }
    107                 This->pvICInDataBuf = lpv;
    108                 This->dwICInDataBufSize = lFrameLength;
    109         }
    110 
    111         hr = IAVIStream_Read(This->pas,lPos,1,
    112                              This->pvICInDataBuf,This->dwICInDataBufSize,
    113                              &lFrameLength,&lSampleCount);
    114         if ( hr != S_OK || lSampleCount <= 0 )
    115         {
    116                 FIXME( "IAVIStream_Read to buffer failed! res = %08lx\n", hr );
    117                 return NULL;
    118         }
    119 
    120         This->pbiICIn->bmiHeader.biSizeImage = lFrameLength;
    121 
    122         TRACE( "call ICM_DECOMPRESS\n" );
    123         icd.dwFlags = (*(BYTE*)This->pvICInDataBuf) == 'c' ?
    124                                       ICDECOMPRESS_NOTKEYFRAME : 0;
    125         icd.lpbiInput = &This->pbiICIn->bmiHeader;
    126         icd.lpInput = (BYTE*)This->pvICInDataBuf + 8;
    127         icd.lpbiOutput = &This->pbiICOut->bmiHeader;
    128         icd.lpOutput = This->pvICOutBits;
    129         icd.ckid = *((DWORD*)This->pvICInDataBuf);
    130         dwRes = ICSendMessage(This->hIC,ICM_DECOMPRESS,
    131                               (DWORD)(&icd),sizeof(ICDECOMPRESS) );
    132         TRACE( "returned from ICM_DECOMPRESS\n" );
    133         if ( dwRes != ICERR_OK )
    134         {
    135                 ERR( "ICDecompress failed!\n" );
    136                 return NULL;
    137         }
    138 
    139         This->lCachedFrame = lPos;
    140 
    141         return This->pvICOutBits;
     69    HRESULT hr;
     70    DWORD   dwRes;
     71    LONG    lFrameLength;
     72    LONG    lSampleCount;
     73    ICDECOMPRESS    icd;
     74
     75    if ( This->hIC == (HIC)NULL )
     76        return NULL;
     77
     78    hr = IAVIStream_Read(This->pas,lPos,1,NULL,0,
     79                 &lFrameLength,&lSampleCount);
     80    if ( hr != S_OK || lSampleCount <= 0 )
     81    {
     82        FIXME( "IAVIStream_Read failed! res = %08lx\n", hr );
     83        return NULL;
     84    }
     85    TRACE( "frame length = %ld\n", lFrameLength );
     86
     87    if ( This->dwICInDataBufSize < lFrameLength )
     88    {
     89        LPVOID  lpv;
     90
     91        if ( This->pvICInDataBuf == NULL )
     92        {
     93            lpv = HeapAlloc(
     94                AVIFILE_data.hHeap,HEAP_ZERO_MEMORY,
     95                lFrameLength );
     96        }
     97        else
     98        {
     99            lpv = HeapReAlloc(
     100                AVIFILE_data.hHeap,HEAP_ZERO_MEMORY,
     101                This->pvICInDataBuf,lFrameLength );
     102        }
     103        if ( lpv == NULL )
     104        {
     105            ERR( "out of memory!\n" );
     106            return NULL;
     107        }
     108        This->pvICInDataBuf = lpv;
     109        This->dwICInDataBufSize = lFrameLength;
     110    }
     111
     112    hr = IAVIStream_Read(This->pas,lPos,1,
     113                 This->pvICInDataBuf,This->dwICInDataBufSize,
     114                 &lFrameLength,&lSampleCount);
     115    if ( hr != S_OK || lSampleCount <= 0 )
     116    {
     117        FIXME( "IAVIStream_Read to buffer failed! res = %08lx\n", hr );
     118        return NULL;
     119    }
     120
     121    This->pbiICIn->bmiHeader.biSizeImage = lFrameLength;
     122
     123    TRACE( "call ICM_DECOMPRESS\n" );
     124    icd.dwFlags = (*(BYTE*)This->pvICInDataBuf) == 'c' ?
     125                      ICDECOMPRESS_NOTKEYFRAME : 0;
     126    icd.lpbiInput = &This->pbiICIn->bmiHeader;
     127    icd.lpInput = (BYTE*)This->pvICInDataBuf + 8;
     128    icd.lpbiOutput = &This->pbiICOut->bmiHeader;
     129    icd.lpOutput = This->pvICOutBits;
     130    icd.ckid = *((DWORD*)This->pvICInDataBuf);
     131    dwRes = ICSendMessage(This->hIC,ICM_DECOMPRESS,
     132                  (DWORD)(&icd),sizeof(ICDECOMPRESS) );
     133    TRACE( "returned from ICM_DECOMPRESS\n" );
     134    if ( dwRes != ICERR_OK )
     135    {
     136        ERR( "ICDecompress failed!\n" );
     137        return NULL;
     138    }
     139
     140    This->lCachedFrame = lPos;
     141
     142    return This->pvICOutBits;
    142143}
    143144
     
    145146
    146147HRESULT AVIFILE_CreateIGetFrame(void** ppobj,
    147                                 IAVIStream* pstr,LPBITMAPINFOHEADER lpbi)
    148 {
    149         IGetFrameImpl   *This;
    150         HRESULT         hr;
    151 
    152         *ppobj = NULL;
    153         This = (IGetFrameImpl*)HeapAlloc(AVIFILE_data.hHeap,HEAP_ZERO_MEMORY,
    154                                           sizeof(IGetFrameImpl));
    155         This->ref = 1;
    156         ICOM_VTBL(This) = &igetfrm;
    157         hr = IGetFrame_Construct( This, pstr, lpbi );
    158         if ( hr != S_OK )
    159         {
    160                 IGetFrame_Destruct( This );
    161                 return hr;
    162         }
    163 
    164         *ppobj = (LPVOID)This;
    165 
    166         return S_OK;
     148                IAVIStream* pstr,LPBITMAPINFOHEADER lpbi)
     149{
     150    IGetFrameImpl   *This;
     151    HRESULT     hr;
     152
     153    *ppobj = NULL;
     154    This = (IGetFrameImpl*)HeapAlloc(AVIFILE_data.hHeap,HEAP_ZERO_MEMORY,
     155                      sizeof(IGetFrameImpl));
     156    This->ref = 1;
     157    ICOM_VTBL(This) = &igetfrm;
     158    hr = IGetFrame_Construct( This, pstr, lpbi );
     159    if ( hr != S_OK )
     160    {
     161        IGetFrame_Destruct( This );
     162        return hr;
     163    }
     164
     165    *ppobj = (LPVOID)This;
     166
     167    return S_OK;
    167168}
    168169
     
    173174static HRESULT WINAPI IGetFrame_fnQueryInterface(IGetFrame* iface,REFIID refiid,LPVOID *obj)
    174175{
    175         ICOM_THIS(IGetFrameImpl,iface);
    176 
    177         TRACE("(%p)->QueryInterface(%s,%p)\n",This,debugstr_guid(refiid),obj);
    178         if ( IsEqualGUID(&IID_IUnknown,refiid) ||
    179              IsEqualGUID(&IID_IGetFrame,refiid) )
    180         {
    181                 IGetFrame_AddRef(iface);
    182                 *obj = iface;
    183                 return S_OK;
    184         }
    185 
    186         return OLE_E_ENUM_NOMORE;
     176    ICOM_THIS(IGetFrameImpl,iface);
     177
     178    TRACE("(%p)->QueryInterface(%s,%p)\n",This,debugstr_guid(refiid),obj);
     179    if ( IsEqualGUID(&IID_IUnknown,refiid) ||
     180         IsEqualGUID(&IID_IGetFrame,refiid) )
     181    {
     182        IGetFrame_AddRef(iface);
     183        *obj = iface;
     184        return S_OK;
     185    }
     186
     187    return OLE_E_ENUM_NOMORE;
    187188}
    188189
    189190static ULONG WINAPI IGetFrame_fnAddRef(IGetFrame* iface)
    190191{
    191         ICOM_THIS(IGetFrameImpl,iface);
    192 
    193         TRACE("(%p)->AddRef()\n",iface);
    194         return ++(This->ref);
     192    ICOM_THIS(IGetFrameImpl,iface);
     193
     194    TRACE("(%p)->AddRef()\n",iface);
     195    return ++(This->ref);
    195196}
    196197
    197198static ULONG WINAPI IGetFrame_fnRelease(IGetFrame* iface)
    198199{
    199         ICOM_THIS(IGetFrameImpl,iface);
    200 
    201         TRACE("(%p)->Release()\n",iface);
    202         if ((--(This->ref)) > 0 )
    203                 return This->ref;
    204         IGetFrame_Destruct(This);
    205         if ( This->pas != NULL )
    206                 IAVIStream_Release( This->pas );
    207 
    208         HeapFree(AVIFILE_data.hHeap,0,iface);
    209         return 0;
     200    ICOM_THIS(IGetFrameImpl,iface);
     201
     202    TRACE("(%p)->Release()\n",iface);
     203    if ((--(This->ref)) > 0 )
     204        return This->ref;
     205    IGetFrame_Destruct(This);
     206    if ( This->pas != NULL )
     207        IAVIStream_Release( This->pas );
     208
     209    HeapFree(AVIFILE_data.hHeap,0,iface);
     210    return 0;
    210211}
    211212
     
    216217static LPVOID WINAPI IGetFrame_fnGetFrame(IGetFrame* iface,LONG lPos)
    217218{
    218         ICOM_THIS(IGetFrameImpl,iface);
    219         LPVOID  lpv;
    220         LONG    lKeyFrame;
    221 
    222         TRACE( "(%p)->(%ld)\n", This, lPos );
    223 
    224         if ( lPos < 0 )
    225                 return NULL;
    226 
    227         if ( This->lCachedFrame == lPos )
    228                 return This->pvICOutBits;
    229         if ( (This->lCachedFrame+1) != lPos )
    230         {
    231                 lKeyFrame = IAVIStream_FindSample( This->pas, lPos,
    232                                                    FIND_KEY | FIND_PREV );
    233                 if ( lKeyFrame < 0 || lKeyFrame > lPos )
    234                         return NULL;
    235                 while ( ++lKeyFrame < lPos )
    236                 {
    237                         lpv = AVIFILE_IGetFrame_DecodeFrame(This, lKeyFrame);
    238                         if ( lpv == NULL )
    239                                 return NULL;
    240                 }
    241         }
    242 
    243         lpv = AVIFILE_IGetFrame_DecodeFrame(This, lPos);
    244         TRACE( "lpv = %p\n",lpv );
    245         if ( lpv == NULL )
    246                 return NULL;
    247 
    248         return lpv;
     219    ICOM_THIS(IGetFrameImpl,iface);
     220    LPVOID  lpv;
     221    LONG    lKeyFrame;
     222
     223    TRACE( "(%p)->(%ld)\n", This, lPos );
     224
     225    if ( lPos < 0 )
     226        return NULL;
     227
     228    if ( This->lCachedFrame == lPos )
     229        return This->pvICOutBits;
     230    if ( (This->lCachedFrame+1) != lPos )
     231    {
     232        lKeyFrame = IAVIStream_FindSample( This->pas, lPos,
     233                           FIND_KEY | FIND_PREV );
     234        if ( lKeyFrame < 0 || lKeyFrame > lPos )
     235            return NULL;
     236        while ( ++lKeyFrame < lPos )
     237        {
     238            lpv = AVIFILE_IGetFrame_DecodeFrame(This, lKeyFrame);
     239            if ( lpv == NULL )
     240                return NULL;
     241        }
     242    }
     243
     244    lpv = AVIFILE_IGetFrame_DecodeFrame(This, lPos);
     245    TRACE( "lpv = %p\n",lpv );
     246    if ( lpv == NULL )
     247        return NULL;
     248
     249    return lpv;
    249250}
    250251
    251252static HRESULT WINAPI IGetFrame_fnBegin(IGetFrame* iface,LONG lStart,LONG lEnd,LONG lRate)
    252253{
    253         ICOM_THIS(IGetFrameImpl,iface);
    254 
    255         TRACE( "(%p)->(%ld,%ld,%ld)\n", This, lStart, lEnd, lRate );
    256 
    257         if ( This->hIC == (HIC)NULL )
    258                 return E_UNEXPECTED;
    259 
    260         if ( ICDecompressBegin( This->hIC,
    261                                 This->pbiICIn,
    262                                 This->pbiICOut ) != ICERR_OK )
    263                 return E_FAIL;
    264 
    265         return S_OK;
     254    ICOM_THIS(IGetFrameImpl,iface);
     255
     256    TRACE( "(%p)->(%ld,%ld,%ld)\n", This, lStart, lEnd, lRate );
     257
     258    if ( This->hIC == (HIC)NULL )
     259        return E_UNEXPECTED;
     260
     261    if ( ICDecompressBegin( This->hIC,
     262                This->pbiICIn,
     263                This->pbiICOut ) != ICERR_OK )
     264        return E_FAIL;
     265
     266    return S_OK;
    266267}
    267268
    268269static HRESULT WINAPI IGetFrame_fnEnd(IGetFrame* iface)
    269270{
    270         ICOM_THIS(IGetFrameImpl,iface);
    271 
    272         TRACE( "(%p)->()\n", This );
    273 
    274         if ( This->hIC == (HIC)NULL )
    275                 return E_UNEXPECTED;
    276 
    277         if ( ICDecompressEnd( This->hIC ) != ICERR_OK )
    278                 return E_FAIL;
    279 
    280         return S_OK;
     271    ICOM_THIS(IGetFrameImpl,iface);
     272
     273    TRACE( "(%p)->()\n", This );
     274
     275    if ( This->hIC == (HIC)NULL )
     276        return E_UNEXPECTED;
     277
     278    if ( ICDecompressEnd( This->hIC ) != ICERR_OK )
     279        return E_FAIL;
     280
     281    return S_OK;
    281282}
    282283
    283284static HRESULT WINAPI IGetFrame_fnSetFormat(IGetFrame* iface,LPBITMAPINFOHEADER lpbi,LPVOID lpBits,INT x,INT y,INT dx,INT dy)
    284285{
    285         ICOM_THIS(IGetFrameImpl,iface);
    286         HRESULT hr;
    287         LONG    fmtlen;
    288         BITMAPINFOHEADER        biTemp;
    289         DWORD   dwSizeImage;
    290 
    291         FIXME( "(%p)->(%p,%p,%d,%d,%d,%d)\n",This,lpbi,lpBits,x,y,dx,dy );
    292 
    293         IGetFrame_Destruct(This);
    294 
    295         hr = IAVIStream_ReadFormat(This->pas,0,NULL,&fmtlen);
    296         if ( hr != S_OK )
    297                 return hr;
    298         This->pvICInFmtBuf = HeapAlloc(
    299                 AVIFILE_data.hHeap,HEAP_ZERO_MEMORY,fmtlen);
    300         if ( This->pvICInFmtBuf == NULL )
    301                 return AVIERR_MEMORY;
    302         hr = IAVIStream_ReadFormat(This->pas,0,This->pvICInFmtBuf,&fmtlen);
    303         if ( hr != S_OK )
    304                 return hr;
    305         This->pbiICIn = (LPBITMAPINFO)This->pvICInFmtBuf;
    306 
    307         This->hIC = (HIC)ICOpen( ICTYPE_VIDEO,
    308                                 This->pbiICIn->bmiHeader.biCompression,
    309                                 ICMODE_DECOMPRESS );
    310         if ( This->hIC == (HIC)NULL )
    311         {
    312                 ERR( "no AVI decompressor for %c%c%c%c.\n",
    313                      (int)(This->pbiICIn->bmiHeader.biCompression>> 0)&0xff,
    314                      (int)(This->pbiICIn->bmiHeader.biCompression>> 8)&0xff,
    315                      (int)(This->pbiICIn->bmiHeader.biCompression>>16)&0xff,
    316                      (int)(This->pbiICIn->bmiHeader.biCompression>>24)&0xff );
    317                 return E_FAIL;
    318         }
    319 
    320         if ( lpbi == NULL || lpbi == ((LPBITMAPINFOHEADER)1) )
    321         {
    322                 memset( &biTemp, 0, sizeof(biTemp) );
    323                 biTemp.biSize = sizeof(BITMAPINFOHEADER);
    324                 biTemp.biWidth = This->pbiICIn->bmiHeader.biWidth;
    325                 biTemp.biHeight = This->pbiICIn->bmiHeader.biHeight;
    326                 biTemp.biPlanes = 1;
    327                 biTemp.biBitCount = 24;
    328                 biTemp.biCompression = 0;
    329                 lpbi = &biTemp;
    330         }
    331 
    332         if ( lpbi->biPlanes != 1 || lpbi->biCompression != 0 )
    333                 return E_FAIL;
    334 
    335         dwSizeImage =
    336                 ((This->pbiICIn->bmiHeader.biWidth*lpbi->biBitCount+7)/8)*
    337                                         This->pbiICIn->bmiHeader.biHeight;
    338         This->pvICOutBuf = HeapAlloc(
    339                 AVIFILE_data.hHeap,HEAP_ZERO_MEMORY,
    340                 (sizeof(BITMAPINFO)+sizeof(RGBQUAD)*256)*2+
    341                 dwSizeImage );
    342         if ( This->pvICOutBuf == NULL )
    343                 return AVIERR_MEMORY;
    344 
    345         This->pbiICOut = (BITMAPINFO*)This->pvICOutBuf;
    346         This->pvICOutBits = (LPVOID)( (BYTE*)This->pvICOutBuf +
    347                                 sizeof(BITMAPINFO) + sizeof(RGBQUAD)*256 );
    348 
    349         This->pbiICOut->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    350         This->pbiICOut->bmiHeader.biWidth = This->pbiICIn->bmiHeader.biWidth;
    351         This->pbiICOut->bmiHeader.biHeight = This->pbiICIn->bmiHeader.biHeight;
    352         This->pbiICOut->bmiHeader.biPlanes = 1;
    353         This->pbiICOut->bmiHeader.biBitCount = lpbi->biBitCount;
    354         This->pbiICOut->bmiHeader.biSizeImage = dwSizeImage;
    355         memcpy( This->pvICOutBits, This->pbiICOut, sizeof(BITMAPINFOHEADER) );
    356 
    357         return S_OK;
     286    ICOM_THIS(IGetFrameImpl,iface);
     287    HRESULT hr;
     288    LONG    fmtlen;
     289    BITMAPINFOHEADER    biTemp;
     290    DWORD   dwSizeImage;
     291
     292    FIXME( "(%p)->(%p,%p,%d,%d,%d,%d)\n",This,lpbi,lpBits,x,y,dx,dy );
     293
     294    IGetFrame_Destruct(This);
     295
     296    hr = IAVIStream_ReadFormat(This->pas,0,NULL,&fmtlen);
     297    if ( hr != S_OK )
     298        return hr;
     299    This->pvICInFmtBuf = HeapAlloc(
     300        AVIFILE_data.hHeap,HEAP_ZERO_MEMORY,fmtlen);
     301    if ( This->pvICInFmtBuf == NULL )
     302        return AVIERR_MEMORY;
     303    hr = IAVIStream_ReadFormat(This->pas,0,This->pvICInFmtBuf,&fmtlen);
     304    if ( hr != S_OK )
     305        return hr;
     306    This->pbiICIn = (LPBITMAPINFO)This->pvICInFmtBuf;
     307
     308    This->hIC = (HIC)ICOpen( ICTYPE_VIDEO,
     309                This->pbiICIn->bmiHeader.biCompression,
     310                ICMODE_DECOMPRESS );
     311    if ( This->hIC == (HIC)NULL )
     312    {
     313        ERR( "no AVI decompressor for %c%c%c%c.\n",
     314             (int)(This->pbiICIn->bmiHeader.biCompression>> 0)&0xff,
     315             (int)(This->pbiICIn->bmiHeader.biCompression>> 8)&0xff,
     316             (int)(This->pbiICIn->bmiHeader.biCompression>>16)&0xff,
     317             (int)(This->pbiICIn->bmiHeader.biCompression>>24)&0xff );
     318        return E_FAIL;
     319    }
     320
     321    if ( lpbi == NULL || lpbi == ((LPBITMAPINFOHEADER)1) )
     322    {
     323        memset( &biTemp, 0, sizeof(biTemp) );
     324        biTemp.biSize = sizeof(BITMAPINFOHEADER);
     325        biTemp.biWidth = This->pbiICIn->bmiHeader.biWidth;
     326        biTemp.biHeight = This->pbiICIn->bmiHeader.biHeight;
     327        biTemp.biPlanes = 1;
     328        biTemp.biBitCount = 24;
     329        biTemp.biCompression = 0;
     330        lpbi = &biTemp;
     331    }
     332
     333    if ( lpbi->biPlanes != 1 || lpbi->biCompression != 0 )
     334        return E_FAIL;
     335
     336    dwSizeImage =
     337        ((This->pbiICIn->bmiHeader.biWidth*lpbi->biBitCount+7)/8)*
     338                    This->pbiICIn->bmiHeader.biHeight;
     339    This->pvICOutBuf = HeapAlloc(
     340        AVIFILE_data.hHeap,HEAP_ZERO_MEMORY,
     341        (sizeof(BITMAPINFO)+sizeof(RGBQUAD)*256)*2+
     342        dwSizeImage );
     343    if ( This->pvICOutBuf == NULL )
     344        return AVIERR_MEMORY;
     345
     346    This->pbiICOut = (BITMAPINFO*)This->pvICOutBuf;
     347    This->pvICOutBits = (LPVOID)( (BYTE*)This->pvICOutBuf +
     348                sizeof(BITMAPINFO) + sizeof(RGBQUAD)*256 );
     349
     350    This->pbiICOut->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
     351    This->pbiICOut->bmiHeader.biWidth = This->pbiICIn->bmiHeader.biWidth;
     352    This->pbiICOut->bmiHeader.biHeight = This->pbiICIn->bmiHeader.biHeight;
     353    This->pbiICOut->bmiHeader.biPlanes = 1;
     354    This->pbiICOut->bmiHeader.biBitCount = lpbi->biBitCount;
     355    This->pbiICOut->bmiHeader.biSizeImage = dwSizeImage;
     356    memcpy( This->pvICOutBits, This->pbiICOut, sizeof(BITMAPINFOHEADER) );
     357
     358    return S_OK;
    358359}
    359360
    360361static HRESULT IGetFrame_Construct( IGetFrameImpl* This,
    361                                     IAVIStream* pstr,
    362                                     LPBITMAPINFOHEADER lpbi )
    363 {
    364         HRESULT hr;
    365 
    366         TRACE( "(%p)->(%p,%p)\n",This,pstr,lpbi );
    367 
    368         IAVIStream_AddRef( pstr );
    369         This->pas = pstr;
    370         This->hIC = (HIC)NULL;
    371         This->lCachedFrame = -1L;
    372         This->pbiICIn = NULL;
    373         This->pbiICOut = NULL;
    374         This->pvICInFmtBuf = NULL;
    375         This->pvICInDataBuf = NULL;
    376         This->dwICInDataBufSize = 0;
    377         This->pvICOutBuf = NULL;
    378 
    379         hr = IGetFrame_SetFormat((IGetFrame*)This,lpbi,NULL,0,0,0,0);
    380         if ( hr != S_OK )
    381                 return hr;
    382 
    383         return S_OK;
     362                    IAVIStream* pstr,
     363                    LPBITMAPINFOHEADER lpbi )
     364{
     365    HRESULT hr;
     366
     367    TRACE( "(%p)->(%p,%p)\n",This,pstr,lpbi );
     368
     369    IAVIStream_AddRef( pstr );
     370    This->pas = pstr;
     371    This->hIC = (HIC)NULL;
     372    This->lCachedFrame = -1L;
     373    This->pbiICIn = NULL;
     374    This->pbiICOut = NULL;
     375    This->pvICInFmtBuf = NULL;
     376    This->pvICInDataBuf = NULL;
     377    This->dwICInDataBufSize = 0;
     378    This->pvICOutBuf = NULL;
     379
     380    hr = IGetFrame_SetFormat((IGetFrame*)This,lpbi,NULL,0,0,0,0);
     381    if ( hr != S_OK )
     382        return hr;
     383
     384    return S_OK;
    384385}
    385386
    386387static void IGetFrame_Destruct( IGetFrameImpl* This )
    387388{
    388         if ( This->hIC != (HIC)NULL )
    389         {
    390                 ICClose( This->hIC );
    391                 This->hIC = (HIC)NULL;
    392         }
    393         if ( This->pvICInFmtBuf != NULL )
    394         {
    395                 HeapFree( AVIFILE_data.hHeap, 0, This->pvICInFmtBuf );
    396                 This->pvICInFmtBuf = NULL;
    397         }
    398         if ( This->pvICInDataBuf != NULL )
    399         {
    400                 HeapFree( AVIFILE_data.hHeap, 0, This->pvICInDataBuf );
    401                 This->pvICInDataBuf = NULL;
    402         }
    403         if ( This->pvICOutBuf != NULL )
    404         {
    405                 HeapFree( AVIFILE_data.hHeap, 0, This->pvICOutBuf );
    406                 This->pvICOutBuf = NULL;
    407         }
    408 
    409         This->lCachedFrame = -1L;
    410         This->pbiICIn = NULL;
    411         This->pbiICOut = NULL;
    412         This->dwICInDataBufSize = 0;
    413 }
     389    if ( This->hIC != (HIC)NULL )
     390    {
     391        ICClose( This->hIC );
     392        This->hIC = (HIC)NULL;
     393    }
     394    if ( This->pvICInFmtBuf != NULL )
     395    {
     396        HeapFree( AVIFILE_data.hHeap, 0, This->pvICInFmtBuf );
     397        This->pvICInFmtBuf = NULL;
     398    }
     399    if ( This->pvICInDataBuf != NULL )
     400    {
     401        HeapFree( AVIFILE_data.hHeap, 0, This->pvICInDataBuf );
     402        This->pvICInDataBuf = NULL;
     403    }
     404    if ( This->pvICOutBuf != NULL )
     405    {
     406        HeapFree( AVIFILE_data.hHeap, 0, This->pvICOutBuf );
     407        This->pvICOutBuf = NULL;
     408    }
     409
     410    This->lCachedFrame = -1L;
     411    This->pbiICIn = NULL;
     412    This->pbiICOut = NULL;
     413    This->dwICInDataBufSize = 0;
     414}
Note: See TracChangeset for help on using the changeset viewer.