ReactOS 0.4.16-dev-981-g80eb313
bmpdecode.c File Reference
#include <assert.h>
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "winreg.h"
#include "wingdi.h"
#include "objbase.h"
#include "wincodecs_private.h"
#include "wine/debug.h"
Include dependency graph for bmpdecode.c:

Go to the source code of this file.

Classes

struct  BITMAPCOREHEADER2
 
struct  BmpDecoder
 
struct  bitfields_format
 

Macros

#define COBJMACROS
 

Typedefs

typedef HRESULT(* ReadDataFunc) (BmpDecoder *This)
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (wincodecs)
 
static BmpDecoderimpl_from_IWICBitmapDecoder (IWICBitmapDecoder *iface)
 
static BmpDecoderimpl_from_IWICBitmapFrameDecode (IWICBitmapFrameDecode *iface)
 
static HRESULT WINAPI BmpFrameDecode_QueryInterface (IWICBitmapFrameDecode *iface, REFIID iid, void **ppv)
 
static ULONG WINAPI BmpFrameDecode_AddRef (IWICBitmapFrameDecode *iface)
 
static ULONG WINAPI BmpFrameDecode_Release (IWICBitmapFrameDecode *iface)
 
static HRESULT WINAPI BmpFrameDecode_GetSize (IWICBitmapFrameDecode *iface, UINT *puiWidth, UINT *puiHeight)
 
static HRESULT WINAPI BmpFrameDecode_GetPixelFormat (IWICBitmapFrameDecode *iface, WICPixelFormatGUID *pPixelFormat)
 
static HRESULT BmpHeader_GetResolution (BITMAPV5HEADER *bih, double *pDpiX, double *pDpiY)
 
static HRESULT WINAPI BmpFrameDecode_GetResolution (IWICBitmapFrameDecode *iface, double *pDpiX, double *pDpiY)
 
static HRESULT WINAPI BmpFrameDecode_CopyPalette (IWICBitmapFrameDecode *iface, IWICPalette *pIPalette)
 
static HRESULT WINAPI BmpFrameDecode_CopyPixels (IWICBitmapFrameDecode *iface, const WICRect *prc, UINT cbStride, UINT cbBufferSize, BYTE *pbBuffer)
 
static HRESULT WINAPI BmpFrameDecode_GetMetadataQueryReader (IWICBitmapFrameDecode *iface, IWICMetadataQueryReader **ppIMetadataQueryReader)
 
static HRESULT WINAPI BmpFrameDecode_GetColorContexts (IWICBitmapFrameDecode *iface, UINT cCount, IWICColorContext **ppIColorContexts, UINT *pcActualCount)
 
static HRESULT WINAPI BmpFrameDecode_GetThumbnail (IWICBitmapFrameDecode *iface, IWICBitmapSource **ppIThumbnail)
 
static HRESULT BmpFrameDecode_ReadUncompressed (BmpDecoder *This)
 
static HRESULT BmpFrameDecode_ReadABGRasBGR (BmpDecoder *This)
 
static HRESULT BmpFrameDecode_ReadRGB8 (BmpDecoder *This)
 
static HRESULT ReadByte (IStream *stream, BYTE *buffer, ULONG buffer_size, ULONG *cursor, ULONG *bytesread, BYTE *result)
 
static HRESULT BmpFrameDecode_ReadRLE8 (BmpDecoder *This)
 
static HRESULT BmpFrameDecode_ReadRLE4 (BmpDecoder *This)
 
static HRESULT BmpFrameDecode_ReadUnsupported (BmpDecoder *This)
 
static HRESULT BmpDecoder_ReadHeaders (BmpDecoder *This, IStream *stream)
 
static HRESULT WINAPI BmpDecoder_QueryInterface (IWICBitmapDecoder *iface, REFIID iid, void **ppv)
 
static ULONG WINAPI BmpDecoder_AddRef (IWICBitmapDecoder *iface)
 
static ULONG WINAPI BmpDecoder_Release (IWICBitmapDecoder *iface)
 
static HRESULT WINAPI BmpDecoder_QueryCapability (IWICBitmapDecoder *iface, IStream *stream, DWORD *capability)
 
static HRESULT WINAPI BmpDecoder_Initialize (IWICBitmapDecoder *iface, IStream *pIStream, WICDecodeOptions cacheOptions)
 
static HRESULT WINAPI BmpDecoder_GetContainerFormat (IWICBitmapDecoder *iface, GUID *pguidContainerFormat)
 
static HRESULT WINAPI BmpDecoder_GetDecoderInfo (IWICBitmapDecoder *iface, IWICBitmapDecoderInfo **ppIDecoderInfo)
 
static HRESULT WINAPI BmpDecoder_CopyPalette (IWICBitmapDecoder *iface, IWICPalette *pIPalette)
 
static HRESULT WINAPI BmpDecoder_GetMetadataQueryReader (IWICBitmapDecoder *iface, IWICMetadataQueryReader **ppIMetadataQueryReader)
 
static HRESULT WINAPI BmpDecoder_GetPreview (IWICBitmapDecoder *iface, IWICBitmapSource **ppIBitmapSource)
 
static HRESULT WINAPI BmpDecoder_GetColorContexts (IWICBitmapDecoder *iface, UINT cCount, IWICColorContext **ppIColorContexts, UINT *pcActualCount)
 
static HRESULT WINAPI BmpDecoder_GetThumbnail (IWICBitmapDecoder *iface, IWICBitmapSource **ppIThumbnail)
 
static HRESULT WINAPI BmpDecoder_GetFrameCount (IWICBitmapDecoder *iface, UINT *pCount)
 
static HRESULT WINAPI BmpDecoder_GetFrame (IWICBitmapDecoder *iface, UINT index, IWICBitmapFrameDecode **ppIBitmapFrame)
 
static HRESULT BmpDecoder_Create (int packed, int icoframe, BmpDecoder **ppDecoder)
 
static HRESULT BmpDecoder_Construct (int packed, int icoframe, REFIID iid, void **ppv)
 
HRESULT BmpDecoder_CreateInstance (REFIID iid, void **ppv)
 
HRESULT DibDecoder_CreateInstance (REFIID iid, void **ppv)
 
HRESULT IcoDibDecoder_CreateInstance (BmpDecoder **ppDecoder)
 
void BmpDecoder_GetWICDecoder (BmpDecoder *This, IWICBitmapDecoder **ppDecoder)
 
void BmpDecoder_FindIconMask (BmpDecoder *This, ULONG *mask_offset, int *topdown)
 

Variables

static const struct bitfields_format bitfields_formats []
 
static const IWICBitmapFrameDecodeVtbl BmpDecoder_FrameVtbl
 
static const IWICBitmapDecoderVtbl BmpDecoder_Vtbl
 

Macro Definition Documentation

◆ COBJMACROS

#define COBJMACROS

Definition at line 22 of file bmpdecode.c.

Typedef Documentation

◆ ReadDataFunc

typedef HRESULT(* ReadDataFunc) (BmpDecoder *This)

Definition at line 59 of file bmpdecode.c.

Function Documentation

◆ BmpDecoder_AddRef()

static ULONG WINAPI BmpDecoder_AddRef ( IWICBitmapDecoder iface)
static

Definition at line 1028 of file bmpdecode.c.

1029{
1032
1033 TRACE("(%p) refcount=%lu\n", iface, ref);
1034
1035 return ref;
1036}
#define InterlockedIncrement
Definition: armddk.h:53
static BmpDecoder * impl_from_IWICBitmapDecoder(IWICBitmapDecoder *iface)
Definition: bmpdecode.c:81
#define TRACE(s)
Definition: solgame.cpp:4
Definition: send.c:48
uint32_t ULONG
Definition: typedefs.h:59

◆ BmpDecoder_Construct()

static HRESULT BmpDecoder_Construct ( int  packed,
int  icoframe,
REFIID  iid,
void **  ppv 
)
static

Definition at line 1212 of file bmpdecode.c.

