ReactOS 0.4.15-dev-8241-g63935f8
icoformat.c File Reference
#include "config.h"
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "wingdi.h"
#include "objbase.h"
#include "wincodecs_private.h"
#include "wine/debug.h"
#include "pshpack1.h"
#include "poppack.h"
Include dependency graph for icoformat.c:

Go to the source code of this file.

Classes

struct  ICONDIRENTRY
 
struct  ICONHEADER
 
struct  IcoDecoder
 
struct  IcoFrameDecode
 

Macros

#define COBJMACROS
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (wincodecs)
 
static IcoDecoderimpl_from_IWICBitmapDecoder (IWICBitmapDecoder *iface)
 
static IcoFrameDecodeimpl_from_IWICBitmapFrameDecode (IWICBitmapFrameDecode *iface)
 
static HRESULT WINAPI IcoFrameDecode_QueryInterface (IWICBitmapFrameDecode *iface, REFIID iid, void **ppv)
 
static ULONG WINAPI IcoFrameDecode_AddRef (IWICBitmapFrameDecode *iface)
 
static ULONG WINAPI IcoFrameDecode_Release (IWICBitmapFrameDecode *iface)
 
static HRESULT WINAPI IcoFrameDecode_GetSize (IWICBitmapFrameDecode *iface, UINT *puiWidth, UINT *puiHeight)
 
static HRESULT WINAPI IcoFrameDecode_GetPixelFormat (IWICBitmapFrameDecode *iface, WICPixelFormatGUID *pPixelFormat)
 
static HRESULT WINAPI IcoFrameDecode_GetResolution (IWICBitmapFrameDecode *iface, double *pDpiX, double *pDpiY)
 
static HRESULT WINAPI IcoFrameDecode_CopyPalette (IWICBitmapFrameDecode *iface, IWICPalette *pIPalette)
 
static HRESULT WINAPI IcoFrameDecode_CopyPixels (IWICBitmapFrameDecode *iface, const WICRect *prc, UINT cbStride, UINT cbBufferSize, BYTE *pbBuffer)
 
static HRESULT WINAPI IcoFrameDecode_GetMetadataQueryReader (IWICBitmapFrameDecode *iface, IWICMetadataQueryReader **ppIMetadataQueryReader)
 
static HRESULT WINAPI IcoFrameDecode_GetColorContexts (IWICBitmapFrameDecode *iface, UINT cCount, IWICColorContext **ppIColorContexts, UINT *pcActualCount)
 
static HRESULT WINAPI IcoFrameDecode_GetThumbnail (IWICBitmapFrameDecode *iface, IWICBitmapSource **ppIThumbnail)
 
static void pixel_set_trans (DWORD *pixel, BOOL transparent)
 
static HRESULT ReadIcoDib (IStream *stream, IcoFrameDecode *result)
 
static HRESULT ReadIcoPng (IStream *stream, IcoFrameDecode *result)
 
static HRESULT WINAPI IcoDecoder_QueryInterface (IWICBitmapDecoder *iface, REFIID iid, void **ppv)
 
static ULONG WINAPI IcoDecoder_AddRef (IWICBitmapDecoder *iface)
 
static ULONG WINAPI IcoDecoder_Release (IWICBitmapDecoder *iface)
 
static HRESULT WINAPI IcoDecoder_QueryCapability (IWICBitmapDecoder *iface, IStream *stream, DWORD *capability)
 
static HRESULT WINAPI IcoDecoder_Initialize (IWICBitmapDecoder *iface, IStream *pIStream, WICDecodeOptions cacheOptions)
 
static HRESULT WINAPI IcoDecoder_GetContainerFormat (IWICBitmapDecoder *iface, GUID *pguidContainerFormat)
 
static HRESULT WINAPI IcoDecoder_GetDecoderInfo (IWICBitmapDecoder *iface, IWICBitmapDecoderInfo **ppIDecoderInfo)
 
static HRESULT WINAPI IcoDecoder_CopyPalette (IWICBitmapDecoder *iface, IWICPalette *pIPalette)
 
static HRESULT WINAPI IcoDecoder_GetMetadataQueryReader (IWICBitmapDecoder *iface, IWICMetadataQueryReader **ppIMetadataQueryReader)
 
static HRESULT WINAPI IcoDecoder_GetPreview (IWICBitmapDecoder *iface, IWICBitmapSource **ppIBitmapSource)
 
static HRESULT WINAPI IcoDecoder_GetColorContexts (IWICBitmapDecoder *iface, UINT cCount, IWICColorContext **ppIColorContexts, UINT *pcActualCount)
 
static HRESULT WINAPI IcoDecoder_GetThumbnail (IWICBitmapDecoder *iface, IWICBitmapSource **ppIThumbnail)
 
