d3dcompiler: Don't allow semantics on void functions.
[wine/multimedia.git] / dlls / windowscodecs / main.c
blob091b9fb04871a28fa0c0d820d201b2e9c19c93f9
1 /*
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
20 #define COBJMACROS
21 #include "config.h"
23 #include <stdarg.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "objbase.h"
28 #include "wincodec.h"
30 #include "wincodecs_private.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(wincodecs);
36 extern BOOL WINAPI WIC_DllMain(HINSTANCE, DWORD, LPVOID) DECLSPEC_HIDDEN;
38 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
41 switch (fdwReason)
43 case DLL_PROCESS_ATTACH:
44 DisableThreadLibraryCalls(hinstDLL);
45 break;
46 case DLL_PROCESS_DETACH:
47 break;
50 return WIC_DllMain(hinstDLL, fdwReason, lpvReserved);
53 HRESULT WINAPI DllCanUnloadNow(void)
55 return S_FALSE;
58 HRESULT copy_pixels(UINT bpp, const BYTE *srcbuffer,
59 UINT srcwidth, UINT srcheight, INT srcstride,
60 const WICRect *rc, UINT dststride, UINT dstbuffersize, BYTE *dstbuffer)
62 UINT bytesperrow;
63 UINT row_offset; /* number of bits into the source rows where the data starts */
64 WICRect rect;
66 if (!rc)
68 rect.X = 0;
69 rect.Y = 0;
70 rect.Width = srcwidth;
71 rect.Height = srcheight;
72 rc = &rect;
74 else
76 if (rc->X < 0 || rc->Y < 0 || rc->X+rc->Width > srcwidth || rc->Y+rc->Height > srcheight)
77 return E_INVALIDARG;
80 bytesperrow = ((bpp * rc->Width)+7)/8;
82 if (dststride < bytesperrow)
83 return E_INVALIDARG;
85 if ((dststride * rc->Height) > dstbuffersize)
86 return E_INVALIDARG;
88 /* if the whole bitmap is copied and the buffer format matches then it's a matter of a single memcpy */
89 if (rc->X == 0 && rc->Y == 0 && rc->Width == srcwidth && rc->Height == srcheight && srcstride == dststride)
91 memcpy(dstbuffer, srcbuffer, srcstride * srcheight);
92 return S_OK;
95 row_offset = rc->X * bpp;
97 if (row_offset % 8 == 0)
99 /* everything lines up on a byte boundary */
100 UINT row;
101 const BYTE *src;
102 BYTE *dst;
104 src = srcbuffer + (row_offset / 8) + srcstride * rc->Y;
105 dst = dstbuffer;
106 for (row=0; row < rc->Height; row++)
108 memcpy(dst, src, bytesperrow);
109 src += srcstride;
110 dst += dststride;
112 return S_OK;
114 else
116 /* we have to do a weird bitwise copy. eww. */
117 FIXME("cannot reliably copy bitmap data if bpp < 8\n");
118 return E_FAIL;
122 void reverse_bgr8(UINT bytesperpixel, LPBYTE bits, UINT width, UINT height, INT stride)
124 UINT x, y;
125 BYTE *pixel, temp;
127 for (y=0; y<height; y++)
129 pixel = bits + stride * y;
131 for (x=0; x<width; x++)
133 temp = pixel[2];
134 pixel[2] = pixel[0];
135 pixel[0] = temp;
136 pixel += bytesperpixel;
141 HRESULT get_pixelformat_bpp(const GUID *pixelformat, UINT *bpp)
143 HRESULT hr;
144 IWICComponentInfo *info;
145 IWICPixelFormatInfo *formatinfo;
147 hr = CreateComponentInfo(pixelformat, &info);
148 if (SUCCEEDED(hr))
150 hr = IWICComponentInfo_QueryInterface(info, &IID_IWICPixelFormatInfo, (void**)&formatinfo);
152 if (SUCCEEDED(hr))
154 hr = IWICPixelFormatInfo_GetBitsPerPixel(formatinfo, bpp);
156 IWICPixelFormatInfo_Release(formatinfo);
159 IWICComponentInfo_Release(info);
162 return hr;