1213{
1215 HRESULT ret;
1216
1217 TRACE("(%s,%p)\n", debugstr_guid(iid), ppv);
1218
1219 *ppv = NULL;
1220
1221 ret = BmpDecoder_Create(packed, icoframe, &This);
1222 if (FAILED(ret)) return ret;
1223
1224 ret = IWICBitmapDecoder_QueryInterface(&This->IWICBitmapDecoder_iface, iid, ppv);
1225 IWICBitmapDecoder_Release(&This->IWICBitmapDecoder_iface);
1226
1227 return ret;
1228}
static HRESULT BmpDecoder_Create(int packed, int icoframe, BmpDecoder **ppDecoder)
Definition: bmpdecode.c:1185
#define NULL
Definition: types.h:112
GLuint GLenum GLsizei GLsizei GLint GLint GLboolean packed
Definition: glext.h:9271
REFIID LPVOID * ppv
Definition: atlbase.h:39
#define FAILED(hr)
Definition: intsafe.h:51
#define debugstr_guid
Definition: kernel32.h:35
int ret

Referenced by BmpDecoder_CreateInstance(), and DibDecoder_CreateInstance().

◆ BmpDecoder_CopyPalette()

static HRESULT WINAPI BmpDecoder_CopyPalette ( IWICBitmapDecoder iface,
IWICPalette pIPalette 
)
static

Definition at line 1108 of file bmpdecode.c.

1110{
1111 TRACE("(%p,%p)\n", iface, pIPalette);
1112
1114}
#define WINCODEC_ERR_PALETTEUNAVAILABLE
Definition: winerror.h:3292

◆ BmpDecoder_Create()

static HRESULT BmpDecoder_Create ( int  packed,
int  icoframe,
BmpDecoder **  ppDecoder 
)
static

Definition at line 1185 of file bmpdecode.c.

1186{
1188
1189 This = malloc(sizeof(BmpDecoder));
1190 if (!This) return E_OUTOFMEMORY;
1191
1192 This->IWICBitmapDecoder_iface.lpVtbl = &BmpDecoder_Vtbl;
1193 This->IWICBitmapFrameDecode_iface.lpVtbl = &BmpDecoder_FrameVtbl;
1194 This->ref = 1;
1195 This->initialized = FALSE;
1196 This->stream = NULL;
1197 This->imagedata = NULL;
1198#ifdef __REACTOS__
1200#else
1202#endif
1203 This->lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": BmpDecoder.lock");
1204 This->packed = packed;
1205 This->icoframe = icoframe;
1206
1207 *ppDecoder = This;
1208
1209 return S_OK;
1210}
static const IWICBitmapFrameDecodeVtbl BmpDecoder_FrameVtbl
Definition: bmpdecode.c:783
static const IWICBitmapDecoderVtbl BmpDecoder_Vtbl
Definition: bmpdecode.c:1168
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define malloc
Definition: debug_ros.c:4
#define FALSE
Definition: types.h:117
BOOL WINAPI InitializeCriticalSectionEx(OUT LPCRITICAL_SECTION lpCriticalSection, IN DWORD dwSpinCount, IN DWORD flags)
Definition: sync.c:107
#define S_OK
Definition: intsafe.h:52
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:751
#define DWORD_PTR
Definition: treelist.c:76
#define RTL_CRITICAL_SECTION_FLAG_FORCE_DEBUG_INFO
Definition: winnt_old.h:1116

Referenced by BmpDecoder_Construct(), and IcoDibDecoder_CreateInstance().

◆ BmpDecoder_CreateInstance()

HRESULT BmpDecoder_CreateInstance ( REFIID  iid,
void **  ppv 
)

Definition at line 1230 of file bmpdecode.c.

1231{
1232 return BmpDecoder_Construct(FALSE, FALSE, iid, ppv);
1233}
static HRESULT BmpDecoder_Construct(int packed, int icoframe, REFIID iid, void **ppv)
Definition: bmpdecode.c:1212

◆ BmpDecoder_FindIconMask()

void BmpDecoder_FindIconMask ( BmpDecoder This,
ULONG mask_offset,
int topdown 
)

Definition at line 1251 of file bmpdecode.c.

1252{
1253 assert(This->stream != NULL);
1254
1255 if (This->read_data_func == BmpFrameDecode_ReadUncompressed)
1256 {
1257 /* RGB or BITFIELDS data */
1258 UINT width, height;
1259 ULONG bytesperrow, datasize;
1260 IWICBitmapFrameDecode_GetSize(&This->IWICBitmapFrameDecode_iface, &width, &height);
1261 bytesperrow = (((width * This->bitsperpixel)+31)/32)*4;
1262 datasize = bytesperrow * height;
1263 *mask_offset = This->image_offset + datasize;
1264 }
1265 else
1266 *mask_offset = 0;
1267
1268 *topdown = This->stride > 0;
1269}
static HRESULT BmpFrameDecode_ReadUncompressed(BmpDecoder *This)
Definition: bmpdecode.c:361
static SIZE_T datasize
Definition: asm.c:30
#define assert(x)
Definition: debug.h:53
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
GLint GLint GLsizei width
Definition: gl.h:1546
unsigned int UINT
Definition: ndis.h:50

Referenced by ReadIcoDib().

◆ BmpDecoder_GetColorContexts()

static HRESULT WINAPI BmpDecoder_GetColorContexts ( IWICBitmapDecoder iface,
UINT  cCount,
IWICColorContext **  ppIColorContexts,
UINT pcActualCount 
)
static

Definition at line 1130 of file bmpdecode.c.

1132{
1133 TRACE("(%p,%u,%p,%p)\n", iface, cCount, ppIColorContexts, pcActualCount);
1135}
#define WINCODEC_ERR_UNSUPPORTEDOPERATION
Definition: winerror.h:3308

◆ BmpDecoder_GetContainerFormat()

static HRESULT WINAPI BmpDecoder_GetContainerFormat ( IWICBitmapDecoder iface,
GUID pguidContainerFormat 
)
static

Definition at line 1093 of file bmpdecode.c.

1095{
1096 memcpy(pguidContainerFormat, &GUID_ContainerFormatBmp, sizeof(GUID));
1097 return S_OK;
1098}
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878

◆ BmpDecoder_GetDecoderInfo()

static HRESULT WINAPI BmpDecoder_GetDecoderInfo ( IWICBitmapDecoder iface,
IWICBitmapDecoderInfo **  ppIDecoderInfo 
)
static

Definition at line 1100 of file bmpdecode.c.

1102{
1103 TRACE("(%p,%p)\n", iface, ppIDecoderInfo);
1104
1105 return get_decoder_info(&CLSID_WICBmpDecoder, ppIDecoderInfo);
1106}
static GpStatus get_decoder_info(IStream *stream, const struct image_codec **result)
Definition: image.c:4285

◆ BmpDecoder_GetFrame()

static HRESULT WINAPI BmpDecoder_GetFrame ( IWICBitmapDecoder iface,
UINT  index,
IWICBitmapFrameDecode **  ppIBitmapFrame 
)
static

Definition at line 1153 of file bmpdecode.c.

1155{
1157
1158 if (index != 0) return E_INVALIDARG;
1159
1160 if (!This->stream) return WINCODEC_ERR_FRAMEMISSING;
1161
1162 *ppIBitmapFrame = &This->IWICBitmapFrameDecode_iface;
1163 IWICBitmapDecoder_AddRef(iface);
1164
1165 return S_OK;
1166}
#define E_INVALIDARG
Definition: ddrawi.h:101
GLuint index
Definition: glext.h:6031
#define WINCODEC_ERR_FRAMEMISSING
Definition: winerror.h:3301

◆ BmpDecoder_GetFrameCount()

static HRESULT WINAPI BmpDecoder_GetFrameCount ( IWICBitmapDecoder iface,
UINT pCount 
)
static

Definition at line 1144 of file bmpdecode.c.

1146{
1147 if (!pCount) return E_INVALIDARG;
1148
1149 *pCount = 1;
1150 return S_OK;
1151}

◆ BmpDecoder_GetMetadataQueryReader()

static HRESULT WINAPI BmpDecoder_GetMetadataQueryReader ( IWICBitmapDecoder iface,
IWICMetadataQueryReader **  ppIMetadataQueryReader 
)
static

Definition at line 1116 of file bmpdecode.c.