static HRESULT WINAPI IcoDecoder_GetFrameCount (IWICBitmapDecoder *iface, UINT *pCount)
 
static HRESULT WINAPI IcoDecoder_GetFrame (IWICBitmapDecoder *iface, UINT index, IWICBitmapFrameDecode **ppIBitmapFrame)
 
HRESULT IcoDecoder_CreateInstance (REFIID iid, void **ppv)
 

Variables

static const IWICBitmapFrameDecodeVtbl IcoFrameDecode_Vtbl
 
static const IWICBitmapDecoderVtbl IcoDecoder_Vtbl
 

Macro Definition Documentation

◆ COBJMACROS

#define COBJMACROS

Definition at line 23 of file icoformat.c.

Function Documentation

◆ IcoDecoder_AddRef()

static ULONG WINAPI IcoDecoder_AddRef ( IWICBitmapDecoder iface)
static

Definition at line 463 of file icoformat.c.

464{
467
468 TRACE("(%p) refcount=%u\n", iface, ref);
469
470 return ref;
471}
#define InterlockedIncrement
Definition: armddk.h:53
static IcoDecoder * impl_from_IWICBitmapDecoder(IWICBitmapDecoder *iface)
Definition: icoformat.c:75
#define TRACE(s)
Definition: solgame.cpp:4
Definition: send.c:48
uint32_t ULONG
Definition: typedefs.h:59

◆ IcoDecoder_CopyPalette()

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

Definition at line 594 of file icoformat.c.

596{
597 TRACE("(%p,%p)\n", iface, pIPalette);
599}
#define WINCODEC_ERR_PALETTEUNAVAILABLE
Definition: winerror.h:3292

◆ IcoDecoder_CreateInstance()

HRESULT IcoDecoder_CreateInstance ( REFIID  iid,
void **  ppv 
)

Definition at line 759 of file icoformat.c.

760{
762 HRESULT ret;
763
764 TRACE("(%s,%p)\n", debugstr_guid(iid), ppv);
765
766 *ppv = NULL;
767
768 This = HeapAlloc(GetProcessHeap(), 0, sizeof(IcoDecoder));
769 if (!This) return E_OUTOFMEMORY;
770
771 This->IWICBitmapDecoder_iface.lpVtbl = &IcoDecoder_Vtbl;
772 This->ref = 1;
773 This->stream = NULL;
774 This->initialized = FALSE;
776 This->lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": IcoDecoder.lock");
777
778 ret = IWICBitmapDecoder_QueryInterface(&This->IWICBitmapDecoder_iface, iid, ppv);
779 IWICBitmapDecoder_Release(&This->IWICBitmapDecoder_iface);
780
781 return ret;
782}
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
static const IWICBitmapDecoderVtbl IcoDecoder_Vtbl
Definition: icoformat.c:742
REFIID LPVOID * ppv
Definition: atlbase.h:39
#define debugstr_guid
Definition: kernel32.h:35
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:751
#define DWORD_PTR
Definition: treelist.c:76
int ret

◆ IcoDecoder_GetColorContexts()

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

Definition at line 615 of file icoformat.c.

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

◆ IcoDecoder_GetContainerFormat()

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

Definition at line 579 of file icoformat.c.

581{
582 memcpy(pguidContainerFormat, &GUID_ContainerFormatIco, sizeof(GUID));
583 return S_OK;
584}
#define S_OK
Definition: intsafe.h:52
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878

◆ IcoDecoder_GetDecoderInfo()

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

Definition at line 586 of file icoformat.c.

588{
589 TRACE("(%p,%p)\n", iface, ppIDecoderInfo);
590
591 return get_decoder_info(&CLSID_WICIcoDecoder, ppIDecoderInfo);
592}
static GpStatus get_decoder_info(IStream *stream, const struct image_codec **result)
Definition: image.c:4285

◆ IcoDecoder_GetFrame()

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

Definition at line 645 of file icoformat.c.

