ReactOS 0.4.16-dev-755-g88f105e
icoformat.c File Reference
#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 21 of file icoformat.c.

Function Documentation

◆ IcoDecoder_AddRef()

static ULONG WINAPI IcoDecoder_AddRef ( IWICBitmapDecoder iface)
static

Definition at line 461 of file icoformat.c.

462{
465
466 TRACE("(%p) refcount=%lu\n", iface, ref);
467
468 return ref;
469}
#define InterlockedIncrement
Definition: armddk.h:53
static IcoDecoder * impl_from_IWICBitmapDecoder(IWICBitmapDecoder *iface)
Definition: icoformat.c:73
#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 592 of file icoformat.c.

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

◆ IcoDecoder_CreateInstance()

HRESULT IcoDecoder_CreateInstance ( REFIID  iid,
void **  ppv 
)

Definition at line 757 of file icoformat.c.

758{
760 HRESULT ret;
761
762 TRACE("(%s,%p)\n", debugstr_guid(iid), ppv);
763
764 *ppv = NULL;
765
766 This = malloc(sizeof(IcoDecoder));
767 if (!This) return E_OUTOFMEMORY;
768
769 This->IWICBitmapDecoder_iface.lpVtbl = &IcoDecoder_Vtbl;
770 This->ref = 1;
771 This->stream = NULL;
772 This->initialized = FALSE;
773#ifdef __REACTOS__
775#else
777#endif
778 This->lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": IcoDecoder.lock");
779
780 ret = IWICBitmapDecoder_QueryInterface(&This->IWICBitmapDecoder_iface, iid, ppv);
781 IWICBitmapDecoder_Release(&This->IWICBitmapDecoder_iface);
782
783 return ret;
784}
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define malloc
Definition: debug_ros.c:4
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
BOOL WINAPI InitializeCriticalSectionEx(OUT LPCRITICAL_SECTION lpCriticalSection, IN DWORD dwSpinCount, IN DWORD flags)
Definition: sync.c:107
static const IWICBitmapDecoderVtbl IcoDecoder_Vtbl
Definition: icoformat.c:740
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
#define RTL_CRITICAL_SECTION_FLAG_FORCE_DEBUG_INFO
Definition: winnt_old.h:1118

◆ IcoDecoder_GetColorContexts()

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

Definition at line 613 of file icoformat.c.

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

◆ IcoDecoder_GetContainerFormat()

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

Definition at line 577 of file icoformat.c.

579{
580 memcpy(pguidContainerFormat, &GUID_ContainerFormatIco, sizeof(GUID));
581 return S_OK;
582}
#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 584 of file icoformat.c.

586{
587 TRACE("(%p,%p)\n", iface, ppIDecoderInfo);
588
589 return get_decoder_info(&CLSID_WICIcoDecoder, ppIDecoderInfo);
590}
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 643 of file icoformat.c.