1118{
1119 TRACE("(%p,%p)\n", iface, ppIMetadataQueryReader);
1121}

◆ BmpDecoder_GetPreview()

static HRESULT WINAPI BmpDecoder_GetPreview ( IWICBitmapDecoder iface,
IWICBitmapSource **  ppIBitmapSource 
)
static

Definition at line 1123 of file bmpdecode.c.

1125{
1126 TRACE("(%p,%p)\n", iface, ppIBitmapSource);
1128}

◆ BmpDecoder_GetThumbnail()

static HRESULT WINAPI BmpDecoder_GetThumbnail ( IWICBitmapDecoder iface,
IWICBitmapSource **  ppIThumbnail 
)
static

Definition at line 1137 of file bmpdecode.c.

1139{
1140 TRACE("(%p,%p)\n", iface, ppIThumbnail);
1142}
#define WINCODEC_ERR_CODECNOTHUMBNAIL
Definition: winerror.h:3291

◆ BmpDecoder_GetWICDecoder()

void BmpDecoder_GetWICDecoder ( BmpDecoder This,
IWICBitmapDecoder **  ppDecoder 
)

Definition at line 1245 of file bmpdecode.c.

1246{
1247 *ppDecoder = &This->IWICBitmapDecoder_iface;
1248}

Referenced by ReadIcoDib().

◆ BmpDecoder_Initialize()

static HRESULT WINAPI BmpDecoder_Initialize ( IWICBitmapDecoder iface,
IStream pIStream,
WICDecodeOptions  cacheOptions 
)
static

Definition at line 1074 of file bmpdecode.c.

1076{
1077 HRESULT hr;
1079
1080 EnterCriticalSection(&This->lock);
1081 hr = BmpDecoder_ReadHeaders(This, pIStream);
1082
1083 if (SUCCEEDED(hr))
1084 {
1085 This->stream = pIStream;
1086 IStream_AddRef(pIStream);
1087 }
1088 LeaveCriticalSection(&This->lock);
1089
1090 return hr;
1091}
static HRESULT BmpDecoder_ReadHeaders(BmpDecoder *This, IStream *stream)
Definition: bmpdecode.c:797
#define SUCCEEDED(hr)
Definition: intsafe.h:50
HRESULT hr
Definition: shlfolder.c:183
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)

◆ BmpDecoder_QueryCapability()

static HRESULT WINAPI BmpDecoder_QueryCapability ( IWICBitmapDecoder iface,
IStream stream,
DWORD capability 
)
static

Definition at line 1057 of file bmpdecode.c.

1059{
1060 HRESULT hr;
1062
1063 TRACE("(%p,%p,%p)\n", iface, stream, capability);
1064
1065 if (!stream || !capability) return E_INVALIDARG;
1066
1067 hr = IWICBitmapDecoder_Initialize(iface, stream, WICDecodeMetadataCacheOnDemand);
1068 if (hr != S_OK) return hr;
1069
1071 return S_OK;
1072}
static HRESULT BmpFrameDecode_ReadUnsupported(BmpDecoder *This)
Definition: bmpdecode.c:758
Definition: parse.h:23
@ WICDecodeMetadataCacheOnDemand
Definition: wincodec.idl:29
@ WICBitmapDecoderCapabilityCanDecodeAllImages
Definition: wincodec.idl:50

◆ BmpDecoder_QueryInterface()

static HRESULT WINAPI BmpDecoder_QueryInterface ( IWICBitmapDecoder iface,
REFIID  iid,
void **  ppv 
)
static

Definition at line 1005 of file bmpdecode.c.

1007{
1009 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
1010
1011 if (!ppv) return E_INVALIDARG;
1012
1013 if (IsEqualIID(&IID_IUnknown, iid) ||
1014 IsEqualIID(&IID_IWICBitmapDecoder, iid))
1015 {
1016 *ppv = &This->IWICBitmapDecoder_iface;
1017 }
1018 else
1019 {
1020 *ppv = NULL;
1021 return E_NOINTERFACE;
1022 }
1023
1024 IUnknown_AddRef((IUnknown*)*ppv);
1025 return S_OK;
1026}
const GUID IID_IUnknown
#define IsEqualIID(riid1, riid2)
Definition: guiddef.h:95
#define E_NOINTERFACE
Definition: winerror.h:2364

◆ BmpDecoder_ReadHeaders()

static HRESULT BmpDecoder_ReadHeaders ( BmpDecoder This,
IStream stream 
)
static

Definition at line 797 of file bmpdecode.c.