647{
652 HRESULT hr;
653 ULONG bytesread;
655 IWICStream *substream=NULL;
656 DWORD magic;
657 TRACE("(%p,%u,%p)\n", iface, index, ppIBitmapFrame);
658
660
661 if (!This->initialized)
662 {
664 goto fail;
665 }
666
667 if (This->header.idCount < index)
668 {
670 goto fail;
671 }
672
674 if (!result)
675 {
677 goto fail;
678 }
679
680 result->IWICBitmapFrameDecode_iface.lpVtbl = &IcoFrameDecode_Vtbl;
681 result->ref = 1;
682 result->bits = NULL;
683
684 /* read the icon entry */
685 seek.QuadPart = sizeof(ICONHEADER) + sizeof(ICONDIRENTRY) * index;
686 hr = IStream_Seek(This->stream, seek, STREAM_SEEK_SET, 0);
687 if (FAILED(hr)) goto fail;
688
689 hr = IStream_Read(This->stream, &entry, sizeof(ICONDIRENTRY), &bytesread);
690 if (FAILED(hr) || bytesread != sizeof(ICONDIRENTRY)) goto fail;
691
692 /* create a stream object for this icon */
693 hr = StreamImpl_Create(&substream);
694 if (FAILED(hr)) goto fail;
695
696 offset.QuadPart = entry.dwDIBOffset;
697 length.QuadPart = entry.dwDIBSize;
698 hr = IWICStream_InitializeFromIStreamRegion(substream, This->stream, offset, length);
699 if (FAILED(hr)) goto fail;
700
701 /* read the bitmapinfo size or magic number */
702 hr = IWICStream_Read(substream, &magic, sizeof(magic), &bytesread);
703 if (FAILED(hr) || bytesread != sizeof(magic)) goto fail;
704
705 /* forward to the appropriate decoding function based on the magic number */
706 switch (magic)
707 {
708 case sizeof(BITMAPCOREHEADER):
709 case 64: /* sizeof(BITMAPCOREHEADER2) */
710 case sizeof(BITMAPINFOHEADER):
711 case sizeof(BITMAPV4HEADER):
712 case sizeof(BITMAPV5HEADER):
713 hr = ReadIcoDib((IStream*)substream, result);
714 break;
715 case 0x474e5089:
716 hr = ReadIcoPng((IStream*)substream, result);
717 break;
718 default:
719 FIXME("Unrecognized ICO frame magic: %x\n", magic);
720 hr = E_FAIL;
721 break;
722 }
723 if (FAILED(hr)) goto fail;
724
725 *ppIBitmapFrame = &result->IWICBitmapFrameDecode_iface;
726
728
729 IWICStream_Release(substream);
730
731 return S_OK;
732
733fail:
736 if (substream) IWICStream_Release(substream);
737 if (SUCCEEDED(hr)) hr = E_FAIL;
738 TRACE("<-- %x\n", hr);
739 return hr;
740}
#define index(s, c)
Definition: various.h:29
#define FIXME(fmt,...)
Definition: debug.h:114
#define E_INVALIDARG
Definition: ddrawi.h:101
#define E_FAIL
Definition: ddrawi.h:102
#define HeapFree(x, y, z)
Definition: compat.h:735
static HRESULT ReadIcoDib(IStream *stream, IcoFrameDecode *result)
Definition: icoformat.c:226
static const IWICBitmapFrameDecodeVtbl IcoFrameDecode_Vtbl
Definition: icoformat.c:206
static HRESULT ReadIcoPng(IStream *stream, IcoFrameDecode *result)
Definition: icoformat.c:391
HRESULT StreamImpl_Create(IWICStream **stream)
Definition: stream.c:1150
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint index
Definition: glext.h:6031
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
GLuint64EXT * result
Definition: glext.h:11304
GLintptr offset
Definition: glext.h:5920
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define FAILED(hr)
Definition: intsafe.h:51
uint32_t entry
Definition: isohybrid.c:63
u32_t magic(void)
int seek(void *fd, ulong off, int mode)
Definition: pe.c:51
HRESULT hr
Definition: shlfolder.c:183
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
#define WINCODEC_ERR_FRAMEMISSING
Definition: winerror.h:3301
struct tagBITMAPCOREHEADER BITMAPCOREHEADER

◆ IcoDecoder_GetFrameCount()

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

Definition at line 629 of file icoformat.c.

631{
633
634 if (!pCount) return E_INVALIDARG;
635
637 *pCount = This->initialized ? This->header.idCount : 0;
639
640 TRACE("(%p) <-- %d\n", iface, *pCount);
641
642 return S_OK;
643}

◆ IcoDecoder_GetMetadataQueryReader()

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

Definition at line 601 of file icoformat.c.

603{
604 TRACE("(%p,%p)\n", iface, ppIMetadataQueryReader);
606}

◆ IcoDecoder_GetPreview()

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

Definition at line 608 of file icoformat.c.

610{
611 TRACE("(%p,%p)\n", iface, ppIBitmapSource);
613}

◆ IcoDecoder_GetThumbnail()

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

Definition at line 622 of file icoformat.c.

624{
625 TRACE("(%p,%p)\n", iface, ppIThumbnail);
627}
#define WINCODEC_ERR_CODECNOTHUMBNAIL
Definition: winerror.h:3291

◆ IcoDecoder_Initialize()

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

Definition at line 507 of file icoformat.c.