645{
650 HRESULT hr;
651 ULONG bytesread;
653 IWICStream *substream=NULL;
654 DWORD magic;
655 TRACE("(%p,%u,%p)\n", iface, index, ppIBitmapFrame);
656
658
659 if (!This->initialized)
660 {
662 goto fail;
663 }
664
665 if (This->header.idCount < index)
666 {
668 goto fail;
669 }
670
671 result = malloc(sizeof(IcoFrameDecode));
672 if (!result)
673 {
675 goto fail;
676 }
677
678 result->IWICBitmapFrameDecode_iface.lpVtbl = &IcoFrameDecode_Vtbl;
679 result->ref = 1;
680 result->bits = NULL;
681
682 /* read the icon entry */
683 seek.QuadPart = sizeof(ICONHEADER) + sizeof(ICONDIRENTRY) * index;
684 hr = IStream_Seek(This->stream, seek, STREAM_SEEK_SET, 0);
685 if (FAILED(hr)) goto fail;
686
687 hr = IStream_Read(This->stream, &entry, sizeof(ICONDIRENTRY), &bytesread);
688 if (FAILED(hr) || bytesread != sizeof(ICONDIRENTRY)) goto fail;
689
690 /* create a stream object for this icon */
691 hr = StreamImpl_Create(&substream);
692 if (FAILED(hr)) goto fail;
693
694 offset.QuadPart = entry.dwDIBOffset;
695 length.QuadPart = entry.dwDIBSize;
696 hr = IWICStream_InitializeFromIStreamRegion(substream, This->stream, offset, length);
697 if (FAILED(hr)) goto fail;
698
699 /* read the bitmapinfo size or magic number */
700 hr = IWICStream_Read(substream, &magic, sizeof(magic), &bytesread);
701 if (FAILED(hr) || bytesread != sizeof(magic)) goto fail;
702
703 /* forward to the appropriate decoding function based on the magic number */
704 switch (magic)
705 {
706 case sizeof(BITMAPCOREHEADER):
707 case 64: /* sizeof(BITMAPCOREHEADER2) */
708 case sizeof(BITMAPINFOHEADER):
709 case sizeof(BITMAPV4HEADER):
710 case sizeof(BITMAPV5HEADER):
711 hr = ReadIcoDib((IStream*)substream, result);
712 break;
713 case 0x474e5089:
714 hr = ReadIcoPng((IStream*)substream, result);
715 break;
716 default:
717 FIXME("Unrecognized ICO frame magic: %lx\n", magic);
718 hr = E_FAIL;
719 break;
720 }
721 if (FAILED(hr)) goto fail;
722
723 *ppIBitmapFrame = &result->IWICBitmapFrameDecode_iface;
724
726
727 IWICStream_Release(substream);
728
729 return S_OK;
730
731fail:
733 free(result);
734 if (substream) IWICStream_Release(substream);
735 if (SUCCEEDED(hr)) hr = E_FAIL;
736 TRACE("<-- %lx\n", hr);
737 return hr;
738}
#define index(s, c)
Definition: various.h:29
#define FIXME(fmt,...)
Definition: precomp.h:53
#define E_INVALIDARG
Definition: ddrawi.h:101
#define E_FAIL
Definition: ddrawi.h:102
#define free
Definition: debug_ros.c:5
static HRESULT ReadIcoDib(IStream *stream, IcoFrameDecode *result)
Definition: icoformat.c:224
static const IWICBitmapFrameDecodeVtbl IcoFrameDecode_Vtbl
Definition: icoformat.c:204
static HRESULT ReadIcoPng(IStream *stream, IcoFrameDecode *result)
Definition: icoformat.c:389
HRESULT StreamImpl_Create(IWICStream **stream)
Definition: stream.c:1158
unsigned long DWORD
Definition: ntddk_ex.h:95
GLintptr offset
Definition: glext.h:5920
GLuint index
Definition: glext.h:6031
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
GLuint64EXT * result
Definition: glext.h:11304
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define FAILED(hr)
Definition: intsafe.h:51
uint32_t entry
Definition: isohybrid.c:63
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 627 of file icoformat.c.

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

◆ IcoDecoder_GetMetadataQueryReader()

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

Definition at line 599 of file icoformat.c.

601{
602 TRACE("(%p,%p)\n", iface, ppIMetadataQueryReader);
604}

◆ IcoDecoder_GetPreview()

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

Definition at line 606 of file icoformat.c.

608{
609 TRACE("(%p,%p)\n", iface, ppIBitmapSource);
611}

◆ IcoDecoder_GetThumbnail()

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

Definition at line 620 of file icoformat.c.

622{
623 TRACE("(%p,%p)\n", iface, ppIThumbnail);
625}
#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 505 of file icoformat.c.