798{
799 HRESULT hr;
800 ULONG bytestoread, bytesread;
802
803 if (This->initialized) return WINCODEC_ERR_WRONGSTATE;
804
805 seek.QuadPart = 0;
806 hr = IStream_Seek(stream, seek, STREAM_SEEK_SET, NULL);
807 if (FAILED(hr)) return hr;
808
809 if (!This->packed)
810 {
812 hr = IStream_Read(stream, &bfh, sizeof(BITMAPFILEHEADER), &bytesread);
813 if (FAILED(hr)) return hr;
814 if (bytesread != sizeof(BITMAPFILEHEADER) ||
815 bfh.bfType != 0x4d42 /* "BM" */) return E_FAIL;
816 This->image_offset = bfh.bfOffBits;
817 }
818
819 hr = IStream_Read(stream, &This->bih.bV5Size, sizeof(DWORD), &bytesread);
820 if (FAILED(hr)) return hr;
821 if (bytesread != sizeof(DWORD) ||
822 (This->bih.bV5Size != sizeof(BITMAPCOREHEADER) &&
823 This->bih.bV5Size != sizeof(BITMAPCOREHEADER2) &&
824 This->bih.bV5Size != sizeof(BITMAPINFOHEADER) &&
825 This->bih.bV5Size != sizeof(BITMAPV4HEADER) &&
826 This->bih.bV5Size != sizeof(BITMAPV5HEADER))) return E_FAIL;
827
828 bytestoread = This->bih.bV5Size-sizeof(DWORD);
829 hr = IStream_Read(stream, &This->bih.bV5Width, bytestoread, &bytesread);
830 if (FAILED(hr)) return hr;
831 if (bytestoread != bytesread) return E_FAIL;
832
833 if (This->packed)
834 This->palette_offset = This->bih.bV5Size;
835 else
836 This->palette_offset = sizeof(BITMAPFILEHEADER) + This->bih.bV5Size;
837
838 if (This->icoframe)
839 {
840 if (This->bih.bV5Size == sizeof(BITMAPCOREHEADER))
841 {
843 bch->bcHeight /= 2;
844 }
845 else
846 {
847 This->bih.bV5Height /= 2;
848 }
849 }
850
851 /* if this is a BITMAPINFOHEADER with BI_BITFIELDS compression, we need to
852 read the extra fields */
853 if (This->bih.bV5Size == sizeof(BITMAPINFOHEADER) &&
854 This->bih.bV5Compression == BI_BITFIELDS)
855 {
856 hr = IStream_Read(stream, &This->bih.bV5RedMask, 12, &bytesread);
857 if (FAILED(hr)) return hr;
858 if (bytesread != 12) return E_FAIL;
859 This->bih.bV5AlphaMask = 0;
860 This->palette_offset += 12;
861 }
862
863 /* decide what kind of bitmap this is and how/if we can read it */
864 if (This->bih.bV5Size == sizeof(BITMAPCOREHEADER))
865 {
867 TRACE("BITMAPCOREHEADER with depth=%i\n", bch->bcBitCount);
868 This->bitsperpixel = bch->bcBitCount;
869 This->read_data_func = BmpFrameDecode_ReadUncompressed;
870 switch(bch->bcBitCount)
871 {
872 case 1:
873 This->pixelformat = &GUID_WICPixelFormat1bppIndexed;
874 break;
875 case 2:
876 This->pixelformat = &GUID_WICPixelFormat2bppIndexed;
877 break;
878 case 4:
879 This->pixelformat = &GUID_WICPixelFormat4bppIndexed;
880 break;
881 case 8:
882 This->pixelformat = &GUID_WICPixelFormat8bppIndexed;
883 break;
884 case 24:
885 This->pixelformat = &GUID_WICPixelFormat24bppBGR;
886 break;
887 default:
888 This->pixelformat = &GUID_WICPixelFormatUndefined;
889 WARN("unsupported bit depth %i for BITMAPCOREHEADER\n", bch->bcBitCount);
890 break;
891 }
892 }
893 else /* struct is compatible with BITMAPINFOHEADER */
894 {
895 TRACE("bitmap header=%li compression=%li depth=%i\n", This->bih.bV5Size, This->bih.bV5Compression, This->bih.bV5BitCount);
896 switch(This->bih.bV5Compression)
897 {
898 case BI_RGB:
899 This->bitsperpixel = This->bih.bV5BitCount;
900 This->read_data_func = BmpFrameDecode_ReadUncompressed;
901 switch(This->bih.bV5BitCount)
902 {
903 case 1:
904 This->pixelformat = &GUID_WICPixelFormat1bppIndexed;
905 break;
906 case 2:
907 This->pixelformat = &GUID_WICPixelFormat2bppIndexed;
908 break;
909 case 4:
910 This->pixelformat = &GUID_WICPixelFormat4bppIndexed;
911 break;
912 case 8:
913 This->pixelformat = &GUID_WICPixelFormat8bppIndexed;
914 break;
915 case 16:
916 This->pixelformat = &GUID_WICPixelFormat16bppBGR555;
917 break;
918 case 24:
919 This->pixelformat = &GUID_WICPixelFormat24bppBGR;
920 break;
921 case 32:
922 This->pixelformat = &GUID_WICPixelFormat32bppBGR;
923 break;
924 default:
925 This->pixelformat = &GUID_WICPixelFormatUndefined;
926 FIXME("unsupported bit depth %i for uncompressed RGB\n", This->bih.bV5BitCount);
927 }
928 break;
929 case BI_RLE8:
930 This->bitsperpixel = 32;
931 This->read_data_func = BmpFrameDecode_ReadRLE8;
932 This->pixelformat = &GUID_WICPixelFormat32bppBGR;
933 break;
934 case BI_RLE4:
935 This->bitsperpixel = 32;
936 This->read_data_func = BmpFrameDecode_ReadRLE4;
937 This->pixelformat = &GUID_WICPixelFormat32bppBGR;
938 break;
939 case BI_BITFIELDS:
940 {
941 const struct bitfields_format *format;
942 if (This->bih.bV5Size == sizeof(BITMAPCOREHEADER2))
943 {
944 /* BCH2 doesn't support bitfields; this is Huffman 1D compression */
945 This->bitsperpixel = 0;
946 This->read_data_func = BmpFrameDecode_ReadUnsupported;
947 This->pixelformat = &GUID_WICPixelFormatUndefined;
948 FIXME("Huffman 1D compression is unsupported\n");
949 break;
950 }
951 This->bitsperpixel = This->bih.bV5BitCount;
952 for (format = bitfields_formats; format->bitcount; format++)
953 {
954 if ((format->bitcount == This->bih.bV5BitCount) &&
955 (format->redmask == This->bih.bV5RedMask) &&
956 (format->greenmask == This->bih.bV5GreenMask) &&
957 (format->bluemask == This->bih.bV5BlueMask) &&
958 (format->alphamask == This->bih.bV5AlphaMask))
959 {
960 This->read_data_func = format->read_data_func;
961 This->pixelformat = format->pixelformat;
962 break;
963 }
964 }
965 if (!format->bitcount)
966 {
967 This->read_data_func = BmpFrameDecode_ReadUncompressed;
968 This->pixelformat = &GUID_WICPixelFormatUndefined;
969 FIXME("unsupported bitfields type depth=%i red=%lx green=%lx blue=%lx alpha=%lx\n",
970 This->bih.bV5BitCount, This->bih.bV5RedMask, This->bih.bV5GreenMask, This->bih.bV5BlueMask, This->bih.bV5AlphaMask);
971 }
972 break;
973 }
974 default:
975 This->bitsperpixel = 0;
976 This->read_data_func = BmpFrameDecode_ReadUnsupported;
977 This->pixelformat = &GUID_WICPixelFormatUndefined;
978 FIXME("unsupported bitmap type header=%li compression=%li depth=%i\n", This->bih.bV5Size, This->bih.bV5Compression, This->bih.bV5BitCount);
979 break;
980 }
981 }
982
983 if (This->packed)
984 {
985 /* In a packed DIB, the image follows the palette. */
986 ULONG palette_count, palette_size;
987 if (This->bih.bV5ClrUsed)
988 palette_count = This->bih.bV5ClrUsed;
989 else if (This->bih.bV5BitCount <= 8)
990 palette_count = 1 << This->bih.bV5BitCount;
991 else
992 palette_count = 0;
993 if (This->bih.bV5Size == sizeof(BITMAPCOREHEADER))
994 palette_size = sizeof(RGBTRIPLE) * palette_count;
995 else
996 palette_size = sizeof(RGBQUAD) * palette_count;
997 This->image_offset = This->palette_offset + palette_size;
998 }
999
1000 This->initialized = TRUE;
1001
1002 return S_OK;
1003}
#define FIXME(fmt,...)
Definition: precomp.h:53
#define WARN(fmt,...)
Definition: precomp.h:61
static HRESULT BmpFrameDecode_ReadRLE8(BmpDecoder *This)
Definition: bmpdecode.c:494
static const struct bitfields_format bitfields_formats[]
Definition: bmpdecode.c:773
static HRESULT BmpFrameDecode_ReadRLE4(BmpDecoder *This)
Definition: bmpdecode.c:618
#define E_FAIL
Definition: ddrawi.h:102
#define TRUE
Definition: types.h:120
static unsigned int palette_size(DWORD flags)
Definition: palette.c:241
#define BI_RLE4
Definition: precomp.h:57
#define BI_RGB
Definition: precomp.h:56
ULONG RGBQUAD
Definition: precomp.h:59
unsigned long DWORD
Definition: ntddk_ex.h:95
if(dx< 0)
Definition: linetemp.h:194
#define BI_BITFIELDS
Definition: mmreg.h:507
#define DWORD
Definition: nt_native.h:44
int seek(void *fd, ulong off, int mode)
Definition: pe.c:51
Definition: format.c:58
#define WINCODEC_ERR_WRONGSTATE
Definition: winerror.h:3281
struct tagBITMAPFILEHEADER BITMAPFILEHEADER
struct tagRGBTRIPLE RGBTRIPLE
#define BI_RLE8
Definition: wingdi.h:35

Referenced by BmpDecoder_Initialize().

◆ BmpDecoder_Release()

static ULONG WINAPI BmpDecoder_Release ( IWICBitmapDecoder iface)
static

Definition at line 1038 of file bmpdecode.c.

1039{
1042
1043 TRACE("(%p) refcount=%lu\n", iface, ref);
1044
1045 if (ref == 0)
1046 {
1047 if (This->stream) IStream_Release(This->stream);
1048 free(This->imagedata);
1049 This->lock.DebugInfo->Spare[0] = 0;
1051 free(This);
1052 }
1053
1054 return ref;
1055}
#define InterlockedDecrement
Definition: armddk.h:52
#define free
Definition: debug_ros.c:5
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)

◆ BmpFrameDecode_AddRef()

static ULONG WINAPI BmpFrameDecode_AddRef ( IWICBitmapFrameDecode iface)
static

Definition at line 116 of file bmpdecode.c.

117{
119
120 return IWICBitmapDecoder_AddRef(&This->IWICBitmapDecoder_iface);
121}
static BmpDecoder * impl_from_IWICBitmapFrameDecode(IWICBitmapFrameDecode *iface)
Definition: bmpdecode.c:86

◆ BmpFrameDecode_CopyPalette()

static HRESULT WINAPI BmpFrameDecode_CopyPalette ( IWICBitmapFrameDecode iface,
IWICPalette pIPalette 
)
static

Definition at line 203 of file bmpdecode.c.