509{
512 HRESULT hr;
513 ULONG bytesread;
514 STATSTG statstg;
515 unsigned int i;
516
517 TRACE("(%p,%p,%x)\n", iface, pIStream, cacheOptions);
518
520
521 if (This->initialized)
522 {
524 goto end;
525 }
526
527 seek.QuadPart = 0;
528 hr = IStream_Seek(pIStream, seek, STREAM_SEEK_SET, NULL);
529 if (FAILED(hr)) goto end;
530
531 hr = IStream_Read(pIStream, &This->header, sizeof(ICONHEADER), &bytesread);
532 if (FAILED(hr)) goto end;
533
534 if (bytesread != sizeof(ICONHEADER))
535 {
537 goto end;
538 }
539
540 if (This->header.idReserved != 0 ||
541 This->header.idType != 1)
542 {
543 hr = E_FAIL;
544 goto end;
545 }
546
547 hr = IStream_Stat(pIStream, &statstg, STATFLAG_NONAME);
548 if (FAILED(hr))
549 {
550 WARN("Stat() failed, hr %#x.\n", hr);
551 goto end;
552 }
553
554 for (i = 0; i < This->header.idCount; i++)
555 {
556 ICONDIRENTRY direntry;
557
558 hr = IStream_Read(pIStream, &direntry, sizeof(direntry), &bytesread);
559 if (FAILED(hr)) goto end;
560
561 if (bytesread != sizeof(direntry) || (direntry.dwDIBSize + direntry.dwDIBOffset > statstg.cbSize.QuadPart))
562 {
564 goto end;
565 }
566 }
567
568 This->initialized = TRUE;
569 This->stream = pIStream;
570 IStream_AddRef(pIStream);
571
572end:
573
575
576 return hr;
577}
#define WARN(fmt,...)
Definition: debug.h:115
#define TRUE
Definition: types.h:120
GLuint GLuint end
Definition: gl.h:1545
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
DWORD dwDIBSize
Definition: icoformat.c:45
DWORD dwDIBOffset
Definition: icoformat.c:46
#define WINCODEC_ERR_WRONGSTATE
Definition: winerror.h:3281
#define WINCODEC_ERR_BADIMAGE
Definition: winerror.h:3299
#define WINCODEC_ERR_STREAMREAD
Definition: winerror.h:3305

◆ IcoDecoder_QueryCapability()

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

Definition at line 491 of file icoformat.c.

493{
494 HRESULT hr;
495
496 TRACE("(%p,%p,%p)\n", iface, stream, capability);
497
498 if (!stream || !capability) return E_INVALIDARG;
499
500 hr = IWICBitmapDecoder_Initialize(iface, stream, WICDecodeMetadataCacheOnDemand);
501 if (hr != S_OK) return hr;
502
504 return S_OK;
505}
Definition: parse.h:23
@ WICDecodeMetadataCacheOnDemand
Definition: wincodec.idl:28
@ WICBitmapDecoderCapabilityCanDecodeAllImages
Definition: wincodec.idl:49

◆ IcoDecoder_QueryInterface()

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

Definition at line 440 of file icoformat.c.

442{
444 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
445
446 if (!ppv) return E_INVALIDARG;
447
448 if (IsEqualIID(&IID_IUnknown, iid) ||
449 IsEqualIID(&IID_IWICBitmapDecoder, iid))
450 {
451 *ppv = &This->IWICBitmapDecoder_iface;
452 }
453 else
454 {
455 *ppv = NULL;
456 return E_NOINTERFACE;
457 }
458
459 IUnknown_AddRef((IUnknown*)*ppv);
460 return S_OK;
461}
const GUID IID_IUnknown
#define IsEqualIID(riid1, riid2)
Definition: guiddef.h:95
#define E_NOINTERFACE
Definition: winerror.h:2364

◆ IcoDecoder_Release()

static ULONG WINAPI IcoDecoder_Release ( IWICBitmapDecoder iface)
static

Definition at line 473 of file icoformat.c.

474{
477
478 TRACE("(%p) refcount=%u\n", iface, ref);
479
480 if (ref == 0)
481 {
482 This->lock.DebugInfo->Spare[0] = 0;
484 if (This->stream) IStream_Release(This->stream);
486 }
487
488 return ref;
489}
#define InterlockedDecrement
Definition: armddk.h:52
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)

◆ IcoFrameDecode_AddRef()

static ULONG WINAPI IcoFrameDecode_AddRef ( IWICBitmapFrameDecode iface)
static

Definition at line 109 of file icoformat.c.

110{
113
114 TRACE("(%p) refcount=%u\n", iface, ref);
115
116 return ref;
117}
static IcoFrameDecode * impl_from_IWICBitmapFrameDecode(IWICBitmapFrameDecode *iface)
Definition: icoformat.c:80

◆ IcoFrameDecode_CopyPalette()

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

