ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

fliprotate.c
Go to the documentation of this file.
00001 /*
00002  * Copyright 2010 Vincent Povirk for CodeWeavers
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with this library; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00017  */
00018 
00019 #include "config.h"
00020 
00021 #include <stdarg.h>
00022 
00023 #define COBJMACROS
00024 
00025 #include "windef.h"
00026 #include "winbase.h"
00027 #include "objbase.h"
00028 #include "wincodec.h"
00029 
00030 #include "wincodecs_private.h"
00031 
00032 #include "wine/debug.h"
00033 
00034 WINE_DEFAULT_DEBUG_CHANNEL(wincodecs);
00035 
00036 typedef struct FlipRotator {
00037     const IWICBitmapFlipRotatorVtbl *lpVtbl;
00038     LONG ref;
00039     IWICBitmapSource *source;
00040     int flip_x;
00041     int flip_y;
00042     int swap_xy;
00043     CRITICAL_SECTION lock; /* must be held when initialized */
00044 } FlipRotator;
00045 
00046 static HRESULT WINAPI FlipRotator_QueryInterface(IWICBitmapFlipRotator *iface, REFIID iid,
00047     void **ppv)
00048 {
00049     FlipRotator *This = (FlipRotator*)iface;
00050     TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
00051 
00052     if (!ppv) return E_INVALIDARG;
00053 
00054     if (IsEqualIID(&IID_IUnknown, iid) ||
00055         IsEqualIID(&IID_IWICBitmapSource, iid) ||
00056         IsEqualIID(&IID_IWICBitmapFlipRotator, iid))
00057     {
00058         *ppv = This;
00059     }
00060     else
00061     {
00062         *ppv = NULL;
00063         return E_NOINTERFACE;
00064     }
00065 
00066     IUnknown_AddRef((IUnknown*)*ppv);
00067     return S_OK;
00068 }
00069 
00070 static ULONG WINAPI FlipRotator_AddRef(IWICBitmapFlipRotator *iface)
00071 {
00072     FlipRotator *This = (FlipRotator*)iface;
00073     ULONG ref = InterlockedIncrement(&This->ref);
00074 
00075     TRACE("(%p) refcount=%u\n", iface, ref);
00076 
00077     return ref;
00078 }
00079 
00080 static ULONG WINAPI FlipRotator_Release(IWICBitmapFlipRotator *iface)
00081 {
00082     FlipRotator *This = (FlipRotator*)iface;
00083     ULONG ref = InterlockedDecrement(&This->ref);
00084 
00085     TRACE("(%p) refcount=%u\n", iface, ref);
00086 
00087     if (ref == 0)
00088     {
00089         This->lock.DebugInfo->Spare[0] = 0;
00090         DeleteCriticalSection(&This->lock);
00091         if (This->source) IWICBitmapSource_Release(This->source);
00092         HeapFree(GetProcessHeap(), 0, This);
00093     }
00094 
00095     return ref;
00096 }
00097 
00098 static HRESULT WINAPI FlipRotator_GetSize(IWICBitmapFlipRotator *iface,
00099     UINT *puiWidth, UINT *puiHeight)
00100 {
00101     FlipRotator *This = (FlipRotator*)iface;
00102     TRACE("(%p,%p,%p)\n", iface, puiWidth, puiHeight);
00103 
00104     if (!This->source)
00105         return WINCODEC_ERR_WRONGSTATE;
00106     else if (This->swap_xy)
00107         return IWICBitmapSource_GetSize(This->source, puiHeight, puiWidth);
00108     else
00109         return IWICBitmapSource_GetSize(This->source, puiWidth, puiHeight);
00110 }
00111 
00112 static HRESULT WINAPI FlipRotator_GetPixelFormat(IWICBitmapFlipRotator *iface,
00113     WICPixelFormatGUID *pPixelFormat)
00114 {
00115     FIXME("(%p,%p): stub\n", iface, pPixelFormat);
00116 
00117     return E_NOTIMPL;
00118 }
00119 
00120 static HRESULT WINAPI FlipRotator_GetResolution(IWICBitmapFlipRotator *iface,
00121     double *pDpiX, double *pDpiY)
00122 {
00123     FIXME("(%p,%p,%p): stub\n", iface, pDpiX, pDpiY);
00124 
00125     return E_NOTIMPL;
00126 }
00127 
00128 static HRESULT WINAPI FlipRotator_CopyPalette(IWICBitmapFlipRotator *iface,
00129     IWICPalette *pIPalette)
00130 {
00131     FIXME("(%p,%p): stub\n", iface, pIPalette);
00132     return E_NOTIMPL;
00133 }
00134 
00135 static HRESULT WINAPI FlipRotator_CopyPixels(IWICBitmapFlipRotator *iface,
00136     const WICRect *prc, UINT cbStride, UINT cbBufferSize, BYTE *pbBuffer)
00137 {
00138     FlipRotator *This = (FlipRotator*)iface;
00139     HRESULT hr;
00140     UINT y;
00141     UINT srcy, srcwidth, srcheight;
00142     WICRect rc;
00143 
00144     TRACE("(%p,%p,%u,%u,%p)\n", iface, prc, cbStride, cbBufferSize, pbBuffer);
00145 
00146     if (!This->source) return WINCODEC_ERR_WRONGSTATE;
00147 
00148     if (This->swap_xy || This->flip_x)
00149     {
00150         /* This requires knowledge of the pixel format. */
00151         FIXME("flipping x and rotating are not implemented\n");
00152         return E_NOTIMPL;
00153     }
00154 
00155     hr = IWICBitmapSource_GetSize(This->source, &srcwidth, &srcheight);
00156     if (FAILED(hr)) return hr;
00157 
00158     for (y=prc->Y; y - prc->Y < prc->Height; y++)
00159     {
00160         if (This->flip_y)
00161             srcy = srcheight - 1 - y;
00162         else
00163             srcy = y;
00164 
00165         rc.X = prc->X;
00166         rc.Y = srcy;
00167         rc.Width = prc->Width;
00168         rc.Height = 1;
00169 
00170         hr = IWICBitmapSource_CopyPixels(This->source, &rc, cbStride, cbStride,
00171             pbBuffer);
00172 
00173         if (FAILED(hr)) break;
00174 
00175         pbBuffer += cbStride;
00176     }
00177 
00178     return hr;
00179 }
00180 
00181 static HRESULT WINAPI FlipRotator_Initialize(IWICBitmapFlipRotator *iface,
00182     IWICBitmapSource *pISource, WICBitmapTransformOptions options)
00183 {
00184     FlipRotator *This = (FlipRotator*)iface;
00185     HRESULT hr=S_OK;
00186 
00187     TRACE("(%p,%p,%u)\n", iface, pISource, options);
00188 
00189     EnterCriticalSection(&This->lock);
00190 
00191     if (This->source)
00192     {
00193         hr = WINCODEC_ERR_WRONGSTATE;
00194         goto end;
00195     }
00196 
00197     if (options&WICBitmapTransformRotate90)
00198     {
00199         This->swap_xy = 1;
00200         This->flip_x = !This->flip_x;
00201     }
00202 
00203     if (options&WICBitmapTransformRotate180)
00204     {
00205         This->flip_x = !This->flip_x;
00206         This->flip_y = !This->flip_y;
00207     }
00208 
00209     if (options&WICBitmapTransformFlipHorizontal)
00210         This->flip_x = !This->flip_x;
00211 
00212     if (options&WICBitmapTransformFlipVertical)
00213         This->flip_y = !This->flip_y;
00214 
00215     IWICBitmapSource_AddRef(pISource);
00216     This->source = pISource;
00217 
00218 end:
00219     LeaveCriticalSection(&This->lock);
00220 
00221     return hr;
00222 }
00223 
00224 static const IWICBitmapFlipRotatorVtbl FlipRotator_Vtbl = {
00225     FlipRotator_QueryInterface,
00226     FlipRotator_AddRef,
00227     FlipRotator_Release,
00228     FlipRotator_GetSize,
00229     FlipRotator_GetPixelFormat,
00230     FlipRotator_GetResolution,
00231     FlipRotator_CopyPalette,
00232     FlipRotator_CopyPixels,
00233     FlipRotator_Initialize
00234 };
00235 
00236 HRESULT FlipRotator_Create(IWICBitmapFlipRotator **fliprotator)
00237 {
00238     FlipRotator *This;
00239 
00240     This = HeapAlloc(GetProcessHeap(), 0, sizeof(FlipRotator));
00241     if (!This) return E_OUTOFMEMORY;
00242 
00243     This->lpVtbl = &FlipRotator_Vtbl;
00244     This->ref = 1;
00245     This->source = NULL;
00246     This->flip_x = 0;
00247     This->flip_y = 0;
00248     This->swap_xy = 0;
00249     InitializeCriticalSection(&This->lock);
00250     This->lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": FlipRotator.lock");
00251 
00252     *fliprotator = (IWICBitmapFlipRotator*)This;
00253 
00254     return S_OK;
00255 }

Generated on Fri May 25 2012 04:24:55 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.