gdip-pixbuf-loader r44 - in trunk: . src
- From: doml svn gnome org
- To: svn-commits-list gnome org
- Subject: gdip-pixbuf-loader r44 - in trunk: . src
- Date: Tue, 4 Mar 2008 19:37:52 +0000 (GMT)
Author: doml
Date: Tue Mar 4 19:37:52 2008
New Revision: 44
URL: http://svn.gnome.org/viewvc/gdip-pixbuf-loader?rev=44&view=rev
Log:
2008-03-04 Dominic Lachowicz <domlachowicz gmail com>
* src/io-gdip-utils.c: More informative error codes, taken from the COM HRESULT
Modified:
trunk/ChangeLog
trunk/src/io-gdip-bmp.c
trunk/src/io-gdip-gif.c
trunk/src/io-gdip-jpeg.c
trunk/src/io-gdip-png.c
trunk/src/io-gdip-tiff.c
trunk/src/io-gdip-utils.c
trunk/src/io-gdip-utils.h
Modified: trunk/src/io-gdip-bmp.c
==============================================================================
--- trunk/src/io-gdip-bmp.c (original)
+++ trunk/src/io-gdip-bmp.c Tue Mar 4 19:37:52 2008
@@ -31,14 +31,7 @@
gchar **values,
GError **error)
{
- EncoderParameters *encoder_params = NULL;
- gboolean status;
-
- status = io_gdip_save_pixbuf (pixbuf, L"image/bmp", encoder_params, save_func, user_data, error);
-
- g_free (encoder_params);
-
- return status;
+ return gdip_save_pixbuf (pixbuf, L"image/bmp", NULL, save_func, user_data, error);
}
static gboolean
Modified: trunk/src/io-gdip-gif.c
==============================================================================
--- trunk/src/io-gdip-gif.c (original)
+++ trunk/src/io-gdip-gif.c Tue Mar 4 19:37:52 2008
@@ -31,15 +31,7 @@
gchar **values,
GError **error)
{
- /* TODO: support exif data and the like */
- EncoderParameters *encoder_params = NULL;
- gboolean status;
-
- status = io_gdip_save_pixbuf (pixbuf, L"image/gif", encoder_params, save_func, user_data, error);
-
- g_free (encoder_params);
-
- return status;
+ return gdip_save_pixbuf (pixbuf, L"image/gif", NULL, save_func, user_data, error);
}
static gboolean
Modified: trunk/src/io-gdip-jpeg.c
==============================================================================
--- trunk/src/io-gdip-jpeg.c (original)
+++ trunk/src/io-gdip-jpeg.c Tue Mar 4 19:37:52 2008
@@ -28,11 +28,11 @@
static gboolean
gdk_pixbuf__gdip_image_save_JPEG_to_callback (GdkPixbufSaveFunc save_func,
- gpointer user_data,
- GdkPixbuf *pixbuf,
- gchar **keys,
- gchar **values,
- GError **error)
+ gpointer user_data,
+ GdkPixbuf *pixbuf,
+ gchar **keys,
+ gchar **values,
+ GError **error)
{
EncoderParameters encoder_params;
LONG quality = 75; /* default; must be between 0 and 100 */
@@ -85,11 +85,11 @@
encoder_params.Parameter[0].NumberOfValues = 1;
encoder_params.Parameter[0].Value = &quality;
- return io_gdip_save_pixbuf (pixbuf, L"image/jpeg", &encoder_params, save_func, user_data, error);
+ return gdip_save_pixbuf (pixbuf, L"image/jpeg", &encoder_params, save_func, user_data, error);
}
static gboolean
-gdk_pixbuf__gdip_image_save_JPEG (FILE *f,
+gdk_pixbuf__gdip_image_save_JPEG (FILE *f,
GdkPixbuf *pixbuf,
gchar **keys,
gchar **values,
Modified: trunk/src/io-gdip-png.c
==============================================================================
--- trunk/src/io-gdip-png.c (original)
+++ trunk/src/io-gdip-png.c Tue Mar 4 19:37:52 2008
@@ -84,7 +84,7 @@
encoder_params.Parameter[0].NumberOfValues = 1;
encoder_params.Parameter[0].Value = &compression;
- return io_gdip_save_pixbuf (pixbuf, L"image/png", &encoder_params, save_func, user_data, error);
+ return gdip_save_pixbuf (pixbuf, L"image/png", &encoder_params, save_func, user_data, error);
}
static gboolean
Modified: trunk/src/io-gdip-tiff.c
==============================================================================
--- trunk/src/io-gdip-tiff.c (original)
+++ trunk/src/io-gdip-tiff.c Tue Mar 4 19:37:52 2008
@@ -25,25 +25,17 @@
static gboolean
gdk_pixbuf__gdip_image_save_TIFF_to_callback (GdkPixbufSaveFunc save_func,
- gpointer user_data,
- GdkPixbuf *pixbuf,
- gchar **keys,
- gchar **values,
- GError **error)
+ gpointer user_data,
+ GdkPixbuf *pixbuf,
+ gchar **keys,
+ gchar **values,
+ GError **error)
{
- /* TODO: support exif data and the like */
- EncoderParameters *encoder_params = NULL;
- gboolean status;
-
- status = io_gdip_save_pixbuf (pixbuf, L"image/tiff", encoder_params, save_func, user_data, error);
-
- g_free (encoder_params);
-
- return status;
+ return gdip_save_pixbuf (pixbuf, L"image/tiff", NULL, save_func, user_data, error);
}
static gboolean
-gdk_pixbuf__gdip_image_save_TIFF (FILE *f,
+gdk_pixbuf__gdip_image_save_TIFF (FILE *f,
GdkPixbuf *pixbuf,
gchar **keys,
gchar **values,
Modified: trunk/src/io-gdip-utils.c
==============================================================================
--- trunk/src/io-gdip-utils.c (original)
+++ trunk/src/io-gdip-utils.c Tue Mar 4 19:37:52 2008
@@ -66,8 +66,42 @@
}
}
+static gchar *
+gdip_hresult_to_utf8 (HRESULT hr)
+{
+ void *pMsgBuf;
+ gchar *utf8_msg;
+
+ if (SUCCEEDED (hr))
+ return NULL;
+
+ FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM, NULL, hr,
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&pMsgBuf, 0, NULL);
+
+ utf8_msg = g_locale_to_utf8 ((char const *)pMsgBuf, -1, NULL, NULL, NULL);
+ if (utf8_msg == NULL)
+ utf8_msg = g_strdup ("!SUCCEEDED (hr)");
+
+ LocalFree(pMsgBuf);
+
+ return utf8_msg;
+}
+
+static void
+gdip_hresult_to_gerror (HRESULT hr, gint code, GError **err)
+{
+ gchar *msg;
+
+ msg = gdip_hresult_to_utf8 (hr);
+
+ if (msg) {
+ gdip_propegate_error(err, msg, code);
+ g_free (msg);
+ }
+}
+
static gboolean
-io_gdip_init (void)
+gdip_init (void)
{
GdiplusStartupInput input;
ULONG_PTR gdiplusToken = 0;
@@ -76,7 +110,7 @@
if (!gdipluslib)
gdipluslib = LoadLibrary ("gdiplus.dll");
else
- return TRUE; /* io_gdip_init() is idempotent */
+ return TRUE; /* gdip_init() is idempotent */
if (!gdipluslib)
return FALSE;
@@ -182,7 +216,7 @@
}
static HGLOBAL
-io_gdip_buffer_to_hglobal (const gchar *buffer, size_t size)
+gdip_buffer_to_hglobal (const gchar *buffer, size_t size)
{
HGLOBAL hg = NULL;
@@ -197,12 +231,12 @@
}
static gboolean
-io_gdip_save_bitmap_to_callback (GpBitmap *bitmap,
- const CLSID *format,
- const EncoderParameters *encoder_params,
- GdkPixbufSaveFunc save_func,
- gpointer user_data,
- GError **error)
+gdip_save_bitmap_to_callback (GpBitmap *bitmap,
+ const CLSID *format,
+ const EncoderParameters *encoder_params,
+ GdkPixbufSaveFunc save_func,
+ gpointer user_data,
+ GError **error)
{
HRESULT hr;
IStream *streamOut = NULL;
@@ -211,7 +245,7 @@
hr = CreateStreamOnHGlobal (NULL, TRUE, &streamOut);
if (!SUCCEEDED (hr)) {
- gdip_propegate_error (error, _("Couldn't save"), GDK_PIXBUF_ERROR_FAILED);
+ gdip_hresult_to_gerror (hr, GDK_PIXBUF_ERROR_FAILED, error);
return FALSE;
}
@@ -222,7 +256,9 @@
}
/* seek back to the beginning of the stream */
- if (!SUCCEEDED (IStream_Seek (streamOut, *(LARGE_INTEGER *)&zero, STREAM_SEEK_SET, NULL))) {
+ hr = IStream_Seek (streamOut, *(LARGE_INTEGER *)&zero, STREAM_SEEK_SET, NULL);
+ if (!SUCCEEDED (hr)) {
+ gdip_hresult_to_gerror (hr, GDK_PIXBUF_ERROR_FAILED, error);
IStream_Release (streamOut);
return FALSE;
}
@@ -233,7 +269,10 @@
hr = IStream_Read (streamOut, buffer, sizeof(buffer), &nread);
if (!SUCCEEDED (hr))
- break;
+ {
+ gdip_hresult_to_gerror (hr, GDK_PIXBUF_ERROR_FAILED, error);
+ break;
+ }
else if (0 == nread) {
success = TRUE; /* EOF */
break;
@@ -248,7 +287,7 @@
}
static GpBitmap *
-io_gdip_pixbuf_to_bitmap (GdkPixbuf *pixbuf)
+gdip_pixbuf_to_bitmap (GdkPixbuf *pixbuf)
{
GpBitmap *bitmap = NULL;
@@ -302,7 +341,7 @@
}
static GpBitmap *
-io_gdip_buffer_to_bitmap (const gchar *buffer, size_t size)
+gdip_buffer_to_bitmap (const gchar *buffer, size_t size, GError **error)
{
HRESULT hr;
HGLOBAL hg = NULL;
@@ -310,7 +349,7 @@
IStream *stream = NULL;
int status;
- hg = io_gdip_buffer_to_hglobal (buffer, size);
+ hg = gdip_buffer_to_hglobal (buffer, size);
if (!hg)
return NULL;
@@ -318,6 +357,7 @@
hr = CreateStreamOnHGlobal (hg, FALSE, (LPSTREAM *)&stream);
if (!SUCCEEDED (hr)) {
+ gdip_hresult_to_gerror (hr, GDK_PIXBUF_ERROR_FAILED, error);
GlobalFree (hg);
return NULL;
}
@@ -331,7 +371,7 @@
}
static void
-io_gdip_bitmap_get_size (GpBitmap *bitmap, guint *width, guint *height)
+gdip_bitmap_get_size (GpBitmap *bitmap, guint *width, guint *height)
{
if (bitmap == NULL || width == NULL || height == NULL)
return;
@@ -343,7 +383,7 @@
}
static void
-io_gdip_bitmap_get_has_alpha (GpBitmap *bitmap, gboolean *has_alpha)
+gdip_bitmap_get_has_alpha (GpBitmap *bitmap, gboolean *has_alpha)
{
guint flags = 0;
@@ -355,7 +395,7 @@
}
static gboolean
-io_gdip_bitmap_get_n_frames (GpBitmap *bitmap, guint *n_frames, gboolean timeDimension)
+gdip_bitmap_get_n_frames (GpBitmap *bitmap, guint *n_frames, gboolean timeDimension)
{
if (bitmap == NULL || n_frames == NULL)
return FALSE;
@@ -366,7 +406,7 @@
}
static gboolean
-io_gdip_bitmap_select_frame (GpBitmap *bitmap, guint frame, gboolean timeDimension)
+gdip_bitmap_select_frame (GpBitmap *bitmap, guint frame, gboolean timeDimension)
{
if (bitmap == NULL)
return FALSE;
@@ -375,7 +415,7 @@
}
static gboolean
-io_gdip_bitmap_get_property_as_string (GpBitmap *bitmap, guint propertyId, gchar **str)
+gdip_bitmap_get_property_as_string (GpBitmap *bitmap, guint propertyId, gchar **str)
{
guint item_size;
gboolean success = FALSE;
@@ -459,7 +499,7 @@
}
static gboolean
-io_gdip_bitmap_get_frame_delay (GpBitmap *bitmap, guint *delay)
+gdip_bitmap_get_frame_delay (GpBitmap *bitmap, guint *delay)
{
guint item_size;
gboolean success = FALSE;
@@ -486,7 +526,7 @@
}
static gboolean
-io_gdip_bitmap_get_n_loops (GpBitmap *bitmap, guint *loops)
+gdip_bitmap_get_n_loops (GpBitmap *bitmap, guint *loops)
{
guint item_size;
gboolean success = FALSE;
@@ -607,8 +647,8 @@
guint width = 0, height = 0, x, y;
- io_gdip_bitmap_get_size (bitmap, &width, &height);
- io_gdip_bitmap_get_has_alpha (bitmap, &has_alpha);
+ gdip_bitmap_get_size (bitmap, &width, &height);
+ gdip_bitmap_get_has_alpha (bitmap, &has_alpha);
pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, has_alpha, 8, width, height);
@@ -635,17 +675,17 @@
}
}
- if (io_gdip_bitmap_get_property_as_string (bitmap, PropertyTagOrientation, &option)) {
+ if (gdip_bitmap_get_property_as_string (bitmap, PropertyTagOrientation, &option)) {
gdk_pixbuf_set_option (pixbuf, "orientation", option);
g_free (option);
}
- if (io_gdip_bitmap_get_property_as_string (bitmap, PropertyTagArtist, &option)) {
+ if (gdip_bitmap_get_property_as_string (bitmap, PropertyTagArtist, &option)) {
gdk_pixbuf_set_option (pixbuf, "Author", option);
g_free (option);
}
- if (io_gdip_bitmap_get_property_as_string (bitmap, PropertyTagImageTitle, &option)) {
+ if (gdip_bitmap_get_property_as_string (bitmap, PropertyTagImageTitle, &option)) {
gdk_pixbuf_set_option (pixbuf, "Title", option);
g_free (option);
}
@@ -671,7 +711,7 @@
buffer_len = image_buffer->len;
tmp_buffer = image_buffer->data;
- bitmap = io_gdip_buffer_to_bitmap ((gchar *)image_buffer->data, image_buffer->len);
+ bitmap = gdip_buffer_to_bitmap ((gchar *)image_buffer->data, image_buffer->len, error);
if (!bitmap) {
destroy_gdipcontext (context);
@@ -679,14 +719,14 @@
return FALSE;
}
- io_gdip_bitmap_get_n_frames (bitmap, &n_frames, TRUE);
+ gdip_bitmap_get_n_frames (bitmap, &n_frames, TRUE);
for (i = 0; i < n_frames; i++) {
GdkPixbuf *pixbuf = NULL;
GdkPixbufFrame *frame;
guint frame_delay = 0;
- io_gdip_bitmap_select_frame (bitmap, i, TRUE);
+ gdip_bitmap_select_frame (bitmap, i, TRUE);
pixbuf = gdi_bitmap_to_pixbuf (bitmap);
@@ -703,14 +743,14 @@
guint n_loops = 1;
animation = g_object_new (GDK_TYPE_PIXBUF_GDIP_ANIM, NULL);
- io_gdip_bitmap_get_n_loops (bitmap, &n_loops);
+ gdip_bitmap_get_n_loops (bitmap, &n_loops);
animation->loop = n_loops;
}
frame = g_new (GdkPixbufFrame, 1);
frame->pixbuf = pixbuf;
- io_gdip_bitmap_get_frame_delay (bitmap, &frame_delay);
+ gdip_bitmap_get_frame_delay (bitmap, &frame_delay);
animation->n_frames++;
animation->frames = g_list_append (animation->frames, frame);
@@ -824,7 +864,7 @@
void
gdip_fill_vtable (GdkPixbufModule *module)
{
- if (io_gdip_init ()) {
+ if (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;
@@ -836,12 +876,12 @@
}
gboolean
-io_gdip_save_pixbuf (GdkPixbuf *pixbuf,
- const WCHAR *format,
- const EncoderParameters *encoder_params,
- GdkPixbufSaveFunc save_func,
- gpointer user_data,
- GError **error)
+gdip_save_pixbuf (GdkPixbuf *pixbuf,
+ const WCHAR *format,
+ const EncoderParameters *encoder_params,
+ GdkPixbufSaveFunc save_func,
+ gpointer user_data,
+ GError **error)
{
GpBitmap *image;
CLSID clsid;
@@ -852,14 +892,14 @@
return FALSE;
}
- image = io_gdip_pixbuf_to_bitmap (pixbuf);
+ image = gdip_pixbuf_to_bitmap (pixbuf);
if (image == NULL) {
gdip_propegate_error (error, _("Couldn't save"), GDK_PIXBUF_ERROR_FAILED);
return FALSE;
}
- success = io_gdip_save_bitmap_to_callback (image, &clsid, encoder_params, save_func, user_data, error);
+ success = gdip_save_bitmap_to_callback (image, &clsid, encoder_params, save_func, user_data, error);
GdipDisposeImage ((GpImage *)image);
Modified: trunk/src/io-gdip-utils.h
==============================================================================
--- trunk/src/io-gdip-utils.h (original)
+++ trunk/src/io-gdip-utils.h Tue Mar 4 19:37:52 2008
@@ -51,11 +51,11 @@
gdip_fill_vtable (GdkPixbufModule *module);
gboolean
-io_gdip_save_pixbuf (GdkPixbuf *pixbuf,
- const WCHAR *format,
- const EncoderParameters *encoder_params,
- GdkPixbufSaveFunc save_func,
- gpointer user_data,
- GError **error);
+gdip_save_pixbuf (GdkPixbuf *pixbuf,
+ const WCHAR *format,
+ const EncoderParameters *encoder_params,
+ GdkPixbufSaveFunc save_func,
+ gpointer user_data,
+ GError **error);
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]