windowscodecs: Move PNG CopyPixels to unix lib.
[wine.git] / dlls / windowscodecs / unix_iface.c
blob1af1bca066605069d1a3b77da7c94c562f046995
1 /*
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
21 #include "config.h"
22 #include "wine/port.h"
24 #include <stdarg.h>
26 #define NONAMELESSUNION
27 #define COBJMACROS
29 #include "windef.h"
30 #include "winbase.h"
31 #include "objbase.h"
32 #include "winternl.h"
34 #include "wincodecs_private.h"
36 #include "wine/debug.h"
38 static INIT_ONCE init_once = INIT_ONCE_STATIC_INIT;
40 static const struct unix_funcs *unix_funcs;
42 static const struct win32_funcs win32_funcs = {
43 stream_read,
44 stream_seek
47 static BOOL WINAPI load_unixlib( INIT_ONCE *once, void *param, void **context )
49 __wine_init_unix_lib( windowscodecs_module, DLL_PROCESS_ATTACH, &win32_funcs, &unix_funcs );
50 return TRUE;
53 static void init_unixlib(void)
55 InitOnceExecuteOnce( &init_once, load_unixlib, NULL, NULL );
58 struct decoder_wrapper
60 struct decoder win32_decoder;
61 struct decoder *unix_decoder;
64 static inline struct decoder_wrapper *impl_from_decoder(struct decoder* iface)
66 return CONTAINING_RECORD(iface, struct decoder_wrapper, win32_decoder);
69 HRESULT CDECL decoder_wrapper_initialize(struct decoder* iface, IStream* stream, struct decoder_stat *st)
71 struct decoder_wrapper* This = impl_from_decoder(iface);
72 return unix_funcs->decoder_initialize(This->unix_decoder, stream, st);
75 HRESULT CDECL decoder_wrapper_get_frame_info(struct decoder* iface, UINT frame, struct decoder_frame *info)
77 struct decoder_wrapper* This = impl_from_decoder(iface);
78 return unix_funcs->decoder_get_frame_info(This->unix_decoder, frame, info);
81 HRESULT CDECL decoder_wrapper_copy_pixels(struct decoder* iface, UINT frame,
82 const WICRect *prc, UINT stride, UINT buffersize, BYTE *buffer)
84 struct decoder_wrapper* This = impl_from_decoder(iface);
85 return unix_funcs->decoder_copy_pixels(This->unix_decoder, frame, prc, stride, buffersize, buffer);
88 void CDECL decoder_wrapper_destroy(struct decoder* iface)
90 struct decoder_wrapper* This = impl_from_decoder(iface);
91 unix_funcs->decoder_destroy(This->unix_decoder);
92 HeapFree(GetProcessHeap(), 0, This);
95 static const struct decoder_funcs decoder_wrapper_vtable = {
96 decoder_wrapper_initialize,
97 decoder_wrapper_get_frame_info,
98 decoder_wrapper_copy_pixels,
99 decoder_wrapper_destroy
102 HRESULT get_unix_decoder(const CLSID *decoder_clsid, struct decoder_info *info, struct decoder **result)
104 HRESULT hr;
105 struct decoder_wrapper *wrapper;
106 struct decoder *unix_decoder;
108 init_unixlib();
110 hr = unix_funcs->decoder_create(decoder_clsid, info, &unix_decoder);
112 if (SUCCEEDED(hr))
114 wrapper = HeapAlloc(GetProcessHeap(), 0, sizeof(*wrapper));
116 if (!wrapper)
118 unix_funcs->decoder_destroy(unix_decoder);
119 return E_OUTOFMEMORY;
122 wrapper->win32_decoder.vtable = &decoder_wrapper_vtable;
123 wrapper->unix_decoder = unix_decoder;
124 *result = &wrapper->win32_decoder;
127 return hr;