gdip-pixbuf-loader r23 - in trunk: . src
- From: tml svn gnome org
- To: svn-commits-list gnome org
- Subject: gdip-pixbuf-loader r23 - in trunk: . src
- Date: Tue, 19 Feb 2008 17:06:12 +0000 (GMT)
Author: tml
Date: Tue Feb 19 17:06:12 2008
New Revision: 23
URL: http://svn.gnome.org/viewvc/gdip-pixbuf-loader?rev=23&view=rev
Log:
2008-02-19 Tor Lillqvist <tml novell com>
* src/io-gdip.c
* src/io-gdip-utils.c
* src/test.c: Use spaces instead of tabs. Use 2-column indentation
offset which was the original intent. Remove trailing whitespace.
Modified:
trunk/ChangeLog
trunk/src/io-gdip-utils.c
trunk/src/io-gdip.c
trunk/src/test.c
Modified: trunk/src/io-gdip-utils.c
==============================================================================
--- trunk/src/io-gdip-utils.c (original)
+++ trunk/src/io-gdip-utils.c Tue Feb 19 17:06:12 2008
@@ -1,11 +1,11 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* GdkPixbuf library - Win32 GDI+ Pixbuf Loader
*
* Copyright (C) 2008 Alberto Ruiz
* Copyright (C) 2008 Dom Lachowicz
*
* Authors: Alberto Ruiz <aruiz gnome org>
- * Dom Lachowicz <domlachowicz gmail com>
+ * Dom Lachowicz <domlachowicz gmail com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -33,99 +33,99 @@
GpStatus WINGDIPAPI
GdiplusStartup (ULONG_PTR *token, const GdiplusStartupInput *input, gpointer *output)
{
- static GdiplusStartupFunc proc = NULL;
+ static GdiplusStartupFunc proc = NULL;
- if (gdipluslib && !proc)
- proc = (GdiplusStartupFunc) GetProcAddress(gdipluslib, "GdiplusStartup");
+ if (gdipluslib && !proc)
+ proc = (GdiplusStartupFunc) GetProcAddress(gdipluslib, "GdiplusStartup");
- if (!proc)
- return GenericError;
+ if (!proc)
+ return GenericError;
- return (*proc) (token, (gpointer)input, output);
+ return (*proc) (token, (gpointer)input, output);
}
GpStatus WINGDIPAPI
GdipCreateBitmapFromStream (gpointer stream, GpBitmap** bitmap)
{
- static GdipCreateBitmapFromStreamFunc proc = NULL;
+ static GdipCreateBitmapFromStreamFunc proc = NULL;
- if (gdipluslib && !proc)
- proc = (GdipCreateBitmapFromStreamFunc) GetProcAddress(gdipluslib, "GdipCreateBitmapFromStream");
+ if (gdipluslib && !proc)
+ proc = (GdipCreateBitmapFromStreamFunc) GetProcAddress(gdipluslib, "GdipCreateBitmapFromStream");
- if (!proc)
- return GenericError;
+ if (!proc)
+ return GenericError;
- return (*proc) (stream, bitmap);
+ return (*proc) (stream, bitmap);
}
GpStatus WINGDIPAPI
GdipBitmapGetPixel(GpBitmap* bitmap, gint x, gint y, ARGB *color)
{
- static GdipBitmapGetPixelFunc proc = NULL;
+ static GdipBitmapGetPixelFunc proc = NULL;
- if (gdipluslib && !proc)
- proc = (GdipBitmapGetPixelFunc) GetProcAddress(gdipluslib, "GdipBitmapGetPixel");
+ if (gdipluslib && !proc)
+ proc = (GdipBitmapGetPixelFunc) GetProcAddress(gdipluslib, "GdipBitmapGetPixel");
- if (!proc)
- return GenericError;
+ if (!proc)
+ return GenericError;
- return (*proc) (bitmap, x, y, color);
+ return (*proc) (bitmap, x, y, color);
}
GpStatus WINGDIPAPI
GdipGetImageHeight (GpImage* image, guint* height)
{
- static GdipGetImageHeightFunc proc = NULL;
+ static GdipGetImageHeightFunc proc = NULL;
- if (gdipluslib && !proc)
- proc = (GdipGetImageHeightFunc) GetProcAddress(gdipluslib, "GdipGetImageHeight");
+ if (gdipluslib && !proc)
+ proc = (GdipGetImageHeightFunc) GetProcAddress(gdipluslib, "GdipGetImageHeight");
- if (!proc)
- return GenericError;
+ if (!proc)
+ return GenericError;
- return (*proc) (image, height);
+ return (*proc) (image, height);
}
GpStatus WINGDIPAPI
GdipDisposeImage (GpImage* image)
{
- static GdipDisposeImageFunc proc = NULL;
+ static GdipDisposeImageFunc proc = NULL;
- if (gdipluslib && !proc)
- proc = (GdipDisposeImageFunc) GetProcAddress(gdipluslib, "GdipDisposeImage");
+ if (gdipluslib && !proc)
+ proc = (GdipDisposeImageFunc) GetProcAddress(gdipluslib, "GdipDisposeImage");
- if (!proc)
- return GenericError;
+ if (!proc)
+ return GenericError;
- return (*proc) (image);
+ return (*proc) (image);
}
GpStatus WINGDIPAPI
GdipGetImageFlags (GpImage *image, guint *flags)
{
- static GdipGetImageFlagsFunc proc = NULL;
+ static GdipGetImageFlagsFunc proc = NULL;
- if (gdipluslib && !proc)
- proc = (GdipGetImageFlagsFunc) GetProcAddress(gdipluslib, "GdipGetImageFlags");
+ if (gdipluslib && !proc)
+ proc = (GdipGetImageFlagsFunc) GetProcAddress(gdipluslib, "GdipGetImageFlags");
- if (!proc)
- return GenericError;
+ if (!proc)
+ return GenericError;
- return (*proc) (image, flags);
+ return (*proc) (image, flags);
}
GpStatus WINGDIPAPI
GdipGetImageWidth (GpImage* image, guint* width)
{
- static GdipGetImageWidthFunc proc = NULL;
+ static GdipGetImageWidthFunc proc = NULL;
- if (gdipluslib && !proc)
- proc = (GdipGetImageWidthFunc) GetProcAddress(gdipluslib, "GdipGetImageWidth");
+ if (gdipluslib && !proc)
+ proc = (GdipGetImageWidthFunc) GetProcAddress(gdipluslib, "GdipGetImageWidth");
- if (!proc)
- return GenericError;
+ if (!proc)
+ return GenericError;
- return (*proc) (image, width);
+ return (*proc) (image, width);
}
DEFINE_GUID(FrameDimensionTime, 0x6aedbd6d,0x3fb5,0x418a,0x83,0xa6,0x7f,0x45,0x22,0x9d,0xc8,0x72);
@@ -133,10 +133,10 @@
struct _PropItem
{
- ULONG id;
- ULONG length;
- WORD type;
- VOID *value;
+ ULONG id;
+ ULONG length;
+ WORD type;
+ VOID *value;
};
typedef struct _PropItem PropertyItem;
@@ -144,62 +144,62 @@
typedef GpStatus (WINGDIPAPI* GdipImageGetFrameCountFunc) (GpImage *image, GDIPCONST GUID* dimensionID, UINT* count);
typedef GpStatus (WINGDIPAPI* GdipImageSelectActiveFrameFunc) (GpImage *image, GDIPCONST GUID* dimensionID, UINT frameIndex);
typedef GpStatus (WINGDIPAPI* GdipGetPropertyItemSizeFunc) (GpImage *image, int propId, guint* size);
-typedef GpStatus (WINGDIPAPI* GdipGetPropertyItemFunc) (GpImage *image, int propId,guint propSize, PropertyItem* buffer);
+typedef GpStatus (WINGDIPAPI* GdipGetPropertyItemFunc) (GpImage *image, int propId, guint propSize, PropertyItem* buffer);
GpStatus WINGDIPAPI
GdipImageGetFrameCount (GpImage* image, GDIPCONST GUID* dimensionID, guint* count)
{
- static GdipImageGetFrameCountFunc proc = NULL;
+ static GdipImageGetFrameCountFunc proc = NULL;
- if (gdipluslib && !proc)
- proc = (GdipImageGetFrameCountFunc) GetProcAddress(gdipluslib, "GdipImageGetFrameCount");
+ if (gdipluslib && !proc)
+ proc = (GdipImageGetFrameCountFunc) GetProcAddress(gdipluslib, "GdipImageGetFrameCount");
- if (!proc)
- return GenericError;
+ if (!proc)
+ return GenericError;
- return (*proc) (image, dimensionID, count);
+ return (*proc) (image, dimensionID, count);
}
GpStatus WINGDIPAPI
GdipImageSelectActiveFrame (GpImage* image, GDIPCONST GUID* dimensionID, guint frameIndex)
{
- static GdipImageSelectActiveFrameFunc proc = NULL;
+ static GdipImageSelectActiveFrameFunc proc = NULL;
- if (gdipluslib && !proc)
- proc = (GdipImageSelectActiveFrameFunc) GetProcAddress(gdipluslib, "GdipImageSelectActiveFrame");
+ if (gdipluslib && !proc)
+ proc = (GdipImageSelectActiveFrameFunc) GetProcAddress(gdipluslib, "GdipImageSelectActiveFrame");
- if (!proc)
- return GenericError;
+ if (!proc)
+ return GenericError;
- return (*proc) (image, dimensionID, frameIndex);
+ return (*proc) (image, dimensionID, frameIndex);
}
GpStatus WINGDIPAPI
GdipGetPropertyItemSize (GpImage *image, PROPID propId, guint* size)
{
- static GdipGetPropertyItemSizeFunc proc = NULL;
+ static GdipGetPropertyItemSizeFunc proc = NULL;
- if (gdipluslib && !proc)
- proc = (GdipGetPropertyItemSizeFunc) GetProcAddress(gdipluslib, "GdipGetPropertyItemSize");
+ if (gdipluslib && !proc)
+ proc = (GdipGetPropertyItemSizeFunc) GetProcAddress(gdipluslib, "GdipGetPropertyItemSize");
- if (!proc)
- return GenericError;
+ if (!proc)
+ return GenericError;
- return (*proc) (image, propId, size);
+ return (*proc) (image, propId, size);
}
GpStatus WINGDIPAPI
GdipGetPropertyItem (GpImage *image, int propId, guint propSize, PropertyItem* buffer)
{
- static GdipGetPropertyItemFunc proc = NULL;
+ static GdipGetPropertyItemFunc proc = NULL;
- if (gdipluslib && !proc)
- proc = (GdipGetPropertyItemFunc) GetProcAddress(gdipluslib, "GdipGetPropertyItem");
+ if (gdipluslib && !proc)
+ proc = (GdipGetPropertyItemFunc) GetProcAddress(gdipluslib, "GdipGetPropertyItem");
- if (!proc)
- return GenericError;
+ if (!proc)
+ return GenericError;
- return (*proc) (image, propId, propSize, buffer);
+ return (*proc) (image, propId, propSize, buffer);
}
/*
@@ -209,35 +209,35 @@
gboolean
io_gdip_init (void)
{
- GdiplusStartupInput input;
- ULONG_PTR gdiplusToken = 0;
+ GdiplusStartupInput input;
+ ULONG_PTR gdiplusToken = 0;
- input.GdiplusVersion = 1;
- input.DebugEventCallback = NULL;
- input.SuppressBackgroundThread = input.SuppressExternalCodecs = FALSE;
+ input.GdiplusVersion = 1;
+ input.DebugEventCallback = NULL;
+ input.SuppressBackgroundThread = input.SuppressExternalCodecs = FALSE;
- if (!gdipluslib)
- gdipluslib = LoadLibrary (TEXT("gdiplus.dll"));
+ if (!gdipluslib)
+ gdipluslib = LoadLibrary (TEXT("gdiplus.dll"));
- if (!gdipluslib)
- return FALSE;
+ if (!gdipluslib)
+ return FALSE;
- return (GdiplusStartup (&gdiplusToken, &input, NULL) == 0 ? TRUE : FALSE);
+ return (GdiplusStartup (&gdiplusToken, &input, NULL) == 0 ? TRUE : FALSE);
}
static HGLOBAL
io_gdip_buffer_to_hglobal (const gchar * buffer, size_t size)
{
- HGLOBAL hg = NULL;
+ HGLOBAL hg = NULL;
- hg = GlobalAlloc (GPTR, size);
-
- if (!hg)
- return NULL;
+ hg = GlobalAlloc (GPTR, size);
- CopyMemory (hg, buffer, size);
+ if (!hg)
+ return NULL;
- return hg;
+ CopyMemory (hg, buffer, size);
+
+ return hg;
}
#ifndef IStream_Release
@@ -247,145 +247,149 @@
GpBitmap *
io_gdip_buffer_to_bitmap (const gchar * buffer, size_t size)
{
- HRESULT hr;
- HGLOBAL hg = NULL;
- GpBitmap * bitmap = NULL;
- IStream *stream = NULL;
- int status;
-
- hg = io_gdip_buffer_to_hglobal (buffer, size);
-
- if (!hg) return NULL;
-
- hr = CreateStreamOnHGlobal (hg, FALSE, (LPSTREAM*)&stream);
-
- if (!SUCCEEDED(hr))
- {
- GlobalFree(hg);
- return NULL;
- }
-
- status = GdipCreateBitmapFromStream(stream, &bitmap);
+ HRESULT hr;
+ HGLOBAL hg = NULL;
+ GpBitmap * bitmap = NULL;
+ IStream *stream = NULL;
+ int status;
+
+ hg = io_gdip_buffer_to_hglobal (buffer, size);
+
+ if (!hg)
+ return NULL;
+
+ hr = CreateStreamOnHGlobal (hg, FALSE, (LPSTREAM*)&stream);
+
+ if (!SUCCEEDED(hr))
+ {
+ GlobalFree(hg);
+ return NULL;
+ }
- IStream_Release(stream);
- GlobalFree(hg);
+ status = GdipCreateBitmapFromStream(stream, &bitmap);
- return bitmap;
+ IStream_Release(stream);
+ GlobalFree(hg);
+
+ return bitmap;
}
gboolean
io_gdip_bitmap_get_size (GpBitmap * bitmap, guint * width, guint * height)
{
- if (bitmap == NULL || width == NULL || height == NULL)
- return FALSE;
+ if (bitmap == NULL || width == NULL || height == NULL)
+ return FALSE;
+
+ GdipGetImageWidth ((GpImage*) bitmap, width);
+ GdipGetImageHeight ((GpImage*) bitmap, height);
- GdipGetImageWidth ((GpImage*) bitmap, width);
- GdipGetImageHeight ((GpImage*) bitmap, height);
-
- return TRUE;
+ return TRUE;
}
gboolean
io_gdip_bitmap_get_has_alpha (GpBitmap * bitmap, gboolean * has_alpha)
{
- guint flags = 0;
+ guint flags = 0;
+
+ if (bitmap == NULL || has_alpha == NULL)
+ return FALSE;
- if (bitmap == NULL || has_alpha == NULL)
- return FALSE;
+ GdipGetImageFlags ((GpImage*) bitmap, &flags);
+ *has_alpha = (flags & ImageFlagsHasAlpha);
- GdipGetImageFlags ((GpImage*) bitmap, &flags);
- *has_alpha = (flags & ImageFlagsHasAlpha);
- return TRUE;
+ return TRUE;
}
ARGB
io_gdip_bitmap_get_pixel (GpBitmap *bitmap, guint x, guint y)
{
- ARGB pixel;
- GdipBitmapGetPixel (bitmap, x, y, &pixel);
- return pixel;
+ ARGB pixel;
+
+ GdipBitmapGetPixel (bitmap, x, y, &pixel);
+
+ return pixel;
}
void
io_gdip_dispose_bitmap (GpBitmap *bitmap)
{
- GdipDisposeImage ((GpImage*) bitmap);
+ GdipDisposeImage ((GpImage*) bitmap);
}
gboolean
io_gdip_bitmap_get_n_frames (GpBitmap *bitmap, guint *n_frames, gboolean timeDimension)
{
- if (bitmap == NULL || n_frames == NULL)
- return FALSE;
+ if (bitmap == NULL || n_frames == NULL)
+ return FALSE;
- *n_frames = 1;
+ *n_frames = 1;
- return (0 == GdipImageGetFrameCount((GpImage*) bitmap, (timeDimension ? &FrameDimensionTime : &FrameDimensionPage), n_frames));
+ return (0 == GdipImageGetFrameCount((GpImage*) bitmap, (timeDimension ? &FrameDimensionTime : &FrameDimensionPage), n_frames));
}
gboolean
io_gdip_bitmap_get_frame_delay (GpBitmap *bitmap, guint *delay)
{
- guint item_size;
- gboolean success = FALSE;
+ guint item_size;
+ gboolean success = FALSE;
- if (bitmap == NULL || delay == NULL)
- return FALSE;
+ if (bitmap == NULL || delay == NULL)
+ return FALSE;
- *delay = 0;
+ *delay = 0;
- if (0 == GdipGetPropertyItemSize ((GpImage*)bitmap, PropertyTagFrameDelay, &item_size))
- {
- PropertyItem *item;
-
- item = (PropertyItem *)g_try_malloc(item_size);
- if (0 == GdipGetPropertyItem ((GpImage*)bitmap, PropertyTagFrameDelay, item_size, item))
- {
- /* PropertyTagFrameDelay. Time delay, in hundredths of a second, between two frames in an animated GIF image. */
- *delay = *((long*)item->value);
- success = TRUE;
- }
+ if (0 == GdipGetPropertyItemSize ((GpImage*)bitmap, PropertyTagFrameDelay, &item_size))
+ {
+ PropertyItem *item;
+
+ item = (PropertyItem *)g_try_malloc(item_size);
+ if (0 == GdipGetPropertyItem ((GpImage*)bitmap, PropertyTagFrameDelay, item_size, item))
+ {
+ /* PropertyTagFrameDelay. Time delay, in hundredths of a second, between two frames in an animated GIF image. */
+ *delay = *((long*)item->value);
+ success = TRUE;
+ }
- g_free(item);
- }
+ g_free(item);
+ }
- return success;
+ return success;
}
gboolean
io_gdip_bitmap_select_frame (GpBitmap *bitmap, guint frame, gboolean timeDimension)
{
- if (bitmap == NULL)
- return FALSE;
+ if (bitmap == NULL)
+ return FALSE;
- return (0 == GdipImageSelectActiveFrame((GpImage*)bitmap, (timeDimension ? &FrameDimensionTime : &FrameDimensionPage), frame));
+ return (0 == GdipImageSelectActiveFrame((GpImage*)bitmap, (timeDimension ? &FrameDimensionTime : &FrameDimensionPage), frame));
}
gboolean
io_gdip_bitmap_get_n_loops (GpBitmap *bitmap, guint *loops)
{
- guint item_size;
- gboolean success = FALSE;
+ guint item_size;
+ gboolean success = FALSE;
- if (bitmap == NULL || loops == NULL)
- return FALSE;
+ if (bitmap == NULL || loops == NULL)
+ return FALSE;
- *loops = 1;
+ *loops = 1;
- /* PropertyTagLoopCount. 0 == infinitely */
- if (0 == GdipGetPropertyItemSize ((GpImage*)bitmap, PropertyTagLoopCount, &item_size))
- {
- PropertyItem *item;
-
- item = (PropertyItem *)g_try_malloc(item_size);
- if (0 == GdipGetPropertyItem ((GpImage*)bitmap, PropertyTagLoopCount, item_size, item))
- {
- *loops = *((short*)item->value);
- success = TRUE;
- }
+ /* PropertyTagLoopCount. 0 == infinitely */
+ if (0 == GdipGetPropertyItemSize ((GpImage*)bitmap, PropertyTagLoopCount, &item_size))
+ {
+ PropertyItem *item;
+
+ item = (PropertyItem *)g_try_malloc(item_size);
+ if (0 == GdipGetPropertyItem ((GpImage*)bitmap, PropertyTagLoopCount, item_size, item))
+ {
+ *loops = *((short*)item->value);
+ success = TRUE;
+ }
- g_free(item);
- }
+ g_free(item);
+ }
- return success;
+ return success;
}
Modified: trunk/src/io-gdip.c
==============================================================================
--- trunk/src/io-gdip.c (original)
+++ trunk/src/io-gdip.c Tue Feb 19 17:06:12 2008
@@ -1,4 +1,4 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* GdkPixbuf library - Win32 GDI+ Pixbuf Loader
*
* Copyright (C) 2008 Alberto Ruiz
@@ -27,15 +27,15 @@
#include <gdk-pixbuf/gdk-pixbuf.h>
struct _GdipContext{
- GdkPixbufModuleUpdatedFunc updated_func;
- GdkPixbufModulePreparedFunc prepared_func;
- GdkPixbufModuleSizeFunc size_func;
+ GdkPixbufModuleUpdatedFunc updated_func;
+ GdkPixbufModulePreparedFunc prepared_func;
+ GdkPixbufModuleSizeFunc size_func;
- gboolean first_write;
+ gboolean first_write;
- gpointer user_data;
+ gpointer user_data;
- GByteArray* buffer;
+ GByteArray* buffer;
};
typedef struct _GdipContext GdipContext;
@@ -47,39 +47,39 @@
const char * reason,
gint code)
{
- if (err)
- {
- *err = NULL;
- g_set_error (err, GDK_PIXBUF_ERROR, code, reason);
- }
+ if (err)
+ {
+ *err = NULL;
+ g_set_error (err, GDK_PIXBUF_ERROR, code, reason);
+ }
}
static void
destroy_gdipcontext (GdipContext *context)
{
- if (context != NULL)
- {
- g_byte_array_free (context->buffer, TRUE);
- g_free (context);
- }
+ if (context != NULL)
+ {
+ g_byte_array_free (context->buffer, TRUE);
+ g_free (context);
+ }
}
static void
emit_updated (GdipContext *context, GdkPixbuf *pixbuf)
{
- if (context->updated_func != NULL)
- (* context->updated_func) (pixbuf,
- 0, 0,
- gdk_pixbuf_get_width (pixbuf),
- gdk_pixbuf_get_height (pixbuf),
- context->user_data);
+ if (context->updated_func != NULL)
+ (* context->updated_func) (pixbuf,
+ 0, 0,
+ gdk_pixbuf_get_width (pixbuf),
+ gdk_pixbuf_get_height (pixbuf),
+ context->user_data);
}
static void
emit_prepared (GdipContext *context, GdkPixbuf *pixbuf, GdkPixbufAnimation *anim)
{
- if (context->prepared_func != NULL)
- (* context->prepared_func) (pixbuf, anim, context->user_data);
+ if (context->prepared_func != NULL)
+ (* context->prepared_func) (pixbuf, anim, context->user_data);
}
static gpointer
@@ -89,27 +89,27 @@
gpointer user_data,
GError **error)
{
- GdipContext *context = g_new(GdipContext, 1);
+ GdipContext *context = g_new(GdipContext, 1);
- if (!context)
- {
- gdip_propegate_error (error, "Couldn't create context", GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY);
- return NULL;
- }
+ if (!context)
+ {
+ gdip_propegate_error (error, "Couldn't create context", GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY);
+ return NULL;
+ }
- if (error)
- *error = NULL;
+ if (error)
+ *error = NULL;
- context->first_write = TRUE;
- context->size_func = size_func;
+ context->first_write = TRUE;
+ context->size_func = size_func;
- context->prepared_func = prepared_func;
- context->updated_func = updated_func;
- context->user_data = user_data;
+ context->prepared_func = prepared_func;
+ context->updated_func = updated_func;
+ context->user_data = user_data;
- context->buffer = g_byte_array_new();
+ context->buffer = g_byte_array_new();
- return context;
+ return context;
}
static gboolean
@@ -117,218 +117,219 @@
const guchar *buf, guint size,
GError **error)
{
- GdipContext *context = (GdipContext *)data;
- GByteArray *image_buffer = context->buffer;
+ GdipContext *context = (GdipContext *)data;
+ GByteArray *image_buffer = context->buffer;
- if (error)
- *error = NULL;
+ if (error)
+ *error = NULL;
- g_byte_array_append(image_buffer, (guint8*)buf, size);
+ g_byte_array_append(image_buffer, (guint8*)buf, size);
- return TRUE;
+ return TRUE;
}
static GdkPixbuf*
gdi_bitmap_to_pixbuf (GpBitmap *bitmap)
{
- GdkPixbuf *pixbuf = NULL;
- guchar *cursor = NULL;
- gint rowstride;
- gboolean has_alpha = FALSE;
- gint n_channels = 0;
-
- guint width = 0, height = 0, x, y;
-
- io_gdip_bitmap_get_size (bitmap, &width, &height);
- io_gdip_bitmap_get_has_alpha (bitmap, &has_alpha);
-
- pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, has_alpha, 8, width, height);
-
- if (!pixbuf)
- {
- return NULL;
- }
-
- rowstride = gdk_pixbuf_get_rowstride (pixbuf);
- cursor = gdk_pixbuf_get_pixels (pixbuf);
- n_channels = gdk_pixbuf_get_n_channels (pixbuf);
-
- for (y = 0; y < height; y++)
- {
- for (x = 0; x < width; x++)
- {
- ARGB pixel;
- guint8 alpha;
- guchar *b = cursor + (y * rowstride + (x * n_channels));
-
- pixel = io_gdip_bitmap_get_pixel (bitmap, x, y);
-
- /* un-premultiply alpha */
- alpha = (pixel & 0xff000000) >> 24;
- if (alpha == 0)
- {
- b[0] = b[1] = b[2];
- }
- else
- {
- b[0] = (((pixel & 0xff0000) >> 16) * 255 + alpha / 2) / alpha;
- b[1] = (((pixel & 0x00ff00) >> 8) * 255 + alpha / 2) / alpha;
- b[2] = (((pixel & 0x0000ff) >> 0) * 255 + alpha / 2) / alpha;
- }
-
- if (has_alpha)
- {
- b[3] = alpha;
- }
- }
- }
+ GdkPixbuf *pixbuf = NULL;
+ guchar *cursor = NULL;
+ gint rowstride;
+ gboolean has_alpha = FALSE;
+ gint n_channels = 0;
+
+ guint width = 0, height = 0, x, y;
+
+ io_gdip_bitmap_get_size (bitmap, &width, &height);
+ io_gdip_bitmap_get_has_alpha (bitmap, &has_alpha);
+
+ pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, has_alpha, 8, width, height);
+
+ if (!pixbuf)
+ {
+ return NULL;
+ }
+
+ rowstride = gdk_pixbuf_get_rowstride (pixbuf);
+ cursor = gdk_pixbuf_get_pixels (pixbuf);
+ n_channels = gdk_pixbuf_get_n_channels (pixbuf);
+
+ for (y = 0; y < height; y++)
+ {
+ for (x = 0; x < width; x++)
+ {
+ ARGB pixel;
+ guint8 alpha;
+ guchar *b = cursor + (y * rowstride + (x * n_channels));
+
+ pixel = io_gdip_bitmap_get_pixel (bitmap, x, y);
+
+ /* un-premultiply alpha */
+ alpha = (pixel & 0xff000000) >> 24;
+ if (alpha == 0)
+ {
+ b[0] = b[1] = b[2];
+ }
+ else
+ {
+ b[0] = (((pixel & 0xff0000) >> 16) * 255 + alpha / 2) / alpha;
+ b[1] = (((pixel & 0x00ff00) >> 8) * 255 + alpha / 2) / alpha;
+ b[2] = (((pixel & 0x0000ff) >> 0) * 255 + alpha / 2) / alpha;
+ }
+
+ if (has_alpha)
+ {
+ b[3] = alpha;
+ }
+ }
+ }
- return pixbuf;
+ return pixbuf;
}
static gboolean
gdk_pixbuf__gdip_image_stop_load (gpointer data, GError **error)
{
- GdipContext *context = (GdipContext *)data;
- GpBitmap *bitmap = NULL;
+ GdipContext *context = (GdipContext *)data;
+ GpBitmap *bitmap = NULL;
- GByteArray *image_buffer = context->buffer;
- guint8 *tmp_buffer = NULL;
- guint buffer_len = 0;
- guint n_frames = 1, i;
- GdkPixbufAnimation *anim = NULL;
-
- if (error)
- *error = NULL;
-
- buffer_len = image_buffer->len;
- tmp_buffer = image_buffer->data;
-
- bitmap = io_gdip_buffer_to_bitmap ((gchar*)image_buffer->data, image_buffer->len);
-
- if (!bitmap)
- {
- destroy_gdipcontext (context);
- gdip_propegate_error (error, "Couldn't load bitmap", GDK_PIXBUF_ERROR_CORRUPT_IMAGE);
- return FALSE;
- }
-
- io_gdip_bitmap_get_n_frames (bitmap, &n_frames, TRUE);
-
- for (i = 0; i < n_frames; i++)
- {
- GdkPixbuf *pixbuf = NULL;
-
- io_gdip_bitmap_select_frame (bitmap, i, TRUE);
-
- if (n_frames > 1 && i == 0)
- {
- guint delay; /* in hundredths per second */
- guint width = 0, height = 0;
- gfloat rate = 1;
-
- io_gdip_bitmap_get_frame_delay (bitmap, &delay);
- rate = 1.0f / ((gfloat)delay / 100);
-
- io_gdip_bitmap_get_size (bitmap, &width, &height);
- // anim = GDK_PIXBUF_ANIMATION(gdk_pixbuf_simple_anim_new (width, height, rate));
- }
-
- pixbuf = gdi_bitmap_to_pixbuf (bitmap);
-
- if (!pixbuf)
- {
- destroy_gdipcontext (context);
- gdip_propegate_error (error, "Couldn't create pixbuf", GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY);
- return FALSE;
- }
-
- if (anim != NULL)
- {
- gdk_pixbuf_simple_anim_add_frame (GDK_PIXBUF_SIMPLE_ANIM(anim), pixbuf);
- }
-
- if (i == 0)
- {
- emit_prepared (context, pixbuf, anim);
- }
-
- emit_updated (context, pixbuf);
- }
-
- destroy_gdipcontext (context);
-
- return TRUE;
+ GByteArray *image_buffer = context->buffer;
+ guint8 *tmp_buffer = NULL;
+ guint buffer_len = 0;
+ guint n_frames = 1, i;
+
+ GdkPixbufAnimation *anim = NULL;
+
+ if (error)
+ *error = NULL;
+
+ buffer_len = image_buffer->len;
+ tmp_buffer = image_buffer->data;
+
+ bitmap = io_gdip_buffer_to_bitmap ((gchar*)image_buffer->data, image_buffer->len);
+
+ if (!bitmap)
+ {
+ destroy_gdipcontext (context);
+ gdip_propegate_error (error, "Couldn't load bitmap", GDK_PIXBUF_ERROR_CORRUPT_IMAGE);
+ return FALSE;
+ }
+
+ io_gdip_bitmap_get_n_frames (bitmap, &n_frames, TRUE);
+
+ for (i = 0; i < n_frames; i++)
+ {
+ GdkPixbuf *pixbuf = NULL;
+
+ io_gdip_bitmap_select_frame (bitmap, i, TRUE);
+
+ if (n_frames > 1 && i == 0)
+ {
+ guint delay; /* in hundredths per second */
+ guint width = 0, height = 0;
+ gfloat rate = 1;
+
+ io_gdip_bitmap_get_frame_delay (bitmap, &delay);
+ rate = 1.0f / ((gfloat)delay / 100);
+
+ io_gdip_bitmap_get_size (bitmap, &width, &height);
+ // anim = GDK_PIXBUF_ANIMATION(gdk_pixbuf_simple_anim_new (width, height, rate));
+ }
+
+ pixbuf = gdi_bitmap_to_pixbuf (bitmap);
+
+ if (!pixbuf)
+ {
+ destroy_gdipcontext (context);
+ gdip_propegate_error (error, "Couldn't create pixbuf", GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY);
+ return FALSE;
+ }
+
+ if (anim != NULL)
+ {
+ gdk_pixbuf_simple_anim_add_frame (GDK_PIXBUF_SIMPLE_ANIM(anim), pixbuf);
+ }
+
+ if (i == 0)
+ {
+ emit_prepared (context, pixbuf, anim);
+ }
+
+ emit_updated (context, pixbuf);
+ }
+
+ destroy_gdipcontext (context);
+
+ return TRUE;
}
void
fill_vtable (GdkPixbufModule *module)
{
- io_gdip_init ();
+ io_gdip_init ();
- module->begin_load = gdk_pixbuf__gdip_image_begin_load;
- module->stop_load = gdk_pixbuf__gdip_image_stop_load;
- module->load_increment = gdk_pixbuf__gdip_image_load_increment;
+ module->begin_load = gdk_pixbuf__gdip_image_begin_load;
+ module->stop_load = gdk_pixbuf__gdip_image_stop_load;
+ module->load_increment = gdk_pixbuf__gdip_image_load_increment;
}
void
fill_info (GdkPixbufFormat *info)
{
- static GdkPixbufModulePattern signature[] = {
- { "\xff\xd8", NULL, 100 }, /* JPEG */
- { "BM", NULL, 100 }, /* BMP */
- { "GIF8", NULL, 100 }, /* GIF */
- { " \x1 ", "zz znz", 100 }, /* ICO */
- { " \x2 ", "zz znz", 100 }, /* ICO */
- { "\x89PNG\r\n\x1a\x0a", NULL, 100 }, /* PNG */
- { "MM \x2a", " z ", 100 }, /* TIFF */
- { "II\x2a ", " z", 100 }, /* TIFF */
- { "\xd7\xcd\xc6\x9a", NULL, 100 }, /* WMF */
- { "\x01\x00\x09\x00", NULL, 100 }, /* WMF */
- { "\x01\x00\x00\x00", NULL, 100 }, /* EMF */
- { NULL, NULL, 0 }
- };
-
- static gchar *mime_types[] = {
- "image/jpeg",
- "image/bmp",
- "image/x-bmp",
- "image/x-MS-bmp",
- "image/gif",
- "image/x-icon",
- "image/x-ico",
- "image/png",
- "image/tiff",
- "image/x-wmf",
- "application/emf",
- "application/x-emf",
- "image/x-emf",
- "image/x-mgx-emf",
- "image/x-xbitmap",
- NULL
- };
-
- static gchar *extensions[] = {
- "jpeg",
- "jpe",
- "jpg",
- "bmp",
- "gif",
- "ico",
- "cur",
- "png",
- "tiff",
- "tif",
- "wmf",
- "apm",
- "emf",
- NULL
- };
-
- info->name = "Win32 GDI+";
- info->signature = signature;
- info->description = "Win32 GDI+ JPEG, Tiff and PNG loader.";
- info->mime_types = mime_types;
- info->extensions = extensions;
- info->flags = 0;
+ static GdkPixbufModulePattern signature[] = {
+ { "\xff\xd8", NULL, 100 }, /* JPEG */
+ { "BM", NULL, 100 }, /* BMP */
+ { "GIF8", NULL, 100 }, /* GIF */
+ { " \x1 ", "zz znz", 100 }, /* ICO */
+ { " \x2 ", "zz znz", 100 }, /* ICO */
+ { "\x89PNG\r\n\x1a\x0a", NULL, 100 }, /* PNG */
+ { "MM \x2a", " z ", 100 }, /* TIFF */
+ { "II\x2a ", " z", 100 }, /* TIFF */
+ { "\xd7\xcd\xc6\x9a", NULL, 100 }, /* WMF */
+ { "\x01\x00\x09\x00", NULL, 100 }, /* WMF */
+ { "\x01\x00\x00\x00", NULL, 100 }, /* EMF */
+ { NULL, NULL, 0 }
+ };
+
+ static gchar *mime_types[] = {
+ "image/jpeg",
+ "image/bmp",
+ "image/x-bmp",
+ "image/x-MS-bmp",
+ "image/gif",
+ "image/x-icon",
+ "image/x-ico",
+ "image/png",
+ "image/tiff",
+ "image/x-wmf",
+ "application/emf",
+ "application/x-emf",
+ "image/x-emf",
+ "image/x-mgx-emf",
+ "image/x-xbitmap",
+ NULL
+ };
+
+ static gchar *extensions[] = {
+ "jpeg",
+ "jpe",
+ "jpg",
+ "bmp",
+ "gif",
+ "ico",
+ "cur",
+ "png",
+ "tiff",
+ "tif",
+ "wmf",
+ "apm",
+ "emf",
+ NULL
+ };
+
+ info->name = "Win32 GDI+";
+ info->signature = signature;
+ info->description = "Win32 GDI+ JPEG, Tiff and PNG loader.";
+ info->mime_types = mime_types;
+ info->extensions = extensions;
+ info->flags = 0;
}
Modified: trunk/src/test.c
==============================================================================
--- trunk/src/test.c (original)
+++ trunk/src/test.c Tue Feb 19 17:06:12 2008
@@ -1,4 +1,4 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* GdkPixbuf library - Win32 GDI+ Pixbuf Loader
*
* Copyright (C) 2008 Alberto Ruiz
@@ -20,36 +20,36 @@
*/
static const unsigned char the_png[] = {
-0xff, 0xd8, 0xff, 0xe0, 0x00, 0x10, 0x4a, 0x46, 0x49, 0x46, 0x00, 0x01,
-0x01, 0x01, 0x01, 0x19, 0x01, 0x19, 0x00, 0x00, 0xff, 0xe1, 0x00, 0x16,
-0x45, 0x78, 0x69, 0x66, 0x00, 0x00, 0x4d, 0x4d, 0x00, 0x2a, 0x00, 0x00,
-0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xdb, 0x00, 0x43,
-0x00, 0x05, 0x03, 0x04, 0x04, 0x04, 0x03, 0x05, 0x04, 0x04, 0x04, 0x05,
-0x05, 0x05, 0x06, 0x07, 0x0c, 0x08, 0x07, 0x07, 0x07, 0x07, 0x0f, 0x0b,
-0x0b, 0x09, 0x0c, 0x11, 0x0f, 0x12, 0x12, 0x11, 0x0f, 0x11, 0x11, 0x13,
-0x16, 0x1c, 0x17, 0x13, 0x14, 0x1a, 0x15, 0x11, 0x11, 0x18, 0x21, 0x18,
-0x1a, 0x1d, 0x1d, 0x1f, 0x1f, 0x1f, 0x13, 0x17, 0x22, 0x24, 0x22, 0x1e,
-0x24, 0x1c, 0x1e, 0x1f, 0x1e, 0xff, 0xdb, 0x00, 0x43, 0x01, 0x05, 0x05,
-0x05, 0x07, 0x06, 0x07, 0x0e, 0x08, 0x08, 0x0e, 0x1e, 0x14, 0x11, 0x14,
-0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
-0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
-0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
-0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
-0x1e, 0x1e, 0xff, 0xc0, 0x00, 0x11, 0x08, 0x00, 0x04, 0x00, 0x05, 0x03,
-0x01, 0x22, 0x00, 0x02, 0x11, 0x01, 0x03, 0x11, 0x01, 0xff, 0xc4, 0x00,
-0x15, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0xff, 0xc4, 0x00, 0x22,
-0x10, 0x00, 0x01, 0x02, 0x05, 0x04, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x03, 0x05, 0x06, 0x12,
-0x31, 0x04, 0x07, 0x13, 0x21, 0x22, 0x25, 0x71, 0xff, 0xc4, 0x00, 0x14,
-0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xc4, 0x00, 0x14, 0x11, 0x01,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0xff, 0xda, 0x00, 0x0c, 0x03, 0x01, 0x00, 0x02,
-0x11, 0x03, 0x11, 0x00, 0x3f, 0x00, 0xa1, 0xf6, 0xe6, 0x53, 0x0a, 0x0d,
-0x4f, 0x50, 0xbc, 0x6a, 0x63, 0xbf, 0x90, 0xb8, 0xda, 0xfb, 0x1c, 0x1b,
-0xec, 0x26, 0x18, 0xf1, 0xeb, 0x20, 0x7c, 0x0d, 0x18, 0x01, 0x11, 0x10,
-0x7f, 0xff, 0xd9,
+0xff, 0xd8, 0xff, 0xe0, 0x00, 0x10, 0x4a, 0x46, 0x49, 0x46, 0x00, 0x01,
+0x01, 0x01, 0x01, 0x19, 0x01, 0x19, 0x00, 0x00, 0xff, 0xe1, 0x00, 0x16,
+0x45, 0x78, 0x69, 0x66, 0x00, 0x00, 0x4d, 0x4d, 0x00, 0x2a, 0x00, 0x00,
+0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xdb, 0x00, 0x43,
+0x00, 0x05, 0x03, 0x04, 0x04, 0x04, 0x03, 0x05, 0x04, 0x04, 0x04, 0x05,
+0x05, 0x05, 0x06, 0x07, 0x0c, 0x08, 0x07, 0x07, 0x07, 0x07, 0x0f, 0x0b,
+0x0b, 0x09, 0x0c, 0x11, 0x0f, 0x12, 0x12, 0x11, 0x0f, 0x11, 0x11, 0x13,
+0x16, 0x1c, 0x17, 0x13, 0x14, 0x1a, 0x15, 0x11, 0x11, 0x18, 0x21, 0x18,
+0x1a, 0x1d, 0x1d, 0x1f, 0x1f, 0x1f, 0x13, 0x17, 0x22, 0x24, 0x22, 0x1e,
+0x24, 0x1c, 0x1e, 0x1f, 0x1e, 0xff, 0xdb, 0x00, 0x43, 0x01, 0x05, 0x05,
+0x05, 0x07, 0x06, 0x07, 0x0e, 0x08, 0x08, 0x0e, 0x1e, 0x14, 0x11, 0x14,
+0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
+0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
+0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
+0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
+0x1e, 0x1e, 0xff, 0xc0, 0x00, 0x11, 0x08, 0x00, 0x04, 0x00, 0x05, 0x03,
+0x01, 0x22, 0x00, 0x02, 0x11, 0x01, 0x03, 0x11, 0x01, 0xff, 0xc4, 0x00,
+0x15, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0xff, 0xc4, 0x00, 0x22,
+0x10, 0x00, 0x01, 0x02, 0x05, 0x04, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x03, 0x05, 0x06, 0x12,
+0x31, 0x04, 0x07, 0x13, 0x21, 0x22, 0x25, 0x71, 0xff, 0xc4, 0x00, 0x14,
+0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xc4, 0x00, 0x14, 0x11, 0x01,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0xff, 0xda, 0x00, 0x0c, 0x03, 0x01, 0x00, 0x02,
+0x11, 0x03, 0x11, 0x00, 0x3f, 0x00, 0xa1, 0xf6, 0xe6, 0x53, 0x0a, 0x0d,
+0x4f, 0x50, 0xbc, 0x6a, 0x63, 0xbf, 0x90, 0xb8, 0xda, 0xfb, 0x1c, 0x1b,
+0xec, 0x26, 0x18, 0xf1, 0xeb, 0x20, 0x7c, 0x0d, 0x18, 0x01, 0x11, 0x10,
+0x7f, 0xff, 0xd9,
};
@@ -59,43 +59,44 @@
void
_print_pixels (GpBitmap * bitmap)
{
- int width = 0, height = 0, x, y;
- ARGB pixel;
- gchar * p1, * p2, * p3, * p4;
-
- io_gdip_bitmap_get_size (bitmap, &width, &height);
-
- for (x = 0; x <= width; x++) {
- for (y = 0; y <= height; y++)
- {
- pixel = io_gdip_bitmap_get_pixel(bitmap, x, y);
- p1 = (gchar *)&pixel;
- p2 = p1 + 1;
- p3 = p2 + 1;
- p4 = p3 + 1;
- printf("%32x", pixel);
- }
-
- printf("\n");
- }
+ int width = 0, height = 0, x, y;
+ ARGB pixel;
+ gchar * p1, * p2, * p3, * p4;
+
+ io_gdip_bitmap_get_size (bitmap, &width, &height);
+
+ for (x = 0; x <= width; x++) {
+ for (y = 0; y <= height; y++)
+ {
+ pixel = io_gdip_bitmap_get_pixel(bitmap, x, y);
+ p1 = (gchar *)&pixel;
+ p2 = p1 + 1;
+ p3 = p2 + 1;
+ p4 = p3 + 1;
+ printf("%32x", pixel);
+ }
+
+ printf("\n");
+ }
}
int
main ()
{
- GpBitmap * bitmap = NULL;
+ GpBitmap * bitmap = NULL;
+
+ if (!io_gdip_init ())
+ return 1;
- if (!io_gdip_init ())
- return 1;
+ bitmap = io_gdip_buffer_to_bitmap (the_png, sizeof (the_png));
+ if (!bitmap)
+ return 1;
- bitmap = io_gdip_buffer_to_bitmap (the_png, sizeof (the_png));
- if (!bitmap) return 1;
+ _print_pixels (bitmap);
- _print_pixels (bitmap);
+ io_gdip_dispose_bitmap (bitmap);
- io_gdip_dispose_bitmap (bitmap);
-
- return 0;
+ return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]