gdip-pixbuf-loader r13 - in trunk: . src
- From: doml svn gnome org
- To: svn-commits-list gnome org
- Subject: gdip-pixbuf-loader r13 - in trunk: . src
- Date: Mon, 18 Feb 2008 18:14:49 +0000 (GMT)
Author: doml
Date: Mon Feb 18 18:14:49 2008
New Revision: 13
URL: http://svn.gnome.org/viewvc/gdip-pixbuf-loader?rev=13&view=rev
Log:
2008-02-18 Dominic Lachowicz <domlachowicz gmail com>
* src/io-gdip.c: Fill pixbuf properly; propegate errors. Plugin now works for non-animations
Modified:
trunk/ChangeLog
trunk/src/io-gdip.c
Modified: trunk/src/io-gdip.c
==============================================================================
--- trunk/src/io-gdip.c (original)
+++ trunk/src/io-gdip.c Mon Feb 18 18:14:49 2008
@@ -49,6 +49,17 @@
G_MODULE_EXPORT void fill_info (GdkPixbufFormat *info);
static void
+gdip_propegate_error (GError ** err,
+ const char * reason,
+ gint code)
+{
+ if (err) {
+ *err = NULL;
+ g_set_error (err, GDK_PIXBUF_ERROR, code, reason);
+ }
+}
+
+static void
destroy_gdipcontext (GdipContext *context)
{
if (context != NULL)
@@ -86,8 +97,10 @@
GdipContext *context = g_new(GdipContext, 1);
if (!context)
- //TODO: This should be a proper error
- return NULL;
+ {
+ gdip_propegate_error (error, "Couldn't create context", 0);
+ return NULL;
+ }
if (error)
*error = NULL;
@@ -132,7 +145,6 @@
GdkPixbuf *pixbuf = NULL;
guchar *cursor = NULL;
gint rowstride;
- gint n_channels;
gboolean result = TRUE;
@@ -149,6 +161,7 @@
if (!bitmap)
{
destroy_gdipcontext (context);
+ gdip_propegate_error (error, "Couldn't load bitmap", 0);
return FALSE;
}
@@ -159,36 +172,34 @@
if (!pixbuf)
{
destroy_gdipcontext (context);
+ gdip_propegate_error (error, "Couldn't create Pixbuf", 0);
return FALSE;
}
- n_channels = gdk_pixbuf_get_n_channels (pixbuf);
rowstride = gdk_pixbuf_get_rowstride (pixbuf);
cursor = gdk_pixbuf_get_pixels (pixbuf);
- for (y = 0; y<=height; y++)
+ for (y = 0; y < height; y++)
{
- for (x = 0; x<=width; x++)
+ guint8 *row_data = (cursor + (y * rowstride));
+
+ for (x = 0; x < width; x++)
{
ARGB pixel;
- guchar * channel;
guint8 alpha;
+ guchar *b = cursor + (y * rowstride + (x * 4));
pixel = io_gdip_bitmap_get_pixel (bitmap, x, y);
- channel = (guchar*) &pixel;
-
- if (y > 0) cursor += y * x * n_channels;
- else cursor += x * n_channels;
/* un-premultiply alpha */
alpha = (pixel & 0xff000000) >> 24;
if (alpha == 0) {
- cursor[0] = cursor[1] = cursor[2] = cursor[3] = 0;
+ b[0] = b[1] = b[2] = b[3] = 0;
} else {
- cursor[0] = (((pixel & 0xff0000) >> 16) * 255 + alpha / 2) / alpha;
- cursor[1] = (((pixel & 0x00ff00) >> 8) * 255 + alpha / 2) / alpha;
- cursor[2] = (((pixel & 0x0000ff) >> 0) * 255 + alpha / 2) / alpha;
- cursor[3] = alpha;
+ 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;
+ b[3] = alpha;
}
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]