2 * Copyright 2009 Vincent Povirk for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #define WIN32_NO_STATUS
21 #define COM_NO_WINDOWS_H
33 #include "wincodecs_private.h"
35 #include <wine/debug.h>
37 WINE_DEFAULT_DEBUG_CHANNEL(wincodecs
);
39 extern BOOL WINAPI
WIC_DllMain(HINSTANCE
, DWORD
, LPVOID
) DECLSPEC_HIDDEN
;
41 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
46 case DLL_PROCESS_ATTACH
:
47 DisableThreadLibraryCalls(hinstDLL
);
49 case DLL_PROCESS_DETACH
:
53 return WIC_DllMain(hinstDLL
, fdwReason
, lpvReserved
);
56 HRESULT WINAPI
DllCanUnloadNow(void)
61 HRESULT
copy_pixels(UINT bpp
, const BYTE
*srcbuffer
,
62 UINT srcwidth
, UINT srcheight
, INT srcstride
,
63 const WICRect
*rc
, UINT dststride
, UINT dstbuffersize
, BYTE
*dstbuffer
)
66 UINT row_offset
; /* number of bits into the source rows where the data starts */
73 rect
.Width
= srcwidth
;
74 rect
.Height
= srcheight
;
79 if (rc
->X
< 0 || rc
->Y
< 0 || rc
->X
+rc
->Width
> srcwidth
|| rc
->Y
+rc
->Height
> srcheight
)
83 bytesperrow
= ((bpp
* rc
->Width
)+7)/8;
85 if (dststride
< bytesperrow
)
88 if ((dststride
* (rc
->Height
-1)) + ((rc
->Width
* bpp
) + 7)/8 > dstbuffersize
)
91 /* if the whole bitmap is copied and the buffer format matches then it's a matter of a single memcpy */
92 if (rc
->X
== 0 && rc
->Y
== 0 && rc
->Width
== srcwidth
&& rc
->Height
== srcheight
&& srcstride
== dststride
)
94 memcpy(dstbuffer
, srcbuffer
, srcstride
* srcheight
);
98 row_offset
= rc
->X
* bpp
;
100 if (row_offset
% 8 == 0)
102 /* everything lines up on a byte boundary */
107 src
= srcbuffer
+ (row_offset
/ 8) + srcstride
* rc
->Y
;
109 for (row
=0; row
< rc
->Height
; row
++)
111 memcpy(dst
, src
, bytesperrow
);
119 /* we have to do a weird bitwise copy. eww. */
120 FIXME("cannot reliably copy bitmap data if bpp < 8\n");
125 void reverse_bgr8(UINT bytesperpixel
, LPBYTE bits
, UINT width
, UINT height
, INT stride
)
130 for (y
=0; y
<height
; y
++)
132 pixel
= bits
+ stride
* y
;
134 for (x
=0; x
<width
; x
++)
139 pixel
+= bytesperpixel
;
144 HRESULT
get_pixelformat_bpp(const GUID
*pixelformat
, UINT
*bpp
)
147 IWICComponentInfo
*info
;
148 IWICPixelFormatInfo
*formatinfo
;
150 hr
= CreateComponentInfo(pixelformat
, &info
);
153 hr
= IWICComponentInfo_QueryInterface(info
, &IID_IWICPixelFormatInfo
, (void**)&formatinfo
);
157 hr
= IWICPixelFormatInfo_GetBitsPerPixel(formatinfo
, bpp
);
159 IWICPixelFormatInfo_Release(formatinfo
);
162 IWICComponentInfo_Release(info
);