205{
206 HRESULT hr;
208 int count;
209 WICColor *wiccolors=NULL;
210 RGBTRIPLE *bgrcolors=NULL;
211
212 TRACE("(%p,%p)\n", iface, pIPalette);
213
215
216 if (This->bih.bV5Size == sizeof(BITMAPCOREHEADER))
217 {
219 if (bch->bcBitCount <= 8)
220 {
221 /* 2**n colors in BGR format after the header */
222 ULONG tablesize, bytesread;
224 int i;
225
226 count = 1 << bch->bcBitCount;
227 wiccolors = malloc(sizeof(WICColor) * count);
228 tablesize = sizeof(RGBTRIPLE) * count;
229 bgrcolors = malloc(tablesize);
230 if (!wiccolors || !bgrcolors)
231 {
233 goto end;
234 }
235
236 offset.QuadPart = This->palette_offset;
237 hr = IStream_Seek(This->stream, offset, STREAM_SEEK_SET, NULL);
238 if (FAILED(hr)) goto end;
239
240 hr = IStream_Read(This->stream, bgrcolors, tablesize, &bytesread);
241 if (FAILED(hr)) goto end;
242 if (bytesread != tablesize) {
243 hr = E_FAIL;
244 goto end;
245 }
246
247 for (i=0; i<count; i++)
248 {
249 wiccolors[i] = 0xff000000|
250 (bgrcolors[i].rgbtRed<<16)|
251 (bgrcolors[i].rgbtGreen<<8)|
252 bgrcolors[i].rgbtBlue;
253 }
254 }
255 else
256 {
258 goto end;
259 }
260 }
261 else
262 {
263 if (This->bih.bV5BitCount <= 8)
264 {
265 ULONG tablesize, bytesread;
267 int i;
268
269 if (This->bih.bV5ClrUsed == 0)
270 count = 1 << This->bih.bV5BitCount;
271 else
272 count = min(This->bih.bV5ClrUsed, 1 << This->bih.bV5BitCount);
273
274 tablesize = sizeof(WICColor) * count;
275 wiccolors = malloc(tablesize);
276 if (!wiccolors)
277 {
279 goto end;
280 }
281
282 offset.QuadPart = This->palette_offset;
283 hr = IStream_Seek(This->stream, offset, STREAM_SEEK_SET, NULL);
284 if (FAILED(hr)) goto end;
285
286 hr = IStream_Read(This->stream, wiccolors, tablesize, &bytesread);
287 if (FAILED(hr)) goto end;
288 if (bytesread != tablesize) {
289 hr = E_FAIL;
290 goto end;
291 }
292
293 /* convert from BGR to BGRA by setting alpha to 100% */
294 for (i=0; i<count; i++)
295 wiccolors[i] |= 0xff000000;
296 }
297 else
298 {
300 goto end;
301 }
302 }
303
304end:
305
307
308 if (SUCCEEDED(hr))
309 hr = IWICPalette_InitializeCustom(pIPalette, wiccolors, count);
310
311 free(wiccolors);
312 free(bgrcolors);
313 return hr;
314}
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLuint GLuint end
Definition: gl.h:1545
GLintptr offset
Definition: glext.h:5920
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define min(a, b)
Definition: monoChain.cc:55
BYTE rgbtBlue
Definition: wingdi.h:1438
BYTE rgbtRed
Definition: wingdi.h:1440
UINT32 WICColor
Definition: wincodec.idl:364

◆ BmpFrameDecode_CopyPixels()

static HRESULT WINAPI BmpFrameDecode_CopyPixels ( IWICBitmapFrameDecode iface,
const WICRect prc,
UINT  cbStride,
UINT  cbBufferSize,
BYTE pbBuffer 
)
static

Definition at line 316 of file bmpdecode.c.

318{
322 TRACE("(%p,%s,%u,%u,%p)\n", iface, debug_wic_rect(prc), cbStride, cbBufferSize, pbBuffer);
323
325 if (!This->imagedata)
326 {
327 hr = This->read_data_func(This);
328 }
330 if (FAILED(hr)) return hr;
331
333 if (FAILED(hr)) return hr;
334
335 return copy_pixels(This->bitsperpixel, This->imagedatastart,
336 width, height, This->stride,
337 prc, cbStride, cbBufferSize, pbBuffer);
338}
static HRESULT WINAPI BmpFrameDecode_GetSize(IWICBitmapFrameDecode *iface, UINT *puiWidth, UINT *puiHeight)
Definition: bmpdecode.c:130
void copy_pixels(const BYTE *src, UINT src_row_pitch, UINT src_slice_pitch, BYTE *dst, UINT dst_row_pitch, UINT dst_slice_pitch, const struct volume *size, const struct pixel_format_desc *format) DECLSPEC_HIDDEN
Definition: surface.c:1700
_Out_ LPRECT prc
Definition: ntgdi.h:1658
static const char * debug_wic_rect(const WICRect *rect)

◆ BmpFrameDecode_GetColorContexts()

static HRESULT WINAPI BmpFrameDecode_GetColorContexts ( IWICBitmapFrameDecode iface,
UINT  cCount,
IWICColorContext **  ppIColorContexts,
UINT pcActualCount 
)
static

Definition at line 347 of file bmpdecode.c.

349{
350 TRACE("(%p,%u,%p,%p)\n", iface, cCount, ppIColorContexts, pcActualCount);
352}

◆ BmpFrameDecode_GetMetadataQueryReader()

static HRESULT WINAPI BmpFrameDecode_GetMetadataQueryReader ( IWICBitmapFrameDecode iface,
IWICMetadataQueryReader **  ppIMetadataQueryReader 
)
static

Definition at line 340 of file bmpdecode.c.

342{
343 TRACE("(%p,%p)\n", iface, ppIMetadataQueryReader);
345}

◆ BmpFrameDecode_GetPixelFormat()

static HRESULT WINAPI BmpFrameDecode_GetPixelFormat ( IWICBitmapFrameDecode iface,
WICPixelFormatGUID pPixelFormat 
)
static

Definition at line 150 of file bmpdecode.c.

152{
154 TRACE("(%p,%p)\n", iface, pPixelFormat);
155
156 memcpy(pPixelFormat, This->pixelformat, sizeof(GUID));
157
158 return S_OK;
159}

◆ BmpFrameDecode_GetResolution()

static HRESULT WINAPI BmpFrameDecode_GetResolution ( IWICBitmapFrameDecode iface,
double pDpiX,
double pDpiY 
)
static

Definition at line 194 of file bmpdecode.c.

196{
198 TRACE("(%p,%p,%p)\n", iface, pDpiX, pDpiY);
199
200 return BmpHeader_GetResolution(&This->bih, pDpiX, pDpiY);
201}
static HRESULT BmpHeader_GetResolution(BITMAPV5HEADER *bih, double *pDpiX, double *pDpiY)
Definition: bmpdecode.c:161

◆ BmpFrameDecode_GetSize()

static HRESULT WINAPI BmpFrameDecode_GetSize ( IWICBitmapFrameDecode iface,
UINT puiWidth,
UINT puiHeight 
)
static

Definition at line 130 of file bmpdecode.c.

132{
134 TRACE("(%p,%p,%p)\n", iface, puiWidth, puiHeight);
135
136 if (This->bih.bV5Size == sizeof(BITMAPCOREHEADER))
137 {
139 *puiWidth = bch->bcWidth;
140 *puiHeight = bch->bcHeight;
141 }
142 else
143 {
144 *puiWidth = This->bih.bV5Width;
145 *puiHeight = abs(This->bih.bV5Height);
146 }
147 return S_OK;
148}
#define abs(i)
Definition: fconv.c:206

Referenced by BmpFrameDecode_CopyPixels().

◆ BmpFrameDecode_GetThumbnail()

static HRESULT WINAPI BmpFrameDecode_GetThumbnail ( IWICBitmapFrameDecode iface,
IWICBitmapSource **  ppIThumbnail 
)
static

Definition at line 354 of file bmpdecode.c.

356{
357 TRACE("(%p,%p)\n", iface, ppIThumbnail);
359}

◆ BmpFrameDecode_QueryInterface()

static HRESULT WINAPI BmpFrameDecode_QueryInterface ( IWICBitmapFrameDecode iface,
REFIID  iid,
void **  ppv 
)
static

Definition at line 91 of file bmpdecode.c.

