strmbase: Implement BaseControlWindow.
[wine/multimedia.git] / dlls / windowscodecs / main.c
blob8dd847e93d799a4785bb58af1f790b68770e8589
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 #include "config.h"
22 #include <stdarg.h>
24 #include "windef.h"
25 #include "winbase.h"
26 #include "objbase.h"
27 #include "wincodec.h"
29 #include "wincodecs_private.h"
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(wincodecs);
35 extern BOOL WINAPI WIC_DllMain(HINSTANCE, DWORD, LPVOID) DECLSPEC_HIDDEN;
37 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
40 switch (fdwReason)
42 case DLL_PROCESS_ATTACH:
43 DisableThreadLibraryCalls(hinstDLL);
44 break;
45 case DLL_PROCESS_DETACH:
46 break;
49 return WIC_DllMain(hinstDLL, fdwReason, lpvReserved);
52 HRESULT WINAPI DllCanUnloadNow(void)
54 return S_FALSE;
57 HRESULT copy_pixels(UINT bpp, const BYTE *srcbuffer,
58 UINT srcwidth, UINT srcheight, INT srcstride,
59 const WICRect *rc, UINT dststride, UINT dstbuffersize, BYTE *dstbuffer)
61 UINT bytesperrow;
62 UINT row_offset; /* number of bits into the source rows where the data starts */
63 WICRect rect;
65 if (!rc)
67 rect.X = 0;
68 rect.Y = 0;
69 rect.Width = srcwidth;
70 rect.Height = srcheight;
71 rc = &rect;
73 else
75 if (rc->X < 0 || rc->Y < 0 || rc->X+rc->Width > srcwidth || rc->Y+rc->Height > srcheight)
76 return E_INVALIDARG;
79 bytesperrow = ((bpp * rc->Width)+7)/8;
81 if (dststride < bytesperrow)
82 return E_INVALIDARG;
84 if ((dststride * rc->Height) > dstbuffersize)
85 return E_INVALIDARG;
87 /* if the whole bitmap is copied and the buffer format matches then it's a matter of a single memcpy */
88 if (rc->X == 0 && rc->Y == 0 && rc->Width == srcwidth && rc->Height == srcheight && srcstride == dststride)
90 memcpy(dstbuffer, srcbuffer, srcstride * srcheight);
91 return S_OK;
94 row_offset = rc->X * bpp;
96 if (row_offset % 8 == 0)
98 /* everything lines up on a byte boundary */
99 UINT row;
100 const BYTE *src;
101 BYTE *dst;
103 src = srcbuffer + (row_offset / 8) + srcstride * rc->Y;
104 dst = dstbuffer;
105 for (row=0; row < rc->Height; row++)
107 memcpy(dst, src, bytesperrow);
108 src += srcstride;
109 dst += dststride;
111 return S_OK;
113 else
115 /* we have to do a weird bitwise copy. eww. */
116 FIXME("cannot reliably copy bitmap data if bpp < 8\n");
117 return E_FAIL;
121 void reverse_bgr8(UINT bytesperpixel, LPBYTE bits, UINT width, UINT height, INT stride)
123 UINT x, y;
124 BYTE *pixel, temp;
126 for (y=0; y<height; y++)
128 pixel = bits + stride * y;
130 for (x=0; x<width; x++)
132 temp = pixel[2];
133 pixel[2] = pixel[0];
134 pixel[0] = temp;
135 pixel += bytesperpixel;