507{
510 HRESULT hr;
511 ULONG bytesread;
512 STATSTG statstg;
513 unsigned int i;
514
515 TRACE("(%p,%p,%x)\n", iface, pIStream, cacheOptions);
516
518
519 if (This->initialized)
520 {
522 goto end;
523 }
524
525 seek.QuadPart = 0;
526 hr = IStream_Seek(pIStream, seek, STREAM_SEEK_SET, NULL);
527 if (FAILED(hr)) goto end;
528
529 hr = IStream_Read(pIStream, &This->header, sizeof(ICONHEADER), &bytesread);
530 if (FAILED(hr)) goto end;
531
532 if (bytesread != sizeof(ICONHEADER))
533 {
535 goto end;
536 }
537
538 if (This->header.idReserved != 0 ||
539 This->header.idType != 1)
540 {
541 hr = E_FAIL;
542 goto end;
543 }
544
545 hr = IStream_Stat(pIStream, &statstg, STATFLAG_NONAME);
546 if (FAILED(hr))
547 {
548 WARN("Stat() failed, hr %#lx.\n", hr);
549 goto end;
550 }
551
552 for (i = 0; i < This->header.idCount; i++)
553 {
554 ICONDIRENTRY direntry;
555
556 hr = IStream_Read(pIStream, &direntry, sizeof(direntry), &bytesread);
557 if (FAILED(hr)) goto end;
558
559 if (bytesread != sizeof(direntry) || (direntry.dwDIBSize + direntry.dwDIBOffset > statstg.cbSize.QuadPart))
560 {
562 goto end;
563 }
564 }
565
566 This->initialized = TRUE;
567 This->stream = pIStream;
568 IStream_AddRef(pIStream);
569
570end:
571
573
574 return hr;
575}
#define WARN(fmt,...)
Definition: precomp.h:61
#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:43
DWORD dwDIBOffset
Definition: icoformat.c:44
#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 489 of file icoformat.c.

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

◆ IcoDecoder_QueryInterface()

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

Definition at line 438 of file icoformat.c.

440{
442 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
443
444 if (!ppv) return E_INVALIDARG;
445
446 if (IsEqualIID(&IID_IUnknown, iid) ||
447 IsEqualIID(&IID_IWICBitmapDecoder, iid))
448 {
449 *ppv = &This->IWICBitmapDecoder_iface;
450 }
451 else
452 {
453 *ppv = NULL;
454 return E_NOINTERFACE;
455 }
456
457 IUnknown_AddRef((IUnknown*)*ppv);
458 return S_OK;
459}
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 471 of file icoformat.c.

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

◆ IcoFrameDecode_AddRef()

static ULONG WINAPI IcoFrameDecode_AddRef ( IWICBitmapFrameDecode iface)
static

Definition at line 107 of file icoformat.c.

108{
111
112 TRACE("(%p) refcount=%lu\n", iface, ref);
113
114 return ref;
115}
static IcoFrameDecode * impl_from_IWICBitmapFrameDecode(IWICBitmapFrameDecode *iface)
Definition: icoformat.c:78

◆ IcoFrameDecode_CopyPalette()

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

Definition at line 166 of file icoformat.c.

168{
169 TRACE("(%p,%p)\n", iface, pIPalette);
171}

◆ IcoFrameDecode_CopyPixels()

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

Definition at line 173 of file icoformat.c.

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

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

◆ IcoFrameDecode_GetMetadataQueryReader()

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

Definition at line 183 of file icoformat.c.

185{
186 TRACE("(%p,%p)\n", iface, ppIMetadataQueryReader);
188}

◆ IcoFrameDecode_GetPixelFormat()

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

Definition at line 146 of file icoformat.c.

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

◆ IcoFrameDecode_GetResolution()

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

Definition at line 153 of file icoformat.c.

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

◆ IcoFrameDecode_GetSize()

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

Definition at line 133 of file icoformat.c.

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

◆ IcoFrameDecode_GetThumbnail()

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

Definition at line 197 of file icoformat.c.

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

◆ IcoFrameDecode_QueryInterface()

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