93{
95
96 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
97
98 if (!ppv) return E_INVALIDARG;
99
100 if (IsEqualIID(&IID_IUnknown, iid) ||
101 IsEqualIID(&IID_IWICBitmapSource, iid) ||
102 IsEqualIID(&IID_IWICBitmapFrameDecode, iid))
103 {
104 *ppv = &This->IWICBitmapFrameDecode_iface;
105 }
106 else
107 {
108 *ppv = NULL;
109 return E_NOINTERFACE;
110 }
111
112 IUnknown_AddRef((IUnknown*)*ppv);
113 return S_OK;
114}

◆ BmpFrameDecode_ReadABGRasBGR()

static HRESULT BmpFrameDecode_ReadABGRasBGR ( BmpDecoder This)
static

Definition at line 418 of file bmpdecode.c.

419{
420 UINT x, y, width, height;
421 BYTE *pixel;
422 HRESULT hr;
423
424 hr = IWICBitmapFrameDecode_GetSize(&This->IWICBitmapFrameDecode_iface, &width, &height);
425
426 if (SUCCEEDED(hr))
427 {
429 }
430
431 if (SUCCEEDED(hr))
432 {
433 for (y = 0; y < height; y++)
434 {
435 pixel = This->imagedatastart + This->stride * (INT)y;
436
437 for (x = 0; x < width; x++)
438 {
439 pixel[0] = pixel[1];
440 pixel[1] = pixel[2];
441 pixel[2] = pixel[3];
442 pixel[3] = 0;
443 pixel += 4;
444 }
445 }
446 }
447
448 return hr;
449}
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
#define INT
Definition: polytest.cpp:20
unsigned char BYTE
Definition: xxhash.c:193

◆ BmpFrameDecode_ReadRGB8()

static HRESULT BmpFrameDecode_ReadRGB8 ( BmpDecoder This)
static

Definition at line 451 of file bmpdecode.c.

452{
453 HRESULT hr;
455
456 hr = IWICBitmapFrameDecode_GetSize(&This->IWICBitmapFrameDecode_iface, &width, &height);
457
458 if (SUCCEEDED(hr))
459 {
461 }
462
463 if (SUCCEEDED(hr))
464 {
465 reverse_bgr8(This->bitsperpixel/8, This->imagedatastart,
466 width, height, This->stride);
467 }
468
469 return hr;
470}
void reverse_bgr8(UINT bytesperpixel, LPBYTE bits, UINT width, UINT height, INT stride)

◆ BmpFrameDecode_ReadRLE4()

static HRESULT BmpFrameDecode_ReadRLE4 ( BmpDecoder This)
static

Definition at line 618 of file bmpdecode.c.

619{
620 UINT bytesperrow;
622 BYTE rledata[4096];
623 UINT datasize, palettesize;
624 DWORD palette[16];
625 UINT x, y;
626 DWORD *bgrdata;
627 HRESULT hr;
628 LARGE_INTEGER offbits;
629 ULONG cursor=0, bytesread=0;
630
631 width = This->bih.bV5Width;
632 height = abs(This->bih.bV5Height);
633 bytesperrow = width * 4;
634 datasize = bytesperrow * height;
635 if (This->bih.bV5ClrUsed && This->bih.bV5ClrUsed < 16)
636 palettesize = 4 * This->bih.bV5ClrUsed;
637 else
638 palettesize = 4 * 16;
639
640 This->imagedata = malloc(datasize);
641 if (!This->imagedata)
642 {
644 goto fail;
645 }
646
647 /* read palette */
648 offbits.QuadPart = This->palette_offset;
649 hr = IStream_Seek(This->stream, offbits, STREAM_SEEK_SET, NULL);
650 if (FAILED(hr)) goto fail;
651
652 hr = IStream_Read(This->stream, palette, palettesize, &bytesread);
653 if (FAILED(hr) || bytesread != palettesize) goto fail;
654
655 /* read RLE data */
656 offbits.QuadPart = This->image_offset;
657 hr = IStream_Seek(This->stream, offbits, STREAM_SEEK_SET, NULL);
658 if (FAILED(hr)) goto fail;
659
660 /* decode RLE */
661 bgrdata = (DWORD*)This->imagedata;
662 x = 0;
663 y = 0;
664 cursor = 0;
665 bytesread = 0;
666 while (y < height)
667 {
668 BYTE length;
669 hr = ReadByte(This->stream, rledata, 4096, &cursor, &bytesread, &length);
670
671 if (FAILED(hr))
672 goto fail;
673 else if (length == 0)
674 {
675 /* escape code */
676 BYTE escape;
677 hr = ReadByte(This->stream, rledata, 4096, &cursor, &bytesread, &escape);
678 if (FAILED(hr))
679 goto fail;
680 switch(escape)
681 {
682 case 0: /* end of line */
683 x = 0;
684 y++;
685 break;
686 case 1: /* end of bitmap */
687 goto end;
688 case 2: /* delta */
689 {
690 BYTE dx, dy;
691 hr = ReadByte(This->stream, rledata, 4096, &cursor, &bytesread, &dx);
692 if (SUCCEEDED(hr))
693 hr = ReadByte(This->stream, rledata, 4096, &cursor, &bytesread, &dy);
694 if (FAILED(hr))
695 goto fail;
696 x += dx;
697 y += dy;
698 break;
699 }
700 default: /* absolute mode */
701 {
702 BYTE realsize=0;
703 length = escape;
704 while (length-- && x < width)
705 {
706 BYTE colors;
707 hr = ReadByte(This->stream, rledata, 4096, &cursor, &bytesread, &colors);
708 realsize++;
709 if (FAILED(hr))
710 goto fail;
711 bgrdata[y*width + x++] = palette[colors>>4];
712 if (length-- && x < width)
713 bgrdata[y*width + x++] = palette[colors&0xf];
714 else
715 break;
716 }
717 if (realsize & 1)
718 hr = ReadByte(This->stream, rledata, 4096, &cursor, &bytesread, &length); /* skip pad byte */
719 if (FAILED(hr))
720 goto fail;
721 }
722 }
723 }
724 else
725 {
726 BYTE colors;
727 DWORD color1;
728 DWORD color2;
729 hr = ReadByte(This->stream, rledata, 4096, &cursor, &bytesread, &colors);
730 if (FAILED(hr))
731 goto fail;
732 color1 = palette[colors>>4];
733 color2 = palette[colors&0xf];
734 while (length-- && x < width)
735 {
736 bgrdata[y*width + x++] = color1;
737 if (length-- && x < width)
738 bgrdata[y*width + x++] = color2;
739 else
740 break;
741 }
742 }
743 }
744
745end:
746 This->imagedatastart = This->imagedata + (height-1) * bytesperrow;
747 This->stride = -bytesperrow;
748
749 return S_OK;
750
751fail:
752 free(This->imagedata);
753 This->imagedata = NULL;
754 if (SUCCEEDED(hr)) hr = E_FAIL;
755 return hr;
756}
static HRESULT ReadByte(IStream *stream, BYTE *buffer, ULONG buffer_size, ULONG *cursor, ULONG *bytesread, BYTE *result)
Definition: bmpdecode.c:472
while(CdLookupNextInitialFileDirent(IrpContext, Fcb, FileContext))
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
const char cursor[]
Definition: icontest.c:13
GLint dy
Definition: linetemp.h:97
GLint dx
Definition: linetemp.h:97
static HPALETTE palette
Definition: clipboard.c:1345
static WCHAR escape[]
Definition: url.c:36
LONGLONG QuadPart
Definition: typedefs.h:114

Referenced by BmpDecoder_ReadHeaders().

◆ BmpFrameDecode_ReadRLE8()

static HRESULT BmpFrameDecode_ReadRLE8 ( BmpDecoder This)
static

Definition at line 494 of file bmpdecode.c.

