2 * Wrapper for 16 bit avifile functions
4 * Copyright 2016 Michael Müller
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "wine/winbase16.h"
26 typedef struct _AVISTREAMINFO16
{
37 DWORD dwInitialFrames
;
38 DWORD dwSuggestedBufferSize
;
43 DWORD dwFormatChangeCount
;
45 } AVISTREAMINFO16
, *LPAVISTREAMINFO16
, *PAVISTREAMINFO16
;
47 struct frame_wrapper16
56 static void free_segptr_frame(struct frame_wrapper16
*wrapper
)
63 for (i
= 0; i
< wrapper
->count
; i
++)
64 FreeSelector16(wrapper
->sel
+ (i
<< __AHSHIFT
));
69 static SEGPTR
alloc_segptr_frame(struct frame_wrapper16
*wrapper
, void *ptr
, DWORD size
)
75 if (wrapper
->ptr
== ptr
&& wrapper
->size
== size
)
76 return MAKESEGPTR(wrapper
->sel
, 0);
77 free_segptr_frame(wrapper
);
82 wrapper
->count
= (size
+ 0xffff) / 0x10000;
83 wrapper
->sel
= AllocSelectorArray16(wrapper
->count
);
87 for (i
= 0; i
< wrapper
->count
; i
++)
89 SetSelectorBase(wrapper
->sel
+ (i
<< __AHSHIFT
), (DWORD
)ptr
+ i
* 0x10000);
90 SetSelectorLimit16(wrapper
->sel
+ (i
<< __AHSHIFT
), size
- 1);
94 return MAKESEGPTR(wrapper
->sel
, 0);
97 /***********************************************************************
98 * AVIStreamGetFrameOpen (AVIFILE.112)
100 PGETFRAME WINAPI
AVIStreamGetFrameOpen16(PAVISTREAM pstream
, LPBITMAPINFOHEADER lpbiWanted
)
102 struct frame_wrapper16
*wrapper
;
105 pg
= AVIStreamGetFrameOpen(pstream
, lpbiWanted
);
106 if (!pg
) return NULL
;
108 wrapper
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*wrapper
));
111 AVIStreamGetFrameClose(pg
);
116 return (PGETFRAME
)wrapper
;
119 /***********************************************************************
120 * AVIStreamGetFrame (AVIFILE.110)
122 SEGPTR WINAPI
AVIStreamGetFrame16(PGETFRAME pg
, LONG pos
)
124 struct frame_wrapper16
*wrapper
= (void *)pg
;
125 BITMAPINFOHEADER
*bih
;
129 bih
= AVIStreamGetFrame(wrapper
->pg
, pos
);
132 DWORD size
= bih
->biSize
+ bih
->biSizeImage
;
133 return alloc_segptr_frame(wrapper
, bih
, size
);
140 /***********************************************************************
141 * AVIStreamGetFrameClose (AVIFILE.111)
143 HRESULT WINAPI
AVIStreamGetFrameClose16(PGETFRAME pg
)
145 struct frame_wrapper16
*wrapper
= (void *)pg
;
148 if (!pg
) return S_OK
;
150 hr
= AVIStreamGetFrameClose(wrapper
->pg
);
151 free_segptr_frame(wrapper
);
152 HeapFree(GetProcessHeap(), 0, wrapper
);
156 /***********************************************************************
157 * AVIFileCreateStream (AVIFILE.144)
159 HRESULT WINAPI
AVIFileCreateStream16(PAVIFILE pfile
, PAVISTREAM
*ppavi
, LPAVISTREAMINFO16 asi16
)
164 return AVIFileCreateStreamA(pfile
, ppavi
, NULL
);
166 asi
.fccType
= asi16
->fccType
;
167 asi
.fccHandler
= asi16
->fccHandler
;
168 asi
.dwFlags
= asi16
->dwFlags
;
169 asi
.dwCaps
= asi16
->dwCaps
;
170 asi
.wPriority
= asi16
->wPriority
;
171 asi
.wLanguage
= asi16
->wLanguage
;
172 asi
.dwScale
= asi16
->dwScale
;
173 asi
.dwRate
= asi16
->dwRate
;
174 asi
.dwStart
= asi16
->dwStart
;
175 asi
.dwLength
= asi16
->dwLength
;
176 asi
.dwInitialFrames
= asi16
->dwInitialFrames
;
177 asi
.dwSuggestedBufferSize
= asi16
->dwSuggestedBufferSize
;
178 asi
.dwQuality
= asi16
->dwQuality
;
179 asi
.dwSampleSize
= asi16
->dwSampleSize
;
180 asi
.rcFrame
.left
= asi16
->rcFrame
.left
;
181 asi
.rcFrame
.top
= asi16
->rcFrame
.top
;
182 asi
.rcFrame
.right
= asi16
->rcFrame
.right
;
183 asi
.rcFrame
.bottom
= asi16
->rcFrame
.bottom
;
184 asi
.dwEditCount
= asi16
->dwEditCount
;
185 asi
.dwFormatChangeCount
= asi16
->dwFormatChangeCount
;
186 strcpy( asi
.szName
, asi16
->szName
);
188 return AVIFileCreateStreamA(pfile
, ppavi
, &asi
);
192 /***********************************************************************
193 * AVIStreamInfo (AVIFILE.162)
195 HRESULT WINAPI
AVIStreamInfo16(PAVISTREAM pstream
, LPAVISTREAMINFO16 asi16
, LONG size
)
201 return AVIStreamInfoA(pstream
, NULL
, size
);
203 if (size
< sizeof(AVISTREAMINFO16
))
204 return AVIERR_BADSIZE
;
206 hr
= AVIStreamInfoA(pstream
, &asi
, sizeof(asi
));
209 asi16
->fccType
= asi
.fccType
;
210 asi16
->fccHandler
= asi
.fccHandler
;
211 asi16
->dwFlags
= asi
.dwFlags
;
212 asi16
->dwCaps
= asi
.dwCaps
;
213 asi16
->wPriority
= asi
.wPriority
;
214 asi16
->wLanguage
= asi
.wLanguage
;
215 asi16
->dwScale
= asi
.dwScale
;
216 asi16
->dwRate
= asi
.dwRate
;
217 asi16
->dwStart
= asi
.dwStart
;
218 asi16
->dwLength
= asi
.dwLength
;
219 asi16
->dwInitialFrames
= asi
.dwInitialFrames
;
220 asi16
->dwSuggestedBufferSize
= asi
.dwSuggestedBufferSize
;
221 asi16
->dwQuality
= asi
.dwQuality
;
222 asi16
->dwSampleSize
= asi
.dwSampleSize
;
223 asi16
->rcFrame
.left
= asi
.rcFrame
.left
;
224 asi16
->rcFrame
.top
= asi
.rcFrame
.top
;
225 asi16
->rcFrame
.right
= asi
.rcFrame
.right
;
226 asi16
->rcFrame
.bottom
= asi
.rcFrame
.bottom
;
227 asi16
->dwEditCount
= asi
.dwEditCount
;
228 asi16
->dwFormatChangeCount
= asi
.dwFormatChangeCount
;
229 strcpy( asi16
->szName
, asi
.szName
);