Definition at line 168 of file icoformat.c.

170{
171 TRACE("(%p,%p)\n", iface, pIPalette);
173}

◆ IcoFrameDecode_CopyPixels()

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

Definition at line 175 of file icoformat.c.

177{
179 TRACE("(%p,%s,%u,%u,%p)\n", iface, debug_wic_rect(prc), cbStride, cbBufferSize, pbBuffer);
180
181 return copy_pixels(32, This->bits, This->width, This->height, This->width * 4,
182 prc, cbStride, cbBufferSize, pbBuffer);
183}
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)

◆ IcoFrameDecode_GetColorContexts()

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

Definition at line 192 of file icoformat.c.

194{
195 TRACE("(%p,%u,%p,%p)\n", iface, cCount, ppIColorContexts, pcActualCount);
197}

◆ IcoFrameDecode_GetMetadataQueryReader()

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

Definition at line 185 of file icoformat.c.

187{
188 TRACE("(%p,%p)\n", iface, ppIMetadataQueryReader);
190}

◆ IcoFrameDecode_GetPixelFormat()

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

Definition at line 148 of file icoformat.c.

150{
151 memcpy(pPixelFormat, &GUID_WICPixelFormat32bppBGRA, sizeof(GUID));
152 return S_OK;
153}

◆ IcoFrameDecode_GetResolution()

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

Definition at line 155 of file icoformat.c.

157{
159
160 *pDpiX = This->dpiX;
161 *pDpiY = This->dpiY;
162
163 TRACE("(%p) -> (%f,%f)\n", iface, *pDpiX, *pDpiY);
164
165 return S_OK;
166}

◆ IcoFrameDecode_GetSize()

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

Definition at line 135 of file icoformat.c.

137{
139
140 *puiWidth = This->width;
141 *puiHeight = This->height;
142
143 TRACE("(%p) -> (%i,%i)\n", iface, *puiWidth, *puiHeight);
144
145 return S_OK;
146}

◆ IcoFrameDecode_GetThumbnail()

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

Definition at line 199 of file icoformat.c.

201{
202 TRACE("(%p,%p)\n", iface, ppIThumbnail);
203 return IWICBitmapFrameDecode_QueryInterface(iface, &IID_IWICBitmapSource, (void **)ppIThumbnail);
204}

◆ IcoFrameDecode_QueryInterface()

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

Definition at line 85 of file icoformat.c.

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

◆ IcoFrameDecode_Release()

static ULONG WINAPI IcoFrameDecode_Release ( IWICBitmapFrameDecode iface)
static

Definition at line 119 of file icoformat.c.

120{
123
124 TRACE("(%p) refcount=%u\n", iface, ref);
125
126 if (ref == 0)
127 {
128 HeapFree(GetProcessHeap(), 0, This->bits);
130 }
131
132 return ref;
133}

◆ impl_from_IWICBitmapDecoder()

static IcoDecoder * impl_from_IWICBitmapDecoder ( IWICBitmapDecoder iface)
inlinestatic

Definition at line 75 of file icoformat.c.

76{
77 return CONTAINING_RECORD(iface, IcoDecoder, IWICBitmapDecoder_iface);
78}
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260

Referenced by IcoDecoder_AddRef(), IcoDecoder_GetFrame(), IcoDecoder_GetFrameCount(), IcoDecoder_Initialize(), IcoDecoder_QueryInterface(), and IcoDecoder_Release().

◆ impl_from_IWICBitmapFrameDecode()

static IcoFrameDecode * impl_from_IWICBitmapFrameDecode ( IWICBitmapFrameDecode iface)
inlinestatic

◆ pixel_set_trans()

static void pixel_set_trans ( DWORD pixel,
BOOL  transparent 
)
inlinestatic

Definition at line 220 of file icoformat.c.

221{
222 if (transparent) *pixel = 0;
223 else *pixel |= 0xff000000;
224}

Referenced by ReadIcoDib().

◆ ReadIcoDib()

static HRESULT ReadIcoDib ( IStream stream,
IcoFrameDecode result 
)
static

Definition at line 226 of file icoformat.c.

