cmd: DIR command outputs free space for the path.
[wine.git] / dlls / avifile.dll16 / main.c
blob6c2d992c63048fab06940ea81dbb48ab57938dda
1 /*
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"
22 #include "winternl.h"
23 #include "wingdi.h"
24 #include "vfw.h"
26 typedef struct _AVISTREAMINFO16 {
27 DWORD fccType;
28 DWORD fccHandler;
29 DWORD dwFlags;
30 DWORD dwCaps;
31 WORD wPriority;
32 WORD wLanguage;
33 DWORD dwScale;
34 DWORD dwRate;
35 DWORD dwStart;
36 DWORD dwLength;
37 DWORD dwInitialFrames;
38 DWORD dwSuggestedBufferSize;
39 DWORD dwQuality;
40 DWORD dwSampleSize;
41 RECT16 rcFrame;
42 DWORD dwEditCount;
43 DWORD dwFormatChangeCount;
44 CHAR szName[64];
45 } AVISTREAMINFO16, *LPAVISTREAMINFO16, *PAVISTREAMINFO16;
47 struct frame_wrapper16
49 PGETFRAME pg;
50 PVOID ptr;
51 DWORD size;
52 WORD sel;
53 WORD count;
56 static void free_segptr_frame(struct frame_wrapper16 *wrapper)
58 int i;
60 if (!wrapper->sel)
61 return;
63 for (i = 0; i < wrapper->count; i++)
64 FreeSelector16(wrapper->sel + (i << __AHSHIFT));
66 wrapper->sel = 0;
69 static SEGPTR alloc_segptr_frame(struct frame_wrapper16 *wrapper, void *ptr, DWORD size)
71 int i;
73 if (wrapper->sel)
75 if (wrapper->ptr == ptr && wrapper->size == size)
76 return MAKESEGPTR(wrapper->sel, 0);
77 free_segptr_frame(wrapper);
80 wrapper->ptr = ptr;
81 wrapper->size = size;
82 wrapper->count = (size + 0xffff) / 0x10000;
83 wrapper->sel = AllocSelectorArray16(wrapper->count);
84 if (!wrapper->sel)
85 return 0;
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);
91 size -= 0x10000;
94 return MAKESEGPTR(wrapper->sel, 0);
97 /***********************************************************************
98 * AVIStreamGetFrameOpen (AVIFILE.112)
100 PGETFRAME WINAPI AVIStreamGetFrameOpen16(PAVISTREAM pstream, LPBITMAPINFOHEADER lpbiWanted)
102 struct frame_wrapper16 *wrapper;
103 PGETFRAME pg;
105 pg = AVIStreamGetFrameOpen(pstream, lpbiWanted);
106 if (!pg) return NULL;
108 wrapper = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*wrapper));
109 if (!wrapper)
111 AVIStreamGetFrameClose(pg);
112 return NULL;
115 wrapper->pg = 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;
127 if (!pg) return 0;
129 bih = AVIStreamGetFrame(wrapper->pg, pos);
130 if (bih)
132 DWORD size = bih->biSize + bih->biSizeImage;
133 return alloc_segptr_frame(wrapper, bih, size);
136 return 0;
140 /***********************************************************************
141 * AVIStreamGetFrameClose (AVIFILE.111)
143 HRESULT WINAPI AVIStreamGetFrameClose16(PGETFRAME pg)
145 struct frame_wrapper16 *wrapper = (void *)pg;
146 HRESULT hr;
148 if (!pg) return S_OK;
150 hr = AVIStreamGetFrameClose(wrapper->pg);
151 free_segptr_frame(wrapper);
152 HeapFree(GetProcessHeap(), 0, wrapper);
153 return hr;
156 /***********************************************************************
157 * AVIFileCreateStream (AVIFILE.144)
159 HRESULT WINAPI AVIFileCreateStream16(PAVIFILE pfile, PAVISTREAM *ppavi, LPAVISTREAMINFO16 asi16)
161 AVISTREAMINFOA asi;
163 if (!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)
197 AVISTREAMINFOA asi;
198 HRESULT hr;
200 if (!asi16)
201 return AVIStreamInfoA(pstream, NULL, size);
203 if (size < sizeof(AVISTREAMINFO16))
204 return AVIERR_BADSIZE;
206 hr = AVIStreamInfoA(pstream, &asi, sizeof(asi));
207 if (SUCCEEDED(hr))
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 );
232 return hr;