2 * unix_iface.c - This is the Win32 side of the Unix interface.
4 * Copyright 2020 Esme Povirk
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
23 #define NONAMELESSUNION
31 #include "wincodecs_private.h"
33 #include "wine/debug.h"
35 static INIT_ONCE init_once
= INIT_ONCE_STATIC_INIT
;
37 static const struct unix_funcs
*unix_funcs
;
39 static const struct win32_funcs win32_funcs
= {
46 static BOOL WINAPI
load_unixlib( INIT_ONCE
*once
, void *param
, void **context
)
48 __wine_init_unix_lib( windowscodecs_module
, DLL_PROCESS_ATTACH
, &win32_funcs
, &unix_funcs
);
52 static void init_unixlib(void)
54 InitOnceExecuteOnce( &init_once
, load_unixlib
, NULL
, NULL
);
57 struct decoder_wrapper
59 struct decoder win32_decoder
;
60 struct decoder
*unix_decoder
;
63 static inline struct decoder_wrapper
*impl_from_decoder(struct decoder
* iface
)
65 return CONTAINING_RECORD(iface
, struct decoder_wrapper
, win32_decoder
);
68 HRESULT CDECL
decoder_wrapper_initialize(struct decoder
* iface
, IStream
* stream
, struct decoder_stat
*st
)
70 struct decoder_wrapper
* This
= impl_from_decoder(iface
);
71 return unix_funcs
->decoder_initialize(This
->unix_decoder
, stream
, st
);
74 HRESULT CDECL
decoder_wrapper_get_frame_info(struct decoder
* iface
, UINT frame
, struct decoder_frame
*info
)
76 struct decoder_wrapper
* This
= impl_from_decoder(iface
);
77 return unix_funcs
->decoder_get_frame_info(This
->unix_decoder
, frame
, info
);
80 HRESULT CDECL
decoder_wrapper_copy_pixels(struct decoder
* iface
, UINT frame
,
81 const WICRect
*prc
, UINT stride
, UINT buffersize
, BYTE
*buffer
)
83 struct decoder_wrapper
* This
= impl_from_decoder(iface
);
84 return unix_funcs
->decoder_copy_pixels(This
->unix_decoder
, frame
, prc
, stride
, buffersize
, buffer
);
87 HRESULT CDECL
decoder_wrapper_get_metadata_blocks(struct decoder
* iface
,
88 UINT frame
, UINT
*count
, struct decoder_block
**blocks
)
90 struct decoder_wrapper
* This
= impl_from_decoder(iface
);
91 return unix_funcs
->decoder_get_metadata_blocks(This
->unix_decoder
, frame
, count
, blocks
);
94 HRESULT CDECL
decoder_wrapper_get_color_context(struct decoder
* iface
,
95 UINT frame
, UINT num
, BYTE
**data
, DWORD
*datasize
)
97 struct decoder_wrapper
* This
= impl_from_decoder(iface
);
98 return unix_funcs
->decoder_get_color_context(This
->unix_decoder
, frame
, num
, data
, datasize
);
101 void CDECL
decoder_wrapper_destroy(struct decoder
* iface
)
103 struct decoder_wrapper
* This
= impl_from_decoder(iface
);
104 unix_funcs
->decoder_destroy(This
->unix_decoder
);
105 HeapFree(GetProcessHeap(), 0, This
);
108 static const struct decoder_funcs decoder_wrapper_vtable
= {
109 decoder_wrapper_initialize
,
110 decoder_wrapper_get_frame_info
,
111 decoder_wrapper_copy_pixels
,
112 decoder_wrapper_get_metadata_blocks
,
113 decoder_wrapper_get_color_context
,
114 decoder_wrapper_destroy
117 HRESULT
get_unix_decoder(const CLSID
*decoder_clsid
, struct decoder_info
*info
, struct decoder
**result
)
120 struct decoder_wrapper
*wrapper
;
121 struct decoder
*unix_decoder
;
125 hr
= unix_funcs
->decoder_create(decoder_clsid
, info
, &unix_decoder
);
129 wrapper
= HeapAlloc(GetProcessHeap(), 0, sizeof(*wrapper
));
133 unix_funcs
->decoder_destroy(unix_decoder
);
134 return E_OUTOFMEMORY
;
137 wrapper
->win32_decoder
.vtable
= &decoder_wrapper_vtable
;
138 wrapper
->unix_decoder
= unix_decoder
;
139 *result
= &wrapper
->win32_decoder
;
145 struct encoder_wrapper
147 struct encoder win32_encoder
;
148 struct encoder
*unix_encoder
;
151 static inline struct encoder_wrapper
*impl_from_encoder(struct encoder
* iface
)
153 return CONTAINING_RECORD(iface
, struct encoder_wrapper
, win32_encoder
);
156 HRESULT CDECL
encoder_wrapper_initialize(struct encoder
* iface
, IStream
* stream
)
158 struct encoder_wrapper
* This
= impl_from_encoder(iface
);
159 return unix_funcs
->encoder_initialize(This
->unix_encoder
, stream
);
162 HRESULT CDECL
encoder_wrapper_get_supported_format(struct encoder
* iface
, GUID
*pixel_format
, DWORD
*bpp
, BOOL
*indexed
)
164 struct encoder_wrapper
* This
= impl_from_encoder(iface
);
165 return unix_funcs
->encoder_get_supported_format(This
->unix_encoder
, pixel_format
, bpp
, indexed
);
168 HRESULT CDECL
encoder_wrapper_create_frame(struct encoder
* iface
, const struct encoder_frame
*frame
)
170 struct encoder_wrapper
* This
= impl_from_encoder(iface
);
171 return unix_funcs
->encoder_create_frame(This
->unix_encoder
, frame
);
174 HRESULT CDECL
encoder_wrapper_write_lines(struct encoder
* iface
, BYTE
*data
, DWORD line_count
, DWORD stride
)
176 struct encoder_wrapper
* This
= impl_from_encoder(iface
);
177 return unix_funcs
->encoder_write_lines(This
->unix_encoder
, data
, line_count
, stride
);
180 HRESULT CDECL
encoder_wrapper_commit_frame(struct encoder
* iface
)
182 struct encoder_wrapper
* This
= impl_from_encoder(iface
);
183 return unix_funcs
->encoder_commit_frame(This
->unix_encoder
);
186 HRESULT CDECL
encoder_wrapper_commit_file(struct encoder
* iface
)
188 struct encoder_wrapper
* This
= impl_from_encoder(iface
);
189 return unix_funcs
->encoder_commit_file(This
->unix_encoder
);
192 void CDECL
encoder_wrapper_destroy(struct encoder
* iface
)
194 struct encoder_wrapper
* This
= impl_from_encoder(iface
);
195 unix_funcs
->encoder_destroy(This
->unix_encoder
);
196 HeapFree(GetProcessHeap(), 0, This
);
199 static const struct encoder_funcs encoder_wrapper_vtable
= {
200 encoder_wrapper_initialize
,
201 encoder_wrapper_get_supported_format
,
202 encoder_wrapper_create_frame
,
203 encoder_wrapper_write_lines
,
204 encoder_wrapper_commit_frame
,
205 encoder_wrapper_commit_file
,
206 encoder_wrapper_destroy
209 HRESULT
get_unix_encoder(const CLSID
*encoder_clsid
, struct encoder_info
*info
, struct encoder
**result
)
212 struct encoder_wrapper
*wrapper
;
213 struct encoder
*unix_encoder
;
217 hr
= unix_funcs
->encoder_create(encoder_clsid
, info
, &unix_encoder
);
221 wrapper
= HeapAlloc(GetProcessHeap(), 0, sizeof(*wrapper
));
225 unix_funcs
->encoder_destroy(unix_encoder
);
226 return E_OUTOFMEMORY
;
229 wrapper
->win32_encoder
.vtable
= &encoder_wrapper_vtable
;
230 wrapper
->unix_encoder
= unix_encoder
;
231 *result
= &wrapper
->win32_encoder
;