Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/dlls/avifile.dll16/main.c
4389 views
1
/*
2
* Wrapper for 16 bit avifile functions
3
*
4
* Copyright 2016 Michael Müller
5
*
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.
10
*
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.
15
*
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
19
*/
20
21
#include "wine/winbase16.h"
22
#include "winternl.h"
23
#include "wingdi.h"
24
#include "vfw.h"
25
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;
46
47
struct frame_wrapper16
48
{
49
PGETFRAME pg;
50
PVOID ptr;
51
DWORD size;
52
WORD sel;
53
WORD count;
54
};
55
56
static void free_segptr_frame(struct frame_wrapper16 *wrapper)
57
{
58
int i;
59
60
if (!wrapper->sel)
61
return;
62
63
for (i = 0; i < wrapper->count; i++)
64
FreeSelector16(wrapper->sel + (i << __AHSHIFT));
65
66
wrapper->sel = 0;
67
}
68
69
static SEGPTR alloc_segptr_frame(struct frame_wrapper16 *wrapper, void *ptr, DWORD size)
70
{
71
int i;
72
73
if (wrapper->sel)
74
{
75
if (wrapper->ptr == ptr && wrapper->size == size)
76
return MAKESEGPTR(wrapper->sel, 0);
77
free_segptr_frame(wrapper);
78
}
79
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;
86
87
for (i = 0; i < wrapper->count; i++)
88
{
89
SetSelectorBase(wrapper->sel + (i << __AHSHIFT), (DWORD)ptr + i * 0x10000);
90
SetSelectorLimit16(wrapper->sel + (i << __AHSHIFT), size - 1);
91
size -= 0x10000;
92
}
93
94
return MAKESEGPTR(wrapper->sel, 0);
95
}
96
97
/***********************************************************************
98
* AVIStreamGetFrameOpen (AVIFILE.112)
99
*/
100
PGETFRAME WINAPI AVIStreamGetFrameOpen16(PAVISTREAM pstream, LPBITMAPINFOHEADER lpbiWanted)
101
{
102
struct frame_wrapper16 *wrapper;
103
PGETFRAME pg;
104
105
pg = AVIStreamGetFrameOpen(pstream, lpbiWanted);
106
if (!pg) return NULL;
107
108
wrapper = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*wrapper));
109
if (!wrapper)
110
{
111
AVIStreamGetFrameClose(pg);
112
return NULL;
113
}
114
115
wrapper->pg = pg;
116
return (PGETFRAME)wrapper;
117
}
118
119
/***********************************************************************
120
* AVIStreamGetFrame (AVIFILE.110)
121
*/
122
SEGPTR WINAPI AVIStreamGetFrame16(PGETFRAME pg, LONG pos)
123
{
124
struct frame_wrapper16 *wrapper = (void *)pg;
125
BITMAPINFOHEADER *bih;
126
127
if (!pg) return 0;
128
129
bih = AVIStreamGetFrame(wrapper->pg, pos);
130
if (bih)
131
{
132
DWORD size = bih->biSize + bih->biSizeImage;
133
return alloc_segptr_frame(wrapper, bih, size);
134
}
135
136
return 0;
137
}
138
139
140
/***********************************************************************
141
* AVIStreamGetFrameClose (AVIFILE.111)
142
*/
143
HRESULT WINAPI AVIStreamGetFrameClose16(PGETFRAME pg)
144
{
145
struct frame_wrapper16 *wrapper = (void *)pg;
146
HRESULT hr;
147
148
if (!pg) return S_OK;
149
150
hr = AVIStreamGetFrameClose(wrapper->pg);
151
free_segptr_frame(wrapper);
152
HeapFree(GetProcessHeap(), 0, wrapper);
153
return hr;
154
}
155
156
/***********************************************************************
157
* AVIFileCreateStream (AVIFILE.144)
158
*/
159
HRESULT WINAPI AVIFileCreateStream16(PAVIFILE pfile, PAVISTREAM *ppavi, LPAVISTREAMINFO16 asi16)
160
{
161
AVISTREAMINFOA asi;
162
163
if (!asi16)
164
return AVIFileCreateStreamA(pfile, ppavi, NULL);
165
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 );
187
188
return AVIFileCreateStreamA(pfile, ppavi, &asi);
189
}
190
191
192
/***********************************************************************
193
* AVIStreamInfo (AVIFILE.162)
194
*/
195
HRESULT WINAPI AVIStreamInfo16(PAVISTREAM pstream, LPAVISTREAMINFO16 asi16, LONG size)
196
{
197
AVISTREAMINFOA asi;
198
HRESULT hr;
199
200
if (!asi16)
201
return AVIStreamInfoA(pstream, NULL, size);
202
203
if (size < sizeof(AVISTREAMINFO16))
204
return AVIERR_BADSIZE;
205
206
hr = AVIStreamInfoA(pstream, &asi, sizeof(asi));
207
if (SUCCEEDED(hr))
208
{
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 );
230
}
231
232
return hr;
233
}
234
235