gdk-pixbuf-data.c 977 Bytes
Newer Older
1
/*
2
 * gdk-pixbuf-data.c: Code to load images into GdkPixbufs from constant data
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
 *
 * Author:
 *    Michael Fulbright (drmike@redhat.com)
 *    Copyright (C) 1999 Red Hat, Inc.
 */

#include <config.h>
#include <stdio.h>
#include <string.h>
#include <glib.h>

#include "gdk-pixbuf.h"

/* This function does all the work. */

18
static GdkPixbuf *
19 20
_pixbuf_create_from_rgb_d(unsigned char *data, int w, int h)
{
21
	GdkPixbuf *pixbuf;
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
	ArtPixBuf *art_pixbuf;
	art_u8 *pixels;

	pixels = art_alloc (w*h*3);
	if (!pixels) {
		g_warning ("RGBD: Cannot alloc ArtBuf");
		return NULL;
	}

	memcpy (pixels, data, w*h*3);

	art_pixbuf = art_pixbuf_new_rgb (pixels, w, h, (w*3));
	pixbuf = gdk_pixbuf_new (art_pixbuf, NULL);

	if (!pixbuf)
		art_free (pixels);

	return pixbuf;
}


43 44
GdkPixbuf *
gdk_pixbuf_load_image_from_rgb_d (unsigned char *data, int rgb_width, int rgb_height)
45 46 47 48 49
{
	g_return_val_if_fail (data != NULL, NULL);

	return _pixbuf_create_from_rgb_d(data, rgb_width, rgb_height);
}