227{
228 HRESULT hr;
229 BmpDecoder *bmp_decoder;
230 IWICBitmapDecoder *decoder;
231 IWICBitmapFrameDecode *framedecode;
234 BOOL has_alpha=FALSE; /* if TRUE, alpha data might be in the image data */
235 WICRect rc;
236
237 hr = IcoDibDecoder_CreateInstance(&bmp_decoder);
238 if (SUCCEEDED(hr))
239 {
240 BmpDecoder_GetWICDecoder(bmp_decoder, &decoder);
241 hr = IWICBitmapDecoder_Initialize(decoder, stream, WICDecodeMetadataCacheOnLoad);
242
243 if (SUCCEEDED(hr))
244 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &framedecode);
245
246 if (SUCCEEDED(hr))
247 {
248 hr = IWICBitmapFrameDecode_GetSize(framedecode, &result->width, &result->height);
249
250 if (SUCCEEDED(hr))
251 {
252 result->bits = HeapAlloc(GetProcessHeap(), 0, result->width * result->height * 4);
253 if (!result->bits) hr = E_OUTOFMEMORY;
254 }
255
256 if (SUCCEEDED(hr))
257 hr = IWICBitmapFrameDecode_GetPixelFormat(framedecode, &pixelformat);
258
259 if (IsEqualGUID(&pixelformat, &GUID_WICPixelFormat32bppBGR) ||
260 IsEqualGUID(&pixelformat, &GUID_WICPixelFormat32bppBGRA))
261 {
262 source = (IWICBitmapSource*)framedecode;
263 IWICBitmapSource_AddRef(source);
264 has_alpha = TRUE;
265 }
266 else
267 {
268 hr = WICConvertBitmapSource(&GUID_WICPixelFormat32bppBGRA,
269 (IWICBitmapSource*)framedecode, &source);
270 has_alpha = FALSE;
271 }
272
273 if (SUCCEEDED(hr))
274 {
275 rc.X = 0;
276 rc.Y = 0;
277 rc.Width = result->width;
278 rc.Height = result->height;
279 hr = IWICBitmapSource_CopyPixels(source, &rc, result->width * 4,
280 result->width * result->height * 4, result->bits);
281
282 IWICBitmapSource_Release(source);
283 }
284
285 if (SUCCEEDED(hr))
286 hr = IWICBitmapFrameDecode_GetResolution(framedecode, &result->dpiX, &result->dpiY);
287
288 IWICBitmapFrameDecode_Release(framedecode);
289 }
290
291 if (SUCCEEDED(hr) && has_alpha)
292 {
293 /* If the alpha channel is fully transparent, we should ignore it. */
294 int nonzero_alpha = 0;
295 UINT i;
296
297 for (i=0; i<(result->height*result->width); i++)
298 {
299 if (result->bits[i*4+3] != 0)
300 {
301 nonzero_alpha = 1;
302 break;
303 }
304 }
305
306 if (!nonzero_alpha)
307 {
308 for (i=0; i<(result->height*result->width); i++)
309 result->bits[i*4+3] = 0xff;
310
311 has_alpha = FALSE;
312 }
313 }
314
315 if (SUCCEEDED(hr) && !has_alpha)
316 {
317 /* set alpha data based on the AND mask */
318 UINT andBytesPerRow = (result->width+31)/32*4;
319 UINT andBytes = andBytesPerRow * result->height;
320 INT andStride;
321 BYTE *tempdata=NULL;
322 BYTE *andRow;
323 BYTE *bitsRow;
324 UINT bitsStride = result->width * 4;
325 UINT x, y;
327 ULONG bytesread;
329 int topdown;
330
331 BmpDecoder_FindIconMask(bmp_decoder, &offset, &topdown);
332
333 if (offset)
334 {
335 seek.QuadPart = offset;
336
337 hr = IStream_Seek(stream, seek, STREAM_SEEK_SET, 0);
338
339 if (SUCCEEDED(hr))
340 {
341 tempdata = HeapAlloc(GetProcessHeap(), 0, andBytes);
342 if (!tempdata) hr = E_OUTOFMEMORY;
343 }
344
345 if (SUCCEEDED(hr))
346 hr = IStream_Read(stream, tempdata, andBytes, &bytesread);
347
348 if (SUCCEEDED(hr) && bytesread == andBytes)
349 {
350 if (topdown)
351 {
352 andStride = andBytesPerRow;
353 andRow = tempdata;
354 }
355 else
356 {
357 andStride = -andBytesPerRow;
358 andRow = tempdata + (result->height-1)*andBytesPerRow;
359 }
360
361 bitsRow = result->bits;
362 for (y=0; y<result->height; y++) {
363 BYTE *andByte=andRow;
364 DWORD *bitsPixel=(DWORD*)bitsRow;
365 for (x=0; x<result->width; x+=8) {
366 BYTE andVal=*andByte++;
367 pixel_set_trans(bitsPixel++, andVal>>7&1);
368 if (x+1 < result->width) pixel_set_trans(bitsPixel++, andVal>>6&1);
369 if (x+2 < result->width) pixel_set_trans(bitsPixel++, andVal>>5&1);
370 if (x+3 < result->width) pixel_set_trans(bitsPixel++, andVal>>4&1);
371 if (x+4 < result->width) pixel_set_trans(bitsPixel++, andVal>>3&1);
372 if (x+5 < result->width) pixel_set_trans(bitsPixel++, andVal>>2&1);
373 if (x+6 < result->width) pixel_set_trans(bitsPixel++, andVal>>1&1);
374 if (x+7 < result->width) pixel_set_trans(bitsPixel++, andVal&1);
375 }
376 andRow += andStride;
377 bitsRow += bitsStride;
378 }
379 }
380
381 HeapFree(GetProcessHeap(), 0, tempdata);
382 }
383 }
384
385 IWICBitmapDecoder_Release(decoder);
386 }
387
388 return hr;
389}
void BmpDecoder_GetWICDecoder(BmpDecoder *This, IWICBitmapDecoder **ppDecoder)
Definition: bmpdecode.c:1210
void BmpDecoder_FindIconMask(BmpDecoder *This, ULONG *mask_offset, int *topdown)
Definition: bmpdecode.c:1216
HRESULT IcoDibDecoder_CreateInstance(BmpDecoder **ppDecoder)
Definition: bmpdecode.c:1205
pixelformat
Definition: converter.c:40
static void pixel_set_trans(DWORD *pixel, BOOL transparent)
Definition: icoformat.c:220
HRESULT WINAPI WICConvertBitmapSource(REFWICPixelFormatGUID dstFormat, IWICBitmapSource *pISrc, IWICBitmapSource **ppIDst)
Definition: info.c:2474
unsigned int BOOL
Definition: ntddk_ex.h:94
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
unsigned int UINT
Definition: ndis.h:50
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
INT Height
Definition: wincodec.idl:301
INT Width
Definition: wincodec.idl:300
int32_t INT
Definition: typedefs.h:58
@ WICDecodeMetadataCacheOnLoad
Definition: wincodec.idl:29
unsigned char BYTE
Definition: xxhash.c:193