495{
496 UINT bytesperrow;
498 BYTE rledata[4096];
499 UINT datasize, palettesize;
500 DWORD palette[256];
501 UINT x, y;
502 DWORD *bgrdata;
503 HRESULT hr;
504 LARGE_INTEGER offbits;
505 ULONG cursor=0, bytesread=0;
506
507 width = This->bih.bV5Width;
508 height = abs(This->bih.bV5Height);
509 bytesperrow = width * 4;
510 datasize = bytesperrow * height;
511 if (This->bih.bV5ClrUsed && This->bih.bV5ClrUsed < 256)
512 palettesize = 4 * This->bih.bV5ClrUsed;
513 else
514 palettesize = 4 * 256;
515
516 This->imagedata = malloc(datasize);
517 if (!This->imagedata)
518 {
520 goto fail;
521 }
522
523 /* read palette */
524 offbits.QuadPart = This->palette_offset;
525 hr = IStream_Seek(This->stream, offbits, STREAM_SEEK_SET, NULL);
526 if (FAILED(hr)) goto fail;
527
528 hr = IStream_Read(This->stream, palette, palettesize, &bytesread);
529 if (FAILED(hr) || bytesread != palettesize) goto fail;
530
531 /* read RLE data */
532 offbits.QuadPart = This->image_offset;
533 hr = IStream_Seek(This->stream, offbits, STREAM_SEEK_SET, NULL);
534 if (FAILED(hr)) goto fail;
535
536 /* decode RLE */
537 bgrdata = (DWORD*)This->imagedata;
538 x = 0;
539 y = 0;
540 cursor = 0;
541 bytesread = 0;
542 while (y < height)
543 {
544 BYTE length;
545 hr = ReadByte(This->stream, rledata, 4096, &cursor, &bytesread, &length);
546
547 if (FAILED(hr))
548 goto fail;
549 else if (length == 0)
550 {
551 /* escape code */
552 BYTE escape;
553 hr = ReadByte(This->stream, rledata, 4096, &cursor, &bytesread, &escape);
554 if (FAILED(hr))
555 goto fail;
556 switch(escape)
557 {
558 case 0: /* end of line */
559 x = 0;
560 y++;
561 break;
562 case 1: /* end of bitmap */
563 goto end;
564 case 2: /* delta */
565 {
566 BYTE dx, dy;
567 hr = ReadByte(This->stream, rledata, 4096, &cursor, &bytesread, &dx);
568 if (SUCCEEDED(hr))
569 hr = ReadByte(This->stream, rledata, 4096, &cursor, &bytesread, &dy);
570 if (FAILED(hr))
571 goto fail;
572 x += dx;
573 y += dy;
574 break;
575 }
576 default: /* absolute mode */
577 length = escape;
578 while (length-- && x < width)
579 {
580 BYTE index;
581 hr = ReadByte(This->stream, rledata, 4096, &cursor, &bytesread, &index);
582 if (FAILED(hr))
583 goto fail;
584 bgrdata[y*width + x++] = palette[index];
585 }
586 if (escape & 1)
587 hr = ReadByte(This->stream, rledata, 4096, &cursor, &bytesread, &length); /* skip pad byte */
588 if (FAILED(hr))
589 goto fail;
590 }
591 }
592 else
593 {
594 BYTE index;
595 DWORD color;
596 hr = ReadByte(This->stream, rledata, 4096, &cursor, &bytesread, &index);
597 if (FAILED(hr))
598 goto fail;
600 while (length-- && x < width)
601 bgrdata[y*width + x++] = color;
602 }
603 }
604
605end:
606 This->imagedatastart = This->imagedata + (height-1) * bytesperrow;
607 This->stride = -bytesperrow;
608
609 return S_OK;
610
611fail:
612 free(This->imagedata);
613 This->imagedata = NULL;
614 if (SUCCEEDED(hr)) hr = E_FAIL;
615 return hr;
616}
#define index(s, c)
Definition: various.h:29
GLuint color
Definition: glext.h:6243

Referenced by BmpDecoder_ReadHeaders().

◆ BmpFrameDecode_ReadUncompressed()

static HRESULT BmpFrameDecode_ReadUncompressed ( BmpDecoder This)
static

Definition at line 361 of file bmpdecode.c.

362{
363 UINT bytesperrow;
366 int bottomup;
367 HRESULT hr;
368 LARGE_INTEGER offbits;
369 ULONG bytesread;
370
371 if (This->bih.bV5Size == sizeof(BITMAPCOREHEADER))
372 {
374 width = bch->bcWidth;
375 height = bch->bcHeight;
376 bottomup = 1;
377 }
378 else
379 {
380 width = This->bih.bV5Width;
381 height = abs(This->bih.bV5Height);
382 bottomup = (This->bih.bV5Height > 0);
383 }
384
385 /* row sizes in BMP files must be divisible by 4 bytes */
386 bytesperrow = (((width * This->bitsperpixel)+31)/32)*4;
387 datasize = bytesperrow * height;
388
389 This->imagedata = malloc(datasize);
390 if (!This->imagedata) return E_OUTOFMEMORY;
391
392 offbits.QuadPart = This->image_offset;
393 hr = IStream_Seek(This->stream, offbits, STREAM_SEEK_SET, NULL);
394 if (FAILED(hr)) goto fail;
395
396 hr = IStream_Read(This->stream, This->imagedata, datasize, &bytesread);
397 if (FAILED(hr) || bytesread != datasize) goto fail;
398
399 if (bottomup)
400 {
401 This->imagedatastart = This->imagedata + (height-1) * bytesperrow;
402 This->stride = -bytesperrow;
403 }
404 else
405 {
406 This->imagedatastart = This->imagedata;
407 This->stride = bytesperrow;
408 }
409 return S_OK;
410
411fail:
412 free(This->imagedata);
413 This->imagedata = NULL;
414 if (SUCCEEDED(hr)) hr = E_FAIL;
415 return hr;
416}

Referenced by BmpDecoder_FindIconMask(), BmpDecoder_ReadHeaders(), BmpFrameDecode_ReadABGRasBGR(), and BmpFrameDecode_ReadRGB8().

◆ BmpFrameDecode_ReadUnsupported()

static HRESULT BmpFrameDecode_ReadUnsupported ( BmpDecoder This)
static

Definition at line 758 of file bmpdecode.c.

759{
760 return E_FAIL;
761}

Referenced by BmpDecoder_QueryCapability(), and BmpDecoder_ReadHeaders().

◆ BmpFrameDecode_Release()

static ULONG WINAPI BmpFrameDecode_Release ( IWICBitmapFrameDecode iface)
static

Definition at line 123 of file bmpdecode.c.

124{
126
127 return IWICBitmapDecoder_Release(&This->IWICBitmapDecoder_iface);
128}

◆ BmpHeader_GetResolution()

static HRESULT BmpHeader_GetResolution ( BITMAPV5HEADER *  bih,
double pDpiX,
double pDpiY 
)
static

Definition at line 161 of file bmpdecode.c.

162{
163 LONG resx = 0, resy = 0;
164
165 switch (bih->bV5Size)
166 {
167 default:
168 case sizeof(BITMAPCOREHEADER):
169 break;
170
171 case sizeof(BITMAPCOREHEADER2):
172 case sizeof(BITMAPINFOHEADER):
173 case sizeof(BITMAPV4HEADER):
174 case sizeof(BITMAPV5HEADER):
175 resx = bih->bV5XPelsPerMeter;
176 resy = bih->bV5YPelsPerMeter;
177 break;
178 }
179
180 if (!resx || !resy)
181 {
182 *pDpiX = 96.0;
183 *pDpiY = 96.0;
184 }
185 else
186 {
187 *pDpiX = resx * 0.0254;
188 *pDpiY = resy * 0.0254;
189 }
190
191 return S_OK;
192}
long LONG
Definition: pedump.c:60
struct tagBITMAPCOREHEADER BITMAPCOREHEADER

Referenced by BmpFrameDecode_GetResolution().

◆ DibDecoder_CreateInstance()

HRESULT DibDecoder_CreateInstance ( REFIID  iid,
void **  ppv 
)

Definition at line 1235 of file bmpdecode.c.

1236{
1237 return BmpDecoder_Construct(TRUE, FALSE, iid, ppv);
1238}

◆ IcoDibDecoder_CreateInstance()

HRESULT IcoDibDecoder_CreateInstance ( BmpDecoder **  ppDecoder)

Definition at line 1240 of file bmpdecode.c.

1241{
1242 return BmpDecoder_Create(TRUE, TRUE, ppDecoder);
1243}

Referenced by ReadIcoDib().

