* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
-#include "gdk-pixdata.h"
+#include <config.h>
#include "gdk-pixbuf-private.h"
+#include "gdk-pixdata.h"
+#include "gdk-pixbuf-alias.h"
#include <string.h>
#define APPEND g_string_append_printf
return bp;
}
+/* Used as the destroy notification function for gdk_pixbuf_new() */
+static void
+free_buffer (guchar *pixels, gpointer data)
+{
+ g_free (pixels);
+}
+
/**
* gdk_pixdata_from_pixbuf:
* @pixdata: a #GdkPixdata to fill.
{
guint pad, n_bytes = rowstride * height;
guint8 *img_buffer_end, *data;
+ GdkPixbuf *buf = NULL;
+ if (n_bytes % bpp != 0)
+ {
+ rowstride = pixbuf->width * bpp;
+ n_bytes = rowstride * height;
+ data = g_malloc (n_bytes);
+ buf = gdk_pixbuf_new_from_data (data,
+ GDK_COLORSPACE_RGB,
+ pixbuf->has_alpha, 8,
+ pixbuf->width,
+ pixbuf->height,
+ rowstride,
+ free_buffer, NULL);
+ gdk_pixbuf_copy_area (pixbuf, 0, 0, pixbuf->width, pixbuf->height,
+ buf, 0, 0);
+ }
+ else
+ buf = (GdkPixbuf *)pixbuf;
pad = rowstride;
pad = MAX (pad, 130 + n_bytes / 127);
data = g_new (guint8, pad + n_bytes);
free_me = data;
img_buffer = data;
img_buffer_end = rl_encode_rgbx (img_buffer,
- pixbuf->pixels, pixbuf->pixels + n_bytes,
+ buf->pixels, buf->pixels + n_bytes,
bpp);
length = img_buffer_end - img_buffer;
+ if (buf != pixbuf)
+ g_object_unref (buf);
}
else
{
GdkPixdataDumpType dump_type)
{
CSourceData cdata = { 0, };
- gchar *s_uint_8, *s_uint_32, *s_uint, *s_char, *s_null;
+ gchar *s_uint_8;
guint bpp, width, height, rowstride;
gboolean rle_encoded;
gchar *macro_name;
cdata.gstring = gstring;
if (!cdata.dump_macros && cdata.dump_gtypes)
- {
- s_uint_8 = "guint8 ";
- s_uint_32 = "guint32";
- s_uint = "guint ";
- s_char = "gchar ";
- s_null = "NULL";
- }
+ s_uint_8 = "guint8 ";
else if (!cdata.dump_macros)
- {
- s_uint_8 = "unsigned char";
- s_uint_32 = "unsigned int ";
- s_uint = "unsigned int ";
- s_char = "char ";
- s_null = "(char*) 0";
- }
+ s_uint_8 = "unsigned char";
else if (cdata.dump_macros && cdata.dump_gtypes)
- {
- s_uint_8 = "guint8";
- s_uint_32 = "guint32";
- s_uint = "guint";
- s_char = "gchar";
- s_null = "NULL";
- }
+ s_uint_8 = "guint8";
else /* cdata.dump_macros && !cdata.dump_gtypes */
- {
- s_uint_8 = "unsigned char";
- s_uint_32 = "unsigned int";
- s_uint = "unsigned int";
- s_char = "char";
- s_null = "(char*) 0";
- }
+ s_uint_8 = "unsigned char";
/* initial comment
*/
cdata.static_prefix, cdata.const_prefix, name);
APPEND (gstring, " 0x%x, /* Pixbuf magic: 'GdkP' */\n",
GDK_PIXBUF_MAGIC_NUMBER);
- APPEND (gstring, " %u + %lu, /* header length + pixel_data length */\n",
+ APPEND (gstring, " %d + %lu, /* header length + pixel_data length */\n",
GDK_PIXDATA_HEADER_LENGTH,
rle_encoded ? (glong)(img_buffer_end - img_buffer) : (glong)rowstride * height);
APPEND (gstring, " 0x%x, /* pixdata_type */\n",
cdata.pos = 3;
save_uchar (&cdata, *img_buffer++); save_uchar (&cdata, *img_buffer++);
save_uchar (&cdata, *img_buffer++); save_uchar (&cdata, *img_buffer++);
- APPEND (gstring, "\"\n /* length: header (%u) + pixel_data (%u) */\n \"",
+ APPEND (gstring, "\"\n /* length: header (%d) + pixel_data (%u) */\n \"",
GDK_PIXDATA_HEADER_LENGTH,
rle_encoded ? pix_length : rowstride * height);
cdata.pos = 3;
return gdk_pixbuf_from_pixdata (&pixdata, copy_pixels, error);
}
+
+#define __GDK_PIXDATA_C__
+#include "gdk-pixbuf-aliasdef.c"