Definition at line 83 of file icoformat.c.

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

◆ IcoFrameDecode_Release()

static ULONG WINAPI IcoFrameDecode_Release ( IWICBitmapFrameDecode iface)
static

Definition at line 117 of file icoformat.c.

118{
121
122 TRACE("(%p) refcount=%lu\n", iface, ref);
123
124 if (ref == 0)
125 {
126 free(This->bits);
127 free(This);
128 }
129
130 return ref;
131}

◆ impl_from_IWICBitmapDecoder()

static IcoDecoder * impl_from_IWICBitmapDecoder ( IWICBitmapDecoder iface)
inlinestatic

Definition at line 73 of file icoformat.c.

74{
75 return CONTAINING_RECORD(iface, IcoDecoder, IWICBitmapDecoder_iface);
76}
#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 218 of file icoformat.c.

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

Referenced by ReadIcoDib().

◆ ReadIcoDib()

static HRESULT ReadIcoDib ( IStream stream,
IcoFrameDecode result 
)
static

Definition at line 224 of file icoformat.c.

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

Referenced by IcoDecoder_GetFrame().

◆ ReadIcoPng()

static HRESULT ReadIcoPng ( IStream stream,
IcoFrameDecode result 
)
static

Definition at line 389 of file icoformat.c.

390{
392 IWICBitmapFrameDecode *sourceFrame = NULL;
393 IWICBitmapSource *sourceBitmap = NULL;
395 HRESULT hr;
396
397 hr = PngDecoder_CreateInstance(&IID_IWICBitmapDecoder, (void**)&decoder);
398 if (FAILED(hr))
399 goto end;
400 hr = IWICBitmapDecoder_Initialize(decoder, stream, WICDecodeMetadataCacheOnLoad);
401 if (FAILED(hr))
402 goto end;
403 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &sourceFrame);
404 if (FAILED(hr))
405 goto end;
406 hr = WICConvertBitmapSource(&GUID_WICPixelFormat32bppBGRA, (IWICBitmapSource*)sourceFrame, &sourceBitmap);
407 if (FAILED(hr))
408 goto end;
409 hr = IWICBitmapFrameDecode_GetSize(sourceFrame, &result->width, &result->height);
410 if (FAILED(hr))
411 goto end;
412 hr = IWICBitmapFrameDecode_GetResolution(sourceFrame, &result->dpiX, &result->dpiY);
413 if (FAILED(hr))
414 goto end;
415 result->bits = malloc(4 * result->width * result->height);
416 if (result->bits == NULL)
417 {
419 goto end;
420 }
421 rect.X = 0;
422 rect.Y = 0;
423 rect.Width = result->width;
424 rect.Height = result->height;
425 hr = IWICBitmapSource_CopyPixels(sourceBitmap, &rect, 4*result->width,
426 4*result->width*result->height, result->bits);
427
428end:
429 if (decoder != NULL)
430 IWICBitmapDecoder_Release(decoder);
431 if (sourceFrame != NULL)
432 IWICBitmapFrameDecode_Release(sourceFrame);
433 if (sourceBitmap != NULL)
434 IWICBitmapSource_Release(sourceBitmap);
435 return hr;
436}
HRESULT PngDecoder_CreateInstance(REFIID iid, void **ppv)
Definition: pngformat.c:399
& 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:592
static HRESULT WINAPI IcoDecoder_GetContainerFormat(IWICBitmapDecoder *iface, GUID *pguidContainerFormat)
Definition: icoformat.c:577
static HRESULT WINAPI IcoDecoder_GetThumbnail(IWICBitmapDecoder *iface, IWICBitmapSource **ppIThumbnail)
Definition: icoformat.c:620
static HRESULT WINAPI IcoDecoder_GetPreview(IWICBitmapDecoder *iface, IWICBitmapSource **ppIBitmapSource)
Definition: icoformat.c:606
static ULONG WINAPI IcoDecoder_AddRef(IWICBitmapDecoder *iface)
Definition: icoformat.c:461
static HRESULT WINAPI IcoDecoder_GetColorContexts(IWICBitmapDecoder *iface, UINT cCount, IWICColorContext **ppIColorContexts, UINT *pcActualCount)
Definition: icoformat.c:613
static ULONG WINAPI IcoDecoder_Release(IWICBitmapDecoder *iface)
Definition: icoformat.c:471
static HRESULT WINAPI IcoDecoder_QueryInterface(IWICBitmapDecoder *iface, REFIID iid, void **ppv)
Definition: icoformat.c:438
static HRESULT WINAPI IcoDecoder_GetMetadataQueryReader(IWICBitmapDecoder *iface, IWICMetadataQueryReader **ppIMetadataQueryReader)
Definition: icoformat.c:599
static HRESULT WINAPI IcoDecoder_GetDecoderInfo(IWICBitmapDecoder *iface, IWICBitmapDecoderInfo **ppIDecoderInfo)
Definition: icoformat.c:584
static HRESULT WINAPI IcoDecoder_QueryCapability(IWICBitmapDecoder *iface, IStream *stream, DWORD *capability)
Definition: icoformat.c:489
static HRESULT WINAPI IcoDecoder_Initialize(IWICBitmapDecoder *iface, IStream *pIStream, WICDecodeOptions cacheOptions)
Definition: icoformat.c:505
static HRESULT WINAPI IcoDecoder_GetFrame(IWICBitmapDecoder *iface, UINT index, IWICBitmapFrameDecode **ppIBitmapFrame)
Definition: icoformat.c:643
static HRESULT WINAPI IcoDecoder_GetFrameCount(IWICBitmapDecoder *iface, UINT *pCount)
Definition: icoformat.c:627