◆ impl_from_IWICBitmapDecoder()

static BmpDecoder * impl_from_IWICBitmapDecoder ( IWICBitmapDecoder iface)
inlinestatic

Definition at line 81 of file bmpdecode.c.

82{
83 return CONTAINING_RECORD(iface, BmpDecoder, IWICBitmapDecoder_iface);
84}
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260

Referenced by BmpDecoder_AddRef(), BmpDecoder_GetFrame(), BmpDecoder_Initialize(), BmpDecoder_QueryCapability(), BmpDecoder_QueryInterface(), and BmpDecoder_Release().

◆ impl_from_IWICBitmapFrameDecode()

◆ ReadByte()

static HRESULT ReadByte ( IStream stream,
BYTE buffer,
ULONG  buffer_size,
ULONG cursor,
ULONG bytesread,
BYTE result 
)
static

Definition at line 472 of file bmpdecode.c.

474{
476
477 if (*bytesread == 0 || *cursor == *bytesread)
478 {
479 hr = IStream_Read(stream, buffer, buffer_size, bytesread);
480 *cursor = 0;
481 }
482
483 if (SUCCEEDED(hr))
484 {
485 if (*cursor < *bytesread)
486 *result = buffer[(*cursor)++];
487 else
488 hr = E_FAIL;
489 }
490
491 return hr;
492}
GLuint buffer
Definition: glext.h:5915
GLuint64EXT * result
Definition: glext.h:11304
wchar_t const *const size_t const buffer_size
Definition: stat.cpp:95

Referenced by BmpFrameDecode_ReadRLE4(), and BmpFrameDecode_ReadRLE8().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( wincodecs  )

Variable Documentation

◆ bitfields_formats

const struct bitfields_format bitfields_formats[]
static
Initial value:
= {
{16,0x7c00,0x3e0,0x1f,0,&GUID_WICPixelFormat16bppBGR555,BmpFrameDecode_ReadUncompressed},
{16,0xf800,0x7e0,0x1f,0,&GUID_WICPixelFormat16bppBGR565,BmpFrameDecode_ReadUncompressed},
{32,0xff0000,0xff00,0xff,0,&GUID_WICPixelFormat32bppBGR,BmpFrameDecode_ReadUncompressed},
{32,0xff0000,0xff00,0xff,0xff000000,&GUID_WICPixelFormat32bppBGRA,BmpFrameDecode_ReadUncompressed},
{32,0xff000000,0xff0000,0xff00,0xff,&GUID_WICPixelFormat32bppBGR,BmpFrameDecode_ReadABGRasBGR},
{32,0xff,0xff00,0xff0000,0,&GUID_WICPixelFormat32bppBGR,BmpFrameDecode_ReadRGB8},
{0}
}
static HRESULT BmpFrameDecode_ReadABGRasBGR(BmpDecoder *This)
Definition: bmpdecode.c:418
static HRESULT BmpFrameDecode_ReadRGB8(BmpDecoder *This)
Definition: bmpdecode.c:451

Definition at line 773 of file bmpdecode.c.

Referenced by BmpDecoder_ReadHeaders().

◆ BmpDecoder_FrameVtbl

const IWICBitmapFrameDecodeVtbl BmpDecoder_FrameVtbl
static
Initial value:
= {
}
static HRESULT WINAPI BmpFrameDecode_CopyPalette(IWICBitmapFrameDecode *iface, IWICPalette *pIPalette)
Definition: bmpdecode.c:203
static HRESULT WINAPI BmpFrameDecode_QueryInterface(IWICBitmapFrameDecode *iface, REFIID iid, void **ppv)
Definition: bmpdecode.c:91
static HRESULT WINAPI BmpFrameDecode_GetResolution(IWICBitmapFrameDecode *iface, double *pDpiX, double *pDpiY)
Definition: bmpdecode.c:194
static HRESULT WINAPI BmpFrameDecode_GetThumbnail(IWICBitmapFrameDecode *iface, IWICBitmapSource **ppIThumbnail)
Definition: bmpdecode.c:354
static ULONG WINAPI BmpFrameDecode_Release(IWICBitmapFrameDecode *iface)
Definition: bmpdecode.c:123
static HRESULT WINAPI BmpFrameDecode_GetMetadataQueryReader(IWICBitmapFrameDecode *iface, IWICMetadataQueryReader **ppIMetadataQueryReader)
Definition: bmpdecode.c:340
static HRESULT WINAPI BmpFrameDecode_GetPixelFormat(IWICBitmapFrameDecode *iface, WICPixelFormatGUID *pPixelFormat)
Definition: bmpdecode.c:150
static ULONG WINAPI BmpFrameDecode_AddRef(IWICBitmapFrameDecode *iface)
Definition: bmpdecode.c:116
static HRESULT WINAPI BmpFrameDecode_GetColorContexts(IWICBitmapFrameDecode *iface, UINT cCount, IWICColorContext **ppIColorContexts, UINT *pcActualCount)
Definition: bmpdecode.c:347
static HRESULT WINAPI BmpFrameDecode_CopyPixels(IWICBitmapFrameDecode *iface, const WICRect *prc, UINT cbStride, UINT cbBufferSize, BYTE *pbBuffer)
Definition: bmpdecode.c:316

Definition at line 783 of file bmpdecode.c.

Referenced by BmpDecoder_Create().

◆ BmpDecoder_Vtbl

const IWICBitmapDecoderVtbl BmpDecoder_Vtbl
static
Initial value:
= {
}
static ULONG WINAPI BmpDecoder_AddRef(IWICBitmapDecoder *iface)
Definition: bmpdecode.c:1028
static HRESULT WINAPI BmpDecoder_GetContainerFormat(IWICBitmapDecoder *iface, GUID *pguidContainerFormat)
Definition: bmpdecode.c:1093
static HRESULT WINAPI BmpDecoder_GetColorContexts(IWICBitmapDecoder *iface, UINT cCount, IWICColorContext **ppIColorContexts, UINT *pcActualCount)
Definition: bmpdecode.c:1130
static ULONG WINAPI BmpDecoder_Release(IWICBitmapDecoder *iface)
Definition: bmpdecode.c:1038
static HRESULT WINAPI BmpDecoder_QueryCapability(IWICBitmapDecoder *iface, IStream *stream, DWORD *capability)
Definition: bmpdecode.c:1057
static HRESULT WINAPI BmpDecoder_CopyPalette(IWICBitmapDecoder *iface, IWICPalette *pIPalette)
Definition: bmpdecode.c:1108
static HRESULT WINAPI BmpDecoder_GetFrame(IWICBitmapDecoder *iface, UINT index, IWICBitmapFrameDecode **ppIBitmapFrame)
Definition: bmpdecode.c:1153
static HRESULT WINAPI BmpDecoder_QueryInterface(IWICBitmapDecoder *iface, REFIID iid, void **ppv)
Definition: bmpdecode.c:1005
static HRESULT WINAPI BmpDecoder_GetThumbnail(IWICBitmapDecoder *iface, IWICBitmapSource **ppIThumbnail)
Definition: bmpdecode.c:1137
static HRESULT WINAPI BmpDecoder_Initialize(IWICBitmapDecoder *iface, IStream *pIStream, WICDecodeOptions cacheOptions)
Definition: bmpdecode.c:1074
static HRESULT WINAPI BmpDecoder_GetMetadataQueryReader(IWICBitmapDecoder *iface, IWICMetadataQueryReader **ppIMetadataQueryReader)
Definition: bmpdecode.c:1116
static HRESULT WINAPI BmpDecoder_GetFrameCount(IWICBitmapDecoder *iface, UINT *pCount)
Definition: bmpdecode.c:1144
static HRESULT WINAPI BmpDecoder_GetDecoderInfo(IWICBitmapDecoder *iface, IWICBitmapDecoderInfo **ppIDecoderInfo)
Definition: bmpdecode.c:1100
static HRESULT WINAPI BmpDecoder_GetPreview(IWICBitmapDecoder *iface, IWICBitmapSource **ppIBitmapSource)
Definition: bmpdecode.c:1123

Definition at line 1168 of file bmpdecode.c.

Referenced by BmpDecoder_Create().