Referenced by IcoDecoder_GetFrame().

◆ ReadIcoPng()

static HRESULT ReadIcoPng ( IStream stream,
IcoFrameDecode result 
)
static

Definition at line 391 of file icoformat.c.

392{
393 IWICBitmapDecoder *decoder = NULL;
394 IWICBitmapFrameDecode *sourceFrame = NULL;
395 IWICBitmapSource *sourceBitmap = NULL;
397 HRESULT hr;
398
399 hr = PngDecoder_CreateInstance(&IID_IWICBitmapDecoder, (void**)&decoder);
400 if (FAILED(hr))
401 goto end;
402 hr = IWICBitmapDecoder_Initialize(decoder, stream, WICDecodeMetadataCacheOnLoad);
403 if (FAILED(hr))
404 goto end;
405 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &sourceFrame);
406 if (FAILED(hr))
407 goto end;
408 hr = WICConvertBitmapSource(&GUID_WICPixelFormat32bppBGRA, (IWICBitmapSource*)sourceFrame, &sourceBitmap);
409 if (FAILED(hr))
410 goto end;
411 hr = IWICBitmapFrameDecode_GetSize(sourceFrame, &result->width, &result->height);
412 if (FAILED(hr))
413 goto end;
414 hr = IWICBitmapFrameDecode_GetResolution(sourceFrame, &result->dpiX, &result->dpiY);
415 if (FAILED(hr))
416 goto end;
417 result->bits = HeapAlloc(GetProcessHeap(), 0, 4 * result->width * result->height);
418 if (result->bits == NULL)
419 {
421 goto end;
422 }
423 rect.X = 0;
424 rect.Y = 0;
425 rect.Width = result->width;
426 rect.Height = result->height;
427 hr = IWICBitmapSource_CopyPixels(sourceBitmap, &rect, 4*result->width,
428 4*result->width*result->height, result->bits);
429
430end:
431 if (decoder != NULL)
432 IWICBitmapDecoder_Release(decoder);
433 if (sourceFrame != NULL)
434 IWICBitmapFrameDecode_Release(sourceFrame);
435 if (sourceBitmap != NULL)
436 IWICBitmapSource_Release(sourceBitmap);
437 return hr;
438}
HRESULT PngDecoder_CreateInstance(REFIID iid, void **ppv)
Definition: pngformat.c:2188
& rect
Definition: startmenu.cpp:1413

Referenced by IcoDecoder_GetFrame().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( wincodecs  )

Variable Documentation

◆ IcoDecoder_Vtbl

