- Sync windowscodecs with Wine 1.1.29

svn path=/trunk/; revision=42986
This commit is contained in:
Dmitry Chapyshev 2009-09-03 14:54:19 +00:00
parent 509c6dadc2
commit 953707a174
11 changed files with 1619 additions and 19 deletions

View file

@ -333,8 +333,8 @@ static HRESULT WINAPI BmpFrameEncode_Commit(IWICBitmapFrameEncode *iface)
bih.bV5BitCount = This->format->bpp;
bih.bV5Compression = This->format->compression;
bih.bV5SizeImage = This->stride*This->height;
bih.bV5XPelsPerMeter = (This->xres-0.0127) / 0.0254;
bih.bV5YPelsPerMeter = (This->yres-0.0127) / 0.0254;
bih.bV5XPelsPerMeter = (This->xres+0.0127) / 0.0254;
bih.bV5YPelsPerMeter = (This->yres+0.0127) / 0.0254;
bih.bV5ClrUsed = 0;
bih.bV5ClrImportant = 0;

View file

@ -44,9 +44,11 @@ typedef struct {
static classinfo wic_classes[] = {
{&CLSID_WICImagingFactory, ImagingFactory_CreateInstance},
{&CLSID_WICBmpDecoder, BmpDecoder_CreateInstance},
{&CLSID_WICPngDecoder, PngDecoder_CreateInstance},
{&CLSID_WICBmpEncoder, BmpEncoder_CreateInstance},
{&CLSID_WICGifDecoder, GifDecoder_CreateInstance},
{&CLSID_WICIcoDecoder, IcoDecoder_CreateInstance},
{&CLSID_WICJpegDecoder, JpegDecoder_CreateInstance},
{&CLSID_WICDefaultFormatConverter, FormatConverter_CreateInstance},
{0}};

View file

@ -37,13 +37,21 @@ struct FormatConverter;
enum pixelformat {
format_1bppIndexed,
format_2bppIndexed,
format_4bppIndexed,
format_8bppIndexed,
format_BlackWhite,
format_2bppGray,
format_4bppGray,
format_8bppGray,
format_16bppGray,
format_16bppBGR555,
format_16bppBGR565,
format_24bppBGR,
format_32bppBGR,
format_32bppBGRA
format_32bppBGRA,
format_48bppRGB,
format_64bppRGBA,
};
typedef HRESULT (*copyfunc)(struct FormatConverter *This, const WICRect *prc,
@ -65,12 +73,23 @@ typedef struct FormatConverter {
WICBitmapPaletteType palette_type;
} FormatConverter;
static void make_grayscale_palette(WICColor *colors, UINT num_colors)
{
int i, v;
for (i=0; i<num_colors; i++)
{
v = i * 255 / (num_colors-1);
colors[i] = 0xff000000 | v<<16 | v<<8 | v;
}
}
static HRESULT copypixels_to_32bppBGRA(struct FormatConverter *This, const WICRect *prc,
UINT cbStride, UINT cbBufferSize, BYTE *pbBuffer, enum pixelformat source_format)
{
switch (source_format)
{
case format_1bppIndexed:
case format_BlackWhite:
if (prc)
{
HRESULT res;
@ -85,16 +104,24 @@ static HRESULT copypixels_to_32bppBGRA(struct FormatConverter *This, const WICRe
IWICPalette *palette;
UINT actualcolors;
res = PaletteImpl_Create(&palette);
if (FAILED(res)) return res;
if (source_format == format_1bppIndexed)
{
res = PaletteImpl_Create(&palette);
if (FAILED(res)) return res;
res = IWICBitmapSource_CopyPalette(This->source, palette);
if (SUCCEEDED(res))
res = IWICPalette_GetColors(palette, 2, colors, &actualcolors);
res = IWICBitmapSource_CopyPalette(This->source, palette);
if (SUCCEEDED(res))
res = IWICPalette_GetColors(palette, 2, colors, &actualcolors);
IWICPalette_Release(palette);
IWICPalette_Release(palette);
if (FAILED(res)) return res;
if (FAILED(res)) return res;
}
else
{
colors[0] = 0xff000000;
colors[1] = 0xffffffff;
}
srcstride = (prc->Width+7)/8;
srcdatasize = srcstride * prc->Height;
@ -133,7 +160,73 @@ static HRESULT copypixels_to_32bppBGRA(struct FormatConverter *This, const WICRe
return res;
}
return S_OK;
case format_2bppIndexed:
case format_2bppGray:
if (prc)
{
HRESULT res;
UINT x, y;
BYTE *srcdata;
UINT srcstride, srcdatasize;
const BYTE *srcrow;
const BYTE *srcbyte;
BYTE *dstrow;
DWORD *dstpixel;
WICColor colors[4];
IWICPalette *palette;
UINT actualcolors;
if (source_format == format_2bppIndexed)
{
res = PaletteImpl_Create(&palette);
if (FAILED(res)) return res;
res = IWICBitmapSource_CopyPalette(This->source, palette);
if (SUCCEEDED(res))
res = IWICPalette_GetColors(palette, 4, colors, &actualcolors);
IWICPalette_Release(palette);
if (FAILED(res)) return res;
}
else
make_grayscale_palette(colors, 4);
srcstride = (prc->Width+3)/4;
srcdatasize = srcstride * prc->Height;
srcdata = HeapAlloc(GetProcessHeap(), 0, srcdatasize);
if (!srcdata) return E_OUTOFMEMORY;
res = IWICBitmapSource_CopyPixels(This->source, prc, srcstride, srcdatasize, srcdata);
if (SUCCEEDED(res))
{
srcrow = srcdata;
dstrow = pbBuffer;
for (y=0; y<prc->Height; y++) {
srcbyte=(const BYTE*)srcrow;
dstpixel=(DWORD*)dstrow;
for (x=0; x<prc->Width; x+=4) {
BYTE srcval;
srcval=*srcbyte++;
*dstpixel++ = colors[srcval>>6];
if (x+1 < prc->Width) *dstpixel++ = colors[srcval>>4&0x3];
if (x+2 < prc->Width) *dstpixel++ = colors[srcval>>2&0x3];
if (x+1 < prc->Width) *dstpixel++ = colors[srcval&0x3];
}
srcrow += srcstride;
dstrow += cbStride;
}
}
HeapFree(GetProcessHeap(), 0, srcdata);
return res;
}
return S_OK;
case format_4bppIndexed:
case format_4bppGray:
if (prc)
{
HRESULT res;
@ -148,16 +241,21 @@ static HRESULT copypixels_to_32bppBGRA(struct FormatConverter *This, const WICRe
IWICPalette *palette;
UINT actualcolors;
res = PaletteImpl_Create(&palette);
if (FAILED(res)) return res;
if (source_format == format_4bppIndexed)
{
res = PaletteImpl_Create(&palette);
if (FAILED(res)) return res;
res = IWICBitmapSource_CopyPalette(This->source, palette);
if (SUCCEEDED(res))
res = IWICPalette_GetColors(palette, 16, colors, &actualcolors);
res = IWICBitmapSource_CopyPalette(This->source, palette);
if (SUCCEEDED(res))
res = IWICPalette_GetColors(palette, 16, colors, &actualcolors);
IWICPalette_Release(palette);
IWICPalette_Release(palette);
if (FAILED(res)) return res;
if (FAILED(res)) return res;
}
else
make_grayscale_palette(colors, 16);
srcstride = (prc->Width+1)/2;
srcdatasize = srcstride * prc->Height;
@ -190,6 +288,48 @@ static HRESULT copypixels_to_32bppBGRA(struct FormatConverter *This, const WICRe
return res;
}
return S_OK;
case format_8bppGray:
if (prc)
{
HRESULT res;
UINT x, y;
BYTE *srcdata;
UINT srcstride, srcdatasize;
const BYTE *srcrow;
const BYTE *srcbyte;
BYTE *dstrow;
DWORD *dstpixel;
srcstride = prc->Width;
srcdatasize = srcstride * prc->Height;
srcdata = HeapAlloc(GetProcessHeap(), 0, srcdatasize);
if (!srcdata) return E_OUTOFMEMORY;
res = IWICBitmapSource_CopyPixels(This->source, prc, srcstride, srcdatasize, srcdata);
if (SUCCEEDED(res))
{
srcrow = srcdata;
dstrow = pbBuffer;
for (y=0; y<prc->Height; y++) {
srcbyte=(const BYTE*)srcrow;
dstpixel=(DWORD*)dstrow;
for (x=0; x<prc->Width; x++)
{
*dstpixel++ = 0xff000000|(*srcbyte<<16)|(*srcbyte<<8)|*srcbyte;
srcbyte++;
}
srcrow += srcstride;
dstrow += cbStride;
}
}
HeapFree(GetProcessHeap(), 0, srcdata);
return res;
}
return S_OK;
case format_8bppIndexed:
if (prc)
{
@ -243,6 +383,48 @@ static HRESULT copypixels_to_32bppBGRA(struct FormatConverter *This, const WICRe
return res;
}
return S_OK;
case format_16bppGray:
if (prc)
{
HRESULT res;
UINT x, y;
BYTE *srcdata;
UINT srcstride, srcdatasize;
const BYTE *srcrow;
const BYTE *srcbyte;
BYTE *dstrow;
DWORD *dstpixel;
srcstride = prc->Width * 2;
srcdatasize = srcstride * prc->Height;
srcdata = HeapAlloc(GetProcessHeap(), 0, srcdatasize);
if (!srcdata) return E_OUTOFMEMORY;
res = IWICBitmapSource_CopyPixels(This->source, prc, srcstride, srcdatasize, srcdata);
if (SUCCEEDED(res))
{
srcrow = srcdata;
dstrow = pbBuffer;
for (y=0; y<prc->Height; y++) {
srcbyte=(const BYTE*)srcrow;
dstpixel=(DWORD*)dstrow;
for (x=0; x<prc->Width; x++)
{
*dstpixel++ = 0xff000000|(*srcbyte<<16)|(*srcbyte<<8)|*srcbyte;
srcbyte+=2;
}
srcrow += srcstride;
dstrow += cbStride;
}
}
HeapFree(GetProcessHeap(), 0, srcdata);
return res;
}
return S_OK;
case format_16bppBGR555:
if (prc)
{
@ -401,6 +583,95 @@ static HRESULT copypixels_to_32bppBGRA(struct FormatConverter *This, const WICRe
if (prc)
return IWICBitmapSource_CopyPixels(This->source, prc, cbStride, cbBufferSize, pbBuffer);
return S_OK;
case format_48bppRGB:
if (prc)
{
HRESULT res;
UINT x, y;
BYTE *srcdata;
UINT srcstride, srcdatasize;
const BYTE *srcrow;
const BYTE *srcpixel;
BYTE *dstrow;
DWORD *dstpixel;
srcstride = 6 * prc->Width;
srcdatasize = srcstride * prc->Height;
srcdata = HeapAlloc(GetProcessHeap(), 0, srcdatasize);
if (!srcdata) return E_OUTOFMEMORY;
res = IWICBitmapSource_CopyPixels(This->source, prc, srcstride, srcdatasize, srcdata);
if (SUCCEEDED(res))
{
srcrow = srcdata;
dstrow = pbBuffer;
for (y=0; y<prc->Height; y++) {
srcpixel=srcrow;
dstpixel=(DWORD*)dstrow;
for (x=0; x<prc->Width; x++) {
BYTE red, green, blue;
red = *srcpixel++; srcpixel++;
green = *srcpixel++; srcpixel++;
blue = *srcpixel++; srcpixel++;
*dstpixel++=0xff000000|red<<16|green<<8|blue;
}
srcrow += srcstride;
dstrow += cbStride;
}
}
HeapFree(GetProcessHeap(), 0, srcdata);
return res;
}
return S_OK;
case format_64bppRGBA:
if (prc)
{
HRESULT res;
UINT x, y;
BYTE *srcdata;
UINT srcstride, srcdatasize;
const BYTE *srcrow;
const BYTE *srcpixel;
BYTE *dstrow;
DWORD *dstpixel;
srcstride = 8 * prc->Width;
srcdatasize = srcstride * prc->Height;
srcdata = HeapAlloc(GetProcessHeap(), 0, srcdatasize);
if (!srcdata) return E_OUTOFMEMORY;
res = IWICBitmapSource_CopyPixels(This->source, prc, srcstride, srcdatasize, srcdata);
if (SUCCEEDED(res))
{
srcrow = srcdata;
dstrow = pbBuffer;
for (y=0; y<prc->Height; y++) {
srcpixel=srcrow;
dstpixel=(DWORD*)dstrow;
for (x=0; x<prc->Width; x++) {
BYTE red, green, blue, alpha;
red = *srcpixel++; srcpixel++;
green = *srcpixel++; srcpixel++;
blue = *srcpixel++; srcpixel++;
alpha = *srcpixel++; srcpixel++;
*dstpixel++=alpha<<24|red<<16|green<<8|blue;
}
srcrow += srcstride;
dstrow += cbStride;
}
}
HeapFree(GetProcessHeap(), 0, srcdata);
return res;
}
return S_OK;
default:
return WINCODEC_ERR_UNSUPPORTEDOPERATION;
}
@ -423,13 +694,21 @@ static HRESULT copypixels_to_32bppBGR(struct FormatConverter *This, const WICRec
static const struct pixelformatinfo supported_formats[] = {
{format_1bppIndexed, &GUID_WICPixelFormat1bppIndexed, NULL},
{format_2bppIndexed, &GUID_WICPixelFormat2bppIndexed, NULL},
{format_4bppIndexed, &GUID_WICPixelFormat4bppIndexed, NULL},
{format_8bppIndexed, &GUID_WICPixelFormat8bppIndexed, NULL},
{format_BlackWhite, &GUID_WICPixelFormatBlackWhite, NULL},
{format_2bppGray, &GUID_WICPixelFormat2bppGray, NULL},
{format_4bppGray, &GUID_WICPixelFormat4bppGray, NULL},
{format_8bppGray, &GUID_WICPixelFormat8bppGray, NULL},
{format_16bppGray, &GUID_WICPixelFormat16bppGray, NULL},
{format_16bppBGR555, &GUID_WICPixelFormat16bppBGR555, NULL},
{format_16bppBGR565, &GUID_WICPixelFormat16bppBGR565, NULL},
{format_24bppBGR, &GUID_WICPixelFormat24bppBGR, NULL},
{format_32bppBGR, &GUID_WICPixelFormat32bppBGR, copypixels_to_32bppBGR},
{format_32bppBGRA, &GUID_WICPixelFormat32bppBGRA, copypixels_to_32bppBGRA},
{format_48bppRGB, &GUID_WICPixelFormat48bppRGB, NULL},
{format_64bppRGBA, &GUID_WICPixelFormat64bppRGBA, NULL},
{0}
};

View file

@ -1064,6 +1064,7 @@ HRESULT WINAPI WICConvertBitmapSource(REFWICPixelFormatGUID dstFormat, IWICBitma
}
else
{
FIXME("cannot convert %s to %s\n", debugstr_guid(&srcFormat), debugstr_guid(dstFormat));
*ppIDst = NULL;
return WINCODEC_ERR_COMPONENTNOTFOUND;
}

View file

@ -0,0 +1,577 @@
/*
* Copyright 2009 Vincent Povirk for CodeWeavers
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "config.h"
#include "wine/port.h"
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#ifdef SONAME_LIBJPEG
/* This is a hack, so jpeglib.h does not redefine INT32 and the like*/
#define XMD_H
#define UINT8 JPEG_UINT8
#define UINT16 JPEG_UINT16
#define boolean jpeg_boolean
#undef HAVE_STDLIB_H
# include <jpeglib.h>
#undef HAVE_STDLIB_H
#define HAVE_STDLIB_H 1
#undef UINT8
#undef UINT16
#undef boolean
#endif
#define COBJMACROS
#include "windef.h"
#include "winbase.h"
#include "objbase.h"
#include "wincodec.h"
#include "wincodecs_private.h"
#include "wine/debug.h"
#include "wine/library.h"
WINE_DEFAULT_DEBUG_CHANNEL(wincodecs);
#ifdef SONAME_LIBJPEG
static void *libjpeg_handle;
#define MAKE_FUNCPTR(f) static typeof(f) * p##f
MAKE_FUNCPTR(jpeg_CreateDecompress);
MAKE_FUNCPTR(jpeg_destroy_decompress);
MAKE_FUNCPTR(jpeg_read_header);
MAKE_FUNCPTR(jpeg_read_scanlines);
MAKE_FUNCPTR(jpeg_resync_to_restart);
MAKE_FUNCPTR(jpeg_start_decompress);
MAKE_FUNCPTR(jpeg_std_error);
#undef MAKE_FUNCPTR
static void *load_libjpeg(void)
{
if((libjpeg_handle = wine_dlopen(SONAME_LIBJPEG, RTLD_NOW, NULL, 0)) != NULL) {
#define LOAD_FUNCPTR(f) \
if((p##f = wine_dlsym(libjpeg_handle, #f, NULL, 0)) == NULL) { \
libjpeg_handle = NULL; \
return NULL; \
}
LOAD_FUNCPTR(jpeg_CreateDecompress);
LOAD_FUNCPTR(jpeg_destroy_decompress);
LOAD_FUNCPTR(jpeg_read_header);
LOAD_FUNCPTR(jpeg_read_scanlines);
LOAD_FUNCPTR(jpeg_resync_to_restart);
LOAD_FUNCPTR(jpeg_start_decompress);
LOAD_FUNCPTR(jpeg_std_error);
#undef LOAD_FUNCPTR
}
return libjpeg_handle;
}
typedef struct {
const IWICBitmapDecoderVtbl *lpVtbl;
const IWICBitmapFrameDecodeVtbl *lpFrameVtbl;
LONG ref;
BOOL initialized;
BOOL cinfo_initialized;
IStream *stream;
struct jpeg_decompress_struct cinfo;
struct jpeg_error_mgr jerr;
struct jpeg_source_mgr source_mgr;
BYTE source_buffer[1024];
BYTE *image_data;
} JpegDecoder;
static inline JpegDecoder *decoder_from_decompress(j_decompress_ptr decompress)
{
return CONTAINING_RECORD(decompress, JpegDecoder, cinfo);
}
static inline JpegDecoder *decoder_from_frame(IWICBitmapFrameDecode *iface)
{
return CONTAINING_RECORD(iface, JpegDecoder, lpFrameVtbl);
}
static HRESULT WINAPI JpegDecoder_QueryInterface(IWICBitmapDecoder *iface, REFIID iid,
void **ppv)
{
JpegDecoder *This = (JpegDecoder*)iface;
TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
if (!ppv) return E_INVALIDARG;
if (IsEqualIID(&IID_IUnknown, iid) || IsEqualIID(&IID_IWICBitmapDecoder, iid))
{
*ppv = This;
}
else
{
*ppv = NULL;
return E_NOINTERFACE;
}
IUnknown_AddRef((IUnknown*)*ppv);
return S_OK;
}
static ULONG WINAPI JpegDecoder_AddRef(IWICBitmapDecoder *iface)
{
JpegDecoder *This = (JpegDecoder*)iface;
ULONG ref = InterlockedIncrement(&This->ref);
TRACE("(%p) refcount=%u\n", iface, ref);
return ref;
}
static ULONG WINAPI JpegDecoder_Release(IWICBitmapDecoder *iface)
{
JpegDecoder *This = (JpegDecoder*)iface;
ULONG ref = InterlockedDecrement(&This->ref);
TRACE("(%p) refcount=%u\n", iface, ref);
if (ref == 0)
{
if (This->cinfo_initialized) pjpeg_destroy_decompress(&This->cinfo);
if (This->stream) IStream_Release(This->stream);
HeapFree(GetProcessHeap(), 0, This->image_data);
HeapFree(GetProcessHeap(), 0, This);
}
return ref;
}
static HRESULT WINAPI JpegDecoder_QueryCapability(IWICBitmapDecoder *iface, IStream *pIStream,
DWORD *pdwCapability)
{
FIXME("(%p,%p,%p): stub\n", iface, pIStream, pdwCapability);
return E_NOTIMPL;
}
static void source_mgr_init_source(j_decompress_ptr cinfo)
{
}
static jpeg_boolean source_mgr_fill_input_buffer(j_decompress_ptr cinfo)
{
JpegDecoder *This = decoder_from_decompress(cinfo);
HRESULT hr;
ULONG bytesread;
hr = IStream_Read(This->stream, This->source_buffer, 1024, &bytesread);
if (hr != S_OK || bytesread == 0)
{
return FALSE;
}
else
{
This->source_mgr.next_input_byte = This->source_buffer;
This->source_mgr.bytes_in_buffer = bytesread;
return TRUE;
}
}
static void source_mgr_skip_input_data(j_decompress_ptr cinfo, long num_bytes)
{
JpegDecoder *This = decoder_from_decompress(cinfo);
LARGE_INTEGER seek;
if (num_bytes > This->source_mgr.bytes_in_buffer)
{
seek.QuadPart = num_bytes - This->source_mgr.bytes_in_buffer;
IStream_Seek(This->stream, seek, STREAM_SEEK_CUR, NULL);
This->source_mgr.bytes_in_buffer = 0;
}
else if (num_bytes > 0)
{
This->source_mgr.next_input_byte += num_bytes;
This->source_mgr.bytes_in_buffer -= num_bytes;
}
}
static void source_mgr_term_source(j_decompress_ptr cinfo)
{
}
static HRESULT WINAPI JpegDecoder_Initialize(IWICBitmapDecoder *iface, IStream *pIStream,
WICDecodeOptions cacheOptions)
{
JpegDecoder *This = (JpegDecoder*)iface;
int ret;
TRACE("(%p,%p,%u)\n", iface, pIStream, cacheOptions);
if (This->cinfo_initialized) return WINCODEC_ERR_WRONGSTATE;
This->cinfo.err = pjpeg_std_error(&This->jerr);
pjpeg_CreateDecompress(&This->cinfo, JPEG_LIB_VERSION, sizeof(struct jpeg_decompress_struct));
This->cinfo_initialized = TRUE;
This->stream = pIStream;
IStream_AddRef(pIStream);
This->source_mgr.bytes_in_buffer = 0;
This->source_mgr.init_source = source_mgr_init_source;
This->source_mgr.fill_input_buffer = source_mgr_fill_input_buffer;
This->source_mgr.skip_input_data = source_mgr_skip_input_data;
This->source_mgr.resync_to_restart = pjpeg_resync_to_restart;
This->source_mgr.term_source = source_mgr_term_source;
This->cinfo.src = &This->source_mgr;
ret = pjpeg_read_header(&This->cinfo, TRUE);
if (ret != JPEG_HEADER_OK) {
WARN("Jpeg image in stream has bad format, read header returned %d.\n",ret);
return E_FAIL;
}
if (This->cinfo.jpeg_color_space == JCS_GRAYSCALE)
This->cinfo.out_color_space = JCS_GRAYSCALE;
else
This->cinfo.out_color_space = JCS_RGB;
if (!pjpeg_start_decompress(&This->cinfo))
{
ERR("jpeg_start_decompress failed\n");
return E_FAIL;
}
This->initialized = TRUE;
return S_OK;
}
static HRESULT WINAPI JpegDecoder_GetContainerFormat(IWICBitmapDecoder *iface,
GUID *pguidContainerFormat)
{
memcpy(pguidContainerFormat, &GUID_ContainerFormatJpeg, sizeof(GUID));
return S_OK;
}
static HRESULT WINAPI JpegDecoder_GetDecoderInfo(IWICBitmapDecoder *iface,
IWICBitmapDecoderInfo **ppIDecoderInfo)
{
FIXME("(%p,%p): stub\n", iface, ppIDecoderInfo);
return E_NOTIMPL;
}
static HRESULT WINAPI JpegDecoder_CopyPalette(IWICBitmapDecoder *iface,
IWICPalette *pIPalette)
{
TRACE("(%p,%p)\n", iface, pIPalette);
return WINCODEC_ERR_PALETTEUNAVAILABLE;
}
static HRESULT WINAPI JpegDecoder_GetMetadataQueryReader(IWICBitmapDecoder *iface,
IWICMetadataQueryReader **ppIMetadataQueryReader)
{
FIXME("(%p,%p): stub\n", iface, ppIMetadataQueryReader);
return E_NOTIMPL;
}
static HRESULT WINAPI JpegDecoder_GetPreview(IWICBitmapDecoder *iface,
IWICBitmapSource **ppIBitmapSource)
{
FIXME("(%p,%p): stub\n", iface, ppIBitmapSource);
return WINCODEC_ERR_UNSUPPORTEDOPERATION;
}
static HRESULT WINAPI JpegDecoder_GetColorContexts(IWICBitmapDecoder *iface,
UINT cCount, IWICColorContext **ppIColorContexts, UINT *pcActualCount)
{
FIXME("(%p,%u,%p,%p): stub\n", iface, cCount, ppIColorContexts, pcActualCount);
return WINCODEC_ERR_UNSUPPORTEDOPERATION;
}
static HRESULT WINAPI JpegDecoder_GetThumbnail(IWICBitmapDecoder *iface,
IWICBitmapSource **ppIThumbnail)
{
FIXME("(%p,%p): stub\n", iface, ppIThumbnail);
return WINCODEC_ERR_CODECNOTHUMBNAIL;
}
static HRESULT WINAPI JpegDecoder_GetFrameCount(IWICBitmapDecoder *iface,
UINT *pCount)
{
*pCount = 1;
return S_OK;
}
static HRESULT WINAPI JpegDecoder_GetFrame(IWICBitmapDecoder *iface,
UINT index, IWICBitmapFrameDecode **ppIBitmapFrame)
{
JpegDecoder *This = (JpegDecoder*)iface;
TRACE("(%p,%u,%p)\n", iface, index, ppIBitmapFrame);
if (!This->initialized) return WINCODEC_ERR_NOTINITIALIZED;
if (index != 0) return E_INVALIDARG;
IWICBitmapDecoder_AddRef(iface);
*ppIBitmapFrame = (IWICBitmapFrameDecode*)&This->lpFrameVtbl;
return S_OK;
}
static const IWICBitmapDecoderVtbl JpegDecoder_Vtbl = {
JpegDecoder_QueryInterface,
JpegDecoder_AddRef,
JpegDecoder_Release,
JpegDecoder_QueryCapability,
JpegDecoder_Initialize,
JpegDecoder_GetContainerFormat,
JpegDecoder_GetDecoderInfo,
JpegDecoder_CopyPalette,
JpegDecoder_GetMetadataQueryReader,
JpegDecoder_GetPreview,
JpegDecoder_GetColorContexts,
JpegDecoder_GetThumbnail,
JpegDecoder_GetFrameCount,
JpegDecoder_GetFrame
};
static HRESULT WINAPI JpegDecoder_Frame_QueryInterface(IWICBitmapFrameDecode *iface, REFIID iid,
void **ppv)
{
TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
if (!ppv) return E_INVALIDARG;
if (IsEqualIID(&IID_IUnknown, iid) ||
IsEqualIID(&IID_IWICBitmapSource, iid) ||
IsEqualIID(&IID_IWICBitmapFrameDecode, iid))
{
*ppv = iface;
}
else
{
*ppv = NULL;
return E_NOINTERFACE;
}
IUnknown_AddRef((IUnknown*)*ppv);
return S_OK;
}
static ULONG WINAPI JpegDecoder_Frame_AddRef(IWICBitmapFrameDecode *iface)
{
JpegDecoder *This = decoder_from_frame(iface);
return IUnknown_AddRef((IUnknown*)This);
}
static ULONG WINAPI JpegDecoder_Frame_Release(IWICBitmapFrameDecode *iface)
{
JpegDecoder *This = decoder_from_frame(iface);
return IUnknown_Release((IUnknown*)This);
}
static HRESULT WINAPI JpegDecoder_Frame_GetSize(IWICBitmapFrameDecode *iface,
UINT *puiWidth, UINT *puiHeight)
{
JpegDecoder *This = decoder_from_frame(iface);
*puiWidth = This->cinfo.output_width;
*puiHeight = This->cinfo.output_height;
TRACE("(%p)->(%u,%u)\n", iface, *puiWidth, *puiHeight);
return S_OK;
}
static HRESULT WINAPI JpegDecoder_Frame_GetPixelFormat(IWICBitmapFrameDecode *iface,
WICPixelFormatGUID *pPixelFormat)
{
JpegDecoder *This = decoder_from_frame(iface);
TRACE("(%p,%p)\n", iface, pPixelFormat);
if (This->cinfo.out_color_space == JCS_RGB)
memcpy(pPixelFormat, &GUID_WICPixelFormat24bppBGR, sizeof(GUID));
else /* This->cinfo.out_color_space == JCS_GRAYSCALE */
memcpy(pPixelFormat, &GUID_WICPixelFormat8bppGray, sizeof(GUID));
return S_OK;
}
static HRESULT WINAPI JpegDecoder_Frame_GetResolution(IWICBitmapFrameDecode *iface,
double *pDpiX, double *pDpiY)
{
FIXME("(%p,%p,%p): stub\n", iface, pDpiX, pDpiY);
return E_NOTIMPL;
}
static HRESULT WINAPI JpegDecoder_Frame_CopyPalette(IWICBitmapFrameDecode *iface,
IWICPalette *pIPalette)
{
FIXME("(%p,%p): stub\n", iface, pIPalette);
return E_NOTIMPL;
}
static HRESULT WINAPI JpegDecoder_Frame_CopyPixels(IWICBitmapFrameDecode *iface,
const WICRect *prc, UINT cbStride, UINT cbBufferSize, BYTE *pbBuffer)
{
JpegDecoder *This = decoder_from_frame(iface);
UINT bpp;
UINT stride;
UINT data_size;
UINT max_row_needed;
TRACE("(%p,%p,%u,%u,%p)\n", iface, prc, cbStride, cbBufferSize, pbBuffer);
if (This->cinfo.out_color_space == JCS_GRAYSCALE) bpp = 8;
else bpp = 24;
stride = bpp * This->cinfo.output_width;
data_size = stride * This->cinfo.output_height;
max_row_needed = prc->Y + prc->Height;
if (max_row_needed > This->cinfo.output_height) return E_INVALIDARG;
if (!This->image_data)
{
This->image_data = HeapAlloc(GetProcessHeap(), 0, data_size);
if (!This->image_data) return E_OUTOFMEMORY;
}
while (max_row_needed > This->cinfo.output_scanline)
{
UINT first_scanline = This->cinfo.output_scanline;
UINT max_rows;
JSAMPROW out_rows[4];
UINT i, j;
JDIMENSION ret;
max_rows = min(This->cinfo.output_height-first_scanline, 4);
for (i=0; i<max_rows; i++)
out_rows[i] = This->image_data + stride * (first_scanline+i);
ret = pjpeg_read_scanlines(&This->cinfo, out_rows, max_rows);
if (ret == 0)
{
ERR("read_scanlines failed\n");
return E_FAIL;
}
if (bpp == 24)
{
/* libjpeg gives us RGB data and we want BGR, so byteswap the data */
for (i=first_scanline; i<This->cinfo.output_scanline; i++)
{
BYTE *pixel = This->image_data + stride * i;
for (j=0; j<This->cinfo.output_width; j++)
{
BYTE red=pixel[0];
BYTE blue=pixel[2];
pixel[0]=blue;
pixel[2]=red;
pixel+=3;
}
}
}
}
return copy_pixels(bpp, This->image_data,
This->cinfo.output_width, This->cinfo.output_height, stride,
prc, cbStride, cbBufferSize, pbBuffer);
}
static HRESULT WINAPI JpegDecoder_Frame_GetMetadataQueryReader(IWICBitmapFrameDecode *iface,
IWICMetadataQueryReader **ppIMetadataQueryReader)
{
FIXME("(%p,%p): stub\n", iface, ppIMetadataQueryReader);
return WINCODEC_ERR_UNSUPPORTEDOPERATION;
}
static HRESULT WINAPI JpegDecoder_Frame_GetColorContexts(IWICBitmapFrameDecode *iface,
UINT cCount, IWICColorContext **ppIColorContexts, UINT *pcActualCount)
{
FIXME("(%p,%u,%p,%p): stub\n", iface, cCount, ppIColorContexts, pcActualCount);
return WINCODEC_ERR_UNSUPPORTEDOPERATION;
}
static HRESULT WINAPI JpegDecoder_Frame_GetThumbnail(IWICBitmapFrameDecode *iface,
IWICBitmapSource **ppIThumbnail)
{
FIXME("(%p,%p): stub\n", iface, ppIThumbnail);
return WINCODEC_ERR_CODECNOTHUMBNAIL;
}
static const IWICBitmapFrameDecodeVtbl JpegDecoder_Frame_Vtbl = {
JpegDecoder_Frame_QueryInterface,
JpegDecoder_Frame_AddRef,
JpegDecoder_Frame_Release,
JpegDecoder_Frame_GetSize,
JpegDecoder_Frame_GetPixelFormat,
JpegDecoder_Frame_GetResolution,
JpegDecoder_Frame_CopyPalette,
JpegDecoder_Frame_CopyPixels,
JpegDecoder_Frame_GetMetadataQueryReader,
JpegDecoder_Frame_GetColorContexts,
JpegDecoder_Frame_GetThumbnail
};
HRESULT JpegDecoder_CreateInstance(IUnknown *pUnkOuter, REFIID iid, void** ppv)
{
JpegDecoder *This;
HRESULT ret;
TRACE("(%p,%s,%p)\n", pUnkOuter, debugstr_guid(iid), ppv);
if (!libjpeg_handle && !load_libjpeg())
{
ERR("Failed reading JPEG because unable to find %s\n", SONAME_LIBJPEG);
return E_FAIL;
}
*ppv = NULL;
if (pUnkOuter) return CLASS_E_NOAGGREGATION;
This = HeapAlloc(GetProcessHeap(), 0, sizeof(JpegDecoder));
if (!This) return E_OUTOFMEMORY;
This->lpVtbl = &JpegDecoder_Vtbl;
This->lpFrameVtbl = &JpegDecoder_Frame_Vtbl;
This->ref = 1;
This->initialized = FALSE;
This->cinfo_initialized = FALSE;
This->stream = NULL;
This->image_data = NULL;
ret = IUnknown_QueryInterface((IUnknown*)This, iid, ppv);
IUnknown_Release((IUnknown*)This);
return ret;
}
#else /* !defined(SONAME_LIBJPEG) */
HRESULT JpegDecoder_CreateInstance(IUnknown *pUnkOuter, REFIID iid, void** ppv)
{
ERR("Trying to load JPEG picture, but JPEG supported not compiled in.\n");
return E_FAIL;
}
#endif

View file

@ -0,0 +1,650 @@
/*
* Copyright 2009 Vincent Povirk for CodeWeavers
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "config.h"
#include "wine/port.h"
#include <stdarg.h>
#ifdef HAVE_PNG_H
#include <png.h>
#endif
#define COBJMACROS
#include "windef.h"
#include "winbase.h"
#include "objbase.h"
#include "wincodec.h"
#include "wincodecs_private.h"
#include "wine/debug.h"
#include "wine/library.h"
WINE_DEFAULT_DEBUG_CHANNEL(wincodecs);
#ifdef SONAME_LIBPNG
static void *libpng_handle;
#define MAKE_FUNCPTR(f) static typeof(f) * p##f
MAKE_FUNCPTR(png_create_read_struct);
MAKE_FUNCPTR(png_create_info_struct);
MAKE_FUNCPTR(png_destroy_read_struct);
MAKE_FUNCPTR(png_error);
MAKE_FUNCPTR(png_get_bit_depth);
MAKE_FUNCPTR(png_get_color_type);
MAKE_FUNCPTR(png_get_image_height);
MAKE_FUNCPTR(png_get_image_width);
MAKE_FUNCPTR(png_get_io_ptr);
MAKE_FUNCPTR(png_get_PLTE);
MAKE_FUNCPTR(png_get_tRNS);
MAKE_FUNCPTR(png_set_bgr);
MAKE_FUNCPTR(png_set_gray_1_2_4_to_8);
MAKE_FUNCPTR(png_set_gray_to_rgb);
MAKE_FUNCPTR(png_set_read_fn);
MAKE_FUNCPTR(png_set_strip_16);
MAKE_FUNCPTR(png_set_tRNS_to_alpha);
MAKE_FUNCPTR(png_read_end);
MAKE_FUNCPTR(png_read_image);
MAKE_FUNCPTR(png_read_info);
#undef MAKE_FUNCPTR
static void *load_libpng(void)
{
if((libpng_handle = wine_dlopen(SONAME_LIBPNG, RTLD_NOW, NULL, 0)) != NULL) {
#define LOAD_FUNCPTR(f) \
if((p##f = wine_dlsym(libpng_handle, #f, NULL, 0)) == NULL) { \
libpng_handle = NULL; \
return NULL; \
}
LOAD_FUNCPTR(png_create_read_struct);
LOAD_FUNCPTR(png_create_info_struct);
LOAD_FUNCPTR(png_destroy_read_struct);
LOAD_FUNCPTR(png_error);
LOAD_FUNCPTR(png_get_bit_depth);
LOAD_FUNCPTR(png_get_color_type);
LOAD_FUNCPTR(png_get_image_height);
LOAD_FUNCPTR(png_get_image_width);
LOAD_FUNCPTR(png_get_io_ptr);
LOAD_FUNCPTR(png_get_PLTE);
LOAD_FUNCPTR(png_get_tRNS);
LOAD_FUNCPTR(png_set_bgr);
LOAD_FUNCPTR(png_set_gray_1_2_4_to_8);
LOAD_FUNCPTR(png_set_gray_to_rgb);
LOAD_FUNCPTR(png_set_read_fn);
LOAD_FUNCPTR(png_set_strip_16);
LOAD_FUNCPTR(png_set_tRNS_to_alpha);
LOAD_FUNCPTR(png_read_end);
LOAD_FUNCPTR(png_read_image);
LOAD_FUNCPTR(png_read_info);
#undef LOAD_FUNCPTR
}
return libpng_handle;
}
typedef struct {
const IWICBitmapDecoderVtbl *lpVtbl;
const IWICBitmapFrameDecodeVtbl *lpFrameVtbl;
LONG ref;
png_structp png_ptr;
png_infop info_ptr;
png_infop end_info;
BOOL initialized;
int bpp;
int width, height;
UINT stride;
const WICPixelFormatGUID *format;
BYTE *image_bits;
} PngDecoder;
static inline PngDecoder *impl_from_frame(IWICBitmapFrameDecode *iface)
{
return CONTAINING_RECORD(iface, PngDecoder, lpFrameVtbl);
}
static const IWICBitmapFrameDecodeVtbl PngDecoder_FrameVtbl;
static HRESULT WINAPI PngDecoder_QueryInterface(IWICBitmapDecoder *iface, REFIID iid,
void **ppv)
{
PngDecoder *This = (PngDecoder*)iface;
TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
if (!ppv) return E_INVALIDARG;
if (IsEqualIID(&IID_IUnknown, iid) || IsEqualIID(&IID_IWICBitmapDecoder, iid))
{
*ppv = This;
}
else
{
*ppv = NULL;
return E_NOINTERFACE;
}
IUnknown_AddRef((IUnknown*)*ppv);
return S_OK;
}
static ULONG WINAPI PngDecoder_AddRef(IWICBitmapDecoder *iface)
{
PngDecoder *This = (PngDecoder*)iface;
ULONG ref = InterlockedIncrement(&This->ref);
TRACE("(%p) refcount=%u\n", iface, ref);
return ref;
}
static ULONG WINAPI PngDecoder_Release(IWICBitmapDecoder *iface)
{
PngDecoder *This = (PngDecoder*)iface;
ULONG ref = InterlockedDecrement(&This->ref);
TRACE("(%p) refcount=%u\n", iface, ref);
if (ref == 0)
{
if (This->png_ptr)
ppng_destroy_read_struct(&This->png_ptr, &This->info_ptr, &This->end_info);
HeapFree(GetProcessHeap(), 0, This->image_bits);
HeapFree(GetProcessHeap(), 0, This);
}
return ref;
}
static HRESULT WINAPI PngDecoder_QueryCapability(IWICBitmapDecoder *iface, IStream *pIStream,
DWORD *pdwCapability)
{
FIXME("(%p,%p,%p): stub\n", iface, pIStream, pdwCapability);
return E_NOTIMPL;
}
static void user_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
{
IStream *stream = ppng_get_io_ptr(png_ptr);
HRESULT hr;
ULONG bytesread;
hr = IStream_Read(stream, data, length, &bytesread);
if (FAILED(hr) || bytesread != length)
{
ppng_error(png_ptr, "failed reading data");
}
}
static HRESULT WINAPI PngDecoder_Initialize(IWICBitmapDecoder *iface, IStream *pIStream,
WICDecodeOptions cacheOptions)
{
PngDecoder *This = (PngDecoder*)iface;
LARGE_INTEGER seek;
HRESULT hr;
png_bytep *row_pointers=NULL;
UINT image_size;
UINT i;
int color_type, bit_depth;
png_bytep trans;
int num_trans;
png_uint_32 transparency;
png_color_16p trans_values;
TRACE("(%p,%p,%x)\n", iface, pIStream, cacheOptions);
/* initialize libpng */
This->png_ptr = ppng_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!This->png_ptr) return E_FAIL;
This->info_ptr = ppng_create_info_struct(This->png_ptr);
if (!This->info_ptr)
{
ppng_destroy_read_struct(&This->png_ptr, (png_infopp)NULL, (png_infopp)NULL);
This->png_ptr = NULL;
return E_FAIL;
}
This->end_info = ppng_create_info_struct(This->png_ptr);
if (!This->info_ptr)
{
ppng_destroy_read_struct(&This->png_ptr, &This->info_ptr, (png_infopp)NULL);
This->png_ptr = NULL;
return E_FAIL;
}
/* set up setjmp/longjmp error handling */
if (setjmp(png_jmpbuf(This->png_ptr)))
{
ppng_destroy_read_struct(&This->png_ptr, &This->info_ptr, &This->end_info);
HeapFree(GetProcessHeap(), 0, row_pointers);
This->png_ptr = NULL;
return E_FAIL;
}
/* seek to the start of the stream */
seek.QuadPart = 0;
hr = IStream_Seek(pIStream, seek, STREAM_SEEK_SET, NULL);
if (FAILED(hr)) return hr;
/* set up custom i/o handling */
ppng_set_read_fn(This->png_ptr, pIStream, user_read_data);
/* read the header */
ppng_read_info(This->png_ptr, This->info_ptr);
/* choose a pixel format */
color_type = ppng_get_color_type(This->png_ptr, This->info_ptr);
bit_depth = ppng_get_bit_depth(This->png_ptr, This->info_ptr);
/* check for color-keyed alpha */
transparency = ppng_get_tRNS(This->png_ptr, This->info_ptr, &trans, &num_trans, &trans_values);
if (transparency && color_type != PNG_COLOR_TYPE_PALETTE)
{
/* expand to RGBA */
if (color_type == PNG_COLOR_TYPE_GRAY)
{
if (bit_depth < 8)
{
ppng_set_gray_1_2_4_to_8(This->png_ptr);
bit_depth = 8;
}
ppng_set_gray_to_rgb(This->png_ptr);
}
ppng_set_tRNS_to_alpha(This->png_ptr);
color_type = PNG_COLOR_TYPE_RGB_ALPHA;
}
switch (color_type)
{
case PNG_COLOR_TYPE_GRAY:
This->bpp = bit_depth;
switch (bit_depth)
{
case 1: This->format = &GUID_WICPixelFormatBlackWhite; break;
case 2: This->format = &GUID_WICPixelFormat2bppGray; break;
case 4: This->format = &GUID_WICPixelFormat4bppGray; break;
case 8: This->format = &GUID_WICPixelFormat8bppGray; break;
case 16: This->format = &GUID_WICPixelFormat16bppGray; break;
default:
ERR("invalid grayscale bit depth: %i\n", bit_depth);
return E_FAIL;
}
break;
case PNG_COLOR_TYPE_GRAY_ALPHA:
/* WIC does not support grayscale alpha formats so use RGBA */
ppng_set_gray_to_rgb(This->png_ptr);
case PNG_COLOR_TYPE_RGB_ALPHA:
This->bpp = bit_depth * 4;
switch (bit_depth)
{
case 8:
ppng_set_bgr(This->png_ptr);
This->format = &GUID_WICPixelFormat32bppBGRA;
break;
case 16: This->format = &GUID_WICPixelFormat64bppRGBA; break;
default:
ERR("invalid RGBA bit depth: %i\n", bit_depth);
return E_FAIL;
}
break;
case PNG_COLOR_TYPE_PALETTE:
This->bpp = bit_depth;
switch (bit_depth)
{
case 1: This->format = &GUID_WICPixelFormat1bppIndexed; break;
case 2: This->format = &GUID_WICPixelFormat2bppIndexed; break;
case 4: This->format = &GUID_WICPixelFormat4bppIndexed; break;
case 8: This->format = &GUID_WICPixelFormat8bppIndexed; break;
default:
ERR("invalid indexed color bit depth: %i\n", bit_depth);
return E_FAIL;
}
break;
case PNG_COLOR_TYPE_RGB:
This->bpp = bit_depth * 3;
switch (bit_depth)
{
case 8:
ppng_set_bgr(This->png_ptr);
This->format = &GUID_WICPixelFormat24bppBGR;
break;
case 16: This->format = &GUID_WICPixelFormat48bppRGB; break;
default:
ERR("invalid RGB color bit depth: %i\n", bit_depth);
return E_FAIL;
}
break;
default:
ERR("invalid color type %i\n", color_type);
return E_FAIL;
}
/* read the image data */
This->width = ppng_get_image_width(This->png_ptr, This->info_ptr);
This->height = ppng_get_image_height(This->png_ptr, This->info_ptr);
This->stride = This->width * This->bpp;
image_size = This->stride * This->height;
This->image_bits = HeapAlloc(GetProcessHeap(), 0, image_size);
if (!This->image_bits) return E_OUTOFMEMORY;
row_pointers = HeapAlloc(GetProcessHeap(), 0, sizeof(png_bytep)*This->height);
if (!row_pointers) return E_OUTOFMEMORY;
for (i=0; i<This->height; i++)
row_pointers[i] = This->image_bits + i * This->stride;
ppng_read_image(This->png_ptr, row_pointers);
HeapFree(GetProcessHeap(), 0, row_pointers);
row_pointers = NULL;
ppng_read_end(This->png_ptr, This->end_info);
This->initialized = TRUE;
return S_OK;
}
static HRESULT WINAPI PngDecoder_GetContainerFormat(IWICBitmapDecoder *iface,
GUID *pguidContainerFormat)
{
memcpy(pguidContainerFormat, &GUID_ContainerFormatPng, sizeof(GUID));
return S_OK;
}
static HRESULT WINAPI PngDecoder_GetDecoderInfo(IWICBitmapDecoder *iface,
IWICBitmapDecoderInfo **ppIDecoderInfo)
{
FIXME("(%p,%p): stub\n", iface, ppIDecoderInfo);
return E_NOTIMPL;
}
static HRESULT WINAPI PngDecoder_CopyPalette(IWICBitmapDecoder *iface,
IWICPalette *pIPalette)
{
FIXME("(%p,%p): stub\n", iface, pIPalette);
return E_NOTIMPL;
}
static HRESULT WINAPI PngDecoder_GetMetadataQueryReader(IWICBitmapDecoder *iface,
IWICMetadataQueryReader **ppIMetadataQueryReader)
{
FIXME("(%p,%p): stub\n", iface, ppIMetadataQueryReader);
return E_NOTIMPL;
}
static HRESULT WINAPI PngDecoder_GetPreview(IWICBitmapDecoder *iface,
IWICBitmapSource **ppIBitmapSource)
{
FIXME("(%p,%p): stub\n", iface, ppIBitmapSource);
return E_NOTIMPL;
}
static HRESULT WINAPI PngDecoder_GetColorContexts(IWICBitmapDecoder *iface,
UINT cCount, IWICColorContext **ppIColorContexts, UINT *pcActualCount)
{
FIXME("(%p,%u,%p,%p)\n", iface, cCount, ppIColorContexts, pcActualCount);
return E_NOTIMPL;
}
static HRESULT WINAPI PngDecoder_GetThumbnail(IWICBitmapDecoder *iface,
IWICBitmapSource **ppIThumbnail)
{
TRACE("(%p,%p)\n", iface, ppIThumbnail);
return WINCODEC_ERR_CODECNOTHUMBNAIL;
}
static HRESULT WINAPI PngDecoder_GetFrameCount(IWICBitmapDecoder *iface,
UINT *pCount)
{
*pCount = 1;
return S_OK;
}
static HRESULT WINAPI PngDecoder_GetFrame(IWICBitmapDecoder *iface,
UINT index, IWICBitmapFrameDecode **ppIBitmapFrame)
{
PngDecoder *This = (PngDecoder*)iface;
TRACE("(%p,%u,%p)\n", iface, index, ppIBitmapFrame);
if (!This->initialized) return WINCODEC_ERR_NOTINITIALIZED;
if (index != 0) return E_INVALIDARG;
IWICBitmapDecoder_AddRef(iface);
*ppIBitmapFrame = (void*)(&This->lpFrameVtbl);
return S_OK;
}
static const IWICBitmapDecoderVtbl PngDecoder_Vtbl = {
PngDecoder_QueryInterface,
PngDecoder_AddRef,
PngDecoder_Release,
PngDecoder_QueryCapability,
PngDecoder_Initialize,
PngDecoder_GetContainerFormat,
PngDecoder_GetDecoderInfo,
PngDecoder_CopyPalette,
PngDecoder_GetMetadataQueryReader,
PngDecoder_GetPreview,
PngDecoder_GetColorContexts,
PngDecoder_GetThumbnail,
PngDecoder_GetFrameCount,
PngDecoder_GetFrame
};
static HRESULT WINAPI PngDecoder_Frame_QueryInterface(IWICBitmapFrameDecode *iface, REFIID iid,
void **ppv)
{
if (!ppv) return E_INVALIDARG;
if (IsEqualIID(&IID_IUnknown, iid) ||
IsEqualIID(&IID_IWICBitmapSource, iid) ||
IsEqualIID(&IID_IWICBitmapFrameDecode, iid))
{
*ppv = iface;
}
else
{
*ppv = NULL;
return E_NOINTERFACE;
}
IUnknown_AddRef((IUnknown*)*ppv);
return S_OK;
}
static ULONG WINAPI PngDecoder_Frame_AddRef(IWICBitmapFrameDecode *iface)
{
PngDecoder *This = impl_from_frame(iface);
return IUnknown_AddRef((IUnknown*)This);
}
static ULONG WINAPI PngDecoder_Frame_Release(IWICBitmapFrameDecode *iface)
{
PngDecoder *This = impl_from_frame(iface);
return IUnknown_Release((IUnknown*)This);
}
static HRESULT WINAPI PngDecoder_Frame_GetSize(IWICBitmapFrameDecode *iface,
UINT *puiWidth, UINT *puiHeight)
{
PngDecoder *This = impl_from_frame(iface);
*puiWidth = This->width;
*puiHeight = This->height;
TRACE("(%p)->(%u,%u)\n", iface, *puiWidth, *puiHeight);
return S_OK;
}
static HRESULT WINAPI PngDecoder_Frame_GetPixelFormat(IWICBitmapFrameDecode *iface,
WICPixelFormatGUID *pPixelFormat)
{
PngDecoder *This = impl_from_frame(iface);
TRACE("(%p,%p)\n", iface, pPixelFormat);
memcpy(pPixelFormat, This->format, sizeof(GUID));
return S_OK;
}
static HRESULT WINAPI PngDecoder_Frame_GetResolution(IWICBitmapFrameDecode *iface,
double *pDpiX, double *pDpiY)
{
FIXME("(%p,%p,%p): stub\n", iface, pDpiX, pDpiY);
return E_NOTIMPL;
}
static HRESULT WINAPI PngDecoder_Frame_CopyPalette(IWICBitmapFrameDecode *iface,
IWICPalette *pIPalette)
{
PngDecoder *This = impl_from_frame(iface);
png_uint_32 ret;
png_colorp png_palette;
int num_palette;
WICColor palette[256];
png_bytep trans;
int num_trans;
png_color_16p trans_values;
int i;
TRACE("(%p,%p)\n", iface, pIPalette);
ret = ppng_get_PLTE(This->png_ptr, This->info_ptr, &png_palette, &num_palette);
if (!ret) return WINCODEC_ERR_PALETTEUNAVAILABLE;
if (num_palette > 256)
{
ERR("palette has %i colors?!\n", num_palette);
return E_FAIL;
}
for (i=0; i<num_palette; i++)
{
palette[i] = (0xff000000|
png_palette[i].red << 16|
png_palette[i].green << 8|
png_palette[i].blue);
}
ret = ppng_get_tRNS(This->png_ptr, This->info_ptr, &trans, &num_trans, &trans_values);
if (ret)
{
for (i=0; i<num_trans; i++)
{
palette[trans[i]] = 0x00000000;
}
}
return IWICPalette_InitializeCustom(pIPalette, palette, num_palette);
}
static HRESULT WINAPI PngDecoder_Frame_CopyPixels(IWICBitmapFrameDecode *iface,
const WICRect *prc, UINT cbStride, UINT cbBufferSize, BYTE *pbBuffer)
{
PngDecoder *This = impl_from_frame(iface);
TRACE("(%p,%p,%u,%u,%p)\n", iface, prc, cbStride, cbBufferSize, pbBuffer);
return copy_pixels(This->bpp, This->image_bits,
This->width, This->height, This->stride,
prc, cbStride, cbBufferSize, pbBuffer);
}
static HRESULT WINAPI PngDecoder_Frame_GetMetadataQueryReader(IWICBitmapFrameDecode *iface,
IWICMetadataQueryReader **ppIMetadataQueryReader)
{
FIXME("(%p,%p): stub\n", iface, ppIMetadataQueryReader);
return E_NOTIMPL;
}
static HRESULT WINAPI PngDecoder_Frame_GetColorContexts(IWICBitmapFrameDecode *iface,
UINT cCount, IWICColorContext **ppIColorContexts, UINT *pcActualCount)
{
FIXME("(%p,%u,%p,%p): stub\n", iface, cCount, ppIColorContexts, pcActualCount);
return E_NOTIMPL;
}
static HRESULT WINAPI PngDecoder_Frame_GetThumbnail(IWICBitmapFrameDecode *iface,
IWICBitmapSource **ppIThumbnail)
{
FIXME("(%p,%p): stub\n", iface, ppIThumbnail);
return E_NOTIMPL;
}
static const IWICBitmapFrameDecodeVtbl PngDecoder_FrameVtbl = {
PngDecoder_Frame_QueryInterface,
PngDecoder_Frame_AddRef,
PngDecoder_Frame_Release,
PngDecoder_Frame_GetSize,
PngDecoder_Frame_GetPixelFormat,
PngDecoder_Frame_GetResolution,
PngDecoder_Frame_CopyPalette,
PngDecoder_Frame_CopyPixels,
PngDecoder_Frame_GetMetadataQueryReader,
PngDecoder_Frame_GetColorContexts,
PngDecoder_Frame_GetThumbnail
};
HRESULT PngDecoder_CreateInstance(IUnknown *pUnkOuter, REFIID iid, void** ppv)
{
PngDecoder *This;
HRESULT ret;
TRACE("(%p,%s,%p)\n", pUnkOuter, debugstr_guid(iid), ppv);
*ppv = NULL;
if (pUnkOuter) return CLASS_E_NOAGGREGATION;
if (!libpng_handle && !load_libpng())
{
ERR("Failed reading PNG because unable to find %s\n",SONAME_LIBPNG);
return E_FAIL;
}
This = HeapAlloc(GetProcessHeap(), 0, sizeof(PngDecoder));
if (!This) return E_OUTOFMEMORY;
This->lpVtbl = &PngDecoder_Vtbl;
This->lpFrameVtbl = &PngDecoder_FrameVtbl;
This->ref = 1;
This->png_ptr = NULL;
This->info_ptr = NULL;
This->end_info = NULL;
This->initialized = FALSE;
This->image_bits = NULL;
ret = IUnknown_QueryInterface((IUnknown*)This, iid, ppv);
IUnknown_Release((IUnknown*)This);
return ret;
}
#else /* !HAVE_PNG_H */
HRESULT PngDecoder_CreateInstance(IUnknown *pUnkOuter, REFIID iid, void** ppv)
{
ERR("Trying to load PNG picture, but PNG supported not compiled in.\n");
return E_FAIL;
}
#endif

View file

@ -735,6 +735,12 @@ static struct regsvr_coclass const coclass_list[] = {
"windowscodecs.dll",
"Apartment"
},
{ &CLSID_WICPngDecoder,
"WIC PNG Decoder",
NULL,
"windowscodecs.dll",
"Apartment"
},
{ &CLSID_WICBmpEncoder,
"WIC BMP Encoder",
NULL,
@ -753,6 +759,12 @@ static struct regsvr_coclass const coclass_list[] = {
"windowscodecs.dll",
"Apartment"
},
{ &CLSID_WICJpegDecoder,
"WIC JPEG Decoder",
NULL,
"windowscodecs.dll",
"Apartment"
},
{ &CLSID_WICDefaultFormatConverter,
"WIC Default Format Converter",
NULL,
@ -765,7 +777,7 @@ static struct regsvr_coclass const coclass_list[] = {
/***********************************************************************
* decoder list
*/
static const BYTE mask_all[] = {0xff,0xff,0xff,0xff,0xff,0xff};
static const BYTE mask_all[] = {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
static const BYTE bmp_magic[] = {0x42,0x4d};
@ -813,6 +825,43 @@ static struct decoder_pattern const ico_patterns[] = {
{0}
};
static const BYTE jpeg_magic[] = {0xff, 0xd8, 0xff, 0xe0};
static GUID const * const jpeg_formats[] = {
&GUID_WICPixelFormat24bppBGR,
&GUID_WICPixelFormat8bppGray,
NULL
};
static struct decoder_pattern const jpeg_patterns[] = {
{4,0,jpeg_magic,mask_all,0},
{0}
};
static const BYTE png_magic[] = {137,80,78,71,13,10,26,10};
static GUID const * const png_formats[] = {
&GUID_WICPixelFormatBlackWhite,
&GUID_WICPixelFormat2bppGray,
&GUID_WICPixelFormat4bppGray,
&GUID_WICPixelFormat8bppGray,
&GUID_WICPixelFormat16bppGray,
&GUID_WICPixelFormat32bppBGRA,
&GUID_WICPixelFormat64bppRGBA,
&GUID_WICPixelFormat1bppIndexed,
&GUID_WICPixelFormat2bppIndexed,
&GUID_WICPixelFormat4bppIndexed,
&GUID_WICPixelFormat8bppIndexed,
&GUID_WICPixelFormat24bppBGR,
&GUID_WICPixelFormat48bppRGB,
NULL
};
static struct decoder_pattern const png_patterns[] = {
{8,0,png_magic,mask_all,0},
{0}
};
static struct regsvr_decoder const decoder_list[] = {
{ &CLSID_WICBmpDecoder,
"The Wine Project",
@ -844,18 +893,46 @@ static struct regsvr_decoder const decoder_list[] = {
ico_formats,
ico_patterns
},
{ &CLSID_WICJpegDecoder,
"The Wine Project",
"JPEG Decoder",
"1.0.0.0",
&GUID_VendorMicrosoft,
"image/jpeg",
".jpg;.jpeg;.jfif",
jpeg_formats,
jpeg_patterns
},
{ &CLSID_WICPngDecoder,
"The Wine Project",
"PNG Decoder",
"1.0.0.0",
&GUID_VendorMicrosoft,
"image/png",
".png",
png_formats,
png_patterns
},
{ NULL } /* list terminator */
};
static GUID const * const converter_formats[] = {
&GUID_WICPixelFormat1bppIndexed,
&GUID_WICPixelFormat2bppIndexed,
&GUID_WICPixelFormat4bppIndexed,
&GUID_WICPixelFormat8bppIndexed,
&GUID_WICPixelFormatBlackWhite,
&GUID_WICPixelFormat2bppGray,
&GUID_WICPixelFormat4bppGray,
&GUID_WICPixelFormat8bppGray,
&GUID_WICPixelFormat16bppGray,
&GUID_WICPixelFormat16bppBGR555,
&GUID_WICPixelFormat16bppBGR565,
&GUID_WICPixelFormat24bppBGR,
&GUID_WICPixelFormat32bppBGR,
&GUID_WICPixelFormat32bppBGRA,
&GUID_WICPixelFormat48bppRGB,
&GUID_WICPixelFormat64bppRGBA,
NULL
};

View file

@ -138,7 +138,7 @@ static HRESULT WINAPI StreamOnMemory_Seek(IStream *iface,
if (NewPosition.QuadPart > This->dwMemsize) return E_INVALIDARG;
if (NewPosition.QuadPart < 0) return E_INVALIDARG;
This->dwCurPos = NewPosition.LowPart;
This->dwCurPos = NewPosition.u.LowPart;
if(plibNewPosition) plibNewPosition->QuadPart = This->dwCurPos;
return S_OK;

View file

@ -22,9 +22,11 @@
extern HRESULT FormatConverter_CreateInstance(IUnknown *pUnkOuter, REFIID riid, void** ppv);
extern HRESULT ImagingFactory_CreateInstance(IUnknown *pUnkOuter, REFIID riid, void** ppv);
extern HRESULT BmpDecoder_CreateInstance(IUnknown *pUnkOuter, REFIID riid, void** ppv);
extern HRESULT PngDecoder_CreateInstance(IUnknown *pUnkOuter, REFIID iid, void** ppv);
extern HRESULT BmpEncoder_CreateInstance(IUnknown *pUnkOuter, REFIID iid, void** ppv);
extern HRESULT GifDecoder_CreateInstance(IUnknown *pUnkOuter, REFIID riid, void** ppv);
extern HRESULT IcoDecoder_CreateInstance(IUnknown *pUnkOuter, REFIID iid, void** ppv);
extern HRESULT JpegDecoder_CreateInstance(IUnknown *pUnkOuter, REFIID iid, void** ppv);
extern HRESULT PaletteImpl_Create(IWICPalette **palette);
extern HRESULT StreamImpl_Create(IWICStream **stream);

View file

@ -3,6 +3,7 @@
<importlibrary definition="windowscodecs.spec" />
<include base="windowscodecs">.</include>
<include base="ReactOS">include/reactos/wine</include>
<include base="ReactOS">include/reactos/libs/libjpeg</include>
<define name="__WINESRC__" />
<redefine name="_WIN32_WINNT">0x600</redefine>
@ -21,8 +22,10 @@
<file>icoformat.c</file>
<file>imgfactory.c</file>
<file>info.c</file>
<file>jpegformat.c</file>
<file>main.c</file>
<file>palette.c</file>
<file>pngformat.c</file>
<file>propertybag.c</file>
<file>regsvr.c</file>
<file>stream.c</file>

View file

@ -126,6 +126,12 @@ cpp_quote("DEFINE_GUID(GUID_WICPixelFormat2bppIndexed, 0x6fddc324,0x4e03,0x4bfe,
cpp_quote("DEFINE_GUID(GUID_WICPixelFormat4bppIndexed, 0x6fddc324,0x4e03,0x4bfe,0xb1,0x85,0x3d,0x77,0x76,0x8d,0xc9,0x03);")
cpp_quote("DEFINE_GUID(GUID_WICPixelFormat8bppIndexed, 0x6fddc324,0x4e03,0x4bfe,0xb1,0x85,0x3d,0x77,0x76,0x8d,0xc9,0x04);")
cpp_quote("DEFINE_GUID(GUID_WICPixelFormatBlackWhite, 0x6fddc324,0x4e03,0x4bfe,0xb1,0x85,0x3d,0x77,0x76,0x8d,0xc9,0x05);")
cpp_quote("DEFINE_GUID(GUID_WICPixelFormat2bppGray, 0x6fddc324,0x4e03,0x4bfe,0xb1,0x85,0x3d,0x77,0x76,0x8d,0xc9,0x06);")
cpp_quote("DEFINE_GUID(GUID_WICPixelFormat4bppGray, 0x6fddc324,0x4e03,0x4bfe,0xb1,0x85,0x3d,0x77,0x76,0x8d,0xc9,0x07);")
cpp_quote("DEFINE_GUID(GUID_WICPixelFormat8bppGray, 0x6fddc324,0x4e03,0x4bfe,0xb1,0x85,0x3d,0x77,0x76,0x8d,0xc9,0x08);")
cpp_quote("DEFINE_GUID(GUID_WICPixelFormat16bppGray, 0x6fddc324,0x4e03,0x4bfe,0xb1,0x85,0x3d,0x77,0x76,0x8d,0xc9,0x0b);")
cpp_quote("DEFINE_GUID(GUID_WICPixelFormat16bppBGR555, 0x6fddc324,0x4e03,0x4bfe,0xb1,0x85,0x3d,0x77,0x76,0x8d,0xc9,0x09);")
cpp_quote("DEFINE_GUID(GUID_WICPixelFormat16bppBGR565, 0x6fddc324,0x4e03,0x4bfe,0xb1,0x85,0x3d,0x77,0x76,0x8d,0xc9,0x0a);")
cpp_quote("DEFINE_GUID(GUID_WICPixelFormat24bppBGR, 0x6fddc324,0x4e03,0x4bfe,0xb1,0x85,0x3d,0x77,0x76,0x8d,0xc9,0x0c);")
@ -133,6 +139,9 @@ cpp_quote("DEFINE_GUID(GUID_WICPixelFormat32bppBGR, 0x6fddc324,0x4e03,0x4bfe,0xb
cpp_quote("DEFINE_GUID(GUID_WICPixelFormat32bppBGRA, 0x6fddc324,0x4e03,0x4bfe,0xb1,0x85,0x3d,0x77,0x76,0x8d,0xc9,0x0f);")
cpp_quote("DEFINE_GUID(GUID_WICPixelFormat32bppPBGRA, 0x6fddc324,0x4e03,0x4bfe,0xb1,0x85,0x3d,0x77,0x76,0x8d,0xc9,0x10);")
cpp_quote("DEFINE_GUID(GUID_WICPixelFormat48bppRGB, 0x6fddc324,0x4e03,0x4bfe,0xb1,0x85,0x3d,0x77,0x76,0x8d,0xc9,0x15);")
cpp_quote("DEFINE_GUID(GUID_WICPixelFormat64bppRGBA, 0x6fddc324,0x4e03,0x4bfe,0xb1,0x85,0x3d,0x77,0x76,0x8d,0xc9,0x16);")
typedef struct WICRect {
INT X;
INT Y;