Definition at line 740 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:146
static HRESULT WINAPI IcoFrameDecode_GetResolution(IWICBitmapFrameDecode *iface, double *pDpiX, double *pDpiY)
Definition: icoformat.c:153
static HRESULT WINAPI IcoFrameDecode_CopyPalette(IWICBitmapFrameDecode *iface, IWICPalette *pIPalette)
Definition: icoformat.c:166
static HRESULT WINAPI IcoFrameDecode_GetMetadataQueryReader(IWICBitmapFrameDecode *iface, IWICMetadataQueryReader **ppIMetadataQueryReader)
Definition: icoformat.c:183
static HRESULT WINAPI IcoFrameDecode_GetColorContexts(IWICBitmapFrameDecode *iface, UINT cCount, IWICColorContext **ppIColorContexts, UINT *pcActualCount)
Definition: icoformat.c:190
static HRESULT WINAPI IcoFrameDecode_QueryInterface(IWICBitmapFrameDecode *iface, REFIID iid, void **ppv)
Definition: icoformat.c:83
static HRESULT WINAPI IcoFrameDecode_GetSize(IWICBitmapFrameDecode *iface, UINT *puiWidth, UINT *puiHeight)
Definition: icoformat.c:133
static ULONG WINAPI IcoFrameDecode_Release(IWICBitmapFrameDecode *iface)
Definition: icoformat.c:117
static ULONG WINAPI IcoFrameDecode_AddRef(IWICBitmapFrameDecode *iface)
Definition: icoformat.c:107
static HRESULT WINAPI IcoFrameDecode_GetThumbnail(IWICBitmapFrameDecode *iface, IWICBitmapSource **ppIThumbnail)
Definition: icoformat.c:197
static HRESULT WINAPI IcoFrameDecode_CopyPixels(IWICBitmapFrameDecode *iface, const WICRect *prc, UINT cbStride, UINT cbBufferSize, BYTE *pbBuffer)
Definition: icoformat.c:173

Definition at line 204 of file icoformat.c.

Referenced by IcoDecoder_GetFrame().