mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
Gfx: Move WIC files to Util
This commit is contained in:
136
Common/Gfx/Util/WICBitmapDIB.cpp
Normal file
136
Common/Gfx/Util/WICBitmapDIB.cpp
Normal file
@ -0,0 +1,136 @@
|
||||
/*
|
||||
Copyright (C) 2013 Birunthan Mohanathas
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "WICBitmapDIB.h"
|
||||
#include "WICBitmapLockDIB.h"
|
||||
#include <cassert>
|
||||
|
||||
namespace Gfx {
|
||||
namespace Util {
|
||||
|
||||
WICBitmapDIB::WICBitmapDIB() :
|
||||
m_DIBSectionBuffer(),
|
||||
m_DIBSectionBufferPixels(),
|
||||
m_W(0),
|
||||
m_H(0)
|
||||
{
|
||||
}
|
||||
|
||||
WICBitmapDIB::~WICBitmapDIB()
|
||||
{
|
||||
if (m_DIBSectionBuffer)
|
||||
{
|
||||
DeleteObject(m_DIBSectionBuffer);
|
||||
m_DIBSectionBufferPixels = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void WICBitmapDIB::Resize(UINT w, UINT h)
|
||||
{
|
||||
if (m_DIBSectionBuffer)
|
||||
{
|
||||
DeleteObject(m_DIBSectionBuffer);
|
||||
m_DIBSectionBufferPixels = nullptr;
|
||||
}
|
||||
|
||||
m_W = w;
|
||||
m_H = h;
|
||||
|
||||
BITMAPV4HEADER bh = {sizeof(BITMAPV4HEADER)};
|
||||
bh.bV4Width = (LONG)m_W;
|
||||
bh.bV4Height = -(LONG)m_H; // Top-down DIB
|
||||
bh.bV4Planes = 1;
|
||||
bh.bV4BitCount = 32;
|
||||
bh.bV4V4Compression = BI_BITFIELDS;
|
||||
bh.bV4RedMask = 0x00FF0000;
|
||||
bh.bV4GreenMask = 0x0000FF00;
|
||||
bh.bV4BlueMask = 0x000000FF;
|
||||
bh.bV4AlphaMask = 0xFF000000;
|
||||
|
||||
m_DIBSectionBuffer = CreateDIBSection(
|
||||
nullptr,
|
||||
(BITMAPINFO*)&bh,
|
||||
DIB_RGB_COLORS,
|
||||
(void**)&m_DIBSectionBufferPixels,
|
||||
nullptr,
|
||||
0);
|
||||
|
||||
assert(m_DIBSectionBufferPixels);
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapDIB::QueryInterface(REFIID riid, void** ppvObject)
|
||||
{
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP_(ULONG) WICBitmapDIB::AddRef()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP_(ULONG) WICBitmapDIB::Release()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapDIB::GetSize(UINT* puiWidth, UINT* puiHeight)
|
||||
{
|
||||
if (puiWidth) *puiWidth = m_W;
|
||||
if (puiHeight) *puiHeight = m_H;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapDIB::GetPixelFormat(WICPixelFormatGUID* pPixelFormat)
|
||||
{
|
||||
*pPixelFormat = GUID_WICPixelFormat32bppPBGRA;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapDIB::GetResolution(double* pDpiX, double* pDpiY)
|
||||
{
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapDIB::CopyPalette(IWICPalette* pIPalette)
|
||||
{
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapDIB::CopyPixels(const WICRect* prc, UINT cbStride, UINT cbBufferSize, BYTE* pbBuffer)
|
||||
{
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapDIB::Lock(const WICRect* prcLock, DWORD flags, IWICBitmapLock** ppILock)
|
||||
{
|
||||
if (ppILock) *ppILock = (IWICBitmapLock*)new WICBitmapLockDIB(this, prcLock);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapDIB::SetPalette(IWICPalette* pIPalette)
|
||||
{
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapDIB::SetResolution(double dpiX, double dpiY)
|
||||
{
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
} // namespace Util
|
||||
} // namespace Gfx
|
74
Common/Gfx/Util/WICBitmapDIB.h
Normal file
74
Common/Gfx/Util/WICBitmapDIB.h
Normal file
@ -0,0 +1,74 @@
|
||||
/*
|
||||
Copyright (C) 2013 Birunthan Mohanathas
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef RM_GFX_WICBITMAPDIB_H_
|
||||
#define RM_GFX_WICBITMAPDIB_H_
|
||||
|
||||
#include <Windows.h>
|
||||
#include <GdiPlus.h>
|
||||
#include <wincodec.h>
|
||||
|
||||
namespace Gfx {
|
||||
namespace Util {
|
||||
|
||||
// Allows the use of a DIB section (HBITMAP) in Direct2D as a WIC bitmap. It is assumed that this
|
||||
// class is used only with 32bpp PARGB bitmaps and using a sigle thread.
|
||||
//
|
||||
// This class does not follow the COM reference count model. RTTI is used instead. This class
|
||||
// implements only the bare essentials in order to use a DIB section as a Direct2D render target.
|
||||
class WICBitmapDIB : public IWICBitmap
|
||||
{
|
||||
public:
|
||||
WICBitmapDIB();
|
||||
~WICBitmapDIB();
|
||||
|
||||
void Resize(UINT w, UINT h);
|
||||
|
||||
HBITMAP GetHandle() const { return m_DIBSectionBuffer; }
|
||||
BYTE* GetData() const { return (BYTE*)m_DIBSectionBufferPixels; }
|
||||
|
||||
// IUnknown
|
||||
IFACEMETHOD(QueryInterface)(REFIID riid, void** ppvObject);
|
||||
IFACEMETHOD_(ULONG, AddRef)();
|
||||
IFACEMETHOD_(ULONG, Release)();
|
||||
|
||||
// IWICBitmapSource
|
||||
IFACEMETHOD(GetSize)(UINT* puiWidth, UINT* puiHeight);
|
||||
IFACEMETHOD(GetPixelFormat)(WICPixelFormatGUID* pPixelFormat);
|
||||
IFACEMETHOD(GetResolution)(double* pDpiX, double* pDpiY);
|
||||
IFACEMETHOD(CopyPalette)(IWICPalette* pIPalette);
|
||||
IFACEMETHOD(CopyPixels)(const WICRect* prc, UINT cbStride, UINT cbBufferSize, BYTE* pbBuffer);
|
||||
|
||||
// IWICBitmap
|
||||
IFACEMETHOD(Lock)(const WICRect* prcLock, DWORD flags, IWICBitmapLock** ppILock);
|
||||
IFACEMETHOD(SetPalette)(IWICPalette* pIPalette);
|
||||
IFACEMETHOD(SetResolution)(double dpiX, double dpiY);
|
||||
|
||||
private:
|
||||
friend class WICBitmapLockDIB;
|
||||
|
||||
HBITMAP m_DIBSectionBuffer;
|
||||
LPDWORD m_DIBSectionBufferPixels;
|
||||
UINT m_W;
|
||||
UINT m_H;
|
||||
};
|
||||
|
||||
} // namespace Util
|
||||
} // namespace Gfx
|
||||
|
||||
#endif
|
91
Common/Gfx/Util/WICBitmapLockDIB.cpp
Normal file
91
Common/Gfx/Util/WICBitmapLockDIB.cpp
Normal file
@ -0,0 +1,91 @@
|
||||
/*
|
||||
Copyright (C) 2013 Birunthan Mohanathas
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "WICBitmapLockDIB.h"
|
||||
#include <cassert>
|
||||
|
||||
namespace Gfx {
|
||||
namespace Util {
|
||||
|
||||
WICBitmapLockDIB::WICBitmapLockDIB(WICBitmapDIB* bitmap, const WICRect* lockRect) :
|
||||
m_Bitmap(bitmap),
|
||||
m_Rect(lockRect),
|
||||
m_RefCount(1)
|
||||
{
|
||||
}
|
||||
|
||||
WICBitmapLockDIB::~WICBitmapLockDIB()
|
||||
{
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapLockDIB::QueryInterface(REFIID riid, void** ppvObject)
|
||||
{
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP_(ULONG) WICBitmapLockDIB::AddRef()
|
||||
{
|
||||
++m_RefCount;
|
||||
return m_RefCount;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP_(ULONG) WICBitmapLockDIB::Release()
|
||||
{
|
||||
--m_RefCount;
|
||||
if (m_RefCount == 0)
|
||||
{
|
||||
delete this;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return m_RefCount;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapLockDIB::GetSize(UINT* puiWidth, UINT* puiHeight)
|
||||
{
|
||||
return m_Bitmap->GetSize(puiWidth, puiHeight);
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapLockDIB::GetStride(UINT* pcbStride)
|
||||
{
|
||||
UINT width = 0;
|
||||
m_Bitmap->GetSize(&width, nullptr);
|
||||
|
||||
if (pcbStride) *pcbStride = (width * 32 + 31) / 32 * 4;
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapLockDIB::GetDataPointer(UINT* pcbBufferSize, BYTE** ppbData)
|
||||
{
|
||||
UINT stride = 0;
|
||||
GetStride(&stride);
|
||||
|
||||
if (pcbBufferSize) *pcbBufferSize = stride * m_Rect->Height;
|
||||
if (ppbData) *ppbData = (BYTE*)&m_Bitmap->m_DIBSectionBufferPixels[m_Rect->Y * m_Rect->Width + m_Rect->X];
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapLockDIB::GetPixelFormat(WICPixelFormatGUID* pPixelFormat)
|
||||
{
|
||||
return m_Bitmap->GetPixelFormat(pPixelFormat);
|
||||
}
|
||||
|
||||
} // namespace Util
|
||||
} // namespace Gfx
|
60
Common/Gfx/Util/WICBitmapLockDIB.h
Normal file
60
Common/Gfx/Util/WICBitmapLockDIB.h
Normal file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
Copyright (C) 2013 Birunthan Mohanathas
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef RM_GFX_WICBITMAPLOCKDIB_H_
|
||||
#define RM_GFX_WICBITMAPLOCKDIB_H_
|
||||
|
||||
#include <Windows.h>
|
||||
#include <GdiPlus.h>
|
||||
#include <wincodec.h>
|
||||
#include "WICBitmapDIB.h"
|
||||
|
||||
namespace Gfx {
|
||||
namespace Util {
|
||||
|
||||
// Implements the IWICBitmapLock interface for use with WICBitmapDIB. It is assumed that this
|
||||
// class is used only with 32bpp PARGB bitmaps and using a sigle thread.
|
||||
class WICBitmapLockDIB : public IWICBitmapLock
|
||||
{
|
||||
public:
|
||||
WICBitmapLockDIB(WICBitmapDIB* bitmap, const WICRect* lockRect);
|
||||
virtual ~WICBitmapLockDIB();
|
||||
|
||||
void Resize(UINT w, UINT h);
|
||||
|
||||
// IUnknown
|
||||
IFACEMETHOD(QueryInterface)(REFIID riid, void** ppvObject);
|
||||
IFACEMETHOD_(ULONG, AddRef)();
|
||||
IFACEMETHOD_(ULONG, Release)();
|
||||
|
||||
// IWICBitmapLock
|
||||
IFACEMETHOD(GetSize)(UINT* puiWidth, UINT* puiHeight);
|
||||
IFACEMETHOD(GetStride)(UINT* pcbStride);
|
||||
IFACEMETHOD(GetDataPointer)(UINT* pcbBufferSize, BYTE** ppbData);
|
||||
IFACEMETHOD(GetPixelFormat)(WICPixelFormatGUID* pPixelFormat);
|
||||
|
||||
private:
|
||||
WICBitmapDIB* m_Bitmap;
|
||||
const WICRect* m_Rect;
|
||||
UINT m_RefCount;
|
||||
};
|
||||
|
||||
} // namespace Util
|
||||
} // namespace Gfx
|
||||
|
||||
#endif
|
82
Common/Gfx/Util/WICBitmapLockGDIP.cpp
Normal file
82
Common/Gfx/Util/WICBitmapLockGDIP.cpp
Normal file
@ -0,0 +1,82 @@
|
||||
/*
|
||||
Copyright (C) 2013 Birunthan Mohanathas
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "WICBitmapLockGDIP.h"
|
||||
#include <cassert>
|
||||
|
||||
namespace Gfx {
|
||||
namespace Util {
|
||||
|
||||
WICBitmapLockGDIP::WICBitmapLockGDIP() :
|
||||
m_RefCount(1)
|
||||
{
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapLockGDIP::QueryInterface(REFIID riid, void** ppvObject)
|
||||
{
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP_(ULONG) WICBitmapLockGDIP::AddRef()
|
||||
{
|
||||
++m_RefCount;
|
||||
return m_RefCount;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP_(ULONG) WICBitmapLockGDIP::Release()
|
||||
{
|
||||
--m_RefCount;
|
||||
if (m_RefCount == 0)
|
||||
{
|
||||
delete this;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return m_RefCount;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapLockGDIP::GetSize(UINT* puiWidth, UINT* puiHeight)
|
||||
{
|
||||
*puiWidth = m_BitmapData.Width;
|
||||
*puiHeight = m_BitmapData.Height;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapLockGDIP::GetStride(UINT* pcbStride)
|
||||
{
|
||||
*pcbStride = m_BitmapData.Stride;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapLockGDIP::GetDataPointer(UINT* pcbBufferSize, BYTE** ppbData)
|
||||
{
|
||||
assert(m_BitmapData.PixelFormat == PixelFormat32bppPARGB);
|
||||
*pcbBufferSize = m_BitmapData.Stride * m_BitmapData.Height;
|
||||
*ppbData = (BYTE*)m_BitmapData.Scan0;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapLockGDIP::GetPixelFormat(WICPixelFormatGUID* pPixelFormat)
|
||||
{
|
||||
assert(m_BitmapData.PixelFormat == PixelFormat32bppPARGB);
|
||||
*pPixelFormat = GUID_WICPixelFormat32bppPBGRA;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
} // namespace Util
|
||||
} // namespace Gfx
|
57
Common/Gfx/Util/WICBitmapLockGDIP.h
Normal file
57
Common/Gfx/Util/WICBitmapLockGDIP.h
Normal file
@ -0,0 +1,57 @@
|
||||
/*
|
||||
Copyright (C) 2013 Birunthan Mohanathas
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef RM_GFX_WICBITMAPLOCKGDIP_H_
|
||||
#define RM_GFX_WICBITMAPLOCKGDIP_H_
|
||||
|
||||
#include <Windows.h>
|
||||
#include <GdiPlus.h>
|
||||
#include <wincodec.h>
|
||||
|
||||
namespace Gfx {
|
||||
namespace Util {
|
||||
|
||||
// Allows the creation of a shared ID2D1Bitmap using pixel data in a Gdiplus::Bitmap. It is
|
||||
// assumed that this class is used only with 32bpp PARGB bitmaps and using a sigle thread.
|
||||
class WICBitmapLockGDIP : public IWICBitmapLock
|
||||
{
|
||||
public:
|
||||
WICBitmapLockGDIP();
|
||||
|
||||
Gdiplus::BitmapData* GetBitmapData() { return &m_BitmapData; }
|
||||
|
||||
// IUnknown
|
||||
IFACEMETHOD(QueryInterface)(REFIID riid, void** ppvObject);
|
||||
IFACEMETHOD_(ULONG, AddRef)();
|
||||
IFACEMETHOD_(ULONG, Release)();
|
||||
|
||||
// IWICBitmapLock
|
||||
IFACEMETHOD(GetSize)(UINT* puiWidth, UINT* puiHeight);
|
||||
IFACEMETHOD(GetStride)(UINT* pcbStride);
|
||||
IFACEMETHOD(GetDataPointer)(UINT* pcbBufferSize, BYTE** ppbData);
|
||||
IFACEMETHOD(GetPixelFormat)(WICPixelFormatGUID* pPixelFormat);
|
||||
|
||||
private:
|
||||
Gdiplus::BitmapData m_BitmapData;
|
||||
UINT m_RefCount;
|
||||
};
|
||||
|
||||
} // namespace Util
|
||||
} // namespace Gfx
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user