2017-06-21 19:37:31 -07:00
|
|
|
From dcebc7fcedaffca0940a4324b1525ea9485a4674 Mon Sep 17 00:00:00 2001
|
2016-03-10 19:25:51 -08:00
|
|
|
From: Dmitry Timoshkov <dmitry@baikal.ru>
|
|
|
|
Date: Fri, 11 Mar 2016 03:48:46 +0100
|
2016-03-13 09:06:48 -07:00
|
|
|
Subject: windowscodecs: Implement WICCreateBitmapFromSection(Ex). (v2)
|
2016-03-10 19:25:51 -08:00
|
|
|
|
|
|
|
---
|
2016-03-13 09:06:48 -07:00
|
|
|
dlls/windowscodecs/bitmap.c | 27 ++++++++-----
|
|
|
|
dlls/windowscodecs/imgfactory.c | 73 ++++++++++++++++++++++++++++++++++-
|
|
|
|
dlls/windowscodecs/windowscodecs.spec | 3 +-
|
|
|
|
include/wincodec.idl | 8 ++++
|
|
|
|
4 files changed, 100 insertions(+), 11 deletions(-)
|
2016-03-10 19:25:51 -08:00
|
|
|
|
2016-03-13 09:06:48 -07:00
|
|
|
diff --git a/dlls/windowscodecs/bitmap.c b/dlls/windowscodecs/bitmap.c
|
2017-06-21 19:37:31 -07:00
|
|
|
index 6adaab0aea1..76298b22ca2 100644
|
2016-03-13 09:06:48 -07:00
|
|
|
--- a/dlls/windowscodecs/bitmap.c
|
|
|
|
+++ b/dlls/windowscodecs/bitmap.c
|
2016-12-11 19:28:52 -08:00
|
|
|
@@ -45,6 +45,7 @@ typedef struct BitmapImpl {
|
2016-03-13 09:06:48 -07:00
|
|
|
int palette_set;
|
|
|
|
LONG lock; /* 0 if not locked, -1 if locked for writing, count if locked for reading */
|
|
|
|
BYTE *data;
|
|
|
|
+ BOOL is_section; /* TRUE if data is a section created by an application */
|
|
|
|
UINT width, height;
|
|
|
|
UINT stride;
|
|
|
|
UINT bpp;
|
2016-12-11 19:28:52 -08:00
|
|
|
@@ -284,7 +285,10 @@ static ULONG WINAPI BitmapImpl_Release(IWICBitmap *iface)
|
2016-03-13 09:06:48 -07:00
|
|
|
if (This->palette) IWICPalette_Release(This->palette);
|
|
|
|
This->cs.DebugInfo->Spare[0] = 0;
|
|
|
|
DeleteCriticalSection(&This->cs);
|
|
|
|
- HeapFree(GetProcessHeap(), 0, This->data);
|
|
|
|
+ if (This->is_section)
|
|
|
|
+ UnmapViewOfFile(This->data);
|
|
|
|
+ else
|
|
|
|
+ HeapFree(GetProcessHeap(), 0, This->data);
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
}
|
|
|
|
|
2016-12-11 19:28:52 -08:00
|
|
|
@@ -694,13 +698,12 @@ static const IMILUnknown2Vtbl IMILUnknown2Impl_Vtbl =
|
2016-03-13 09:06:48 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
HRESULT BitmapImpl_Create(UINT uiWidth, UINT uiHeight,
|
|
|
|
- UINT stride, UINT datasize, BYTE *bits,
|
|
|
|
+ UINT stride, UINT datasize, BYTE *data,
|
|
|
|
REFWICPixelFormatGUID pixelFormat, WICBitmapCreateCacheOption option,
|
|
|
|
IWICBitmap **ppIBitmap)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
BitmapImpl *This;
|
|
|
|
- BYTE *data;
|
|
|
|
UINT bpp;
|
|
|
|
|
|
|
|
hr = get_pixelformat_bpp(pixelFormat, &bpp);
|
2016-12-11 19:28:52 -08:00
|
|
|
@@ -713,14 +716,20 @@ HRESULT BitmapImpl_Create(UINT uiWidth, UINT uiHeight,
|
2016-03-13 09:06:48 -07:00
|
|
|
if (stride < ((bpp*uiWidth)+7)/8) return E_INVALIDARG;
|
|
|
|
|
|
|
|
This = HeapAlloc(GetProcessHeap(), 0, sizeof(BitmapImpl));
|
|
|
|
- data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, datasize);
|
|
|
|
- if (!This || !data)
|
|
|
|
+ if (!This) return E_OUTOFMEMORY;
|
|
|
|
+
|
|
|
|
+ if (!data)
|
|
|
|
{
|
|
|
|
- HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
- HeapFree(GetProcessHeap(), 0, data);
|
|
|
|
- return E_OUTOFMEMORY;
|
|
|
|
+ data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, datasize);
|
|
|
|
+ if (!data)
|
|
|
|
+ {
|
|
|
|
+ HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
+ return E_OUTOFMEMORY;
|
|
|
|
+ }
|
|
|
|
+ This->is_section = FALSE;
|
|
|
|
}
|
|
|
|
- if (bits) memcpy(data, bits, datasize);
|
|
|
|
+ else
|
|
|
|
+ This->is_section = TRUE;
|
|
|
|
|
|
|
|
This->IWICBitmap_iface.lpVtbl = &BitmapImpl_Vtbl;
|
|
|
|
This->IMILBitmapSource_iface.lpVtbl = &IMILBitmapImpl_Vtbl;
|
2016-03-10 19:25:51 -08:00
|
|
|
diff --git a/dlls/windowscodecs/imgfactory.c b/dlls/windowscodecs/imgfactory.c
|
2017-06-21 19:37:31 -07:00
|
|
|
index bf634949b44..50e6725a5c7 100644
|
2016-03-10 19:25:51 -08:00
|
|
|
--- a/dlls/windowscodecs/imgfactory.c
|
|
|
|
+++ b/dlls/windowscodecs/imgfactory.c
|
2016-12-11 19:28:52 -08:00
|
|
|
@@ -595,12 +595,36 @@ static HRESULT WINAPI ComponentFactory_CreateBitmapFromMemory(IWICComponentFacto
|
2016-03-13 09:06:48 -07:00
|
|
|
UINT width, UINT height, REFWICPixelFormatGUID format, UINT stride,
|
|
|
|
UINT size, BYTE *buffer, IWICBitmap **bitmap)
|
|
|
|
{
|
|
|
|
+ HRESULT hr;
|
|
|
|
+
|
|
|
|
TRACE("(%p,%u,%u,%s,%u,%u,%p,%p\n", iface, width, height,
|
|
|
|
debugstr_guid(format), stride, size, buffer, bitmap);
|
|
|
|
|
|
|
|
if (!stride || !size || !buffer || !bitmap) return E_INVALIDARG;
|
|
|
|
|
|
|
|
- return BitmapImpl_Create(width, height, stride, size, buffer, format, WICBitmapCacheOnLoad, bitmap);
|
|
|
|
+ hr = BitmapImpl_Create(width, height, stride, size, NULL, format, WICBitmapCacheOnLoad, bitmap);
|
|
|
|
+ if (SUCCEEDED(hr))
|
|
|
|
+ {
|
|
|
|
+ IWICBitmapLock *lock;
|
|
|
|
+
|
|
|
|
+ hr = IWICBitmap_Lock(*bitmap, NULL, WICBitmapLockWrite, &lock);
|
|
|
|
+ if (SUCCEEDED(hr))
|
|
|
|
+ {
|
|
|
|
+ UINT buffersize;
|
|
|
|
+ BYTE *data;
|
|
|
|
+
|
|
|
|
+ IWICBitmapLock_GetDataPointer(lock, &buffersize, &data);
|
|
|
|
+ memcpy(data, buffer, buffersize);
|
|
|
|
+
|
|
|
|
+ IWICBitmapLock_Release(lock);
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ IWICBitmap_Release(*bitmap);
|
|
|
|
+ *bitmap = NULL;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL get_16bpp_format(HBITMAP hbm, WICPixelFormatGUID *format)
|
2016-12-11 19:28:52 -08:00
|
|
|
@@ -1176,3 +1200,50 @@ HRESULT ComponentFactory_CreateInstance(REFIID iid, void** ppv)
|
2016-03-10 19:25:51 -08:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
+
|
|
|
|
+HRESULT WINAPI WICCreateBitmapFromSectionEx(UINT width, UINT height,
|
|
|
|
+ REFWICPixelFormatGUID format, HANDLE section, UINT stride,
|
|
|
|
+ UINT offset, WICSectionAccessLevel wicaccess, IWICBitmap **bitmap)
|
|
|
|
+{
|
|
|
|
+ DWORD access;
|
2016-03-13 09:06:48 -07:00
|
|
|
+ void *buffer;
|
2016-03-10 19:25:51 -08:00
|
|
|
+ HRESULT hr;
|
|
|
|
+
|
|
|
|
+ TRACE("%u,%u,%s,%p,%u,%#x,%#x,%p\n", width, height, debugstr_guid(format),
|
|
|
|
+ section, stride, offset, wicaccess, bitmap);
|
|
|
|
+
|
|
|
|
+ if (!width || !height || !section || !bitmap) return E_INVALIDARG;
|
|
|
|
+
|
|
|
|
+ switch (wicaccess)
|
|
|
|
+ {
|
|
|
|
+ case WICSectionAccessLevelReadWrite:
|
|
|
|
+ access = FILE_MAP_READ | FILE_MAP_WRITE;
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ case WICSectionAccessLevelRead:
|
|
|
|
+ access = FILE_MAP_READ;
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ default:
|
|
|
|
+ FIXME("unsupported access %#x\n", wicaccess);
|
|
|
|
+ return E_INVALIDARG;
|
|
|
|
+ }
|
|
|
|
+
|
2016-03-13 09:06:48 -07:00
|
|
|
+ buffer = MapViewOfFile(section, access, 0, offset, 0);
|
|
|
|
+ if (!buffer) return HRESULT_FROM_WIN32(GetLastError());
|
2016-03-10 19:25:51 -08:00
|
|
|
+
|
2016-03-13 09:06:48 -07:00
|
|
|
+ hr = BitmapImpl_Create(width, height, stride, 0, buffer, format, WICBitmapCacheOnLoad, bitmap);
|
|
|
|
+ if (FAILED(hr)) UnmapViewOfFile(buffer);
|
2016-03-10 19:25:51 -08:00
|
|
|
+ return hr;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+HRESULT WINAPI WICCreateBitmapFromSection(UINT width, UINT height,
|
|
|
|
+ REFWICPixelFormatGUID format, HANDLE section,
|
|
|
|
+ UINT stride, UINT offset, IWICBitmap **bitmap)
|
|
|
|
+{
|
|
|
|
+ TRACE("%u,%u,%s,%p,%u,%u,%p\n", width, height, debugstr_guid(format),
|
|
|
|
+ section, stride, offset, bitmap);
|
|
|
|
+
|
|
|
|
+ return WICCreateBitmapFromSectionEx(width, height, format, section,
|
|
|
|
+ stride, offset, WICSectionAccessLevelRead, bitmap);
|
|
|
|
+}
|
|
|
|
diff --git a/dlls/windowscodecs/windowscodecs.spec b/dlls/windowscodecs/windowscodecs.spec
|
2017-06-21 19:37:31 -07:00
|
|
|
index 49346fc86b7..905ef835afc 100644
|
2016-03-10 19:25:51 -08:00
|
|
|
--- a/dlls/windowscodecs/windowscodecs.spec
|
|
|
|
+++ b/dlls/windowscodecs/windowscodecs.spec
|
|
|
|
@@ -105,7 +105,8 @@
|
|
|
|
@ stdcall IWICStream_InitializeFromIStream_Proxy(ptr ptr) IWICStream_InitializeFromIStream_Proxy_W
|
|
|
|
@ stdcall IWICStream_InitializeFromMemory_Proxy(ptr ptr long) IWICStream_InitializeFromMemory_Proxy_W
|
|
|
|
@ stdcall WICConvertBitmapSource(ptr ptr ptr)
|
|
|
|
-@ stub WICCreateBitmapFromSection
|
|
|
|
+@ stdcall WICCreateBitmapFromSection(long long ptr long long long ptr)
|
|
|
|
+@ stdcall WICCreateBitmapFromSectionEx(long long ptr long long long long ptr)
|
|
|
|
@ stdcall WICCreateColorContext_Proxy(ptr ptr)
|
|
|
|
@ stdcall WICCreateImagingFactory_Proxy(long ptr)
|
|
|
|
@ stub WICGetMetadataContentSize
|
|
|
|
diff --git a/include/wincodec.idl b/include/wincodec.idl
|
2017-06-21 19:37:31 -07:00
|
|
|
index 1bbdab90c4a..43ed1c4a08b 100644
|
2016-03-10 19:25:51 -08:00
|
|
|
--- a/include/wincodec.idl
|
|
|
|
+++ b/include/wincodec.idl
|
2017-06-21 19:37:31 -07:00
|
|
|
@@ -181,6 +181,12 @@ typedef enum WICPngFilterOption {
|
2016-12-11 19:28:52 -08:00
|
|
|
WICPNFFILTEROPTION_FORCE_DWORD = CODEC_FORCE_DWORD
|
|
|
|
} WICPngFilterOption;
|
2016-03-10 19:25:51 -08:00
|
|
|
|
|
|
|
+typedef enum WICSectionAccessLevel {
|
|
|
|
+ WICSectionAccessLevelRead = 0x00000001,
|
|
|
|
+ WICSectionAccessLevelReadWrite = 0x00000003,
|
|
|
|
+ WICSectionAccessLevel_FORCE_DWORD = CODEC_FORCE_DWORD
|
|
|
|
+} WICSectionAccessLevel;
|
|
|
|
+
|
|
|
|
typedef GUID WICPixelFormatGUID;
|
|
|
|
typedef REFGUID REFWICPixelFormatGUID;
|
|
|
|
|
2017-06-21 19:37:31 -07:00
|
|
|
@@ -1050,6 +1056,8 @@ interface IWICEnumMetadataItem : IUnknown
|
2016-03-10 19:25:51 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
cpp_quote("HRESULT WINAPI WICConvertBitmapSource(REFWICPixelFormatGUID dstFormat, IWICBitmapSource *pISrc, IWICBitmapSource **ppIDst);")
|
|
|
|
+cpp_quote("HRESULT WINAPI WICCreateBitmapFromSection(UINT width, UINT height, REFWICPixelFormatGUID format, HANDLE section, UINT stride, UINT offset, IWICBitmap **bitmap);")
|
|
|
|
+cpp_quote("HRESULT WINAPI WICCreateBitmapFromSectionEx(UINT width, UINT height, REFWICPixelFormatGUID format, HANDLE section, UINT stride, UINT offset, WICSectionAccessLevel access, IWICBitmap **bitmap);")
|
|
|
|
|
2017-06-21 19:37:31 -07:00
|
|
|
cpp_quote("HRESULT WINAPI WICMapGuidToShortName(REFGUID,UINT,WCHAR *,UINT *);")
|
|
|
|
cpp_quote("HRESULT WINAPI WICMapShortNameToGuid(PCWSTR,GUID *);")
|
2016-03-10 19:25:51 -08:00
|
|
|
--
|
2017-06-21 19:37:31 -07:00
|
|
|
2.13.1
|
2016-03-10 19:25:51 -08:00
|
|
|
|