const IWICBitmapDecoderVtbl IcoDecoder_Vtbl
static
Initial value:
= {
}
static HRESULT WINAPI IcoDecoder_CopyPalette(IWICBitmapDecoder *iface, IWICPalette *pIPalette)
Definition: icoformat.c:594
static HRESULT WINAPI IcoDecoder_GetContainerFormat(IWICBitmapDecoder *iface, GUID *pguidContainerFormat)
Definition: icoformat.c:579
static HRESULT WINAPI IcoDecoder_GetThumbnail(IWICBitmapDecoder *iface, IWICBitmapSource **ppIThumbnail)
Definition: icoformat.c:622
static HRESULT WINAPI IcoDecoder_GetPreview(IWICBitmapDecoder *iface, IWICBitmapSource **ppIBitmapSource)
Definition: icoformat.c:608
static ULONG WINAPI IcoDecoder_AddRef(IWICBitmapDecoder *iface)
Definition: icoformat.c:463
static HRESULT WINAPI IcoDecoder_GetColorContexts(IWICBitmapDecoder *iface, UINT cCount, IWICColorContext **ppIColorContexts, UINT *pcActualCount)
Definition: icoformat.c:615
static ULONG WINAPI IcoDecoder_Release(IWICBitmapDecoder *iface)
Definition: icoformat.c:473
static HRESULT WINAPI IcoDecoder_QueryInterface(IWICBitmapDecoder *iface, REFIID iid, void **ppv)
Definition: icoformat.c:440
static HRESULT WINAPI IcoDecoder_GetMetadataQueryReader(IWICBitmapDecoder *iface, IWICMetadataQueryReader **ppIMetadataQueryReader)
Definition: icoformat.c:601
static HRESULT WINAPI IcoDecoder_GetDecoderInfo(IWICBitmapDecoder *iface, IWICBitmapDecoderInfo **ppIDecoderInfo)
Definition: icoformat.c:586
static HRESULT WINAPI IcoDecoder_QueryCapability(IWICBitmapDecoder *iface, IStream *stream, DWORD *capability)
Definition: icoformat.c:491
static HRESULT WINAPI IcoDecoder_Initialize(IWICBitmapDecoder *iface, IStream *pIStream, WICDecodeOptions cacheOptions)
Definition: icoformat.c:507
static HRESULT WINAPI IcoDecoder_GetFrame(IWICBitmapDecoder *iface, UINT index, IWICBitmapFrameDecode **ppIBitmapFrame)
Definition: icoformat.c:645
static HRESULT WINAPI IcoDecoder_GetFrameCount(IWICBitmapDecoder *iface, UINT *pCount)
Definition: icoformat.c:629

Definition at line 742 of file icoformat.c.

Referenced by IcoDecoder_CreateInstance().

◆ IcoFrameDecode_Vtbl

const IWICBitmapFrameDecodeVtbl IcoFrameDecode_Vtbl
static
Initial value:
= {
}
static HRESULT WINAPI IcoFrameDecode_GetPixelFormat(IWICBitmapFrameDecode *iface, WICPixelFormatGUID *pPixelFormat)
Definition: icoformat.c:148
static HRESULT WINAPI IcoFrameDecode_GetResolution(IWICBitmapFrameDecode *iface, double *pDpiX, double *pDpiY)
Definition: icoformat.c:155
static HRESULT WINAPI IcoFrameDecode_CopyPalette(IWICBitmapFrameDecode *iface, IWICPalette *pIPalette)
Definition: icoformat.c:168
static HRESULT WINAPI IcoFrameDecode_GetMetadataQueryReader(IWICBitmapFrameDecode *iface, IWICMetadataQueryReader **ppIMetadataQueryReader)
Definition: icoformat.c:185
static HRESULT WINAPI IcoFrameDecode_GetColorContexts(IWICBitmapFrameDecode *iface, UINT cCount, IWICColorContext **ppIColorContexts, UINT *pcActualCount)
Definition: icoformat.c:192
static HRESULT WINAPI IcoFrameDecode_QueryInterface(IWICBitmapFrameDecode *iface, REFIID iid, void **ppv)
Definition: icoformat.c:85
static HRESULT WINAPI IcoFrameDecode_GetSize(IWICBitmapFrameDecode *iface, UINT *puiWidth, UINT *puiHeight)
Definition: icoformat.c:135
static ULONG WINAPI IcoFrameDecode_Release(IWICBitmapFrameDecode *iface)
Definition: icoformat.c:119
static ULONG WINAPI IcoFrameDecode_AddRef(IWICBitmapFrameDecode *iface)
Definition: icoformat.c:109
static HRESULT WINAPI IcoFrameDecode_GetThumbnail(IWICBitmapFrameDecode *iface, IWICBitmapSource **ppIThumbnail)
Definition: icoformat.c:199
static HRESULT WINAPI IcoFrameDecode_CopyPixels(IWICBitmapFrameDecode *iface, const WICRect *prc, UINT cbStride, UINT cbBufferSize, BYTE *pbBuffer)
Definition: icoformat.c:175

Definition at line 206 of file icoformat.c.

Referenced by IcoDecoder_GetFrame().